From 2f8d7643d03f39fa848576692264d0fe3a37ed91 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 6 Nov 2023 20:48:33 +0000 Subject: Reformat with new clang-format --- game/vehicles/railVehicle.h | 1 + game/vehicles/railVehicleClass.h | 1 + game/vehicles/vehicle.h | 1 + 3 files changed, 3 insertions(+) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h index f34643e..be88142 100644 --- a/game/vehicles/railVehicle.h +++ b/game/vehicles/railVehicle.h @@ -25,4 +25,5 @@ public: BLocation location; std::array bogies; }; + using RailVehiclePtr = std::unique_ptr; diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h index 80b3fda..4668d7d 100644 --- a/game/vehicles/railVehicleClass.h +++ b/game/vehicles/railVehicleClass.h @@ -41,4 +41,5 @@ private: glVertexArray instanceVAO; std::array instancesBogiesVAO; }; + using RailVehicleClassPtr = std::shared_ptr; diff --git a/game/vehicles/vehicle.h b/game/vehicles/vehicle.h index 763ade9..354f904 100644 --- a/game/vehicles/vehicle.h +++ b/game/vehicles/vehicle.h @@ -27,4 +27,5 @@ protected: void move(TickDuration dur); LinkHistory linkHist; }; + using VehicleWPtr = std::weak_ptr; -- cgit v1.2.3 From d6e99a696aa582b81018078b68f6600c8030d643 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 7 Nov 2023 02:51:42 +0000 Subject: WIP typedefing all the things - headers --- game/vehicles/railVehicle.h | 2 +- game/vehicles/train.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h index be88142..e034852 100644 --- a/game/vehicles/railVehicle.h +++ b/game/vehicles/railVehicle.h @@ -17,7 +17,7 @@ public: void move(const Train *, float & trailBy); - [[nodiscard]] bool intersectRay(const Ray &, glm::vec2 *, float *) const override; + [[nodiscard]] bool intersectRay(const Ray &, Position2D *, float *) const override; RailVehicleClassPtr rvClass; using LV = RailVehicleClass::LocationVertex; diff --git a/game/vehicles/train.h b/game/vehicles/train.h index 20c3bc4..7f0bb99 100644 --- a/game/vehicles/train.h +++ b/game/vehicles/train.h @@ -27,7 +27,7 @@ public: return objects.front()->location; } - [[nodiscard]] bool intersectRay(const Ray &, glm::vec2 *, float *) const override; + [[nodiscard]] bool intersectRay(const Ray &, Position2D *, float *) const override; void tick(TickDuration elapsed) override; void doActivity(Go *, TickDuration) override; -- cgit v1.2.3 From 9c2c3f71065c94a18c02440111b6ff8ca977b90e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 00:40:40 +0000 Subject: WIP typedefing all the things - sources --- game/vehicles/railVehicle.cpp | 12 ++++++------ game/vehicles/train.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index 2d820b6..fc43995 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -14,8 +14,8 @@ RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : 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}}, + {&LV::front, *this, Position3D {0, rvClass->wheelBase / 2.F, 0}}, + {&LV::back, *this, Position3D {0, -rvClass->wheelBase / 2.F, 0}}, }} { } @@ -32,13 +32,13 @@ RailVehicle::move(const Train * t, float & trailBy) } bool -RailVehicle::intersectRay(const Ray & ray, glm::vec2 * baryPos, float * distance) const +RailVehicle::intersectRay(const Ray & ray, Position2D * baryPos, float * distance) const { constexpr const auto X = 1.35F; const auto Y = this->rvClass->length / 2.F; constexpr const auto Z = 3.9F; const auto moveBy = location.getTransform(); - const std::array cornerVertices {{ + const std::array cornerVertices {{ moveBy * glm::vec4 {-X, Y, 0, 1}, // LFB moveBy * glm::vec4 {X, Y, 0, 1}, // RFB moveBy * glm::vec4 {-X, Y, Z, 1}, // LFT @@ -48,7 +48,7 @@ RailVehicle::intersectRay(const Ray & ray, glm::vec2 * baryPos, float * distance moveBy * glm::vec4 {-X, -Y, Z, 1}, // LBT moveBy * glm::vec4 {X, -Y, Z, 1}, // RBT }}; - static constexpr const std::array triangles {{ + static constexpr const std::array, 10> triangles {{ // Front {0, 1, 2}, {1, 2, 3}, @@ -66,7 +66,7 @@ RailVehicle::intersectRay(const Ray & ray, glm::vec2 * baryPos, float * distance {3, 6, 7}, }}; return std::any_of( - triangles.begin(), triangles.end(), [&cornerVertices, &ray, &baryPos, &distance](const glm::uvec3 idx) { + triangles.begin(), triangles.end(), [&cornerVertices, &ray, &baryPos, &distance](const auto & idx) { return glm::intersectRayTriangle(ray.start, ray.direction, cornerVertices[idx[0]], cornerVertices[idx[1]], cornerVertices[idx[2]], *baryPos, *distance); }); diff --git a/game/vehicles/train.cpp b/game/vehicles/train.cpp index 6f3b036..4aa24dc 100644 --- a/game/vehicles/train.cpp +++ b/game/vehicles/train.cpp @@ -20,7 +20,7 @@ Train::getBogiePosition(float linkDist, float dist) const } bool -Train::intersectRay(const Ray & ray, glm::vec2 * baryPos, float * distance) const +Train::intersectRay(const Ray & ray, Position2D * baryPos, float * distance) const { return applyOne(&RailVehicle::intersectRay, ray, baryPos, distance) != end(); } -- cgit v1.2.3 From 5e25d79beef19c39537b0f15982a175fec45bb3e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 11 Nov 2023 17:37:57 +0000 Subject: Refactor BufferedLocationT to use a callback Simplifies customisation in the face of multiple fields --- game/vehicles/railVehicle.cpp | 15 ++++++++++++--- game/vehicles/railVehicle.h | 5 ++--- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index fc43995..1ed904d 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -12,10 +12,19 @@ #include RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : - RailVehicleClass::Instance {rvc->instances.acquire()}, rvClass {std::move(rvc)}, location {&LV::body, *this}, + RailVehicleClass::Instance {rvc->instances.acquire()}, rvClass {std::move(rvc)}, + location {[this](const BufferedLocation * l) { + this->get()->body = l->getTransform(); + }}, bogies {{ - {&LV::front, *this, Position3D {0, rvClass->wheelBase / 2.F, 0}}, - {&LV::back, *this, Position3D {0, -rvClass->wheelBase / 2.F, 0}}, + {[this](const BufferedLocation * l) { + this->get()->front = l->getTransform(); + }, + Position3D {0, rvClass->wheelBase / 2.F, 0}}, + {[this](const BufferedLocation * l) { + this->get()->back = l->getTransform(); + }, + Position3D {0, -rvClass->wheelBase / 2.F, 0}}, }} { } diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h index e034852..20d1ea1 100644 --- a/game/vehicles/railVehicle.h +++ b/game/vehicles/railVehicle.h @@ -21,9 +21,8 @@ public: RailVehicleClassPtr rvClass; using LV = RailVehicleClass::LocationVertex; - using BLocation = BufferedLocationT; - BLocation location; - std::array bogies; + BufferedLocationUpdater location; + std::array bogies; }; using RailVehiclePtr = std::unique_ptr; -- cgit v1.2.3 From 356e874050e5ad5af87b04a2bb01ce34a86640bb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 13 Nov 2023 00:17:11 +0000 Subject: Send position and rotation matrix to GPU separately --- game/vehicles/railVehicle.cpp | 9 ++++++--- game/vehicles/railVehicleClass.cpp | 8 +++++--- game/vehicles/railVehicleClass.h | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index 1ed904d..6e6e18f 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -14,15 +14,18 @@ RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : RailVehicleClass::Instance {rvc->instances.acquire()}, rvClass {std::move(rvc)}, location {[this](const BufferedLocation * l) { - this->get()->body = l->getTransform(); + this->get()->body = l->getRotationTransform(); + this->get()->bodyPos = l->position(); }}, bogies {{ {[this](const BufferedLocation * l) { - this->get()->front = l->getTransform(); + this->get()->front = l->getRotationTransform(); + this->get()->frontPos = l->position(); }, Position3D {0, rvClass->wheelBase / 2.F, 0}}, {[this](const BufferedLocation * l) { - this->get()->back = l->getTransform(); + this->get()->back = l->getRotationTransform(); + this->get()->backPos = l->position(); }, Position3D {0, -rvClass->wheelBase / 2.F, 0}}, }} diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index 324148c..7a6a9fe 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -35,13 +35,15 @@ void RailVehicleClass::postLoad() { texture = getTexture(); - bodyMesh->configureVAO(instanceVAO).addAttribs(instances.bufferName(), 1); + bodyMesh->configureVAO(instanceVAO) + .addAttribs(instances.bufferName(), 1); bogies.front() ->configureVAO(instancesBogiesVAO.front()) - .addAttribs(instances.bufferName(), 1); + .addAttribs(instances.bufferName(), 1); bogies.back() ->configureVAO(instancesBogiesVAO.back()) - .addAttribs(instances.bufferName(), 1); + .addAttribs(instances.bufferName(), 1); + static_assert(sizeof(LocationVertex) == 228UL); } void diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h index 4668d7d..16dce01 100644 --- a/game/vehicles/railVehicleClass.h +++ b/game/vehicles/railVehicleClass.h @@ -20,6 +20,7 @@ public: struct LocationVertex { glm::mat4 body, front, back; + Position3D bodyPos, frontPos, backPos; }; std::array bogies; -- cgit v1.2.3 From 685b33980cc7a346574b24732464f0cbe3115a1f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Nov 2023 01:29:24 +0000 Subject: Switch to millimeters for spatial units Mostly a case of changing far too many magic numbers, something else to fix I guess. I probably missed something. Also there's some hackery when loading 3D models, which are still assumed to be in metres. --- game/vehicles/linkHistory.cpp | 2 +- game/vehicles/railVehicle.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/linkHistory.cpp b/game/vehicles/linkHistory.cpp index 2802109..e6bab36 100644 --- a/game/vehicles/linkHistory.cpp +++ b/game/vehicles/linkHistory.cpp @@ -8,7 +8,7 @@ LinkHistory::add(const Link::WPtr & l, unsigned char d) links.insert(links.begin(), {l, d}); const auto lp = l.lock(); totalLen += lp->length; - while (totalLen >= 1000.F && !links.empty()) { + while (totalLen >= 1000000.F && !links.empty()) { totalLen -= links.back().first.lock()->length; links.pop_back(); } diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index 6e6e18f..26536f5 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -46,9 +46,9 @@ RailVehicle::move(const Train * t, float & trailBy) bool RailVehicle::intersectRay(const Ray & ray, Position2D * baryPos, float * distance) const { - constexpr const auto X = 1.35F; + constexpr const auto X = 1350.F; const auto Y = this->rvClass->length / 2.F; - constexpr const auto Z = 3.9F; + constexpr const auto Z = 3900.F; const auto moveBy = location.getTransform(); const std::array cornerVertices {{ moveBy * glm::vec4 {-X, Y, 0, 1}, // LFB -- cgit v1.2.3 From 3200eb41d60595813dca751fe15193ba0b44dddf Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 Nov 2023 14:32:56 +0000 Subject: Remove getTransform --- game/vehicles/railVehicle.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index 26536f5..bee0dd0 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -49,16 +49,16 @@ RailVehicle::intersectRay(const Ray & ray, Position2D * baryPos, float * distanc constexpr const auto X = 1350.F; const auto Y = this->rvClass->length / 2.F; constexpr const auto Z = 3900.F; - const auto moveBy = location.getTransform(); + const auto moveBy = location.getRotationTransform(); const std::array cornerVertices {{ - moveBy * glm::vec4 {-X, Y, 0, 1}, // LFB - moveBy * glm::vec4 {X, Y, 0, 1}, // RFB - moveBy * glm::vec4 {-X, Y, Z, 1}, // LFT - moveBy * glm::vec4 {X, Y, Z, 1}, // RFT - moveBy * glm::vec4 {-X, -Y, 0, 1}, // LBB - moveBy * glm::vec4 {X, -Y, 0, 1}, // RBB - moveBy * glm::vec4 {-X, -Y, Z, 1}, // LBT - moveBy * glm::vec4 {X, -Y, Z, 1}, // RBT + location.position() + (moveBy * glm::vec4 {-X, Y, 0, 1}).xyz(), // LFB + location.position() + (moveBy * glm::vec4 {X, Y, 0, 1}).xyz(), // RFB + location.position() + (moveBy * glm::vec4 {-X, Y, Z, 1}).xyz(), // LFT + location.position() + (moveBy * glm::vec4 {X, Y, Z, 1}).xyz(), // RFT + location.position() + (moveBy * glm::vec4 {-X, -Y, 0, 1}).xyz(), // LBB + location.position() + (moveBy * glm::vec4 {X, -Y, 0, 1}).xyz(), // RBB + location.position() + (moveBy * glm::vec4 {-X, -Y, Z, 1}).xyz(), // LBT + location.position() + (moveBy * glm::vec4 {X, -Y, Z, 1}).xyz(), // RBT }}; static constexpr const std::array, 10> triangles {{ // Front -- cgit v1.2.3 From 0aa665c3648d788755b00c9e431c872d57fddbb8 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 Nov 2023 16:28:39 +0000 Subject: Model positions as integers Introduces test failure in arcs due to rounding, but I don't want to create a complicated fix as link positions are still floats and hopefully that'll go away... somehow --- game/vehicles/railVehicle.cpp | 22 +++++++++++----------- game/vehicles/railVehicleClass.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index bee0dd0..30b615c 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -38,9 +38,9 @@ RailVehicle::move(const Train * t, float & trailBy) const auto overhang {(rvClass->length - rvClass->wheelBase) / 2}; const auto & b1Pos = bogies[0] = t->getBogiePosition(t->linkDist, trailBy += overhang); const auto & b2Pos = bogies[1] = t->getBogiePosition(t->linkDist, trailBy += rvClass->wheelBase); - const auto diff = glm::normalize(b2Pos.position() - b1Pos.position()); - location.setLocation((b1Pos.position() + b2Pos.position()) / 2.F, {vector_pitch(diff), vector_yaw(diff), 0}); - trailBy += 0.6F + overhang; + const auto diff = glm::normalize(RelativePosition3D(b2Pos.position() - b1Pos.position())); + location.setLocation((b1Pos.position() + b2Pos.position()) / 2, {vector_pitch(diff), vector_yaw(diff), 0}); + trailBy += 600.F + overhang; } bool @@ -51,14 +51,14 @@ RailVehicle::intersectRay(const Ray & ray, Position2D * baryPos, float * distanc constexpr const auto Z = 3900.F; const auto moveBy = location.getRotationTransform(); const std::array cornerVertices {{ - location.position() + (moveBy * glm::vec4 {-X, Y, 0, 1}).xyz(), // LFB - location.position() + (moveBy * glm::vec4 {X, Y, 0, 1}).xyz(), // RFB - location.position() + (moveBy * glm::vec4 {-X, Y, Z, 1}).xyz(), // LFT - location.position() + (moveBy * glm::vec4 {X, Y, Z, 1}).xyz(), // RFT - location.position() + (moveBy * glm::vec4 {-X, -Y, 0, 1}).xyz(), // LBB - location.position() + (moveBy * glm::vec4 {X, -Y, 0, 1}).xyz(), // RBB - location.position() + (moveBy * glm::vec4 {-X, -Y, Z, 1}).xyz(), // LBT - location.position() + (moveBy * glm::vec4 {X, -Y, Z, 1}).xyz(), // RBT + location.position() + GlobalPosition3D(moveBy * glm::vec4 {-X, Y, 0, 1}).xyz(), // LFB + location.position() + GlobalPosition3D(moveBy * glm::vec4 {X, Y, 0, 1}).xyz(), // RFB + location.position() + GlobalPosition3D(moveBy * glm::vec4 {-X, Y, Z, 1}).xyz(), // LFT + location.position() + GlobalPosition3D(moveBy * glm::vec4 {X, Y, Z, 1}).xyz(), // RFT + location.position() + GlobalPosition3D(moveBy * glm::vec4 {-X, -Y, 0, 1}).xyz(), // LBB + location.position() + GlobalPosition3D(moveBy * glm::vec4 {X, -Y, 0, 1}).xyz(), // RBB + location.position() + GlobalPosition3D(moveBy * glm::vec4 {-X, -Y, Z, 1}).xyz(), // LBT + location.position() + GlobalPosition3D(moveBy * glm::vec4 {X, -Y, Z, 1}).xyz(), // RBT }}; static constexpr const std::array, 10> triangles {{ // Front diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h index 16dce01..913feea 100644 --- a/game/vehicles/railVehicleClass.h +++ b/game/vehicles/railVehicleClass.h @@ -20,7 +20,7 @@ public: struct LocationVertex { glm::mat4 body, front, back; - Position3D bodyPos, frontPos, backPos; + GlobalPosition3D bodyPos, frontPos, backPos; }; std::array bogies; -- cgit v1.2.3