47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#include "server.h"
|
|
#include "tier1/utlstring.h"
|
|
#include "baseentity.h"
|
|
#include "console.h"
|
|
#include "physics.h"
|
|
|
|
void *g_serverdll;
|
|
ConVar g_tickrate("tickrate","64",FCVAR_PROTECTED);
|
|
float g_fAccumulator = 0;
|
|
|
|
void IServer::LoadGame( const char *psz )
|
|
{
|
|
#ifdef __WIN32__
|
|
g_serverdll = Plat_LoadLibrary(CUtlString("%s/bin/server.dll", psz));
|
|
#endif
|
|
#ifdef __linux__
|
|
g_serverdll = Plat_LoadLibrary(CUtlString("%s/bin/libserver.so", psz));
|
|
Plat_LoadLibrary(CUtlString("%s/bin/libclient.so", psz));
|
|
|
|
#endif
|
|
void (*GameLoadfn)() = (void(*)())Plat_GetProc(g_serverdll, "IGame_Load");
|
|
if (!GameLoadfn)
|
|
Plat_FatalErrorFunc("IGame_Load not found in libserver.so\n");
|
|
GameLoadfn();
|
|
};
|
|
|
|
void IServer::Think( float fDelta )
|
|
{
|
|
g_fAccumulator += fDelta;
|
|
float fTickrate = 1.0/g_tickrate.GetFloat();
|
|
/* tickrate */
|
|
while(g_fAccumulator>=fTickrate)
|
|
{
|
|
g_fAccumulator-=fTickrate;
|
|
for (auto &entity: g_entities)
|
|
{
|
|
entity->Think(fTickrate);
|
|
}
|
|
px_frame(px, fTickrate);
|
|
}
|
|
for (auto &entity: g_entities)
|
|
{
|
|
if (entity->pClientEntity)
|
|
entity->pClientEntity->Think(fDelta);
|
|
}
|
|
};
|