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;
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
|
||||
typedef uint32_t HFunnyMaterial;
|
||||
typedef uint32_t HFunnyMesh;
|
||||
typedef uint32_t HFunnyPhysicalMesh;
|
||||
typedef uint32_t HFunnyPhysicalMaterial;
|
||||
typedef uint32_t HFunnyPhysics;
|
||||
typedef uint32_t HFunnyModel;
|
||||
|
||||
struct FunnyMaterial_t
|
||||
@@ -26,11 +25,7 @@ struct FunnyMesh_t
|
||||
IMesh *m_pMesh;
|
||||
};
|
||||
|
||||
struct FunnyPhysicalMaterial_t
|
||||
{
|
||||
};
|
||||
|
||||
struct FunnyPhysicalMesh_t
|
||||
struct FunnyPhysics_t
|
||||
{
|
||||
HShape m_hShape;
|
||||
};
|
||||
@@ -39,8 +34,7 @@ struct FunnyModel_t
|
||||
{
|
||||
HFunnyMesh m_hMesh;
|
||||
HFunnyMaterial m_hMaterial;
|
||||
HFunnyPhysicalMesh m_hPhysicalMesh;
|
||||
HFunnyPhysicalMaterial m_hPhysicalMaterial;
|
||||
HFunnyPhysics m_hPhysics;
|
||||
};
|
||||
|
||||
|
||||
@@ -59,17 +53,11 @@ public:
|
||||
virtual FunnyMaterial_t *GetMaterialByIndex( HFunnyMaterial hMat ) = 0;
|
||||
virtual void UnrefMaterial( HFunnyMaterial hMat ) = 0;
|
||||
|
||||
virtual HFunnyPhysicalMesh LoadPhysicalMesh( const char *szName ) = 0;
|
||||
virtual FunnyPhysicalMesh_t *GetPhysicalMeshByIndex( HFunnyPhysicalMesh hPhysicalMesh ) = 0;
|
||||
virtual void UnrefPhysicalMesh( HFunnyPhysicalMesh hPhysicalMesh ) = 0;
|
||||
|
||||
virtual HFunnyPhysicalMaterial LoadPhysicalMaterial( const char *szName ) = 0;
|
||||
virtual FunnyPhysicalMaterial_t *GetPhysicalMaterialByIndex( HFunnyPhysicalMaterial hPhysicalMaterial ) = 0;
|
||||
virtual void UnrefPhysicalMaterial( HFunnyPhysicalMaterial hPhysicalMaterial ) = 0;
|
||||
virtual HFunnyPhysics LoadPhysics( const char *szName ) = 0;
|
||||
virtual FunnyPhysics_t *GetPhysicsByIndex( HFunnyPhysics hPhysics ) = 0;
|
||||
virtual void UnrefPhysics( HFunnyPhysics hPhysics ) = 0;
|
||||
};
|
||||
|
||||
extern IAssetManager *g_pAssetManager;
|
||||
|
||||
#define ASSET_MANAGER_INTERFACE_VERSION "AssetMgr001"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,11 +22,16 @@ void C_BaseEntity::Spawn()
|
||||
{
|
||||
Precache();
|
||||
SetAbsOrigin({0, 0, 0});
|
||||
SetAbsAngles(0, 0, 0);
|
||||
SetAbsQAngles(0, 0, 0);
|
||||
SetScale(1);
|
||||
}
|
||||
|
||||
void C_BaseEntity::SetAbsAngles( float fPitch, float fYaw, float fRoll )
|
||||
void C_BaseEntity::SetAbsAngles( Quat vQuat )
|
||||
{
|
||||
m_vRotation = vQuat;
|
||||
}
|
||||
|
||||
void C_BaseEntity::SetAbsQAngles( float fPitch, float fYaw, float fRoll )
|
||||
{
|
||||
versor q;
|
||||
glm_euler_yzx_quat((vec3){fPitch, fYaw, fRoll}, q);
|
||||
|
||||
@@ -61,7 +61,8 @@ public:
|
||||
virtual void Precache();
|
||||
virtual void Spawn();
|
||||
|
||||
virtual void SetAbsAngles( float fPitch, float fYaw, float fRoll );
|
||||
virtual void SetAbsAngles( Quat vQuat );
|
||||
virtual void SetAbsQAngles( float fPitch, float fYaw, float fRoll );
|
||||
virtual void SetAbsOrigin( Vector origin );
|
||||
virtual void SetScale( float fScale );
|
||||
|
||||
|
||||
@@ -20,12 +20,12 @@ void C_BaseModelEntity::Think( float fDelta )
|
||||
|
||||
void C_BaseModelEntity::SetModel( const char *szName )
|
||||
{
|
||||
if (m_uModelIndex)
|
||||
if (m_hModelHandle)
|
||||
{
|
||||
g_pAssetManager->UnrefModel(m_uModelIndex);
|
||||
g_pAssetManager->UnrefModel(m_hModelHandle);
|
||||
}
|
||||
m_uModelIndex = g_pAssetManager->LoadModel(szName);
|
||||
m_pModel = g_pAssetManager->GetModelByIndex(m_uModelIndex);
|
||||
m_hModelHandle = g_pAssetManager->LoadModel(szName);
|
||||
m_pModel = g_pAssetManager->GetModelByIndex(m_hModelHandle);
|
||||
|
||||
FunnyMesh_t *pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh);
|
||||
m_pInstance = g_pWorldRenderer->CreateInstance(pMesh->m_pMesh);
|
||||
@@ -35,7 +35,7 @@ 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_uModelIndex);
|
||||
g_pAssetManager->UnrefModel(m_hModelHandle);
|
||||
}
|
||||
|
||||
BEGIN_DATADESC(C_BaseModelEntity)
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
#endif
|
||||
|
||||
IFileSystem *filesystem;
|
||||
|
||||
IRenderContext *g_pRenderContext;
|
||||
IGameWindow *g_pMainWindow;
|
||||
|
||||
static CEngineVars s_vars;
|
||||
CEngineVars *g_pEngineVars = &s_vars;
|
||||
EngineConsts_t *g_pEngineConstants;
|
||||
@@ -25,6 +27,9 @@ EngineConsts_t *g_pEngineConstants;
|
||||
INetworkBase *g_pServerBridge;
|
||||
INetworkBase *g_pServerConnection;
|
||||
|
||||
IPhysics *g_pPhysics;
|
||||
IPhysicsWorld *g_pPhysicsWorld;
|
||||
|
||||
class CFunnyGameBridge: public IEngineBridge
|
||||
{
|
||||
virtual void Init() override;
|
||||
@@ -70,6 +75,10 @@ void CFunnyGameBridge::Init()
|
||||
};
|
||||
g_pServerBridge->SendPacket({&join, sizeof(join)});
|
||||
}
|
||||
|
||||
CreateInterfaceFn fnPhysicsFactory = Sys_GetFactory("RapierPhysics");
|
||||
g_pPhysics = (IPhysics*)fnPhysicsFactory(PHYSICS_INTERFACE_VERSION, NULL);
|
||||
g_pPhysicsWorld = g_pPhysics->CreateWorld();
|
||||
}
|
||||
|
||||
void CFunnyGameBridge::Tick( float fDelta )
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
#include "assetmgr.h"
|
||||
#include "tier2/ifilesystem.h"
|
||||
#include "tier2/fileformats/json.h"
|
||||
#include "game.h"
|
||||
|
||||
#define MAX_MODEL_COUNT 2048
|
||||
#define MAX_MESH_COUNT 2048
|
||||
#define MAX_MATERIAL_COUNT 2048
|
||||
#define MAX_TEXTURE_COUNT 4096
|
||||
#define MAX_SHADER_COUNT 1024
|
||||
|
||||
#define MAX_PHYSICS_COUNT 1024
|
||||
|
||||
template<typename T, uint32_t nCount>
|
||||
class CAssetArc
|
||||
{
|
||||
struct ObjectHandle_t
|
||||
{
|
||||
CUtlString m_szName;
|
||||
uint32_t m_uUsageCount;
|
||||
T *m_pObject;
|
||||
};
|
||||
ObjectHandle_t m_objects[nCount] = {};
|
||||
public:
|
||||
uint32_t GetOrCreateObject( const char *szName, bool *pbHasBeenCreated )
|
||||
{
|
||||
uint32_t uFoundIndex = 1;
|
||||
for ( uint32_t u = 1; u < nCount; u++ )
|
||||
{
|
||||
if (m_objects[u].m_pObject == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (m_objects[u].m_szName == szName)
|
||||
{
|
||||
m_objects[u].m_uUsageCount++;
|
||||
if (pbHasBeenCreated)
|
||||
*pbHasBeenCreated = false;
|
||||
return u;
|
||||
}
|
||||
}
|
||||
for ( auto &m: m_objects)
|
||||
{
|
||||
if (m.m_pObject == NULL)
|
||||
break;
|
||||
uFoundIndex++;
|
||||
}
|
||||
m_objects[uFoundIndex].m_szName = szName;
|
||||
m_objects[uFoundIndex].m_uUsageCount++;
|
||||
m_objects[uFoundIndex].m_pObject = (T*)V_malloc(sizeof(T));
|
||||
if (pbHasBeenCreated)
|
||||
*pbHasBeenCreated = true;
|
||||
return uFoundIndex;
|
||||
}
|
||||
T *GetObjectPtr( uint32_t uIndex )
|
||||
{
|
||||
if (uIndex >= nCount)
|
||||
return 0;
|
||||
return m_objects[uIndex].m_pObject;
|
||||
}
|
||||
void UnrefObject( uint32_t uIndex )
|
||||
{
|
||||
if (uIndex >= nCount)
|
||||
return;
|
||||
|
||||
m_objects[uIndex].m_uUsageCount--;
|
||||
if (m_objects[uIndex].m_uUsageCount == 0)
|
||||
{
|
||||
V_free(m_objects[uIndex].m_pObject);
|
||||
m_objects[uIndex].m_pObject = NULL;
|
||||
m_objects[uIndex].m_szName = NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class CAssetManager: public IAssetManager
|
||||
{
|
||||
public:
|
||||
virtual HFunnyModel LoadModel( const char *szName ) override;
|
||||
virtual FunnyModel_t *GetModelByIndex( HFunnyModel hModel ) override;
|
||||
virtual void UnrefModel( HFunnyModel uIndex ) override;
|
||||
|
||||
virtual HFunnyMesh LoadMesh( const char *szName ) override;
|
||||
virtual FunnyMesh_t *GetMeshByIndex( HFunnyMesh hMesh ) override;
|
||||
virtual void UnrefMesh( HFunnyMesh hMesh ) override;
|
||||
|
||||
virtual HFunnyMaterial LoadMaterial( const char *szName ) override;
|
||||
virtual FunnyMaterial_t *GetMaterialByIndex( HFunnyMaterial hMat ) override;
|
||||
virtual void UnrefMaterial( HFunnyMaterial hMat ) override;
|
||||
|
||||
virtual HFunnyPhysics LoadPhysics( const char *szName ) override;
|
||||
virtual FunnyPhysics_t *GetPhysicsByIndex( HFunnyPhysics hPhysics ) override;
|
||||
virtual void UnrefPhysics( HFunnyPhysics hPhysics ) override;
|
||||
|
||||
CAssetArc<FunnyModel_t, MAX_MODEL_COUNT> m_models = {};
|
||||
CAssetArc<FunnyPhysics_t, MAX_PHYSICS_COUNT> m_physics = {};
|
||||
|
||||
};
|
||||
|
||||
FunnyModel_t *CAssetManager::GetModelByIndex( uint32_t uIndex )
|
||||
{
|
||||
return m_models.GetObjectPtr(uIndex);
|
||||
}
|
||||
|
||||
FunnyMaterial_t *CAssetManager::GetMaterialByIndex( uint32_t uIndex )
|
||||
{
|
||||
}
|
||||
|
||||
FunnyMesh_t *CAssetManager::GetMeshByIndex( uint32_t uIndex )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
uint32_t CAssetManager::LoadModel( const char *szName )
|
||||
{
|
||||
bool bHasBeenCreated = false;
|
||||
HFunnyModel hModel = m_models.GetOrCreateObject(szName, &bHasBeenCreated);
|
||||
if (!bHasBeenCreated)
|
||||
return hModel;
|
||||
|
||||
FunnyModel_t *pModel = m_models.GetObjectPtr(hModel);
|
||||
|
||||
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;
|
||||
|
||||
IJSONObject *pMainObject;
|
||||
CUtlString szMeshData;
|
||||
IVertexBuffer *pVertices;
|
||||
switch (pRoot->GetType())
|
||||
{
|
||||
case JSON_PARAMETER_OBJECT:
|
||||
{
|
||||
pMainObject = pRoot->GetObject();
|
||||
if (!pMainObject)
|
||||
{
|
||||
V_printf("Failed to load properties\n");
|
||||
return 0;
|
||||
|
||||
}
|
||||
IJSONValue *pPhysics = pMainObject->GetValue("Physics");
|
||||
if (pPhysics)
|
||||
pModel->m_hPhysics = LoadPhysics(pPhysics->GetStringValue());
|
||||
|
||||
return hModel;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CAssetManager::UnrefModel( uint32_t uIndex )
|
||||
{
|
||||
m_models.UnrefObject(uIndex);
|
||||
}
|
||||
|
||||
|
||||
uint32_t CAssetManager::LoadMaterial( const char *szName )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CAssetManager::UnrefMaterial( uint32_t uIndex )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
HFunnyMesh CAssetManager::LoadMesh( const char *szName )
|
||||
{
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
void CAssetManager::UnrefMesh( uint32_t uIndex )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
FunnyPhysics_t *CAssetManager::GetPhysicsByIndex( HFunnyPhysics hPhysics )
|
||||
{
|
||||
return m_physics.GetObjectPtr(hPhysics);
|
||||
}
|
||||
|
||||
void CAssetManager::UnrefPhysics( HFunnyPhysics hPhysics )
|
||||
{
|
||||
m_physics.UnrefObject(hPhysics);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static CAssetManager s_assetmgr;
|
||||
IAssetManager *g_pAssetManager = &s_assetmgr;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef ASSET_MANAGER_H
|
||||
#define ASSET_MANAGER_H
|
||||
|
||||
#include "datamap.h"
|
||||
#include "iphysics.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
typedef uint32_t HFunnyMaterial;
|
||||
typedef uint32_t HFunnyMesh;
|
||||
typedef uint32_t HFunnyPhysics;
|
||||
typedef uint32_t HFunnyModel;
|
||||
|
||||
struct FunnyMaterial_t
|
||||
{
|
||||
};
|
||||
|
||||
struct FunnyMesh_t
|
||||
{
|
||||
};
|
||||
|
||||
struct FunnyPhysics_t
|
||||
{
|
||||
HShape m_hShape;
|
||||
};
|
||||
|
||||
struct FunnyModel_t
|
||||
{
|
||||
HFunnyPhysics m_hPhysics;
|
||||
};
|
||||
|
||||
|
||||
class IAssetManager
|
||||
{
|
||||
public:
|
||||
virtual HFunnyModel LoadModel( const char *szName ) = 0;
|
||||
virtual FunnyModel_t *GetModelByIndex( HFunnyModel hModel ) = 0;
|
||||
virtual void UnrefModel( HFunnyModel uIndex ) = 0;
|
||||
|
||||
virtual HFunnyMesh LoadMesh( const char *szName ) = 0;
|
||||
virtual FunnyMesh_t *GetMeshByIndex( HFunnyMesh hMesh ) = 0;
|
||||
virtual void UnrefMesh( HFunnyMesh hMesh ) = 0;
|
||||
|
||||
virtual HFunnyMaterial LoadMaterial( const char *szName ) = 0;
|
||||
virtual FunnyMaterial_t *GetMaterialByIndex( HFunnyMaterial hMat ) = 0;
|
||||
virtual void UnrefMaterial( HFunnyMaterial hMat ) = 0;
|
||||
|
||||
virtual HFunnyPhysics LoadPhysics( const char *szName ) = 0;
|
||||
virtual FunnyPhysics_t *GetPhysicsByIndex( HFunnyPhysics hPhysics ) = 0;
|
||||
virtual void UnrefPhysics( HFunnyPhysics hPhysics ) = 0;
|
||||
};
|
||||
|
||||
extern IAssetManager *g_pAssetManager;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,10 +20,18 @@ void CBaseEntity::Precache()
|
||||
|
||||
void CBaseEntity::Spawn()
|
||||
{
|
||||
Precache();
|
||||
Precache();
|
||||
SetAbsOrigin({0, 0, 0});
|
||||
SetAbsQAngles(0, 0, 0);
|
||||
SetScale(1);
|
||||
}
|
||||
|
||||
void CBaseEntity::SetAbsAngles( float fPitch, float fYaw, float fRoll )
|
||||
void CBaseEntity::SetAbsAngles( Quat vQuat )
|
||||
{
|
||||
m_vRotation = vQuat;
|
||||
}
|
||||
|
||||
void CBaseEntity::SetAbsQAngles( float fPitch, float fYaw, float fRoll )
|
||||
{
|
||||
versor q;
|
||||
glm_euler_yzx_quat((vec3){fPitch, fYaw, fRoll}, q);
|
||||
|
||||
@@ -61,7 +61,8 @@ public:
|
||||
virtual void Precache();
|
||||
virtual void Spawn();
|
||||
|
||||
virtual void SetAbsAngles( float fPitch, float fYaw, float fRoll );
|
||||
virtual void SetAbsAngles( Quat vQuat );
|
||||
virtual void SetAbsQAngles( float fPitch, float fYaw, float fRoll );
|
||||
virtual void SetAbsOrigin( Vector origin );
|
||||
virtual void SetScale( float fScale );
|
||||
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
#include "basemodelentity.h"
|
||||
#include "game.h"
|
||||
|
||||
void CBaseModelEntity::Spawn()
|
||||
void CBaseModelEntity::SetModel( const char *szName )
|
||||
{
|
||||
}
|
||||
|
||||
void CBaseModelEntity::Precache()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,18 +9,7 @@ class CBaseModelEntity: public CBaseEntity
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS(CBaseModelEntity, CBaseEntity);
|
||||
virtual void Spawn() override;
|
||||
virtual void Precache() override;
|
||||
|
||||
void SetModel( const char *szName );
|
||||
private:
|
||||
|
||||
HFunnyModel m_hModelHandle;
|
||||
FunnyModel_t *m_pModel;
|
||||
|
||||
HShape m_hShape;
|
||||
HCollider m_hCollider;
|
||||
IPhysicsBody *m_pBody;
|
||||
virtual void SetModel( const char *szName );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,9 +17,12 @@ DECLARE_BUILD_STAGE(Server)
|
||||
compileProject.m_szName = "server";
|
||||
compileProject.files = {
|
||||
"game.cpp",
|
||||
"assetmgr.cpp",
|
||||
|
||||
"entitysystem.cpp",
|
||||
"baseentity.cpp",
|
||||
"basemodelentity.cpp",
|
||||
"physicsprop.cpp",
|
||||
|
||||
"milmoba/player.cpp",
|
||||
};
|
||||
|
||||
@@ -129,6 +129,11 @@ void CEntitySystem::Think()
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// Purpose: Sends packets to clients.
|
||||
// Since we are running this on server we can't really accept any packet.
|
||||
// We only allow packets from the entities sent by a client
|
||||
//-------------------------------------------------------------------------------
|
||||
void CEntitySystem::NetThink( INetworkBase *pBase )
|
||||
{
|
||||
|
||||
|
||||
@@ -14,11 +14,14 @@
|
||||
|
||||
|
||||
IFileSystem *filesystem;
|
||||
|
||||
IRenderContext *g_pRenderContext;
|
||||
IGameWindow *g_pMainWindow;
|
||||
|
||||
static CEngineVars s_vars;
|
||||
CEngineVars *g_pEngineVars = &s_vars;
|
||||
EngineConsts_t *g_pEngineConstants;
|
||||
|
||||
INetworkBase *g_pClientBridge;
|
||||
INetworkBase *g_pPublicConnection;
|
||||
INetworkBase *g_pCurrentConnection;
|
||||
@@ -211,6 +214,7 @@ void CFunnyGameBridge::Shutdown()
|
||||
#define CONNECT_INTERFACE(szName, pGlobal) if (!V_strcmp(psz, szName)) { pGlobal = (typeof(pGlobal))pInterface; return; }
|
||||
void CFunnyGameBridge::ConnectInterface( const char *psz, void *pInterface )
|
||||
{
|
||||
CONNECT_INTERFACE(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
||||
CONNECT_INTERFACE("EngineConstants", g_pEngineConstants)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,15 +5,14 @@
|
||||
|
||||
void CMOBAPlayer::Spawn()
|
||||
{
|
||||
SetModel("game/core/models/cube.fmdl");
|
||||
SetThink(Think);
|
||||
m_fTimer = 0;
|
||||
};
|
||||
|
||||
void CMOBAPlayer::Think( float fDelta )
|
||||
{
|
||||
m_fTimer += 1.0/60.0;
|
||||
SetAbsOrigin({m_fTimer, 0, 0});
|
||||
SetAbsAngles(glm_rad(90), m_fTimer, 0);
|
||||
BaseClass::Think(fDelta);
|
||||
SetScale(1);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef MILMOBA_PLAYER_H
|
||||
#define MILMOBA_PLAYER_H
|
||||
|
||||
#include "basemodelentity.h"
|
||||
|
||||
|
||||
class CMOBAPlayer: public CBaseModelEntity
|
||||
class CMOBAPlayer: public CBaseModelEntity
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS(CMOBAPlayer, CBaseModelEntity);
|
||||
@@ -12,8 +12,6 @@ public:
|
||||
|
||||
virtual void Spawn( void ) override;
|
||||
void Think( float fDelta );
|
||||
|
||||
float m_fTimer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
0
game/server/milmoba/projectile.cpp
Normal file
0
game/server/milmoba/projectile.cpp
Normal file
0
game/server/milmoba/projectile.h
Normal file
0
game/server/milmoba/projectile.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "physicsprop.h"
|
||||
#include "game.h"
|
||||
|
||||
|
||||
void CPhysicsProp::Precache()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CPhysicsProp::Spawn()
|
||||
{
|
||||
SetThink(Think);
|
||||
}
|
||||
|
||||
void CPhysicsProp::Think( float fDelta )
|
||||
{
|
||||
SetAbsOrigin(m_pBody->GetPosition());
|
||||
SetAbsAngles(m_pBody->GetRotation());
|
||||
}
|
||||
|
||||
void CPhysicsProp::SetModel( const char *szName )
|
||||
{
|
||||
if (m_hModel)
|
||||
{
|
||||
g_pAssetManager->UnrefModel(m_hModel);
|
||||
}
|
||||
m_hModel = g_pAssetManager->LoadModel(szName);
|
||||
m_pModel = g_pAssetManager->GetModelByIndex(m_hModel);
|
||||
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);
|
||||
}
|
||||
|
||||
void CPhysicsProp::EnableMovement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CPhysicsProp::DisableMovement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,19 @@ friend CBaseModelEntity;
|
||||
public:
|
||||
DECLARE_CLASS(CPhysicsProp, CBaseModelEntity);
|
||||
virtual void Spawn() override;
|
||||
virtual void Precache() override;
|
||||
|
||||
virtual void SetModel( const char *szName ) override;
|
||||
virtual void EnableMovement();
|
||||
virtual void DisableMovement();
|
||||
|
||||
void Think( float fDelta );
|
||||
private:
|
||||
HFunnyModel m_hModel;
|
||||
FunnyModel_t *m_pModel;
|
||||
FunnyPhysics_t *m_pPhysics;
|
||||
HCollider m_hCollider;
|
||||
IPhysicsBody *m_pBody;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define GAME_H
|
||||
#include "tier2/ifilesystem.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "iphysics.h"
|
||||
extern IRenderContext *g_pRenderContext;
|
||||
extern IFileSystem *filesystem;
|
||||
extern IGameWindowManager *g_pWindowManager;
|
||||
@@ -15,6 +16,9 @@ public:
|
||||
|
||||
extern CEngineVars *g_pEngineVars;
|
||||
|
||||
extern IPhysics *g_pPhysics;
|
||||
extern IPhysicsWorld *g_pPhysicsWorld;
|
||||
|
||||
#define FUNNY_SECURE_PORT 27015
|
||||
#define FUNNY_QUERY_PORT 27016
|
||||
|
||||
|
||||
Reference in New Issue
Block a user