diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-04-07 20:48:14 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-04-07 20:48:14 +0100 |
commit | c2aecdc0d6089a3c41b3d15c45cdb49fee6a45cc (patch) | |
tree | 0bc8c296e89e53c6f0d9d9e9010adf2db2dc3100 | |
parent | More uniform/flexible window constructors (diff) | |
download | ilt-c2aecdc0d6089a3c41b3d15c45cdb49fee6a45cc.tar.bz2 ilt-c2aecdc0d6089a3c41b3d15c45cdb49fee6a45cc.tar.xz ilt-c2aecdc0d6089a3c41b3d15c45cdb49fee6a45cc.zip |
Add Asset interface to create an arbitrarily placed instance
InstanceProxy is returned out via a std::any containing a
std::shared_ptr because any can only contain copyable things.
-rw-r--r-- | assetFactory/asset.cpp | 6 | ||||
-rw-r--r-- | assetFactory/asset.h | 5 | ||||
-rw-r--r-- | game/scenary/foliage.cpp | 10 | ||||
-rw-r--r-- | game/scenary/foliage.h | 2 | ||||
-rw-r--r-- | game/scenary/illuminator.cpp | 10 | ||||
-rw-r--r-- | game/scenary/illuminator.h | 2 | ||||
-rw-r--r-- | game/vehicles/railVehicleClass.cpp | 13 | ||||
-rw-r--r-- | game/vehicles/railVehicleClass.h | 2 |
8 files changed, 50 insertions, 0 deletions
diff --git a/assetFactory/asset.cpp b/assetFactory/asset.cpp index e3f5feb..0254943 100644 --- a/assetFactory/asset.cpp +++ b/assetFactory/asset.cpp @@ -7,6 +7,12 @@ Asset::persist(Persistence::PersistenceStore & store) return STORE_MEMBER(id) && STORE_MEMBER(name); } +std::any +Asset::createAt(const Location &) const +{ + return {}; +} + Asset::TexturePtr Asset::getTexture() const { diff --git a/assetFactory/asset.h b/assetFactory/asset.h index b5de056..061a7c8 100644 --- a/assetFactory/asset.h +++ b/assetFactory/asset.h @@ -2,17 +2,22 @@ #include "factoryMesh.h" #include "persistence.h" +#include <any> #include <manyPtr.h> #include <stdTypeDefs.h> class TextureAtlas; class Renderable; +class Location; class Asset : public Persistence::Persistable, public StdTypeDefs<Asset> { public: using ManyPtr = ManySharedPtr<Asset, const Renderable>; using TexturePtr = std::shared_ptr<TextureAtlas>; + /// Used only for the asset viewer + [[nodiscard]] virtual std::any createAt(const Location &) const; + std::string id; std::string name; diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index 159a078..140c4e5 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -2,6 +2,16 @@ #include "gfx/gl/sceneShader.h" #include "gfx/gl/shadowMapper.h" #include "gfx/gl/vertexArrayObject.h" +#include <location.h> + +static_assert(std::is_constructible_v<Foliage>); + +std::any +Foliage::createAt(const Location & position) const +{ + return std::make_shared<InstanceVertices<LocationVertex>::InstanceProxy>( + instances.acquire(position.getRotationTransform(), position.rot.y, position.pos)); +} bool Foliage::persist(Persistence::PersistenceStore & store) diff --git a/game/scenary/foliage.h b/game/scenary/foliage.h index 71bc734..d15a8b0 100644 --- a/game/scenary/foliage.h +++ b/game/scenary/foliage.h @@ -17,6 +17,8 @@ class Foliage : public Asset, public Renderable, public StdTypeDefs<Foliage> { glVertexArray instancePointVAO; public: + [[nodiscard]] std::any createAt(const Location &) const override; + struct LocationVertex { glm::mat3 rotation; float yaw; diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp index f1a02b2..d8e4c4e 100644 --- a/game/scenary/illuminator.cpp +++ b/game/scenary/illuminator.cpp @@ -2,6 +2,16 @@ #include "gfx/gl/sceneShader.h" #include "gfx/gl/vertexArrayObject.h" #include "gfx/models/texture.h" // IWYU pragma: keep +#include <location.h> + +static_assert(std::is_constructible_v<Illuminator>); + +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) diff --git a/game/scenary/illuminator.h b/game/scenary/illuminator.h index 47ce337..200ba40 100644 --- a/game/scenary/illuminator.h +++ b/game/scenary/illuminator.h @@ -15,6 +15,8 @@ class Illuminator : public Asset, public Renderable, public StdTypeDefs<Illumina std::optional<glVertexArray> instancesSpotLightVAO, instancesPointLightVAO; public: + [[nodiscard]] std::any createAt(const Location &) const override; + struct LightCommonVertex { RelativePosition3D position; RGB colour; diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index 162a29a..21f01c8 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -17,6 +17,19 @@ RailVehicleClass::persist(Persistence::PersistenceStore & store) && STORE_HELPER(bodyMesh, Asset::MeshConstruct) && Asset::persist(store); } +std::any +RailVehicleClass::createAt(const Location & position) const +{ + return std::make_shared<InstanceVertices<LocationVertex>::InstanceProxy>(instances.acquire(LocationVertex { + .body = position.getRotationTransform(), + .front = position.getRotationTransform(), + .back = position.getRotationTransform(), + .bodyPos = position.pos, + .frontPos = {sincos(position.rot.x) * wheelBase * 0.5F, position.pos.z}, + .backPos = {sincos(position.rot.x) * wheelBase * -0.5F, position.pos.z}, + })); +} + void RailVehicleClass::postLoad() { diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h index 6eb4ca5..ccff3e2 100644 --- a/game/vehicles/railVehicleClass.h +++ b/game/vehicles/railVehicleClass.h @@ -17,6 +17,8 @@ public: void render(const SceneShader & shader, const Frustum &) const override; void shadows(const ShadowMapper & shadowMapper, const Frustum &) const override; + [[nodiscard]] std::any createAt(const Location &) const override; + struct LocationVertex { glm::mat3 body, front, back; GlobalPosition3D bodyPos, frontPos, backPos; |