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.
 
 
 
 
 

138 lines
6.1 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),
RunParticleEffect = CreateCallback<RunParticleEffectCallback>(Callback_RunParticleEffect),
CreateParticleEffect = CreateCallback<CreateParticleEffectCallback>(Callback_CreateParticleEffect),
CreateParticleTrail = CreateCallback<CreateParticleTrailCallback>(Callback_CreateParticleTrail),
};
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;
public IntPtr RunParticleEffect;
public IntPtr CreateParticleEffect;
public IntPtr CreateParticleTrail;
}
[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();
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void RunParticleEffectCallback(IntPtr context, ref QVec3 origin, ref QVec3 direction, uint colorMin, uint colorMax, int count);
[MonoPInvokeCallback(typeof(RunParticleEffectCallback))]
private static void Callback_RunParticleEffect(IntPtr context, ref QVec3 origin, ref QVec3 direction, uint colorMin, uint colorMax, int count)
{
Profiler.BeginSample("RunParticleEffect");
GetSelf(context).RunParticleEffect(origin.ToUnityPosition(), direction.ToUnityPosition(), colorMin.ToColor(), colorMax.ToColor(), count);
Profiler.EndSample();
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void CreateParticleEffectCallback(IntPtr context, ParticleEffect type, ref QVec3 origin, uint colorMin, uint colorMax);
[MonoPInvokeCallback(typeof(CreateParticleEffectCallback))]
private static void Callback_CreateParticleEffect(IntPtr context, ParticleEffect type, ref QVec3 origin, uint colorMin, uint colorMax)
{
Profiler.BeginSample("CreateParticleEffect");
if (type == ParticleEffect.RogueExplosion)
GetSelf(context).CreateRogueExplosion(origin.ToUnityPosition(), colorMin.ToColor(), colorMax.ToColor());
else
GetSelf(context).CreateParticleEffect(type, origin.ToUnityPosition());
Profiler.EndSample();
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void CreateParticleTrailCallback(IntPtr context, int type, ref QVec3 start, ref QVec3 end);
[MonoPInvokeCallback(typeof(CreateParticleTrailCallback))]
private static void Callback_CreateParticleTrail(IntPtr context, int type, ref QVec3 start, ref QVec3 end)
{
Profiler.BeginSample("CreateParticleTrail");
GetSelf(context).CreateParticleTrail(type, start.ToUnityPosition(), end.ToUnityPosition());
Profiler.EndSample();
}
}