diff options
Diffstat (limited to 'game')
| -rw-r--r-- | game/scenary/foliage.cpp | 28 | ||||
| -rw-r--r-- | game/scenary/foliage.h | 12 | ||||
| -rw-r--r-- | game/scenary/illuminator.cpp | 79 | ||||
| -rw-r--r-- | game/scenary/illuminator.h | 39 | ||||
| -rw-r--r-- | game/scenary/light.cpp | 11 | ||||
| -rw-r--r-- | game/scenary/light.h | 5 | ||||
| -rw-r--r-- | game/scenary/plant.cpp | 2 | ||||
| -rw-r--r-- | game/scenary/plant.h | 2 | ||||
| -rw-r--r-- | game/vehicles/railVehicle.cpp | 49 | ||||
| -rw-r--r-- | game/vehicles/railVehicle.h | 8 | ||||
| -rw-r--r-- | game/vehicles/railVehicleClass.cpp | 25 | ||||
| -rw-r--r-- | game/vehicles/railVehicleClass.h | 11 | ||||
| -rw-r--r-- | game/vehicles/train.cpp | 6 | ||||
| -rw-r--r-- | game/vehicles/train.h | 7 | ||||
| -rw-r--r-- | game/vehicles/vehicle.h | 2 |
15 files changed, 94 insertions, 192 deletions
diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index ff00af4..f27ac26 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -4,6 +4,7 @@ #include "gfx/gl/sceneShader.h" #include "gfx/gl/shadowMapper.h" #include "gfx/gl/shadowStenciller.h" +#include "util.h" #include <location.h> static_assert(std::is_constructible_v<Foliage>); @@ -25,8 +26,8 @@ std::weak_ptr<glVertexArray> Foliage::commonInstanceVAO, Foliage::commonInstance std::any Foliage::createAt(const Location & position) const { - return std::make_shared<InstanceVertices<LocationVertex>::InstanceProxy>( - instances.acquire(position.getRotationTransform(), position.rot.y, position.pos)); + return std::make_shared<InstanceVertices<InstanceVertex>::InstanceProxy>( + instances.acquire(locationData->acquire(position))); } bool @@ -40,14 +41,11 @@ Foliage::postLoad() { texture = getTexture(); glDebugScope _ {0}; - if (!(instanceVAO = commonInstanceVAO.lock())) { - commonInstanceVAO = instanceVAO = std::make_shared<glVertexArray>(); - bodyMesh->configureVAO(*instanceVAO, 0) - .addAttribs<LocationVertex, &LocationVertex::rotation, &LocationVertex::position>(1); + if (createIfRequired(instanceVAO, commonInstanceVAO)) { + bodyMesh->configureVAO(*instanceVAO, 0).addAttribs<InstanceVertex, &InstanceVertex::location>(1); } - if (!(instancePointVAO = commonInstancePointVAO.lock())) { - commonInstancePointVAO = instancePointVAO = std::make_shared<glVertexArray>(); - instancePointVAO->configure().addAttribs<LocationVertex, &LocationVertex::position, &LocationVertex::yaw>(0); + if (createIfRequired(instancePointVAO, commonInstancePointVAO)) { + instancePointVAO->configure().addAttribs<InstanceVertex, &InstanceVertex::location>(0); } const auto & size = bodyMesh->getDimensions().size; billboardSize = billboardTextureSizeForObject(size); @@ -82,14 +80,14 @@ Foliage::preFrame(const Frustum & frustum, const Frustum & lighting) if (instances.size() > 0) { const auto & dims = bodyMesh->getDimensions(); instancePartitions = instances.partition( - [&frustum, &dims](const auto & location) { - return frustum.contains(location.position + dims.centre, dims.size); + [&frustum, &dims](const auto & instance) { + return frustum.contains(instance.location->position.xyz() + dims.centre, dims.size); }, - [&frustum, this](const auto & location) { - return distance(frustum.getPosition(), location.position) < useMeshClipDist; + [&frustum, this](const auto & instance) { + return distance(frustum.getPosition(), instance.location->position.xyz()) < useMeshClipDist; }, - [&lighting, &dims](const auto & location) { - return lighting.contains(location.position + dims.centre, dims.size); + [&lighting, &dims](const auto & instance) { + return lighting.contains(instance.location->position.xyz() + dims.centre, dims.size); }); // In view frustum / Outside view frustum / // Close to view / Far from view / Casts shadow into view / No shadow in view / diff --git a/game/scenary/foliage.h b/game/scenary/foliage.h index c599649..f424ffc 100644 --- a/game/scenary/foliage.h +++ b/game/scenary/foliage.h @@ -18,13 +18,13 @@ class Foliage : public Asset, public Renderable, public StdTypeDefs<Foliage> { public: [[nodiscard]] std::any createAt(const Location &) const override; - struct LocationVertex { - glm::mat3 rotation; - float yaw; - GlobalPosition3D position; + struct InstanceVertex { + CommonLocationInstance location; + // float scale; + // something colorBias; }; - mutable InstanceVertices<LocationVertex> instances; + mutable InstanceVertices<InstanceVertex> instances; void preFrame(const Frustum &, const Frustum &) override; void render(const SceneShader &, const Frustum &) const override; void shadows(const ShadowMapper &, const Frustum &) const override; @@ -43,5 +43,5 @@ protected: glTextures<GL_TEXTURE_2D_ARRAY, 3> billboard; private: - InstanceVertices<Foliage::LocationVertex>::PartitionResult instancePartitions; + InstanceVertices<InstanceVertex>::PartitionResult instancePartitions; }; diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp index 4398853..7f0c7c2 100644 --- a/game/scenary/illuminator.cpp +++ b/game/scenary/illuminator.cpp @@ -1,31 +1,18 @@ #include "illuminator.h" #include "gfx/gl/sceneShader.h" #include "gfx/models/texture.h" // IWYU pragma: keep +#include "util.h" #include <location.h> static_assert(std::is_constructible_v<Illuminator>); -std::weak_ptr<glVertexArray> Illuminator::commonInstanceVAO, Illuminator::commonInstancesSpotLightVAO, - Illuminator::commonInstancesPointLightVAO; +std::weak_ptr<glVertexArray> Illuminator::commonInstanceVAO; std::any Illuminator::createAt(const Location & position) const { - return std::make_shared<InstanceVertices<LocationVertex>::InstanceProxy>( - instances.acquire(position.getRotationTransform(), position.pos)); -} - -bool -Illuminator::SpotLight::persist(Persistence::PersistenceStore & store) -{ - return STORE_TYPE && STORE_MEMBER(position) && STORE_MEMBER(direction) && STORE_MEMBER(colour) && STORE_MEMBER(kq) - && STORE_MEMBER(arc); -} - -bool -Illuminator::PointLight::persist(Persistence::PersistenceStore & store) -{ - return STORE_TYPE && STORE_MEMBER(position) && STORE_MEMBER(colour) && STORE_MEMBER(kq); + return std::make_shared<InstanceVertices<InstanceVertex>::InstanceProxy>( + instances.acquire(locationData->acquire(position))); } bool @@ -44,36 +31,8 @@ Illuminator::postLoad() } texture = getTexture(); glDebugScope _ {0}; - if (!(instanceVAO = commonInstanceVAO.lock())) { - commonInstanceVAO = instanceVAO = std::make_shared<glVertexArray>(); - bodyMesh->configureVAO(*instanceVAO, 0) - .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(1); - } - if (!spotLight.empty()) { - if (!(instancesSpotLightVAO = commonInstancesSpotLightVAO.lock())) { - commonInstancesSpotLightVAO = instancesSpotLightVAO = std::make_shared<glVertexArray>(); - instancesSpotLightVAO->configure() - .addAttribs<SpotLightVertex, &SpotLightVertex::position, &SpotLightVertex::direction, - &SpotLightVertex::colour, &SpotLightVertex::kq, &SpotLightVertex::arc>(0) - .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(1); - } - std::transform( - spotLight.begin(), spotLight.end(), std::back_inserter(spotLightInstances), [this](const auto & s) { - return instancesSpotLight.acquire(*s); - }); - } - if (!pointLight.empty()) { - if (!(instancesPointLightVAO = commonInstancesPointLightVAO.lock())) { - commonInstancesPointLightVAO = instancesPointLightVAO = std::make_shared<glVertexArray>(); - instancesPointLightVAO->configure() - .addAttribs<PointLightVertex, &PointLightVertex::position, &PointLightVertex::colour, - &PointLightVertex::kq>(0) - .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(1); - } - std::transform( - pointLight.begin(), pointLight.end(), std::back_inserter(pointLightInstances), [this](const auto & s) { - return instancesPointLight.acquire(*s); - }); + if (createIfRequired(instanceVAO, commonInstanceVAO)) { + bodyMesh->configureVAO(*instanceVAO, 0).addAttribs<InstanceVertex, &InstanceVertex::location>(1); } } @@ -90,29 +49,3 @@ Illuminator::render(const SceneShader & shader, const Frustum &) const bodyMesh->drawInstanced(*instanceVAO, static_cast<GLsizei>(count)); } } - -void -Illuminator::lights(const SceneShader & shader) const -{ - if (const auto count = instances.size()) { - glDebugScope _ {*instanceVAO}; - if (const auto scount = instancesSpotLight.size()) { - glDebugScope _ {*instancesSpotLightVAO, "Spot lights"}; - shader.spotLightInst.use(); - glBindVertexArray(*instancesSpotLightVAO); - instancesSpotLightVAO->useBuffer(0, instancesSpotLight); - instancesSpotLightVAO->useBuffer(1, instances); - glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(scount), static_cast<GLsizei>(count)); - } - if (const auto pcount = instancesPointLight.size()) { - glDebugScope _ {*instancesPointLightVAO, "Point llights"}; - shader.pointLightInst.use(); - glBindVertexArray(*instancesPointLightVAO); - instancesPointLightVAO->useBuffer(0, instancesPointLight); - instancesPointLightVAO->useBuffer(1, instances); - glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(pcount), static_cast<GLsizei>(count)); - } - - glBindVertexArray(0); - } -} diff --git a/game/scenary/illuminator.h b/game/scenary/illuminator.h index 7b6e7ad..216b536 100644 --- a/game/scenary/illuminator.h +++ b/game/scenary/illuminator.h @@ -1,6 +1,7 @@ #pragma once #include "assetFactory/asset.h" +#include "assetFactory/lights.h" #include "gfx/gl/instanceVertices.h" #include "gfx/models/texture.h" #include "gfx/renderable.h" @@ -11,51 +12,25 @@ class Location; class Illuminator : public Asset, public Renderable, public StdTypeDefs<Illuminator> { Mesh::Ptr bodyMesh; Texture::Ptr texture; - std::shared_ptr<glVertexArray> instanceVAO, instancesSpotLightVAO, instancesPointLightVAO; - static std::weak_ptr<glVertexArray> commonInstanceVAO, commonInstancesSpotLightVAO, commonInstancesPointLightVAO; + std::shared_ptr<glVertexArray> instanceVAO; + static std::weak_ptr<glVertexArray> commonInstanceVAO; public: [[nodiscard]] std::any createAt(const Location &) const override; - struct LightCommonVertex { - RelativePosition3D position; - RGB colour; - RelativeDistance kq; + struct InstanceVertex { + CommonLocationInstance location; }; - struct SpotLightVertex : LightCommonVertex { - Direction3D direction; - Angle arc; - }; - - struct PointLightVertex : LightCommonVertex { }; - - struct SpotLight : Persistence::Persistable, SpotLightVertex, StdTypeDefs<SpotLight> { - private: - friend Persistence::SelectionPtrBase<std::shared_ptr<SpotLight>>; - bool persist(Persistence::PersistenceStore & store) override; - }; - - struct PointLight : Persistence::Persistable, PointLightVertex, StdTypeDefs<PointLight> { - private: - friend Persistence::SelectionPtrBase<std::shared_ptr<PointLight>>; - bool persist(Persistence::PersistenceStore & store) override; - }; - - using LocationVertex = std::pair<glm::mat3, GlobalPosition3D>; - mutable InstanceVertices<LocationVertex> instances; - mutable InstanceVertices<SpotLightVertex> instancesSpotLight; - mutable InstanceVertices<PointLightVertex> instancesPointLight; + mutable InstanceVertices<InstanceVertex> instances; void render(const SceneShader &, const Frustum &) const override; - void lights(const SceneShader &) const override; protected: friend Persistence::SelectionPtrBase<std::shared_ptr<Illuminator>>; bool persist(Persistence::PersistenceStore & store) override; void postLoad() override; +public: std::vector<SpotLight::Ptr> spotLight; std::vector<PointLight::Ptr> pointLight; - std::vector<InstanceVertices<SpotLightVertex>::InstanceProxy> spotLightInstances; - std::vector<InstanceVertices<PointLightVertex>::InstanceProxy> pointLightInstances; }; diff --git a/game/scenary/light.cpp b/game/scenary/light.cpp index 6207497..c51efda 100644 --- a/game/scenary/light.cpp +++ b/game/scenary/light.cpp @@ -2,6 +2,15 @@ #include "location.h" Light::Light(std::shared_ptr<const Illuminator> type, const Location & position) : - type {std::move(type)}, location {this->type->instances.acquire(position.getRotationTransform(), position.pos)} + type {std::move(type)}, + instance {this->type->instances.acquire(Renderable::commonLocationData.lock()->acquire(position))} { + std::ranges::transform(this->type->spotLight, std::back_inserter(spotLightInstances), + [spotLights = Renderable::commonSpotLights.lock(), this](const auto & spotLight) { + return spotLights->acquire(*spotLight, instance->location.index); + }); + std::ranges::transform(this->type->pointLight, std::back_inserter(pointLightInstances), + [pointLights = Renderable::commonPointLights.lock(), this](const auto & pointLight) { + return pointLights->acquire(*pointLight, instance->location.index); + }); } diff --git a/game/scenary/light.h b/game/scenary/light.h index 0b19535..b1ea469 100644 --- a/game/scenary/light.h +++ b/game/scenary/light.h @@ -7,13 +7,16 @@ class Location; class Light : public WorldObject { std::shared_ptr<const Illuminator> type; - InstanceVertices<Illuminator::LocationVertex>::InstanceProxy location; + InstanceVertices<Illuminator::InstanceVertex>::InstanceProxy instance; void tick(TickDuration) override { } + std::vector<InstanceVertices<SpotLightVertex>::InstanceProxy> spotLightInstances; + std::vector<InstanceVertices<PointLightVertex>::InstanceProxy> pointLightInstances; + public: Light(std::shared_ptr<const Illuminator> type, const Location & position); }; diff --git a/game/scenary/plant.cpp b/game/scenary/plant.cpp index 2006225..b0e7d16 100644 --- a/game/scenary/plant.cpp +++ b/game/scenary/plant.cpp @@ -3,6 +3,6 @@ Plant::Plant(std::shared_ptr<const Foliage> type, const Location & position) : type {std::move(type)}, - location {this->type->instances.acquire(position.getRotationTransform(), position.rot.y, position.pos)} + instance {this->type->instances.acquire(Renderable::commonLocationData.lock()->acquire(position))} { } diff --git a/game/scenary/plant.h b/game/scenary/plant.h index 77c9ff7..cc690c5 100644 --- a/game/scenary/plant.h +++ b/game/scenary/plant.h @@ -7,7 +7,7 @@ class Location; class Plant : public WorldObject { std::shared_ptr<const Foliage> type; - InstanceVertices<Foliage::LocationVertex>::InstanceProxy location; + InstanceVertices<Foliage::InstanceVertex>::InstanceProxy instance; void tick(TickDuration) override diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index 61f6c93..c11d817 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -11,24 +11,14 @@ #include <maths.h> #include <ray.h> -RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : - RailVehicleClass::Instance {rvc->instances.acquire()}, rvClass {std::move(rvc)}, - location {[this](const BufferedLocation * l) { - this->get()->body.rotation = l->getRotationTransform(); - this->get()->body.position = l->position(); - }}, - bogies {{ - {[this](const BufferedLocation * l) { - this->get()->front.rotation = l->getRotationTransform(); - this->get()->front.position = l->position(); - }, - GlobalPosition3D {0, rvClass->wheelBase / 2.F, 0}}, - {[this](const BufferedLocation * l) { - this->get()->back.rotation = l->getRotationTransform(); - this->get()->back.position = l->position(); - }, - GlobalPosition3D {0, -rvClass->wheelBase / 2.F, 0}}, - }} +RailVehicle::RailVehicle(RailVehicleClassPtr rvc, GlobalPosition3D position) : + RailVehicleClass::Instance {rvc->instances.acquire( + RailVehicleClass::commonLocationData.lock()->acquire(Location {.pos = position, .rot = {}}), + RailVehicleClass::commonLocationData.lock()->acquire( + Location {.pos = position + RelativePosition3D {0, rvc->wheelBase / 2.F, 0}, .rot = {}}), + RailVehicleClass::commonLocationData.lock()->acquire( + Location {.pos = position + RelativePosition3D {0, -rvc->wheelBase / 2.F, 0}, .rot = {}}))}, + rvClass {std::move(rvc)} { } @@ -36,23 +26,30 @@ void 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(RelativePosition3D(b2Pos.position() - b1Pos.position())); - location.setLocation((b1Pos.position() + b2Pos.position()) / 2, {vector_pitch(diff), vector_yaw(diff), 0}); + const auto & b1Pos = *(get()->front = t->getBogiePosition(t->linkDist, trailBy += overhang)); + const auto & b2Pos = *(get()->back = t->getBogiePosition(t->linkDist, trailBy += rvClass->wheelBase)); + const auto diff = glm::normalize(difference(b1Pos.position, b2Pos.position)); + get()->body = Location { + .pos = midpoint(b1Pos.position, b2Pos.position), .rot = {vector_pitch(diff), vector_yaw(diff), 0}}; trailBy += 600.F + overhang; } +Location +RailVehicle::getLocation() const +{ + return {.pos = get()->body->position, .rot = get()->body->rotation}; +} + bool RailVehicle::intersectRay(const Ray<GlobalPosition3D> & ray, BaryPosition & baryPos, RelativeDistance & distance) const { constexpr const auto X = 1350.F; const auto Y = this->rvClass->length / 2.F; constexpr const auto Z = 3900.F; - const glm::mat3 moveBy = location.getRotationTransform(); - const auto cornerVertices = cuboidCorners(-X, X, -Y, Y, 0.F, Z) * [&moveBy, this](const auto & corner) { - return location.position() + (moveBy * corner); - }; + const auto cornerVertices + = cuboidCorners(-X, X, -Y, Y, 0.F, Z) * [body = this->get()->body.get()](const auto & corner) { + return body->position + (body->rotationMatrix * corner); + }; static constexpr const std::array<glm::vec<3, uint8_t>, 10> triangles {{ // Front {0, 1, 2}, diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h index bf1e782..0f341f9 100644 --- a/game/vehicles/railVehicle.h +++ b/game/vehicles/railVehicle.h @@ -1,8 +1,6 @@ #pragma once -#include "gfx/gl/bufferedLocation.h" #include "railVehicleClass.h" -#include <array> #include <game/selectable.h> #include <glm/glm.hpp> #include <memory> @@ -12,16 +10,14 @@ class Train; class RailVehicle : Selectable, RailVehicleClass::Instance { public: - explicit RailVehicle(RailVehicleClassPtr rvc); + explicit RailVehicle(RailVehicleClassPtr rvc, GlobalPosition3D = {}); void move(const Train *, float & trailBy); + [[nodiscard]] Location getLocation() const; [[nodiscard]] bool intersectRay(const Ray<GlobalPosition3D> &, BaryPosition &, RelativeDistance &) const override; RailVehicleClassPtr rvClass; - using LV = RailVehicleClass::LocationVertex; - BufferedLocationUpdater location; - std::array<BufferedLocationUpdater, 2> bogies; }; using RailVehiclePtr = std::unique_ptr<RailVehicle>; diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index 176fe82..4e9404c 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -7,7 +7,6 @@ #include <location.h> #include <maths.h> #include <memory> -#include <ranges> bool RailVehicleClass::persist(Persistence::PersistenceStore & store) @@ -20,12 +19,10 @@ RailVehicleClass::persist(Persistence::PersistenceStore & store) std::any RailVehicleClass::createAt(const Location & position) const { - return std::make_shared<InstanceVertices<LocationVertex>::InstanceProxy>(instances.acquire(LocationVertex { - .body = {.rotation = position.getRotationTransform(), .position = position.pos}, - .front = {.rotation = position.getRotationTransform(), - .position = {sincos(position.rot.x) * wheelBase * 0.5F, position.pos.z}}, - .back = {.rotation = position.getRotationTransform(), - .position = {sincos(position.rot.x) * wheelBase * -0.5F, position.pos.z}}, + return std::make_shared<InstanceVertices<InstanceVertex>::InstanceProxy>(instances.acquire(InstanceVertex { + .body = locationData->acquire(position), + .front = locationData->acquire(position + ((sincos(position.rot.x) * wheelBase * 0.5F) || 0.F)), + .back = locationData->acquire(position + ((sincos(position.rot.x) * wheelBase * -0.5F) || 0.F)), })); } @@ -34,22 +31,20 @@ RailVehicleClass::postLoad() { texture = getTexture(); glDebugScope _ {0}; - bodyMesh->configureVAO(instanceVAO, 0) - .addAttribs<LocationVertex, &LocationVertex::Part::rotation, &LocationVertex::Part::position>(1); - static_assert(sizeof(LocationVertex) == 144UL); + bodyMesh->configureVAO(instanceVAO, 0).addAttribs<InstanceVertex, &InstanceVertex::body>(1); } void RailVehicleClass::renderAllParts(const size_t count) const { - using PartPair = std::pair<Mesh::Ptr, LocationVertex::Part LocationVertex::*>; + using PartPair = std::pair<Mesh::Ptr, CommonLocationInstance InstanceVertex::*>; const auto bufferName = instances.bufferName(); for (const auto & [mesh, part] : { - PartPair {bodyMesh, &LocationVertex::body}, - PartPair {bogies.front(), &LocationVertex::front}, - PartPair {bogies.back(), &LocationVertex::back}, + PartPair {bodyMesh, &InstanceVertex::body}, + PartPair {bogies.front(), &InstanceVertex::front}, + PartPair {bogies.back(), &InstanceVertex::back}, }) { - instanceVAO.useBuffer<LocationVertex>(1, bufferName, part); + instanceVAO.useBuffer<InstanceVertex>(1, bufferName, part); mesh->drawInstanced(instanceVAO, static_cast<GLsizei>(count)); } } diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h index fe27230..a635122 100644 --- a/game/vehicles/railVehicleClass.h +++ b/game/vehicles/railVehicleClass.h @@ -19,13 +19,8 @@ public: [[nodiscard]] std::any createAt(const Location &) const override; - struct LocationVertex { - struct Part { - glm::mat3 rotation; - GlobalPosition3D position; - }; - - Part body, front, back; + struct InstanceVertex { + CommonLocationInstance body, front, back; }; std::array<Mesh::Ptr, 2> bogies; @@ -35,7 +30,7 @@ public: float length; float maxSpeed; - mutable InstanceVertices<LocationVertex> instances; + mutable InstanceVertices<InstanceVertex> instances; using Instance = decltype(instances)::InstanceProxy; protected: diff --git a/game/vehicles/train.cpp b/game/vehicles/train.cpp index 2461d9c..c79fd17 100644 --- a/game/vehicles/train.cpp +++ b/game/vehicles/train.cpp @@ -21,6 +21,12 @@ Train::getBogiePosition(float linkDist, float dist) const return b2Link.first->positionAt(b2linkDist, b2Link.second); } +Location +Train::getLocation() const +{ + return objects.front()->getLocation(); +} + bool Train::intersectRay(const Ray<GlobalPosition3D> & ray, BaryPosition & baryPos, RelativeDistance & distance) const { diff --git a/game/vehicles/train.h b/game/vehicles/train.h index 88e30f9..9ca53a8 100644 --- a/game/vehicles/train.h +++ b/game/vehicles/train.h @@ -19,12 +19,7 @@ class Train : public Vehicle, public UniqueCollection<RailVehicle>, public Can<G public: explicit Train(const Link::CPtr & link, float linkDist = 0) : Vehicle {link, linkDist} { } - [[nodiscard]] const Location & - getLocation() const override - { - return objects.front()->location; - } - + [[nodiscard]] Location getLocation() const override; [[nodiscard]] bool intersectRay(const Ray<GlobalPosition3D> &, BaryPosition &, RelativeDistance &) const override; void tick(TickDuration elapsed) override; diff --git a/game/vehicles/vehicle.h b/game/vehicles/vehicle.h index c3b35b7..cca8ff0 100644 --- a/game/vehicles/vehicle.h +++ b/game/vehicles/vehicle.h @@ -18,7 +18,7 @@ public: float linkDist; // distance along current link float speed {}; // speed in m/s (~75 km/h) - [[nodiscard]] virtual const Location & getLocation() const = 0; + [[nodiscard]] virtual Location getLocation() const = 0; Orders orders; ActivityPtr currentActivity; |
