Browse Source

Implemented minimum system functionality to initialize Quake from inside a DLL

console
Nico de Poel 5 years ago
parent
commit
03cee3a4ce
  1. 8
      engine/code/sys_win.c
  2. 78
      engine/projects/uniquake/uniquake.c
  3. 22
      engine/projects/uniquake/uniquake.cpp
  4. 16
      engine/projects/uniquake/uniquake.h
  5. 5
      engine/projects/uniquake/uniquake.vcxproj
  6. 6
      engine/projects/uniquake/uniquake.vcxproj.filters

8
engine/code/sys_win.c

@ -453,7 +453,7 @@ void Sys_Init (void)
}
void Sys_Error (char *error, ...)
void Sys_Error_Obsolete (char *error, ...)
{
va_list argptr;
char text[1024], text2[1024];
@ -533,7 +533,7 @@ void Sys_Error (char *error, ...)
exit (1);
}
void Sys_Printf (char *fmt, ...)
void Sys_Printf_Obsolete (char *fmt, ...)
{
va_list argptr;
char text[1024];
@ -549,7 +549,7 @@ void Sys_Printf (char *fmt, ...)
}
}
void Sys_Quit (void)
void Sys_Quit_Obsolete (void)
{
VID_ForceUnlockedAndReturnState ();
@ -574,7 +574,7 @@ void Sys_Quit (void)
Sys_FloatTime
================
*/
double Sys_FloatTime (void)
double Sys_FloatTime_Win (void) // TODO: obsolete
{
static int sametimecount;
static unsigned int oldtime;

78
engine/projects/uniquake/uniquake.c

@ -0,0 +1,78 @@
// uniquake.cpp : Defines the exported functions for the DLL.
//
#include "pch.h"
#include "framework.h"
#include "uniquake.h"
#include "../../code/quakedef.h"
typedef struct unity_callbacks_s
{
void(__stdcall *DebugLog)(const char *msg);
void(__stdcall *DebugLogError)(const char *msg);
void(__stdcall *ApplicationQuit)(int exitCode);
double(__stdcall *RealtimeSinceStartup)();
} unity_callbacks_t;
const unity_callbacks_t *unity_callbacks;
void Sys_Error(char *error, ...)
{
va_list argptr;
char text[1024];
va_start(argptr, error);
vsprintf(text, error, argptr);
va_end(argptr);
unity_callbacks->DebugLogError(text);
unity_callbacks->ApplicationQuit(1);
}
void Sys_Printf(char *fmt, ...)
{
va_list argptr;
char text[1024];
va_start(argptr, fmt);
vsprintf(text, fmt, argptr);
va_end(argptr);
unity_callbacks->DebugLog(text);
}
void Sys_Quit(void)
{
Host_Shutdown();
unity_callbacks->ApplicationQuit(0);
}
double Sys_FloatTime(void)
{
return unity_callbacks->RealtimeSinceStartup();
}
UNIQUAKE_API void Uniquake_Echo(void(__stdcall *DebugLog)(const char *msg), const char *message)
{
DebugLog(message);
}
UNIQUAKE_API void Uniquake_Init(const unity_callbacks_t *callbacks, quakeparms_t *parms)
{
unity_callbacks = callbacks;
COM_InitArgv(parms->argc, parms->argv);
// TODO winquake writes com_argc/argv back to parms.argc/argv, is this necessary?
isDedicated = true;
Host_Init(parms);
}
UNIQUAKE_API void Uniquake_Update(float deltaTime)
{
// TODO: limit ticrate when running dedicated server
Host_Frame(deltaTime);
}

22
engine/projects/uniquake/uniquake.cpp

@ -1,22 +0,0 @@
// uniquake.cpp : Defines the exported functions for the DLL.
//
#include "pch.h"
#include "framework.h"
#include "uniquake.h"
// This is an example of an exported variable
UNIQUAKE_API int nuniquake=0;
// This is an example of an exported function.
UNIQUAKE_API int fnuniquake(void)
{
return 0;
}
// This is the constructor of a class that has been exported.
Cuniquake::Cuniquake()
{
return;
}

16
engine/projects/uniquake/uniquake.h

@ -1,22 +1,6 @@
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the UNIQUAKE_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// UNIQUAKE_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef UNIQUAKE_EXPORTS
#define UNIQUAKE_API __declspec(dllexport)
#else
#define UNIQUAKE_API __declspec(dllimport)
#endif
// This class is exported from the dll
class UNIQUAKE_API Cuniquake {
public:
Cuniquake(void);
// TODO: add your methods here.
};
extern UNIQUAKE_API int nuniquake;
UNIQUAKE_API int fnuniquake(void);

5
engine/projects/uniquake/uniquake.vcxproj

@ -71,7 +71,7 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<TargetName>UNIQUAKE</TargetName>
<TargetName>uniquake</TargetName>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -97,6 +97,7 @@
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -354,7 +355,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="uniquake.cpp" />
<ClCompile Include="uniquake.c" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\code\winquake.rc" />

6
engine/projects/uniquake/uniquake.vcxproj.filters

@ -245,9 +245,6 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="uniquake.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -539,6 +536,9 @@
<ClCompile Include="..\..\jpeg-6\jutils.c">
<Filter>jpeg</Filter>
</ClCompile>
<ClCompile Include="uniquake.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\code\winquake.rc">

Loading…
Cancel
Save