work on world
This commit is contained in:
@@ -36,6 +36,7 @@ DECLARE_BUILD_STAGE(install_game)
|
|||||||
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(config, "steam_lib"));
|
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(config, "steam_lib"));
|
||||||
}
|
}
|
||||||
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(launcher, "launcher"));
|
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(launcher, "launcher"));
|
||||||
|
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/maps");
|
||||||
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/models");
|
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/models");
|
||||||
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/meshes");
|
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/meshes");
|
||||||
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/materials");
|
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/materials");
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"classname": "prop_physics",
|
"classname": "prop_physics",
|
||||||
"mesh": "game/core/maps/test/test0.fmesh_c",
|
"model": "game/core/maps/test/test0.fmdl",
|
||||||
"material": "game/core/materials",
|
|
||||||
"physics_type": "triangles",
|
|
||||||
"physics_mesh": "game/core/maps/test/test0.fmesh_c",
|
|
||||||
"physics": "static"
|
"physics": "static"
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"classname": "prop_physics",
|
"classname": "prop_physics",
|
||||||
"model": "game/core/meshes/cube.fmdl",
|
"model": "game/core/models/cube.fmdl",
|
||||||
"physics": "dynamic",
|
"physics": "dynamic",
|
||||||
"origin": [ 0, 15, 0 ]
|
"origin": [ 0, 3, 0 ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
5
funnyassets/maps/test/test0.fmdl
Normal file
5
funnyassets/maps/test/test0.fmdl
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"Mesh": "game/core/maps/test/test0.fmesh_c",
|
||||||
|
"Material": "game/core/materials/cube.fmat",
|
||||||
|
"Physics": "game/core/maps/test/test0.fpx"
|
||||||
|
}
|
||||||
Binary file not shown.
4
funnyassets/maps/test/test0.fpx
Normal file
4
funnyassets/maps/test/test0.fpx
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"Type": "Triangles",
|
||||||
|
"Mesh": "game/core/maps/test/test0.fpx"
|
||||||
|
}
|
||||||
@@ -151,29 +151,29 @@ uint32_t CAssetManager::LoadModel( const char *szName )
|
|||||||
switch (pRoot->GetType())
|
switch (pRoot->GetType())
|
||||||
{
|
{
|
||||||
case JSON_PARAMETER_OBJECT:
|
case JSON_PARAMETER_OBJECT:
|
||||||
|
{
|
||||||
|
pMainObject = pRoot->GetObject();
|
||||||
|
if (!pMainObject)
|
||||||
{
|
{
|
||||||
pMainObject = pRoot->GetObject();
|
V_printf("Failed to load properties\n");
|
||||||
if (!pMainObject)
|
return 0;
|
||||||
{
|
|
||||||
V_printf("Failed to load properties\n");
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
IJSONValue *pMesh = pMainObject->GetValue("Mesh");
|
IJSONValue *pMesh = pMainObject->GetValue("Mesh");
|
||||||
IJSONValue *pMaterial = pMainObject->GetValue("Material");
|
IJSONValue *pMaterial = pMainObject->GetValue("Material");
|
||||||
IJSONValue *pPhysics = pMainObject->GetValue("Physics");
|
IJSONValue *pPhysics = pMainObject->GetValue("Physics");
|
||||||
if (pMesh)
|
if (pMesh)
|
||||||
pModel->m_hMesh = LoadMesh(pMesh->GetStringValue());
|
pModel->m_hMesh = LoadMesh(pMesh->GetStringValue());
|
||||||
if (pMaterial)
|
if (pMaterial)
|
||||||
pModel->m_hMaterial = LoadMaterial(pMaterial->GetStringValue());
|
pModel->m_hMaterial = LoadMaterial(pMaterial->GetStringValue());
|
||||||
if (pPhysics)
|
if (pPhysics)
|
||||||
pModel->m_hPhysics = LoadPhysics(pPhysics->GetStringValue());
|
pModel->m_hPhysics = LoadPhysics(pPhysics->GetStringValue());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return hModel;
|
return hModel;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -317,6 +317,7 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
|||||||
IJSONValue *pRoot = JSONManager()->ReadString(szProperties);
|
IJSONValue *pRoot = JSONManager()->ReadString(szProperties);
|
||||||
if (!pRoot)
|
if (!pRoot)
|
||||||
return 0;
|
return 0;
|
||||||
|
V_printf("PHYSICS %s\n", szName);
|
||||||
|
|
||||||
IJSONObject *pMainObject;
|
IJSONObject *pMainObject;
|
||||||
switch (pRoot->GetType())
|
switch (pRoot->GetType())
|
||||||
@@ -339,6 +340,7 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
CUtlString szType = pTypeValue->GetStringValue();
|
CUtlString szType = pTypeValue->GetStringValue();
|
||||||
|
V_printf("szType\n");
|
||||||
if (szType == "Sphere")
|
if (szType == "Sphere")
|
||||||
{
|
{
|
||||||
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
||||||
|
|||||||
@@ -78,9 +78,9 @@ public:
|
|||||||
fnThink m_pfnThink = NULL;
|
fnThink m_pfnThink = NULL;
|
||||||
CUtlString m_szClassName;
|
CUtlString m_szClassName;
|
||||||
private:
|
private:
|
||||||
Vector m_vPosition;
|
Vector m_vPosition = {};
|
||||||
Quat m_vRotation;
|
Quat m_vRotation = {};
|
||||||
Vector m_vScale;
|
Vector m_vScale = {1,1,1};
|
||||||
|
|
||||||
uint64_t m_uSlot;
|
uint64_t m_uSlot;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,32 +12,68 @@ void C_BaseModelEntity::Spawn()
|
|||||||
|
|
||||||
void C_BaseModelEntity::Think( float fDelta )
|
void C_BaseModelEntity::Think( float fDelta )
|
||||||
{
|
{
|
||||||
m_pInstance->SetPosition(GetAbsOrigin());
|
UpdateModel();
|
||||||
m_pInstance->SetRotation(GetAbsAngles());
|
if (m_pInstance)
|
||||||
m_pInstance->SetScale({GetScale(),GetScale(),GetScale()});
|
{
|
||||||
|
m_pInstance->SetPosition(GetAbsOrigin());
|
||||||
|
m_pInstance->SetRotation(GetAbsAngles());
|
||||||
|
m_pInstance->SetScale({GetScale(),GetScale(),GetScale()});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void C_BaseModelEntity::SetModel( const char *szName )
|
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)
|
if (m_hModelHandle)
|
||||||
{
|
{
|
||||||
g_pAssetManager->UnrefModel(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);
|
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);
|
FunnyMesh_t *pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh);
|
||||||
m_pInstance = g_pWorldRenderer->CreateInstance(pMesh->m_pMesh);
|
m_pInstance = g_pWorldRenderer->CreateInstance(pMesh->m_pMesh);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
C_BaseModelEntity::~C_BaseModelEntity()
|
C_BaseModelEntity::~C_BaseModelEntity()
|
||||||
{
|
{
|
||||||
FunnyMesh_t *pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh);
|
if (m_pInstance)
|
||||||
g_pWorldRenderer->DestroyMeshInstance(pMesh->m_pMesh, m_pInstance);
|
{
|
||||||
g_pAssetManager->UnrefModel(m_hModelHandle);
|
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)
|
BEGIN_DATADESC(C_BaseModelEntity)
|
||||||
|
DEFINE_KEYFIELD(m_szModel, FIELD_STRING, "model")
|
||||||
END_DATADESC()
|
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
|
class C_BaseModelEntity: public C_BaseEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_CLASS(C_BaseModelEntity, C_BaseEntity);
|
DECLARE_CLASS(C_BaseModelEntity, C_BaseEntity)
|
||||||
DECLARE_DATADESC();
|
DECLARE_DATADESC()
|
||||||
|
DECLARE_CLIENTCLASS()
|
||||||
|
|
||||||
virtual ~C_BaseModelEntity() override;
|
virtual ~C_BaseModelEntity() override;
|
||||||
virtual void Precache() override;
|
virtual void Precache() override;
|
||||||
@@ -20,9 +21,13 @@ public:
|
|||||||
void SetModel( const char *szName );
|
void SetModel( const char *szName );
|
||||||
private:
|
private:
|
||||||
|
|
||||||
HFunnyModel m_hModelHandle;
|
void UpdateModel();
|
||||||
FunnyModel_t *m_pModel;
|
char m_szCurrentModel[256] = {};
|
||||||
IMeshInstance *m_pInstance;
|
char m_szModel[256] = {};
|
||||||
|
|
||||||
|
HFunnyModel m_hModelHandle = 0;
|
||||||
|
FunnyModel_t *m_pModel = NULL;
|
||||||
|
IMeshInstance *m_pInstance = NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -229,6 +229,16 @@ void CEntitySystem::NetRecvPacket( NetPacket_t *pPacket )
|
|||||||
if (pPlayerPacket->m_setLocalEntity.m_uIndex > MAX_EDICTS)
|
if (pPlayerPacket->m_setLocalEntity.m_uIndex > MAX_EDICTS)
|
||||||
break;
|
break;
|
||||||
s_pLocalEntity = m_pEntities[pPlayerPacket->m_setLocalEntity.m_uIndex];
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
void C_MOBAPlayer::Precache()
|
void C_MOBAPlayer::Precache()
|
||||||
{
|
{
|
||||||
SetModel("game/core/models/cube.fmdl");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ void CFunnyMeshInstance::Frame()
|
|||||||
v[2] = m_vScale.z;
|
v[2] = m_vScale.z;
|
||||||
glm_scale_make(m, v);
|
glm_scale_make(m, v);
|
||||||
glm_mat4_mul(m_data.m_matTranslation, m, m_data.m_matTranslation);
|
glm_mat4_mul(m_data.m_matTranslation, m, m_data.m_matTranslation);
|
||||||
|
|
||||||
m_data.m_uAlbedo = 1;
|
m_data.m_uAlbedo = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,12 +224,6 @@ void CFunnyWorldRenderer::Frame( float fDelta )
|
|||||||
glm_translate(matCamera2, m_vPos);
|
glm_translate(matCamera2, m_vPos);
|
||||||
glm_perspective(glm_rad(60), uWidth/(float)uHeight, 0.01, 10000, matCamera);
|
glm_perspective(glm_rad(60), uWidth/(float)uHeight, 0.01, 10000, matCamera);
|
||||||
glm_mul(matCamera, matCamera2, 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_pViewBufferData = (ViewBuffer_t*)m_pViewBuffer->Map();
|
||||||
m_pViewBuffer->Lock();
|
m_pViewBuffer->Lock();
|
||||||
V_memcpy(&m_pViewBufferData->m_matCameraProjection, matCamera, sizeof(matCamera));
|
V_memcpy(&m_pViewBufferData->m_matCameraProjection, matCamera, sizeof(matCamera));
|
||||||
@@ -308,11 +303,11 @@ void CFunnyWorldRenderer::Frame( float fDelta )
|
|||||||
m_pRasterMaterial->PSSetTextureArray(1, m_pTextures);
|
m_pRasterMaterial->PSSetTextureArray(1, m_pTextures);
|
||||||
g_pRenderContext->DestroyBuffer(pDataBuffer);
|
g_pRenderContext->DestroyBuffer(pDataBuffer);
|
||||||
}
|
}
|
||||||
|
m_pRasterCommandList->SetMaterial(m_pRasterMaterial);
|
||||||
for ( auto mesh: m_pMeshes)
|
for ( auto mesh: m_pMeshes)
|
||||||
{
|
{
|
||||||
if (mesh->m_instances.GetSize()==0)
|
if (mesh->m_instances.GetSize()==0)
|
||||||
continue;
|
continue;
|
||||||
m_pRasterCommandList->SetMaterial(m_pRasterMaterial);
|
|
||||||
m_pRasterCommandList->SetVertexBuffer(0, mesh->m_pVertexBuffer);
|
m_pRasterCommandList->SetVertexBuffer(0, mesh->m_pVertexBuffer);
|
||||||
m_pRasterCommandList->DrawPrimitives(mesh->m_pVertexBuffer->GetSize()/32, 0, mesh->m_instances.GetSize(), 0);
|
m_pRasterCommandList->DrawPrimitives(mesh->m_pVertexBuffer->GetSize()/32, 0, mesh->m_instances.GetSize(), 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,6 +195,7 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
|||||||
if (!bHasBeenCreated)
|
if (!bHasBeenCreated)
|
||||||
return hPhysics;
|
return hPhysics;
|
||||||
FunnyPhysics_t *pPhysics = m_physics.GetObjectPtr(hPhysics);
|
FunnyPhysics_t *pPhysics = m_physics.GetObjectPtr(hPhysics);
|
||||||
|
*pPhysics = {};
|
||||||
|
|
||||||
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
|
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
|
||||||
if (!pHandle)
|
if (!pHandle)
|
||||||
@@ -225,10 +226,14 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
CUtlString szType = pTypeValue->GetStringValue();
|
CUtlString szType = pTypeValue->GetStringValue();
|
||||||
|
V_printf("%s\n", szType.GetString());
|
||||||
if (szType == "Sphere")
|
if (szType == "Sphere")
|
||||||
{
|
{
|
||||||
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
||||||
}
|
}
|
||||||
|
if (szType == "Triangles")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
return hPhysics;
|
return hPhysics;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ lookforname:
|
|||||||
BEGIN_DATADESC_NOBASE(CBaseEntity)
|
BEGIN_DATADESC_NOBASE(CBaseEntity)
|
||||||
DEFINE_KEYFIELD(m_vPosition, FIELD_FLOAT3, "origin")
|
DEFINE_KEYFIELD(m_vPosition, FIELD_FLOAT3, "origin")
|
||||||
DEFINE_KEYFIELD(m_vRotation, FIELD_QUATERNION, "angles")
|
DEFINE_KEYFIELD(m_vRotation, FIELD_QUATERNION, "angles")
|
||||||
DEFINE_KEYFIELD(m_vScale, FIELD_FLOAT3, "scales")
|
DEFINE_KEYFIELD(m_vScale, FIELD_FLOAT3, "scale")
|
||||||
END_DATADESC()
|
END_DATADESC()
|
||||||
|
|
||||||
IMPLEMENT_SEND_DT_NOBASE(CBaseEntity)
|
IMPLEMENT_SEND_DT_NOBASE(CBaseEntity)
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ public:
|
|||||||
const char *m_szClassName;
|
const char *m_szClassName;
|
||||||
uint64_t m_ullOwner;
|
uint64_t m_ullOwner;
|
||||||
private:
|
private:
|
||||||
Vector m_vPosition;
|
Vector m_vPosition = {};
|
||||||
Quat m_vRotation;
|
Quat m_vRotation = {};
|
||||||
Vector m_vScale;
|
Vector m_vScale = {1,1,1};
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,37 @@
|
|||||||
#include "basemodelentity.h"
|
#include "basemodelentity.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
|
void CBaseModelEntity::Spawn()
|
||||||
|
{
|
||||||
|
SetThink(Think);
|
||||||
|
}
|
||||||
|
|
||||||
void CBaseModelEntity::SetModel( const char *szName )
|
void CBaseModelEntity::SetModel( const char *szName )
|
||||||
{
|
{
|
||||||
|
V_memset(m_szModel, 0, 256);
|
||||||
|
V_strncpy(m_szModel, szName, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CBaseModelEntity::OnModelChanged( const char *szName )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBaseModelEntity::Think( float fDelta )
|
||||||
|
{
|
||||||
|
if (V_strncmp(m_szModel, m_szCurrentModel, 256))
|
||||||
|
{
|
||||||
|
V_memset(m_szCurrentModel, 0, 256);
|
||||||
|
V_strncpy(m_szCurrentModel, m_szModel, 255);
|
||||||
|
OnModelChanged(m_szCurrentModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_SEND_DT(CBaseModelEntity)
|
||||||
|
NetPropString(m_szModel)
|
||||||
|
END_RECV_DT()
|
||||||
|
IMPLEMENT_EMPTY_RECV_DT(CBaseModelEntity)
|
||||||
|
|
||||||
|
BEGIN_DATADESC(CBaseModelEntity)
|
||||||
|
DEFINE_KEYFIELD(m_szModel, FIELD_STRING, "model")
|
||||||
|
END_DATADESC()
|
||||||
|
|||||||
@@ -10,7 +10,15 @@ class CBaseModelEntity: public CBaseEntity
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
DECLARE_CLASS(CBaseModelEntity, CBaseEntity);
|
DECLARE_CLASS(CBaseModelEntity, CBaseEntity);
|
||||||
|
DECLARE_DATADESC()
|
||||||
|
DECLARE_SERVERCLASS()
|
||||||
|
virtual void Spawn() override;
|
||||||
virtual void SetModel( const char *szName );
|
virtual void SetModel( const char *szName );
|
||||||
|
virtual void OnModelChanged( const char *szName );
|
||||||
|
virtual void Think( float fDelta );
|
||||||
|
private:
|
||||||
|
char m_szCurrentModel[256] = {};
|
||||||
|
char m_szModel[256] = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ DECLARE_BUILD_STAGE(Server)
|
|||||||
|
|
||||||
"game.cpp",
|
"game.cpp",
|
||||||
"assetmgr.cpp",
|
"assetmgr.cpp",
|
||||||
|
"worldsystem.cpp",
|
||||||
|
|
||||||
"entitysystem.cpp",
|
"entitysystem.cpp",
|
||||||
"baseentity.cpp",
|
"baseentity.cpp",
|
||||||
|
|||||||
@@ -262,6 +262,8 @@ void CEntitySystem::NetSendThink( INetworkBase *pBase )
|
|||||||
V_memcpy(pcCurrentData,
|
V_memcpy(pcCurrentData,
|
||||||
pNetMap->m_pFields[u].m_uOffset+(char*)pEntity,
|
pNetMap->m_pFields[u].m_uOffset+(char*)pEntity,
|
||||||
pNetMap->m_pFields[u].m_uSize);
|
pNetMap->m_pFields[u].m_uSize);
|
||||||
|
//if (pNetMap->m_pFields[u].m_eType == FIELD_STRING)
|
||||||
|
//V_printf("v: %s %u\n", pcCurrentData, pNetMap->m_pFields[u].m_uSize);
|
||||||
pcCurrentData += (pNetMap->m_pFields[u].m_uSize+7) & ~7;
|
pcCurrentData += (pNetMap->m_pFields[u].m_uSize+7) & ~7;
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,9 @@
|
|||||||
#include "baseentity.h"
|
#include "baseentity.h"
|
||||||
#include "enginebridge.h"
|
#include "enginebridge.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "inetworkserver.h"
|
|
||||||
#include "netprotocol.h"
|
#include "netprotocol.h"
|
||||||
#include "tier1/utlvector.h"
|
|
||||||
#include "iphysics.h"
|
#include "iphysics.h"
|
||||||
|
#include "worldsystem.h"
|
||||||
#ifdef STEAM
|
#ifdef STEAM
|
||||||
#include "steam/isteamgameserver.h"
|
#include "steam/isteamgameserver.h"
|
||||||
#include "steam/steam_gameserver.h"
|
#include "steam/steam_gameserver.h"
|
||||||
@@ -91,9 +90,12 @@ void CFunnyGameBridge::Init()
|
|||||||
if (g_pEngineConstants->m_bIsSteam)
|
if (g_pEngineConstants->m_bIsSteam)
|
||||||
{
|
{
|
||||||
SteamErrMsg err = { 0 };
|
SteamErrMsg err = { 0 };
|
||||||
if (SteamGameServer_InitEx(INADDR_ANY, FUNNY_SECURE_PORT, FUNNY_QUERY_PORT, eServerModeAuthentication, "0.0.0.0", &err));
|
if (!SteamGameServer())
|
||||||
{
|
{
|
||||||
V_printf("SteamGameServer_InitEx: %s\n", err);
|
if (SteamGameServer_InitEx(INADDR_ANY, FUNNY_SECURE_PORT, FUNNY_QUERY_PORT, eServerModeAuthentication, "0.0.0.0", &err))
|
||||||
|
{
|
||||||
|
V_printf("SteamGameServer_InitEx: %s\n", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SteamNetworkingUtils()->InitRelayNetworkAccess();
|
SteamNetworkingUtils()->InitRelayNetworkAccess();
|
||||||
}
|
}
|
||||||
@@ -118,6 +120,8 @@ void CFunnyGameBridge::Init()
|
|||||||
CreateInterfaceFn fnPhysicsFactory = Sys_GetFactory("RapierPhysics");
|
CreateInterfaceFn fnPhysicsFactory = Sys_GetFactory("RapierPhysics");
|
||||||
g_pPhysics = (IPhysics*)fnPhysicsFactory(PHYSICS_INTERFACE_VERSION, NULL);
|
g_pPhysics = (IPhysics*)fnPhysicsFactory(PHYSICS_INTERFACE_VERSION, NULL);
|
||||||
g_pPhysicsWorld = g_pPhysics->CreateWorld();
|
g_pPhysicsWorld = g_pPhysics->CreateWorld();
|
||||||
|
|
||||||
|
g_pWorldSystem->LoadMap("game/core/maps/test/test.fmap");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,19 @@ void CPhysicsProp::Spawn()
|
|||||||
{
|
{
|
||||||
CBaseEntity::Spawn();
|
CBaseEntity::Spawn();
|
||||||
SetThink(Think);
|
SetThink(Think);
|
||||||
|
|
||||||
|
V_printf("hi\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPhysicsProp::Think( float fDelta )
|
void CPhysicsProp::Think( float fDelta )
|
||||||
{
|
{
|
||||||
BaseClass::SetAbsOrigin(m_pBody->GetPosition());
|
BaseClass::Think(fDelta);
|
||||||
BaseClass::SetAbsAngles(m_pBody->GetRotation());
|
if (m_pBody)
|
||||||
|
{
|
||||||
|
BaseClass::SetAbsOrigin(m_pBody->GetPosition());
|
||||||
|
BaseClass::SetAbsAngles(m_pBody->GetRotation());
|
||||||
|
}
|
||||||
|
V_printf("%f %f %f\n", GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPhysicsProp::SetAbsAngles( Quat vQuat )
|
void CPhysicsProp::SetAbsAngles( Quat vQuat )
|
||||||
@@ -42,7 +49,7 @@ void CPhysicsProp::SetAbsOrigin( Vector origin )
|
|||||||
m_pBody->SetPosition(m_pBody->GetPosition());
|
m_pBody->SetPosition(m_pBody->GetPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPhysicsProp::SetModel( const char *szName )
|
void CPhysicsProp::OnModelChanged( const char *szName )
|
||||||
{
|
{
|
||||||
if (m_hModel)
|
if (m_hModel)
|
||||||
{
|
{
|
||||||
@@ -65,3 +72,4 @@ void CPhysicsProp::DisableMovement()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LINK_ENTITY_TO_CLASS(prop_physics, CPhysicsProp)
|
||||||
|
|||||||
@@ -16,12 +16,13 @@ public:
|
|||||||
virtual void SetAbsQAngles( float fPitch, float fYaw, float fRoll ) override;
|
virtual void SetAbsQAngles( float fPitch, float fYaw, float fRoll ) override;
|
||||||
virtual void SetAbsOrigin( Vector origin ) override;
|
virtual void SetAbsOrigin( Vector origin ) override;
|
||||||
|
|
||||||
virtual void SetModel( const char *szName ) override;
|
virtual void OnModelChanged( const char *szName ) override;
|
||||||
virtual void EnableMovement();
|
virtual void EnableMovement();
|
||||||
virtual void DisableMovement();
|
virtual void DisableMovement();
|
||||||
|
|
||||||
void Think( float fDelta );
|
void Think( float fDelta );
|
||||||
private:
|
private:
|
||||||
|
EPhysicsBodyType m_ePhysicsType;
|
||||||
HFunnyModel m_hModel = 0;
|
HFunnyModel m_hModel = 0;
|
||||||
FunnyModel_t *m_pModel = NULL;
|
FunnyModel_t *m_pModel = NULL;
|
||||||
FunnyPhysics_t *m_pPhysics = NULL;
|
FunnyPhysics_t *m_pPhysics = NULL;
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
#include "worldsystem.h"
|
||||||
|
#include "game.h"
|
||||||
|
#include "entitysystem.h"
|
||||||
|
#include "baseentity.h"
|
||||||
|
#include "netprotocol.h"
|
||||||
|
|
||||||
|
void CWorldSystem::LoadEntity( IJSONValue *pObject )
|
||||||
|
{
|
||||||
|
if (pObject->GetType() != JSON_PARAMETER_OBJECT)
|
||||||
|
return;
|
||||||
|
IJSONObject *pObjectRoot = pObject->GetObject();
|
||||||
|
|
||||||
|
const char *szClassName = NULL;
|
||||||
|
|
||||||
|
for ( int i = 0; i < pObjectRoot->GetCount(); i++)
|
||||||
|
{
|
||||||
|
if (V_strcmp(pObjectRoot->GetParameterName(i),"classname"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
IJSONValue *pValue = pObjectRoot->GetParameter(i);
|
||||||
|
if (pValue->GetType() != JSON_PARAMETER_STRING)
|
||||||
|
{
|
||||||
|
V_printf("classname must be a string\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
szClassName = pValue->GetStringValue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (szClassName == NULL)
|
||||||
|
return;
|
||||||
|
CBaseEntity *pEntity = EntitySystem()->CreateByClassname(szClassName, NULL);
|
||||||
|
if (!pEntity)
|
||||||
|
return;
|
||||||
|
for ( int i = 0; i < pObjectRoot->GetCount(); i++)
|
||||||
|
{
|
||||||
|
if (!V_strcmp(pObjectRoot->GetParameterName(i),"classname"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
|
||||||
|
IJSONValue *pValue = pObjectRoot->GetParameter(i);
|
||||||
|
typedescription_t *pDataMap = pEntity->FindDataByMapName(pObjectRoot->GetParameterName(i));
|
||||||
|
if (!pDataMap)
|
||||||
|
continue;
|
||||||
|
union {
|
||||||
|
void *pData;
|
||||||
|
float *pfData;
|
||||||
|
Vector *pvData;
|
||||||
|
char *pcData;
|
||||||
|
};
|
||||||
|
pData = (char*)pEntity+pDataMap->m_iFieldOffset;
|
||||||
|
switch (pDataMap->m_eFieldType)
|
||||||
|
{
|
||||||
|
case FIELD_STRING:
|
||||||
|
if (pValue->GetType() != JSON_PARAMETER_STRING)
|
||||||
|
continue;
|
||||||
|
V_strncpy(pcData, pValue->GetStringValue(), pDataMap->m_uFieldSize);
|
||||||
|
V_printf("loading %s %u\n", pValue->GetStringValue(), pDataMap->m_uFieldSize);
|
||||||
|
continue;
|
||||||
|
case FIELD_FLOAT3:
|
||||||
|
if (pValue->GetType() != JSON_PARAMETER_ARRAY)
|
||||||
|
continue;
|
||||||
|
if (pValue->GetArray()->GetCount() == 3)
|
||||||
|
{
|
||||||
|
if ( pValue->GetArray()->GetParameter(0)->GetType()
|
||||||
|
== JSON_PARAMETER_NUMBER )
|
||||||
|
pvData->x = pValue->GetArray()->GetParameter(0)->GetNumberValue();
|
||||||
|
if ( pValue->GetArray()->GetParameter(1)->GetType()
|
||||||
|
== JSON_PARAMETER_NUMBER )
|
||||||
|
pvData->y = pValue->GetArray()->GetParameter(1)->GetNumberValue();
|
||||||
|
if ( pValue->GetArray()->GetParameter(2)->GetType()
|
||||||
|
== JSON_PARAMETER_NUMBER )
|
||||||
|
pvData->z = pValue->GetArray()->GetParameter(2)->GetNumberValue();
|
||||||
|
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
pEntity->Spawn();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CWorldSystem::LoadMap( const char *szName )
|
||||||
|
{
|
||||||
|
V_printf("Loading %s\n", szName);
|
||||||
|
// unload the map
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
// can't fail at this point
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
switch (pRoot->GetType())
|
||||||
|
{
|
||||||
|
case JSON_PARAMETER_ARRAY:
|
||||||
|
{
|
||||||
|
for ( uint32_t u = 0; u < pRoot->GetArray()->GetCount(); u++ )
|
||||||
|
{
|
||||||
|
IJSONValue *pObjectValue = pRoot->GetArray()->GetParameter(u);
|
||||||
|
if ( !pObjectValue )
|
||||||
|
continue;
|
||||||
|
LoadEntity(pObjectValue);
|
||||||
|
}
|
||||||
|
JSONManager()->FreeValue(pRoot);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static CWorldSystem s_worldSystem;
|
||||||
|
CWorldSystem *g_pWorldSystem = &s_worldSystem;
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef WORLD_SYSTEM_H
|
||||||
|
#define WORLD_SYSTEM_H
|
||||||
|
|
||||||
|
#include "assetmgr.h"
|
||||||
|
#include "tier2/fileformats/json.h"
|
||||||
|
|
||||||
|
class CWorldSystem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual bool LoadMap( const char *szName );
|
||||||
|
private:
|
||||||
|
virtual void LoadEntity( IJSONValue *pObject);
|
||||||
|
};
|
||||||
|
extern CWorldSystem *g_pWorldSystem;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -98,9 +98,11 @@ struct datamap_t
|
|||||||
#define _class_offsetof( class, var ) ((size_t)&(((class*)0)->var))
|
#define _class_offsetof( class, var ) ((size_t)&(((class*)0)->var))
|
||||||
|
|
||||||
#define _FIELD( name, fieldtype, count, flags, mapname, tolerance) { #name, mapname, fieldtype, _class_offsetof(ThisClass, name), count, sizeof(((ThisClass*)0)->name), flags },
|
#define _FIELD( name, fieldtype, count, flags, mapname, tolerance) { #name, mapname, fieldtype, _class_offsetof(ThisClass, name), count, sizeof(((ThisClass*)0)->name), flags },
|
||||||
#define DEFINE_FIELD( name, fieldtype ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY, 0, 0)
|
#define DEFINE_FIELD( name, fieldtype ) _FIELD( name, fieldtype, 1, FTYPEDESC_SAVE, 0, 0)
|
||||||
#define DEFINE_KEYFIELD( name, fieldtype, mapname ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY, mapname, 0)
|
#define DEFINE_KEYFIELD( name, fieldtype, mapname ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY | FTYPEDESC_SAVE, mapname, 0)
|
||||||
|
|
||||||
|
#define FTYPEDESC_GLOBAL 0x0001
|
||||||
|
#define FTYPEDESC_SAVE 0x0002
|
||||||
#define FTYPEDESC_KEY 0x0004
|
#define FTYPEDESC_KEY 0x0004
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,13 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "datamap.h"
|
#include "datamap.h"
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class CNetworkVarBase
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct netfield_t
|
struct netfield_t
|
||||||
{
|
{
|
||||||
const char *m_szName;
|
const char *m_szName;
|
||||||
@@ -20,6 +27,7 @@ struct netmap_t
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define NetPropInt(name) { #name, FIELD_INT, _class_offsetof(ThisClass, name), sizeof(name)}
|
#define NetPropInt(name) { #name, FIELD_INT, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||||
|
#define NetPropString(name) { #name, FIELD_STRING, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||||
#define NetPropFloat(name) { #name, FIELD_FLOAT, _class_offsetof(ThisClass, name), sizeof(name)}
|
#define NetPropFloat(name) { #name, FIELD_FLOAT, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||||
#define NetPropFloat3(name) \
|
#define NetPropFloat3(name) \
|
||||||
NetPropFloat(name.x), \
|
NetPropFloat(name.x), \
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "tier0/network.h"
|
#include "tier0/network.h"
|
||||||
|
|
||||||
class CNetworkUInt32
|
class CNetworkProtocolUInt32
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CNetworkUInt32() : m_uValue(0) {}
|
CNetworkProtocolUInt32() : m_uValue(0) {}
|
||||||
CNetworkUInt32( uint32_t uValue ) : m_uValue(htonl(uValue)) {}
|
CNetworkProtocolUInt32( uint32_t uValue ) : m_uValue(htonl(uValue)) {}
|
||||||
operator uint32_t() const {
|
operator uint32_t() const {
|
||||||
return htonl(m_uValue);
|
return htonl(m_uValue);
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,7 @@ enum EMessageType: uint32_t
|
|||||||
MESSAGE_ENTITY_DATA_SYNC,
|
MESSAGE_ENTITY_DATA_SYNC,
|
||||||
|
|
||||||
k_EMessage_PlayerSetLocalEntity,
|
k_EMessage_PlayerSetLocalEntity,
|
||||||
|
k_EMessage_ResetEntities,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlayerJoined_t
|
struct PlayerJoined_t
|
||||||
@@ -36,39 +37,39 @@ struct PlayerJoined_t
|
|||||||
struct PlayerJoinedCallback_t
|
struct PlayerJoinedCallback_t
|
||||||
{
|
{
|
||||||
EMessageType m_eType;
|
EMessageType m_eType;
|
||||||
CNetworkUInt32 m_uPlayerIndex;
|
CNetworkProtocolUInt32 m_uPlayerIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlayerLeft_t
|
struct PlayerLeft_t
|
||||||
{
|
{
|
||||||
EMessageType m_eType;
|
EMessageType m_eType;
|
||||||
CNetworkUInt32 m_uPlayerIndex;
|
CNetworkProtocolUInt32 m_uPlayerIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EntityClass_t
|
struct EntityClass_t
|
||||||
{
|
{
|
||||||
EMessageType m_eType;
|
EMessageType m_eType;
|
||||||
CNetworkUInt32 m_uIndex;
|
CNetworkProtocolUInt32 m_uIndex;
|
||||||
int8_t m_szEntityName[256];
|
int8_t m_szEntityName[256];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EntityDataSync_t
|
struct EntityDataSync_t
|
||||||
{
|
{
|
||||||
EMessageType m_eType;
|
EMessageType m_eType;
|
||||||
CNetworkUInt32 m_uIndex;
|
CNetworkProtocolUInt32 m_uIndex;
|
||||||
CNetworkUInt32 m_uCount;
|
CNetworkProtocolUInt32 m_uCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EntityDataSyncValue_t
|
struct EntityDataSyncValue_t
|
||||||
{
|
{
|
||||||
CNetworkUInt32 m_uVariableIndex;
|
CNetworkProtocolUInt32 m_uVariableIndex;
|
||||||
CNetworkUInt32 m_uVariableSize;
|
CNetworkProtocolUInt32 m_uVariableSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SetLocalEntity_t
|
struct SetLocalEntity_t
|
||||||
{
|
{
|
||||||
EMessageType m_eType;
|
EMessageType m_eType;
|
||||||
CNetworkUInt32 m_uIndex;
|
CNetworkProtocolUInt32 m_uIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
union PlayerPacket_t
|
union PlayerPacket_t
|
||||||
|
|||||||
@@ -17,6 +17,14 @@ struct CuboidShape_t
|
|||||||
float m_fExtentZ;
|
float m_fExtentZ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct TrianglesShape_t
|
||||||
|
{
|
||||||
|
float *m_pfPositions;
|
||||||
|
uint32_t m_nPositionCount;
|
||||||
|
uint32_t *m_puIndicies;
|
||||||
|
uint32_t m_nIndiciesCount;
|
||||||
|
};
|
||||||
|
|
||||||
enum EPhysicsBodyType
|
enum EPhysicsBodyType
|
||||||
{
|
{
|
||||||
k_EPhysics_Static,
|
k_EPhysics_Static,
|
||||||
@@ -58,6 +66,7 @@ abstract_class IPhysics
|
|||||||
public:
|
public:
|
||||||
virtual HShape CreateBall( BallShape_t ball ) = 0;
|
virtual HShape CreateBall( BallShape_t ball ) = 0;
|
||||||
virtual HShape CreateCube( CuboidShape_t ball ) = 0;
|
virtual HShape CreateCube( CuboidShape_t ball ) = 0;
|
||||||
|
virtual HShape CreateTriangles( TrianglesShape_t shape ) = 0;
|
||||||
virtual void DestroyShape( HShape hShape ) = 0;
|
virtual void DestroyShape( HShape hShape ) = 0;
|
||||||
|
|
||||||
virtual HCollider CreateCollider( HShape hShape ) = 0;
|
virtual HCollider CreateCollider( HShape hShape ) = 0;
|
||||||
|
|||||||
@@ -95,6 +95,11 @@ public:
|
|||||||
return CRapierPhysics_CreateCube(m_pRustHandle, ball);
|
return CRapierPhysics_CreateCube(m_pRustHandle, ball);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual HShape CreateTriangles( TrianglesShape_t shape ) override
|
||||||
|
{
|
||||||
|
return CRapierPhysics_CreateCube(m_pRustHandle, shape);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void DestroyShape( HShape hShape ) override
|
virtual void DestroyShape( HShape hShape ) override
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ pub struct BallShape_t
|
|||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct CuboidShape_t
|
pub struct CuboidShape_t
|
||||||
{
|
{
|
||||||
m_fExtentX: f32,
|
m_fExtentX: f32,
|
||||||
@@ -36,12 +37,38 @@ pub struct CuboidShape_t
|
|||||||
m_fExtentZ: f32,
|
m_fExtentZ: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum RapierShapeType {
|
||||||
|
Ball(Ball),
|
||||||
|
Cuboid(Cuboid),
|
||||||
|
Capsule(Capsule),
|
||||||
|
Segment(Segment),
|
||||||
|
Triangle(Triangle),
|
||||||
|
Voxels(Voxels),
|
||||||
|
TriMesh(TriMesh),
|
||||||
|
Polyline(Polyline),
|
||||||
|
HalfSpace(HalfSpace),
|
||||||
|
HeightField(HeightField),
|
||||||
|
Compound(Compound),
|
||||||
|
ConvexPolyhedron(ConvexPolyhedron),
|
||||||
|
Cylinder(Cylinder),
|
||||||
|
Cone(Cone),
|
||||||
|
RoundCuboid(RoundCuboid),
|
||||||
|
RoundTriangle(RoundTriangle),
|
||||||
|
RoundCylinder(RoundCylinder),
|
||||||
|
RoundCone(RoundCone),
|
||||||
|
RoundConvexPolyhedron(RoundConvexPolyhedron),
|
||||||
|
#[allow(dead_code)]
|
||||||
|
Custom,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct RapierShape_t
|
pub struct RapierShape_t
|
||||||
{
|
{
|
||||||
m_eType: ShapeType,
|
m_shape: RapierShapeType,
|
||||||
m_pShape: *mut dyn Shape,
|
|
||||||
m_sharedShape: SharedShape,
|
m_sharedShape: SharedShape,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +84,7 @@ pub enum EPhysicsBodyType
|
|||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct RapierCollider_t
|
pub struct RapierCollider_t
|
||||||
{
|
{
|
||||||
m_collider: Collider,
|
m_collider: Collider,
|
||||||
@@ -94,6 +122,14 @@ pub struct RapierPhysics_t
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TrianglesShape_t
|
||||||
|
{
|
||||||
|
m_pfPositions: *const f32,
|
||||||
|
m_nPositionCount: const u32,
|
||||||
|
m_puIndicies,
|
||||||
|
m_nIndiciesCount,
|
||||||
|
};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn CRapierPhysicsBody_SetPosition( this: *mut RapierPhysicsBody_t, fX: f32, fY: f32, fZ: f32 )
|
pub unsafe extern "C" fn CRapierPhysicsBody_SetPosition( this: *mut RapierPhysicsBody_t, fX: f32, fY: f32, fZ: f32 )
|
||||||
{
|
{
|
||||||
@@ -201,51 +237,52 @@ pub unsafe extern "C" fn CRapierPhysics_New() -> *mut RapierPhysics_t
|
|||||||
{
|
{
|
||||||
let physics = RapierPhysics_t {};
|
let physics = RapierPhysics_t {};
|
||||||
let pPhysics = V_malloc!(RapierPhysics_t, 1);
|
let pPhysics = V_malloc!(RapierPhysics_t, 1);
|
||||||
*pPhysics = physics;
|
*pPhysics = physics.clone();
|
||||||
pPhysics
|
pPhysics
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn CRapierPhysics_CreateBall( this: *mut RapierPhysics_t, ball: BallShape_t ) -> *mut RapierShape_t
|
pub unsafe extern "C" fn CRapierPhysics_CreateBall( this: *mut RapierPhysics_t, ball: BallShape_t ) -> *mut RapierShape_t
|
||||||
{
|
{
|
||||||
let rapierShape = Ball::new(ball.m_fRadius);
|
|
||||||
let pRapierShapeMemory: *mut Ball = V_malloc!(Ball, 1);
|
|
||||||
*pRapierShapeMemory = rapierShape;
|
|
||||||
|
|
||||||
let shape: RapierShape_t = RapierShape_t {
|
|
||||||
m_eType: ShapeType::Ball,
|
|
||||||
m_pShape: pRapierShapeMemory,
|
|
||||||
m_sharedShape: SharedShape::new(rapierShape)
|
|
||||||
};
|
|
||||||
let pShapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1);
|
let pShapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1);
|
||||||
*pShapeMemory = shape;
|
std::ptr::write(&mut (*pShapeMemory).m_shape, RapierShapeType::Ball(Ball::new(ball.m_fRadius)));
|
||||||
|
match ((*pShapeMemory).m_shape)
|
||||||
|
{
|
||||||
|
RapierShapeType::Ball(b) => {
|
||||||
|
std::ptr::write(&mut (*pShapeMemory).m_sharedShape, SharedShape::new(b));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
pShapeMemory
|
pShapeMemory
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn CRapierPhysics_CreateCube( this: *mut RapierPhysics_t, cuboid: CuboidShape_t ) -> *mut RapierShape_t
|
pub unsafe extern "C" fn CRapierPhysics_CreateCube( this: *mut RapierPhysics_t, cuboid: CuboidShape_t ) -> *mut RapierShape_t
|
||||||
{
|
{
|
||||||
let rapierShape = Cuboid::new(vec3(cuboid.m_fExtentX, cuboid.m_fExtentY, cuboid.m_fExtentZ));
|
|
||||||
let pRapierShapeMemory: *mut Cuboid = V_malloc!(Cuboid, 1);
|
|
||||||
*pRapierShapeMemory = rapierShape;
|
|
||||||
|
|
||||||
let shape: RapierShape_t = RapierShape_t {
|
|
||||||
m_eType: ShapeType::Cuboid,
|
|
||||||
m_pShape: pRapierShapeMemory,
|
|
||||||
m_sharedShape: SharedShape::new(rapierShape)
|
|
||||||
};
|
|
||||||
let pShapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1);
|
let pShapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1);
|
||||||
*pShapeMemory = shape;
|
std::ptr::write(&mut (*pShapeMemory).m_shape, RapierShapeType::Cuboid(
|
||||||
|
Cuboid::new(vec3(cuboid.m_fExtentX, cuboid.m_fExtentY, cuboid.m_fExtentZ)))
|
||||||
|
);
|
||||||
|
match ((*pShapeMemory).m_shape)
|
||||||
|
{
|
||||||
|
RapierShapeType::Cuboid(b) => {
|
||||||
|
std::ptr::write(&mut (*pShapeMemory).m_sharedShape, SharedShape::new(b));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
pShapeMemory
|
pShapeMemory
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn CRapierPhysics_CreateCollider( this: *mut RapierPhysics_t, pShape: *mut RapierShape_t ) -> *mut RapierCollider_t
|
pub unsafe extern "C" fn CRapierPhysics_CreateCollider( this: *mut RapierPhysics_t, pShape: *mut RapierShape_t ) -> *mut RapierCollider_t
|
||||||
{
|
{
|
||||||
let pRapierShape = (*pShape).m_pShape;
|
println!("this {:?}", pShape);
|
||||||
let shape: &SharedShape = &(*pShape).m_sharedShape;
|
let shape: &SharedShape = &(*pShape).m_sharedShape;
|
||||||
|
println!("this {:?}", pShape);
|
||||||
let pCollider = V_malloc!(RapierCollider_t, 1);
|
let pCollider = V_malloc!(RapierCollider_t, 1);
|
||||||
|
println!("this {:?}", pShape);
|
||||||
std::ptr::write(&mut (*pCollider).m_collider, ColliderBuilder::new(shape.clone()).build());
|
std::ptr::write(&mut (*pCollider).m_collider, ColliderBuilder::new(shape.clone()).build());
|
||||||
|
println!("this {:?}", pShape);
|
||||||
pCollider
|
pCollider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class ExportFunnyMesh(Operator, ExportHelper):
|
|||||||
filename_ext = ".fmesh_c"
|
filename_ext = ".fmesh_c"
|
||||||
|
|
||||||
filter_glob: StringProperty(
|
filter_glob: StringProperty(
|
||||||
default="*.map",
|
default="*.fmesh_c",
|
||||||
options={'HIDDEN'},
|
options={'HIDDEN'},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -44,8 +44,8 @@ def export_my_format(filepath):
|
|||||||
world_pos = obj.matrix_world @ vert.co
|
world_pos = obj.matrix_world @ vert.co
|
||||||
world_normal = obj.matrix_world @ vert.normal
|
world_normal = obj.matrix_world @ vert.normal
|
||||||
f.write(struct.pack('f', world_pos.x))
|
f.write(struct.pack('f', world_pos.x))
|
||||||
f.write(struct.pack('f', world_pos.y))
|
|
||||||
f.write(struct.pack('f', world_pos.z))
|
f.write(struct.pack('f', world_pos.z))
|
||||||
|
f.write(struct.pack('f', world_pos.y))
|
||||||
if uv_layer:
|
if uv_layer:
|
||||||
uv = uv_layer[loop_index].uv
|
uv = uv_layer[loop_index].uv
|
||||||
f.write(struct.pack('f', uv.x))
|
f.write(struct.pack('f', uv.x))
|
||||||
@@ -54,8 +54,8 @@ def export_my_format(filepath):
|
|||||||
f.write(struct.pack('f', 0))
|
f.write(struct.pack('f', 0))
|
||||||
f.write(struct.pack('f', 0))
|
f.write(struct.pack('f', 0))
|
||||||
f.write(struct.pack('f', world_normal.x))
|
f.write(struct.pack('f', world_normal.x))
|
||||||
f.write(struct.pack('f', world_normal.y))
|
|
||||||
f.write(struct.pack('f', world_normal.z))
|
f.write(struct.pack('f', world_normal.z))
|
||||||
|
f.write(struct.pack('f', world_normal.y))
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user