Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*�Copyright 2009-2012 DIVIDE-Studio�*/
/* This file is part of DIVIDE Framework.

   DIVIDE Framework is free software: you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   DIVIDE Framework is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public License
   along with DIVIDE Framework.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _SCENE_H
#define _SCENE_H

#include "core.h"
#include "Graphs/Headers/SceneGraph.h"
#include "Hardware/Input/InputManager.h"
#include "Utility/Headers/Event.h"
#include "Hardware/Video/GFXDevice.h"
#include "Hardware/Audio/SFXDevice.h"
#include "Core/Headers/ParamHandler.h"
#include "Rendering/Lighting/Headers/Light.h"
#include "Managers/Headers/LightManager.h"
#include "Core/Resources/Headers/ResourceCache.h"

typedef std::tr1::shared_ptr<Event> Event_ptr;
typedef unordered_map<std::string, Object3D*> Name_Object_map;
class SceneGraph;
class Light;

class TerrainDescriptor;
class Scene : public Resource{

public:
	Scene() :  Resource(),
	  _GFX(GFX_DEVICE),
	  _paramHandler(ParamHandler::getInstance()),
	  _drawBB(false),
	  _drawSkeletons(false),
	  _drawObjects(true),
	  _lightTexture(NULL),
	  _deferredBuffer(NULL),
	  _deferredShader(NULL),
	  _camera(NULL),
	  _inputManager(InputManagerInterface::getInstance()),
	  _sceneGraph(New SceneGraph())
	  {
		  _white = vec4<F32>(1.0f,1.0f,1.0f,1.0f);
		  _black = vec4<F32>(0.0f,0.0f,0.0f,0.0f);
		  _moveFB = 0.0f;
	      _moveLR = 0.0f;
		  _angleUD = 0.0f;
		  _angleLR = 0.0f;
	  };

	virtual ~Scene() {
		
	};
	SceneGraphNode* addGeometry(Object3D* const object);
	bool removeGeometry(SceneNode* node);

	virtual bool unload();
	virtual void render() = 0;
	virtual void preRender() = 0;
	virtual bool load(const std::string& name);
	
	virtual void processInput();
	virtual void processEvents(F32 time) = 0;

	/// Update animations, network data, sounds, triggers etc.
	virtual void updateSceneState(D32 sceneTime);
	/// Update current camera (simple, fast, inlined poitner swap)
	inline void updateCamera(Camera* const camera) {_camera = camera;}

	inline F32&  getWindSpeed()         {return _windSpeed;}
	inline F32&  getWindDirX()          {return _windDirX;}
	inline F32&  getWindDirZ()          {return _windDirZ;}
	inline F32&  getGrassVisibility()	{return _grassVisibility;}
	inline F32&  getTreeVisibility()	{return _treeVisibility;}
	inline F32&  getGeneralVisibility()	{return _generalVisibility;}
	inline F32&  getWaterLevel()        {return _waterHeight;}
	inline F32&  getWaterDepth()        {return _waterDepth;}

   
   inline U32 getNumberOfTerrains(){return TerrainInfoArray.size();}
   inline std::vector<TerrainDescriptor*>& getTerrainInfoArray() {return TerrainInfoArray;}
   inline ShaderProgram*                   getDeferredShaders() {return _deferredShader;}
   
   inline std::vector<FileData>& getModelDataArray() {return ModelDataArray;}
   inline std::vector<FileData>& getVegetationDataArray() {return VegetationDataArray;}

   inline std::vector<Event_ptr>& getEvents() {return _events;}

   inline SceneGraph* getSceneGraph()	{return _sceneGraph;}
   inline void   addEvent(Event_ptr eventItem) {_events.push_back(eventItem);}

   inline void addModel(FileData& model) {ModelDataArray.push_back(model);}
   inline void addTerrain(TerrainDescriptor* ter) {TerrainInfoArray.push_back(ter);}
   void addPatch(std::vector<FileData>& data);
   void addLight(Light* const lightItem);
   bool clean();

   inline bool drawBBox() {return _drawBB;}
   inline void drawBBox(bool visibility) {_drawBB = visibility;}
   inline bool drawSkeletons() {return  _drawSkeletons;}
   inline void drawSkeletons(bool visibility) {_drawSkeletons = visibility;}
   inline bool drawObjects() {return _drawObjects;}
   inline void drawObjects(bool visibility) {_drawObjects=visibility;}

protected:

	GFXDevice& _GFX;
	ParamHandler& _paramHandler;

	/*Name_Object_map GeometryArray;
	Name_Object_map::iterator GeometryIterator;*/

	///Datablocks for models,vegetation and terrains
	std::vector<FileData>           ModelDataArray;
	std::vector<FileData>           VegetationDataArray;
	std::vector<FileData>           PendingDataArray;
	std::vector<TerrainDescriptor*> TerrainInfoArray;
	
	std::vector<F32> _eventTimers;

	bool _drawBB,_drawObjects, _drawSkeletons;
	boost::mutex _mutex;

	vec4<F32> _white, _black;
	InputManagerInterface& _inputManager;

	///Deferred rendering
	FrameBufferObject* _deferredBuffer;
	PixelBufferObject* _lightTexture;
	ShaderProgram*	   _deferredShader;

	///Global info
	Camera*            _camera;
	SceneGraph*        _sceneGraph;
	F32			       _grassVisibility,_treeVisibility,_generalVisibility,
				 	   _windSpeed,_windDirX, _windDirZ, _waterHeight, _waterDepth;
	F32 _moveFB;  ///< forward-back move change detected
	F32 _moveLR;  ///< left-right move change detected
	F32 _angleUD; ///< up-down angle change detected
	F32 _angleLR; ///< left-right angle change detected

