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
/*
   Copyright (c) 2017 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 _CORE_KERNEL_H_
#define _CORE_KERNEL_H_

#include "EngineTaskPool.h"
#include "Core/Headers/Application.h"
#include "Platform/Input/Headers/InputAggregatorInterface.h"

namespace Divide {

class Scene;
class Editor;
class PXDevice;
class GFXDevice;
class SFXDevice;
class Application;
class SceneManager;
class ResourceCache;
class PlatformContext;
class SceneRenderState;
class RenderPassManager;
class FrameListenerManager;

namespace Input {
    class InputInterface;
};

enum class RenderStage : U32;

struct FrameEvent;

class LoopTimingData {
  public:
    LoopTimingData();

    bool _keepAlive;
  
    inline void update(const U64 elapsedTimeUS) {
        _previousTimeUS = _currentTimeUS;
        _currentTimeUS = elapsedTimeUS;
        _currentTimeDeltaUS = _currentTimeUS - _previousTimeUS;

        // In case we break in the debugger
        if (_currentTimeDeltaUS > Time::SecondsToMicroseconds(1)) {
            _currentTimeDeltaUS = Time::SecondsToMicroseconds(1) / Config::TICKS_PER_SECOND;
            _previousTimeUS = _currentTimeUS - _currentTimeDeltaUS;
        }
    }

    // return true on change
    inline bool freezeTime(bool state) {
        if (_freezeLoopTime != state) {
            _freezeLoopTime = state;
            _currentTimeFrozenUS = _currentTimeUS;
            return true;
        }
        return false;
    }

    inline bool runUpdateLoop() {
        if (_currentTimeUS > _nextGameTickUS && _updateLoops < Config::MAX_FRAMESKIP) {
            return true;
        }

        _updateLoops = 0;
        return false;
    }

    inline void endUpdateLoop(const U64 deltaTimeUS) {
        _nextGameTickUS += deltaTimeUS;
        ++_updateLoops;

        if (Config::USE_FIXED_TIMESTEP) {
            if (_updateLoops == Config::MAX_FRAMESKIP && _currentTimeUS > _nextGameTickUS) {
                _nextGameTickUS = _currentTimeUS;
            }
        } else {
            _nextGameTickUS = _currentTimeUS;
        }
    }

    inline bool freezeTime() const {
        return _freezeLoopTime;
    }

    inline U64 currentTimeUS() const {
        return _currentTimeUS;
    }

    inline U64 currentTimeDeltaUS(bool ignoreFreeze = false) const {
        return (!ignoreFreeze && _freezeLoopTime) ? 0ULL : _currentTimeDeltaUS;
    }

    inline U64 nextGameTickUS() const {
        return _nextGameTickUS;
    }

    inline U8 updateLoops() const {
        return _updateLoops;
    }

  protected:
    // number of scene update loops
    U8 _updateLoops;
    bool _freezeLoopTime;
    U64 _currentTimeUS;
    U64 _currentTimeFrozenUS;
    U64 _currentTimeDeltaUS;
    U64 _previousTimeUS;
    U64 _nextGameTickUS;
};

namespace Attorney {
    class KernelApplication;
    class KernelWindowManager;
};

namespace Time {
    class ProfileTimer;
};

namespace Input {
    class InputInterface;
};

/// The kernel is the main interface to our engine components:
///-video
///-audio
///-physx
///-scene manager
///-etc
class Kernel : public Input::InputAggregatorInterface, private NonCopyable {
    friend class Attorney::KernelApplication;
    friend class Attorney::KernelWindowManager;

   public:
    Kernel(I32 argc, char** argv, Application& parentApp);
    ~Kernel();

    /// Our main application rendering loop.
    /// Call input requests, physics calculations, pre-rendering,
    /// rendering,post-rendering etc
    void onLoop();
    /// Called after a swap-buffer call and before a clear-buffer call.
    /// In a GPU-bound application, the CPU will wait on the GPU to finish
    /// processing the frame
    /// so this should keep it busy (old-GLUT heritage)
    void idle();
    
    /// Key pressed
    bool onKeyDown(const Input::KeyEvent& key);
    /// Key released
    bool onKeyUp(const Input::KeyEvent& key);
    /// Joystick 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 joystickvector3Moved(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);

    inline TaskPool& taskPool() {
        return _taskPool;
    }

    inline const TaskPool& taskPool() const {
        return _taskPool;
    }

    ResourceCache& resourceCache() {
        assert(_resCache != nullptr);
        return *_resCache;
    }

    const ResourceCache& resourceCache() const {
        assert(_resCache != nullptr);
        return *_resCache;
    }

    PlatformContext& platformContext() {
        assert(_platformContext != nullptr);
        return *_platformContext;
    }

    const PlatformContext& platformContext() const {
        assert(_platformContext != nullptr);
        return *_platformContext;
    }

    SceneManager& sceneManager() {
        assert(_sceneManager != nullptr);
        return *_sceneManager;
    }

    const SceneManager& sceneManager() const {
        assert(_sceneManager != nullptr);
        return *_sceneManager;
    }

    RenderPassManager& renderPassManager() {
        assert(_renderPassManager != nullptr);
        return *_renderPassManager;
    }

    const RenderPassManager& renderPassManager() const {
        assert(_renderPassManager != nullptr);
        return *_renderPassManager;
    }

   private:
    ErrorCode initialize(const stringImpl& entryPoint);
    void warmup();
    void shutdown();
    void startSplashScreen();
    void stopSplashScreen();
    bool mainLoopScene(FrameEvent& evt, const U64 deltaTimeUS);
    bool presentToScreen(FrameEvent& evt, const U64 deltaTimeUS);
    bool setCursorPosition(I32 x, I32 y) const;
    /// Update all engine components that depend on the current screen size
    void onSizeChange(const SizeChangeParams& params) const;

   private:
    std::unique_ptr<ResourceCache>     _resCache;
    std::unique_ptr<PlatformContext>   _platformContext;
    std::unique_ptr<SceneManager>      _sceneManager;
    std::unique_ptr<RenderPassManager> _renderPassManager;
    LoopTimingData _timingData;

    TaskPool _taskPool;

    Time::ProfileTimer& _appLoopTimer;
    Time::ProfileTimer& _frameTimer;
    Time::ProfileTimer& _appIdleTimer;
    Time::ProfileTimer& _appScenePass;
    Time::ProfileTimer& _physicsUpdateTimer;
    Time::ProfileTimer& _physicsProcessTimer;
    Time::ProfileTimer& _sceneUpdateTimer;
    Time::ProfileTimer& _sceneUpdateLoopTimer;
    Time::ProfileTimer& _cameraMgrTimer;
    Time::ProfileTimer& _flushToScreenTimer;
    Time::ProfileTimer& _preRenderTimer;
    Time::ProfileTimer& _postRenderTimer;
    vectorImpl<Time::ProfileTimer*> _renderTimer;
    vectorImpl<Time::ProfileTimer*> _postFxRenderTimer;
    vectorImpl<Time::ProfileTimer*> _blitToDisplayTimer;

    // Command line arguments
    I32 _argc;
    char** _argv;
};

namespace Attorney {
    class KernelApplication {
      protected:
        static ErrorCode initialize(Kernel& kernel, const stringImpl& entryPoint) {
            return kernel.initialize(entryPoint);
        }

        static void shutdown(Kernel& kernel) {
            kernel.shutdown();
        }

        static void onSizeChange(Kernel& kernel, const SizeChangeParams& params) {
            kernel.onSizeChange(params);
        }

        static void warmup(Kernel& kernel) {
            kernel.warmup();
        }

        static void onLoop(Kernel& kernel) {
            kernel.onLoop();
        }

        static void startSplashScreen(Kernel& kernel) {
            kernel.startSplashScreen();
        }

        static void stopSplashScreen(Kernel& kernel) {
            kernel.stopSplashScreen();
        }

        friend class Divide::Application;
        friend class Divide::Attorney::ApplicationTask;
    };

    class KernelWindowManager {
      protected:
        static bool setCursorPosition(Kernel& kernel, I32 x, I32 y) {
            return kernel.setCursorPosition(x, y);
        }

        friend class Divide::WindowManager;
    };
};

};  // namespace Divide

#endif  //_CORE_KERNEL_H_

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

Diff revisions: vs.
Revision Author Commited Message
978 Diff Diff IonutCava picture IonutCava Mon 20 Nov, 2017 23:42:23 +0000

[Ionut]
- More decoupling between window size and render resolution.
- Attempt to preserve render target aspect on window resize events

  • Resolution change is currently broken *
969 Diff Diff IonutCava picture IonutCava Mon 13 Nov, 2017 00:15:57 +0000

[Ionut]
- Further improve DisplayWindow <-> Input relationship
- Add Flip-Y 2D camera (D3D style projection)
- Fix IMGUI rendering
- Add IMGUI sample and IMWINDOW sample rendering at the same time
- Improve IMWINDOW multi-window support
— Bug: nothing rendering in child platform windows
- Add draw command to move render context from one window to another

968 Diff Diff IonutCava picture IonutCava Tue 07 Nov, 2017 17:32:31 +0000

[Ionut]
- Consistent naming between timing variables

962 Diff Diff IonutCava picture IonutCava Fri 03 Nov, 2017 17:17:55 +0000

[Ionut]
- Fix creation/destruction of multiple DisplayWindows
- Add an InputInterface per DisplayWindow
- More work on the ImWindow based Editor

960 Diff Diff IonutCava picture IonutCava Thu 02 Nov, 2017 17:39:53 +0000

[Ionut]
- Started porting ImWindow to our command buffer based rendering system.
- Also moved mouse positioning system to the window manager since mouse position is always relative to the active window

952 Diff Diff IonutCava picture IonutCava Wed 25 Oct, 2017 00:35:37 +0000

[Ionut]
- Added the CEGUI rendering project to our solution for easier modification, debugging and integration
- Updated to OIS 1.4
- Some updates to the WindowHandle struct

  • Only compiled in Debug*
909 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 23:57:18 +0000

[Ionut]
- Rework RenderTarget class
— RTAttachment now deal with textures directly
— RT size needs to be specified upfront
- Application class is no longer a Singleton but passed around in the PlatformContext

896 Diff Diff IonutCava picture IonutCava Thu 22 Jun, 2017 16:13:10 +0000

[Ionut]
- Add vs140 platform support
- Remove GPU sync options for tasks. This should be an API-level capability.

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

835 IonutCava picture IonutCava Fri 27 Jan, 2017 14:58:07 +0000

[IonutCava]
- Split Engine lib into Core and Engine lib.
- Fix Server build issues