diff --git a/build.cpp b/build.cpp index 8ec7822..dfbc53e 100755 --- a/build.cpp +++ b/build.cpp @@ -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"); diff --git a/funnyassets/maps/test/test.fmap b/funnyassets/maps/test/test.fmap index b9c68d9..c965de8 100644 --- a/funnyassets/maps/test/test.fmap +++ b/funnyassets/maps/test/test.fmap @@ -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 ] } ] diff --git a/funnyassets/maps/test/test0.fmdl b/funnyassets/maps/test/test0.fmdl new file mode 100644 index 0000000..8b9342c --- /dev/null +++ b/funnyassets/maps/test/test0.fmdl @@ -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" +} diff --git a/funnyassets/maps/test/test0.fmesh_c b/funnyassets/maps/test/test0.fmesh_c index de79f66..ee7216b 100644 Binary files a/funnyassets/maps/test/test0.fmesh_c and b/funnyassets/maps/test/test0.fmesh_c differ diff --git a/funnyassets/maps/test/test0.fpx b/funnyassets/maps/test/test0.fpx new file mode 100644 index 0000000..1e86f19 --- /dev/null +++ b/funnyassets/maps/test/test0.fpx @@ -0,0 +1,4 @@ +{ + "Type": "Triangles", + "Mesh": "game/core/maps/test/test0.fpx" +} diff --git a/game/client/assetmgr.cpp b/game/client/assetmgr.cpp index bcf3816..f3a8276 100644 --- a/game/client/assetmgr.cpp +++ b/game/client/assetmgr.cpp @@ -151,29 +151,29 @@ uint32_t CAssetManager::LoadModel( const char *szName ) switch (pRoot->GetType()) { case JSON_PARAMETER_OBJECT: + { + pMainObject = pRoot->GetObject(); + if (!pMainObject) { - pMainObject = pRoot->GetObject(); - if (!pMainObject) - { - V_printf("Failed to load properties\n"); - return 0; + V_printf("Failed to load properties\n"); + return 0; - } - 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()); + } + 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()); - return hModel; - } - break; + return hModel; + } + break; default: return 0; } @@ -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}); diff --git a/game/client/baseentity.h b/game/client/baseentity.h index 8ffd63f..efe7e31 100644 --- a/game/client/baseentity.h +++ b/game/client/baseentity.h @@ -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; }; diff --git a/game/client/basemodelentity.cpp b/game/client/basemodelentity.cpp index 2718db5..9940658 100644 --- a/game/client/basemodelentity.cpp +++ b/game/client/basemodelentity.cpp @@ -12,32 +12,68 @@ void C_BaseModelEntity::Spawn() void C_BaseModelEntity::Think( float fDelta ) { - m_pInstance->SetPosition(GetAbsOrigin()); - m_pInstance->SetRotation(GetAbsAngles()); - m_pInstance->SetScale({GetScale(),GetScale(),GetScale()}); + 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() { - FunnyMesh_t *pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh); - g_pWorldRenderer->DestroyMeshInstance(pMesh->m_pMesh, m_pInstance); - g_pAssetManager->UnrefModel(m_hModelHandle); + 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) diff --git a/game/client/basemodelentity.h b/game/client/basemodelentity.h index 8cb4176..e6f0258 100644 --- a/game/client/basemodelentity.h +++ b/game/client/basemodelentity.h @@ -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 diff --git a/game/client/entitysystem.cpp b/game/client/entitysystem.cpp index fd3a434..ffd4f89 100644 --- a/game/client/entitysystem.cpp +++ b/game/client/entitysystem.cpp @@ -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; } diff --git a/game/client/milmoba/player.cpp b/game/client/milmoba/player.cpp index a6cb3f0..a3addee 100644 --- a/game/client/milmoba/player.cpp +++ b/game/client/milmoba/player.cpp @@ -5,7 +5,6 @@ void C_MOBAPlayer::Precache() { - SetModel("game/core/models/cube.fmdl"); } diff --git a/game/client/worldrender.cpp b/game/client/worldrender.cpp index 5cef572..4e98dcf 100644 --- a/game/client/worldrender.cpp +++ b/game/client/worldrender.cpp @@ -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); } diff --git a/game/client/worldsystem.cpp b/game/client/worldsystem.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/game/client/worldsystem.h b/game/client/worldsystem.h deleted file mode 100644 index e69de29..0000000 diff --git a/game/server/assetmgr.cpp b/game/server/assetmgr.cpp index bdd8ebc..8aa7a2c 100644 --- a/game/server/assetmgr.cpp +++ b/game/server/assetmgr.cpp @@ -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; } diff --git a/game/server/baseentity.cpp b/game/server/baseentity.cpp index 82f140c..185c309 100644 --- a/game/server/baseentity.cpp +++ b/game/server/baseentity.cpp @@ -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) diff --git a/game/server/baseentity.h b/game/server/baseentity.h index a554f81..8069055 100644 --- a/game/server/baseentity.h +++ b/game/server/baseentity.h @@ -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}; }; diff --git a/game/server/basemodelentity.cpp b/game/server/basemodelentity.cpp index 7bb14b8..16b52db 100644 --- a/game/server/basemodelentity.cpp +++ b/game/server/basemodelentity.cpp @@ -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() diff --git a/game/server/basemodelentity.h b/game/server/basemodelentity.h index 63432db..3f90464 100644 --- a/game/server/basemodelentity.h +++ b/game/server/basemodelentity.h @@ -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 diff --git a/game/server/build.cpp b/game/server/build.cpp index 0ff55ff..1449d93 100644 --- a/game/server/build.cpp +++ b/game/server/build.cpp @@ -21,6 +21,7 @@ DECLARE_BUILD_STAGE(Server) "game.cpp", "assetmgr.cpp", + "worldsystem.cpp", "entitysystem.cpp", "baseentity.cpp", diff --git a/game/server/entitysystem.cpp b/game/server/entitysystem.cpp index 1902c35..198a01f 100644 --- a/game/server/entitysystem.cpp +++ b/game/server/entitysystem.cpp @@ -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++; } diff --git a/game/server/game.cpp b/game/server/game.cpp index 6353dc2..103c568 100644 --- a/game/server/game.cpp +++ b/game/server/game.cpp @@ -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,9 +90,12 @@ 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()) { - 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(); } @@ -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"); } diff --git a/game/server/physicsprop.cpp b/game/server/physicsprop.cpp index d58266d..b0a2a3f 100644 --- a/game/server/physicsprop.cpp +++ b/game/server/physicsprop.cpp @@ -11,12 +11,19 @@ void CPhysicsProp::Spawn() { CBaseEntity::Spawn(); SetThink(Think); + + V_printf("hi\n"); } void CPhysicsProp::Think( float fDelta ) { - BaseClass::SetAbsOrigin(m_pBody->GetPosition()); - BaseClass::SetAbsAngles(m_pBody->GetRotation()); + 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) diff --git a/game/server/physicsprop.h b/game/server/physicsprop.h index 9ef277b..b5cc194 100644 --- a/game/server/physicsprop.h +++ b/game/server/physicsprop.h @@ -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; diff --git a/game/server/worldsystem.cpp b/game/server/worldsystem.cpp index e69de29..67117dc 100644 --- a/game/server/worldsystem.cpp +++ b/game/server/worldsystem.cpp @@ -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; diff --git a/game/server/worldsystem.h b/game/server/worldsystem.h index e69de29..af4da1e 100644 --- a/game/server/worldsystem.h +++ b/game/server/worldsystem.h @@ -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 diff --git a/game/shared/datamap.h b/game/shared/datamap.h index cfda34e..3198aba 100644 --- a/game/shared/datamap.h +++ b/game/shared/datamap.h @@ -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 diff --git a/game/shared/netmap.h b/game/shared/netmap.h index 70aeab9..5728a47 100644 --- a/game/shared/netmap.h +++ b/game/shared/netmap.h @@ -4,6 +4,13 @@ #include "stdint.h" #include "datamap.h" +template +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), \ diff --git a/game/shared/netprotocol.h b/game/shared/netprotocol.h index 42fac93..d321f96 100644 --- a/game/shared/netprotocol.h +++ b/game/shared/netprotocol.h @@ -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 diff --git a/public/iphysics.h b/public/iphysics.h index 4cadf2e..f3228bd 100644 --- a/public/iphysics.h +++ b/public/iphysics.h @@ -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; diff --git a/rapier/physics.cpp b/rapier/physics.cpp index ec134b6..611a18a 100644 --- a/rapier/physics.cpp +++ b/rapier/physics.cpp @@ -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 { diff --git a/rapier/physics.rs b/rapier/physics.rs index ae13914..4201df6 100644 --- a/rapier/physics.rs +++ b/rapier/physics.rs @@ -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 } diff --git a/tools/blender_funnyasset.py b/tools/blender_funnyasset.py index b421aa4..800f371 100644 --- a/tools/blender_funnyasset.py +++ b/tools/blender_funnyasset.py @@ -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'}