steam networking
This commit is contained in:
@@ -64,7 +64,7 @@ uint32_t CAssetManager::LoadModel( const char *szName )
|
||||
u++;
|
||||
continue;
|
||||
}
|
||||
if (m->m_szName == szName)
|
||||
if (m->m_szParentName == szName)
|
||||
{
|
||||
m_modelUsages[uFoundIndex]++;
|
||||
return u;
|
||||
@@ -81,6 +81,8 @@ uint32_t CAssetManager::LoadModel( const char *szName )
|
||||
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
|
||||
CUtlString szProperties = filesystem->ReadString(pHandle);
|
||||
IJSONValue *pRoot = JSONManager()->ReadString(szProperties);
|
||||
filesystem->Close(pHandle);
|
||||
|
||||
IJSONObject *pMainObject;
|
||||
CUtlString szMeshData;
|
||||
IVertexBuffer *pVertices;
|
||||
@@ -97,10 +99,13 @@ uint32_t CAssetManager::LoadModel( const char *szName )
|
||||
}
|
||||
IJSONValue *pMesh = pMainObject->GetValue("mesh");
|
||||
IJSONValue *pMaterial = pMainObject->GetValue("material");
|
||||
|
||||
|
||||
CUtlString szMesh = pMesh->GetStringValue();
|
||||
CUtlString szMaterial = pMaterial->GetStringValue();
|
||||
|
||||
m_models[uFoundIndex] = LoadModelFromParams(szMesh, szMaterial);
|
||||
m_models[uFoundIndex]->m_szParentName = szName;
|
||||
m_modelUsages[uFoundIndex]++;
|
||||
|
||||
return uFoundIndex;
|
||||
|
||||
@@ -20,6 +20,7 @@ struct FunnyModel_t
|
||||
CUtlString m_szName;
|
||||
IMesh *m_pMesh;
|
||||
FunnyMaterial_t *m_pFunnyMaterial;
|
||||
CUtlString m_szParentName;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,12 @@ void C_BaseModelEntity::SetModel( const char *szName )
|
||||
m_pInstance = g_pWorldRenderer->CreateInstance(m_pModel->m_pMesh);
|
||||
}
|
||||
|
||||
C_BaseModelEntity::~C_BaseModelEntity()
|
||||
{
|
||||
g_pWorldRenderer->DestroyMeshInstance(m_pModel->m_pMesh, m_pInstance);
|
||||
g_pAssetManager->UnrefModel(m_uModelIndex);
|
||||
}
|
||||
|
||||
BEGIN_DATADESC(C_BaseModelEntity)
|
||||
|
||||
END_DATADESC()
|
||||
|
||||
@@ -12,6 +12,7 @@ public:
|
||||
DECLARE_CLASS(C_BaseModelEntity, C_BaseEntity);
|
||||
DECLARE_DATADESC();
|
||||
|
||||
virtual ~C_BaseModelEntity() override;
|
||||
virtual void Precache() override;
|
||||
virtual void Spawn() override;
|
||||
void Think( float fDelta );
|
||||
|
||||
@@ -120,6 +120,22 @@ IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CEntitySystem::DestroyEntityByIndex( uint32_t uIndex )
|
||||
{
|
||||
if ( uIndex >= MAX_EDICTS )
|
||||
return;
|
||||
if (m_pEntities[uIndex])
|
||||
{
|
||||
V_printf("Deleting: %i\n", uIndex);
|
||||
delete m_pEntities[uIndex];
|
||||
m_pEntities[uIndex] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CEntitySystem::DestroyEntityByPtr( C_BaseEntity *pEntity )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CEntitySystem::Think()
|
||||
{
|
||||
|
||||
@@ -25,6 +25,9 @@ public:
|
||||
|
||||
virtual IEntityFactory *GetFactoryByClassname( const char *szName );
|
||||
|
||||
virtual void DestroyEntityByIndex( uint32_t uIndex );
|
||||
virtual void DestroyEntityByPtr( C_BaseEntity *pEntity );
|
||||
|
||||
virtual void Think();
|
||||
virtual C_BaseEntity **GetEntities();
|
||||
private:
|
||||
|
||||
@@ -114,6 +114,11 @@ void CFunnyGameBridge::TryToConnectToServer()
|
||||
if (g_pServerConnection)
|
||||
{
|
||||
m_bIsConnectedToServer = true;
|
||||
C_BaseEntity **ppEntities = EntitySystem()->GetEntities();
|
||||
for ( int i = 0; i < MAX_EDICTS; i++ )
|
||||
{
|
||||
EntitySystem()->DestroyEntityByIndex(i);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -133,7 +138,9 @@ void CFunnyGameBridge::Frame( float fDelta )
|
||||
pCurrentServer = g_pServerBridge;
|
||||
if (m_bIsConnectedToServer)
|
||||
if (g_pServerConnection->BIsActive())
|
||||
{
|
||||
pCurrentServer = g_pServerConnection;
|
||||
}
|
||||
|
||||
|
||||
if (pCurrentServer)
|
||||
@@ -150,6 +157,7 @@ void CFunnyGameBridge::Frame( float fDelta )
|
||||
switch (pPacket->m_eType)
|
||||
{
|
||||
case MESSAGE_ENTITY_CLASS_SYNC:
|
||||
V_printf("MESSAGE_ENTITY_CLASS_SYNC: %u = %s\n", (uint32_t)pPacket->m_entityClass.m_uIndex, pPacket->m_entityClass.m_szEntityName);
|
||||
pEntity = EntitySystem()->CreateByClassnameWithIndex(
|
||||
(char*)pPacket->m_entityClass.m_szEntityName, pPacket->m_entityClass.m_uIndex
|
||||
);
|
||||
|
||||
@@ -120,6 +120,8 @@ public:
|
||||
|
||||
virtual IMesh *CreateMesh( const char *szName ) override;
|
||||
virtual IMeshInstance *CreateInstance( IMesh *pMesh ) override;
|
||||
virtual void DestroyMeshInstance( IMesh *pMesh, IMeshInstance *pInstance ) override;
|
||||
virtual void DestroyMesh( IMesh *pMesh ) override;
|
||||
|
||||
virtual void ConfigureShader( IShader *pShader ) override;
|
||||
private:
|
||||
@@ -355,3 +357,25 @@ IMeshInstance *CFunnyWorldRenderer::CreateInstance( IMesh *pMesh )
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
void CFunnyWorldRenderer::DestroyMeshInstance( IMesh *pMesh, IMeshInstance *pInstance )
|
||||
{
|
||||
if (!pMesh)
|
||||
return;
|
||||
CFunnyMesh *pFunnyMesh = (CFunnyMesh*)pMesh;
|
||||
for ( uint32_t i = 0; i < pFunnyMesh->m_instances.GetSize(); i++ )
|
||||
{
|
||||
if ( pFunnyMesh->m_instances[i] != pInstance)
|
||||
continue;
|
||||
delete pFunnyMesh->m_instances[i];
|
||||
pFunnyMesh->m_instances.RemoveAt(i, 1);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CFunnyWorldRenderer::DestroyMesh( IMesh *pMesh )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
|
||||
virtual IMesh *CreateMesh( const char *szName ) = 0;
|
||||
virtual IMeshInstance *CreateInstance( IMesh *pMesh ) = 0;
|
||||
virtual void DestroyMeshInstance( IMesh *pMesh, IMeshInstance *pInstance ) = 0;
|
||||
virtual void DestroyMesh( IMesh *pMesh ) = 0;
|
||||
|
||||
virtual void ConfigureShader( IShader *pShader ) = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user