40 lines
1.5 KiB
C++
40 lines
1.5 KiB
C++
#include "MonoGameObjectSystem.hpp"
|
|
|
|
namespace ougge::modules {
|
|
|
|
const std::string& MonoGameObjectSystem::getName() {
|
|
return ougge_type_name<MonoGameObjectSystem>();
|
|
}
|
|
|
|
MonoGameObjectSystem::MonoGameObjectSystem(Engine& engine, u32 max_game_objects) :
|
|
IEngineModule(engine),
|
|
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;
|
|
}
|
|
|
|
}
|