fixes for physics
This commit is contained in:
@@ -93,6 +93,7 @@ public:
|
||||
virtual void UnrefPhysics( HFunnyPhysics hPhysics ) override;
|
||||
|
||||
CAssetArc<FunnyModel_t, MAX_MODEL_COUNT> m_models = {};
|
||||
CAssetArc<FunnyMesh_t, MAX_MODEL_COUNT> m_meshes = {};
|
||||
CAssetArc<FunnyPhysics_t, MAX_PHYSICS_COUNT> m_physics = {};
|
||||
|
||||
};
|
||||
@@ -108,6 +109,7 @@ FunnyMaterial_t *CAssetManager::GetMaterialByIndex( uint32_t uIndex )
|
||||
|
||||
FunnyMesh_t *CAssetManager::GetMeshByIndex( uint32_t uIndex )
|
||||
{
|
||||
return m_meshes.GetObjectPtr(uIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +181,30 @@ HFunnyMesh CAssetManager::LoadMesh( const char *szName )
|
||||
{
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
bool bHasBeenCreated = false;
|
||||
HFunnyMesh hAsset = m_meshes.GetOrCreateObject(szName, &bHasBeenCreated);
|
||||
if (!bHasBeenCreated)
|
||||
return hAsset;
|
||||
FunnyMesh_t *pMesh = m_meshes.GetObjectPtr(hAsset);
|
||||
|
||||
IFileHandle *hMesh = filesystem->Open(szName, FILEMODE_READ);
|
||||
if ( hMesh == NULL )
|
||||
{
|
||||
V_printf("Failed to load %s\n", szName);
|
||||
m_meshes.UnrefObject(hAsset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
pMesh->m_nPositionCount = filesystem->Size(hMesh)/4;
|
||||
pMesh->m_pfPositions = new float[pMesh->m_nPositionCount];
|
||||
filesystem->Read( hMesh, pMesh->m_pfPositions, filesystem->Size(hMesh));
|
||||
pMesh->m_nIndiciesCount = 0;
|
||||
pMesh->m_puIndicies = 0;
|
||||
|
||||
|
||||
return hAsset;
|
||||
|
||||
}
|
||||
void CAssetManager::UnrefMesh( uint32_t uIndex )
|
||||
@@ -231,8 +256,25 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||
{
|
||||
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
||||
}
|
||||
if (szType == "Triangles")
|
||||
if (szType == "TriangleMesh")
|
||||
{
|
||||
V_printf("hi\n");
|
||||
IJSONValue *pMeshValue = pMainObject->GetValue("Mesh");
|
||||
V_printf("hi\n");
|
||||
if (!pMeshValue)
|
||||
{
|
||||
|
||||
V_printf("\"Mesh\" must be specified\n");
|
||||
m_physics.UnrefObject(hPhysics);
|
||||
return 0;
|
||||
}
|
||||
CUtlString szMesh = pMeshValue->GetStringValue();
|
||||
V_printf("%s\n", szMesh.GetString());
|
||||
HFunnyMesh hMesh = LoadMesh(szMesh);
|
||||
FunnyMesh_t *pMesh = GetMeshByIndex(hMesh);
|
||||
pPhysics->m_hShape = g_pPhysics->CreateTriangleMesh({pMesh->m_pfPositions, pMesh->m_nPositionCount});
|
||||
V_printf("%p\n", pPhysics->m_hShape);
|
||||
pPhysics->m_hMesh = hMesh;
|
||||
}
|
||||
|
||||
return hPhysics;
|
||||
|
||||
@@ -16,11 +16,20 @@ struct FunnyMaterial_t
|
||||
|
||||
struct FunnyMesh_t
|
||||
{
|
||||
float *m_pfPositions;
|
||||
uint32_t m_nPositionCount;
|
||||
uint32_t *m_puIndicies;
|
||||
uint32_t m_nIndiciesCount;
|
||||
};
|
||||
|
||||
struct FunnyPhysics_t
|
||||
{
|
||||
HShape m_hShape;
|
||||
|
||||
union
|
||||
{
|
||||
HFunnyMesh m_hMesh;
|
||||
};
|
||||
};
|
||||
|
||||
struct FunnyModel_t
|
||||
|
||||
@@ -205,6 +205,8 @@ void CFunnyGameBridge::Frame( float fDelta )
|
||||
float fTickRate = 1.0/60.0;
|
||||
|
||||
m_fNetUpdateTimer += fDelta;
|
||||
if (m_fNetUpdateTimer >= 0.3)
|
||||
m_fNetUpdateTimer = 0.3;
|
||||
while (m_fNetUpdateTimer >= fTickRate)
|
||||
{
|
||||
m_fNetUpdateTimer-=fTickRate;
|
||||
|
||||
@@ -22,6 +22,7 @@ void CMOBAPlayer::Think( float fDelta )
|
||||
vPosition.x += m_vMovementVector.x*fDelta*5;
|
||||
vPosition.z += m_vMovementVector.z*fDelta*5;
|
||||
SetAbsOrigin(vPosition);
|
||||
V_printf("player: %f %f %f\n", vPosition.x, vPosition.y, vPosition.z);
|
||||
};
|
||||
|
||||
LINK_ENTITY_TO_CLASS(player, CMOBAPlayer)
|
||||
|
||||
@@ -11,8 +11,6 @@ void CPhysicsProp::Spawn()
|
||||
{
|
||||
CBaseEntity::Spawn();
|
||||
SetThink(Think);
|
||||
|
||||
V_printf("hi\n");
|
||||
}
|
||||
|
||||
void CPhysicsProp::Think( float fDelta )
|
||||
@@ -60,6 +58,8 @@ void CPhysicsProp::OnModelChanged( const char *szName )
|
||||
m_pPhysics = g_pAssetManager->GetPhysicsByIndex(m_pModel->m_hPhysics);
|
||||
m_hCollider = g_pPhysics->CreateCollider(m_pPhysics->m_hShape);
|
||||
m_pBody = g_pPhysicsWorld->CreateRigidBody(m_hCollider, k_EPhysics_Dynamic);
|
||||
m_pBody->SetPosition({0,0,0});
|
||||
m_pBody->SetRotation({0,0,0});
|
||||
}
|
||||
|
||||
void CPhysicsProp::EnableMovement()
|
||||
@@ -71,5 +71,8 @@ void CPhysicsProp::DisableMovement()
|
||||
{
|
||||
|
||||
}
|
||||
BEGIN_DATADESC(CPhysicsProp)
|
||||
DEFINE_KEYFIELD(m_ePhysicsType, FIELD_INTEGER, "physics_type")
|
||||
END_DATADESC()
|
||||
|
||||
LINK_ENTITY_TO_CLASS(prop_physics, CPhysicsProp)
|
||||
|
||||
@@ -8,7 +8,8 @@ class CPhysicsProp: public CBaseModelEntity
|
||||
friend CBaseEntity;
|
||||
friend CBaseModelEntity;
|
||||
public:
|
||||
DECLARE_CLASS(CPhysicsProp, CBaseModelEntity);
|
||||
DECLARE_CLASS(CPhysicsProp, CBaseModelEntity)
|
||||
DECLARE_DATADESC()
|
||||
virtual void Spawn() override;
|
||||
virtual void Precache() override;
|
||||
|
||||
@@ -20,14 +21,18 @@ public:
|
||||
virtual void EnableMovement();
|
||||
virtual void DisableMovement();
|
||||
|
||||
virtual void SetPhysics( EPhysicsBodyType eType );
|
||||
|
||||
void Think( float fDelta );
|
||||
private:
|
||||
EPhysicsBodyType m_ePhysicsType;
|
||||
EPhysicsBodyType m_eCurrentPhysicsType;
|
||||
HFunnyModel m_hModel = 0;
|
||||
FunnyModel_t *m_pModel = NULL;
|
||||
FunnyPhysics_t *m_pPhysics = NULL;
|
||||
HCollider m_hCollider = 0;
|
||||
IPhysicsBody *m_pBody = NULL;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user