work on world
This commit is contained in:
@@ -151,29 +151,29 @@ uint32_t CAssetManager::LoadModel( const char *szName )
|
||||
switch (pRoot->GetType())
|
||||
{
|
||||
case JSON_PARAMETER_OBJECT:
|
||||
{
|
||||
pMainObject = pRoot->GetObject();
|
||||
if (!pMainObject)
|
||||
{
|
||||
pMainObject = pRoot->GetObject();
|
||||
if (!pMainObject)
|
||||
{
|
||||
V_printf("Failed to load properties\n");
|
||||
return 0;
|
||||
V_printf("Failed to load properties\n");
|
||||
return 0;
|
||||
|
||||
}
|
||||
IJSONValue *pMesh = pMainObject->GetValue("Mesh");
|
||||
IJSONValue *pMaterial = pMainObject->GetValue("Material");
|
||||
IJSONValue *pPhysics = pMainObject->GetValue("Physics");
|
||||
if (pMesh)
|
||||
pModel->m_hMesh = LoadMesh(pMesh->GetStringValue());
|
||||
if (pMaterial)
|
||||
pModel->m_hMaterial = LoadMaterial(pMaterial->GetStringValue());
|
||||
if (pPhysics)
|
||||
pModel->m_hPhysics = LoadPhysics(pPhysics->GetStringValue());
|
||||
}
|
||||
IJSONValue *pMesh = pMainObject->GetValue("Mesh");
|
||||
IJSONValue *pMaterial = pMainObject->GetValue("Material");
|
||||
IJSONValue *pPhysics = pMainObject->GetValue("Physics");
|
||||
if (pMesh)
|
||||
pModel->m_hMesh = LoadMesh(pMesh->GetStringValue());
|
||||
if (pMaterial)
|
||||
pModel->m_hMaterial = LoadMaterial(pMaterial->GetStringValue());
|
||||
if (pPhysics)
|
||||
pModel->m_hPhysics = LoadPhysics(pPhysics->GetStringValue());
|
||||
|
||||
|
||||
|
||||
return hModel;
|
||||
}
|
||||
break;
|
||||
return hModel;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -317,6 +317,7 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||
IJSONValue *pRoot = JSONManager()->ReadString(szProperties);
|
||||
if (!pRoot)
|
||||
return 0;
|
||||
V_printf("PHYSICS %s\n", szName);
|
||||
|
||||
IJSONObject *pMainObject;
|
||||
switch (pRoot->GetType())
|
||||
@@ -339,6 +340,7 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||
return 0;
|
||||
}
|
||||
CUtlString szType = pTypeValue->GetStringValue();
|
||||
V_printf("szType\n");
|
||||
if (szType == "Sphere")
|
||||
{
|
||||
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
||||
|
||||
@@ -78,9 +78,9 @@ public:
|
||||
fnThink m_pfnThink = NULL;
|
||||
CUtlString m_szClassName;
|
||||
private:
|
||||
Vector m_vPosition;
|
||||
Quat m_vRotation;
|
||||
Vector m_vScale;
|
||||
Vector m_vPosition = {};
|
||||
Quat m_vRotation = {};
|
||||
Vector m_vScale = {1,1,1};
|
||||
|
||||
uint64_t m_uSlot;
|
||||
};
|
||||
|
||||
@@ -12,32 +12,68 @@ void C_BaseModelEntity::Spawn()
|
||||
|
||||
void C_BaseModelEntity::Think( float fDelta )
|
||||
{
|
||||
m_pInstance->SetPosition(GetAbsOrigin());
|
||||
m_pInstance->SetRotation(GetAbsAngles());
|
||||
m_pInstance->SetScale({GetScale(),GetScale(),GetScale()});
|
||||
UpdateModel();
|
||||
if (m_pInstance)
|
||||
{
|
||||
m_pInstance->SetPosition(GetAbsOrigin());
|
||||
m_pInstance->SetRotation(GetAbsAngles());
|
||||
m_pInstance->SetScale({GetScale(),GetScale(),GetScale()});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void C_BaseModelEntity::SetModel( const char *szName )
|
||||
{
|
||||
V_memset(m_szModel, 0, 256);
|
||||
V_strncpy(m_szModel, szName, 255);
|
||||
}
|
||||
|
||||
void C_BaseModelEntity::UpdateModel()
|
||||
{
|
||||
if (!V_strncmp(m_szModel, m_szCurrentModel, 256))
|
||||
return;
|
||||
|
||||
V_memset(m_szCurrentModel, 0, 256);
|
||||
V_strncpy(m_szCurrentModel, m_szModel, 255);
|
||||
|
||||
if (m_hModelHandle)
|
||||
{
|
||||
g_pAssetManager->UnrefModel(m_hModelHandle);
|
||||
g_pWorldRenderer->DestroyMeshInstance(
|
||||
g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh)->m_pMesh,
|
||||
m_pInstance);
|
||||
}
|
||||
m_hModelHandle = g_pAssetManager->LoadModel(szName);
|
||||
m_hModelHandle = g_pAssetManager->LoadModel(m_szCurrentModel);
|
||||
m_pModel = g_pAssetManager->GetModelByIndex(m_hModelHandle);
|
||||
if (!m_pModel)
|
||||
{
|
||||
V_printf("Failed to load %u %s\n", V_strnlen(m_szCurrentModel,255), m_szCurrentModel);
|
||||
m_pInstance = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
FunnyMesh_t *pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh);
|
||||
m_pInstance = g_pWorldRenderer->CreateInstance(pMesh->m_pMesh);
|
||||
|
||||
}
|
||||
|
||||
C_BaseModelEntity::~C_BaseModelEntity()
|
||||
{
|
||||
FunnyMesh_t *pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh);
|
||||
g_pWorldRenderer->DestroyMeshInstance(pMesh->m_pMesh, m_pInstance);
|
||||
g_pAssetManager->UnrefModel(m_hModelHandle);
|
||||
if (m_pInstance)
|
||||
{
|
||||
FunnyMesh_t *pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh);
|
||||
g_pWorldRenderer->DestroyMeshInstance(pMesh->m_pMesh, m_pInstance);
|
||||
g_pAssetManager->UnrefModel(m_hModelHandle);
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_DATADESC(C_BaseModelEntity)
|
||||
|
||||
DEFINE_KEYFIELD(m_szModel, FIELD_STRING, "model")
|
||||
END_DATADESC()
|
||||
|
||||
IMPLEMENT_RECV_DT(C_BaseModelEntity)
|
||||
NetPropString(m_szModel)
|
||||
END_RECV_DT()
|
||||
IMPLEMENT_EMPTY_SEND_DT(C_BaseModelEntity)
|
||||
|
||||
LINK_ENTITY_TO_CLASS(prop_physics, C_BaseModelEntity)
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
class C_BaseModelEntity: public C_BaseEntity
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS(C_BaseModelEntity, C_BaseEntity);
|
||||
DECLARE_DATADESC();
|
||||
DECLARE_CLASS(C_BaseModelEntity, C_BaseEntity)
|
||||
DECLARE_DATADESC()
|
||||
DECLARE_CLIENTCLASS()
|
||||
|
||||
virtual ~C_BaseModelEntity() override;
|
||||
virtual void Precache() override;
|
||||
@@ -20,9 +21,13 @@ public:
|
||||
void SetModel( const char *szName );
|
||||
private:
|
||||
|
||||
HFunnyModel m_hModelHandle;
|
||||
FunnyModel_t *m_pModel;
|
||||
IMeshInstance *m_pInstance;
|
||||
void UpdateModel();
|
||||
char m_szCurrentModel[256] = {};
|
||||
char m_szModel[256] = {};
|
||||
|
||||
HFunnyModel m_hModelHandle = 0;
|
||||
FunnyModel_t *m_pModel = NULL;
|
||||
IMeshInstance *m_pInstance = NULL;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -229,6 +229,16 @@ void CEntitySystem::NetRecvPacket( NetPacket_t *pPacket )
|
||||
if (pPlayerPacket->m_setLocalEntity.m_uIndex > MAX_EDICTS)
|
||||
break;
|
||||
s_pLocalEntity = m_pEntities[pPlayerPacket->m_setLocalEntity.m_uIndex];
|
||||
break;
|
||||
case k_EMessage_ResetEntities:
|
||||
{
|
||||
C_BaseEntity **ppEntities = m_pEntities;
|
||||
for ( int i = 0; i < MAX_EDICTS; i++ )
|
||||
{
|
||||
DestroyEntityByIndex(i);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
void C_MOBAPlayer::Precache()
|
||||
{
|
||||
SetModel("game/core/models/cube.fmdl");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ void CFunnyMeshInstance::Frame()
|
||||
v[2] = m_vScale.z;
|
||||
glm_scale_make(m, v);
|
||||
glm_mat4_mul(m_data.m_matTranslation, m, m_data.m_matTranslation);
|
||||
|
||||
m_data.m_uAlbedo = 1;
|
||||
}
|
||||
|
||||
@@ -223,12 +224,6 @@ void CFunnyWorldRenderer::Frame( float fDelta )
|
||||
glm_translate(matCamera2, m_vPos);
|
||||
glm_perspective(glm_rad(60), uWidth/(float)uHeight, 0.01, 10000, matCamera);
|
||||
glm_mul(matCamera, matCamera2, matCamera);
|
||||
/*
|
||||
V_printf("%f %f %f %f\n", matCamera[0][0], matCamera[0][1], matCamera[0][2], matCamera[0][3]);
|
||||
V_printf("%f %f %f %f\n", matCamera[1][0], matCamera[1][1], matCamera[1][2], matCamera[1][3]);
|
||||
V_printf("%f %f %f %f\n", matCamera[2][0], matCamera[2][1], matCamera[2][2], matCamera[2][3]);
|
||||
V_printf("%f %f %f %f\n", matCamera[3][0], matCamera[3][1], matCamera[3][2], matCamera[3][3]);
|
||||
*/
|
||||
m_pViewBufferData = (ViewBuffer_t*)m_pViewBuffer->Map();
|
||||
m_pViewBuffer->Lock();
|
||||
V_memcpy(&m_pViewBufferData->m_matCameraProjection, matCamera, sizeof(matCamera));
|
||||
@@ -308,11 +303,11 @@ void CFunnyWorldRenderer::Frame( float fDelta )
|
||||
m_pRasterMaterial->PSSetTextureArray(1, m_pTextures);
|
||||
g_pRenderContext->DestroyBuffer(pDataBuffer);
|
||||
}
|
||||
m_pRasterCommandList->SetMaterial(m_pRasterMaterial);
|
||||
for ( auto mesh: m_pMeshes)
|
||||
{
|
||||
if (mesh->m_instances.GetSize()==0)
|
||||
continue;
|
||||
m_pRasterCommandList->SetMaterial(m_pRasterMaterial);
|
||||
m_pRasterCommandList->SetVertexBuffer(0, mesh->m_pVertexBuffer);
|
||||
m_pRasterCommandList->DrawPrimitives(mesh->m_pVertexBuffer->GetSize()/32, 0, mesh->m_instances.GetSize(), 0);
|
||||
}
|
||||
|
||||
@@ -195,6 +195,7 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||
if (!bHasBeenCreated)
|
||||
return hPhysics;
|
||||
FunnyPhysics_t *pPhysics = m_physics.GetObjectPtr(hPhysics);
|
||||
*pPhysics = {};
|
||||
|
||||
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
|
||||
if (!pHandle)
|
||||
@@ -225,10 +226,14 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||
return 0;
|
||||
}
|
||||
CUtlString szType = pTypeValue->GetStringValue();
|
||||
V_printf("%s\n", szType.GetString());
|
||||
if (szType == "Sphere")
|
||||
{
|
||||
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
||||
}
|
||||
if (szType == "Triangles")
|
||||
{
|
||||
}
|
||||
|
||||
return hPhysics;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ lookforname:
|
||||
BEGIN_DATADESC_NOBASE(CBaseEntity)
|
||||
DEFINE_KEYFIELD(m_vPosition, FIELD_FLOAT3, "origin")
|
||||
DEFINE_KEYFIELD(m_vRotation, FIELD_QUATERNION, "angles")
|
||||
DEFINE_KEYFIELD(m_vScale, FIELD_FLOAT3, "scales")
|
||||
DEFINE_KEYFIELD(m_vScale, FIELD_FLOAT3, "scale")
|
||||
END_DATADESC()
|
||||
|
||||
IMPLEMENT_SEND_DT_NOBASE(CBaseEntity)
|
||||
|
||||
@@ -81,9 +81,9 @@ public:
|
||||
const char *m_szClassName;
|
||||
uint64_t m_ullOwner;
|
||||
private:
|
||||
Vector m_vPosition;
|
||||
Quat m_vRotation;
|
||||
Vector m_vScale;
|
||||
Vector m_vPosition = {};
|
||||
Quat m_vRotation = {};
|
||||
Vector m_vScale = {1,1,1};
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -1,6 +1,37 @@
|
||||
#include "basemodelentity.h"
|
||||
#include "game.h"
|
||||
|
||||
void CBaseModelEntity::Spawn()
|
||||
{
|
||||
SetThink(Think);
|
||||
}
|
||||
|
||||
void CBaseModelEntity::SetModel( const char *szName )
|
||||
{
|
||||
V_memset(m_szModel, 0, 256);
|
||||
V_strncpy(m_szModel, szName, 255);
|
||||
}
|
||||
|
||||
void CBaseModelEntity::OnModelChanged( const char *szName )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CBaseModelEntity::Think( float fDelta )
|
||||
{
|
||||
if (V_strncmp(m_szModel, m_szCurrentModel, 256))
|
||||
{
|
||||
V_memset(m_szCurrentModel, 0, 256);
|
||||
V_strncpy(m_szCurrentModel, m_szModel, 255);
|
||||
OnModelChanged(m_szCurrentModel);
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_SEND_DT(CBaseModelEntity)
|
||||
NetPropString(m_szModel)
|
||||
END_RECV_DT()
|
||||
IMPLEMENT_EMPTY_RECV_DT(CBaseModelEntity)
|
||||
|
||||
BEGIN_DATADESC(CBaseModelEntity)
|
||||
DEFINE_KEYFIELD(m_szModel, FIELD_STRING, "model")
|
||||
END_DATADESC()
|
||||
|
||||
@@ -10,7 +10,15 @@ class CBaseModelEntity: public CBaseEntity
|
||||
public:
|
||||
|
||||
DECLARE_CLASS(CBaseModelEntity, CBaseEntity);
|
||||
DECLARE_DATADESC()
|
||||
DECLARE_SERVERCLASS()
|
||||
virtual void Spawn() override;
|
||||
virtual void SetModel( const char *szName );
|
||||
virtual void OnModelChanged( const char *szName );
|
||||
virtual void Think( float fDelta );
|
||||
private:
|
||||
char m_szCurrentModel[256] = {};
|
||||
char m_szModel[256] = {};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,7 @@ DECLARE_BUILD_STAGE(Server)
|
||||
|
||||
"game.cpp",
|
||||
"assetmgr.cpp",
|
||||
"worldsystem.cpp",
|
||||
|
||||
"entitysystem.cpp",
|
||||
"baseentity.cpp",
|
||||
|
||||
@@ -262,6 +262,8 @@ void CEntitySystem::NetSendThink( INetworkBase *pBase )
|
||||
V_memcpy(pcCurrentData,
|
||||
pNetMap->m_pFields[u].m_uOffset+(char*)pEntity,
|
||||
pNetMap->m_pFields[u].m_uSize);
|
||||
//if (pNetMap->m_pFields[u].m_eType == FIELD_STRING)
|
||||
//V_printf("v: %s %u\n", pcCurrentData, pNetMap->m_pFields[u].m_uSize);
|
||||
pcCurrentData += (pNetMap->m_pFields[u].m_uSize+7) & ~7;
|
||||
x++;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
#include "baseentity.h"
|
||||
#include "enginebridge.h"
|
||||
#include "game.h"
|
||||
#include "inetworkserver.h"
|
||||
#include "netprotocol.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "iphysics.h"
|
||||
#include "worldsystem.h"
|
||||
#ifdef STEAM
|
||||
#include "steam/isteamgameserver.h"
|
||||
#include "steam/steam_gameserver.h"
|
||||
@@ -91,9 +90,12 @@ void CFunnyGameBridge::Init()
|
||||
if (g_pEngineConstants->m_bIsSteam)
|
||||
{
|
||||
SteamErrMsg err = { 0 };
|
||||
if (SteamGameServer_InitEx(INADDR_ANY, FUNNY_SECURE_PORT, FUNNY_QUERY_PORT, eServerModeAuthentication, "0.0.0.0", &err));
|
||||
if (!SteamGameServer())
|
||||
{
|
||||
V_printf("SteamGameServer_InitEx: %s\n", err);
|
||||
if (SteamGameServer_InitEx(INADDR_ANY, FUNNY_SECURE_PORT, FUNNY_QUERY_PORT, eServerModeAuthentication, "0.0.0.0", &err))
|
||||
{
|
||||
V_printf("SteamGameServer_InitEx: %s\n", err);
|
||||
}
|
||||
}
|
||||
SteamNetworkingUtils()->InitRelayNetworkAccess();
|
||||
}
|
||||
@@ -118,6 +120,8 @@ void CFunnyGameBridge::Init()
|
||||
CreateInterfaceFn fnPhysicsFactory = Sys_GetFactory("RapierPhysics");
|
||||
g_pPhysics = (IPhysics*)fnPhysicsFactory(PHYSICS_INTERFACE_VERSION, NULL);
|
||||
g_pPhysicsWorld = g_pPhysics->CreateWorld();
|
||||
|
||||
g_pWorldSystem->LoadMap("game/core/maps/test/test.fmap");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,12 +11,19 @@ void CPhysicsProp::Spawn()
|
||||
{
|
||||
CBaseEntity::Spawn();
|
||||
SetThink(Think);
|
||||
|
||||
V_printf("hi\n");
|
||||
}
|
||||
|
||||
void CPhysicsProp::Think( float fDelta )
|
||||
{
|
||||
BaseClass::SetAbsOrigin(m_pBody->GetPosition());
|
||||
BaseClass::SetAbsAngles(m_pBody->GetRotation());
|
||||
BaseClass::Think(fDelta);
|
||||
if (m_pBody)
|
||||
{
|
||||
BaseClass::SetAbsOrigin(m_pBody->GetPosition());
|
||||
BaseClass::SetAbsAngles(m_pBody->GetRotation());
|
||||
}
|
||||
V_printf("%f %f %f\n", GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z);
|
||||
}
|
||||
|
||||
void CPhysicsProp::SetAbsAngles( Quat vQuat )
|
||||
@@ -42,7 +49,7 @@ void CPhysicsProp::SetAbsOrigin( Vector origin )
|
||||
m_pBody->SetPosition(m_pBody->GetPosition());
|
||||
}
|
||||
|
||||
void CPhysicsProp::SetModel( const char *szName )
|
||||
void CPhysicsProp::OnModelChanged( const char *szName )
|
||||
{
|
||||
if (m_hModel)
|
||||
{
|
||||
@@ -65,3 +72,4 @@ void CPhysicsProp::DisableMovement()
|
||||
|
||||
}
|
||||
|
||||
LINK_ENTITY_TO_CLASS(prop_physics, CPhysicsProp)
|
||||
|
||||
@@ -16,12 +16,13 @@ public:
|
||||
virtual void SetAbsQAngles( float fPitch, float fYaw, float fRoll ) override;
|
||||
virtual void SetAbsOrigin( Vector origin ) override;
|
||||
|
||||
virtual void SetModel( const char *szName ) override;
|
||||
virtual void OnModelChanged( const char *szName ) override;
|
||||
virtual void EnableMovement();
|
||||
virtual void DisableMovement();
|
||||
|
||||
void Think( float fDelta );
|
||||
private:
|
||||
EPhysicsBodyType m_ePhysicsType;
|
||||
HFunnyModel m_hModel = 0;
|
||||
FunnyModel_t *m_pModel = NULL;
|
||||
FunnyPhysics_t *m_pPhysics = NULL;
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
#include "worldsystem.h"
|
||||
#include "game.h"
|
||||
#include "entitysystem.h"
|
||||
#include "baseentity.h"
|
||||
#include "netprotocol.h"
|
||||
|
||||
void CWorldSystem::LoadEntity( IJSONValue *pObject )
|
||||
{
|
||||
if (pObject->GetType() != JSON_PARAMETER_OBJECT)
|
||||
return;
|
||||
IJSONObject *pObjectRoot = pObject->GetObject();
|
||||
|
||||
const char *szClassName = NULL;
|
||||
|
||||
for ( int i = 0; i < pObjectRoot->GetCount(); i++)
|
||||
{
|
||||
if (V_strcmp(pObjectRoot->GetParameterName(i),"classname"))
|
||||
continue;
|
||||
|
||||
IJSONValue *pValue = pObjectRoot->GetParameter(i);
|
||||
if (pValue->GetType() != JSON_PARAMETER_STRING)
|
||||
{
|
||||
V_printf("classname must be a string\n");
|
||||
break;
|
||||
}
|
||||
szClassName = pValue->GetStringValue();
|
||||
break;
|
||||
}
|
||||
if (szClassName == NULL)
|
||||
return;
|
||||
CBaseEntity *pEntity = EntitySystem()->CreateByClassname(szClassName, NULL);
|
||||
if (!pEntity)
|
||||
return;
|
||||
for ( int i = 0; i < pObjectRoot->GetCount(); i++)
|
||||
{
|
||||
if (!V_strcmp(pObjectRoot->GetParameterName(i),"classname"))
|
||||
continue;
|
||||
|
||||
|
||||
IJSONValue *pValue = pObjectRoot->GetParameter(i);
|
||||
typedescription_t *pDataMap = pEntity->FindDataByMapName(pObjectRoot->GetParameterName(i));
|
||||
if (!pDataMap)
|
||||
continue;
|
||||
union {
|
||||
void *pData;
|
||||
float *pfData;
|
||||
Vector *pvData;
|
||||
char *pcData;
|
||||
};
|
||||
pData = (char*)pEntity+pDataMap->m_iFieldOffset;
|
||||
switch (pDataMap->m_eFieldType)
|
||||
{
|
||||
case FIELD_STRING:
|
||||
if (pValue->GetType() != JSON_PARAMETER_STRING)
|
||||
continue;
|
||||
V_strncpy(pcData, pValue->GetStringValue(), pDataMap->m_uFieldSize);
|
||||
V_printf("loading %s %u\n", pValue->GetStringValue(), pDataMap->m_uFieldSize);
|
||||
continue;
|
||||
case FIELD_FLOAT3:
|
||||
if (pValue->GetType() != JSON_PARAMETER_ARRAY)
|
||||
continue;
|
||||
if (pValue->GetArray()->GetCount() == 3)
|
||||
{
|
||||
if ( pValue->GetArray()->GetParameter(0)->GetType()
|
||||
== JSON_PARAMETER_NUMBER )
|
||||
pvData->x = pValue->GetArray()->GetParameter(0)->GetNumberValue();
|
||||
if ( pValue->GetArray()->GetParameter(1)->GetType()
|
||||
== JSON_PARAMETER_NUMBER )
|
||||
pvData->y = pValue->GetArray()->GetParameter(1)->GetNumberValue();
|
||||
if ( pValue->GetArray()->GetParameter(2)->GetType()
|
||||
== JSON_PARAMETER_NUMBER )
|
||||
pvData->z = pValue->GetArray()->GetParameter(2)->GetNumberValue();
|
||||
|
||||
}
|
||||
continue;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
pEntity->Spawn();
|
||||
}
|
||||
|
||||
bool CWorldSystem::LoadMap( const char *szName )
|
||||
{
|
||||
V_printf("Loading %s\n", szName);
|
||||
// unload the map
|
||||
|
||||
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
|
||||
if (!pHandle)
|
||||
return 0;
|
||||
|
||||
CUtlString szProperties = filesystem->ReadString(pHandle);
|
||||
IJSONValue *pRoot = JSONManager()->ReadString(szProperties);
|
||||
filesystem->Close(pHandle);
|
||||
|
||||
if (!pRoot)
|
||||
return 0;
|
||||
|
||||
|
||||
// can't fail at this point
|
||||
|
||||
|
||||
|
||||
switch (pRoot->GetType())
|
||||
{
|
||||
case JSON_PARAMETER_ARRAY:
|
||||
{
|
||||
for ( uint32_t u = 0; u < pRoot->GetArray()->GetCount(); u++ )
|
||||
{
|
||||
IJSONValue *pObjectValue = pRoot->GetArray()->GetParameter(u);
|
||||
if ( !pObjectValue )
|
||||
continue;
|
||||
LoadEntity(pObjectValue);
|
||||
}
|
||||
JSONManager()->FreeValue(pRoot);
|
||||
return 1;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
static CWorldSystem s_worldSystem;
|
||||
CWorldSystem *g_pWorldSystem = &s_worldSystem;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef WORLD_SYSTEM_H
|
||||
#define WORLD_SYSTEM_H
|
||||
|
||||
#include "assetmgr.h"
|
||||
#include "tier2/fileformats/json.h"
|
||||
|
||||
class CWorldSystem
|
||||
{
|
||||
public:
|
||||
virtual bool LoadMap( const char *szName );
|
||||
private:
|
||||
virtual void LoadEntity( IJSONValue *pObject);
|
||||
};
|
||||
extern CWorldSystem *g_pWorldSystem;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -98,9 +98,11 @@ struct datamap_t
|
||||
#define _class_offsetof( class, var ) ((size_t)&(((class*)0)->var))
|
||||
|
||||
#define _FIELD( name, fieldtype, count, flags, mapname, tolerance) { #name, mapname, fieldtype, _class_offsetof(ThisClass, name), count, sizeof(((ThisClass*)0)->name), flags },
|
||||
#define DEFINE_FIELD( name, fieldtype ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY, 0, 0)
|
||||
#define DEFINE_KEYFIELD( name, fieldtype, mapname ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY, mapname, 0)
|
||||
#define DEFINE_FIELD( name, fieldtype ) _FIELD( name, fieldtype, 1, FTYPEDESC_SAVE, 0, 0)
|
||||
#define DEFINE_KEYFIELD( name, fieldtype, mapname ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY | FTYPEDESC_SAVE, mapname, 0)
|
||||
|
||||
#define FTYPEDESC_GLOBAL 0x0001
|
||||
#define FTYPEDESC_SAVE 0x0002
|
||||
#define FTYPEDESC_KEY 0x0004
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,13 @@
|
||||
#include "stdint.h"
|
||||
#include "datamap.h"
|
||||
|
||||
template <typename T>
|
||||
class CNetworkVarBase
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct netfield_t
|
||||
{
|
||||
const char *m_szName;
|
||||
@@ -20,6 +27,7 @@ struct netmap_t
|
||||
};
|
||||
|
||||
#define NetPropInt(name) { #name, FIELD_INT, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||
#define NetPropString(name) { #name, FIELD_STRING, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||
#define NetPropFloat(name) { #name, FIELD_FLOAT, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||
#define NetPropFloat3(name) \
|
||||
NetPropFloat(name.x), \
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
#include "stdint.h"
|
||||
#include "tier0/network.h"
|
||||
|
||||
class CNetworkUInt32
|
||||
class CNetworkProtocolUInt32
|
||||
{
|
||||
public:
|
||||
CNetworkUInt32() : m_uValue(0) {}
|
||||
CNetworkUInt32( uint32_t uValue ) : m_uValue(htonl(uValue)) {}
|
||||
CNetworkProtocolUInt32() : m_uValue(0) {}
|
||||
CNetworkProtocolUInt32( uint32_t uValue ) : m_uValue(htonl(uValue)) {}
|
||||
operator uint32_t() const {
|
||||
return htonl(m_uValue);
|
||||
}
|
||||
@@ -25,6 +25,7 @@ enum EMessageType: uint32_t
|
||||
MESSAGE_ENTITY_DATA_SYNC,
|
||||
|
||||
k_EMessage_PlayerSetLocalEntity,
|
||||
k_EMessage_ResetEntities,
|
||||
};
|
||||
|
||||
struct PlayerJoined_t
|
||||
@@ -36,39 +37,39 @@ struct PlayerJoined_t
|
||||
struct PlayerJoinedCallback_t
|
||||
{
|
||||
EMessageType m_eType;
|
||||
CNetworkUInt32 m_uPlayerIndex;
|
||||
CNetworkProtocolUInt32 m_uPlayerIndex;
|
||||
};
|
||||
|
||||
struct PlayerLeft_t
|
||||
{
|
||||
EMessageType m_eType;
|
||||
CNetworkUInt32 m_uPlayerIndex;
|
||||
CNetworkProtocolUInt32 m_uPlayerIndex;
|
||||
};
|
||||
|
||||
struct EntityClass_t
|
||||
{
|
||||
EMessageType m_eType;
|
||||
CNetworkUInt32 m_uIndex;
|
||||
CNetworkProtocolUInt32 m_uIndex;
|
||||
int8_t m_szEntityName[256];
|
||||
};
|
||||
|
||||
struct EntityDataSync_t
|
||||
{
|
||||
EMessageType m_eType;
|
||||
CNetworkUInt32 m_uIndex;
|
||||
CNetworkUInt32 m_uCount;
|
||||
CNetworkProtocolUInt32 m_uIndex;
|
||||
CNetworkProtocolUInt32 m_uCount;
|
||||
};
|
||||
|
||||
struct EntityDataSyncValue_t
|
||||
{
|
||||
CNetworkUInt32 m_uVariableIndex;
|
||||
CNetworkUInt32 m_uVariableSize;
|
||||
CNetworkProtocolUInt32 m_uVariableIndex;
|
||||
CNetworkProtocolUInt32 m_uVariableSize;
|
||||
};
|
||||
|
||||
struct SetLocalEntity_t
|
||||
{
|
||||
EMessageType m_eType;
|
||||
CNetworkUInt32 m_uIndex;
|
||||
CNetworkProtocolUInt32 m_uIndex;
|
||||
};
|
||||
|
||||
union PlayerPacket_t
|
||||
|
||||
Reference in New Issue
Block a user