private: 
	std::vector<Event_ptr> _events;
	Event_ptr _inputEvent;
	Event_ptr _aiEvent;

protected:

	friend class SceneManager;
	///Description in SceneManager
	virtual bool initializeAI(bool continueOnErrors)   {return true;}
	///Description in SceneManager
	virtual bool deinitializeAI(bool continueOnErrors) {return true;}
	///Description in SceneManager
	virtual bool loadResources(bool continueOnErrors)  {return true;}
	virtual bool loadEvents(bool continueOnErrors);
	virtual void setInitialData();
	void clearEvents();
	void clearObjects();
	void clearLights();
	bool loadModel(const FileData& data);
	bool loadGeometry(const FileData& data);
	Light* addDefaultLight();

public: //Input
	virtual void onKeyDown(const OIS::KeyEvent& key);
	virtual void onKeyUp(const OIS::KeyEvent& key);
	virtual void OnJoystickMoveAxis(const OIS::JoyStickEvent& key,I8 axis);
	virtual void OnJoystickMovePOV(const OIS::JoyStickEvent& key,I8 pov){}
	virtual void OnJoystickButtonDown(const OIS::JoyStickEvent& key,I8 button){}
	virtual void OnJoystickButtonUp(const OIS::JoyStickEvent& key, I8 button){}
	virtual void onMouseMove(const OIS::MouseEvent& key);
	virtual void onMouseClickDown(const OIS::MouseEvent& key,OIS::MouseButtonID button);
	virtual void onMouseClickUp(const OIS::MouseEvent& key,OIS::MouseButtonID button);
};

#endif

Commits for Divide-Framework/trunk/Source Code/Scenes/Headers/Scene.h

Diff revisions: vs.
Revision Author Commited Message
117 Diff Diff k1ngp1n picture k1ngp1n Tue 05 Jun, 2012 17:30:40 +0000

