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

#include "WindowManager.h"
#include <thread>

namespace Divide {

enum class ErrorCode : I32 {
    NO_ERR = 0,
    MISSING_SCENE_DATA = -1,
    MISSING_SCENE_LOAD_CALL = -2,
    CPU_NOT_SUPPORTED = -3,
    GFX_NOT_SUPPORTED = -4,
    GFX_NON_SPECIFIED = -5,
    SFX_NON_SPECIFIED = -6,
    PFX_NON_SPECIFIED = -7,
    WINDOW_INIT_ERROR = -8,
    SDL_WINDOW_INIT_ERROR = -9,
    FONT_INIT_ERROR = -10,
    GLBINGING_INIT_ERROR = -11,
    GLSL_INIT_ERROR = -12,
    GL_OLD_HARDWARE = -13,
    DX_INIT_ERROR = -14,
    DX_OLD_HARDWARE = -15,
    OGL_OLD_HARDWARE = -16,
    SDL_AUDIO_INIT_ERROR = -17,
    SDL_AUDIO_MIX_INIT_ERROR = -18,
    FMOD_AUDIO_INIT_ERROR = -19,
    OAL_INIT_ERROR = -20,
    OCL_INIT_ERROR = -21,
    PHYSX_INIT_ERROR = -22,
    PHYSX_EXTENSION_ERROR = -23,
    NO_LANGUAGE_INI = -24,
    NOT_ENOUGH_RAM = -25,
    PLATFORM_INIT_ERROR = -26,
    PLATFORM_CLOSE_ERROR = -27
};

class Task;
class Kernel;
const char* getErrorCodeName(ErrorCode code);
  
namespace Attorney {
    class ApplicationTask;
};

/// Lightweight singleton class that manages our application's kernel and window
/// information
DEFINE_SINGLETON(Application)
    friend class Attorney::ApplicationTask;
  public:
    static bool initStaticData();
    /// Startup and shutdown
    ErrorCode initialize(const stringImpl& entryPoint, I32 argc, char** argv);
    void run();
    bool onLoop();

    inline void RequestShutdown();
    inline void CancelShutdown();
    inline bool ShutdownRequested() const;

    inline Kernel& kernel() const;
    inline WindowManager& windowManager();
    inline const WindowManager& windowManager() const;

    bool             isMainThread() const;
    std::thread::id  mainThreadID() const;
    void mainThreadTask(const DELEGATE_CBK<>& task, bool wait = true);

    inline void setMemoryLogFile(const stringImpl& fileName);

    inline bool mainLoopActive() const;
    inline void mainLoopActive(bool state);

    inline bool mainLoopPaused() const;
    inline void mainLoopPaused(bool state);

    void onChangeWindowSize(U16 w, U16 h) const;
    void onChangeRenderResolution(U16 w, U16 h) const;

    void setCursorPosition(I32 x, I32 y) const;
    inline void snapCursorToCenter() const;
        
    inline void throwError(ErrorCode err);
    inline ErrorCode errorCode() const;

    inline SysInfo& sysInfo();
    inline const SysInfo& sysInfo() const;
    /// Add a list of callback functions that should be called when the application
    /// instance is destroyed
    /// (release hardware, file handlers, etc)
    inline void registerShutdownCallback(const DELEGATE_CBK<>& cbk);

  private:
    Application();
    ~Application();

  private:
    SysInfo _sysInfo;
    WindowManager _windowManager;
     
    ErrorCode _errorCode;
    /// this is true when we are inside the main app loop
    std::atomic_bool _mainLoopActive;
    std::atomic_bool _mainLoopPaused;
    std::atomic_bool _requestShutdown;
    Kernel* _kernel;
    /// buffer to register all of the memory allocations recorded via
    /// "MemoryManager_NEW"
    stringImpl _memLogBuffer;
    /// Main application thread ID
    std::thread::id _threadID;
    /// A list of callback functions that get called when the application instance
    /// is destroyed
    vectorImpl<DELEGATE_CBK<> > _shutdownCallback;

    /// A list of callbacks to execute on the main thread
    mutable SharedLock _taskLock;
    vectorImpl<DELEGATE_CBK<> > _mainThreadCallbacks;
END_SINGLETON

namespace Attorney {
    class ApplicationTask {
    private:
        // threadID = calling thread
        // beginSync = true, called before thread processes data / false, called when thread finished processing data
        static void syncThreadToGPU(std::thread::id threadID, bool beginSync);

        friend class Divide::Task;
    };
};  // namespace Attorney

};  // namespace Divide

#endif  //_CORE_APPLICATION_H_

#include "Application.inl"

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

Diff revisions: vs.
Revision Author Commited Message
737 Diff Diff IonutCava picture IonutCava Thu 23 Jun, 2016 16:20:05 +0000

[IonutCava]
- Improved GenericVertexData structure (separate buffer data from attribute data entirely)
- Added a VAO pool for OpenGL so that all requested VAOs are allocated on the main thread
- Added a mainThreadTask system to queue a task to run on the main thread and optionally wait for it to complete
- Added the option to specify generic geometry for the particle system with an optional index buffer

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

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

686 Diff Diff IonutCava picture IonutCava Thu 21 Apr, 2016 16:24:19 +0000

[IonutCava]
- Refactor the scene self-registering system to prevent linker related issues
- Add a SGNRelationshipCache class that can quickly verify if any 2 given nodes are related in any way
— This should speed up Octree updates by a lot

note: The template refactoring code has significantly slowed down performance for reasons yet unknown. Investigating.

669 Diff Diff IonutCava picture IonutCava Mon 04 Apr, 2016 16:15:35 +0000

[IonutCava]
- Move Task creation calls to TaskPool.h
- Allow tasks to use any pool, but default behaviour is to use the Kernel’s main task pool
- Change image transparency check to use the task pool instead of OpenMP
— Perfect place for future parallel_for implementation
- Warning fixes
- Some method renaming for improved readability

660 Diff Diff IonutCava picture IonutCava Mon 21 Mar, 2016 17:11:19 +0000

[IonutCava]
- Finish Parent<->Children thread pool system
- Use new thread pool system for most multithreaded tasks in the engine: culling, sorting, light preparation, etc
- Add platform specific init/close calls at the start and end of the main function for future use

656 Diff Diff IonutCava picture IonutCava Fri 04 Mar, 2016 17:23:26 +0000

[Ionut]
- Separate resolution from window size
— Still buggy

655 Diff Diff IonutCava picture IonutCava Wed 02 Mar, 2016 17:22:28 +0000

[IonutCava]
- Rebalance responsibilities between Kernel and Application
— Application handles the main loop and calls the appropriate kernel methods

654 IonutCava picture IonutCava Tue 01 Mar, 2016 17:22:09 +0000

[Ionut]
- Moved window related code from rendering API code into proper classes:
— DisplayWindow handles SDL based window management
— WindowManager handles multiple DisplayWindow instances
— Code still needs proper extensive testing
- Small performance optimizations