NLS Engine  v0.1
The Next Logical Step in game engine design.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
RenderModule.h
Go to the documentation of this file.
00001 
00011 #pragma once
00012 
00013 #include <d3d9.h>
00014 #include <d3dx9tex.h>
00015 #include <set>
00016 #include <string>
00017 #include <boost/function.hpp>
00018 #include <boost/bimap/bimap.hpp>
00019 #include <threading.h>
00020 
00021 #include "../sharedbase/ModuleInterface.h"
00022 #include "../sharedbase/Envelope_fwd.h"
00023 
00024 class MessageRouter;
00025 extern "C"
00026 {
00027   __declspec(dllexport) ModuleInterface* ModuleFactory(PropertyMap*, MessageRouter*, EntityList*, EventLogger*);
00028 }
00029 
00031 namespace GraphicsCore {
00032   class RenderableComponent;
00033   class CameraComponent;
00034   class MaterialsSystemInterface;
00035   class TexturesSystemInterface;
00036   class InterfaceUpdateable;
00037   enum ECoordinateSpace;
00038 }
00039 
00040 namespace GraphicsCore {
00041   typedef boost::bimaps::bimap<std::string, CameraComponent*> cameramap;
00042   typedef cameramap::value_type namedcamera;
00043 }
00044 
00045 namespace GraphicsCore {
00046   class RenderModule: public ModuleInterface {
00047   public:
00048     static RenderModule* GetRenderModule() {
00049       return RenderModule::currentRenderModule;
00050       // *TODO: remove the need for this from RenderableComponent (the complex auto-registration no longer needs to exist, it can be implmented during the Create event)
00051     }
00052 
00053     RenderModule(PropertyMap* gprops, MessageRouter* msgrouter);
00054     ~RenderModule(void); // NOTE: Do NOT inherit from: the class is not designed for inheritance.
00055 
00056     bool RegisterComponent(RenderableComponent* renderableComponent);
00057     bool UnregisterComponent(RenderableComponent* renderableComponent);
00058 
00059     bool RegisterUpdateable(InterfaceUpdateable*);
00060     bool UnregisterUpdateable(InterfaceUpdateable*);
00061 
00062     void Update(double dt);
00063     void Startup(EnvelopeSPTR);
00064     void Shutdown(EnvelopeSPTR);
00065     void CreateComponent(std::string, std::map<std::string, boost::any>&, EntitySPTR);
00066     WHO_DELETES::TYPE RemoveComponent(ComponentInterface*);
00067     
00068     MessageRouter* GetMessageRouter() {
00069       return this->msgrouter;
00070     }
00071 
00080     HRESULT TextureFactory(const std::string& file, LPDIRECT3DTEXTURE9 *texture);
00081 
00095     HRESULT MeshFactory(const std::string& file, DWORD options, LPD3DXBUFFER* ppAdjacency, LPD3DXBUFFER* ppMaterials, LPD3DXBUFFER* ppEffectInstances, DWORD* pNumMaterials, LPD3DXMESH* ppMesh);
00096 
00097   private: // Member methods
00098     static void SetRenderModule(RenderModule* engine) {
00099       RenderModule::currentRenderModule = engine;
00100     }
00101 
00102     bool Resize();
00103 
00104     void Render();
00105     void RenderObjectInSpace(ECoordinateSpace);
00106 
00107     void RegisterListeners();
00108 
00109     bool SetCurrentCamera(const std::string&);
00110     bool SetFillMode(D3DFILLMODE);
00111     bool SetRenderDelay(float);
00112     bool SetRenderRate(float);
00113     
00114     bool CreateMaterial(EnvelopeSPTR, MaterialsSystemInterface*) const;
00115     bool CreateTexture(EnvelopeSPTR, TexturesSystemInterface*) const;
00116 
00117     // Message Handlers
00118     EnvelopeSPTR HandleSetCurrentCamera(EnvelopeSPTR);
00119     EnvelopeSPTR HandleSetFillMode(EnvelopeSPTR);
00120     EnvelopeSPTR HandleSetRenderDelay(EnvelopeSPTR);
00121     EnvelopeSPTR HandleSetRenderRate(EnvelopeSPTR);
00122     EnvelopeSPTR HandleGetRenderDelay(EnvelopeSPTR) const;
00123     EnvelopeSPTR HandleGetRenderRate(EnvelopeSPTR) const;
00124 
00125 
00126   private: // Member data
00127     static RenderModule* currentRenderModule;
00128 
00129     double deltaAccumulator; 
00130 
00131     mutable Threading::ReadWriteMutex renderableComponentsMutex;
00132     std::set<RenderableComponent*> renderableComponents;
00133     
00134     mutable Threading::ReadWriteMutex myRenderableComponentsMutex;
00135     std::set<RenderableComponent*> myRenderableComponents;
00136     
00137     mutable Threading::ReadWriteMutex cameraComponentsMutex;
00138     cameramap cameraComponents;
00139     
00140     mutable Threading::ReadWriteMutex updateableObjectsMutex;
00141     std::set<InterfaceUpdateable*> updateableObjects;
00142 
00143     mutable Threading::ReadWriteMutex currentCameraMutex;
00144     CameraComponent* currentCamera;
00145     std::string currentCameraName;
00146 
00147     D3DFILLMODE fillMode;
00148     float renderDelay;
00149 
00150     LPDIRECT3D9 pD3D;
00151     LPDIRECT3DDEVICE9 pd3dDevice;
00152     D3DPRESENT_PARAMETERS d3dpp;
00153   };
00154 }