Skip to content

Commit

Permalink
feat(Native): implement DaedalusVm.{allocInstance,initInstanceDirect}
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Dec 28, 2023
1 parent efcc1b4 commit 1f342f2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ZenKit.Test/Vobs/TestCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void TestLoadG2()
Assert.That(vob.TargetCount, Is.EqualTo(1));

var frames = vob.Frames;
Assert.That(frames, Has.Count.EqualTo(3));
Assert.That(frames, Has.Count.EqualTo(2));
Assert.That(frames[0].Time, Is.EqualTo(0.0f));
Assert.That(frames[0].RollAngle, Is.EqualTo(0.0f));
Assert.That(frames[0].FovScale, Is.EqualTo(1.0f));
Expand Down
45 changes: 45 additions & 0 deletions ZenKit/DaedalusVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,51 @@ public void PrintStackTrace()
{
Native.ZkDaedalusVm_printStackTrace(Handle);
}

public T AllocInstance<T>(string symbolName)
{
var sym = GetSymbolByName(symbolName);
if (sym == null) throw new Exception("Symbol not found");
return AllocInstance<T>(sym);
}

public T AllocInstance<T>(DaedalusSymbol symbol)
{
DaedalusInstanceType type;

if (typeof(T) == typeof(GuildValuesInstance)) type = DaedalusInstanceType.GuildValues;
else if (typeof(T) == typeof(NpcInstance)) type = DaedalusInstanceType.Npc;
else if (typeof(T) == typeof(MissionInstance)) type = DaedalusInstanceType.Mission;
else if (typeof(T) == typeof(ItemInstance)) type = DaedalusInstanceType.Item;
else if (typeof(T) == typeof(FocusInstance)) type = DaedalusInstanceType.Focus;
else if (typeof(T) == typeof(InfoInstance)) type = DaedalusInstanceType.Info;
else if (typeof(T) == typeof(ItemReactInstance)) type = DaedalusInstanceType.ItemReact;
else if (typeof(T) == typeof(SpellInstance)) type = DaedalusInstanceType.Spell;
else if (typeof(T) == typeof(MenuInstance)) type = DaedalusInstanceType.Menu;
else if (typeof(T) == typeof(MenuItemInstance)) type = DaedalusInstanceType.MenuItem;
else if (typeof(T) == typeof(CameraInstance)) type = DaedalusInstanceType.Camera;
else if (typeof(T) == typeof(MusicSystemInstance)) type = DaedalusInstanceType.MusicSystem;
else if (typeof(T) == typeof(MusicThemeInstance)) type = DaedalusInstanceType.MusicTheme;
else if (typeof(T) == typeof(MusicJingleInstance)) type = DaedalusInstanceType.MusicJingle;
else if (typeof(T) == typeof(ParticleEffectInstance)) type = DaedalusInstanceType.ParticleEffect;
else if (typeof(T) == typeof(EffectBaseInstance)) type = DaedalusInstanceType.EffectBase;
else if (typeof(T) == typeof(ParticleEffectEmitKeyInstance))
type = DaedalusInstanceType.ParticleEffectEmitKey;
else if (typeof(T) == typeof(FightAiInstance)) type = DaedalusInstanceType.FightAi;
else if (typeof(T) == typeof(SoundEffectInstance)) type = DaedalusInstanceType.SoundEffect;
else if (typeof(T) == typeof(SoundSystemInstance)) type = DaedalusInstanceType.SoundSystem;
else if (typeof(T) == typeof(InvalidOperationException)) type = DaedalusInstanceType.Svm;
else throw new NotSupportedException("Must be DaedalusInstance");

var ptr = DaedalusInstance.FromNative(Native.ZkDaedalusVm_allocInstance(Handle, symbol.Handle, type)) ??
throw new InvalidOperationException();
return (T)(object)ptr;
}

public void InitInstance(DaedalusInstance instance)
{
Native.ZkDaedalusVm_initInstanceDirect(Handle, instance.Handle);
}

public T InitInstance<T>(string symbolName)
{
Expand Down
7 changes: 7 additions & 0 deletions ZenKit/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3205,8 +3205,15 @@ public static extern void ZkDaedalusScript_enumerateInstanceSymbols(UIntPtr slf,
[DllImport(DllName)]
public static extern void ZkDaedalusVm_callFunction(UIntPtr slf, UIntPtr sym);

[DllImport(DllName)]
public static extern UIntPtr ZkDaedalusVm_allocInstance(UIntPtr slf, UIntPtr sym, DaedalusInstanceType type);

[DllImport(DllName)]
public static extern UIntPtr ZkDaedalusVm_initInstance(UIntPtr slf, UIntPtr sym, DaedalusInstanceType type);

[DllImport(DllName)]
public static extern void ZkDaedalusVm_initInstanceDirect(UIntPtr slf, UIntPtr instance);


[DllImport(DllName)]
public static extern void ZkDaedalusVm_registerExternal(UIntPtr slf, UIntPtr sym,
Expand Down
Binary file modified ZenKit/runtimes/android-arm64/native/libzenkitcapi.so
Binary file not shown.
Binary file modified ZenKit/runtimes/linux-x64/native/libzenkitcapi.so
Binary file not shown.
Binary file modified ZenKit/runtimes/osx-x64/native/libzenkitcapi.dylib
Binary file not shown.
Binary file modified ZenKit/runtimes/win-x64/native/zenkitcapi.dll
Binary file not shown.

0 comments on commit 1f342f2

Please sign in to comment.