implemented functions from NativeFunctions.cs
This commit is contained in:
@@ -15,6 +15,28 @@ MonoGameObjectSystem::MonoGameObjectSystem(Engine& engine, u32 max_game_objects)
|
||||
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");
|
||||
registerNativeCallbacks();
|
||||
}
|
||||
|
||||
// sets implementations for extern functions from src-csharp/NativeFunctions.cs
|
||||
void MonoGameObjectSystem::registerNativeCallbacks(){
|
||||
static MonoGameObjectSystem* this_static = this;
|
||||
if(this_static != this)
|
||||
throw new UsefulException("creation of more than one instance of MonoGameObjectSystem is not allowed");
|
||||
|
||||
auto createGameObject_callback = static_cast<void(*)(u64*, u32*)> (
|
||||
[](u64* id_out, u32* index_out) -> void {
|
||||
this_static->createGameObjectInPool(id_out, index_out);
|
||||
}
|
||||
);
|
||||
mono_add_internal_call("createGameObject", (void*)createGameObject_callback);
|
||||
|
||||
auto freeGameObject_callback = static_cast<bool(*)(u32)>(
|
||||
[](u32 index) -> bool {
|
||||
return this_static->gameObjectPool.erase(index);
|
||||
}
|
||||
);
|
||||
mono_add_internal_call("freeGameObject", (void*)freeGameObject_callback);
|
||||
}
|
||||
|
||||
void MonoGameObjectSystem::beginFrame(){
|
||||
@@ -23,10 +45,20 @@ void MonoGameObjectSystem::beginFrame(){
|
||||
}
|
||||
}
|
||||
|
||||
game::GameObject& MonoGameObjectSystem::createGameObject(){
|
||||
// is used in NativeFunctions.cs
|
||||
game::GameObject& MonoGameObjectSystem::createGameObjectInPool(u64* id_out, u32* index_out){
|
||||
auto pair = gameObjectPool.emplace(game::GameObject(mono.createObject(gameObjectClass)));
|
||||
*id_out = ++obj_id;
|
||||
*index_out = pair.first;
|
||||
game::GameObject& obj = pair.second;
|
||||
gameObjectCtor(obj.getObjectHandle().getObject(), ++obj_id, pair.first);
|
||||
return obj;
|
||||
}
|
||||
|
||||
game::GameObject& MonoGameObjectSystem::createAndConstructGameObject(){
|
||||
u64 obj_id;
|
||||
u32 obj_index;
|
||||
game::GameObject& obj = createGameObjectInPool(&obj_id, &obj_index);
|
||||
gameObjectCtor(obj.getObjectHandle().getObject(), obj_id, obj_index);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user