tried to fix bugs (partial success)

This commit is contained in:
2025-04-18 22:31:32 +05:00
parent 04e4f63fd7
commit d5d28d4884
8 changed files with 46 additions and 30 deletions

View File

@@ -26,23 +26,21 @@ public class GameObject
public Transform Transform { get; }
public GameObject? Parent;
public readonly Dictionary<Type, Component> Components = new();
public Dictionary<Type, Component> Components = new();
private GameObject()
{
}
private void Init(ulong id, uint nativePoolIndex)
private GameObject(ulong id, uint nativePoolIndex)
{
_id = id;
_index = nativePoolIndex;
// constructor doesn't work without writing to console
// TODO: FIX THIS BULLSHIT
Console.WriteLine($"GameObject(id: {id}, nativePoolIndex: {nativePoolIndex})");
}
static public GameObject Create()
{
NativeMethods.createGameObject(out ulong id, out uint index);
var o = new GameObject();
o.Init(id, index);
var o = new GameObject(id, index);
return o;
}
@@ -56,6 +54,9 @@ public class GameObject
throw new Exception($"Can't destroy GameObject({_id})");
}
/// <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>
/// <exception cref="Exception"></exception>
public bool TryCreateComponent(Type t)
{
if(!t.IsSubclassOf(typeof(Component)))
@@ -67,12 +68,13 @@ public class GameObject
Components.Add(t, (Component)Activator.CreateInstance(t, this));
return true;
}
private bool TryCreateComponent(string fullName)
private bool TryCreateComponent_internal(string fullName)
{
return TryCreateComponent(Type.GetType(fullName));
Type t = Type.GetType(fullName) ?? throw new Exception($"type not found '{fullName}'");
return TryCreateComponent(t);
}
private void UpdateComponents(double deltaTime)
private void InvokeUpdate(double deltaTime)
{
foreach(var p in Components)
{

View File

@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<LangVersion>latest</LangVersion>
<RootNamespace>Ougge</RootNamespace>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<DebugType>embedded</DebugType>
</PropertyGroup>
</Project>