From c977c02ba3a6ad6ada3f1a458b41a77f2be2b871 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 1 May 2023 21:29:01 +0100 Subject: Refactor InstanceVertices in terms of glContainer --- game/vehicles/railVehicleClass.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index 64a21be..148081f 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -46,26 +46,24 @@ RailVehicleClass::postLoad() void RailVehicleClass::render(const SceneShader & shader) const { - if (const auto count = instancesBody.count()) { + if (const auto count = instancesBody.size()) { if (texture) { texture->bind(); } shader.basicInst.use(); bodyMesh->DrawInstanced(instanceVAO, static_cast(count)); - bogies.front()->DrawInstanced( - instancesBogiesVAO.front(), static_cast(instancesBogies.front().count())); - bogies.back()->DrawInstanced(instancesBogiesVAO.back(), static_cast(instancesBogies.back().count())); + bogies.front()->DrawInstanced(instancesBogiesVAO.front(), static_cast(instancesBogies.front().size())); + bogies.back()->DrawInstanced(instancesBogiesVAO.back(), static_cast(instancesBogies.back().size())); } } void RailVehicleClass::shadows(const ShadowMapper & mapper) const { - if (const auto count = instancesBody.count()) { + if (const auto count = instancesBody.size()) { mapper.dynamicPointInst.use(); bodyMesh->DrawInstanced(instanceVAO, static_cast(count)); - bogies.front()->DrawInstanced( - instancesBogiesVAO.front(), static_cast(instancesBogies.front().count())); - bogies.back()->DrawInstanced(instancesBogiesVAO.back(), static_cast(instancesBogies.back().count())); + bogies.front()->DrawInstanced(instancesBogiesVAO.front(), static_cast(instancesBogies.front().size())); + bogies.back()->DrawInstanced(instancesBogiesVAO.back(), static_cast(instancesBogies.back().size())); } } -- cgit v1.2.3 From 72ab29786f6d4c97a92cb95c75091537490e2d0f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 6 May 2023 16:42:08 +0100 Subject: Templated BufferedLocation and single buffer storage for RVC locations --- game/vehicles/railVehicle.cpp | 11 +++++------ game/vehicles/railVehicle.h | 12 ++++++------ game/vehicles/railVehicleClass.cpp | 23 ++++++++++++----------- game/vehicles/railVehicleClass.h | 8 ++++++-- 4 files changed, 29 insertions(+), 25 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index c4a9e96..2d820b6 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -12,13 +12,12 @@ #include RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : - rvClass {std::move(rvc)}, location {rvClass->instancesBody}, bogies { - rvClass->instancesBogies.front(), - rvClass->instancesBogies.back(), - } + RailVehicleClass::Instance {rvc->instances.acquire()}, rvClass {std::move(rvc)}, location {&LV::body, *this}, + bogies {{ + {&LV::front, *this, glm::vec3 {0, rvClass->wheelBase / 2.F, 0}}, + {&LV::back, *this, glm::vec3 {0, -rvClass->wheelBase / 2.F, 0}}, + }} { - bogies.front().setPosition({0, rvClass->wheelBase / 2.F, 0}); - bogies.back().setPosition({0, -bogies.front().position().y, 0}); } void diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h index 247bf66..f34643e 100644 --- a/game/vehicles/railVehicle.h +++ b/game/vehicles/railVehicle.h @@ -8,12 +8,10 @@ #include #include -class SceneShader; -class ShadowMapper; class Ray; - class Train; -class RailVehicle : Selectable { + +class RailVehicle : Selectable, RailVehicleClass::Instance { public: explicit RailVehicle(RailVehicleClassPtr rvc); @@ -22,7 +20,9 @@ public: [[nodiscard]] bool intersectRay(const Ray &, glm::vec2 *, float *) const override; RailVehicleClassPtr rvClass; - BufferedLocation location; - std::array bogies; + using LV = RailVehicleClass::LocationVertex; + using BLocation = BufferedLocationT; + BLocation location; + std::array bogies; }; using RailVehiclePtr = std::unique_ptr; diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index 148081f..324148c 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -4,6 +4,7 @@ #include "gfx/gl/vertexArrayObject.h" #include "gfx/models/mesh.h" #include "gfx/models/texture.h" +#include "stream_support.h" #include #include #include @@ -34,36 +35,36 @@ void RailVehicleClass::postLoad() { texture = getTexture(); - bodyMesh->configureVAO(instanceVAO).addAttribs(instancesBody.bufferName(), 1); + bodyMesh->configureVAO(instanceVAO).addAttribs(instances.bufferName(), 1); bogies.front() ->configureVAO(instancesBogiesVAO.front()) - .addAttribs(instancesBogies.front().bufferName(), 1); + .addAttribs(instances.bufferName(), 1); bogies.back() ->configureVAO(instancesBogiesVAO.back()) - .addAttribs(instancesBogies.back().bufferName(), 1); + .addAttribs(instances.bufferName(), 1); } void RailVehicleClass::render(const SceneShader & shader) const { - if (const auto count = instancesBody.size()) { + if (const auto count = static_cast(instances.size())) { if (texture) { texture->bind(); } shader.basicInst.use(); - bodyMesh->DrawInstanced(instanceVAO, static_cast(count)); - bogies.front()->DrawInstanced(instancesBogiesVAO.front(), static_cast(instancesBogies.front().size())); - bogies.back()->DrawInstanced(instancesBogiesVAO.back(), static_cast(instancesBogies.back().size())); + bodyMesh->DrawInstanced(instanceVAO, count); + bogies.front()->DrawInstanced(instancesBogiesVAO.front(), count); + bogies.back()->DrawInstanced(instancesBogiesVAO.back(), count); } } void RailVehicleClass::shadows(const ShadowMapper & mapper) const { - if (const auto count = instancesBody.size()) { + if (const auto count = static_cast(instances.size())) { mapper.dynamicPointInst.use(); - bodyMesh->DrawInstanced(instanceVAO, static_cast(count)); - bogies.front()->DrawInstanced(instancesBogiesVAO.front(), static_cast(instancesBogies.front().size())); - bogies.back()->DrawInstanced(instancesBogiesVAO.back(), static_cast(instancesBogies.back().size())); + bodyMesh->DrawInstanced(instanceVAO, count); + bogies.front()->DrawInstanced(instanceVAO, count); + bogies.back()->DrawInstanced(instanceVAO, count); } } diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h index 2fda8f7..80b3fda 100644 --- a/game/vehicles/railVehicleClass.h +++ b/game/vehicles/railVehicleClass.h @@ -18,6 +18,10 @@ public: void render(const SceneShader & shader) const override; void shadows(const ShadowMapper & shadowMapper) const override; + struct LocationVertex { + glm::mat4 body, front, back; + }; + std::array bogies; Mesh::Ptr bodyMesh; std::shared_ptr texture; @@ -25,8 +29,8 @@ public: float length; float maxSpeed; - mutable InstanceVertices instancesBody; - mutable std::array, 2> instancesBogies; + mutable InstanceVertices instances; + using Instance = decltype(instances)::InstanceProxy; protected: friend Persistence::SelectionPtrBase>; -- cgit v1.2.3