something something
This commit is contained in:
@@ -14,6 +14,14 @@ public class ExampleComponent : Component
|
|||||||
Console.WriteLine($"C# deltaTime {deltaTime} object id {Owner.Id}");
|
Console.WriteLine($"C# deltaTime {deltaTime} object id {Owner.Id}");
|
||||||
ImGui.Begin("C# WINDOW");
|
ImGui.Begin("C# WINDOW");
|
||||||
ImGui.Text("Hello from ExampleComponent!");
|
ImGui.Text("Hello from ExampleComponent!");
|
||||||
|
if (ImGui.Button("create GameObject"))
|
||||||
|
{
|
||||||
|
GameObject.Create();
|
||||||
|
}
|
||||||
|
if (ImGui.Button("GC Collect"))
|
||||||
|
{
|
||||||
|
GC.Collect();
|
||||||
|
}
|
||||||
ImGui.End();
|
ImGui.End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,6 +41,7 @@ public class GameObject
|
|||||||
{
|
{
|
||||||
NativeFunctions.createGameObject(out ulong id, out uint index);
|
NativeFunctions.createGameObject(out ulong id, out uint index);
|
||||||
var o = new GameObject(id, index);
|
var o = new GameObject(id, index);
|
||||||
|
Console.WriteLine($"C# created object with id {id}, index {index}");
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,15 +55,21 @@ public class GameObject
|
|||||||
throw new Exception($"Can't destroy GameObject({_id})");
|
throw new Exception($"Can't destroy GameObject({_id})");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~GameObject()
|
||||||
|
{
|
||||||
|
// destroys object native part when managed part is garbage-collected
|
||||||
|
Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
/// <param name="t">type derived from Component</param>
|
/// <param name="t">type derived from Component</param>
|
||||||
/// <returns>true if new component instance was created, false if component of the same tipe is already added to GameObject</returns>
|
/// <returns>true if new component instance was created, false if component of the same tipe is already added to GameObject</returns>
|
||||||
/// <exception cref="Exception"></exception>
|
/// <exception cref="Exception"></exception>
|
||||||
public bool TryCreateComponent(Type t)
|
public bool TryCreateComponent(Type t)
|
||||||
{
|
{
|
||||||
if(!t.IsSubclassOf(typeof(Component)))
|
if (!t.IsSubclassOf(typeof(Component)))
|
||||||
throw new Exception($"type {t.FullName} is not a derived class of {typeof(Component).FullName}");
|
throw new Exception($"type {t.FullName} is not a derived class of {typeof(Component).FullName}");
|
||||||
|
|
||||||
if(Components.ContainsKey(t))
|
if (Components.ContainsKey(t))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Component component = (Component?)Activator.CreateInstance(t, this)
|
Component component = (Component?)Activator.CreateInstance(t, this)
|
||||||
@@ -78,7 +85,9 @@ public class GameObject
|
|||||||
|
|
||||||
private void InvokeUpdate(double deltaTime)
|
private void InvokeUpdate(double deltaTime)
|
||||||
{
|
{
|
||||||
foreach(var p in Components)
|
Console.WriteLine("C# InvokeUpdate");
|
||||||
|
Console.WriteLine($"id {_id}, index {_index}, destroyed {_isDestroyed}");
|
||||||
|
foreach (var p in Components)
|
||||||
{
|
{
|
||||||
p.Value.Update(deltaTime);
|
p.Value.Update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
using System;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace Ougge;
|
namespace Ougge;
|
||||||
|
|
||||||
internal static class NativeFunctions
|
internal static class NativeFunctions
|
||||||
{
|
{
|
||||||
[DllImport("__Internal")]
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||||
internal extern static void createGameObject(out ulong id, out uint index);
|
internal extern static void createGameObject(out ulong id, out uint index);
|
||||||
|
|
||||||
[DllImport("__Internal")]
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||||
internal extern static bool freeGameObject(uint index);
|
internal extern static bool freeGameObject(uint index);
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ void Engine::stopLoop(){
|
|||||||
void Engine::handleModuleError(IEngineModule& module, const char* type, const char* method, const char* error){
|
void Engine::handleModuleError(IEngineModule& module, const char* type, const char* method, const char* error){
|
||||||
std::string error_message = ougge_format(
|
std::string error_message = ougge_format(
|
||||||
"Catched %s at %s.%s(): %s",
|
"Catched %s at %s.%s(): %s",
|
||||||
type, module.getName(), method, error);
|
type, module.getName().c_str(), method, error);
|
||||||
std::cerr<<error_message<<std::endl;
|
std::cerr<<error_message<<std::endl;
|
||||||
error_messages.push_back(error_message);
|
error_messages.push_back(error_message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,22 +26,27 @@ void MonoGameObjectSystem::registerNativeCallbacks(){
|
|||||||
|
|
||||||
auto createGameObject_callback = static_cast<void(*)(u64*, u32*)> (
|
auto createGameObject_callback = static_cast<void(*)(u64*, u32*)> (
|
||||||
[](u64* id_out, u32* index_out) -> void {
|
[](u64* id_out, u32* index_out) -> void {
|
||||||
|
std::cout<<"createGameObject_callback"<<std::endl;
|
||||||
this_static->createGameObjectInPool(id_out, index_out);
|
this_static->createGameObjectInPool(id_out, index_out);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
mono_add_internal_call("createGameObject", (void*)createGameObject_callback);
|
mono_add_internal_call("Ougge.NativeFunctions::createGameObject", (void*)createGameObject_callback);
|
||||||
|
|
||||||
auto freeGameObject_callback = static_cast<bool(*)(u32)>(
|
auto freeGameObject_callback = static_cast<bool(*)(u32)>(
|
||||||
[](u32 index) -> bool {
|
[](u32 index) -> bool {
|
||||||
|
std::cout<<"freeGameObject_callback"<<std::endl;
|
||||||
return this_static->gameObjectPool.erase(index);
|
return this_static->gameObjectPool.erase(index);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
mono_add_internal_call("freeGameObject", (void*)freeGameObject_callback);
|
mono_add_internal_call("Ougge.NativeFunctions::freeGameObject", (void*)freeGameObject_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonoGameObjectSystem::beginFrame(){
|
void MonoGameObjectSystem::beginFrame(){
|
||||||
for(auto pair : gameObjectPool){
|
for(auto pair : gameObjectPool){
|
||||||
gameObjectInvokeUpdate(pair.second.getObjectHandle().getObject(), engine.deltaTime);
|
|
||||||
|
auto obj = pair.second.getObjectHandle().getObject();
|
||||||
|
std::cout<<"updating obj: "<<obj<<std::endl;
|
||||||
|
gameObjectInvokeUpdate(obj, engine.deltaTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user