diff --git a/external/GameNetworkingSockets b/external/GameNetworkingSockets index 517fff0..725e273 160000 --- a/external/GameNetworkingSockets +++ b/external/GameNetworkingSockets @@ -1 +1 @@ -Subproject commit 517fff0cf6866ba163f4f016b0ef28f365c06c05 +Subproject commit 725e273c7442bac7a8bc903c0b210b1c15c34d92 diff --git a/external/SDL b/external/SDL index 1d08131..7c11a8c 160000 --- a/external/SDL +++ b/external/SDL @@ -1 +1 @@ -Subproject commit 1d081314a89eb6bfd22bbc0224b604533ae6156b +Subproject commit 7c11a8cb9f66a2cac63f9a24ab2f49f6d4bf12a0 diff --git a/external/Vulkan-Headers b/external/Vulkan-Headers index 29184b9..2e0a6e6 160000 --- a/external/Vulkan-Headers +++ b/external/Vulkan-Headers @@ -1 +1 @@ -Subproject commit 29184b98984f6169a5e83e97557a77cff1e5b0ca +Subproject commit 2e0a6e699e35c9609bde2ca4abb0d380c0378639 diff --git a/external/Vulkan-Utility-Libraries b/external/Vulkan-Utility-Libraries index c15a1ac..4f4c0b6 160000 --- a/external/Vulkan-Utility-Libraries +++ b/external/Vulkan-Utility-Libraries @@ -1 +1 @@ -Subproject commit c15a1ac31670cb2ce61c235f070fb40ec6e42612 +Subproject commit 4f4c0b6c61223b703f1c753a404578d7d63932ad diff --git a/external/VulkanMemoryAllocator b/external/VulkanMemoryAllocator index b3cbbb4..f0969e9 160000 --- a/external/VulkanMemoryAllocator +++ b/external/VulkanMemoryAllocator @@ -1 +1 @@ -Subproject commit b3cbbb43ea3a506dffe10759e205a41c27c35ae2 +Subproject commit f0969e908b01104f66bec2f203103de2012354c9 diff --git a/external/cglm b/external/cglm index 83d5b2c..a886d6e 160000 --- a/external/cglm +++ b/external/cglm @@ -1 +1 @@ -Subproject commit 83d5b2c97378e61a4666825fd3a5548955c83add +Subproject commit a886d6e170292a1d534a7a2c0471be5953b16455 diff --git a/external/slang b/external/slang index f267cb7..5d775e2 160000 --- a/external/slang +++ b/external/slang @@ -1 +1 @@ -Subproject commit f267cb77a09b0f4cf083a9585bc1ddb3744c310a +Subproject commit 5d775e2829ceef5bd34ec89aa3eafa4968a74c8e diff --git a/external/stb b/external/stb index e6cd956..802cd45 160000 --- a/external/stb +++ b/external/stb @@ -1 +1 @@ -Subproject commit e6cd9561ea6dae43d41633797745789d142b691e +Subproject commit 802cd454f25469d3123e678af41364153c132c2a diff --git a/external/volk b/external/volk index e91ceff..d64d20b 160000 --- a/external/volk +++ b/external/volk @@ -1 +1 @@ -Subproject commit e91ceff7db05f92ac8b498c9631235a6a73566e2 +Subproject commit d64d20b4eaf2698296e085d9d9638c69af280e3e diff --git a/external/xtool b/external/xtool index f12a84e..22655f3 160000 --- a/external/xtool +++ b/external/xtool @@ -1 +1 @@ -Subproject commit f12a84e960fa9bced1249a8d233ab8eafca28f6f +Subproject commit 22655f3e70b87bef9be736e9625984e21bf8c697 diff --git a/funnyassets/maps/test/test.fmap b/funnyassets/maps/test/test.fmap index c965de8..151242e 100644 --- a/funnyassets/maps/test/test.fmap +++ b/funnyassets/maps/test/test.fmap @@ -2,13 +2,14 @@ { "classname": "prop_physics", "model": "game/core/maps/test/test0.fmdl", - "physics": "static" + "physics": "static", + "origin": [ 0, -10, 0 ] }, { "classname": "prop_physics", - "model": "game/core/models/cube.fmdl", + "model": "game/core/models/sphere.fmdl", "physics": "dynamic", - "origin": [ 0, 3, 0 ] + "origin": [ 0, -5, 0 ] } ] diff --git a/funnyassets/maps/test/test0.fmesh_c b/funnyassets/maps/test/test0.fmesh_c index ee7216b..4db1097 100644 Binary files a/funnyassets/maps/test/test0.fmesh_c and b/funnyassets/maps/test/test0.fmesh_c differ diff --git a/funnyassets/meshes/sphere.fmesh_c b/funnyassets/meshes/sphere.fmesh_c new file mode 100644 index 0000000..5da3c38 Binary files /dev/null and b/funnyassets/meshes/sphere.fmesh_c differ diff --git a/funnyassets/models/sphere.fmdl b/funnyassets/models/sphere.fmdl new file mode 100644 index 0000000..f708ebb --- /dev/null +++ b/funnyassets/models/sphere.fmdl @@ -0,0 +1,5 @@ +{ + "Mesh": "game/core/meshes/sphere.fmesh_c", + "Material": "game/core/materials/cube.fmat", + "Physics": "game/core/physics/sphere.fpx" +} diff --git a/funnyassets/physics/sphere.fpx b/funnyassets/physics/sphere.fpx new file mode 100644 index 0000000..cd28979 --- /dev/null +++ b/funnyassets/physics/sphere.fpx @@ -0,0 +1,4 @@ +{ + "Type": "Sphere", + "Radius": "1.0" +} diff --git a/funnyassets/shaders/mesh_raster.shader b/funnyassets/shaders/mesh_raster.shader index 6eed28c..6ec5759 100644 --- a/funnyassets/shaders/mesh_raster.shader +++ b/funnyassets/shaders/mesh_raster.shader @@ -19,6 +19,7 @@ COMMON { float4 m_vWorldPosition: POSITION; float4 m_vTexCoord: TEXCOORD0; float4 m_vNormal: NORMAL0; + uint m_uInstance: SV_InstanceID; } } VS @@ -31,8 +32,10 @@ VS float3 m_vNormal: NORMAL0; } - PS_INPUT vsMain( VS_INPUT input, uint uInstance: SV_InstanceID ) + PS_INPUT vsMain( VS_INPUT input, uint uInstance: SV_InstanceID, uint uBaseInstance: SV_StartInstanceLocation ) { + uint uInstance = uBaseInstance + uInstance; + PS_INPUT output = {}; output.m_vScreenPosition = float4(input.m_vPosition, 1); output.m_vScreenPosition = mul( @@ -53,6 +56,7 @@ VS g_modelData[uInstance].m_matRotation ); output.m_vTexCoord = float4(input.m_vTexCoord, 0, 0); + output.m_uInstance = uInstance; return output; } } @@ -69,10 +73,10 @@ PS float4 m_vWorldPosition: SV_Target2; } - PS_OUTPUT psMain( PS_INPUT input, uint uInstance: SV_InstanceID ) + PS_OUTPUT psMain( PS_INPUT input ) { PS_OUTPUT output = {}; - PerModelData data = g_modelData[uInstance]; + PerModelData data = g_modelData[input.m_uInstance]; output.m_vAlbedo = g_textures[data.m_uAlbedo].Sample(g_textureSampler, input.m_vTexCoord.xy); output.m_vWorldPosition = input.m_vWorldPosition; output.m_vNormal = input.m_vNormal; diff --git a/game/client/assetmgr.cpp b/game/client/assetmgr.cpp index f3a8276..8af6094 100644 --- a/game/client/assetmgr.cpp +++ b/game/client/assetmgr.cpp @@ -317,7 +317,6 @@ 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()) @@ -340,10 +339,9 @@ 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}); + pPhysics->m_hShape = g_pPhysics->CreateBall({0.1}); } return hPhysics; diff --git a/game/client/basemodelentity.cpp b/game/client/basemodelentity.cpp index 9940658..1c3394c 100644 --- a/game/client/basemodelentity.cpp +++ b/game/client/basemodelentity.cpp @@ -54,6 +54,8 @@ void C_BaseModelEntity::UpdateModel() FunnyMesh_t *pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh); m_pInstance = g_pWorldRenderer->CreateInstance(pMesh->m_pMesh); + m_pInstance->SetPosition({0,0,0}); + m_pInstance->SetRotation({0,0,0,1}); } diff --git a/game/client/game.cpp b/game/client/game.cpp index f3ee677..42c8b63 100644 --- a/game/client/game.cpp +++ b/game/client/game.cpp @@ -8,6 +8,7 @@ #include "game.h" #include "netprotocol.h" #include "userinput.h" +#include "math.h" #ifdef STEAM #include "steam/isteamgameserver.h" #include "steam/steam_gameserver.h" @@ -157,9 +158,10 @@ void CFunnyGameBridge::Frame( float fDelta ) m_fNetUpdateTimer += fDelta; if (m_fNetUpdateTimer >= fTickRate) m_fNetUpdateTimer = fTickRate; - while (m_fNetUpdateTimer >= fTickRate) + if (m_fNetUpdateTimer >= fTickRate) { m_fNetUpdateTimer-=fTickRate; + m_fNetUpdateTimer = fmod(m_fNetUpdateTimer, fTickRate); if (pCurrentServer) EntitySystem()->NetSendThink(pCurrentServer); } diff --git a/game/client/milmoba/player.cpp b/game/client/milmoba/player.cpp index a3addee..0223b3f 100644 --- a/game/client/milmoba/player.cpp +++ b/game/client/milmoba/player.cpp @@ -21,7 +21,6 @@ void C_MOBAPlayer::Think( float fDelta ) C_MOBAPlayer *pEntity = (C_MOBAPlayer*)UTIL_GetLocalPlayer(); - m_vMovementVector.z = m_bIsForward - m_bIsBack; m_vMovementVector.x = m_bIsLeft - m_bIsRight; diff --git a/game/client/worldrender.cpp b/game/client/worldrender.cpp index 4e98dcf..4f1236d 100644 --- a/game/client/worldrender.cpp +++ b/game/client/worldrender.cpp @@ -59,8 +59,8 @@ public: virtual void Frame(); PerMeshData_t m_data = {}; - Quat m_vRotation = {}; - Vector m_vPosition = {}; + Quat m_vRotation = { 0, 0, 0, 1 }; + Vector m_vPosition = { 0, 0, 0}; Vector m_vScale = { 1, 1, 1 }; }; @@ -105,6 +105,12 @@ void CFunnyMeshInstance::Frame() glm_mat4_mul(m_data.m_matTranslation, m, m_data.m_matTranslation); m_data.m_uAlbedo = 1; + /* + V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[0][0], m_data.m_matTranslation[0][1], m_data.m_matTranslation[0][2], m_data.m_matTranslation[0][3]); + V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[1][0], m_data.m_matTranslation[1][1], m_data.m_matTranslation[1][2], m_data.m_matTranslation[1][3]); + V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[2][0], m_data.m_matTranslation[2][1], m_data.m_matTranslation[2][2], m_data.m_matTranslation[2][3]); + V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[3][0], m_data.m_matTranslation[3][1], m_data.m_matTranslation[3][2], m_data.m_matTranslation[3][3]); + */ } @@ -222,7 +228,7 @@ void CFunnyWorldRenderer::Frame( float fDelta ) glm_mat4_identity(matCamera); glm_mat4_identity(matCamera2); glm_translate(matCamera2, m_vPos); - glm_perspective(glm_rad(60), uWidth/(float)uHeight, 0.01, 10000, matCamera); + glm_perspective(glm_rad(75), uWidth/(float)uHeight, 0.01, 10000, matCamera); glm_mul(matCamera, matCamera2, matCamera); m_pViewBufferData = (ViewBuffer_t*)m_pViewBuffer->Map(); m_pViewBuffer->Lock(); @@ -278,38 +284,44 @@ void CFunnyWorldRenderer::Frame( float fDelta ) m_pRasterCommandList->SetScissors(0, 0, uWidth, uHeight); m_pRasterCommandList->SetClearColor(0, 0, 0, 0, 0); m_pRasterCommandList->SetClearDepth(1); + uint32_t uTotalMeshes = 0; + uint32_t u = 0; + for ( auto mesh: m_pMeshes) + { + uTotalMeshes+=mesh->m_instances.GetSize(); + } + if (!uTotalMeshes) + return; + IBuffer *pDataBuffer = g_pRenderContext->CreateStorageBuffer(uTotalMeshes*sizeof(PerMeshData_t)); + pDataBuffer->Lock(); + void *pData = pDataBuffer->Map(); for ( auto mesh: m_pMeshes) { if (mesh->m_instances.GetSize()==0) continue; - CUtlVector data = {}; - data.Reserve(mesh->m_instances.GetSize()); - for ( auto instance: mesh->m_instances ) - { - instance->Frame(); - data.AppendTail(instance->m_data); - } - IBuffer *pDataBuffer = g_pRenderContext->CreateStorageBuffer(data.GetSize()*sizeof(PerMeshData_t)); - pDataBuffer->Lock(); - void *pData = pDataBuffer->Map(); for ( uint32_t i = 0; i < mesh->m_instances.GetSize(); i++ ) { - V_memcpy(&((PerMeshData_t*)pData)[i], &mesh->m_instances[i]->m_data, sizeof(PerMeshData_t)); + mesh->m_instances[i]->Frame(); + V_memcpy(&((PerMeshData_t*)pData)[i+u], &mesh->m_instances[i]->m_data, sizeof(PerMeshData_t)); } - pDataBuffer->Unmap(); - pDataBuffer->Unlock(); - m_pRasterMaterial->VSSetConstantsBuffer(0, m_pViewBuffer); - m_pRasterMaterial->VSSetConstantsBuffer(1, pDataBuffer); - m_pRasterMaterial->PSSetTextureArray(1, m_pTextures); - g_pRenderContext->DestroyBuffer(pDataBuffer); + u+=mesh->m_instances.GetSize(); } + pDataBuffer->Unmap(); + pDataBuffer->Unlock(); + g_pRenderContext->DestroyBuffer(pDataBuffer); + m_pRasterMaterial->VSSetConstantsBuffer(0, m_pViewBuffer); + m_pRasterMaterial->VSSetConstantsBuffer(1, pDataBuffer); + m_pRasterMaterial->PSSetTextureArray(1, m_pTextures); + m_pRasterCommandList->SetMaterial(m_pRasterMaterial); + u = 0; for ( auto mesh: m_pMeshes) { if (mesh->m_instances.GetSize()==0) continue; 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(), u); + u += mesh->m_instances.GetSize(); } m_pRasterCommandList->ResolveImage(m_pOutputImage, m_pResolvedOutputImage); diff --git a/game/server/assetmgr.cpp b/game/server/assetmgr.cpp index 94738a4..8a79117 100644 --- a/game/server/assetmgr.cpp +++ b/game/server/assetmgr.cpp @@ -197,11 +197,14 @@ HFunnyMesh CAssetManager::LoadMesh( const char *szName ) } - pMesh->m_nPositionCount = filesystem->Size(hMesh)/4; + *pMesh = {}; + pMesh->m_nPositionCount = filesystem->Size(hMesh)/32*3; pMesh->m_pfPositions = new float[pMesh->m_nPositionCount]; - filesystem->Read( hMesh, pMesh->m_pfPositions, filesystem->Size(hMesh)); - pMesh->m_nIndiciesCount = 0; - pMesh->m_puIndicies = 0; + for ( int i = 0; i < filesystem->Size(hMesh) / 32; i++) + { + filesystem->Seek( hMesh, SEEKMODE_RELATIVE_START, 32*i); + filesystem->Read( hMesh, &pMesh->m_pfPositions[i*3], 12); + } return hAsset; @@ -251,16 +254,13 @@ 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 == "TriangleMesh") { - V_printf("hi\n"); IJSONValue *pMeshValue = pMainObject->GetValue("Mesh"); - V_printf("hi\n"); if (!pMeshValue) { @@ -269,11 +269,9 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName ) return 0; } CUtlString szMesh = pMeshValue->GetStringValue(); - V_printf("%s\n", szMesh.GetString()); HFunnyMesh hMesh = LoadMesh(szMesh); FunnyMesh_t *pMesh = GetMeshByIndex(hMesh); - pPhysics->m_hShape = g_pPhysics->CreateTriangleMesh({pMesh->m_pfPositions, pMesh->m_nPositionCount}); - V_printf("%p\n", pPhysics->m_hShape); + pPhysics->m_hShape = g_pPhysics->CreateTriangleMesh({pMesh->m_pfPositions, pMesh->m_nPositionCount, pMesh->m_puIndicies, pMesh->m_nIndiciesCount}); pPhysics->m_hMesh = hMesh; } diff --git a/game/server/baseentity.cpp b/game/server/baseentity.cpp index 185c309..0bf2e12 100644 --- a/game/server/baseentity.cpp +++ b/game/server/baseentity.cpp @@ -21,9 +21,6 @@ void CBaseEntity::Precache() void CBaseEntity::Spawn() { Precache(); - SetAbsOrigin({0, 0, 0}); - SetAbsQAngles(0, 0, 0); - SetScale(1); } void CBaseEntity::SetAbsAngles( Quat vQuat ) diff --git a/game/server/baseentity.h b/game/server/baseentity.h index 8069055..81b65a2 100644 --- a/game/server/baseentity.h +++ b/game/server/baseentity.h @@ -78,8 +78,8 @@ public: virtual void SetNextThink( float fThink ); fnThink m_pfnThink = NULL; - const char *m_szClassName; - uint64_t m_ullOwner; + const char *m_szClassName = NULL; + uint64_t m_ullOwner = 0; private: Vector m_vPosition = {}; Quat m_vRotation = {}; diff --git a/game/server/basemodelentity.h b/game/server/basemodelentity.h index 3f90464..cdbb030 100644 --- a/game/server/basemodelentity.h +++ b/game/server/basemodelentity.h @@ -16,9 +16,9 @@ public: virtual void SetModel( const char *szName ); virtual void OnModelChanged( const char *szName ); virtual void Think( float fDelta ); + char m_szModel[256] = {}; private: char m_szCurrentModel[256] = {}; - char m_szModel[256] = {}; }; #endif diff --git a/game/server/milmoba/player.cpp b/game/server/milmoba/player.cpp index da2fb21..0ed6cf4 100644 --- a/game/server/milmoba/player.cpp +++ b/game/server/milmoba/player.cpp @@ -7,13 +7,18 @@ void CMOBAPlayer::Spawn() { CBaseEntity::Spawn(); - SetModel("game/core/models/cube.fmdl"); + SetPhysics(k_EPhysics_Static); + SetModel("game/core/models/sphere.fmdl"); SetScale(1); + SetAbsOrigin({0,-14.5, 0}); SetThink(Think); }; void CMOBAPlayer::Think( float fDelta ) { + BaseClass::Think(fDelta); + + Vector vPosition = GetAbsOrigin(); // player might lie to us m_vMovementVector.x = glm_clamp(m_vMovementVector.x, -1, 1); @@ -22,7 +27,6 @@ void CMOBAPlayer::Think( float fDelta ) vPosition.x += m_vMovementVector.x*fDelta*5; vPosition.z += m_vMovementVector.z*fDelta*5; SetAbsOrigin(vPosition); - V_printf("player: %f %f %f\n", vPosition.x, vPosition.y, vPosition.z); }; LINK_ENTITY_TO_CLASS(player, CMOBAPlayer) diff --git a/game/server/milmoba/player.h b/game/server/milmoba/player.h index cc6a44e..f578bc9 100644 --- a/game/server/milmoba/player.h +++ b/game/server/milmoba/player.h @@ -3,10 +3,10 @@ #include "physicsprop.h" -class CMOBAPlayer: public CBaseModelEntity +class CMOBAPlayer: public CPhysicsProp { public: - DECLARE_CLASS(CMOBAPlayer, CBaseModelEntity); + DECLARE_CLASS(CMOBAPlayer, CPhysicsProp); DECLARE_DATADESC(); DECLARE_SERVERCLASS() diff --git a/game/server/physicsprop.cpp b/game/server/physicsprop.cpp index e59d437..4b8a9c0 100644 --- a/game/server/physicsprop.cpp +++ b/game/server/physicsprop.cpp @@ -1,6 +1,11 @@ #include "physicsprop.h" #include "game.h" +CPhysicsProp::CPhysicsProp() +{ + SetAbsOrigin({0,0,0}); + SetAbsQAngles(0,0,0); +} void CPhysicsProp::Precache() { @@ -16,12 +21,17 @@ void CPhysicsProp::Spawn() void CPhysicsProp::Think( float fDelta ) { BaseClass::Think(fDelta); + if (m_pBody) { + if (m_ePhysicsType != m_eCurrentPhysicsType) + { + m_ePhysicsType = m_eCurrentPhysicsType; + m_pBody->SetType(m_eCurrentPhysicsType); + } 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 ) @@ -29,7 +39,7 @@ void CPhysicsProp::SetAbsAngles( Quat vQuat ) BaseClass::SetAbsAngles( vQuat ); if (m_pBody) - m_pBody->SetRotation(m_pBody->GetRotation()); + m_pBody->SetRotation(GetAbsAngles()); } void CPhysicsProp::SetAbsQAngles( float fPitch, float fYaw, float fRoll ) @@ -37,14 +47,14 @@ void CPhysicsProp::SetAbsQAngles( float fPitch, float fYaw, float fRoll ) BaseClass::SetAbsQAngles( fPitch, fYaw, fRoll); if (m_pBody) - m_pBody->SetRotation(m_pBody->GetRotation()); + m_pBody->SetRotation(GetAbsAngles()); } void CPhysicsProp::SetAbsOrigin( Vector origin ) { BaseClass::SetAbsOrigin( origin ); if (m_pBody) - m_pBody->SetPosition(m_pBody->GetPosition()); + m_pBody->SetPosition(GetAbsOrigin()); } void CPhysicsProp::OnModelChanged( const char *szName ) @@ -57,9 +67,16 @@ void CPhysicsProp::OnModelChanged( const char *szName ) m_pModel = g_pAssetManager->GetModelByIndex(m_hModel); m_pPhysics = g_pAssetManager->GetPhysicsByIndex(m_pModel->m_hPhysics); m_hCollider = g_pPhysics->CreateCollider(m_pPhysics->m_hShape); - m_pBody = g_pPhysicsWorld->CreateRigidBody(m_hCollider, k_EPhysics_Dynamic); - m_pBody->SetPosition({0,0,0}); - m_pBody->SetRotation({0,0,0}); + m_pBody = g_pPhysicsWorld->CreateRigidBody(m_hCollider, m_eCurrentPhysicsType); + m_pBody->SetPosition(GetAbsOrigin()); + m_pBody->SetRotation(GetAbsAngles()); + m_ePhysicsType = m_eCurrentPhysicsType; + if (!V_strcmp(szName, "game/core/maps/test/test0.fmdl")) + { + m_pBody->SetType(k_EPhysics_Static); + SetScale(1); + + } } void CPhysicsProp::EnableMovement() @@ -71,6 +88,13 @@ void CPhysicsProp::DisableMovement() { } + + +void CPhysicsProp::SetPhysics( EPhysicsBodyType eType ) +{ + m_eCurrentPhysicsType = eType; +} + BEGIN_DATADESC(CPhysicsProp) DEFINE_KEYFIELD(m_ePhysicsType, FIELD_INTEGER, "physics_type") END_DATADESC() diff --git a/game/server/physicsprop.h b/game/server/physicsprop.h index 8f98d19..637cb33 100644 --- a/game/server/physicsprop.h +++ b/game/server/physicsprop.h @@ -8,8 +8,10 @@ class CPhysicsProp: public CBaseModelEntity friend CBaseEntity; friend CBaseModelEntity; public: + DECLARE_CLASS(CPhysicsProp, CBaseModelEntity) DECLARE_DATADESC() + CPhysicsProp(); virtual void Spawn() override; virtual void Precache() override; @@ -25,8 +27,8 @@ public: void Think( float fDelta ); private: - EPhysicsBodyType m_ePhysicsType; - EPhysicsBodyType m_eCurrentPhysicsType; + EPhysicsBodyType m_ePhysicsType = k_EPhysics_Dynamic; + EPhysicsBodyType m_eCurrentPhysicsType = k_EPhysics_Dynamic; 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 67117dc..2ec49bc 100644 --- a/game/server/worldsystem.cpp +++ b/game/server/worldsystem.cpp @@ -54,7 +54,6 @@ void CWorldSystem::LoadEntity( IJSONValue *pObject ) 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) @@ -83,7 +82,6 @@ void CWorldSystem::LoadEntity( IJSONValue *pObject ) bool CWorldSystem::LoadMap( const char *szName ) { - V_printf("Loading %s\n", szName); // unload the map IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ); diff --git a/rapier/build.cpp b/rapier/build.cpp index 7951095..40b7a45 100644 --- a/rapier/build.cpp +++ b/rapier/build.cpp @@ -17,10 +17,10 @@ DECLARE_BUILD_STAGE(rapier) CUtlString szTarget = target.GetTriplet(); if (CommandLine()->CheckParam("-norust")) return 0; - rapier_lib = CUtlString("target/%s/debug/librapier_rtt.a",szTarget.GetString()); - V_printf("%s\n",rapier_lib.GetString()); + rapier_lib = CUtlString("target/%s/release/librapier_rtt.a",szTarget.GetString()); CUtlVector cargo_args = { "build", + "--release", "--target", szTarget }; diff --git a/rapier/physics.cpp b/rapier/physics.cpp index 0941d9b..5949dfc 100644 --- a/rapier/physics.cpp +++ b/rapier/physics.cpp @@ -42,6 +42,11 @@ public: return CRapierPhysicsBody_GetRotation(m_pBody); } + virtual void SetType( EPhysicsBodyType eType ) override + { + CRapierPhysicsBody_SetType(m_pBody, eType); + } + RapierPhysicsBody_t *m_pBody = NULL; diff --git a/rapier/physics.rs b/rapier/physics.rs index 6f05ae5..0cad87b 100644 --- a/rapier/physics.rs +++ b/rapier/physics.rs @@ -16,7 +16,7 @@ macro_rules! V_malloc { use std::{default, ops::Index, ptr::{self, null, null_mut}, slice::from_raw_parts, sync::Arc}; use parry3d::{glamx::vec3, shape::{Shape, ShapeType, SharedShape}}; -use rapier3d::{geometry::Ball, na::{UnitQuaternion, Vector4}}; +use rapier3d::{geometry::Ball, na::{UnitQuaternion, Vector4, coordinates::XYZ}}; use rapier3d::prelude::*; use libc::{malloc, free}; @@ -56,6 +56,7 @@ pub struct RapierShape_t } #[repr(C)] +#[derive(Debug)] pub enum EPhysicsBodyType { k_EPhysics_Static, @@ -119,7 +120,8 @@ pub unsafe extern "C" fn CRapierPhysicsBody_SetRotation( this: *mut RapierPhysic { let world: &mut RapierWorld_t = &mut *(*this).m_pWorld; world.m_rigidBodies[(*this).m_hRigidBodyHandle] - .set_translation(vec3(fX, fY, fZ), true); + .set_rotation(parry3d::glamx::Quat::from_xyzw(fX, fY, fZ, fW), true); + } #[repr(C)] @@ -256,7 +258,7 @@ pub unsafe extern "C" fn CRapierPhysics_CreateCube( this: *mut RapierPhysics_t, pub unsafe extern "C" fn CRapierPhysics_CreateTriangleMesh( this: *mut RapierPhysics_t, triangle: TriangleMeshShape_t ) -> *mut RapierShape_t { let pShapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1); - let positions = Vec::from_raw_parts(triangle.m_pfPositions as *mut Vec3, triangle.m_nPositionCount as usize, triangle.m_nPositionCount as usize); + let positions = Vec::from_raw_parts(triangle.m_pfPositions as *mut Vec3, (triangle.m_nPositionCount/3) as usize, (triangle.m_nPositionCount/3) as usize); let mut indices: Vec<[u32; 3]>; if ( triangle.m_nIndiciesCount == 0 ) @@ -265,8 +267,8 @@ pub unsafe extern "C" fn CRapierPhysics_CreateTriangleMesh( this: *mut RapierPhy { return null_mut(); } - indices = vec![[0,0,0]; (triangle.m_nPositionCount/3) as usize]; - for i in 0..indices.len()/3 + indices = vec![[0,0,0]; (triangle.m_nPositionCount/9) as usize]; + for i in 0..indices.len() { let u = i as u32; indices[i][0] = u*3; @@ -281,7 +283,7 @@ pub unsafe extern "C" fn CRapierPhysics_CreateTriangleMesh( this: *mut RapierPhy { return null_mut(); } - indices = Vec::from_raw_parts(triangle.m_puIndicies as *mut [u32; 3], triangle.m_nIndiciesCount as usize, triangle.m_nIndiciesCount as usize); + indices = Vec::from_raw_parts(triangle.m_puIndicies as *mut [u32; 3], (triangle.m_nIndiciesCount / 3) as usize, (triangle.m_nIndiciesCount / 3) as usize); } let mesh = TriMesh::new(positions, indices); @@ -291,7 +293,9 @@ pub unsafe extern "C" fn CRapierPhysics_CreateTriangleMesh( this: *mut RapierPhy { std::ptr::write(&mut (*pShapeMemory).m_sharedShape, SharedShape::new(m)); } - default => {} + default => { + return null_mut(); + } } pShapeMemory }