networking i guess
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user