improve rendering and physics
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+33
-21
@@ -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<PerMeshData_t> 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);
|
||||
|
||||
Reference in New Issue
Block a user