Browse Source

Renamed mod* to gl* to reflect that it's about rendering in general, and cleaned up & rearranged some code

console
Nico de Poel 5 years ago
parent
commit
404f19a56d
  1. 9
      Assets/Scripts/UniQuake.cs
  2. 8
      engine/projects/uniquake/gl_uniquake.c
  3. 19
      engine/projects/uniquake/sys_uniquake.c
  4. 4
      engine/projects/uniquake/uniquake.c
  5. 24
      engine/projects/uniquake/uniquake.h
  6. 2
      engine/projects/uniquake/uniquake.vcxproj
  7. 2
      engine/projects/uniquake/uniquake.vcxproj.filters

9
Assets/Scripts/UniQuake.cs

@ -126,7 +126,7 @@ public class UniQuake: MonoBehaviour
} }
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void UniQuake_InitFunc(QuakeParms parms, IntPtr sysCalls, IntPtr modCalls);
private delegate void UniQuake_InitFunc(QuakeParms parms, IntPtr sysCalls, IntPtr glCalls);
private UniQuake_InitFunc UniQuake_Init; private UniQuake_InitFunc UniQuake_Init;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@ -139,7 +139,6 @@ public class UniQuake: MonoBehaviour
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void UniQuake_SetFmodSystemFunc(IntPtr fmodSystem); private delegate void UniQuake_SetFmodSystemFunc(IntPtr fmodSystem);
private UniQuake_SetFmodSystemFunc UniQuake_SetFmodSystem; private UniQuake_SetFmodSystemFunc UniQuake_SetFmodSystem;
private void LoadLibrary() private void LoadLibrary()
@ -157,12 +156,12 @@ public class UniQuake: MonoBehaviour
UniQuake_SetFmodSystem = LoadLibraryFunction<UniQuake_SetFmodSystemFunc>("UniQuake_SetFmodSystem"); UniQuake_SetFmodSystem = LoadLibraryFunction<UniQuake_SetFmodSystemFunc>("UniQuake_SetFmodSystem");
} }
private TDelegate LoadLibraryFunction<TDelegate>(string name)
private TDelegate LoadLibraryFunction<TDelegate>(string functionName)
{ {
IntPtr procAddress = SystemLibrary.GetProcAddress(libraryHandle, name);
IntPtr procAddress = SystemLibrary.GetProcAddress(libraryHandle, functionName);
if (procAddress == IntPtr.Zero) if (procAddress == IntPtr.Zero)
{ {
throw new DllNotFoundException($"Could not find library function: {name}");
throw new DllNotFoundException($"Could not find library function: {functionName}");
} }
return Marshal.GetDelegateForFunctionPointer<TDelegate>(procAddress); return Marshal.GetDelegateForFunctionPointer<TDelegate>(procAddress);

8
engine/projects/uniquake/mod_uniquake.c → engine/projects/uniquake/gl_uniquake.c

@ -3,18 +3,18 @@
#include "../../code/quakedef.h" #include "../../code/quakedef.h"
#include "../../code/gl_model.h" #include "../../code/gl_model.h"
typedef struct unity_modcalls_s
typedef struct unity_glcalls_s
{ {
void *target; void *target;
int(*UploadAliasModel)(void *target, char *name, aliashdr_t *aliashdr, maliasframedesc_t *frames, trivertx_t **poseVerts, mtriangle_t *triangles, stvert_t *stVerts); int(*UploadAliasModel)(void *target, char *name, aliashdr_t *aliashdr, maliasframedesc_t *frames, trivertx_t **poseVerts, mtriangle_t *triangles, stvert_t *stVerts);
} unity_modcalls_t;
} unity_glcalls_t;
const unity_modcalls_t *unity_modcalls;
const unity_glcalls_t *unity_glcalls;
int UQ_GL_UploadAliasModel(char *name, aliashdr_t *aliashdr, trivertx_t **poseVerts, mtriangle_t *triangles, stvert_t *stVerts) int UQ_GL_UploadAliasModel(char *name, aliashdr_t *aliashdr, trivertx_t **poseVerts, mtriangle_t *triangles, stvert_t *stVerts)
{ {
// C# doesn't really understand this idea of a variable-length embedded array of structs, // C# doesn't really understand this idea of a variable-length embedded array of structs,
// so we pass along the pointer to the first frame struct which allows us to manually marshal the entire array. // so we pass along the pointer to the first frame struct which allows us to manually marshal the entire array.
return unity_modcalls->UploadAliasModel(unity_modcalls->target, name, aliashdr, &aliashdr->frames[0], poseVerts, triangles, stVerts);
return unity_glcalls->UploadAliasModel(unity_glcalls->target, name, aliashdr, &aliashdr->frames[0], poseVerts, triangles, stVerts);
} }

19
engine/projects/uniquake/sys_uniquake.c

@ -2,6 +2,25 @@
#include "../../code/quakedef.h" #include "../../code/quakedef.h"
typedef struct unity_syscalls_s
{
void *target;
void(*SysPrint)(void *target, const char *msg);
void(*SysError)(void *target, const char *msg);
void(*SysQuit)(void *target);
double(*SysFloatTime)(void *target);
int(*SysFileOpenRead)(void *target, char *path, int *hndl);
int(*SysFileOpenWrite)(void *target, char *path);
void(*SysFileClose)(void *target, int handle);
void(*SysFileSeek)(void *target, int handle, int position);
int(*SysFileRead)(void *target, int handle, void *dest, int count);
int(*SysFileWrite)(void *target, int handle, void *data, int count);
int(*SysFileTime)(void *target, char *path);
void(*SysMkDir)(void *target, char *path);
} unity_syscalls_t;
const unity_syscalls_t *unity_syscalls; const unity_syscalls_t *unity_syscalls;
void Sys_Error(char *error, ...) void Sys_Error(char *error, ...)

4
engine/projects/uniquake/uniquake.c

@ -7,10 +7,10 @@ UNIQUAKE_API void UniQuake_SetFmodSystem(FMOD_SYSTEM *system)
fmod_system = system; fmod_system = system;
} }
UNIQUAKE_API void UniQuake_Init(quakeparms_t *parms, const unity_syscalls_t *syscalls, const unity_modcalls_t *modcalls)
UNIQUAKE_API void UniQuake_Init(quakeparms_t *parms, const unity_syscalls_t *syscalls, const unity_glcalls_t *glcalls)
{ {
unity_syscalls = syscalls; unity_syscalls = syscalls;
unity_modcalls = modcalls;
unity_glcalls = glcalls;
COM_InitArgv(parms->argc, parms->argv); COM_InitArgv(parms->argc, parms->argv);
parms->argc = com_argc; parms->argc = com_argc;

24
engine/projects/uniquake/uniquake.h

@ -9,26 +9,8 @@
#define UNIQUAKE_API __declspec(dllimport) #define UNIQUAKE_API __declspec(dllimport)
#endif #endif
typedef struct unity_syscalls_s
{
void *target;
void(*SysPrint)(void *target, const char *msg);
void(*SysError)(void *target, const char *msg);
void(*SysQuit)(void *target);
double(*SysFloatTime)(void *target);
int(*SysFileOpenRead)(void *target, char *path, int *hndl);
int(*SysFileOpenWrite)(void *target, char *path);
void(*SysFileClose)(void *target, int handle);
void(*SysFileSeek)(void *target, int handle, int position);
int(*SysFileRead)(void *target, int handle, void *dest, int count);
int(*SysFileWrite)(void *target, int handle, void *data, int count);
int(*SysFileTime)(void *target, char *path);
void(*SysMkDir)(void *target, char *path);
} unity_syscalls_t;
typedef struct unity_syscalls_s unity_syscalls_t;
extern const unity_syscalls_t *unity_syscalls; extern const unity_syscalls_t *unity_syscalls;
typedef struct unity_modcalls_s unity_modcalls_t;
extern const unity_modcalls_t *unity_modcalls;
typedef struct unity_glcalls_s unity_glcalls_t;
extern const unity_glcalls_t *unity_glcalls;

2
engine/projects/uniquake/uniquake.vcxproj

@ -353,7 +353,7 @@
<ClCompile Include="..\..\jpeg-6\jmemmgr.c" /> <ClCompile Include="..\..\jpeg-6\jmemmgr.c" />
<ClCompile Include="..\..\jpeg-6\jmemnobs.c" /> <ClCompile Include="..\..\jpeg-6\jmemnobs.c" />
<ClCompile Include="..\..\jpeg-6\jutils.c" /> <ClCompile Include="..\..\jpeg-6\jutils.c" />
<ClCompile Include="mod_uniquake.c" />
<ClCompile Include="gl_uniquake.c" />
<ClCompile Include="sys_uniquake.c" /> <ClCompile Include="sys_uniquake.c" />
<ClCompile Include="uniquake.c" /> <ClCompile Include="uniquake.c" />
</ItemGroup> </ItemGroup>

2
engine/projects/uniquake/uniquake.vcxproj.filters

@ -533,7 +533,7 @@
<ClCompile Include="sys_uniquake.c"> <ClCompile Include="sys_uniquake.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="mod_uniquake.c">
<ClCompile Include="gl_uniquake.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>

Loading…
Cancel
Save