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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
   Copyright (c) 2014 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy of this software
   and associated documentation files (the "Software"), to deal in the Software without restriction,
   including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _SCENE_H_
#define _SCENE_H_

#include "SceneState.h"
#include "Core/Headers/cdigginsAny.h"
#include "Hardware/Platform/Headers/Task.h"

class Sky;
class Light;
class Object3D;
class TerrainDescriptor;

/*All these includes are useful for a scene, so instead of forward declaring the classes, we include the headers
  to make them available in every scene source file. To reduce compile times, forward declare the "Scene" class instead
*/
//Core files
#include "Core/Headers/Kernel.h"
#include "Core/Headers/Application.h"
#include "Graphs/Headers/SceneGraph.h"
#include "Rendering/Camera/Headers/Camera.h"
//Managers
#include "Managers/Headers/LightManager.h"
//Hardware
#include "Hardware/Video/Headers/GFXDevice.h"
#include "Hardware/Input/Headers/InputInterface.h"
//Scene Elements
#include "Environment/Sky/Headers/Sky.h"
#include "Rendering/Lighting/Headers/Light.h"
#include "Rendering/Lighting/Headers/DirectionalLight.h"
#include "Dynamics/Physics/Headers/PXDevice.h"
#include "Dynamics/Entities/Particles/Headers/ParticleEmitter.h"
//GUI
#include "GUI/Headers/GUI.h"
#include "GUI/Headers/GUIElement.h"

///The scene is a resource (to enforce load/unload and setName) and it has a 2 states: one for game information and one for rendering information
class ParticleEmitter;
struct ParticleEmitterDescriptor;
class PhysicsSceneInterface;
class Scene : public Resource{
protected:
    typedef std::stack<FileData, vectorImpl<FileData> > FileDataStack;
#ifdef _DEBUG
    enum DebugLines{
        DEBUG_LINE_RAY_PICK = 0,
        DEBUG_LINE_OBJECT_TO_TARGET = 1,
        DEBUG_LINE_PLACEHOLDER
    };
#endif
public:

    Scene();
    virtual ~Scene();

    SceneGraphNode* addGeometry(SceneNode* const object,const std::string& sgnName = "");
    bool removeGeometry(SceneNode* node);

    /**Begin scene logic loop*/
    virtual void processInput(const U64 deltaTime) = 0;  //<Get all input commands from the user
    virtual void processTasks(const U64 deltaTime); //<Update the scene based on the inputs
    virtual void processGUI(const U64 deltaTime);
    virtual void preRender() {}                     //<Prepare the scene for rendering after the update
    virtual void postRender();                      //<Perform any post rendering operations
    bool idle();                                    //<Scene is rendering, so add intensive tasks here to save CPU cycles
    void onLostFocus();                             //<The application has lost focus
    /**End scene logic loop*/

    /// Update animations, network data, sounds, triggers etc.
    void updateSceneState(const U64 deltaTime);
    /// Override this for Scene specific updates
    virtual void updateSceneStateInternal(const U64 deltaTime)  {}
    inline SceneGraphNode*                 getSkySGN(I32 index)     {if(_skiesSGN.empty()) {return nullptr;} CLAMP<I32>(index,0,(I32)_skiesSGN.size() - 1); return _skiesSGN[index];}
    inline const vectorImpl<Task_ptr>&     getTasks()               {return _tasks;}
    inline SceneState&                     state()                  {return _sceneState;}
    inline SceneRenderState&               renderState()            {return _sceneState.getRenderState();}
    inline SceneGraph*					   getSceneGraph()	        {return _sceneGraph;}

           void clearTasks();
           void removeTask(Task_ptr taskItem);
           void removeTask(U32 guid);
           void addTask(Task_ptr taskItem);
    inline void addModel(FileData& model)              {_modelDataArray.push(model);}
    inline void addTerrain(TerrainDescriptor* ter)     {_terrainInfoArray.push_back(ter);}
           void addPatch(vectorImpl<FileData>& data);
           SceneGraphNode* addLight(Light* const lightItem, SceneGraphNode* const parentNode = nullptr);

