87 lines
2.0 KiB
C++
87 lines
2.0 KiB
C++
#include "tier2/ifilesystem.h"
|
|
#include "entitysystem.h"
|
|
#include "baseentity.h"
|
|
#include "enginebridge.h"
|
|
#include "game.h"
|
|
#include "inetworkserver.h"
|
|
#include "netprotocol.h"
|
|
|
|
IFileSystem *filesystem;
|
|
IRenderContext *g_pRenderContext;
|
|
IGameWindow *g_pMainWindow;
|
|
static CEngineVars s_vars;
|
|
CEngineVars *g_pEngineVars = &s_vars;
|
|
EngineConsts_t *g_pEngineConstants;
|
|
INetworkBase *g_pClientBridge;
|
|
|
|
class CFunnyGameBridge: public IEngineBridge
|
|
{
|
|
virtual void Init() override;
|
|
virtual void Tick( float fDelta ) override;
|
|
virtual void Frame( float fDelta ) override;
|
|
virtual void Shutdown() override;
|
|
virtual void ConnectInterface( const char *psz, void *pInterface ) override;
|
|
|
|
};
|
|
|
|
IEngineBridge *EngineBridge()
|
|
{
|
|
static CFunnyGameBridge s_bridge;
|
|
return &s_bridge;
|
|
}
|
|
|
|
EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION)
|
|
|
|
void CFunnyGameBridge::Init()
|
|
{
|
|
g_pClientBridge = g_pEngineConstants->LaunchLocalBridge(0);
|
|
}
|
|
|
|
void CFunnyGameBridge::Tick( float fDelta )
|
|
{
|
|
|
|
}
|
|
|
|
void CFunnyGameBridge::Frame( float fDelta )
|
|
{
|
|
g_pEngineVars->m_fTime += fDelta;
|
|
g_pEngineVars->m_fDeltaTime = fDelta;
|
|
|
|
g_pClientBridge->NetThink();
|
|
while (g_pClientBridge->BHasUpdates())
|
|
{
|
|
NetPacket_t packet = g_pClientBridge->PeekPacket();
|
|
// discard it
|
|
if (packet.uSize < sizeof (EMessageType))
|
|
continue;
|
|
PlayerPacket_t *pPacket = (PlayerPacket_t*)packet.pData;
|
|
CBaseEntity *pEntity;
|
|
switch (pPacket->m_eType)
|
|
{
|
|
case MESSAGE_PLAYER_JOINED:
|
|
g_pClientBridge->RecievePacket();
|
|
V_printf("Hi %s\n",pPacket->m_playerJoined.m_szPlayerName);
|
|
pEntity = EntitySystem()->CreateByClassname("player");
|
|
pEntity->Spawn();
|
|
break;
|
|
default:
|
|
continue;
|
|
}
|
|
}
|
|
|
|
EntitySystem()->Think();
|
|
|
|
}
|
|
|
|
void CFunnyGameBridge::Shutdown()
|
|
{
|
|
|
|
}
|
|
|
|
#define CONNECT_INTERFACE(szName, pGlobal) if (!V_strcmp(psz, szName)) { pGlobal = (typeof(pGlobal))pInterface; return; }
|
|
void CFunnyGameBridge::ConnectInterface( const char *psz, void *pInterface )
|
|
{
|
|
CONNECT_INTERFACE("EngineConstants", g_pEngineConstants)
|
|
}
|
|
|