Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
CSharpManager.hpp
1#pragma once
2
3#include <entt/entt.hpp>
4#include "mono/utils/mono-forward.h"
5#include "mono/metadata/image.h"
6#include "mono/metadata/metadata.h"
7
8#include "EngineCore/ECS/ComponentFunctions.hpp"
9
10namespace Grindstone {
11 class EngineCore;
12
13 namespace ECS {
14 class Entity;
15 }
16
17 namespace Scripting {
18 namespace CSharp {
19 struct ScriptComponent;
20 struct ScriptClass;
21
23 public:
24 struct AssemblyData {
25 MonoAssembly* assembly = nullptr;
26 MonoImage* image = nullptr;
27 };
28
29 static CSharpManager& GetInstance();
30 void Cleanup();
31 virtual void Initialize(EngineCore* engineCore);
32 virtual void CreateDomain();
33 virtual void LoadAssembly(const char* path, AssemblyData& outAssemblyData);
34 virtual void LoadAssemblyIntoMap(const char* path);
35 virtual void SetupComponent(entt::registry& registry, entt::entity entity, ScriptComponent& component);
36 virtual void DestroyComponent(entt::registry& registry, entt::entity entity, ScriptComponent& component);
37 virtual void CallStartInAllComponents(entt::registry& registry);
38 virtual void CallUpdateInAllComponents(entt::registry& registry);
39 virtual void CallEditorUpdateInAllComponents(entt::registry& registry);
40 virtual void CallDeleteInAllComponents(entt::registry& registry);
41 void RegisterComponents();
42 void RegisterComponent(std::string& csharpClass, ECS::ComponentFunctions& fns);
43 void CallCreateComponent(SceneManagement::Scene* scene, entt::entity entityHandle, MonoType* monoType);
44 void CallHasComponent(SceneManagement::Scene* scene, entt::entity entityHandle, MonoType* monoTypes);
45 void CallRemoveComponent(SceneManagement::Scene* scene, entt::entity entityHandle, MonoType* monoType);
46 void QueueReload();
47 void PerformReload();
48 void EditorUpdate(entt::registry& registry);
49 private:
50 void LoadAssemblyClasses();
51 void SetupEntityDataInComponent(entt::entity entity, ScriptComponent& component);
52 void CallFunctionInComponent(ScriptComponent& scriptComponent, size_t fnOffset);
53 void CallConstructorInComponent(ScriptComponent& scriptComponent);
54 void CallAttachComponentInComponent(ScriptComponent& scriptComponent);
55 void CallStartInComponent(ScriptComponent& scriptComponent);
56 void CallUpdateInComponent(ScriptComponent& scriptComponent);
57 void CallEditorUpdateInComponent(ScriptComponent& scriptComponent);
58 void CallDeleteInComponent(ScriptComponent& scriptComponent);
59 ScriptClass* SetupClass(const char* assemblyName, const char* namespaceName, const char* className);
60
61 MonoDomain* rootDomain = nullptr;
62 MonoDomain* scriptDomain = nullptr;
63 EngineCore *engineCore = nullptr;
64 std::map<std::string, AssemblyData> assemblies;
65 std::map<std::string, ScriptClass*> smartComponents;
66 AssemblyData grindstoneCoreDll;
67 bool isReloadQueued = false;
68
69 std::map<MonoType*, ECS::CreateComponentFn> createComponentFuncs;
70 std::map<MonoType*, ECS::TryGetComponentFn> tryGetComponentFuncs;
71 std::map<MonoType*, ECS::HasComponentFn> hasComponentFuncs;
72 std::map<MonoType*, ECS::RemoveComponentFn> removeComponentFuncs;
73 };
74 }
75 }
76}
Definition ComponentFunctions.hpp:19
Definition EngineCore.hpp:57
Definition Scene.hpp:21
Definition CSharpManager.hpp:22
Definition Entity.cs:5
Definition ScriptClass.hpp:23
Definition ScriptComponent.hpp:9