work on world

This commit is contained in:
2026-03-16 15:35:31 +02:00
parent c05bca6d27
commit 6d5141cf43
33 changed files with 416 additions and 100 deletions

View File

@@ -36,6 +36,7 @@ DECLARE_BUILD_STAGE(install_game)
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(config, "steam_lib"));
}
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/meshes");
filesystem2->CopyDirectory(CUtlString("%s/core/",szOutputDir.GetString()), "funnyassets/materials");

View File

@@ -1,17 +1,14 @@
[
{
"classname": "prop_physics",
"mesh": "game/core/maps/test/test0.fmesh_c",
"material": "game/core/materials",
"physics_type": "triangles",
"physics_mesh": "game/core/maps/test/test0.fmesh_c",
"model": "game/core/maps/test/test0.fmdl",
"physics": "static"
},
{
"classname": "prop_physics",
"model": "game/core/meshes/cube.fmdl",
"model": "game/core/models/cube.fmdl",
"physics": "dynamic",
"origin": [ 0, 15, 0 ]
"origin": [ 0, 3, 0 ]
}
]

View 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.

View File

@@ -0,0 +1,4 @@
{
"Type": "Triangles",
"Mesh": "game/core/maps/test/test0.fpx"
}

View File

@@ -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});

View File

@@ -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;
};

View File

@@ -12,32 +12,68 @@ void C_BaseModelEntity::Spawn()
void C_BaseModelEntity::Think( float fDelta )
{
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()
{
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)

View File

@@ -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

View File

@@ -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;
}

View File

@@ -5,7 +5,6 @@
void C_MOBAPlayer::Precache()
{
SetModel("game/core/models/cube.fmdl");
}

View File

@@ -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);
}

View File

@@ -195,6 +195,7 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
if (!bHasBeenCreated)
return hPhysics;
FunnyPhysics_t *pPhysics = m_physics.GetObjectPtr(hPhysics);
*pPhysics = {};
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
if (!pHandle)
@@ -225,10 +226,14 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
return 0;
}
CUtlString szType = pTypeValue->GetStringValue();
V_printf("%s\n", szType.GetString());
if (szType == "Sphere")
{
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
}
if (szType == "Triangles")
{
}
return hPhysics;
}

View File

@@ -128,7 +128,7 @@ lookforname:
BEGIN_DATADESC_NOBASE(CBaseEntity)
DEFINE_KEYFIELD(m_vPosition, FIELD_FLOAT3, "origin")
DEFINE_KEYFIELD(m_vRotation, FIELD_QUATERNION, "angles")
DEFINE_KEYFIELD(m_vScale, FIELD_FLOAT3, "scales")
DEFINE_KEYFIELD(m_vScale, FIELD_FLOAT3, "scale")
END_DATADESC()
IMPLEMENT_SEND_DT_NOBASE(CBaseEntity)

View File

@@ -81,9 +81,9 @@ public:
const char *m_szClassName;
uint64_t m_ullOwner;
private:
Vector m_vPosition;
Quat m_vRotation;
Vector m_vScale;
Vector m_vPosition = {};
Quat m_vRotation = {};
Vector m_vScale = {1,1,1};
};

View File

@@ -1,6 +1,37 @@
#include "basemodelentity.h"
#include "game.h"
void CBaseModelEntity::Spawn()
{
SetThink(Think);
}
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()

View File

@@ -10,7 +10,15 @@ class CBaseModelEntity: public CBaseEntity
public:
DECLARE_CLASS(CBaseModelEntity, CBaseEntity);
DECLARE_DATADESC()
DECLARE_SERVERCLASS()
virtual void Spawn() override;
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

View File

@@ -21,6 +21,7 @@ DECLARE_BUILD_STAGE(Server)
"game.cpp",
"assetmgr.cpp",
"worldsystem.cpp",
"entitysystem.cpp",
"baseentity.cpp",

View File

@@ -262,6 +262,8 @@ void CEntitySystem::NetSendThink( INetworkBase *pBase )
V_memcpy(pcCurrentData,
pNetMap->m_pFields[u].m_uOffset+(char*)pEntity,
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;
x++;
}

View File

