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
/*
   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_MANAGER_H
#define _SCENE_MANAGER_H

#include "Scenes/Headers/Scene.h"
#include "Rendering/RenderPass/Headers/RenderPassCuller.h"

namespace Divide {

class LoadSave {
public:
    static bool loadScene(Scene& activeScene);
    static bool saveScene(const Scene& activeScene);
};

enum class RenderStage : U32;
namespace Attorney {
    class SceneManagerKernel;
    class SceneManagerRenderPass;
};

class ScenePool;
class SceneShaderData;
DEFINE_SINGLETON(SceneManager, FrameListener, Input::InputAggregatorInterface)
    friend class Attorney::SceneManagerKernel;
    friend class Attorney::SceneManagerRenderPass;
  public:
    static bool initStaticData();
    static bool destroyStaticData();

    void idle();

    vectorImpl<stringImpl> sceneNameList(bool sorted = true) const;

    Scene& getActiveScene();
    const Scene& getActiveScene() const;

    void setActiveScene(Scene* const scene);

    bool init(GUI* const gui);

    /*Base Scene Operations*/
    Renderer& getRenderer() const;
    void setRenderer(RendererType rendererType);

    // generate a list of nodes to render
    void updateVisibleNodes(RenderStage stage, bool refreshNodeData, U32 pass = 0);
    void renderVisibleNodes(RenderStage stage, bool refreshNodeData, U32 pass = 0);
    // cull the scenegraph against the current view frustum
    const RenderPassCuller::VisibleNodeList& cullSceneGraph(RenderStage stage);
    // get the full list of reflective nodes
    const RenderPassCuller::VisibleNodeList& getSortedReflectiveNodes();
    // get the full list of refractive nodes
    const RenderPassCuller::VisibleNodeList& getSortedRefractiveNodes();

    const RenderPassCuller::VisibleNodeList&
        getSortedCulledNodes(const std::function<bool(const RenderPassCuller::VisibleNode&)>& cullingFunction);

    void onLostFocus();
    /// Check if the scene was loaded properly
    inline bool checkLoadFlag() const {
        return Attorney::SceneManager::checkLoadFlag(getActiveScene());
    }
    /// Update animations, network data, sounds, triggers etc.
    void updateSceneState(const U64 deltaTime);

    /// Gather input events and process them in the current scene
    inline void processInput(const U64 deltaTime) {
        getActiveScene().processInput(deltaTime);
        Attorney::SceneManager::updateCameraControls(getActiveScene());
    }

    inline void processTasks(const U64 deltaTime) {
        getActiveScene().processTasks(deltaTime);
    }
    inline void processGUI(const U64 deltaTime) {
        getActiveScene().processGUI(deltaTime);
    }

    RenderPassCuller::VisibleNodeList& getVisibleNodesCache(RenderStage stage);

    template <typename T, class Factory>
    bool register_new_ptr(Factory& factory, BOOST_DEDUCED_TYPENAME Factory::id_param_type id) { 
        return factory.register_creator(id, new_ptr<T>());
    }

  public:  /// Input
    /// Key pressed
    bool onKeyDown(const Input::KeyEvent& key);
    /// Key released
    bool onKeyUp(const Input::KeyEvent& key);
    /// Joystic axis change
    bool joystickAxisMoved(const Input::JoystickEvent& arg, I8 axis);
    /// Joystick direction change
    bool joystickPovMoved(const Input::JoystickEvent& arg, I8 pov);
    /// Joystick button pressed
    bool joystickButtonPressed(const Input::JoystickEvent& arg,
                               Input::JoystickButton button);
    /// Joystick button released
    bool joystickButtonReleased(const Input::JoystickEvent& arg,
                                Input::JoystickButton button);
    bool joystickSliderMoved(const Input::JoystickEvent& arg, I8 index);
    bool joystickVector3DMoved(const Input::JoystickEvent& arg, I8 index);
    /// Mouse moved
    bool mouseMoved(const Input::MouseEvent& arg);
    /// Mouse button pressed
    bool mouseButtonPressed(const Input::MouseEvent& arg,
                            Input::MouseButton button);
    /// Mouse button released
    bool mouseButtonReleased(const Input::MouseEvent& arg,
                             Input::MouseButton button);

    bool switchScene(const stringImpl& name, bool unloadPrevious, bool threaded = true);

  protected:
    friend class ScenePool;
    void initPostLoadState();
    Scene* load(stringImpl name);
    bool   unloadScene(Scene* scene);

  protected:
    bool frameStarted(const FrameEvent& evt) override;
    bool frameEnded(const FrameEvent& evt) override;
    void onCameraUpdate(Camera& camera);
    void preRender();
    bool generateShadowMaps();

  private:
    SceneManager();
    ~SceneManager();

  private:
    bool _init;
    bool _processInput;
    /// Pointer to the GUI interface
    GUI* _GUI;
    /// Pointer to the scene graph culler that's used to determine what nodes are
    /// visible in the current frame
    RenderPassCuller* _renderPassCuller;
    /// Pointer to the render pass manager
    RenderPassManager* _renderPassManager;
    ScenePool* _scenePool;
    SceneShaderData* _sceneData;
    U64 _elapsedTime;
    U32 _elapsedTimeMS;
    U64 _saveTimer;
    Renderer* _renderer;
    Material_ptr _defaultMaterial;
    RenderPassCuller::VisibleNodeList _tempNodesCache;
    Time::ProfileTimer& _sceneGraphCullTimer;

    struct SwitchSceneTarget {
        SwitchSceneTarget()
            : _targetSceneName(""),
              _unloadPreviousScene(true),
              _loadInSeparateThread(true),
              _isSet(false)
        {
        }

        inline void reset() {
            _targetSceneName.clear();
            _unloadPreviousScene = true;
            _loadInSeparateThread = true;
            _isSet = false;
        }

        inline bool isSet() const {
            return _isSet;
        }

        inline void set(const stringImpl& targetSceneName,
                        bool unloadPreviousScene,
                        bool loadInSeparateThread) {
            _targetSceneName = targetSceneName;
            _unloadPreviousScene = unloadPreviousScene;
            _loadInSeparateThread = loadInSeparateThread;
            _isSet = true;
        }

        inline const stringImpl& targetSceneName() const {
            return _targetSceneName;
        }

        inline bool unloadPreviousScene() const {
            return _unloadPreviousScene;
        }

        inline bool loadInSeparateThread() const {
            return _loadInSeparateThread;
        }

     private:
        stringImpl _targetSceneName;
        bool _unloadPreviousScene;
        bool _loadInSeparateThread;
        bool _isSet;
    } _sceneSwitchTarget;

