You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
3.7 KiB
92 lines
3.7 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using AOT;
|
|
using UnityEngine;
|
|
using UnityEngine.Profiling;
|
|
|
|
public partial class GameModule : CallbackHandler<GameModule>
|
|
{
|
|
private void BuildCallbacks()
|
|
{
|
|
var callbacks = new Callbacks
|
|
{
|
|
SetEntityModel = CreateCallback<GameSetEntityModelCallback>(Callback_GameSetEntityModel),
|
|
SetEntityTransform = CreateCallback<GameSetEntityTransformCallback>(Callback_GameSetEntityTransform),
|
|
RemoveEntity = CreateCallback<GameRemoveEntityCallback>(Callback_GameRemoveEntity),
|
|
UpdateEntityAnimation = CreateCallback<GameUpdateEntityAnimationCallback>(Callback_GameUpdateEntityAnimation),
|
|
SetEntitySkin = CreateCallback<GameSetEntitySkinCallback>(Callback_GameSetEntitySkin),
|
|
};
|
|
|
|
RegisterCallbacks(callbacks);
|
|
}
|
|
|
|
/// <summary>
|
|
/// This matches unity_gamecalls_t from mod_uniquake.c in native code.
|
|
/// </summary>
|
|
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
|
private class Callbacks
|
|
{
|
|
public IntPtr SetEntityModel;
|
|
public IntPtr SetEntityTransform;
|
|
public IntPtr RemoveEntity;
|
|
public IntPtr UpdateEntityAnimation;
|
|
public IntPtr SetEntitySkin;
|
|
}
|
|
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
private delegate void GameSetEntityModelCallback(IntPtr context, int entityNum, [MarshalAs(UnmanagedType.LPStr)] string modelName);
|
|
|
|
[MonoPInvokeCallback(typeof(GameSetEntityModelCallback))]
|
|
private static void Callback_GameSetEntityModel(IntPtr context, int entityNum, string modelName)
|
|
{
|
|
Profiler.BeginSample("GameSetEntityModel");
|
|
GetSelf(context).SetEntityModel(entityNum, modelName);
|
|
Profiler.EndSample();
|
|
}
|
|
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
private delegate void GameSetEntityTransformCallback(IntPtr context, int entityNum, ref QVec3 origin, ref QVec3 angles);
|
|
|
|
[MonoPInvokeCallback(typeof(GameSetEntityTransformCallback))]
|
|
private static void Callback_GameSetEntityTransform(IntPtr context, int entityNum, ref QVec3 origin, ref QVec3 angles)
|
|
{
|
|
Profiler.BeginSample("GameSetEntityTransform");
|
|
GetSelf(context).SetEntityTransform(entityNum, origin, angles);
|
|
Profiler.EndSample();
|
|
}
|
|
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
private delegate void GameRemoveEntityCallback(IntPtr context, int entityNum);
|
|
|
|
[MonoPInvokeCallback(typeof(GameRemoveEntityCallback))]
|
|
private static void Callback_GameRemoveEntity(IntPtr context, int entityNum)
|
|
{
|
|
Profiler.BeginSample("GameRemoveEntity");
|
|
GetSelf(context).RemoveEntity(entityNum);
|
|
Profiler.EndSample();
|
|
}
|
|
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
private delegate void GameUpdateEntityAnimationCallback(IntPtr context, int entityNum, int pose1, int pose2, float blend);
|
|
|
|
[MonoPInvokeCallback(typeof(GameUpdateEntityAnimationCallback))]
|
|
private static void Callback_GameUpdateEntityAnimation(IntPtr context, int entityNum, int pose1, int pose2, float blend)
|
|
{
|
|
Profiler.BeginSample("GameUpdateEntityAnimation");
|
|
GetSelf(context).UpdateEntityAnimation(entityNum, pose1, pose2, blend);
|
|
Profiler.EndSample();
|
|
}
|
|
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
private delegate void GameSetEntitySkinCallback(IntPtr context, int entityNum, int skinNum);
|
|
|
|
[MonoPInvokeCallback(typeof(GameSetEntitySkinCallback))]
|
|
private static void Callback_GameSetEntitySkin(IntPtr context, int entityNum, int skinNum)
|
|
{
|
|
Profiler.BeginSample("GameSetEntitySkin");
|
|
GetSelf(context).SetEntitySkin(entityNum, skinNum);
|
|
Profiler.EndSample();
|
|
}
|
|
}
|