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 struct IVideoDecoderContext *videoDecoderContext = nullptr;
238 struct IVideoEncoderContext *videoEncoderContext = nullptr;
239
240 class AssetSystem * assetSystem = nullptr;
241 class PropertiesSystem * propertiesSystem = nullptr;
242 class TrajectorySystem * trajectorySystem = nullptr;
243 class ModelSystem * modelSystem = nullptr;
244 class InstancedModelSystem * instancedModelSystem = nullptr;
245 class StaticModelSystem * staticModelSystem = nullptr;
246 class LodSystem * lodSystem = nullptr;
247 class AnimationSystem * animationSystem = nullptr;
248 class ScriptSystem * scriptSystem = nullptr;
249 class CameraSystem * cameraSystem = nullptr;
250 class CameraArraySystem* cameraArraySystem = nullptr;
251 class ClipShapeSystem* clipShapeSystem = nullptr;
252 class ClipShapeRefSystem* clipShapeRefSystem = nullptr;
253 class BillboardSystem * billboardSystem = nullptr;
254 class LightSystem * lightSystem = nullptr;
255 class FogSystem * fogSystem = nullptr;
256 class EnvironmentSystem * environmentSystem = nullptr;
257 class BasicOceanSystem * basicOceanSystem = nullptr;
258 class TextSystem * textSystem = nullptr;
259 class Text3DSystem * text3DSystem = nullptr;
260 class OverlaySystem * overlaySystem = nullptr;
261 class AdaptivePlanarGridSystem * adaptivePlanarGridSystem = nullptr;
262 class SpriteRenderSystem * spriteRenderSystem = nullptr;
263 class CaptureSystem * captureSystem = nullptr;
264 class MaterialSystem * materialSystem = nullptr;
265
266 class DynamicComponentSystem * dynamicComponentSystem = nullptr;
267
268 class BufferManager * bufferManager = nullptr;
269 class TextureManager * textureManager = nullptr;
270 class IBlueNoiseManager * blueNoiseManager = nullptr;
271 class AnimationManager * animationManager = nullptr;
272 class MeshManager * meshManager = nullptr;
273 class ModelManager * modelManager = nullptr;
274 class EffectManager * effectManager = nullptr;
275 class MaterialManager * materialManager = nullptr;
276 class MaterialDefinitionManager * materialDefinitionManager = nullptr;
277 class MaterialInstanceManager * materialInstanceManager = nullptr;
278 class FontManager * fontManager = nullptr;
279 class AssetManager * assetManager = nullptr;
280 void * sharedSurface = nullptr;
281
283
289 struct Debug
290 {
292 bool enableExecutionChecks = false;
293
295 std::string miniDumpPath = "./";
296
298 std::string miniDumpName = "Cogs";
299 } debug;
300
305 {
306 ResourceLoadCallback* resourceLoadCallback = nullptr;
307 HierarchyChangeCallback* hierarchyChangeCallback = nullptr;
308 RenderCallback* postSystemsUpdateCallback = nullptr;
309 RenderCallback* preRenderCallback = nullptr;
310 RenderCallback* postRenderCallback = nullptr;
311 ReadbackCallback* readbackCallback = nullptr;
312 ComponentNotifyCallback* componentNotifyCallback = nullptr;
313
314 std::list<ReadbackCallbackInternal*> readbackCallbackInternal;
315
316 } callbacks;
317
318 private:
319 ViewContext* defaultView = nullptr;
320 std::vector<ViewContext*> views;
321 };
322 }
323}
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:143
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:35
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:24
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:305
Debugging context.
Definition: Context.h:290