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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
#include "Headers/Kernel.h"

#include "GUI/Headers/GUI.h"
#include "GUI/Headers/GUISplash.h"
#include "GUI/Headers/GUIConsole.h"
#include "Utility/Headers/XMLParser.h"
#include "Core/Headers/ParamHandler.h"
#include "Managers/Headers/AIManager.h"
#include "Managers/Headers/LightManager.h"
#include "Managers/Headers/SceneManager.h"
#include "Core/Headers/ProfileTimer.h"
#include "Core/Headers/ApplicationTimer.h"
#include "Rendering/Headers/Renderer.h"
#include "Rendering/PostFX/Headers/PostFX.h"
#include "Platform/Video/Headers/GFXDevice.h"
#include "Physics/Headers/PXDevice.h"
#include "Rendering/Camera/Headers/FreeFlyCamera.h"
#include "Platform/Input/Headers/InputInterface.h"
#include "Managers/Headers/FrameListenerManager.h"
#include "Platform/Compute/Headers/OpenCLInterface.h"
#include "Platform/Video/Shaders/Headers/ShaderManager.h"

namespace Divide {

LoopTimingData::LoopTimingData() : _previousTime(0ULL),
                                   _currentTime(0ULL),
                                   _currentTimeFrozen(0ULL),
                                   _currentTimeDelta(0ULL),
                                   _nextGameTick(0ULL),
                                   _keepAlive(true),
                                   _freezeLoopTime(false),
                                   _freezeGUITime(false)
{
}


LoopTimingData Kernel::_timingData;
Time::ProfileTimer* s_appLoopTimer = nullptr;

boost::lockfree::queue<I64> Kernel::_threadedCallbackBuffer(128);
Kernel::CallbackFunctions Kernel::_threadedCallbackFunctions;

Kernel::Kernel(I32 argc, char** argv, Application& parentApp)
    : _argc(argc),
      _argv(argv),
      _APP(parentApp),
      _GFX(GFXDevice::getInstance()),                // Video
      _SFX(SFXDevice::getInstance()),                // Audio
      _PFX(PXDevice::getInstance()),                 // Physics
      _input(Input::InputInterface::getInstance()),  // Input
      _GUI(GUI::getInstance()),  // Graphical User Interface
      _sceneMgr(SceneManager::getInstance())  // Scene Manager

{
    _mainCamera = nullptr;

    ResourceCache::createInstance();
    FrameListenerManager::createInstance();
    // General light management and rendering (individual lights are handled by each scene)
    // Unloading the lights is a scene level responsibility
    LightManager::createInstance();
    OpenCLInterface::createInstance();
    _cameraMgr.reset(new CameraManager(this));  // Camera manager
    assert(_cameraMgr != nullptr);
    // force all lights to update on camera change (to keep them still actually)
    _cameraMgr->addCameraUpdateListener(
        DELEGATE_BIND(&Attorney::GFXDeviceKernel::onCameraUpdate, std::placeholders::_1));
    ParamHandler::getInstance().setParam<stringImpl>(_ID("language"), Locale::currentLanguage());

    // Add our needed app-wide render passes. RenderPassManager is responsible for deleting these!
    RenderPassManager::getInstance().addRenderPass("environmentPass", 0, {RenderStage::REFLECTION});
    RenderPassManager::getInstance().addRenderPass("shadowPass",      1, {RenderStage::SHADOW});
    RenderPassManager::getInstance().addRenderPass("displayStage",    2, {RenderStage::Z_PRE_PASS, RenderStage::DISPLAY});

    s_appLoopTimer = Time::ADD_TIMER("MainLoopTimer");
}

Kernel::~Kernel()
{
    _mainTaskPool.wait(0);
    _tasks.clear();
}

void Kernel::threadPoolCompleted(I64 onExitTaskID) {
    WAIT_FOR_CONDITION(_threadedCallbackBuffer.push(onExitTaskID));
}

Task_ptr Kernel::AddTask(U64 tickInterval, I32 numberOfTicks,
                         const DELEGATE_CBK<>& threadedFunction,
                         const DELEGATE_CBK<>& onCompletionFunction) {
    Task_ptr taskPtr(new Task(_mainTaskPool,
                              tickInterval,
                              numberOfTicks,
                              threadedFunction));

    taskPtr->onCompletionCbk(DELEGATE_BIND(&Kernel::threadPoolCompleted,
                                           this,
                                           std::placeholders::_1));
    if (onCompletionFunction) {
        hashAlg::emplace(_threadedCallbackFunctions,
                         taskPtr->getGUID(),
                         onCompletionFunction);
    }

    _tasks.push_back(taskPtr);

    return taskPtr;
}

void Kernel::idle() {
    Console::flush();
    GFX_DEVICE.idle();
    PHYSICS_DEVICE.idle();
    SceneManager::getInstance().idle();
    LightManager::getInstance().idle();
    FrameListenerManager::getInstance().idle();

    ParamHandler& par = ParamHandler::getInstance();

    _timingData._freezeGUITime = par.getParam(_ID("freezeGUITime"), false);
    bool freezeLoopTime = par.getParam(_ID("freezeLoopTime"), false);
    if (freezeLoopTime != _timingData._freezeLoopTime) {
        _timingData._freezeLoopTime = freezeLoopTime;
        _timingData._currentTimeFrozen = _timingData._currentTime;
        Application::getInstance().mainLoopPaused(_timingData._freezeLoopTime);
    }

    const stringImpl& pendingLanguage = par.getParam<stringImpl>(_ID("language"));
    if (pendingLanguage.compare(Locale::currentLanguage()) != 0) {
        Locale::changeLanguage(pendingLanguage);
    }

    I64 taskGUID = -1;
    if (_threadedCallbackBuffer.pop(taskGUID)) {
        CallbackFunctions::const_iterator it = _threadedCallbackFunctions.find(taskGUID);
        assert(it != std::end(_threadedCallbackFunctions));
        if (it->second) {
            it->second();
        }
    }
}

void Kernel::mainLoopApp() {
    if (!_timingData._keepAlive) {
        // exiting the rendering loop will return us to the last control point
        // (i.e. Kernel::runLogicLoop)
        Application::getInstance().mainLoopActive(false);
        return;
    }

    // Update internal timer
    Time::ApplicationTimer::getInstance().update();

    Time::START_TIMER(*s_appLoopTimer);

    // Update time at every render loop
    _timingData._previousTime = _timingData._currentTime;
    _timingData._currentTime = Time::ElapsedMicroseconds();
    _timingData._currentTimeDelta = _timingData._currentTime - 
                                    _timingData._previousTime;

    // In case we break in the debugger
    if (_timingData._currentTimeDelta > Time::SecondsToMicroseconds(1)) {
        _timingData._currentTimeDelta = Config::SKIP_TICKS;
        _timingData._previousTime = _timingData._currentTime -
                                    _timingData._currentTimeDelta;
    }

    Kernel::idle();

    Task::update(_timingData._currentTimeDelta);

    FrameEvent evt;
    FrameListenerManager& frameMgr = FrameListenerManager::getInstance();
    Application& APP = Application::getInstance();

    // Restore GPU to default state: clear buffers and set default render state
    GFX_DEVICE.beginFrame();
    {
        // Launch the FRAME_STARTED event
        frameMgr.createEvent(_timingData._currentTime,
                             FrameEventType::FRAME_EVENT_STARTED, evt);
        _timingData._keepAlive = frameMgr.frameEvent(evt);

        // Process the current frame
        _timingData._keepAlive = APP.getKernel().mainLoopScene(evt) &&
                                 _timingData._keepAlive;

        // Launch the FRAME_PROCESS event (a.k.a. the frame processing has ended
        // event)
        frameMgr.createEvent(_timingData._currentTime,
                             FrameEventType::FRAME_EVENT_PROCESS, evt);

        _timingData._keepAlive = frameMgr.frameEvent(evt) && 
                                 _timingData._keepAlive;
    }
    GFX_DEVICE.endFrame();

    // Launch the FRAME_ENDED event (buffers have been swapped)
    frameMgr.createEvent(_timingData._currentTime,
                         FrameEventType::FRAME_EVENT_ENDED, evt);
    _timingData._keepAlive = frameMgr.frameEvent(evt) &&
                             _timingData._keepAlive;

    _timingData._keepAlive = !APP.ShutdownRequested() &&
                             _timingData._keepAlive;

    ErrorCode err = APP.errorCode();
    if (err != ErrorCode::NO_ERR) {
        Console::errorfn("Error detected: [ %s ]", getErrorCodeName(err));
        _timingData._keepAlive = false;
    }
    Time::STOP_TIMER(*s_appLoopTimer);

#if !defined(_RELEASE)
    if (GFX_DEVICE.getFrameCount() % (Config::TARGET_FRAME_RATE * 10) == 0) {
        Console::printfn(
            "GPU: [ %5.5f ] [DrawCalls: %d]",
            Time::MicrosecondsToSeconds<F32>(GFX_DEVICE.getFrameDurationGPU()),
            GFX_DEVICE.getDrawCallCount());

        Util::FlushFloatEvents();
    }

    Util::RecordFloatEvent("kernel.mainLoopApp",
                           to_float(s_appLoopTimer->get()),
                           _timingData._currentTime);
#endif
}

bool Kernel::mainLoopScene(FrameEvent& evt) {
    _tasks.erase(std::remove_if(std::begin(_tasks), std::end(_tasks),
                                [](const Task_ptr& task)
                                    -> bool { return task->isFinished(); }),
                 std::end(_tasks));

    U64 deltaTime = Config::USE_FIXED_TIMESTEP ? Config::SKIP_TICKS 
                                               : _timingData._currentTimeDelta;
    // Update camera
    _cameraMgr->update(deltaTime);

    if (_APP.getWindowManager().minimized()) {
        idle();
        return true;
    }

    // Process physics
    _PFX.process(_timingData._freezeLoopTime ? 0ULL
                                             : _timingData._currentTimeDelta);

    U8 loops = 0;
    while (_timingData._currentTime > _timingData._nextGameTick &&
           loops < Config::MAX_FRAMESKIP) {

        if (!_timingData._freezeGUITime) {
            _sceneMgr.processGUI(deltaTime);
        }

        if (!_timingData._freezeLoopTime) {
            // Update scene based on input
            _sceneMgr.processInput(deltaTime);
            // process all scene events
            _sceneMgr.processTasks(deltaTime);
            // Update the scene state based on current time (e.g. animation matrices)
            _sceneMgr.updateSceneState(deltaTime);
        }

        _timingData._nextGameTick += deltaTime;
        loops++;

        if (Config::USE_FIXED_TIMESTEP) {
            if (loops == Config::MAX_FRAMESKIP &&
                _timingData._currentTime > _timingData._nextGameTick) {
                _timingData._nextGameTick = _timingData._currentTime;
            }
        } else {
            _timingData._nextGameTick = _timingData._currentTime;
        }

    }  // while

    D32 interpolationFactor = static_cast<D32>(_timingData._currentTime + 
                                               deltaTime -
                                               _timingData._nextGameTick);

    interpolationFactor /= static_cast<D32>(deltaTime);
    assert(interpolationFactor <= 1.0 && interpolationFactor > 0.0);

    _GFX.setInterpolation(Config::USE_FIXED_TIMESTEP ? interpolationFactor : 1.0);
    
    // Get input events
    if (_APP.getWindowManager().hasFocus()) {
        _input.update(_timingData._currentTimeDelta);
    } else {
        _sceneMgr.onLostFocus();
    }
    // Update physics - uses own timestep implementation
    _PFX.update(_timingData._freezeLoopTime ? 0ULL
                                            : _timingData._currentTimeDelta);
    // Update the graphical user interface
    if (!_timingData._freezeGUITime) {
        GUI::getInstance().update(_timingData._freezeGUITime ? 0ULL
                                                             : _timingData._currentTimeDelta);
    }

    return presentToScreen(evt);
}

bool Kernel::presentToScreen(FrameEvent& evt) {
    FrameListenerManager& frameMgr = FrameListenerManager::getInstance();

    frameMgr.createEvent(_timingData._currentTime,
                         FrameEventType::FRAME_PRERENDER_START, evt);

    if (!frameMgr.frameEvent(evt)) {
        return false;
    }

    // perform time-sensitive shader tasks
    ShaderManager::getInstance().update(_timingData._currentTimeDelta);

    frameMgr.createEvent(_timingData._currentTime,
                         FrameEventType::FRAME_PRERENDER_END, evt);

    if (!frameMgr.frameEvent(evt)) {
        return false;
    }

    RenderPassManager::getInstance().render(_sceneMgr.getActiveScene().renderState(), false);
    //PostFX::getInstance().apply();

    if (_GFX.anaglyphEnabled()) {
        // Save previous screen render target as left eye.
        // Render right eye
        Attorney::GFXDeviceKernel::flushAnaglyph();
        RenderPassManager::getInstance().render(_sceneMgr.getActiveScene().renderState(), true);
        PostFX::getInstance().apply();
    }
    
    Attorney::GFXDeviceKernel::flushDisplay();

    frameMgr.createEvent(_timingData._currentTime, FrameEventType::FRAME_POSTRENDER_START, evt);

    if (!frameMgr.frameEvent(evt)) {
        return false;
    }

    frameMgr.createEvent(_timingData._currentTime,
                         FrameEventType::FRAME_POSTRENDER_END, evt);

    if (!frameMgr.frameEvent(evt)) {
        return false;
    }

    return true;
}

void Kernel::firstLoop() {
    ParamHandler& par = ParamHandler::getInstance();
    bool shadowMappingEnabled = par.getParam<bool>(_ID("rendering.enableShadows"));
    // Skip two frames, one without and one with shadows, so all resources can
    // be built while
    // the splash screen is displayed
    par.setParam(_ID("freezeGUITime"), true);
    par.setParam(_ID("freezeLoopTime"), true);
    par.setParam(_ID("rendering.enableShadows"), false);
    mainLoopApp();
    if (shadowMappingEnabled) {
        par.setParam(_ID("rendering.enableShadows"), true);
        mainLoopApp();
    }
    mainLoopApp();
    par.setParam(_ID("freezeGUITime"), false);
    par.setParam(_ID("freezeLoopTime"), false);
#if defined(_DEBUG) || defined(_PROFILE)
    Time::ApplicationTimer::getInstance().benchmark(true);
#endif
    Attorney::SceneManagerKernel::initPostLoadState();

    _timingData._currentTime = _timingData._nextGameTick = Time::ElapsedMicroseconds();
}

ErrorCode Kernel::initialize(const stringImpl& entryPoint) {
    ParamHandler& par = ParamHandler::getInstance();

    // We have an A.I. thread, a networking thread, a PhysX thread, the main
    // update/rendering thread so how many threads do we allocate for tasks?
    // That's up to the programmer to decide for each app.
    // We add the A.I. thread in the same pool as it's a task. 
    // ReCast should also use this thread.
    U32 threadCount = HARDWARE_THREAD_COUNT();
    if (threadCount <= 2) {
        return ErrorCode::CPU_NOT_SUPPORTED;
    }

    SysInfo& systemInfo = Application::getInstance().getSysInfo();
    if (!CheckMemory(Config::REQUIRED_RAM_SIZE, systemInfo)) {
        return ErrorCode::NOT_ENOUGH_RAM;
    }

    _mainTaskPool.size_controller().resize(std::max(threadCount - 2, 1U));

    Console::bindConsoleOutput(
        DELEGATE_BIND(&GUIConsole::printText, GUI::getInstance().getConsole(),
                      std::placeholders::_1, std::placeholders::_2));
    _PFX.setAPI(PXDevice::PhysicsAPI::PhysX);
    _SFX.setAPI(SFXDevice::AudioAPI::SDL);
    // Using OpenGL for rendering as default
    if (Config::USE_OPENGL_RENDERING) {
        if (Config::USE_OPENGL_ES) {
            _GFX.setAPI(GFXDevice::RenderAPI::OpenGLES);
        } else {
            _GFX.setAPI(GFXDevice::RenderAPI::OpenGL);
        }
    }
    // Load info from XML files
    stringImpl startupScene(XML::loadScripts(entryPoint));
    // Create mem log file
    const stringImpl& mem = par.getParam<stringImpl>("memFile");
    _APP.setMemoryLogFile(mem.compare("none") == 0 ? "mem.log" : mem);
    Console::printfn(Locale::get(_ID("START_RENDER_INTERFACE")));
    WindowManager& winManager = _APP.getWindowManager();
    WindowType windowType = winManager.mainWindowType();

    vec2<U16> resolution = winManager.getResolution();
    F32 aspectRatio = to_float(resolution.width) / to_float(resolution.height);

    ErrorCode initError = _GFX.initRenderingAPI(_argc, _argv);
    // If we could not initialize the graphics device, exit
    if (initError != ErrorCode::NO_ERR) {
        return initError;
    }
    initError = OpenCLInterface::getInstance().init();
    if (initError != ErrorCode::NO_ERR) {
        return initError;
    }
    Console::printfn(Locale::get(_ID("SCENE_ADD_DEFAULT_CAMERA")));
    _mainCamera = _cameraMgr->createCamera("defaultCamera", Camera::CameraType::FREE_FLY);
    _mainCamera->setProjection(aspectRatio,
                               par.getParam<F32>("rendering.verticalFOV"),
                               vec2<F32>(par.getParam<F32>("rendering.zNear"),
                                         par.getParam<F32>("rendering.zFar")));
    _mainCamera->setFixedYawAxis(true);
    // As soon as a camera is added to the camera manager, the manager is
    // responsible for cleaning it up
    _cameraMgr->pushActiveCamera(_mainCamera);
    // We start of with a forward plus renderer
    _sceneMgr.setRenderer(RendererType::RENDERER_FORWARD_PLUS);
    winManager.mainWindowType(WindowType::SPLASH);
    // Load and render the splash screen
    _GFX.beginFrame();
    GUISplash("divideLogo.jpg", winManager.getWindowDimensions(WindowType::SPLASH)).render();
    _GFX.endFrame();

    winManager.mainWindowType(windowType);
    Console::printfn(Locale::get(_ID("START_SOUND_INTERFACE")));
    if ((initError = _SFX.initAudioAPI()) != ErrorCode::NO_ERR) {
        return initError;
    }

    Console::printfn(Locale::get(_ID("START_PHYSICS_INTERFACE")));
    if ((initError = _PFX.initPhysicsAPI(Config::TARGET_FRAME_RATE)) !=
        ErrorCode::NO_ERR) {
        return initError;
    }

    // Bind the kernel with the input interface
     if ((initError = Input::InputInterface::getInstance().init(*this)) !=
        ErrorCode::NO_ERR) {
        return initError;
    }

    LightManager::getInstance().init();

    // Initialize GUI with our current resolution
    _GUI.init(resolution);
    _sceneMgr.init(&_GUI);

    if (!_sceneMgr.load(startupScene, resolution)) {  //< Load the scene
        Console::errorfn(Locale::get(_ID("ERROR_SCENE_LOAD")), startupScene.c_str());
        return ErrorCode::MISSING_SCENE_DATA;
    }

    if (!_sceneMgr.checkLoadFlag()) {
        Console::errorfn(Locale::get(_ID("ERROR_SCENE_LOAD_NOT_CALLED")),
                         startupScene.c_str());
        return ErrorCode::MISSING_SCENE_LOAD_CALL;
    }

    _mainCamera->setMoveSpeedFactor(par.getParam<F32>("options.cameraSpeed.move"));
    _mainCamera->setTurnSpeedFactor(par.getParam<F32>("options.cameraSpeed.turn"));

    Console::printfn(Locale::get(_ID("INITIAL_DATA_LOADED")));
    Console::printfn(Locale::get(_ID("CREATE_AI_ENTITIES_START")));
    // Initialize and start the AI
    _sceneMgr.initializeAI(true);
    Console::printfn(Locale::get(_ID("CREATE_AI_ENTITIES_END")));

    return initError;
}

void Kernel::runLogicLoop() {
    Console::printfn(Locale::get(_ID("START_RENDER_LOOP")));
    _timingData._nextGameTick = Time::ElapsedMicroseconds();
    // lock the scene
    GET_ACTIVE_SCENE().state().runningState(true);
    // The first loops compiles all the visible data, so do not render the first
    // couple of frames
    firstLoop();

    _timingData._keepAlive = true;
    _APP.mainLoopActive(true);
    Console::printfn(Locale::get(_ID("START_MAIN_LOOP")));
    while (_APP.mainLoopActive()) {
        mainLoopApp();
    }

    shutdown();
}

void Kernel::shutdown() {
    Console::printfn(Locale::get(_ID("STOP_KERNEL")));
    _mainTaskPool.clear();
    WAIT_FOR_CONDITION(_mainTaskPool.active() == 0);

    // release the scene
    GET_ACTIVE_SCENE().state().runningState(false);
    Console::bindConsoleOutput(std::function<void(const char*, bool)>());
    GUI::destroyInstance();  /// Deactivate GUI
    _sceneMgr.unloadCurrentScene();
    SceneManager::destroyInstance();
    // Close CEGUI
    try {
        CEGUI::System::destroy();
    } catch (...) {
        Console::d_errorfn(Locale::get(_ID("ERROR_CEGUI_DESTROY")));
    }
    _cameraMgr.reset(nullptr);
    LightManager::destroyInstance();
    Console::printfn(Locale::get(_ID("STOP_ENGINE_OK")));
    Console::printfn(Locale::get(_ID("STOP_PHYSICS_INTERFACE")));
    _PFX.closePhysicsAPI();
    PXDevice::destroyInstance();
    Console::printfn(Locale::get(_ID("STOP_HARDWARE")));
    OpenCLInterface::getInstance().deinit();
    _SFX.closeAudioAPI();
    _GFX.closeRenderingAPI();
    Input::InputInterface::destroyInstance();
    SFXDevice::destroyInstance();
    GFXDevice::destroyInstance();
    ResourceCache::destroyInstance();
    // Destroy the shader manager AFTER the resource cache
    ShaderManager::destroyInstance();
    FrameListenerManager::destroyInstance();
        
   
    Time::REMOVE_TIMER(s_appLoopTimer);
}

void Kernel::onChangeWindowSize(U16 w, U16 h) {
    if (Input::InputInterface::getInstance().isInit()) {
        const OIS::MouseState& ms = Input::InputInterface::getInstance().getMouse().getMouseState();
        ms.width = w;
        ms.height = h;
    }

    CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Sizef(w, h));

