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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
#include "Headers/SceneManager.h"

#include "GUI/Headers/GUI.h"
#include "Core/Headers/ParamHandler.h"
#include "Scenes/Headers/ScenePool.h"
#include "Scenes/Headers/SceneShaderData.h"
#include "Core/Time/Headers/ProfileTimer.h"
#include "Rendering/PostFX/Headers/PostFX.h"
#include "Geometry/Importer/Headers/DVDConverter.h"
#include "Rendering/RenderPass/Headers/RenderQueue.h"
#include "Rendering/Headers/ForwardPlusRenderer.h"
#include "Rendering/Headers/DeferredShadingRenderer.h"
#include "AI/PathFinding/Headers/DivideRecast.h"

#include "Core/Debugging/Headers/DebugInterface.h"

namespace Divide {

/*
    ToDo:
    - Add IMPrimities per Scene and clear on scene unload
    - Cleanup load flags and use ResourceState enum instead
    - Sort out camera loading/unloading issues with parameteres (position, orientation, etc)
*/

namespace {
    // if culled count exceeds this limit, culling becomes multithreaded in the next frame
    const U32 g_asyncCullThreshold = 75;

    struct VisibleNodesFrontToBack {
        VisibleNodesFrontToBack(const vec3<F32>& camPos) : _camPos(camPos)
        {
        }

        bool operator()(const RenderPassCuller::VisibleNode& a, const RenderPassCuller::VisibleNode& b) const {
            F32 distASQ = a.second.lock()->get<BoundsComponent>()->getBoundingSphere()
                .getCenter().distanceSquared(_camPos);
            F32 distBSQ = b.second.lock()->get<BoundsComponent>()->getBoundingSphere()
                .getCenter().distanceSquared(_camPos);
            return distASQ < distBSQ;
        }

