better physics
This commit is contained in:
@@ -9,8 +9,7 @@
|
||||
#define MAX_TEXTURE_COUNT 4096
|
||||
#define MAX_SHADER_COUNT 1024
|
||||
|
||||
#define MAX_PHYSICAL_MESH_COUNT 1024
|
||||
#define MAX_PHYSICAL_MATERIAL_COUNT 512
|
||||
#define MAX_PHYSICS_COUNT 1024
|
||||
|
||||
template<typename T, uint32_t nCount>
|
||||
class CAssetArc
|
||||
@@ -89,13 +88,9 @@ public:
|
||||
virtual FunnyMaterial_t *GetMaterialByIndex( HFunnyMaterial hMat ) override;
|
||||
virtual void UnrefMaterial( HFunnyMaterial hMat ) override;
|
||||
|
||||
virtual HFunnyPhysicalMesh LoadPhysicalMesh( const char *szName ) override;
|
||||
virtual FunnyPhysicalMesh_t *GetPhysicalMeshByIndex( HFunnyPhysicalMesh hPhysicalMesh ) override;
|
||||
virtual void UnrefPhysicalMesh( HFunnyPhysicalMesh hPhysicalMesh ) override;
|
||||
|
||||
virtual HFunnyPhysicalMaterial LoadPhysicalMaterial( const char *szName ) override;
|
||||
virtual FunnyPhysicalMaterial_t *GetPhysicalMaterialByIndex( HFunnyPhysicalMaterial hPhysicalMaterial ) override;
|
||||
virtual void UnrefPhysicalMaterial( HFunnyPhysicalMaterial hPhysicalMaterial ) override;
|
||||
virtual HFunnyPhysics LoadPhysics( const char *szName ) override;
|
||||
virtual FunnyPhysics_t *GetPhysicsByIndex( HFunnyPhysics hPhysics ) override;
|
||||
virtual void UnrefPhysics( HFunnyPhysics hPhysics ) override;
|
||||
|
||||
uint32_t LoadShader( const char *szName );
|
||||
IShader **GetShaderByIndex( uint32_t hShader );
|
||||
@@ -105,6 +100,7 @@ public:
|
||||
CAssetArc<FunnyMesh_t, MAX_MESH_COUNT> m_meshes = {};
|
||||
CAssetArc<FunnyMaterial_t, MAX_MATERIAL_COUNT> m_materials = {};
|
||||
CAssetArc<IShader*, MAX_SHADER_COUNT> m_shaders = {};
|
||||
CAssetArc<FunnyPhysics_t, MAX_PHYSICS_COUNT> m_physics = {};
|
||||
|
||||
};
|
||||
|
||||
@@ -163,12 +159,15 @@ uint32_t CAssetManager::LoadModel( const char *szName )
|
||||
return 0;
|
||||
|
||||
}
|
||||
IJSONValue *pMesh = pMainObject->GetValue("mesh");
|
||||
IJSONValue *pMaterial = pMainObject->GetValue("material");
|
||||
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());
|
||||
|
||||
|
||||
|
||||
@@ -290,6 +289,7 @@ uint32_t CAssetManager::LoadShader( const char *szName )
|
||||
if ( pShader == NULL )
|
||||
{
|
||||
V_printf("Failed to load %s\n", szName);
|
||||
m_shaders.UnrefObject(hShader);
|
||||
return 0;
|
||||
}
|
||||
*ppShader = pShader;
|
||||
@@ -298,40 +298,73 @@ uint32_t CAssetManager::LoadShader( const char *szName )
|
||||
|
||||
void CAssetManager::UnrefShader( uint32_t uIndex )
|
||||
{
|
||||
|
||||
m_shaders.UnrefObject(uIndex);
|
||||
}
|
||||
|
||||
HFunnyPhysicalMesh CAssetManager::LoadPhysicalMesh( const char *szName )
|
||||
|
||||
HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||
{
|
||||
bool bHasBeenCreated = false;
|
||||
HFunnyPhysics hPhysics = m_physics.GetOrCreateObject(szName, &bHasBeenCreated);
|
||||
if (!bHasBeenCreated)
|
||||
return hPhysics;
|
||||
FunnyPhysics_t *pPhysics = m_physics.GetObjectPtr(hPhysics);
|
||||
|
||||
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
|
||||
if (!pHandle)
|
||||
return 0;
|
||||
CUtlString szProperties = filesystem->ReadString(pHandle);
|
||||
IJSONValue *pRoot = JSONManager()->ReadString(szProperties);
|
||||
if (!pRoot)
|
||||
return 0;
|
||||
|
||||
IJSONObject *pMainObject;
|
||||
switch (pRoot->GetType())
|
||||
{
|
||||
case JSON_PARAMETER_OBJECT:
|
||||
{
|
||||
pMainObject = pRoot->GetObject();
|
||||
if (!pMainObject)
|
||||
{
|
||||
V_printf("Failed to load properties\n");
|
||||
m_physics.UnrefObject(hPhysics);
|
||||
return 0;
|
||||
|
||||
}
|
||||
IJSONValue *pTypeValue = pMainObject->GetValue("Type");
|
||||
if (!pTypeValue)
|
||||
{
|
||||
V_printf("\"Type\" must be specified\n");
|
||||
m_physics.UnrefObject(hPhysics);
|
||||
return 0;
|
||||
}
|
||||
CUtlString szType = pTypeValue->GetStringValue();
|
||||
if (szType == "Sphere")
|
||||
{
|
||||
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
||||
}
|
||||
|
||||
return hPhysics;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return hPhysics;
|
||||
}
|
||||
|
||||
FunnyPhysicalMesh_t *CAssetManager::GetPhysicalMeshByIndex( HFunnyPhysicalMesh hPhysicalMesh )
|
||||
FunnyPhysics_t *CAssetManager::GetPhysicsByIndex( HFunnyPhysics hPhysics )
|
||||
{
|
||||
|
||||
return m_physics.GetObjectPtr(hPhysics);
|
||||
}
|
||||
|
||||
void CAssetManager::UnrefPhysicalMesh( HFunnyPhysicalMesh hPhysicalMesh )
|
||||
void CAssetManager::UnrefPhysics( HFunnyPhysics hPhysics )
|
||||
{
|
||||
|
||||
m_physics.UnrefObject(hPhysics);
|
||||
}
|
||||
|
||||
|
||||
HFunnyPhysicalMaterial CAssetManager::LoadPhysicalMaterial( const char *szName )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FunnyPhysicalMaterial_t *CAssetManager::GetPhysicalMaterialByIndex( HFunnyPhysicalMaterial hPhysicalMaterial )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CAssetManager::UnrefPhysicalMaterial( HFunnyPhysicalMaterial hPhysicalMaterial )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static CAssetManager s_assetmgr;
|
||||
|
||||
Reference in New Issue
Block a user