    if (_mainCamera) {
        _mainCamera->setAspectRatio(to_float(w) / to_float(h));
    }
}

///--------------------------Input
/// Management-------------------------------------///

bool Kernel::setCursorPosition(I32 x, I32 y) const {
    _GFX.setCursorPosition(x, y);
    _GUI.setCursorPosition(x, y);
    return true;
}

bool Kernel::onKeyDown(const Input::KeyEvent& key) {
    if (_GUI.onKeyDown(key)) {
        return _sceneMgr.onKeyDown(key);
    }
    return true;  //< InputInterface needs to know when this is completed
}

bool Kernel::onKeyUp(const Input::KeyEvent& key) {
    if (_GUI.onKeyUp(key)) {
        return _sceneMgr.onKeyUp(key);
    }
    // InputInterface needs to know when this is completed
    return false;
}

bool Kernel::mouseMoved(const Input::MouseEvent& arg) {
    _cameraMgr->mouseMoved(arg);
    if (_GUI.mouseMoved(arg)) {
        return _sceneMgr.mouseMoved(arg);
    }
    // InputInterface needs to know when this is completed
    return false;
}

bool Kernel::mouseButtonPressed(const Input::MouseEvent& arg,
                                Input::MouseButton button) {
    if (_GUI.mouseButtonPressed(arg, button)) {
        return _sceneMgr.mouseButtonPressed(arg, button);
    }
    // InputInterface needs to know when this is completed
    return false;
}