    inline void cacheResolution(const vec2<U16>& newResolution) {
        _sceneState.getRenderState()._cachedResolution = newResolution;
    }

    ///Object picking
    void findSelection(F32 mouseX, F32 mouseY);
    void deleteSelection();

    ///call this function if you want to use a more complex rendering callback other than "SceneGraph::render()"
    void renderCallback(const DELEGATE_CBK& renderCallback) {_renderCallback = renderCallback;}
    const DELEGATE_CBK& renderCallback() {return _renderCallback;}

    ///Override this if you need a custom physics implementation (idle,update,process,etc)
    virtual PhysicsSceneInterface* createPhysicsImplementation();

    ParticleEmitter* addParticleEmitter(const std::string& name, const ParticleEmitterDescriptor& descriptor);
    ParticleEmitter* getParticleEmitter(const std::string& name);

    TerrainDescriptor* getTerrainInfo(const std::string& terrainName);
    inline vectorImpl<FileData>& getVegetationDataArray() { return _vegetationDataArray; }

protected:
    ///Global info
    GFXDevice&     _GFX;
    GUI*           _GUI;
    ParamHandler&  _paramHandler;
    SceneGraph*    _sceneGraph;
    
    PhysicsSceneInterface*         _physicsInterface;
    vectorImpl<D32>                _taskTimers;
    vectorImpl<D32>                _guiTimers;
    ///Datablocks for models,vegetation,terrains,tasks etc
    FileDataStack                  _modelDataArray;
    vectorImpl<FileData>           _vegetationDataArray;
    vectorImpl<TerrainDescriptor*> _terrainInfoArray;
    F32                            _LRSpeedFactor;
    ///Current selection
    SceneGraphNode* _currentSelection;

    ///This is the rendering function used to override the default one for the renderer.
    ///If this is empty, the renderer will use the scene's scenegraph render function
    DELEGATE_CBK _renderCallback;

    ///Scene::load must be called by every scene. Add a load flag to make sure!
    bool _loadComplete;
    ///Schedule a scene graph parse with the physics engine to recreate/recheck the collision meshes used by each node
    bool _cookCollisionMeshesScheduled;
    ///_aiTask is the thread handling the AIManager. It is started before each scene's "initializeAI" is called
    ///It is destroyed after each scene's "deinitializeAI" is called
    std::shared_ptr<Task>  _aiTask;

    typedef Unordered_map<std::string, ParticleEmitter *> ParticleEmitterMap;
    ParticleEmitterMap _particleEmitters;

private:
    vectorImpl<Task_ptr> _tasks;
    ///Contains all game related info for the scene (wind speed, visibility ranges, etc)
    SceneState       _sceneState;
    vectorImpl<SceneGraphNode* >   _skiesSGN;///<Add multiple skies that you can toggle through

protected:

    friend class SceneManager;
    /**Begin loading and unloading logic*/
    virtual bool preLoad();
    ///Description in SceneManager
    virtual bool loadResources(bool continueOnErrors)  {return true;}
    virtual bool loadTasks(bool continueOnErrors)      {return true;}
    virtual bool loadPhysics(bool continueOnErrors);
    ///if singleStep is true, only the first model from the modelArray will be loaded. 
    ///Useful for loading one model per frame
    virtual void loadXMLAssets(bool singleStep = false);
    virtual bool load(const std::string& name, CameraManager* const cameraMgr, GUI* const guiInterface);
            bool loadModel(const FileData& data);
            bool loadGeometry(const FileData& data);
    virtual bool unload();
    ///Description in SceneManager
    virtual bool initializeAI(bool continueOnErrors);
    ///Description in SceneManager
    virtual bool deinitializeAI(bool continueOnErrors);
    ///Check if Scene::load() was called
    bool checkLoadFlag() const {return _loadComplete;}
    ///Unload scenegraph
    void clearObjects();
    ///Destroy lights
    void clearLights();
    ///Destroy physics (:D)
    void clearPhysics();
    /**End loading and unloading logic*/
    ///This is a camera listener. Do not call directly.
    void onCameraChange();
    /// returns true if the camera was moved/rotated/etc
    bool updateCameraControls();