[Ionut] [[BR]]
-Separated responsibilities between “Application” and “Kernel” [[BR]]
--“Application” handles data such as window dimensions, logs, “ParamHandler” etc [[BR]]
--“Kernel” handles the main loop, SFX, GFX, physics, sceneManager etc updates [[BR]]
---“Kernel” is now a “Core” component [[BR]]
-Reduced coupling between some classes by passing more info via parameters rather than relying on singleton access [[BR]]
--Ex: eyePos in “Terrain”,“Water” and “Trigger” classes is now passed as a "vec3<F32>" on render call rather than querying “CameraManager” [[BR]]
-Reworked “GLWrapper” shutdown routine [[BR]]
Singleton witch hunt [[BR]]
-“Kernel” is no longer a singleton and it’s initialized on application startup in the “Application” class[[BR]]
-“CameraManager” is no longer a singleton and it’s instantiated in the kernel [[BR]]

115 Diff Diff k1ngp1n picture k1ngp1n Sat 02 Jun, 2012 19:25:51 +0000

[Ionut] [[BR]]
-Resource’s should NOT keep track of their ref counts as they are not the only objects that need reference counting [[BR]]
--Moved all ref counting elements to a new super class “TrackObject” [[BR]]
--Removed hackish “createCopy” / “removeCopy” methods and use dependency map instead (registered via macros) [[BR}}
-Added a basic smart pointer implementation that uses TrackObject, but the pointer is not used itself yet [[BR]]

114 Diff Diff k1ngp1n picture k1ngp1n Sat 02 Jun, 2012 13:03:01 +0000

[Ionut][[BR]]
-First steps in moving away from a generalized “ResourceManager”: [[BR]]
--Added templated resource loaders (Core\Resources\ConcreteLoaders). Just add a new loader for a new resource type and it’s ready for use [[BR]]
---Next step involves moving loading responsibility from the resource itself to the resource loader that handles it’s creation [[BR]]
--Renamed the ResourceManager to ResourceCache and limited it’s responsibility from general resource operations to a more standard abstract template factory with cache [[BR]]
---Manager base class is renamed to BaseCache as it’s a wrapper for a cache map in essence [[BR]]
---Next step involves adding a ResourceCache per scene (dropping Singleton status) with the possibility of sharing resources between them (to avoid reloading existing resources for a new scene) [[BR]]
-Translated AITenisScene and PingPongScene source code to english [[BR]]

111 Diff Diff k1ngp1n picture k1ngp1n Tue 08 May, 2012 21:49:31 +0000

[Ionut] [[BR]]
-Added animation support based on Scott Lee’s animation loader library added a few revision’s back [[BR]]
--Added cached skeleton rendering to the library [[BR]]
--Added cached AABB transformations based on current animation frame [[BR]]
--Scene animators are added per submesh and only processed if said submesh is visible and only in the rendering stage: FINAL_STAGE [[BR]]
[[BR]]
-Added support for shader-based VBO data upload (glVertexAttribPointer) with full backwards compatibility to old method (glTexCoordPointer)[[BR]]
-Added support for Index Buffer Object (improper name) indice upload for VBO’s with full backwards compatibility to old method [[BR]]
-Reworked coordination class to better handle AIEntity teams [[BR]]
-Added “updateSceneState(currentTime)” callback that is called once per frame (used for animation update)[[BR]]
-Added “initializeAI/deinitializeAI” scene callbacks for AI creation/destruction [[BR]]
-Templatized the Quaternion class [[BR]]
-Added a “drawLines” subroutine to the rendering api[[BR]]
-Disabled tree loading in MainScene as current ASSIMP implementation is slow. Will be restored after backing and loading models to own format is added in next revision [[BR]]
-Other various small performance tweaks [[BR]]

106 Diff Diff k1ngp1n picture k1ngp1n Wed 28 Mar, 2012 21:50:23 +0000

[Ionut] [[BR]]
Unstable revision – New animation code is not yet optimized and loading performance is low [[BR]]
[[BR]]
-Added animation loading and bone matrix calculations (actual skinning not implemented yet)[[BR]]
-Modified VBO classes to support dynamic data and faster updates [[BR]]
-Templatized Math classes (vec2,vec3,vec4,mat3,mat4) for greater flexibility [[BR]]
-Separated Rendering API from Rendering API version [[BR]]
-Fixed buggy GL error checking [[BR]]
-Small bugs fixed in Projectile and Weapon classes [[BR]]

