183 lines
4.7 KiB
C++
183 lines
4.7 KiB
C++
#include "input.h"
|
|
#include "tier1/commandline.h"
|
|
#include "tier1/utlstring.h"
|
|
#include "tier0/lib.h"
|
|
#include "console.h"
|
|
#include "filesystem.h"
|
|
#include "rendering.h"
|
|
#include "engine.h"
|
|
#include "baseentity.h"
|
|
#include "server.h"
|
|
#include "physics.h"
|
|
#include "signal.h"
|
|
|
|
double fPrev = 0;
|
|
double fCurrent = 0;
|
|
|
|
funnyphysics *px;
|
|
|
|
IIClient g_localClient;
|
|
|
|
CUtlVector<IIClient*> g_clients;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Engine entry point
|
|
//-----------------------------------------------------------------------------
|
|
extern "C" void FunnyMain( int argc, char **argv ) {
|
|
|
|
ICommandLine::CreateCommandLine(argc, argv);
|
|
IEngine::Init();
|
|
for (;;)
|
|
{
|
|
fPrev = fCurrent;
|
|
fCurrent = Plat_GetTime();
|
|
IEngine::Frame(fCurrent-fPrev);
|
|
};
|
|
/* deinit is handled explicitly */
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Recieves signals from the system
|
|
//-----------------------------------------------------------------------------
|
|
void IEngine_Signal(int sig)
|
|
{
|
|
printf("Trapped signal %i\n",sig);
|
|
switch (sig)
|
|
{
|
|
case SIGSEGV:
|
|
case SIGILL:
|
|
case SIGABRT:
|
|
printf("Consider running app with debugger attached\n");
|
|
Plat_Backtrace();
|
|
break;
|
|
default:
|
|
break;
|
|
};
|
|
IEngine::Shutdown();
|
|
Plat_Exit(0);
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Initializes engine
|
|
//-----------------------------------------------------------------------------
|
|
void IEngine::Init()
|
|
{
|
|
/* trap signals */
|
|
#ifdef __linux__
|
|
signal(SIGHUP, IEngine_Signal);
|
|
signal(SIGINT, IEngine_Signal);
|
|
signal(SIGQUIT, IEngine_Signal);
|
|
signal(SIGILL, IEngine_Signal);
|
|
signal(SIGTRAP, IEngine_Signal);
|
|
signal(SIGIOT, IEngine_Signal);
|
|
signal(SIGBUS, IEngine_Signal);
|
|
signal(SIGFPE, IEngine_Signal);
|
|
signal(SIGSEGV, IEngine_Signal);
|
|
signal(SIGTERM, IEngine_Signal);
|
|
#endif
|
|
#ifdef __WIN32__
|
|
signal(SIGINT, IEngine_Signal);
|
|
signal(SIGILL, IEngine_Signal);
|
|
signal(SIGFPE, IEngine_Signal);
|
|
signal(SIGSEGV, IEngine_Signal);
|
|
signal(SIGTERM, IEngine_Signal);
|
|
#endif
|
|
|
|
IFileSystem::InitFilesystem();
|
|
px = px_init();
|
|
|
|
if (!ICommandLine::CheckParam("-dedicated"))
|
|
{
|
|
g_localClient = {
|
|
|
|
};
|
|
IIEngine::ConnectClient(&g_localClient);
|
|
|
|
IVideo::Init();
|
|
IInput::Init();
|
|
IInput::SetMouseMode(MOUSE_MODE_GAME);
|
|
}
|
|
|
|
IServer::LoadGame("funnygame");
|
|
|
|
IVideo::CreatePipelines();
|
|
|
|
IConsole::AddCommand("exec default.cfg;");
|
|
IConsole::Execute();
|
|
|
|
};
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Updates every frame
|
|
//-----------------------------------------------------------------------------
|
|
void IEngine::Frame(float fDelta)
|
|
{
|
|
IServer::Think(fDelta);
|
|
IVideo::Frame(fDelta);
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Deinitializes engine
|
|
//-----------------------------------------------------------------------------
|
|
void IEngine::Shutdown()
|
|
{
|
|
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Spawns entity in the world
|
|
//-----------------------------------------------------------------------------
|
|
CBaseEntity *IIEngine::SpawnEntity( const char *szName )
|
|
{
|
|
for (auto &entity: g_RegisteredEntities)
|
|
{
|
|
if (!V_strcmp(entity->m_szName, szName))
|
|
{
|
|
CBaseEntity *pEnt = entity->m_pfn();
|
|
g_entities.AppendTail(pEnt);
|
|
if (entity->m_pClientfn)
|
|
{
|
|
pEnt->pClientEntity = entity->m_pClientfn();
|
|
pEnt->pClientEntity->pEntity = pEnt;
|
|
}
|
|
return pEnt;
|
|
}
|
|
}
|
|
return 0;
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Spawns entity without any parameters
|
|
//-----------------------------------------------------------------------------
|
|
void IIEngine::InitEntity( CBaseEntity *pEntity )
|
|
{
|
|
if (!pEntity)
|
|
return;
|
|
pEntity->Spawn();
|
|
if (pEntity->pClientEntity)
|
|
pEntity->pClientEntity->Spawn();
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Destroys entity
|
|
//-----------------------------------------------------------------------------
|
|
void IIEngine::DestroyEntity( CBaseEntity *pEntity )
|
|
{
|
|
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Connects client to the server
|
|
//-----------------------------------------------------------------------------
|
|
void IIEngine::ConnectClient( IIClient *pClient)
|
|
{
|
|
g_clients.AppendTail(pClient);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Disconnects client from the server
|
|
//-----------------------------------------------------------------------------
|
|
void IIEngine::DisconnectClient( IIClient *pClient)
|
|
{
|
|
}
|
|
|