networking i guess
This commit is contained in:
@@ -7,15 +7,20 @@
|
||||
#include "baseentity.h"
|
||||
#include "datamap.h"
|
||||
#include "tier0/lib.h"
|
||||
#include "tier0/mem.h"
|
||||
|
||||
CBaseEntity::~CBaseEntity()
|
||||
{
|
||||
|
||||
}
|
||||
void CBaseEntity::Precache()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CBaseEntity::Spawn()
|
||||
{
|
||||
|
||||
Precache();
|
||||
}
|
||||
|
||||
void CBaseEntity::SetAbsAngles( float fPitch, float fYaw, float fRoll )
|
||||
@@ -35,22 +40,27 @@ void CBaseEntity::SetScale( float fScale )
|
||||
}
|
||||
|
||||
|
||||
QAngle CBaseEntity::GetAbsAngles( void )
|
||||
QAngle CBaseEntity::GetAbsQAngles( void )
|
||||
{
|
||||
|
||||
}
|
||||
Quat CBaseEntity::GetAbsAngles( void )
|
||||
{
|
||||
return m_vRotation;
|
||||
}
|
||||
|
||||
Vector CBaseEntity::GetAbsOrigin( void )
|
||||
{
|
||||
return m_vPosition;
|
||||
|
||||
}
|
||||
|
||||
float CBaseEntity::GetScale( void )
|
||||
{
|
||||
|
||||
return m_vScale.x;
|
||||
}
|
||||
|
||||
void CBaseEntity::SetThink( fnThink pfnThink )
|
||||
void CBaseEntity::SetThinkImpl( fnThink pfnThink )
|
||||
{
|
||||
m_pfnThink = pfnThink;
|
||||
}
|
||||
@@ -107,3 +117,9 @@ BEGIN_DATADESC_NOBASE(CBaseEntity)
|
||||
DEFINE_KEYFIELD(m_vRotation, FIELD_QUATERNION, "angles")
|
||||
DEFINE_KEYFIELD(m_vScale, FIELD_FLOAT3, "scales")
|
||||
END_DATADESC()
|
||||
|
||||
IMPLEMENT_SEND_DT_NOBASE(CBaseEntity)
|
||||
NetPropFloat3(m_vPosition)
|
||||
END_SEND_DT()
|
||||
|
||||
IMPLEMENT_EMPTY_RECV_DT_NOBASE(CBaseEntity)
|
||||
|
||||
@@ -11,15 +11,12 @@
|
||||
#include "datamap.h"
|
||||
#include "cglm/cglm.h"
|
||||
#include "trig.h"
|
||||
#include "netmap.h"
|
||||
|
||||
#define DECLARE_CLASS_NOBASE( className ) \
|
||||
typedef className ThisClass;
|
||||
#define DECLARE_CLASS( className, baseName ) \
|
||||
typedef baseName BaseClass; \
|
||||
typedef className ThisClass;
|
||||
|
||||
#define LINK_ENTITY_TO_CLASS( mapClassName, DLLClassName) \
|
||||
static CEntityFactory<DLLClassName> g_EntityFactory_##mapClassName( #mapClassName );
|
||||
static CEntityFactory<DLLClassName> g_EntityFactory_##mapClassName( #mapClassName ); \
|
||||
|
||||
|
||||
class CBaseEntity;
|
||||
|
||||
@@ -45,35 +42,46 @@ public:
|
||||
|
||||
|
||||
class CBaseEntity;
|
||||
typedef void(*fnThink)( float fTime );
|
||||
typedef void(CBaseEntity::*fnThink)( float fTime );
|
||||
class CBaseEntity
|
||||
{
|
||||
public:
|
||||
|
||||
public:
|
||||
DECLARE_CLASS_NOBASE(CBaseEntity);
|
||||
DECLARE_DATADESC_NOBASE()
|
||||
DECLARE_SERVERCLASS_NOBASE()
|
||||
|
||||
typedescription_t *FindDataByName( const char *szName );
|
||||
typedescription_t *FindDataByMapName( const char *szName );
|
||||
|
||||
const char *GetClassName();
|
||||
|
||||
virtual ~CBaseEntity();
|
||||
virtual void Precache();
|
||||
virtual void Spawn();
|
||||
|
||||
virtual void SetAbsAngles( float fPitch, float fYaw, float fRoll );
|
||||
virtual void SetAbsOrigin( Vector origin );
|
||||
virtual void SetScale( float fScale );
|
||||
|
||||
virtual QAngle GetAbsAngles( void );
|
||||
virtual QAngle GetAbsQAngles( void );
|
||||
virtual Quat GetAbsAngles( void );
|
||||
virtual Vector GetAbsOrigin( void );
|
||||
virtual float GetScale( void );
|
||||
|
||||
virtual void SetThink( fnThink pfnThink );
|
||||
#define SetThink(fn) SetThinkImpl((fnThink)&ThisClass::fn)
|
||||
virtual void SetThinkImpl( fnThink pfnThink );
|
||||
virtual void SetNextThink( float fThink );
|
||||
|
||||
fnThink m_pfnThink = NULL;
|
||||
const char *m_szClassName;
|
||||
private:
|
||||
Vector m_vPosition;
|
||||
Quat m_vRotation;
|
||||
Vector m_vScale;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
1
game/server/basemodelentity.cpp
Normal file
1
game/server/basemodelentity.cpp
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
12
game/server/basemodelentity.h
Normal file
12
game/server/basemodelentity.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef BASE_MODEL_ENTITY_H
|
||||
#define BASE_MODEL_ENTITY_H
|
||||
|
||||
#include "baseentity.h"
|
||||
|
||||
class CBaseModelEntity: public CBaseEntity
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS(CBaseModelEntity, CBaseEntity);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -18,6 +18,9 @@ DECLARE_BUILD_STAGE(Server)
|
||||
"game.cpp",
|
||||
"entitysystem.cpp",
|
||||
"baseentity.cpp",
|
||||
"basemodelentity.cpp",
|
||||
|
||||
"milmoba/player.cpp",
|
||||
};
|
||||
compileProject.includeDirectories = {
|
||||
"../../public",
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "stddef.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "engine.h"
|
||||
#include "netprotocol.h"
|
||||
|
||||
|
||||
CEntitySystem *EntitySystem()
|
||||
@@ -81,11 +83,18 @@ CBaseEntity *CEntitySystem::CreateByClassname( const char *szName )
|
||||
}
|
||||
|
||||
pEntity = pFactory->Create();
|
||||
pEntity->m_szClassName = szName;
|
||||
m_pEntities[iSelectedSlot] = pEntity;
|
||||
m_nEntityCount++;
|
||||
|
||||
EntityClass_t stClassSync = {
|
||||
MESSAGE_ENTITY_CLASS_SYNC,
|
||||
iSelectedSlot,
|
||||
};
|
||||
V_strncpy((char*)stClassSync.m_szEntityName, szName, 256);
|
||||
g_pClientBridge->SendPacket({&stClassSync, sizeof(stClassSync)});
|
||||
return pEntity;
|
||||
}
|
||||
|
||||
IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName )
|
||||
{
|
||||
EntityRegistry_t *pEntity;
|
||||
@@ -99,15 +108,27 @@ IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName )
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void CEntitySystem::Think()
|
||||
{
|
||||
CBaseEntity *pEntity;
|
||||
int i;
|
||||
|
||||
uint32_t u;
|
||||
uint32_t x;
|
||||
uint32_t uSize;
|
||||
netmap_t *pNetMap;
|
||||
void *pData;
|
||||
union {
|
||||
void *pCurrentData;
|
||||
char *pcCurrentData;
|
||||
EntityDataSync_t *pSync;
|
||||
EntityDataSyncValue_t *pValue;
|
||||
};
|
||||
|
||||
|
||||
for ( i = 0; i < MAX_EDICTS; i++ )
|
||||
{
|
||||
|
||||
pEntity = m_pEntities[i];
|
||||
if ( pEntity == NULL )
|
||||
continue;
|
||||
@@ -115,6 +136,54 @@ void CEntitySystem::Think()
|
||||
if ( !pEntity->m_pfnThink )
|
||||
continue;
|
||||
|
||||
pEntity->m_pfnThink(0);
|
||||
(pEntity->*pEntity->m_pfnThink)(0);
|
||||
|
||||
pNetMap = pEntity->GetSendMap();
|
||||
uSize = sizeof(EntityDataSyncValue_t);
|
||||
x = 0;
|
||||
while ( pNetMap )
|
||||
{
|
||||
for ( u = 0; u < pNetMap->m_uFieldCount; u++ )
|
||||
{
|
||||
x++;
|
||||
uSize += (pNetMap->m_pFields[u].m_uSize+7) & ~7;
|
||||
uSize += sizeof(EntityDataSyncValue_t);
|
||||
}
|
||||
pNetMap = pNetMap->m_pBase;
|
||||
}
|
||||
pData = V_malloc(uSize);
|
||||
V_memset(pData, 0, uSize);
|
||||
pCurrentData = pData;
|
||||
pSync->m_eType = MESSAGE_ENTITY_DATA_SYNC;
|
||||
pSync->m_uIndex = i;
|
||||
pSync->m_uCount = x;
|
||||
|
||||
pcCurrentData += sizeof(EntityDataSync_t);
|
||||
pNetMap = pEntity->GetSendMap();
|
||||
x = 0;
|
||||
while ( pNetMap )
|
||||
{
|
||||
for ( u = 0; u < pNetMap->m_uFieldCount; u++ )
|
||||
{
|
||||
pValue->m_uVariableSize = pNetMap->m_pFields[u].m_uSize;
|
||||
pValue->m_uVariableIndex = x;
|
||||
uint32_t uVariableSize;
|
||||
pcCurrentData += sizeof(EntityDataSyncValue_t);
|
||||
V_memcpy(pcCurrentData,
|
||||
pNetMap->m_pFields[u].m_uOffset+(char*)pEntity,
|
||||
pNetMap->m_pFields[u].m_uSize);
|
||||
pcCurrentData += (pNetMap->m_pFields[u].m_uSize+7) & ~7;
|
||||
x++;
|
||||
}
|
||||
pNetMap = pNetMap->m_pBase;
|
||||
}
|
||||
g_pClientBridge->SendPacket({pData, uSize});
|
||||
V_free(pData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
CBaseEntity **CEntitySystem::GetEntities()
|
||||
{
|
||||
return m_pEntities;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
virtual IEntityFactory *GetFactoryByClassname( const char *szName );
|
||||
|
||||
virtual void Think();
|
||||
virtual CBaseEntity **GetEntities();
|
||||
private:
|
||||
CBaseEntity *m_pEntities[MAX_EDICTS];
|
||||
int m_nEntityCount;
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
#include "tier2/ifilesystem.h"
|
||||
#include "materialsystem/imaterialsystem.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
|
||||
{
|
||||
@@ -13,6 +21,7 @@ class CFunnyGameBridge: public IEngineBridge
|
||||
virtual void Frame( float fDelta ) override;
|
||||
virtual void Shutdown() override;
|
||||
virtual void ConnectInterface( const char *psz, void *pInterface ) override;
|
||||
|
||||
};
|
||||
|
||||
IEngineBridge *EngineBridge()
|
||||
@@ -24,7 +33,8 @@ IEngineBridge *EngineBridge()
|
||||
EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION)
|
||||
|
||||
void CFunnyGameBridge::Init()
|
||||
{
|
||||
{
|
||||
g_pClientBridge = g_pEngineConstants->LaunchLocalBridge(0);
|
||||
}
|
||||
|
||||
void CFunnyGameBridge::Tick( float fDelta )
|
||||
@@ -34,6 +44,32 @@ 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();
|
||||
|
||||
}
|
||||
|
||||
@@ -45,5 +81,6 @@ 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)
|
||||
}
|
||||
|
||||
|
||||
26
game/server/milmoba/player.cpp
Normal file
26
game/server/milmoba/player.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "player.h"
|
||||
#include "game.h"
|
||||
|
||||
|
||||
|
||||
void CMOBAPlayer::Spawn()
|
||||
{
|
||||
SetThink(Think);
|
||||
};
|
||||
|
||||
void CMOBAPlayer::Think( float fDelta )
|
||||
{
|
||||
m_fTimer = g_pEngineVars->m_fTime;
|
||||
SetAbsOrigin({m_fTimer,0,0});
|
||||
};
|
||||
|
||||
LINK_ENTITY_TO_CLASS(player, CMOBAPlayer)
|
||||
|
||||
BEGIN_DATADESC(CMOBAPlayer)
|
||||
END_DATADESC()
|
||||
|
||||
IMPLEMENT_SEND_DT(CMOBAPlayer)
|
||||
NetPropFloat(m_fTimer)
|
||||
END_SEND_DT()
|
||||
|
||||
IMPLEMENT_EMPTY_RECV_DT(CMOBAPlayer)
|
||||
19
game/server/milmoba/player.h
Normal file
19
game/server/milmoba/player.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef MILMOBA_PLAYER_H
|
||||
#define MILMOBA_PLAYER_H
|
||||
#include "basemodelentity.h"
|
||||
|
||||
|
||||
class CMOBAPlayer: public CBaseModelEntity
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS(CMOBAPlayer, CBaseModelEntity);
|
||||
DECLARE_DATADESC();
|
||||
DECLARE_SERVERCLASS()
|
||||
|
||||
virtual void Spawn( void ) override;
|
||||
void Think( float fDelta );
|
||||
|
||||
float m_fTimer;
|
||||
};
|
||||
|
||||
#endif
|
||||
1
game/server/pointentity.cpp
Normal file
1
game/server/pointentity.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "pointentity.h"
|
||||
10
game/server/pointentity.h
Normal file
10
game/server/pointentity.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef POINT_ENTITY_H
|
||||
#define POINT_ENTITY_H
|
||||
|
||||
#include "baseentity.h"
|
||||
class CPointEntity: public CBaseEntity
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user