END_SINGLETON

namespace Attorney {
class SceneManagerKernel {
   private:
    static void initPostLoadState() {
        Divide::SceneManager::instance().initPostLoadState();
    }

    static void onCameraUpdate(Camera& camera) {
        Divide::SceneManager::instance().onCameraUpdate(camera);
    }

    friend class Divide::Kernel;
};

class SceneManagerRenderPass {
   private:
    static void preRender(Divide::SceneManager& mgr) {
        mgr.preRender();
    }

    static bool generateShadowMaps(Divide::SceneManager& mgr) {
        return mgr.generateShadowMaps();
    }

    friend class Divide::RenderPass;
};

};  // namespace Attorney

};  // namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Managers/Headers/SceneManager.h

Diff revisions: vs.
Revision Author Commited Message
750 Diff Diff IonutCava picture IonutCava Thu 07 Jul, 2016 16:02:03 +0000

[IonutCava]
- Static analysis based fixes and improvements

749 Diff Diff IonutCava picture IonutCava Mon 04 Jul, 2016 16:01:34 +0000

[IonutCava]
- Added initial environment mapping code:
— Allow adding, per scene, of multiple environment probes that generate cube map reflections
— Support 2 types of probes: infinite (such as sky only probes) and local. Local probes use an AABB that will later be used for parallax correction
— Probes are held in a scene specific pool, can be updated at different rates and their results can be passed on to materials (if materials don’t need specific reflection systems such as for water or mirrors)
- ToDo:
— Blend between probes (currently, only the closes one is selected)
— Reduce VRAM usage
— Set as fallback for screen space reflections

734 Diff Diff IonutCava picture IonutCava Tue 21 Jun, 2016 16:28:11 +0000

[IonutCava]
- Added a render target pool:
— All render targets are now allocated (and tracked) by the GFXDevice.
— Allocation routines return a slim RenderTargetHandle object that will be used later on in draw commands.

- Added a refraction render pass that will handle translucent objects that need refracted textures instead of clear transparency
— Both reflective nodes and refractive nodes are not gathered properly at this point

- All API specific objects (buffers, textures, etc) are now initialized in the GFXDevice class (see GFXDeviceObjects.cpp)
— This allowed for the slimming of the RenderAPIWrapper interface

- Improved ENABLE_GPU_VALIDATION macro utilization:
— It enabled shadow map split plane debugging
— It bypasses loading shaders from text cache

730 Diff Diff IonutCava picture IonutCava Thu 16 Jun, 2016 15:35:07 +0000

[IonutCava]
- More shadow mapping fixes
- Small performance improvements
- Proper per scene XML data loading (e.g. fog)

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

726 Diff Diff IonutCava picture IonutCava Fri 10 Jun, 2016 16:13:52 +0000

[IonutCava]
- More static analysis based corrections
- Added initial stub code for a command pool system for GenericDrawCommands

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

719 Diff Diff IonutCava picture IonutCava Fri 03 Jun, 2016 16:20:08 +0000

[IonutCava]
- More SceneManager – ScenePool splitting of responsibilities
- DefaultScene will be the first scene loaded by the application. If nothing is specified in XML, it will default to "DefaultScene"

718 Diff Diff IonutCava picture IonutCava Thu 02 Jun, 2016 16:02:48 +0000

[IonutCava]
- Code cleanup:
— Rename Framebuffer to RenderTarget. Only OpenGL uses the Framebuffer nomenclature.
— Remove base Shader class as only OpenGL will have separate shaders (and eventually move to pipeline objects) as Direct3D uses FX files and may end up with different structure
— Remove drawBox3D, drawSphere3D and drawLines from GFXDevice class and add them as member functions to the IMPrimitive class (renamed to fromXYZ)
— Pull some elements from SceneManager and move them to standalone classes (W.I.P.)

717 IonutCava picture IonutCava Wed 01 Jun, 2016 16:09:11 +0000

[IonutCava]
- Added initial code for 2 test scenes: ShadowScene and ReflectionScene that will be used to fix and update the shadowing and the reflection systems respectively
- More scene switch bug fixes
— XML scene data is now optional. Scenes can be created entirely form code if needed