        const vec3<F32> _camPos;
    };
};

bool SceneManager::initStaticData() {
    return Attorney::SceneManager::initStaticData();
}

SceneManager::SceneManager()
    : FrameListener(),
      _GUI(nullptr),
      _renderer(nullptr),
      _renderPassCuller(nullptr),
      _renderPassManager(nullptr),
      _defaultMaterial(nullptr),
      _processInput(false),
      _scenePool(nullptr),
      _init(false),
      _elapsedTime(0ULL),
      _elapsedTimeMS(0),
      _saveTimer(0ULL),
      _sceneGraphCullTimer(Time::ADD_TIMER("SceneGraph cull timer"))
{
    ADD_FILE_DEBUG_GROUP();
    ADD_DEBUG_VAR_FILE(&_elapsedTime, CallbackParam::TYPE_LARGE_INTEGER, false);
    AI::Navigation::DivideRecast::createInstance();

    _sceneData = MemoryManager_NEW SceneShaderData();
    _scenePool = MemoryManager_NEW ScenePool(*this);
}

SceneManager::~SceneManager()
{
    UNREGISTER_FRAME_LISTENER(&(this->instance()));
    Console::printfn(Locale::get(_ID("STOP_SCENE_MANAGER")));
    // Console::printfn(Locale::get("SCENE_MANAGER_DELETE"));
    Console::printfn(Locale::get(_ID("SCENE_MANAGER_REMOVE_SCENES")));
    MemoryManager::DELETE(_scenePool);
    MemoryManager::DELETE(_sceneData);
    MemoryManager::DELETE(_renderPassCuller);
    MemoryManager::DELETE(_renderer);
    AI::Navigation::DivideRecast::destroyInstance();
}

Scene& SceneManager::getActiveScene() {
    return _scenePool->activeScene();
}

const Scene& SceneManager::getActiveScene() const {
    return _scenePool->activeScene();
}

void SceneManager::idle() {
    if (_sceneSwitchTarget.isSet()) {
        switchScene(_sceneSwitchTarget.targetSceneName(),
                    _sceneSwitchTarget.unloadPreviousScene(),
                    _sceneSwitchTarget.loadInSeparateThread());
        WaitForAllTasks(true, true);
    } else {
        getActiveScene().idle();
    }
}

bool SceneManager::init(GUI* const gui) {
    REGISTER_FRAME_LISTENER(&(this->instance()), 1);

    // Load default material
    Console::printfn(Locale::get(_ID("LOAD_DEFAULT_MATERIAL")));
    _defaultMaterial = XML::loadMaterialXML(
        ParamHandler::instance().getParam<stringImpl>(_ID("scriptLocation")) +
            "/defaultMaterial",
        false);
    _defaultMaterial->dumpToFile(false);

    _GUI = gui;
    _renderPassCuller = MemoryManager_NEW RenderPassCuller();
    _renderPassManager = &RenderPassManager::instance();
    _sceneData->init();
    _scenePool->init();
    _init = true;
    return true;
}

Scene* SceneManager::load(stringImpl sceneName) {
    bool foundInCache = false;
    Scene* loadingScene = _scenePool->getOrCreateScene(sceneName, foundInCache);

    if (!loadingScene) {
        Console::errorfn(Locale::get(_ID("ERROR_XML_LOAD_INVALID_SCENE")));
        return nullptr;
    }

    ParamHandler::instance().setParam(_ID("currentScene"), sceneName);

    bool state = false;
    bool sceneNotLoaded = loadingScene->getState() != ResourceState::RES_LOADED;

    if (sceneNotLoaded) {
        XML::loadScene(sceneName, loadingScene);
        state = Attorney::SceneManager::load(*loadingScene, sceneName);
        if (state) {
            Attorney::SceneManager::postLoad(*loadingScene);
        }
    } else {
        state = true;
    }

    if (state) {
        state = LoadSave::loadScene(*loadingScene);
    }

    return state ? loadingScene : nullptr;
}

bool SceneManager::unloadScene(Scene* scene) {
    assert(scene != nullptr);
    
    if (Attorney::SceneManager::deinitializeAI(*scene)) {
        _GUI->onUnloadScene(scene);
        return Attorney::SceneManager::unload(*scene);
    }

    return false;
}

void SceneManager::setActiveScene(Scene* const scene) {
    assert(scene != nullptr);

    if (!_scenePool->defaultSceneActive()) {
        Attorney::SceneManager::onRemoveActive(getActiveScene());
    }
    Attorney::SceneManager::onSetActive(*scene);
    _scenePool->activeScene(*scene);
    _GUI->onChangeScene(scene);
    ParamHandler::instance().setParam(_ID("activeScene"), scene->getName());
}

bool SceneManager::switchScene(const stringImpl& name, bool unloadPrevious, bool threaded) {
    assert(!name.empty());

    Scene* sceneToUnload = nullptr;
    if (!_scenePool->defaultSceneActive()) {
        sceneToUnload = &_scenePool->activeScene();
    }

    CreateTask(
        [this, name, unloadPrevious, &sceneToUnload](const std::atomic_bool& stopRequested)
        {
            // Load first, unload after to make sure we don't reload common resources
            if (load(name) != nullptr) {
                if (unloadPrevious && sceneToUnload) {
                    Attorney::SceneManager::onRemoveActive(*sceneToUnload);
                    unloadScene(sceneToUnload);
                }
            }
        },
        [this, name]()
        {
            bool foundInCache = false;
            Scene* loadedScene = _scenePool->getOrCreateScene(name, foundInCache);
            assert(loadedScene != nullptr && foundInCache);
            if(loadedScene->getState() == ResourceState::RES_LOADING) {
                Attorney::SceneManager::postLoadMainThread(*loadedScene);
                if (loadedScene->getGUID() != _scenePool->defaultScene().getGUID())
                {
                    SceneGUIElements* gui = Attorney::SceneManager::gui(*loadedScene);
                    gui->addButton(_ID_RT("Back"),
                        "Back",
                        vec2<I32>(15, 15),
                        vec2<U32>(50, 25),
                        [this](I64 btnGUID)
                    {
                        _sceneSwitchTarget.set(_scenePool->defaultScene().getName(), true, false);
                    });
                }
            }
            assert(loadedScene->getState() == ResourceState::RES_LOADED);
            setActiveScene(loadedScene);

            _reflectiveNodesCache.clear();
            _renderPassCuller->clear();
            
        })._task->startTask(threaded ? Task::TaskPriority::HIGH
                                     : Task::TaskPriority::REALTIME_WITH_CALLBACK,
                            to_const_uint(Task::TaskFlags::SYNC_WITH_GPU));

    _sceneSwitchTarget.reset();

    return true;
}

vectorImpl<stringImpl> SceneManager::sceneNameList(bool sorted) const {
    return _scenePool->sceneNameList(sorted);
}

void SceneManager::initPostLoadState() {
    _processInput = true;
}

bool SceneManager::frameStarted(const FrameEvent& evt) {
    _sceneData->uploadToGPU();
    return Attorney::SceneManager::frameStarted(getActiveScene());
}

bool SceneManager::frameEnded(const FrameEvent& evt) {
    return Attorney::SceneManager::frameEnded(getActiveScene());
}

void SceneManager::onCameraUpdate(Camera& camera) {
    getActiveScene().sceneGraph().onCameraUpdate(camera);
}

void SceneManager::updateSceneState(const U64 deltaTime) {
    Scene& activeScene = getActiveScene();
    assert(activeScene.getState() == ResourceState::RES_LOADED);
    // Update internal timers
    _elapsedTime += deltaTime;
    _elapsedTimeMS = Time::MicrosecondsToMilliseconds<U32>(_elapsedTime);

    ParamHandler& par = ParamHandler::instance();
    LightPool* lightPool = Attorney::SceneManager::lightPool(activeScene);

    // Shadow splits are only visible in debug builds
    _sceneData->enableDebugRender(par.getParam<bool>(_ID("rendering.debug.displayShadowDebugInfo")));
    // Time, fog, etc
    _sceneData->elapsedTime(_elapsedTimeMS);
    _sceneData->deltaTime(Time::MicrosecondsToSeconds<F32>(deltaTime));
    _sceneData->lightCount(LightType::DIRECTIONAL, lightPool->getActiveLightCount(LightType::DIRECTIONAL));
    _sceneData->lightCount(LightType::POINT, lightPool->getActiveLightCount(LightType::POINT));
    _sceneData->lightCount(LightType::SPOT, lightPool->getActiveLightCount(LightType::SPOT));

    _sceneData->setRendererFlag(getRenderer().getFlag());

    _sceneData->toggleShadowMapping(lightPool->shadowMappingEnabled());

    _sceneData->fogDensity(par.getParam<bool>(_ID("rendering.enableFog"))
                            ? par.getParam<F32>(_ID("rendering.sceneState.fogDensity"))
                            : 0.0f);

    const SceneState& activeSceneState = activeScene.state();
    _sceneData->windDetails(activeSceneState.windDirX(),
                            0.0f,
                            activeSceneState.windDirZ(),
                            activeSceneState.windSpeed());

    activeScene.updateSceneState(deltaTime);

    _saveTimer += deltaTime;

    if (_saveTimer >= Time::SecondsToMicroseconds(5)) {
        LoadSave::saveScene(activeScene);
        _saveTimer = 0ULL;
    }
}

void SceneManager::preRender() {
    Scene& activeScene = getActiveScene();
    LightPool* lightPool = Attorney::SceneManager::lightPool(activeScene);
    lightPool->updateAndUploadLightData(activeScene.renderState().getCameraConst().getEye(), GFX_DEVICE.getMatrix(MATRIX::VIEW));
    getRenderer().preRender(*lightPool);
}

bool SceneManager::generateShadowMaps() {
    Scene& activeScene = getActiveScene();
    LightPool* lightPool = Attorney::SceneManager::lightPool(activeScene);
    assert(lightPool != nullptr);
    return lightPool->generateShadowMaps(activeScene.renderState());
}

/// Update fog values
void SceneManager::enableFog(F32 density, const vec3<F32>& colour) {
    ParamHandler& par = ParamHandler::instance();
    par.setParam(_ID("rendering.sceneState.fogColour.r"), colour.r);
    par.setParam(_ID("rendering.sceneState.fogColour.g"), colour.g);
    par.setParam(_ID("rendering.sceneState.fogColour.b"), colour.b);
    par.setParam(_ID("rendering.sceneState.fogDensity"), density);

    _sceneData->fogDetails(colour.r, colour.g, colour.b,
                          par.getParam<bool>(_ID("rendering.enableFog")) ? density : 0.0f);
}

const RenderPassCuller::VisibleNodeList& SceneManager::getSortedReflectiveNodes() {
    auto cullingFunction = [](const RenderPassCuller::VisibleNode& node) -> bool {
        SceneGraphNode_cptr sgnNode = node.second.lock();
        if (sgnNode->getNode()->getType() != SceneNodeType::TYPE_OBJECT3D) {
            return true;
        } else {
            return sgnNode->getNode<Object3D>()->getObjectType() == Object3D::ObjectType::FLYWEIGHT;
        }
        return false;
    };

    const SceneRenderState& renderState = getActiveScene().state().renderState();
    const vec3<F32>& camPos = renderState.getCameraConst().getEye();

    // Get list of nodes in view from the previous frame
    RenderPassCuller::VisibleNodeList& nodeCache = getVisibleNodesCache(RenderStage::Z_PRE_PASS);

    RenderPassCuller::VisibleNodeList waterNodes;
    _reflectiveNodesCache.resize(0);
    for (RenderPassCuller::VisibleNode& node : nodeCache) {
        SceneGraphNode_cptr sgnNode = node.second.lock();
        if (sgnNode->getNode()->getType() != SceneNodeType::TYPE_WATER) {
            _reflectiveNodesCache.push_back(node);
        } else {
            waterNodes.push_back(node);
        }
    }

    // Cull nodes that are not valid reflection targets
    _reflectiveNodesCache.erase(std::remove_if(std::begin(_reflectiveNodesCache),
                                std::end(_reflectiveNodesCache),
                                cullingFunction),
                                std::end(_reflectiveNodesCache));

    // Sort the nodes from front to back
    std::sort(std::begin(_reflectiveNodesCache),
              std::end(_reflectiveNodesCache),
              VisibleNodesFrontToBack(camPos));
    _reflectiveNodesCache.insert(std::begin(_reflectiveNodesCache), std::begin(waterNodes), std::end(waterNodes));

    return _reflectiveNodesCache;
}

const RenderPassCuller::VisibleNodeList& SceneManager::cullSceneGraph(RenderStage stage) {
    Scene& activeScene = getActiveScene();

    auto cullingFunction = [](const SceneGraphNode& node) -> bool {
        if (node.getNode()->getType() == SceneNodeType::TYPE_OBJECT3D) {
            Object3D::ObjectType type = node.getNode<Object3D>()->getObjectType();
            return (type == Object3D::ObjectType::FLYWEIGHT);
        }
        return false;
    };

    auto meshCullingFunction = [](const RenderPassCuller::VisibleNode& node) -> bool {
        SceneGraphNode_cptr sgnNode = node.second.lock();
        if (sgnNode->getNode()->getType() == SceneNodeType::TYPE_OBJECT3D) {
            Object3D::ObjectType type = sgnNode->getNode<Object3D>()->getObjectType();
            return (type == Object3D::ObjectType::MESH);
        }
        return false;
    };

    auto shadowCullingFunction = [](const RenderPassCuller::VisibleNode& node) -> bool {
        SceneNodeType type = node.second.lock()->getNode()->getType();
        return type == SceneNodeType::TYPE_LIGHT || type == SceneNodeType::TYPE_TRIGGER;
    };

    // If we are rendering a high node count, we might want to use async frustum culling
    bool cullAsync = _renderPassManager->getLastTotalBinSize(stage) > g_asyncCullThreshold;
    _renderPassCuller->frustumCull(activeScene.sceneGraph(),
                                   activeScene.state(),
                                   stage,
                                   cullAsync,
                                   cullingFunction);
    RenderPassCuller::VisibleNodeList& visibleNodes = _renderPassCuller->getNodeCache(stage);

    visibleNodes.erase(std::remove_if(std::begin(visibleNodes),
                                      std::end(visibleNodes),
                                      meshCullingFunction),
                       std::end(visibleNodes));

    if (stage == RenderStage::SHADOW) {
        visibleNodes.erase(std::remove_if(std::begin(visibleNodes),
                                          std::end(visibleNodes),
                                          shadowCullingFunction),
                           std::end(visibleNodes));
        
    }

    return visibleNodes;
}

RenderPassCuller::VisibleNodeList& 
SceneManager::getVisibleNodesCache(RenderStage stage) {
    return _renderPassCuller->getNodeCache(stage);
}

void SceneManager::updateVisibleNodes(RenderStage stage, bool refreshNodeData, U32 pass) {
    Scene& activeScene = getActiveScene();

    RenderQueue& queue = _renderPassManager->getQueue();

    RenderPassCuller::VisibleNodeList& visibleNodes = _renderPassCuller->getNodeCache(stage);

    if (refreshNodeData) {
        queue.refresh();
        const vec3<F32>& eyePos = activeScene.renderState().getCameraConst().getEye();
        for (RenderPassCuller::VisibleNode& node : visibleNodes) {
            queue.addNodeToQueue(*node.second.lock(), stage, eyePos);
        }
    }
    
    queue.sort(stage);
    for (RenderPassCuller::VisibleNode& node : visibleNodes) {
        node.first = node.second.lock()->get<RenderingComponent>()->drawOrder();
    }

    std::sort(std::begin(visibleNodes), std::end(visibleNodes),
        [](const RenderPassCuller::VisibleNode& nodeA,
           const RenderPassCuller::VisibleNode& nodeB)
        {
            return nodeA.first < nodeB.first;
        }
    );

    SceneRenderState& renderState = activeScene.renderState();
    I32 stagePass = 0;
    if (stage == RenderStage::REFLECTION) {
        stagePass = renderState.currentReflectorIndex();
    } else if (stage == RenderStage::SHADOW) {
        stagePass = renderState.currentShadowLightIndex();
    }

    RenderPass::BufferData& bufferData = RenderPassManager::instance().getBufferData(stage, stagePass, pass);
    GFX_DEVICE.buildDrawCommands(visibleNodes, renderState, bufferData, refreshNodeData);
}

void SceneManager::renderVisibleNodes(RenderStage stage, bool refreshNodeData, U32 pass) {
    if (refreshNodeData) {
        Time::ScopedTimer timer(_sceneGraphCullTimer);
        cullSceneGraph(stage);
    }

    updateVisibleNodes(stage, refreshNodeData, pass);

    if (getActiveScene().renderState().drawGeometry()) {
        RenderPassManager::instance().getQueue().populateRenderQueues(stage);
    }

    GFX_DEVICE.flushRenderQueues();
}

Renderer& SceneManager::getRenderer() const {
    DIVIDE_ASSERT(_renderer != nullptr,
        "SceneManager error: Renderer requested but not created!");
    return *_renderer;
}

void SceneManager::setRenderer(RendererType rendererType) {
    DIVIDE_ASSERT(rendererType != RendererType::COUNT,
        "SceneManager error: Tried to create an invalid renderer!");

    switch (rendererType) {
    case RendererType::RENDERER_FORWARD_PLUS: {
        MemoryManager::SAFE_UPDATE(_renderer, MemoryManager_NEW ForwardPlusRenderer());
    } break;
    case RendererType::RENDERER_DEFERRED_SHADING: {
        MemoryManager::SAFE_UPDATE(_renderer, MemoryManager_NEW DeferredShadingRenderer());
    } break;
    }
}

void SceneManager::onLostFocus() {
    getActiveScene().onLostFocus();
}
///--------------------------Input Management-------------------------------------///

bool SceneManager::onKeyDown(const Input::KeyEvent& key) {
    if (!_processInput) {
        return false;
    }
    return getActiveScene().input().onKeyDown(key);
}

bool SceneManager::onKeyUp(const Input::KeyEvent& key) {
    if (!_processInput) {
        return false;
    }

    return getActiveScene().input().onKeyUp(key);
}

bool SceneManager::mouseMoved(const Input::MouseEvent& arg) {
    if (!_processInput) {
        return false;
    }

    return getActiveScene().input().mouseMoved(arg);
}

bool SceneManager::mouseButtonPressed(const Input::MouseEvent& arg,
                                      Input::MouseButton button) {
    if (!_processInput) {
        return false;
    }
    return getActiveScene().input().mouseButtonPressed(arg, button);
}

bool SceneManager::mouseButtonReleased(const Input::MouseEvent& arg,
                                       Input::MouseButton button) {
    if (!_processInput) {
        return false;
    }

    return getActiveScene().input().mouseButtonReleased(arg, button);
}

bool SceneManager::joystickAxisMoved(const Input::JoystickEvent& arg, I8 axis) {
    if (!_processInput) {
        return false;
    }
    return getActiveScene().input().joystickAxisMoved(arg, axis);
}

bool SceneManager::joystickPovMoved(const Input::JoystickEvent& arg, I8 pov) {
    if (!_processInput) {
        return false;
    }
    return getActiveScene().input().joystickPovMoved(arg, pov);
}

bool SceneManager::joystickButtonPressed(const Input::JoystickEvent& arg,
                                         Input::JoystickButton button) {
    if (!_processInput) {
        return false;
    }
    return getActiveScene().input().joystickButtonPressed(arg, button);
}

bool SceneManager::joystickButtonReleased(const Input::JoystickEvent& arg,
                                          Input::JoystickButton button) {
    if (!_processInput) {
        return false;
    }
    return getActiveScene().input().joystickButtonReleased(arg, button);
}

bool SceneManager::joystickSliderMoved(const Input::JoystickEvent& arg,
                                       I8 index) {
    if (!_processInput) {
        return false;
    }
    return getActiveScene().input().joystickSliderMoved(arg, index);
}

bool SceneManager::joystickVector3DMoved(const Input::JoystickEvent& arg,
                                         I8 index) {
    if (!_processInput) {
        return false;
    }
    return getActiveScene().input().joystickVector3DMoved(arg, index);
}

bool LoadSave::loadScene(Scene& activeScene) {
    if (activeScene.state().saveLoadDisabled()) {
        return true;
    }

    const stringImpl& sceneName = activeScene.getName();

    stringImpl path = Util::StringFormat("SaveData/%s_", sceneName.c_str());
    stringImpl savePath = path + "current_save.sav";
    stringImpl bakSavePath = path + "save.bak";

    std::ifstream src(savePath.c_str(), std::ios::binary);
    if (src.eof() || src.fail())
    {
        src.close();
        std::ifstream srcBak(bakSavePath.c_str(), std::ios::binary);
        if(srcBak.eof() || srcBak.fail()) {
            srcBak.close();
            return true;
        } else {
            std::ofstream dst(savePath.c_str(), std::ios::binary);
            dst << srcBak.rdbuf();
            dst.close();
            srcBak.close();
        }
    }

    ByteBuffer save;
    save.loadFromFile(savePath);

    return Attorney::SceneLoadSave::load(activeScene, save);
}

bool LoadSave::saveScene(const Scene& activeScene) {
    if (activeScene.state().saveLoadDisabled()) {
        return true;
    }

    const stringImpl& sceneName = activeScene.getName();
    stringImpl path = Util::StringFormat("SaveData/%s_", sceneName.c_str());
    stringImpl savePath = path + "current_save.sav";
    stringImpl bakSavePath = path + "save.bak";

    std::ifstream src(savePath.c_str(), std::ios::binary);
    if (!src.eof() && !src.fail())
    {
        std::ofstream dst(bakSavePath.c_str(), std::ios::out | std::ios::binary);
        dst.clear();
        dst << src.rdbuf();
        dst.close();
    }
    src.close();

    ByteBuffer save;
    if (Attorney::SceneLoadSave::save(activeScene, save)) {
        return save.dumpToFile(savePath);
    }

    return false;
}

};

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

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)

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 Diff Diff 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

