Cogs.Core
Context.h
1#pragma once
2
3#include "Base.h"
4#include "EntityPtr.h"
5
6#include <list>
7#include <span>
8
9namespace Cogs
10{
11 struct WindowData;
12 class FileSystemWatcher;
13 class IGraphicsDevice;
14
15 namespace Platform
16 {
17 class GamepadHandler;
18 }
19
20 namespace Core
21 {
22 struct CameraData;
23 class Time;
24 class ViewContext;
25
29 typedef void ResourceLoadCallback(class Context * context, int resourceType, ResourceId id, int code);
30
34 typedef void HierarchyChangeCallback(class Context * context, EntityId entityId);
35
36 typedef void RenderCallback(class Context * context);
37
38 typedef void ReadbackCallback(class Context * context, const char * key, const void * data, int size);
39
40 typedef void ReadbackCallbackInternal(class Context* context, const CameraData *, uint32_t frame, const char * key, const void * data, int size);
41
42 typedef void MessageCallback(int messageId, const void * data);
43
54 typedef void ComponentNotifyCallback(BridgeContext* context, int componentTypeId, size_t entityId, int notification, const void* data, size_t dataSize);
55
59 class COGSCORE_DLL_API ContextBase
60 {
61 public:
62 virtual ~ContextBase() = default;
63
64 class TransformSystem * transformSystem = nullptr;
65 class SceneSystem * sceneSystem = nullptr;
66 class MeshSystem * meshSystem = nullptr;
67 class RenderSystem * renderSystem = nullptr;
68 class SubMeshRenderSystem * subMeshRenderSystem = nullptr;
69 class InstancedMeshRenderSystem * instancedMeshRenderSystem = nullptr;
70 };
71
82 class COGSCORE_DLL_API Context : public ContextBase
83 {
84 public:
96 Context(const char ** variables, int count);
97 Context();
98
102 ~Context() override;
103
110 static void initializeStatic();
111
115 static void cleanupStatic();
116
117 bool createDevice();
118
123 void initialize();
124
128 void clear();
129
134 void initializeDynamicComponents();
135
141 void registerDynamicComponentType(const StringView & typeName);
142
149 void registerExtensionSystem(const uint16_t id, class ComponentSystemBase * system);
150
158 class ComponentSystemBase * getExtensionSystem(const uint16_t id);
159
160 void update();
161 void preRender();
162
163 ViewContext* createView(WindowData* windowData);
164 void deleteView(ViewContext* view);
165
166 void setDefaultView(ViewContext* view) { defaultView = view; }
167 ViewContext* getDefaultView() const { return defaultView; }
168 std::span<ViewContext*> getViews() { return views; }
169
171 std::unique_ptr<struct MemoryContext> memory;
172
174 std::unique_ptr<class Services> services;
175
177 std::unique_ptr<class Features> features;
178
180 std::unique_ptr<class Variables> variables;
181
183 std::unique_ptr<class ResourceUsageLogger> resourceUsageLogger;
184
186 std::unique_ptr<class TaskManager> taskManager;
187
189 std::unique_ptr<class Random> random;
190
192 std::unique_ptr<class ScriptingManager> scriptingManager;
193
195 std::unique_ptr<class CullingManager> cullingManager;
196
198 std::unique_ptr<class Time> time;
199
201 std::unique_ptr<class QualityService> qualityService;
202
204 std::unique_ptr<class DeferredNameResolution> deferredResolution;
205
207 std::unique_ptr<FileSystemWatcher> watcher;
208
210 std::unique_ptr<class ResourceStore> resourceStore;
211
213 std::unique_ptr<class RayPicking> rayPicking;
214
216 std::unique_ptr<class Bounds> bounds;
217
219 std::unique_ptr<class ExtensionSystems> extensionSystems;
220
222 std::unique_ptr<class Engine> engine;
223
225 std::unique_ptr<class Scene> scene;
226
229
232
234
235 IGraphicsDevice * device = nullptr;
236
237 class AssetSystem * assetSystem = nullptr;
238 class PropertiesSystem * propertiesSystem = nullptr;
239 class TrajectorySystem * trajectorySystem = nullptr;
240 class ModelSystem * modelSystem = nullptr;
241 class InstancedModelSystem * instancedModelSystem = nullptr;
242 class StaticModelSystem * staticModelSystem = nullptr;
243 class LodSystem * lodSystem = nullptr;
244 class AnimationSystem * animationSystem = nullptr;
245 class ScriptSystem * scriptSystem = nullptr;
246 class CameraSystem * cameraSystem = nullptr;
247 class CameraArraySystem* cameraArraySystem = nullptr;
248 class ClipShapeSystem* clipShapeSystem = nullptr;
249 class ClipShapeRefSystem* clipShapeRefSystem = nullptr;
250 class BillboardSystem * billboardSystem = nullptr;
251 class LightSystem * lightSystem = nullptr;
252 class FogSystem * fogSystem = nullptr;
253 class EnvironmentSystem * environmentSystem = nullptr;
254 class BasicOceanSystem * basicOceanSystem = nullptr;
255 class TextSystem * textSystem = nullptr;
256 class Text3DSystem * text3DSystem = nullptr;
257 class OverlaySystem * overlaySystem = nullptr;
258 class AdaptivePlanarGridSystem * adaptivePlanarGridSystem = nullptr;
259 class SpriteRenderSystem * spriteRenderSystem = nullptr;
260 class CaptureSystem * captureSystem = nullptr;
261 class MaterialSystem * materialSystem = nullptr;
262
263 class DynamicComponentSystem * dynamicComponentSystem = nullptr;
264
265 class BufferManager * bufferManager = nullptr;
266 class TextureManager * textureManager = nullptr;
267 class IBlueNoiseManager * blueNoiseManager = nullptr;
268 class AnimationManager * animationManager = nullptr;
269 class MeshManager * meshManager = nullptr;
270 class ModelManager * modelManager = nullptr;
271 class EffectManager * effectManager = nullptr;
272 class MaterialManager * materialManager = nullptr;
273 class MaterialDefinitionManager * materialDefinitionManager = nullptr;
274 class MaterialInstanceManager * materialInstanceManager = nullptr;
275 class FontManager * fontManager = nullptr;
276 class AssetManager * assetManager = nullptr;
277 void * sharedSurface = nullptr;
278
280
286 struct Debug
287 {
289 bool enableExecutionChecks = false;
290
292 std::string miniDumpPath = "./";
293
295 std::string miniDumpName = "Cogs";
296 } debug;
297
302 {
303 ResourceLoadCallback* resourceLoadCallback = nullptr;
304 HierarchyChangeCallback* hierarchyChangeCallback = nullptr;
305 RenderCallback* postSystemsUpdateCallback = nullptr;
306 RenderCallback* preRenderCallback = nullptr;
307 RenderCallback* postRenderCallback = nullptr;
308 ReadbackCallback* readbackCallback = nullptr;
309 ComponentNotifyCallback* componentNotifyCallback = nullptr;
310
311 std::list<ReadbackCallbackInternal*> readbackCallbackInternal;
312
313 } callbacks;
314
315 private:
316 ViewContext* defaultView = nullptr;
317 std::vector<ViewContext*> views;
318 };
319 }
320}
The billboard system calculates data for billboard components found in the scene.
The camera system computes CameraData for every CameraDataComponent in the engine.
Definition: CameraSystem.h:144
Base class for component systems.
Context base contains the parts of a Context that may be instantiated by static scene or model instan...
Definition: Context.h:60
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
std::unique_ptr< class Services > services
Services.
Definition: Context.h:174
std::unique_ptr< class CullingManager > cullingManager
CullingManager instance.
Definition: Context.h:195
std::unique_ptr< class ScriptingManager > scriptingManager
ScriptingManager service instance.
Definition: Context.h:192
std::unique_ptr< class ExtensionSystems > extensionSystems
Mapping of active extension systems.
Definition: Context.h:219
class IRenderer * renderer
Renderer.
Definition: Context.h:228
std::unique_ptr< class Features > features
Features service instance.
Definition: Context.h:177
std::unique_ptr< class Random > random
Random Number service instance.
Definition: Context.h:189
std::unique_ptr< class Bounds > bounds
Bounds service instance.
Definition: Context.h:216
std::unique_ptr< class QualityService > qualityService
Quality service instance.
Definition: Context.h:201
class EntityStore * store
Entity store.
Definition: Context.h:231
std::unique_ptr< class ResourceUsageLogger > resourceUsageLogger
Resource usage logger service instance.
Definition: Context.h:183
std::unique_ptr< class RayPicking > rayPicking
RayPicking service instance.
Definition: Context.h:213
std::unique_ptr< struct MemoryContext > memory
Memory and allocation info.
Definition: Context.h:171
std::unique_ptr< class TaskManager > taskManager
TaskManager service instance.
Definition: Context.h:186
std::unique_ptr< class Variables > variables
Variables service instance.
Definition: Context.h:180
std::unique_ptr< class Time > time
Time service instance.
Definition: Context.h:198
std::unique_ptr< class DeferredNameResolution > deferredResolution
Deferred name resolution service instance.
Definition: Context.h:204
std::unique_ptr< class ResourceStore > resourceStore
ResourceStore service instance.
Definition: Context.h:210
std::unique_ptr< FileSystemWatcher > watcher
File system watcher.
Definition: Context.h:207
std::unique_ptr< class Engine > engine
Engine instance.
Definition: Context.h:222
std::unique_ptr< class Scene > scene
Scene structure.
Definition: Context.h:225
The dynamic component system handles instances of components derived from DynamicComponent.
Effect manager responsible for loading, processing and activating Effect resources.
Definition: EffectManager.h:32
Stores top level entities for the engine.
Definition: EntityStore.h:50
The fog system manages fog instances, in addition to special handling a single fog component as the g...
Definition: FogSystem.h:24
Font manager responsible for loading, processing and lifetime of Font resources.
Definition: FontManager.h:40
Renderer interface used by the engine to control registered renderer instances.
Definition: IRenderer.h:154
Holds all LightComponent instances in the system.
Definition: LightSystem.h:78
The LodSystem is responsible for calculating common basic level of detail data for all entities with ...
Definition: LodSystem.h:38
Material instance manager handles creation, processing and lifetime for MaterialInstance resources.
Material manager handling loading and processing of Material resources.
Updates material components.
Mesh manager handling the creation, processing and lifetime of Mesh resources.
Definition: MeshManager.h:18
Model manager responsible for loading, processing and lifetime for Model resources.
Definition: ModelManager.h:26
The overlay system handles OverlayComponent instances.
Definition: OverlaySystem.h:17
The mesh render system handles MeshRenderComponents.
Definition: RenderSystem.h:75
The scene system handles SceneComponent instances, managing hierarchical visibility and pickability b...
Definition: SceneSystem.h:24
The submesh render system handles SubMeshRenderComponents.
The 3D text system handles Text3DComponents.
Definition: Text3DSystem.h:16
The text system handles TextComponents.
Definition: TextSystem.h:20
Texture manager responsible for loading, processing, activation and lifetime of Texture resources.
The transform system handles TransformComponent instances, calculating local and global transform dat...
Represents a graphics device used to manage graphics resources and issue drawing commands.
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:50
void ResourceLoadCallback(class Context *context, int resourceType, ResourceId id, int code)
Resource loading callback.
Definition: Context.h:29
void HierarchyChangeCallback(class Context *context, EntityId entityId)
Hierarchy change callback.
Definition: Context.h:34
void ComponentNotifyCallback(BridgeContext *context, int componentTypeId, size_t entityId, int notification, const void *data, size_t dataSize)
Callback to receive component notifications.
Definition: Context.h:54
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
Contains data describing a Camera instance and its derived data structured such as matrix data and vi...
Definition: CameraSystem.h:67
Context callbacks.
Definition: Context.h:302
Debugging context.
Definition: Context.h:287