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
/*
   Copyright (c) 2015 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 "Core/Headers/Application.h"
#include "Managers/Headers/CameraManager.h"
#include "Platform/Threading/Headers/Task.h"
#include "Platform/Input/Headers/InputAggregatorInterface.h"

namespace Divide {

class Scene;
class PXDevice;
class GFXDevice;
class SFXDevice;
class Application;
class LightManager;
class SceneManager;
class ShaderManager;
class InputInterface;
class SceneRenderState;
class FrameListenerManager;

enum RenderStage : I32;

struct FrameEvent;
class GUI;

/// The kernel is the main interface to our engine components:
///-video
///-audio
///-physx
///-scene manager
///-etc
class Kernel : public Input::InputAggregatorInterface, private NonCopyable {
   public:
    Kernel(I32 argc, char** argv, Application& parentApp);
    ~Kernel();

    ErrorCode initialize(const stringImpl& entryPoint);

    void runLogicLoop();
    /// Our main application rendering loop.
    /// Call input requests, physics calculations, pre-rendering,
    /// rendering,post-rendering etc
    static void mainLoopApp();
    /// 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)
    static void idle();
    /// Update all engine components that depend on the current resolution
    static void updateResolutionCallback(I32 w, I32 h);

    GFXDevice& getGFXDevice() const { return _GFX; }
    SFXDevice& getSFXDevice() const { return _SFX; }
    PXDevice& getPXDevice() const { return _PFX; }
    /// Get elapsed time since kernel initialization
    inline U64 getCurrentTime() const { return _currentTime; }
    inline U64 getCurrentTimeDelta() const { return _currentTimeDelta; }
    /// Get a pointer to the kernel's threadpool to add,remove,pause or stop
    /// tasks
    inline boost::threadpool::pool* const getThreadPool() {
        assert(_mainTaskPool != nullptr);
        return _mainTaskPool;
    }

    CameraManager& getCameraMgr() { return *_cameraMgr; }

    bool setCursorPosition(U16 x, U16 y) const;
    /// 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, I8 button);
    /// Joystick button released
    bool joystickButtonReleased(const Input::JoystickEvent& arg, I8 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);

    Task* AddTask(
        U64 tickInterval, I32 numberOfTicks,
        const DELEGATE_CBK<>& threadedFunction,
        const DELEGATE_CBK<>& onCompletionFunction = DELEGATE_CBK<>());

   private:
    static void firstLoop();
    void shutdown();
    void renderScene();
    void renderSceneAnaglyph();
    bool mainLoopScene(FrameEvent& evt);
    bool presentToScreen(FrameEvent& evt);
    void threadPoolCompleted(U64 onExitTaskID);

   private:
    friend class SceneManager;
    void submitRenderCall(const RenderStage& stage,
                          const SceneRenderState& sceneRenderState,
                          const DELEGATE_CBK<>& sceneRenderCallback) const;

   private:
    Application& _APP;
    /// Access to the GPU
    GFXDevice& _GFX;
    /// Access to the audio device
    SFXDevice& _SFX;
    /// Access to the physics system
    PXDevice& _PFX;
    /// The graphical user interface
    GUI& _GUI;
    /// The input interface
    Input::InputInterface& _input;
    /// The SceneManager/ Scene Pool
    SceneManager& _sceneMgr;
    /// Keep track of all active cameras used by the engine
    std::unique_ptr<CameraManager> _cameraMgr;

    static bool _keepAlive;
    static bool _renderingPaused;
    static bool _freezeLoopTime;
    static bool _freezeGUITime;
    boost::threadpool::pool* _mainTaskPool;
    // both are in ms
    static U64 _currentTime;
    static U64 _currentTimeFrozen;
    static U64 _currentTimeDelta;
    static U64 _previousTime;
    static D32 _nextGameTick;

    static SharedLock _threadedCallbackLock;
    static vectorImpl<U64> _threadedCallbackBuffer;
    static hashMapImpl<U64, DELEGATE_CBK<> > _threadedCallbackFunctions;

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

};  // namespace Divide

#endif  //_CORE_KERNEL_H_

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

Diff revisions: vs.
Revision Author Commited Message
350 Diff Diff IonutCava picture IonutCava Tue 10 Feb, 2015 16:25:39 +0000

[Ionut]
- Simplified some Util-namespace level functions by using STL algorithms where possible
- Formatted the entire codebase using clang-format with the following style: "{BasedOnStyle: Google, IndentWidth: 4}"
- Attempted to make ProfileTimer thread-safe (temp fix until std::chrono works properly in Visual Studio)

349 Diff Diff IonutCava picture IonutCava Fri 06 Feb, 2015 17:11:39 +0000

[Ionut]
- More raw pointer replacements
- Removed some redundant parameters to a few scene and application functions

343 Diff Diff IonutCava picture IonutCava Thu 15 Jan, 2015 17:30:12 +0000

[Ionut]
- Refactored 2 singletons into static classes (Console and TerrainLoader)
- Changed some C-casts to static_casts
- Updated copyright notices

337 Diff Diff IonutCava picture IonutCava Wed 17 Dec, 2014 17:25:16 +0000

[Ionut]
- Replaced all tabs with 4 spaces (some spacing may be off now. no way to check all the files.)
- Moved implementation details for ParamHandler, BoundingBox, BoundingSphere and ProfileTimer to proper .inl and .cpp files. (more to follow)
- Update all forward declared enums with the required storage type (as requested by the C++11 standard)

334 Diff Diff IonutCava picture IonutCava Wed 10 Dec, 2014 17:21:22 +0000

[Ionut]
- Reorganized the Hardware project and renamed to "Platform"
- Reorganized the Server project

333 Diff Diff IonutCava picture IonutCava Tue 09 Dec, 2014 16:15:44 +0000

[Ionut]
- Removed “core.h” and moved everything to their appropriate header files
- Renamed MathClasses to MathMatrices (finally)
- Renamed “-Inl.h” files to ".inl"
- Some String wrapper refactoring
- Update “InstallLibraries.bat” so that it still offers valid options

331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

326 Diff Diff IonutCava picture IonutCava Tue 30 Sep, 2014 21:11:32 +0000

[Ionut]
- Fixed more memory leaks
- Simplified Task interface and timing System
- Improved compatibility between Boost, STL and EASTL with random combinations of vectors, strings and maps
- Simplified Light class by removing the “slot” member
- Random optimizations

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

321 IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)