split engine code into modules
This commit is contained in:
35
src/modules/MonoGameObjectSystem.cpp
Normal file
35
src/modules/MonoGameObjectSystem.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "MonoGameObjectSystem.hpp"
|
||||
|
||||
namespace ougge::modules {
|
||||
|
||||
MonoGameObjectSystem::MonoGameObjectSystem(Engine& engine, u32 max_game_objects) :
|
||||
EngineModule(engine, nameof(MonoGameObjectSystem)),
|
||||
gameObjectPool(max_game_objects)
|
||||
{
|
||||
engineManagedAssembly = mono.loadAssembly("Ougge.dll");
|
||||
gameObjectClass = engineManagedAssembly->getClass("Ougge", "GameObject");
|
||||
gameObjectCtor = Mono::Method<void(u64, u32)>(gameObjectClass, ".ctor");
|
||||
gameObjectInvokeUpdate = Mono::Method<void(f64)>(gameObjectClass, "InvokeUpdate");
|
||||
gameObjectTryCreateComponent = Mono::Method<Mono::Bool(Mono::String)>(gameObjectClass, "TryCreateComponent_internal");
|
||||
}
|
||||
|
||||
void MonoGameObjectSystem::beginFrame(){
|
||||
for(auto pair : gameObjectPool){
|
||||
gameObjectInvokeUpdate(pair.second.getObjectHandle().getObject(), engine.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
game::GameObject& MonoGameObjectSystem::createGameObject(){
|
||||
auto pair = gameObjectPool.emplace(game::GameObject(mono.createObject(gameObjectClass)));
|
||||
game::GameObject& obj = pair.second;
|
||||
gameObjectCtor(obj.getObjectHandle().getObject(), ++obj_id, pair.first);
|
||||
return obj;
|
||||
}
|
||||
|
||||
bool MonoGameObjectSystem::tryCreateComponent(game::GameObject& obj, const std::string& componentClassName){
|
||||
Mono::String componentClassNameManaged = mono.createString(componentClassName);
|
||||
Mono::Bool created = gameObjectTryCreateComponent(obj.getObjectHandle().getObject(), componentClassNameManaged);
|
||||
return created.wide_bool;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user