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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/*
   Copyright (c) 2016 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_STATE_H_
#define _SCENE_STATE_H_

#include "Managers/Headers/CameraManager.h"
#include "Platform/Audio/Headers/SFXDevice.h"
#include "Platform/Video/Headers/RenderAPIEnums.h"
#include "Platform/Audio/Headers/AudioDescriptor.h"
#include "Core/Resources/Headers/ResourceCache.h"
#include "Core/Headers/Console.h"
#include "Scenes/Headers/SceneComponent.h"
#include "Utility/Headers/Localization.h"

/// This class contains all the variables that define each scene's
/// "unique"-ness:
/// background music, wind information, visibility settings, camera movement,
/// BB and Skeleton visibility, fog info, etc

/// Fog information (fog is so game specific, that it belongs in SceneState not
/// SceneRenderState

namespace Divide {

struct FogDescriptor {
    F32 _fogDensity;
    vec3<F32> _fogColour;
};

class Scene;
class LightPool;
class RenderPass;
namespace Attorney {
    class SceneRenderStateScene;
    class SceneStateScene;
    class SceneRenderStateLightPool;
    class SceneRenderStateRenderPass;
};

/// Contains all the information needed to render the scene: camera position,
/// render state, etc
class SceneRenderState : public SceneComponent {
    friend class Attorney::SceneRenderStateScene;
    friend class Attorney::SceneRenderStateLightPool;
    friend class Attorney::SceneRenderStateRenderPass;

   public:
    enum class GizmoState : U32 {
        NO_GIZMO = toBit(1),
        SCENE_GIZMO = toBit(2),
        SELECTED_GIZMO = toBit(3),
        ALL_GIZMO = SCENE_GIZMO | SELECTED_GIZMO,
        COUNT = 4
    };

    explicit SceneRenderState(Scene& parentScene);

    /// Render wireframe for all scene geometry
    void toggleWireframe();
    /// Render skeletons for animated geometry
    void toggleSkeletons();
    /// Show/hide bounding boxes and/or objects
    void toggleBoundingBoxes();
    /// Show/hide axis gizmos
    void toggleAxisLines();
    /// Show/hide debug lines
    void toggleDebugLines();
    /// Show/hide geometry
    void toggleGeometry();


    inline void drawGeometry(bool state) {
        _drawGeometry = state;
    }

    inline bool drawGeometry() const {
        return _drawGeometry;
    }

    inline void drawSkeletons(bool state) {
        _drawSkeletons = state;
    }

    inline bool drawSkeletons() const {
        return _drawSkeletons;
    }

    inline void drawBoundingBoxes(bool state) {
        _drawBoundingBoxes = state;
    }

    inline bool drawBoundingBoxes() const {
        return _drawBoundingBoxes;
    }

    inline void drawWireframe(bool state) {
        _drawWireframe = state;
    }

    inline bool drawWireframe() const {
        return _drawWireframe;
    }

    inline void drawDebugLines(bool visibility) {
        _debugDrawLines = visibility;
    }

    inline bool drawDebugLines() const {
        return _debugDrawLines;
    }

    inline void drawDebugTargetLines(bool visibility) {
        _debugDrawTargetLines = visibility;
    }

    inline bool drawDebugTargetLines() const {
        return _debugDrawTargetLines;
    }

    inline void drawOctreeRegions(bool visibility) {
        _drawOctreeRegions = visibility;
    }

    inline bool drawOctreeRegions() const {
        return _drawOctreeRegions;
    }

    inline void gizmoState(GizmoState newState) {
        _gizmoState = newState;
    }


    inline I32 currentShadowLightIndex() {
        return _currentShadowLightIndex;
    }

    inline I32 currentReflectorIndex() {
        return _currentReflectorIndex;
    }

    inline GizmoState gizmoState() const {
        return _gizmoState;
    }

    inline CameraManager& getCameraMgr() {
        return *_cameraMgr;
    }

    inline Camera& getCamera() {
        return _cameraMgr->getActiveCamera();
    }

    inline const Camera& getCameraConst() const {
        return _cameraMgr->getActiveCamera();
    }

    inline bool playAnimations() const {
        return _playAnimations;
    }

   protected:

    inline void playAnimations(bool state) { 
        _playAnimations = state; 
    }

    inline void currentShadowLightIndex(I32 idx) {
        _currentShadowLightIndex = idx;
    }

    inline void currentReflectorIndex(I32 idx) {
        _currentReflectorIndex = idx;
    }
   protected:
    bool _drawBB;
    bool _debugDrawLines;
    bool _debugDrawTargetLines;
    bool _playAnimations;

    bool _drawGeometry;
    bool _drawSkeletons;
    bool _drawBoundingBoxes;
    bool _drawWireframe;
    bool _drawOctreeRegions;

    I32 _currentShadowLightIndex;
    I32 _currentReflectorIndex;

    GizmoState _gizmoState;
    CameraManager* _cameraMgr;
};

class SceneState : public SceneComponent {
    friend class Attorney::SceneStateScene;
   public:
       enum class MoveDirection : I32 {
           NONE = 0,
           NEGATIVE = -1,
           POSITIVE = 1
       };

   public:
    /// Background music map : trackName - track
    typedef hashMapImpl<ULL, std::shared_ptr<AudioDescriptor>> MusicPlaylist;

    SceneState(Scene& parentScene)
        : SceneComponent(parentScene),
          _renderState(parentScene),
          _cameraUnderwater(false), 
          _cameraUpdated(false),
          _cameraLockedToMouse(false),
          _saveLoadDisabled(false)
    {
        resetMovement();
        _fog._fogColour = vec3<F32>(0.2f, 0.2f, 0.2f);
        _fog._fogDensity = 0.01f;
    }

    virtual ~SceneState()
    {
        _backgroundMusic.clear();
    }

    inline void resetMovement() {
        _moveFB = _moveLR = _angleUD = _angleLR = _roll = MoveDirection::NONE;
        _mouseXDelta = _mouseYDelta = 0;
    }

    inline FogDescriptor& fogDescriptor()   { return _fog; }
    inline SceneRenderState& renderState()  { return _renderState; }
    inline MusicPlaylist& backgroundMusic() { return _backgroundMusic; }

    inline const FogDescriptor& fogDescriptor() const { return _fog; }
    inline const SceneRenderState& renderState() const { return _renderState; }
    inline const MusicPlaylist& backgroundMusic() const { return _backgroundMusic; }

    inline void windSpeed(F32 speed) { _windSpeed = speed; }
    inline F32  windSpeed()    const { return _windSpeed; }

    inline void windDirX(F32 factor) { _windDirX = factor; }
    inline F32  windDirX()     const { return _windDirX; }

    inline void windDirZ(F32 factor) { _windDirZ = factor; }
    inline F32  windDirZ()     const { return _windDirZ; }

    inline void grassVisibility(F32 distance) { _grassVisibility = distance; }
    inline F32  grassVisibility()       const { return _grassVisibility; }

    inline void treeVisibility(F32 distance) { _treeVisibility = distance; }
    inline F32  treeVisibility()       const { return _treeVisibility; }

    inline void generalVisibility(F32 distance) { _generalVisibility = distance; }
    inline F32  generalVisibility()       const { return _generalVisibility; }

    inline void waterLevel(F32 level) { _waterHeight = level; }
    inline F32  waterLevel()    const { return _waterHeight; }

    inline void waterDepth(F32 depth) { _waterDepth = depth; }
    inline F32  waterDepth()    const { return _waterDepth; }

    inline void cameraUnderwater(bool state) { _cameraUnderwater = state; }
    inline bool cameraUnderwater()     const { return _cameraUnderwater; }

    inline void cameraUpdated(bool state) { _cameraUpdated = state; }
    inline bool cameraUpdated()     const { return _cameraUpdated; }

    inline void moveFB(MoveDirection factor) { _moveFB = factor; }
    inline MoveDirection  moveFB()     const { return _moveFB; }

    inline void moveLR(MoveDirection factor) { _moveLR = factor; }
    inline MoveDirection  moveLR()     const { return _moveLR; }

    inline void angleUD(MoveDirection factor) { _angleUD = factor; }
    inline MoveDirection  angleUD()     const { return _angleUD; }

    inline void angleLR(MoveDirection factor) { _angleLR = factor; }
    inline MoveDirection  angleLR()     const { return _angleLR; }

    inline void roll(MoveDirection factor) { _roll = factor; }
    inline MoveDirection  roll()     const { return _roll; }

    inline void cameraLockedToMouse(bool state) { _cameraLockedToMouse = state; }
    inline bool cameraLockedToMouse()     const { return _cameraLockedToMouse; }

    inline void mouseXDelta(I32 depth) { _mouseXDelta = depth; }
    inline I32  mouseXDelta()    const { return _mouseXDelta; }

    inline void mouseYDelta(I32 depth) { _mouseYDelta = depth; }
    inline I32  mouseYDelta()    const { return _mouseYDelta; }

    inline void saveLoadDisabled(const bool state) { _saveLoadDisabled = state; }
    inline bool saveLoadDisabled()           const { return _saveLoadDisabled; }

protected:
    MusicPlaylist _backgroundMusic;

    I32 _mouseXDelta;
    I32 _mouseYDelta;
    bool _cameraLockedToMouse;
    bool _saveLoadDisabled;

    MoveDirection _moveFB;   ///< forward-back move change detected
    MoveDirection _moveLR;   ///< left-right move change detected
    MoveDirection _angleUD;  ///< up-down angle change detected
    MoveDirection _angleLR;  ///< left-right angle change detected
    MoveDirection _roll;     ///< roll left or right change detected

    F32 _waterHeight;
    F32 _waterDepth;
    bool _cameraUnderwater;
    // was the camera moved or rotated this frame
    bool _cameraUpdated;  

    FogDescriptor _fog;
    /// saves all the rendering information for the scene
    /// (camera position, light info, draw states)
    SceneRenderState _renderState;
    F32 _grassVisibility;
    F32 _treeVisibility;
    F32 _generalVisibility;
    F32 _windSpeed;
    F32 _windDirX;
    F32 _windDirZ;
};

namespace Attorney {
class SceneRenderStateScene {
   private:
    static void playAnimations(SceneRenderState& sceneRenderState,
                               bool playAnimations) {
        sceneRenderState.playAnimations(playAnimations);
    }
    friend class Divide::Scene;
};

class SceneRenderStateLightPool {
   private:
    static void shadowLightIndex(SceneRenderState& sceneRenderState,
                                 I32 shadowLightIndex) {
        sceneRenderState.currentShadowLightIndex(shadowLightIndex);                                    
    }

    friend class Divide::LightPool;
};

class SceneRenderStateRenderPass {
   private:
    static void reflectorIndex(SceneRenderState& sceneRenderState,
                               I32 reflectorIndex) {
        sceneRenderState.currentReflectorIndex(reflectorIndex);
    }

    friend class Divide::RenderPass;
};

class SceneStateScene {
private:
    friend class Divide::Scene;
};

};  // namespace Attorney

};  // namespace Divide
#endif

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

Diff revisions: vs.
Revision Author Commited Message
727 Diff Diff IonutCava picture IonutCava Tue 14 Jun, 2016 16:01:38 +0000

[IonutCava]
- Remove node and cmd buffers from GFXDevice and add them as a new BufferData struct to RenderPass class.
— Each render pass holds its own buffers
- Improvements / fixes to the CSM code
- Added a global toggle to enable/disable custom memory allocators

721 Diff Diff IonutCava picture IonutCava Wed 08 Jun, 2016 15:47:49 +0000

[IonutCava]
- Spelling: change all references from our code of “color” to the PROPER British version of “colour” because it sounds 100x better

720 Diff Diff IonutCava picture IonutCava Mon 06 Jun, 2016 15:51:06 +0000

[IonutCava]
- PVS-Studio guided static analysis fixes and optimizations
- Added a flag to SceneState to bypass the Save/Load system not needed for certain types of scenes (menus, cinematics, etc)

713 Diff Diff IonutCava picture IonutCava Wed 25 May, 2016 15:43:38 +0000

[IonutCava]
- Removed all unique_ptr’s from the code with classic new/delete pairs. They were seriously not needed.
- Added the concept of SceneComponent to scene specific classes: aiManager, lightPool, sceneGraph, physicsInterface etc
— This allowed the removal of the global GET_ACTIVE_SCENEGRAPH call;

709 Diff Diff IonutCava picture IonutCava Thu 19 May, 2016 16:21:46 +0000

[IonutCava]
- Massive rewrite of the resource system:
— ResourceCache now uses a map of weak pointers and passes shared pointers to the call point of CreateResource
— RemoveResource is no longer needed, but resource based smart pointers use a custom deleter that calls unload()
— Keep a shared_ptr of the resource in the entity that needs it and pass shared_ptr references from getter methods
-— All of this removed the need for calls to RemoveResource, REGISTER_TRACKED_DEPENDENCY and UNREGISTER_TRACKED_DEPENDENCY reducing the number of mutex locks and atomic exchanges
- Singleton cleanup:
— Removed ShaderManager singleton and merged it’s data and responsibilities in static methods in both ShaderProgram and Shader classes.
Explanation: Due to the complex interdependency chains in the system, copying, updating, tracking the cache in a thread safe way became a lot more slower than a straight forward smart pointer based implementation. (e.g. scene graph nodes have 3d objects and material instances, 3d objects have materials, materials have textures and shaders, etc)

705 Diff Diff IonutCava picture IonutCava Thu 12 May, 2016 20:27:20 +0000

[IonutCava]
- Decouple asset loading from the active scene
— completely remove GET_ACTIVE_SCENE() method

699 Diff Diff IonutCava picture IonutCava Tue 10 May, 2016 16:16:57 +0000

[IonutCava]
- Initial key binding code with external XML support
— Allow separation of actions and keys
— Specify actions in code by id
— Specify action id for each Key state
— Allow key modifiers: Left/Right Alt, Left/Right Ctrl

- Initial default scene code

648 Diff Diff IonutCava picture IonutCava Sun 21 Feb, 2016 16:32:52 +0000

[IonutCava]
- Update copyright notice
- Move BoundingBox and BoundingSphere to a new BoundsComponent
— Add a temp hack in SceneGraphNode to update these

635 Diff Diff IonutCava picture IonutCava Thu 28 Jan, 2016 16:52:38 +0000

[IonutCava]
- Fix a transparency bug
- Octree implementation updates (still not 100% functional)
— Moving node update is buggy
- Octree debug preview system

602 IonutCava picture IonutCava Thu 10 Dec, 2015 17:00:04 +0000

[IonutCava]
- Implement view independent positioning of SGNs (think first person weapons)
- Remove isInView checks from SceneNode class and move it to SGN class
— Add support for visibility locking for nodes.
— isInView was overridden by classes that were always in view(e.g. sky, grass, etc). No need for virtual indirections for a few exceptions
- Add checks to avoid redundant state changes in SGN and RenderingComponent classes