    Sky*               addDefaultSky();
    DirectionalLight*  addDefaultLight();
    
    ///simple function to load the scene elements.
    inline bool SCENE_LOAD(const std::string& name, CameraManager* const cameraMgr, GUI* const gui, const bool contOnErrorRes, const bool contOnErrorTasks){
        if(!Scene::load(name,cameraMgr,gui)) {
            ERROR_FN(Locale::get("ERROR_SCENE_LOAD"), "scene load function");
            return false;
        }
        if(!loadResources(contOnErrorRes)){
            ERROR_FN(Locale::get("ERROR_SCENE_LOAD"), "scene load resources");
            if(!contOnErrorRes) return false;
        }
        if(!loadTasks(contOnErrorTasks)){
            ERROR_FN(Locale::get("ERROR_SCENE_LOAD"), "scene load tasks");
            if(!contOnErrorTasks) return false;
        }
        if(!loadPhysics(contOnErrorTasks)){
            ERROR_FN(Locale::get("ERROR_SCENE_LOAD"), "scene load physics");
            if(!contOnErrorTasks) return false;
        }
        return true;
    }

    void defaultCameraKeys(OIS::KeyCode code, bool upState);

public: //Input
    virtual bool onKeyDown(const OIS::KeyEvent& key);
    virtual bool onKeyUp(const OIS::KeyEvent& key);
    virtual bool onJoystickMoveAxis(const OIS::JoyStickEvent& key,I8 axis,I32 deadZone);
    virtual bool onJoystickMovePOV(const OIS::JoyStickEvent& key, I8 pov);
    virtual bool onJoystickButtonDown(const OIS::JoyStickEvent& key,I8 button){ return true;}
    virtual bool onJoystickButtonUp(const OIS::JoyStickEvent& key, I8 button) { return true; }
    virtual bool sliderMoved( const OIS::JoyStickEvent &arg, I8 index) { return true; }
    virtual bool vector3Moved( const OIS::JoyStickEvent &arg, I8 index){ return true; }
    virtual bool onMouseMove(const OIS::MouseEvent& key);
    virtual bool onMouseClickDown(const OIS::MouseEvent& key,OIS::MouseButtonID button);
    virtual bool onMouseClickUp(const OIS::MouseEvent& key,OIS::MouseButtonID button);

protected: //Input
    vec2<F32> _previousMousePos;
    bool _mousePressed[8];
#ifdef _DEBUG
    vectorImpl<Line > _lines[DEBUG_LINE_PLACEHOLDER];
#endif
};

///usage: REGISTER_SCENE(A,B) where: - A is the scene's class name
///									  -B is the name used to refer to that scene in the XML files
///Call this function after each scene declaration
#define REGISTER_SCENE_W_NAME(scene, sceneName) bool scene ## _registered = SceneManager::getOrCreateInstance().registerScene<scene>(#sceneName);
///same as REGISTER_SCENE(A,B) but in this case the scene's name in XML must be the same as the class name
#define REGISTER_SCENE(scene) bool scene ## _registered = SceneManager::getOrCreateInstance().registerScene<scene>(#scene);

#endif

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

Diff revisions: vs.
Revision Author Commited Message
286 Diff Diff IonutCava picture IonutCava Fri 18 Jul, 2014 16:32:03 +0000

[Ionut] [[BR]]

    • very buggy commit ** [[BR]]