@@ -3,10 +3,9 @@
#include "baseentity.h"
#include "enginebridge.h"
#include "game.h"
#include "inetworkserver.h"
#include "netprotocol.h"
#include "tier1/utlvector.h"
#include "iphysics.h"
#include "worldsystem.h"
#ifdef STEAM
#include "steam/isteamgameserver.h"
#include "steam/steam_gameserver.h"
@@ -91,10 +90,13 @@ void CFunnyGameBridge::Init()
if (g_pEngineConstants->m_bIsSteam)
{
SteamErrMsg err = { 0 };
if (SteamGameServer_InitEx(INADDR_ANY, FUNNY_SECURE_PORT, FUNNY_QUERY_PORT, eServerModeAuthentication, "0.0.0.0", &err));
if (!SteamGameServer())
{
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();
}
if (g_pEngineConstants->m_bIsDedicated && g_pEngineConstants->m_bIsSteam)
@@ -118,6 +120,8 @@ void CFunnyGameBridge::Init()
CreateInterfaceFn fnPhysicsFactory = Sys_GetFactory("RapierPhysics");
g_pPhysics = (IPhysics*)fnPhysicsFactory(PHYSICS_INTERFACE_VERSION, NULL);
g_pPhysicsWorld = g_pPhysics->CreateWorld();
g_pWorldSystem->LoadMap("game/core/maps/test/test.fmap");
}

View File

