Browse Source

Renamed "target" pointers to "context" to fit in line with the rest of the callbacks refactoring

readme
Nico de Poel 5 years ago
parent
commit
46cafd0c63
  1. 4
      Assets/Scripts/CallbackHandler.cs
  2. 30
      Assets/Scripts/Modules/GameModule.Interop.cs
  3. 36
      Assets/Scripts/Modules/RenderModule.Interop.cs
  4. 72
      Assets/Scripts/Modules/SystemModule.Interop.cs

4
Assets/Scripts/CallbackHandler.cs

@ -36,8 +36,8 @@ public abstract class CallbackHandler<THandler>
callbacksHandle = GCHandle.Alloc(callbacks, GCHandleType.Pinned);
}
protected static THandler GetSelf(IntPtr target)
protected static THandler GetSelf(IntPtr context)
{
return (THandler)GCHandle.FromIntPtr(target).Target;
return (THandler)GCHandle.FromIntPtr(context).Target;
}
}

30
Assets/Scripts/Modules/GameModule.Interop.cs

@ -36,57 +36,57 @@ public partial class GameModule : CallbackHandler<GameModule>
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void GameSetEntityModelCallback(IntPtr target, int entityNum, [MarshalAs(UnmanagedType.LPStr)] string modelName);
private delegate void GameSetEntityModelCallback(IntPtr context, int entityNum, [MarshalAs(UnmanagedType.LPStr)] string modelName);
[MonoPInvokeCallback(typeof(GameSetEntityModelCallback))]
private static void Callback_GameSetEntityModel(IntPtr target, int entityNum, string modelName)
private static void Callback_GameSetEntityModel(IntPtr context, int entityNum, string modelName)
{
Profiler.BeginSample("GameSetEntityModel");
GetSelf(target).SetEntityModel(entityNum, modelName);
GetSelf(context).SetEntityModel(entityNum, modelName);
Profiler.EndSample();
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void GameSetEntityTransformCallback(IntPtr target, int entityNum, ref QVec3 origin, ref QVec3 angles);
private delegate void GameSetEntityTransformCallback(IntPtr context, int entityNum, ref QVec3 origin, ref QVec3 angles);
[MonoPInvokeCallback(typeof(GameSetEntityTransformCallback))]
private static void Callback_GameSetEntityTransform(IntPtr target, int entityNum, ref QVec3 origin, ref QVec3 angles)
private static void Callback_GameSetEntityTransform(IntPtr context, int entityNum, ref QVec3 origin, ref QVec3 angles)
{
Profiler.BeginSample("GameSetEntityTransform");
GetSelf(target).SetEntityTransform(entityNum, origin, angles);
GetSelf(context).SetEntityTransform(entityNum, origin, angles);
Profiler.EndSample();
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void GameRemoveEntityCallback(IntPtr target, int entityNum);
private delegate void GameRemoveEntityCallback(IntPtr context, int entityNum);
[MonoPInvokeCallback(typeof(GameRemoveEntityCallback))]
private static void Callback_GameRemoveEntity(IntPtr target, int entityNum)
private static void Callback_GameRemoveEntity(IntPtr context, int entityNum)
{
Profiler.BeginSample("GameRemoveEntity");
GetSelf(target).RemoveEntity(entityNum);
GetSelf(context).RemoveEntity(entityNum);
Profiler.EndSample();
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void GameUpdateEntityAnimationCallback(IntPtr target, int entityNum, int pose1, int pose2, float blend);
private delegate void GameUpdateEntityAnimationCallback(IntPtr context, int entityNum, int pose1, int pose2, float blend);
[MonoPInvokeCallback(typeof(GameUpdateEntityAnimationCallback))]
private static void Callback_GameUpdateEntityAnimation(IntPtr target, int entityNum, int pose1, int pose2, float blend)
private static void Callback_GameUpdateEntityAnimation(IntPtr context, int entityNum, int pose1, int pose2, float blend)
{
Profiler.BeginSample("GameUpdateEntityAnimation");
GetSelf(target).UpdateEntityAnimation(entityNum, pose1, pose2, blend);
GetSelf(context).UpdateEntityAnimation(entityNum, pose1, pose2, blend);
Profiler.EndSample();
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void GameSetEntitySkinCallback(IntPtr target, int entityNum, int skinNum);
private delegate void GameSetEntitySkinCallback(IntPtr context, int entityNum, int skinNum);
[MonoPInvokeCallback(typeof(GameSetEntitySkinCallback))]
private static void Callback_GameSetEntitySkin(IntPtr target, int entityNum, int skinNum)
private static void Callback_GameSetEntitySkin(IntPtr context, int entityNum, int skinNum)
{
Profiler.BeginSample("GameSetEntitySkin");
GetSelf(target).SetEntitySkin(entityNum, skinNum);
GetSelf(context).SetEntitySkin(entityNum, skinNum);
Profiler.EndSample();
}
}

36
Assets/Scripts/Modules/RenderModule.Interop.cs

@ -39,12 +39,12 @@ public partial class RenderModule: CallbackHandler<RenderModule>
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
private delegate int UploadAliasModelCallback(IntPtr target, [MarshalAs(UnmanagedType.LPStr)] string name,
private delegate int UploadAliasModelCallback(IntPtr context, [MarshalAs(UnmanagedType.LPStr)] string name,
QAliasHeader header, QAliasFrameType frameType, IntPtr frames,
[MarshalAs(UnmanagedType.LPArray, SizeConst = MaxAliasFrames)] IntPtr[] poseVerts, IntPtr triangles, IntPtr stVerts);
[MonoPInvokeCallback(typeof(UploadAliasModelCallback))]
private static int Callback_UploadAliasModel(IntPtr target,
private static int Callback_UploadAliasModel(IntPtr context,
string name, QAliasHeader header, QAliasFrameType frameType, IntPtr frames,
IntPtr[] poseVerts, IntPtr triangles, IntPtr stVerts)
{
@ -82,7 +82,7 @@ public partial class RenderModule: CallbackHandler<RenderModule>
fbTextures[i] = header.fbTextures[i * 4].ToStructArray<QGLTexture>(4);
}
int result = GetSelf(target).UploadAliasModel(
int result = GetSelf(context).UploadAliasModel(
name, header, frameType, poseVertices,
triangles.ToStructArray<QTriangle>(header.numTriangles),
stVerts.ToStructArray<QSTVert>(header.numVerts),
@ -93,46 +93,46 @@ public partial class RenderModule: CallbackHandler<RenderModule>
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int UploadBrushModelCallback(IntPtr target, QModel model);
private delegate int UploadBrushModelCallback(IntPtr context, QModel model);
[MonoPInvokeCallback(typeof(UploadBrushModelCallback))]
private static int Callback_UploadBrushModel(IntPtr target, QModel model)
private static int Callback_UploadBrushModel(IntPtr context, QModel model)
{
if (model == null || model.type != QModelType.Brush)
return -1;
Profiler.BeginSample("UploadBrushModel");
int result = GetSelf(target).UploadBrushModel(model);
int result = GetSelf(context).UploadBrushModel(model);
Profiler.EndSample();
return result;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int UploadWorldModelCallback(IntPtr target, QModel model);
private delegate int UploadWorldModelCallback(IntPtr context, QModel model);
[MonoPInvokeCallback(typeof(UploadBrushModelCallback))]
private static int Callback_UploadWorldModel(IntPtr target, QModel model)
private static int Callback_UploadWorldModel(IntPtr context, QModel model)
{
if (model == null || model.type != QModelType.Brush)
return -1;
Profiler.BeginSample("UploadWorldModel");
int result = GetSelf(target).UploadWorldModel(model);
int result = GetSelf(context).UploadWorldModel(model);
Profiler.EndSample();
return result;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool UploadTextureCallback(IntPtr target, QGLTexture texture, IntPtr data, ref uint texNum);
private delegate bool UploadTextureCallback(IntPtr context, QGLTexture texture, IntPtr data, ref uint texNum);
[MonoPInvokeCallback(typeof(UploadTextureCallback))]
private static bool Callback_UploadTexture(IntPtr target, QGLTexture texture, IntPtr data, ref uint texNum)
private static bool Callback_UploadTexture(IntPtr context, QGLTexture texture, IntPtr data, ref uint texNum)
{
Profiler.BeginSample("UploadTexture");
byte[] dataBytes = new byte[texture.width * texture.height * 4]; // 32 bits per pixel
Marshal.Copy(data, dataBytes, 0, dataBytes.Length);
bool result = GetSelf(target).UploadTexture(texture, dataBytes, ref texNum);
bool result = GetSelf(context).UploadTexture(texture, dataBytes, ref texNum);
Profiler.EndSample();
return result;
@ -141,15 +141,15 @@ public partial class RenderModule: CallbackHandler<RenderModule>
private readonly byte[] lightmapBytes = new byte[QConstants.LightmapBlockWidth * QConstants.LightmapBlockHeight * 4]; // 32 bits per pixel
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool UploadLightmapCallback(IntPtr target, int lmap, IntPtr data);
private delegate bool UploadLightmapCallback(IntPtr context, int lmap, IntPtr data);
[MonoPInvokeCallback(typeof(UploadLightmapCallback))]
private static bool Callback_UploadLightmap(IntPtr target, int lmap, IntPtr data)
private static bool Callback_UploadLightmap(IntPtr context, int lmap, IntPtr data)
{
Profiler.BeginSample("UploadLightmap");
// TODO: this is a fairly pointless additional data copy step; we could probably make this faster by wrapping the IntPtr directly into a NativeArray
var self = GetSelf(target);
var self = GetSelf(context);
Marshal.Copy(data, self.lightmapBytes, 0, self.lightmapBytes.Length);
bool result = self.UploadLightmap(lmap, QConstants.LightmapBlockWidth, QConstants.LightmapBlockHeight, self.lightmapBytes);
@ -158,13 +158,13 @@ public partial class RenderModule: CallbackHandler<RenderModule>
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void SetupViewCallback(IntPtr target, ref QVec3 origin, ref QVec3 angles, ref QLeaf viewLeaf);
private delegate void SetupViewCallback(IntPtr context, ref QVec3 origin, ref QVec3 angles, ref QLeaf viewLeaf);
[MonoPInvokeCallback(typeof(SetupViewCallback))]
private static void Callback_SetupView(IntPtr target, ref QVec3 origin, ref QVec3 angles, ref QLeaf viewLeaf)
private static void Callback_SetupView(IntPtr context, ref QVec3 origin, ref QVec3 angles, ref QLeaf viewLeaf)
{
Profiler.BeginSample("SetupView");
GetSelf(target).SetupView(origin, angles, viewLeaf);
GetSelf(context).SetupView(origin, angles, viewLeaf);
Profiler.EndSample();
}
}

72
Assets/Scripts/Modules/SystemModule.Interop.cs

@ -48,112 +48,112 @@ public partial class SystemModule: CallbackHandler<SystemModule>
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
private delegate void SysPrintCallback(IntPtr target,
private delegate void SysPrintCallback(IntPtr context,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(QuakeTextMarshaler))] string message);
[MonoPInvokeCallback(typeof(SysPrintCallback))]
private static void Callback_SysPrint(IntPtr target, string message)
private static void Callback_SysPrint(IntPtr context, string message)
{
GetSelf(target).Print(message);
GetSelf(context).Print(message);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
private delegate void SysErrorCallback(IntPtr target,
private delegate void SysErrorCallback(IntPtr context,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(QuakeTextMarshaler))] string message);
[MonoPInvokeCallback(typeof(SysErrorCallback))]
private static void Callback_SysError(IntPtr target, string message)
private static void Callback_SysError(IntPtr context, string message)
{
GetSelf(target).Error(message);
GetSelf(context).Error(message);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void SysQuitCallback(IntPtr target);
private delegate void SysQuitCallback(IntPtr context);
[MonoPInvokeCallback(typeof(SysQuitCallback))]
private static void Callback_SysQuit(IntPtr target)
private static void Callback_SysQuit(IntPtr context)
{
GetSelf(target).Quit();
GetSelf(context).Quit();
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate double SysDoubleTimeCallback(IntPtr target);
private delegate double SysDoubleTimeCallback(IntPtr context);
[MonoPInvokeCallback(typeof(SysDoubleTimeCallback))]
private static double Callback_SysDoubleTime(IntPtr target)
private static double Callback_SysDoubleTime(IntPtr context)
{
return GetSelf(target).DoubleTime();
return GetSelf(context).DoubleTime();
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
private delegate int SysFileOpenReadCallback(IntPtr target, [MarshalAs(UnmanagedType.LPStr)] string path, out int handle);
private delegate int SysFileOpenReadCallback(IntPtr context, [MarshalAs(UnmanagedType.LPStr)] string path, out int handle);
[MonoPInvokeCallback(typeof(SysFileOpenReadCallback))]
private static int Callback_SysFileOpenRead(IntPtr target, string path, out int handle)
private static int Callback_SysFileOpenRead(IntPtr context, string path, out int handle)
{
return GetSelf(target).FileOpenRead(path, out handle);
return GetSelf(context).FileOpenRead(path, out handle);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
private delegate int SysFileOpenWriteCallback(IntPtr target, [MarshalAs(UnmanagedType.LPStr)] string path);
private delegate int SysFileOpenWriteCallback(IntPtr context, [MarshalAs(UnmanagedType.LPStr)] string path);
[MonoPInvokeCallback(typeof(SysFileOpenWriteCallback))]
private static int Callback_SysFileOpenWrite(IntPtr target, string path)
private static int Callback_SysFileOpenWrite(IntPtr context, string path)
{
return GetSelf(target).FileOpenWrite(path);
return GetSelf(context).FileOpenWrite(path);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void SysFileCloseCallback(IntPtr target, int handle);
private delegate void SysFileCloseCallback(IntPtr context, int handle);
[MonoPInvokeCallback(typeof(SysFileCloseCallback))]
private static void Callback_SysFileClose(IntPtr target, int handle)
private static void Callback_SysFileClose(IntPtr context, int handle)
{
GetSelf(target).FileClose(handle);
GetSelf(context).FileClose(handle);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void SysFileSeekCallback(IntPtr target, int handle, int position);
private delegate void SysFileSeekCallback(IntPtr context, int handle, int position);
[MonoPInvokeCallback(typeof(SysFileSeekCallback))]
private static void Callback_SysFileSeek(IntPtr target, int handle, int position)
private static void Callback_SysFileSeek(IntPtr context, int handle, int position)
{
GetSelf(target).FileSeek(handle, position);
GetSelf(context).FileSeek(handle, position);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int SysFileReadCallback(IntPtr target, int handle, IntPtr dest, int count);
private delegate int SysFileReadCallback(IntPtr context, int handle, IntPtr dest, int count);
[MonoPInvokeCallback(typeof(SysFileReadCallback))]
private static int Callback_SysFileRead(IntPtr target, int handle, IntPtr dest, int count)
private static int Callback_SysFileRead(IntPtr context, int handle, IntPtr dest, int count)
{
return GetSelf(target).FileRead(handle, dest, count);
return GetSelf(context).FileRead(handle, dest, count);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int SysFileWriteCallback(IntPtr target, int handle, IntPtr data, int count);
private delegate int SysFileWriteCallback(IntPtr context, int handle, IntPtr data, int count);
[MonoPInvokeCallback(typeof(SysFileWriteCallback))]
private static int Callback_SysFileWrite(IntPtr target, int handle, IntPtr data, int count)
private static int Callback_SysFileWrite(IntPtr context, int handle, IntPtr data, int count)
{
return GetSelf(target).FileWrite(handle, data, count);
return GetSelf(context).FileWrite(handle, data, count);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
private delegate int SysFileTimeCallback(IntPtr target, [MarshalAs(UnmanagedType.LPStr)] string path);
private delegate int SysFileTimeCallback(IntPtr context, [MarshalAs(UnmanagedType.LPStr)] string path);
[MonoPInvokeCallback(typeof(SysFileTimeCallback))]
private static int Callback_SysFileTime(IntPtr target, string path)
private static int Callback_SysFileTime(IntPtr context, string path)
{
return GetSelf(target).FileTime(path);
return GetSelf(context).FileTime(path);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
private delegate bool SysMkDirCallback(IntPtr target, [MarshalAs(UnmanagedType.LPStr)] string path);
private delegate bool SysMkDirCallback(IntPtr context, [MarshalAs(UnmanagedType.LPStr)] string path);
[MonoPInvokeCallback(typeof(SysMkDirCallback))]
private static bool Callback_SysMkDir(IntPtr target, string path)
private static bool Callback_SysMkDir(IntPtr context, string path)
{
return GetSelf(target).MkDir(path);
return GetSelf(context).MkDir(path);
}
}
Loading…
Cancel
Save