- New rendering pipeline: [[BR]]
— Bumped OpenGL version to 4.4 [[BR]]
— Command based rendering. GFXDevice dispatches rendering commands to their respective buffers [[BR]]
— State changing is exclusively controlled by the GFXDevice class [[BR]]
— Material properties and transform matrices are stored in shader storage buffers that are updated after culling and uploaded once per RenderPass. Objects use drawIDs to index data in shaders [[BR]]
— Removed all custom matrices and other, per shader, bind data [[BR]]
— Removed per node light data. Light culling and shader buffers will replace the old light management system [[BR]]
— Framebuffers now use the Texture class for attachments [[BR]]
— Sampler objects now work like RenderStateBlocks. GL_API handles them and stores them in a hash indexed map [[BR]]
— Removed “prepareMaterial” calls. Pre-draw material setup is now only limited to texture binding [[BR]]
— Moved immediate mode emulation and primitive rendering from API level to GFXDevice level [[BR]]
— Framebuffer rendering must be completed with a call to end() to ensure proper MSAA resolve (asserts, otherwise) [[BR]]
- Fixed hash code generation for RenderStateBlock (and now, glSamplerObject) using boost::hash_combine [[BR]]
- Temporarily disabled XML caching for materials [[BR]]

264 Diff Diff k1ngp1n picture k1ngp1n Tue 27 May, 2014 13:04:38 +0000

[Ionut] [[BR]]
- New camera system: [[BR]]
— Stack based (push/pop active camera) [[BR]]
— Per camera frustum [[BR]]
— Per camera projection [[BR]]
— Shadow mapping now uses the new camera system (each light has a shadow camera) [[BR]]
[[BR]]
- New terrain, water and vegetation system: [[BR]]
— Direct import of terrain from L3DT both as 8-bit grayscale and 16-bit raw formats [[BR]]
— Multiple alpha maps for texture splatting support [[BR]]
— Per texture detail map support [[BR]]
— Transform feedback based visibility culling for vegetation [[BR]]
— Alpha-map based vegetation placing on terrain [[BR]]
— Water now uses a refraction map instead of alpha blending for better refraction effects [[BR]]
[[BR]]
- SceneGraph improvements: [[BR]]
— Better bounding box updates from child to parent [[BR]]
— Better onDraw / postDraw implementation [[BR]]
[[BR]]
- Performance improvements: [[BR]]
— Batch 2D rendering tasks together as much as possible[[BR]]
— Improve renderStateBlock hash generation for better sorting [[BR]]
— Move most state related gfx changes from API implementation to the GFXDevice class [[BR]]
— Move viewport stack to the GFXDevice class [[BR]]
— Added various performance counters (frame duration with round-robin query system, draw call count, etc) [[BR]]
— Fixed and improved clip plane management [[BR]]
— Delete client-side texture data after GPU upload [[BR]]
[[BR]]
- New features: [[BR]]
— Added callback support to the Task class so that a specific task may call a function in the main thread upon completion [[BR]]
— Added mouse-wheel zoom support to Orbit/ThirdPerson cameras [[BR]]
— Added 2D Texture Array support (e.g. used for terrain textures) [[BR]]

262 Diff Diff k1ngp1n picture k1ngp1n Tue 06 May, 2014 21:04:00 +0000

[Ionut] [[BR]]
- Some AI refactoring (basic AIEntity <-> AESOP interoperability) [[BR]]
- Some render batch sorting code refactored and fixed (wasn’t properly sorted in FINAL_STAGE) [[BR]]
- Simplified RenderStateBlockDescriptor and deferred hash value calculation [[BR]]
- Basic draw call count implementation [[BR]]
- Renamed some classes [[BR]]

260 Diff Diff k1ngp1n picture k1ngp1n Sat 03 May, 2014 19:33:41 +0000

[Ionut] [[BR]]
- More work on CSM. Reverted back to VSM to allow easier blurring and filtering [[BR]]
- Rewrote FrameBuffer classes to fix MSAA and memory leaks that occurred on resize (double creation of textures) [[BR]]
— Removed FBType. FrameBuffer types depend only on attachment types and if it’s MSAA enabled or not [[BR]]
- Rewrote RenderState classes to be API agnostic [[BR]]
- Bug fixes in math classes [[BR]]
- Changed “resolution change” logic [[BR]]
- Simplified some options in config.xml [[BR]]
- Improved per-light shadow options [[BR]]