bool Kernel::mouseButtonReleased(const Input::MouseEvent& arg,
                                 Input::MouseButton button) {
    if (_GUI.mouseButtonReleased(arg, button)) {
        return _sceneMgr.mouseButtonReleased(arg, button);
    }
    // InputInterface needs to know when this is completed
    return false;
}

bool Kernel::joystickAxisMoved(const Input::JoystickEvent& arg, I8 axis) {
    if (_GUI.joystickAxisMoved(arg, axis)) {
        return _sceneMgr.joystickAxisMoved(arg, axis);
    }
    // InputInterface needs to know when this is completed
    return false;
}

bool Kernel::joystickPovMoved(const Input::JoystickEvent& arg, I8 pov) {
    if (_GUI.joystickPovMoved(arg, pov)) {
        return _sceneMgr.joystickPovMoved(arg, pov);
    }
    // InputInterface needs to know when this is completed
    return false;
}

bool Kernel::joystickButtonPressed(const Input::JoystickEvent& arg,
                                   Input::JoystickButton button) {
    if (_GUI.joystickButtonPressed(arg, button)) {
        return _sceneMgr.joystickButtonPressed(arg, button);
    }
    // InputInterface needs to know when this is completed
    return false;
}

bool Kernel::joystickButtonReleased(const Input::JoystickEvent& arg,
                                    Input::JoystickButton button) {
    if (_GUI.joystickButtonReleased(arg, button)) {
        return _sceneMgr.joystickButtonReleased(arg, button);
    }
    // InputInterface needs to know when this is completed
    return false;
}