716 Diff Diff IonutCava picture IonutCava Tue 31 May, 2016 16:08:29 +0000

[IonutCava]
- Multithreaded scene load/unload fixes:
— Added postLoadMainThread call for scenes for thread sensitive loading steps
— GUI element adding is a thread sensitive loading step (a fast one) because CEGUI doesn’t handle threading
- Added REALTIME_WITH_CALLBACK task priority for tasks that need an immediate callback when they complete instead of using the flushCallbackQueue system.
- Some work on shadow mapping for getting it to work again
- ShaderPrograms that fail to load can cause a LockManager infinite wait. Delete the lockManager if the shader didn’t load to avoid waiting on commands that never get called.

715 Diff Diff IonutCava picture IonutCava Fri 27 May, 2016 16:19:22 +0000

[IonutCava]
- Added initial Fade In / Fade Out post effect (used for scene transitions for now)
- Added a GUI Interface that handles a list of GUI elements (used by GUI and SceneGUIElements)
- Fixed some race conditions related to multi-threaded scene loading (a lot remain to be fixed)
- Improved per-thread GPU sync system a bit
- Simplified Singleton define macros (although we should get rid of singletons all together)

714 Diff Diff IonutCava picture IonutCava Thu 26 May, 2016 16:26:23 +0000

[IonutCava]
- Initial code for multithreaded scene load:
— Tasks can have a “sync with gpu” flag that will cause them to use a shared context (so they can call GL functions)
- Added per scene GUI lists that get passed to the main GUI class (still need a base class to hold the map and accessors to avoid code duplication)
- Re-enabled threading unit tests

713 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;