103 Diff Diff k1ngp1n picture k1ngp1n Mon 12 Mar, 2012 19:06:00 +0000

[Ionut] [[BR]]
Features: [[BR]]
-Added a proper RenderState Management system similar to the D3D default one[[BR]]
--All possible states are managed: cull, blend, alpha-blend, color mask, lighting, stencil mask, fill mode etc [[BR]]
--Every material has different states for normal rendering, shadow rendering and reflection rendering [[BR]]
--Nodes are sorted by shader first then by state hash depending on current render stage [[BR]]
--Redundant states are not changed [[BR]]
--Every entity submits it’s desired state before render [[BR]]
--Every state is checked before rendering a VBO or other primitive type[[BR]]
[[BR]]
-Added a Reflector base class used for reflection calculations and updates (useful for water, mirrors, portals etc)[[BR]]
--Reflections are triggered between pre-render and render calls [[BR]]
--Water now derives from Reflector class as well [[BR]]
[[BR]]
-Material now properly calculates if it has transparency or is double sided, setting desired states to handle this feature (cull, blend) [[BR]]
-Added some basic defines or inline template functions to facilitate access to useful classes and methods (hardware devices, resource management, console printing, etc) [[BR]]
-Lights are updated after every camera update[[BR]]
-Added a new FrameListener event triggered after pre-render call is finished (used by reflectors) [[BR]]
-Added a CRC class to compute unique hash values for entities[[BR]]
-Added D3D dummy files [[BR]]
-Removed executables from subversion [[BR]]
Performance: [[BR]]
-Image loading has been improved a bit [[BR]]
-Terrain texel density now varies with LOD level [[BR]]
-Light API specific calls,except position, are set only if values changed[[BR]]
-Specific GUI casting and rendering are the Rendering API’s job now, not the GUI class [[BR]]
-Rendering Queue processing is now more efficient in sorting valid visible nodes and setting appropriate states/materials
[[BR]]
Bug fixes: [[BR]]
-Better drawState checks[[BR]]
-Proper light effects in deferred rendering[[BR]]
-Light dummy now renders properly[[BR]]
-Reworked bounding box computation [[BR]]
[[BR]]
Known bugs: [[BR]]
-Terrain infinite plain still not visible [[BR]]
-Some z-fighting occurs when looking at certain objects from a distance. (looking at another object and back again fixes it) [[BR]]

101 Diff Diff k1ngp1n picture k1ngp1n Wed 07 Mar, 2012 13:56:56 +0000

