From c28e6731ec725705b357996c02c781ac5edebf32 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sat, 22 Sep 2018 18:43:42 +0100 Subject: [PATCH] removed physicsengine from renderer --- WickedEngine/MainComponent.cpp | 8 +++- WickedEngine/MainComponent.h | 6 ++- WickedEngine/wiRenderer.cpp | 85 ---------------------------------- WickedEngine/wiRenderer.h | 3 -- 4 files changed, 11 insertions(+), 91 deletions(-) diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index 8aa77859f..f84878f56 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -14,6 +14,8 @@ #include "wiProfiler.h" #include "wiInitializer.h" #include "wiStartupArguments.h" +#include "wiPHYSICS.h" +#include "wiBULLET.h" #include "wiGraphicsDevice_DX11.h" #include "wiGraphicsDevice_DX12.h" @@ -41,12 +43,16 @@ MainComponent::MainComponent() infoDisplay = InfoDisplayer(); fadeManager.Clear(); + + physicsEngine = new wiBULLET; } MainComponent::~MainComponent() { wiRenderer::GetDevice()->WaitForGPU(); + + SAFE_DELETE(physicsEngine); } void MainComponent::Initialize() @@ -149,7 +155,7 @@ void MainComponent::Run() wiProfiler::GetInstance().EndRange(); // Fixed Update wiProfiler::GetInstance().BeginRange("Physics", wiProfiler::DOMAIN_CPU); - wiRenderer::SynchronizeWithPhysicsEngine((float)elapsedTime); + physicsEngine->Update((float)elapsedTime); wiProfiler::GetInstance().EndRange(); // Physics wiLua::GetGlobal()->SetDeltaTime(elapsedTime); diff --git a/WickedEngine/MainComponent.h b/WickedEngine/MainComponent.h index 398d7655e..9c05e6b75 100644 --- a/WickedEngine/MainComponent.h +++ b/WickedEngine/MainComponent.h @@ -6,7 +6,7 @@ #include "wiWindowRegistration.h" class RenderableComponent; - +class PHYSICS; class MainComponent { @@ -15,7 +15,7 @@ private: bool frameskip; int targetFrameRate; double targetFrameRateInv; - int applicationControlLostThreshold; + int applicationControlLostThreshold; wiFadeManager fadeManager; public: @@ -25,6 +25,8 @@ public: int screenW, screenH; bool fullscreen; + PHYSICS* physicsEngine = nullptr; + // Runs the main engine loop void Run(); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 311c30e4c..57f45f5a2 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -125,7 +125,6 @@ struct VoxelizedSceneData UINT mips = 7; } voxelSceneData; -PHYSICS* physicsEngine = nullptr; wiOcean* ocean = nullptr; Texture2D* shadowMapArray_2D = nullptr; @@ -523,16 +522,11 @@ void CleanUp() SAFE_DELETE(dynamicVertexBufferPool); - if (physicsEngine) physicsEngine->CleanUp(); - SAFE_DELETE(graphicsDevice); } void ClearWorld() { GetDevice()->WaitForGPU(); - - if (physicsEngine) - physicsEngine->ClearWorld(); enviroMap = nullptr; @@ -7785,85 +7779,6 @@ RayIntersectWorldResult RayIntersectWorld(const RAY& ray, UINT renderTypeMask, u return result; } - -void SynchronizeWithPhysicsEngine(float dt) -{ - //if (physicsEngine && GetGameSpeed()) - //{ - // physicsEngine->addWind(GetScene().worldInfo.windDirection); - - // // Update physics world data - // for (Model* model : GetScene().models) - // { - // for (Object* object : model->objects) - // { - // Mesh* mesh = object->mesh; - // int pI = object->physicsObjectID; - - // if (pI < 0 && (object->rigidBody || mesh->softBody)) - // { - // // Register the objects with physics attributes that doesn't exist in the simulation - // physicsEngine->registerObject(object); - // } - - // if (pI >= 0) - // { - // if (mesh->softBody) - // { - // int gvg = mesh->goalVG; - // if (gvg >= 0) - // { - // XMMATRIX worldMat = mesh->hasArmature() ? XMMatrixIdentity() : XMLoadFloat4x4(&object->world); - // int j = 0; - // for (std::map::iterator it = mesh->vertexGroups[gvg].vertices.begin(); it != mesh->vertexGroups[gvg].vertices.end(); ++it) - // { - // int vi = (*it).first; - // MeshComponent::Vertex_FULL tvert = mesh->TransformVertex(vi, worldMat); - // mesh->goalPositions[j] = XMFLOAT3(tvert.pos.x, tvert.pos.y, tvert.pos.z); - // mesh->goalNormals[j] = XMFLOAT3(tvert.nor.x, tvert.nor.y, tvert.nor.z); - // ++j; - // } - // } - // physicsEngine->connectSoftBodyToVertices( - // object->mesh, pI - // ); - // } - // if (object->kinematic && object->rigidBody) - // { - // physicsEngine->transformBody(object->rotation, object->translation, pI); - // } - // } - // } - // } - - // // Run physics simulation - // physicsEngine->Update(dt); - - // // Retrieve physics simulation data - // for (Model* model : GetScene().models) - // { - // for (Object* object : model->objects) { - // int pI = object->physicsObjectID; - // if (pI >= 0 && !object->kinematic && (object->rigidBody || object->mesh->softBody)) { - // PHYSICS::PhysicsTransform* transform(physicsEngine->getObject(pI)); - // object->translation_rest = transform->position; - // object->rotation_rest = transform->rotation; - - // if (object->mesh->softBody) { - // object->scale_rest = XMFLOAT3(1, 1, 1); - // physicsEngine->connectVerticesToSoftBody( - // object->mesh, pI - // ); - // } - // } - // } - // } - - - // physicsEngine->NextRunWorld(); - //} -} - void CreateImpostor(Entity entity, GRAPHICSTHREAD threadID) { GraphicsDevice* device = GetDevice(); diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index cdb6942c8..332a2baeb 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -245,9 +245,6 @@ namespace wiRenderer RayIntersectWorldResult RayIntersectWorld(const RAY& ray, UINT renderTypeMask = RENDERTYPE_OPAQUE, uint32_t layerMask = ~0); - void SynchronizeWithPhysicsEngine(float dt = 1.0f / 60.0f); - - // Add box to render in next frame void AddRenderableBox(const XMFLOAT4X4& boxMatrix, const XMFLOAT4& color = XMFLOAT4(1,1,1,1));