bool Kernel::joystickSliderMoved(const Input::JoystickEvent& arg, I8 index) {
    if (_GUI.joystickSliderMoved(arg, index)) {
        return _sceneMgr.joystickSliderMoved(arg, index);
    }
    // InputInterface needs to know when this is completed
    return false;
}

bool Kernel::joystickVector3DMoved(const Input::JoystickEvent& arg, I8 index) {
    if (_GUI.joystickVector3DMoved(arg, index)) {
        return _sceneMgr.joystickVector3DMoved(arg, index);
    }
    // InputInterface needs to know when this is completed
    return false;
}
};

Commits for Divide-Framework/trunk/Source Code/Core/Kernel.cpp

Diff revisions: vs.
Revision Author Commited Message
631 Diff Diff IonutCava picture IonutCava Sun 24 Jan, 2016 20:28:21 +0000

[IonutCava]
- Fix and optimize particle rendering system
- Temporarily disable Z_PRE_PASS system for testing
- Improve thread pool destruction system a bit
- Fix texture loading when used as fb attachment
- Forward+ renderer now takes the entire light buffer (no need to split up by light type)
- Start work on occlusion culling fixes:
— ToDo: Take into account batching system
— Fix gl_DrawIDARB usage

630 Diff Diff IonutCava picture IonutCava Fri 22 Jan, 2016 17:15:44 +0000

