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.
146 lines
3.1 KiB
146 lines
3.1 KiB
#include "uniquake.h"
|
|
|
|
#include "../Quake/quakedef.h"
|
|
|
|
qboolean isDedicated;
|
|
|
|
cvar_t sys_throttle = { "sys_throttle", "0.02", CVAR_ARCHIVE };
|
|
|
|
typedef struct unity_syscalls_s
|
|
{
|
|
void(*SysPrint)(void *context, const char *msg);
|
|
void(*SysError)(void *context, const char *msg);
|
|
void(*SysQuit)(void *context);
|
|
double(*SysDoubleTime)(void *context);
|
|
|
|
int(*SysFileOpenRead)(void *context, const char *path, int *hndl);
|
|
int(*SysFileOpenWrite)(void *context, const char *path);
|
|
void(*SysFileClose)(void *context, int handle);
|
|
void(*SysFileSeek)(void *context, int handle, int position);
|
|
int(*SysFileRead)(void *context, int handle, void *dest, int count);
|
|
int(*SysFileWrite)(void *context, int handle, const void *data, int count);
|
|
int(*SysFileTime)(void *context, const char *path);
|
|
qboolean(*SysMkDir)(void *context, const char *path);
|
|
} unity_syscalls_t;
|
|
|
|
static void *unity_context;
|
|
static const unity_syscalls_t *unity_syscalls;
|
|
|
|
UNIQUAKE_API void UniQuake_SetSysCallbacks(void *context, const unity_syscalls_t *callbacks)
|
|
{
|
|
unity_context = context;
|
|
unity_syscalls = callbacks;
|
|
}
|
|
|
|
void Sys_Error(const char *error, ...)
|
|
{
|
|
va_list argptr;
|
|
char text[1024];
|
|
|
|
va_start(argptr, error);
|
|
q_vsnprintf(text, sizeof(text), error, argptr);
|
|
va_end(argptr);
|
|
|
|
unity_syscalls->SysError(unity_context, text);
|
|
}
|
|
|
|
void Sys_Printf(const char *fmt, ...)
|
|
{
|
|
va_list argptr;
|
|
char text[1024];
|
|
|
|
va_start(argptr, fmt);
|
|
q_vsnprintf(text, sizeof(text), fmt, argptr);
|
|
va_end(argptr);
|
|
|
|
unity_syscalls->SysPrint(unity_context, text);
|
|
}
|
|
|
|
void Sys_Quit(void)
|
|
{
|
|
unity_syscalls->SysQuit(unity_context);
|
|
}
|
|
|
|
double Sys_DoubleTime(void)
|
|
{
|
|
return unity_syscalls->SysDoubleTime(unity_context);
|
|
}
|
|
|
|
int Sys_FileOpenRead(const char *path, int *hndl)
|
|
{
|
|
return unity_syscalls->SysFileOpenRead(unity_context, path, hndl);
|
|
}
|
|
|
|
int Sys_FileOpenWrite(const char *path)
|
|
{
|
|
return unity_syscalls->SysFileOpenWrite(unity_context, path);
|
|
}
|
|
|
|
void Sys_FileClose(int handle)
|
|
{
|
|
unity_syscalls->SysFileClose(unity_context, handle);
|
|
}
|
|
|
|
void Sys_FileSeek(int handle, int position)
|
|
{
|
|
unity_syscalls->SysFileSeek(unity_context, handle, position);
|
|
}
|
|
|
|
int Sys_FileRead(int handle, void *dest, int count)
|
|
{
|
|
return unity_syscalls->SysFileRead(unity_context, handle, dest, count);
|
|
}
|
|
|
|
int Sys_FileWrite(int handle, const void *data, int count)
|
|
{
|
|
return unity_syscalls->SysFileWrite(unity_context, handle, data, count);
|
|
}
|
|
|
|
int Sys_FileTime(const char *path)
|
|
{
|
|
return unity_syscalls->SysFileTime(unity_context, path);
|
|
}
|
|
|
|
void Sys_mkdir(const char *path)
|
|
{
|
|
if (!unity_syscalls->SysMkDir(unity_context, path))
|
|
Sys_Error("Unable to create directory %s", path);
|
|
}
|
|
|
|
const char *Sys_ConsoleInput(void)
|
|
{
|
|
// Not implemented: we support neither STDIN nor dedicated servers in UniQuake
|
|
return NULL;
|
|
}
|
|
|
|
#ifndef USE_LIBSDL
|
|
|
|
void Sys_Sleep(unsigned long msecs)
|
|
{
|
|
// TODO: implement
|
|
}
|
|
|
|
void Sys_SendKeyEvents(void)
|
|
{
|
|
// TODO: signal Unity to process input & send commands
|
|
}
|
|
|
|
void PL_SetWindowIcon(void)
|
|
{
|
|
}
|
|
|
|
void PL_VID_Shutdown(void)
|
|
{
|
|
}
|
|
|
|
char *PL_GetClipboardData(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
void PL_ErrorDialog(const char *text)
|
|
{
|
|
// TODO: could signal this back to Unity and show a platform-specific system dialog
|
|
}
|
|
|
|
#endif // !USE_LIBSDL
|