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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user