[IonutCava]
- Improve reflection generation system
— Still buggy
- Investigate occlusion culling issue
— Still buggy
- Improve threadpool idle time using main app time and conservative thread sleep calls

629 Diff Diff IonutCava picture IonutCava Thu 21 Jan, 2016 17:08:04 +0000

[IonutCava]
- New environment mapping system:
— Use previous frame’s list of nodes sorted front to back
— Update reflection for each if they meet the necessary criteria
- Cleanup particle system classes
- Cleanup GenericVertexData class
- Improve argument forwarding to frustum culling tasks

622 Diff Diff IonutCava picture IonutCava Thu 14 Jan, 2016 17:18:49 +0000

[IonutCava]
- Remove onCameraUpdate call from LightManager and SceneGraph as it’s not needed
- Remove special threading handlers from Resource class as very few derived classes use them for now
— Use ResourceState to check current loading state
- Use insertion sort for particles as most entries should already be sorted from the previous frame
- Use async RenderBin sorting system

621 Diff Diff IonutCava picture IonutCava Tue 12 Jan, 2016 16:39:50 +0000

[IonutCava]
- Terrain rendering updates
- Framebuffer optimizations

613 Diff Diff IonutCava picture IonutCava Sun 20 Dec, 2015 19:30:47 +0000