@@ -11,12 +11,19 @@ void CPhysicsProp::Spawn()
{
CBaseEntity::Spawn();
SetThink(Think);
V_printf("hi\n");
}
void CPhysicsProp::Think( float fDelta )
{
BaseClass::Think(fDelta);
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 )
@@ -42,7 +49,7 @@ void CPhysicsProp::SetAbsOrigin( Vector origin )
m_pBody->SetPosition(m_pBody->GetPosition());
}
void CPhysicsProp::SetModel( const char *szName )
void CPhysicsProp::OnModelChanged( const char *szName )
{
if (m_hModel)
{
@@ -65,3 +72,4 @@ void CPhysicsProp::DisableMovement()
}
LINK_ENTITY_TO_CLASS(prop_physics, CPhysicsProp)

View File

@@ -16,12 +16,13 @@ public:
virtual void SetAbsQAngles( float fPitch, float fYaw, float fRoll ) 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 DisableMovement();
void Think( float fDelta );
private:
EPhysicsBodyType m_ePhysicsType;
HFunnyModel m_hModel = 0;
FunnyModel_t *m_pModel = NULL;
FunnyPhysics_t *m_pPhysics = NULL;

View File

@@ -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;

View File

@@ -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

View File

@@ -98,9 +98,11 @@ struct datamap_t
#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 DEFINE_FIELD( name, fieldtype ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY, 0, 0)
#define DEFINE_KEYFIELD( name, fieldtype, mapname ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY, mapname, 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 | FTYPEDESC_SAVE, mapname, 0)
#define FTYPEDESC_GLOBAL 0x0001
#define FTYPEDESC_SAVE 0x0002
#define FTYPEDESC_KEY 0x0004

View File

@@ -4,6 +4,13 @@
#include "stdint.h"
#include "datamap.h"
template <typename T>
class CNetworkVarBase
{
};
struct netfield_t
{
const char *m_szName;
@@ -20,6 +27,7 @@ struct netmap_t
};
#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 NetPropFloat3(name) \
NetPropFloat(name.x), \

View File

@@ -5,11 +5,11 @@
#include "stdint.h"
#include "tier0/network.h"
class CNetworkUInt32
class CNetworkProtocolUInt32
{
public:
CNetworkUInt32() : m_uValue(0) {}
CNetworkUInt32( uint32_t uValue ) : m_uValue(htonl(uValue)) {}
CNetworkProtocolUInt32() : m_uValue(0) {}
CNetworkProtocolUInt32( uint32_t uValue ) : m_uValue(htonl(uValue)) {}
operator uint32_t() const {
return htonl(m_uValue);
}
@@ -25,6 +25,7 @@ enum EMessageType: uint32_t
MESSAGE_ENTITY_DATA_SYNC,
k_EMessage_PlayerSetLocalEntity,
k_EMessage_ResetEntities,
};
struct PlayerJoined_t
@@ -36,39 +37,39 @@ struct PlayerJoined_t
struct PlayerJoinedCallback_t
{
EMessageType m_eType;
CNetworkUInt32 m_uPlayerIndex;
CNetworkProtocolUInt32 m_uPlayerIndex;
};
struct PlayerLeft_t
{
EMessageType m_eType;
CNetworkUInt32 m_uPlayerIndex;
CNetworkProtocolUInt32 m_uPlayerIndex;
};
struct EntityClass_t
{
EMessageType m_eType;
CNetworkUInt32 m_uIndex;
CNetworkProtocolUInt32 m_uIndex;
int8_t m_szEntityName[256];
};
struct EntityDataSync_t
{
EMessageType m_eType;
CNetworkUInt32 m_uIndex;
CNetworkUInt32 m_uCount;
CNetworkProtocolUInt32 m_uIndex;
CNetworkProtocolUInt32 m_uCount;
};
struct EntityDataSyncValue_t
{
CNetworkUInt32 m_uVariableIndex;
CNetworkUInt32 m_uVariableSize;
CNetworkProtocolUInt32 m_uVariableIndex;
CNetworkProtocolUInt32 m_uVariableSize;
};
struct SetLocalEntity_t
{
EMessageType m_eType;
CNetworkUInt32 m_uIndex;
CNetworkProtocolUInt32 m_uIndex;
};
union PlayerPacket_t

View File

@@ -17,6 +17,14 @@ struct CuboidShape_t
float m_fExtentZ;
};
struct TrianglesShape_t
{
float *m_pfPositions;
uint32_t m_nPositionCount;
uint32_t *m_puIndicies;
uint32_t m_nIndiciesCount;
};
enum EPhysicsBodyType
{
k_EPhysics_Static,
@@ -58,6 +66,7 @@ abstract_class IPhysics
public:
virtual HShape CreateBall( BallShape_t ball ) = 0;
virtual HShape CreateCube( CuboidShape_t ball ) = 0;
virtual HShape CreateTriangles( TrianglesShape_t shape ) = 0;
virtual void DestroyShape( HShape hShape ) = 0;
virtual HCollider CreateCollider( HShape hShape ) = 0;

View File

@@ -95,6 +95,11 @@ public:
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
{

View File

@@ -29,6 +29,7 @@ pub struct BallShape_t
#[repr(C)]
#[derive(Clone, Copy)]
#[derive(Debug)]
pub struct CuboidShape_t
{
m_fExtentX: f32,
@@ -36,12 +37,38 @@ pub struct CuboidShape_t
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(Debug)]
pub struct RapierShape_t
{
m_eType: ShapeType,
m_pShape: *mut dyn Shape,
m_shape: RapierShapeType,
m_sharedShape: SharedShape,
}
@@ -57,6 +84,7 @@ pub enum EPhysicsBodyType
#[derive(Clone)]
#[derive(Debug)]
pub struct RapierCollider_t
{
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]
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 pPhysics = V_malloc!(RapierPhysics_t, 1);
*pPhysics = physics;
*pPhysics = physics.clone();
pPhysics
}
#[no_mangle]
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);
*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
}
#[no_mangle]
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);
*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
}
#[no_mangle]
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;
println!("this {:?}", pShape);
let pCollider = V_malloc!(RapierCollider_t, 1);
println!("this {:?}", pShape);
std::ptr::write(&mut (*pCollider).m_collider, ColliderBuilder::new(shape.clone()).build());
println!("this {:?}", pShape);
pCollider
}

View File

@@ -23,7 +23,7 @@ class ExportFunnyMesh(Operator, ExportHelper):
filename_ext = ".fmesh_c"
filter_glob: StringProperty(
default="*.map",
default="*.fmesh_c",
options={'HIDDEN'},
)
@@ -44,8 +44,8 @@ def export_my_format(filepath):
world_pos = obj.matrix_world @ vert.co
world_normal = obj.matrix_world @ vert.normal
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.y))
if uv_layer:
uv = uv_layer[loop_index].uv
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', 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.y))
return {'FINISHED'}