259 Diff Diff k1ngp1n picture k1ngp1n Sun 27 Apr, 2014 18:24:52 +0000

[Ionut][[BR]]
- Implemented Exponential Stable Cascaded Shadow Maps for directional lights (still buggy, but basically working) [[BR]]
— CSM settings (resolution, number of splits, etc) are part of the scene render state [[BR]]
- SGN can skip rendering for the current frame if they are not ready (e.g. OnDraw can now return false or materials can fail to bind) [[BR]]
- Frustum class is now using the Plane class [[BR]]
- Removed Math SIMD implementation as the compiler generated code will always be faster and safer [[BR]]
- Added a “STUBBED” macro for outputing to the error stream of important messages (instead of using #pragma message) [[BR]]
- Added “freeze time” logic to pause/resume updates with or without freezing the GUI too [[BR]]
- Added “processGUI” method the every Scene class to separate time-sensitive GUI updates from game logic loop [[BR]]
- GLSL <-> Vertex Buffer bind locations are automatically set for every vertex shader [[BR]]
- Added basic support for compute shaders [[BR]]
- Removed most OS define checks to make porting to a new platform easier [[BR]]
- Texture transparency check per-pixel is now using OpenMP [[BR]]
- Texture samplers can now set a border color for CLAMP_TO_BORDER wrap mode [[BR]]
- Removed “Object” suffix from GFX Classes (pixel buffer, vertex buffer, frame buffer, etc) [[BR]]
- Stop processing scene input when application looses focus [[BR]]
- SceneGraphNode class is now responsible for updating SGNComponents on draw and calling its _node’s OnDraw method [[BR]]
- UBOs can now list all of the active uniforms inside a block with info such as type and offset [[BR]]
- Removed deprecated ‘GLCheck’ macro [[BR]]
- A lot of bug fixes and performance improvements in various places [[BR]]

258 Diff Diff k1ngp1n picture k1ngp1n Tue 15 Apr, 2014 15:26:22 +0000

[Ionut]
- Bumped minimum OpenGL required version to 4.3 (any Fermi and GCN 1.1 GPU)
- Fixed an issue with opacity maps
- Improved loading times by optimizing console output system and various optimizations in DVDConverter
- Create GUIConsole when needed (not on load)
- Moved common control code to the Scene class

254 Diff Diff k1ngp1n picture k1ngp1n Wed 09 Apr, 2014 15:25:42 +0000

[Ionut] [[BR]]
- Fixed a bug from previous commit with stringstream clearing [[BR]]
- Extended the SceneGraphNode component system to include navigation and physics components [[BR]]
- Code cleanups [[BR]]

251 Diff Diff k1ngp1n picture k1ngp1n Wed 02 Apr, 2014 20:38:18 +0000

[Ionut] [[BR]]

  • Divide is now a 64bit statically linked application * [[BR]]

- Updated to a Visual Studio 2013 solution for better C++11 support [[BR]]
— Recompiled all projects with platform toolset v120 [[BR]]
- Recompiled all projects as x64 – MT / MTd (from x86 – MD / MDd) [[BR]]
- Updated PhysX to 3.3 [[BR]]
- Updated GLFW to 3.0.4 [[BR]]

250 Diff Diff k1ngp1n picture k1ngp1n Wed 02 Apr, 2014 12:36:36 +0000

[Ionut] [[BR]]
- More C++11 work [[BR]]
- Renamed “for_each” macro to “FOR_EACH” to avoid name conflicts with the C++11 function [[BR]]

249 k1ngp1n picture k1ngp1n Mon 31 Mar, 2014 20:42:31 +0000

[Ionut] [[BR]]
- Migrated to platform toolset v100 [[BR]]
- Updated boost to 1.55 [[BR]]
- Moved from “NULL” to “nullptr” [[BR]]
- DevIL is now linked dynamically [[BR]]