[IonutCava]
- Merge DEPTH and SCREEN render targets
- Use new anaglyph method:
— Render scene as usual for first pass and apply postFX
— If anaglyph enabled:
-— Blit screen target to anaglyph target
-— Render scene with IoD distance set for second pass and apply PostFX
-— Render scene with SCREEN and ANAGLYPH bound and anaglyphEnabled uniform set to true
— If anaglyph disabled:
-— Render scene with SCREEN and (non-blitted) ANAGLYPH bound and anaglyphEnabled uniform set to false

612 Diff Diff IonutCava picture IonutCava Sun 20 Dec, 2015 17:47:26 +0000

[IonutCava]
- Z-PrePass system improvements
— Depth only rendertarget and both eye render targets (screen and anaglyph) share the same depth buffer
— Screen render targets don’t clear or write the/to the depth buffer

604 Diff Diff IonutCava picture IonutCava Sun 13 Dec, 2015 19:04:57 +0000

[IonutCava]
- New post processing system:
— Simplified operators
— PostFX is always enabled. Individual operators are toggles on or off
— Fixed Bloom and adaptive exposure
- Reworked texture creation and resizing
— Saved TextureDescriptor as part of the texture state

601 Diff Diff IonutCava picture IonutCava Wed 09 Dec, 2015 17:12:38 +0000

[IonutCava]
- Shadow mapping system improvements:
— Point and spot light support
— Variable number of debug preview planes
- Light impostor rendering fix and update:
— Displays coloured icons for point and spot lights
- Camera system improvement:
— Camera manager is the only class allowed to instantiate new cameras
- Initial dual paraboloid rendering code
- Remove discard statements from shader code (should use blending if visual artefacts are encountered)

577 IonutCava picture IonutCava Fri 20 Nov, 2015 15:59:10 +0000

[IonutCava]
- Replace all string indexed maps with unsigned long long indexed maps and add both compile time and runtime hashing functions to convert strings to the proper indices
— Balancing the calls between _ID and _ID_RT can reduce map lookup overhead, especially with ParamHandler and Locale::get