#pragma once #include "Node.h" #include "NxPhysics.h" #include "Quad.h" #include #include #include "Renderer.h" #include "ResourceManager.h" #include "RenderTarget.h" #include "Camera.h" #include "SimpleMeshRenderer.h" #include "TerrainRenderer.h" #include "SkyBoxRenderer.h" #include "HUDRenderer.h" #include "OceanRenderer.h" #include "ParticleRenderer.h" #include "PhysXDebugRenderer.h" #include "Trigger.h" #include "RaytraceRenderer.h" #include "RenderPass.h" #include "ParticleGroup.h" #include "SharedResource.h" #include "SharedResourceTexture.h" class Plane; class GameManager; class Object3d; class soundNode; class ResourceManager; class Box; #define NOFADE 0 #define FADEOUT 1 #define FADEIN 2 #define QUADLEVEL 5 #define SPTR boost::shared_ptr #define WPTR boost::weak_ptr class Scene { public: friend class Node; friend class RenderPass; Scene(void); ~Scene(void); virtual void initScene(GameManager &_manager); Node* getRoot(); void setVisible(bool _visible); bool isVisible(); void fadeIn(float _duration); void fadeOut(float _duration); void setSceneAlpha(float _alpha); void setKeyPressed(UINT key, bool bKeyPressed); void setMouseStatus(bool bLeftButtonDown, bool bRightButtonDown,bool bMiddleButtonDown, bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta, int xPos, int yPos); int* getMousePos(); virtual void OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext ); void setWidth(float _w); void setHeight(float _h); void setDepth(float _d); float getWidth(); float getHeight(); float getDepth(); virtual void clearScene(); Camera * getActiveCamera(); virtual void renderScene(float fElapsedTime); struct renderSortFunction { bool operator()(Renderer* &r1, Renderer* &r2) { return r1->isLowerThan(r2); } }; struct triggerSortFunction { bool operator()(SPTR &t1, SPTR &t2) { return t1->getTime() < t2->getTime(); } }; RenderPass* getActiveRenderPass(); //Physic Stuff NxVec3 pDefaultGravity; NxSceneDesc* getPhysicSceneDescriptor(); float getDeltaTime(); IDirect3DDevice9 * device; //Factory Stuff static const int NODE_OBJECT3D = 1; static const int NODE_CAMERA = 2; static const int NODE_SOUND = 4; static const int NODE_BOX = 8; static const int NODE_PARTICLEGROUP = 16; static const int NODE_PARTICLEEMITTER = 32; static const int NODE_SPRITE = 64; virtual Node* createNode(int type); virtual Node* createNode(int type, Node &father); virtual Node* createNode(int type, bool addDefaultRenderer); virtual Node* createNode(int type, Node &father, bool addDefaultRenderer); virtual Node* createNode(int type, Node &father, bool addDefaultRenderer, bool isReference); virtual Node* createReferenceNode(int type, bool addDefaultRenderer); void connectNodeAndRenderer(Node &node, SPTR &renderer); GameManager *manager; //Shared Resource std::vector > sharedResourceVector; static const int SR_TEXTURE_VIEWDEPTH = 1; //DepthTexture Resource static const int SR_TEXTURE_DISTORTION = 2; //DistortionMap Resource virtual SharedResource* createSharedResource(int id); SharedResource* getSharedResource(int id); //Physic Stuff NxScene* pScene; bool usePhysXDebugger; void setContactReport(NxUserContactReport *_contactReport); void setTriggerReport(NxUserTriggerReport *_triggerReport); void setNotifyReport(NxUserNotify* _notifyReport); //Device Stuff virtual void OnLostDevice( void* pUserContext ); virtual void OnDestroyDevice( void* pUserContext ); virtual HRESULT OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ); //Trigger Stuff static const int TRIGGER_UNSETSTANDBY = 0; static const int TRIGGER_KILLNODE = 1; static const int TRIGGER_SETDETAIL = 2; void setTrigger(int type, float time); void setTrigger(int type, Node *node, float time); void setTrigger(int type, Node *node, Node* secondNode, float time); void setTrigger(int type, Node *node, Node* secondNode, Vector normal, float time); float getSceneLiveTime(); //Effect Stuff Vector getSunDirection(); void setSunDirection(Vector &v); D3DXMATRIX getWorldMatrix(); D3DXMATRIX getViewMatrix(); D3DXMATRIX getProjectionMatrix(); D3DXMATRIX getIdentityMatrix(); void renderNodes(); Renderer* specialRenderer; void deleteNode(Node* node); SPTR getSmartPointer(Node *node); Object3d *sObj; RenderPass *activeRenderPass; // light: void setLight(Vector direction); //Particle Stuff std::list >* getParticleList(); ParticleGroup* getParticleGroup(int id); void addToParticleList(Node *node); ParticleGroup* defaultParticleGroup; std::vector > rendererList; //List of all renderer in scene void deleteRendererInList(Renderer* renderer); bool drawBBoxes; void renderFinalImage(ID3DXEffect* fadeEffect); int getActivePassId(); //Pass stuff static const int PASS_NORMAL = 0; static const int PASS_RAYTRACE = 1; static const int PASS_DEPTH = 2; void setActiveRenderPass(RenderPass &_activePass); LPD3DXMESH getQuadMesh(); bool useDepthImposter; bool useRaytracer; FSOUND_STREAM *bgMusicStream; int bgSoundChannel; float bgSoundVolume; bool soundStopped; void setBackgroundSound(std::string filename); void setBackgroundSoundVolume(float vol); void playBackgroundSound(); virtual void updateSoundNodeVolume(); virtual void setBackgroundSoundMute(bool _playMusic); bool getBackgroundSoundMute(); protected: //Scene Management Stuff bool visible; float fadeDuration; float fadeTimer; int fadeState; float sceneAlpha; bool muteMusic; Box* boundingBox; //Keyboard & Mouse Stuff bool keyDown[256]; static const int MOUSE_LEFT = 0; static const int MOUSE_RIGHT = 1; static const int MOUSE_MIDDLE = 2; static const int MOUSE_SIDE1 = 3; static const int MOUSE_SIDE2 = 4; bool mouseButton[5]; int mousePos[2]; int mouseWheel; float width; float height; float depth; //RenderChain Stuff std::list renderChain; bool firstFrame; void takeTime(); void fetchPhysicResults(); void doFade(); void updateTrigger(); void updateNodes(); void calculateTransformations(); void doFrustumCulling(); void doViewingTransformation(); virtual void cleanUpScene(); void startPhysic(); void startRenderPasses(); //Clear operations void clearRenderTargetAndZBuffer(); void clearSharedResources(); //Physic Stuff NxSceneDesc sceneDesc; NxReal myTimeStep; PhysXDebugRenderer physxRenderer; float dt; LARGE_INTEGER frequency; LARGE_INTEGER lastFrame; LARGE_INTEGER currentFrame; bool initPhysic(); //Culling Stuff Quad fcQuad; void buildQuadTree(); bool enableFrustumCulling; bool quadTreeBuilt; //Scene Objects Stuff Node root; D3DXMATRIX worldMatrix; D3DXMATRIX identMatrix; std::list > visibleNodeList; std::vector raytraceRendererList; std::vector heatHazeParticleRendererList; std::list > zombieNodeList; Camera *activeCamera; Camera *defaultCamera; std::list > nodeList; //List of all nodes in scene std::vector > refObject3dList; //List of all object3d s in scene std::vector > refCameraList; //List of all cameras std::vector > refSoundList; //List of soundNodes std::list > particleList; //List of all Particles in Scene std::list > soundNodeList; //List of all SoundNodes in Scene void deleteNodeInList(Node* node, std::list > &list); //Sun Stuff Vector sunDirection; D3DLIGHT9 d3dLight; //TriggerStuff float sceneLifeTime; std::vector > triggerList; virtual void executeTrigger(SPTR trigger); //Physic Stuff NxUserContactReport *contactReport; NxUserTriggerReport *triggerReport; NxUserNotify *notifyReport; //ParticleSystem Stuff int particleGroupCounter; std::vector > particleGroupVector; //Fading & Postprocessing Stuff IDirect3DTexture9* finalImage; IDirect3DSurface9* finalImageSurface; D3DSURFACE_DESC finalImageDesc; D3DXMATRIX spriteMatrix; LPD3DXMESH quadMesh; bool meshCreated; void createQuadMesh(); struct Vertex { Vertex(float _x, float _y, float _z, float _u, float _v) { x = _x; y = _y; z = _z; u = _u; v = _v; } Vertex(Vector vec, float _u, float _v) { x = vec.x; y = vec.y; z = vec.z; u = _u; v = _v; } float x, y, z, u, v; }; const static DWORD FVF_Flags = D3DFVF_XYZ | D3DFVF_TEX1; RenderPass defaultRenderPass; RenderPass depthRenderPass; RenderPass raytraceRenderPass; SharedResourceTexture* depthTextureResource; LPDIRECT3DSURFACE9 depthSurface; bool needDepthPass; bool needRaytracePass; bool needDistortionPass; IDirect3DTexture9* distortionMap1; IDirect3DTexture9* distortionMap2; IDirect3DTexture9* preDistortionFinal; IDirect3DSurface9* preDistortionFinalSurface; IDirect3DTexture9* screenDistortionMap; IDirect3DSurface9* screenDistortionMapSurface; };