[Ionut] [[BR]]
-Added GLSL effect-like file support using GLSW [http://prideout.net/blog/?p=11] [[BR]]
-Added GLSL “#include” support. Now shader functions can be define in separate frag/vert files as atoms and included in the glsl effect file [[BR]]
-Added more DoxyGen-comments[[BR]]

100 Diff Diff k1ngp1n picture k1ngp1n Mon 05 Mar, 2012 17:45:11 +0000

[Ionut] [[BR]]
Features: [[BR]]
-Added a physics system interface instead of direct PhysX interaction to allow other physics engines (Bullet, ODE etc) to be easily implemented [[BR]]
--This will aid in Object-Object collisions and character control in future revisions [[BR]]
-Added an Ogre3D inspired FrameListener which now allows Before-frame/during-frame/after-frame event plugins of callbacks [[BR]]
-Added a renderInViewport system to draw elements in a user defined rectangle on screen [[BR]]
--Current uses: shadowmap preview (F10) [[BR]]
-Separated Shaders from ShaderPrograms[[BR]]
--ShaderPrograms can now use multiple Shaders [[BR]]
-Error output is now sent to errors.log[[BR]]
-All SceneNode based elements now have a postDraw calls as well [[BR]]
-A cubemap generating function has been added to the GFXDevice class[[BR]]
-Added debug only print options to the Console class [[BR]]
[[BR]]
Performance: [[BR]]
-All shadows are now filtered by a faster Gaussian 3x3 blur filter [[BR]]
-All renderables are now sorted and rendered by material/front-to-back/back-to-front, depending on case [[BR]]
-RenderQueue now sorts and queue’s translucent and opaque objects separately[[BR]]
-Shader uniforms/attributes are now cached to reduce number of address calls to the GPU[[BR]]
-Shaders are now cached, so that if multiple ShaderPrograms use an already compiled Shader, that Shader is returned from memory instead of creating a new copy[[BR]]
-Shaders are not unbound/rebound except when an objects demands so (vastly improves performance)[[BR]]
-Reduced calls to glEnable[[BR]]
[[BR]]
Bug fixes: [[BR]]
-Preprocessor configurations now work properly [[BR]]
-Video API is now unloaded before destruction [[BR]]
-Manager base class now properly frees memory [[BR]]
-Materials are saved to XML only if they are changed at any point [[BR]]

97 k1ngp1n picture k1ngp1n Tue 07 Feb, 2012 15:23:45 +0000

[ Ionut ] [[BR]]
-Restructured code base to a more logical layout [[BR]]
--Geometry folder contains shapes, materials, animations and the importer; Environment folder holds sky, terrain, water, vegetation; etc [[BR]]
--All header files are moved to a “Headers” sub-folder [[BR]]
--Renamed most of the Romanian code/comments/files/folders to English [[BR]]
--Added comments to parts of the code (ongoing from now on) [[BR]]
[[BR]]
-Rewrote the entire lighting system [[BR]]
--Added a LightManager class to handle all lights [[BR]]
---LightManager calls updates and render calls to all lights it manages [[BR]]
--Lights have all needed properties stored in 2 maps (one for vector values, one for float values) [[BR]]
--Added a LightImpostor class that takes the light’s properties and applies it to a dummy sphere [[BR]]
--If a light should draw it’s impostor, the impostor draws the dummy sphere [[BR]]
--Rewrote the Light <-> GFXDevice interaction [[BR]]
---Each light stores it’s type in a variable and passes all properties to the rendering API that then decides what to use based on that type [[BR]]
--Each light handles it’s own ShadowMapping [[BR]]
[[BR]]
-ShadowMapping: [[BR]]
-Each light stores it’s own depth maps and generates them based on it’s type [[BR]]
-LightManager binds all available depth maps and shaders pick them up automatically for use [[BR]]
-Each shadow map (of a total of 3 per light) corresponds to a detail level[[BR]]
-The final shadow map resolution is decided by the shadow detail level set in the config [[BR]]
--Camera and Frustum are set up for shadow rendering and applied to the render callback set for the current light (for example, Scene::render()) [[BR]]
--The light manager tells every light that has “_castShadows = true” to generate shadowmaps automatically after the Scene::PreRender stage [[BR]]
--ShadowMaps are blurred before applied to the fragment’s final color via shaders. [[BR]]
[[BR]]
-Added detail level configuration options [[BR]]
--ToDo: add shaders for each detail level [[BR]]
[[BR]]
-Moved all predefined geometry from immediate mode to VBO’s [[BR]]
--This allowed the rendering pipeline to be more streamlined (one render function for all geometry) [[BR]]
[[BR]]
-Fixed GuiElement visibility toggle [[BR]]
-Fixed GuiText color state problem [[BR]]
-Added FBO texture format options [[BR]]
-VBO rendering uses U16 as default instead of U32 (better for GPU) [[BR]]
-VBO’s now contain BiTangent data as well [[BR]]
-Added OpenGL 2.0 compatibility (not guaranteed!) [[BR]]
-Added static (on load) shader selection based on detail level [[BR]]
-Added SSAO PostFX option, but this won’t work until the implementation of “plugins” for PostFX system [[BR]]
-Optimized/Fixed code based on VisualLint + CppCheck analysis [[BR]]