summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
-rw-r--r--Jamroot.jam1
-rw-r--r--application/main.cpp11
-rw-r--r--assetFactory/asset.h3
-rw-r--r--assetFactory/assetFactory.cpp3
-rw-r--r--assetFactory/assetFactory.h2
-rw-r--r--config/types.h1
-rw-r--r--game/gamestate.h3
-rw-r--r--game/network/network.h2
-rw-r--r--game/network/network.impl.h8
-rw-r--r--game/network/rail.cpp4
-rw-r--r--game/orders.h2
-rw-r--r--game/vehicles/train.h2
-rw-r--r--game/water.h2
-rw-r--r--gfx/gl/shaders/uiShader.fs11
-rw-r--r--gfx/gl/shaders/uiShader.vs13
-rw-r--r--gfx/gl/shaders/uiShaderFont.fs12
-rw-r--r--gfx/gl/shadowMapper.cpp2
-rw-r--r--gfx/gl/uiShader.cpp27
-rw-r--r--gfx/gl/uiShader.h47
-rw-r--r--lib/collection.h263
-rw-r--r--lib/glArrays.h26
-rw-r--r--lib/manyPtr.h86
-rw-r--r--lib/persistence.h3
-rw-r--r--res/ui/icon/magnifier.svg50
-rw-r--r--res/ui/icon/network.pngbin16793 -> 0 bytes
-rw-r--r--res/ui/icon/rails.svg36
-rw-r--r--res/ui/icon/road.svg27
-rw-r--r--test/Jamfile.jam1
-rw-r--r--test/test-assetFactory.cpp24
-rw-r--r--test/test-collection.cpp287
-rw-r--r--test/test-lib.cpp4
-rw-r--r--test/test-network.cpp68
-rw-r--r--test/test-render.cpp13
-rw-r--r--test/test-text.cpp14
-rw-r--r--test/test-ui.cpp20
-rw-r--r--thirdparty/Jamfile.jam12
m---------thirdparty/imgui0
m---------thirdparty/lunasvg0
-rw-r--r--ui/builders/freeExtend.cpp8
-rw-r--r--ui/builders/join.cpp6
-rw-r--r--ui/builders/straight.cpp8
-rw-r--r--ui/editNetwork.cpp38
-rw-r--r--ui/editNetwork.h11
-rw-r--r--ui/gameMainSelector.cpp52
-rw-r--r--ui/gameMainSelector.h15
-rw-r--r--ui/gameMainWindow.cpp64
-rw-r--r--ui/icon.cpp9
-rw-r--r--ui/icon.h3
-rw-r--r--ui/iconButton.cpp57
-rw-r--r--ui/iconButton.h26
-rw-r--r--ui/imgui_extras.cpp33
-rw-r--r--ui/imgui_extras.h10
-rw-r--r--ui/imgui_wrap.h7
-rw-r--r--ui/mainApplication.h2
-rw-r--r--ui/manualCameraController.cpp4
-rw-r--r--ui/manualCameraController.h7
-rw-r--r--ui/modeHelper.h40
-rw-r--r--ui/queryTool.cpp42
-rw-r--r--ui/queryTool.h17
-rw-r--r--ui/svgIcon.cpp34
-rw-r--r--ui/svgIcon.h18
-rw-r--r--ui/text.cpp73
-rw-r--r--ui/text.h34
-rw-r--r--ui/toolbar.cpp35
-rw-r--r--ui/toolbar.h23
-rw-r--r--ui/uiComponent.cpp33
-rw-r--r--ui/uiComponent.h20
-rw-r--r--ui/uiComponentPlacer.cpp27
-rw-r--r--ui/uiComponentPlacer.h19
-rw-r--r--ui/windowContent.cpp4
-rw-r--r--ui/windowContent.h8
72 files changed, 1128 insertions, 752 deletions
diff --git a/.gitmodules b/.gitmodules
index 63a1a38..b5aa2c7 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -7,3 +7,6 @@
[submodule "thirdparty/imgui"]
path = thirdparty/imgui
url = https://github.com/ocornut/imgui
+[submodule "thirdparty/lunasvg"]
+ path = thirdparty/lunasvg
+ url = https://github.com/sammycage/lunasvg
diff --git a/Jamroot.jam b/Jamroot.jam
index 8587aaa..9b589cf 100644
--- a/Jamroot.jam
+++ b/Jamroot.jam
@@ -92,7 +92,6 @@ lib ilt :
<library>thirdparty/<variant>release
<implicit-dependency>thirdparty
<library>sdl2
- <library>thirdparty//imguisdl2
<library>freetype2
<library>glib-2.0
<library>mxml
diff --git a/application/main.cpp b/application/main.cpp
index 723f3d2..9120376 100644
--- a/application/main.cpp
+++ b/application/main.cpp
@@ -86,11 +86,11 @@ public:
}
const std::shared_ptr<Train> train = world.create<Train>(l3, 800000);
- auto b47 = std::dynamic_pointer_cast<RailVehicleClass>(assets.at("brush-47"));
+ auto b47 = assets.at("brush-47").dynamicCast<RailVehicleClass>();
for (int N = 0; N < 6; N++) {
train->create<RailVehicle>(b47);
}
- train->orders.removeAll();
+ train->orders.clear();
train->orders.create<FreeRoam>(&train->orders);
train->currentActivity = train->orders.current()->createActivity();
@@ -101,8 +101,9 @@ public:
std::uniform_int_distribution<int> treeVariantDistribution {1, 4};
for (auto x = 311000000; x < 311830000; x += 5000) {
for (auto y = 491100000; y < 491130000; y += 5000) {
- world.create<Plant>(std::dynamic_pointer_cast<Foliage>(assets.at(std::format("Tree-{:#02}-{}",
- treeDistribution(randomdev), treeVariantDistribution(randomdev)))),
+ world.create<Plant>(assets.at(std::format("Tree-{:#02}-{}", treeDistribution(randomdev),
+ treeVariantDistribution(randomdev)))
+ .dynamicCast<Foliage>(),
Location {terrain->positionAt({{x + positionOffsetDistribution(randomdev),
y + positionOffsetDistribution(randomdev)}}),
{0, rotationDistribution(randomdev), 0}});
@@ -112,7 +113,7 @@ public:
mainLoop();
- world.objects.clear();
+ world.clear();
return 0;
}
};
diff --git a/assetFactory/asset.h b/assetFactory/asset.h
index 5bdd2f2..b5de056 100644
--- a/assetFactory/asset.h
+++ b/assetFactory/asset.h
@@ -2,12 +2,15 @@
#include "factoryMesh.h"
#include "persistence.h"
+#include <manyPtr.h>
#include <stdTypeDefs.h>
class TextureAtlas;
+class Renderable;
class Asset : public Persistence::Persistable, public StdTypeDefs<Asset> {
public:
+ using ManyPtr = ManySharedPtr<Asset, const Renderable>;
using TexturePtr = std::shared_ptr<TextureAtlas>;
std::string id;
diff --git a/assetFactory/assetFactory.cpp b/assetFactory/assetFactory.cpp
index 176e1f5..426fecc 100644
--- a/assetFactory/assetFactory.cpp
+++ b/assetFactory/assetFactory.cpp
@@ -5,6 +5,7 @@
#include "filesystem.h"
#include "gfx/image.h"
#include "gfx/models/texture.h"
+#include "gfx/renderable.h"
#include "object.h"
#include "plane.h"
#include "saxParse-persistence.h"
@@ -146,7 +147,7 @@ bool
AssetFactory::persist(Persistence::PersistenceStore & store)
{
using MapObjects = Persistence::MapByMember<Shapes, std::shared_ptr<Object>>;
- using MapAssets = Persistence::MapByMember<Assets>;
+ using MapAssets = Persistence::MapByMember<Assets, Asset::Ptr>;
using MapTextureFragments = Persistence::MapByMember<TextureFragments>;
using MapAssImp = Persistence::MapByMember<AssImps, std::shared_ptr<AssImp>, &AssImp::path>;
return STORE_TYPE && STORE_NAME_HELPER("object", shapes, MapObjects)
diff --git a/assetFactory/assetFactory.h b/assetFactory/assetFactory.h
index 787f0a4..864e882 100644
--- a/assetFactory/assetFactory.h
+++ b/assetFactory/assetFactory.h
@@ -12,7 +12,7 @@ class Texture;
class AssetFactory : public Persistence::Persistable {
public:
using Shapes = std::map<std::string, Shape::Ptr, std::less<>>;
- using Assets = std::map<std::string, Asset::Ptr, std::less<>>;
+ using Assets = std::map<std::string, Asset::ManyPtr, std::less<>>;
using AssImps = std::map<std::string, AssImp::Ptr, std::less<>>;
using TextureFragments = std::map<std::string, TextureFragment::Ptr, std::less<>>;
using Colour = RGB;
diff --git a/config/types.h b/config/types.h
index c501f41..06825b5 100644
--- a/config/types.h
+++ b/config/types.h
@@ -42,6 +42,7 @@ using Normal3D = Normal<3>;
using Rotation2D = Rotation<2>;
using Rotation3D = Rotation<3>;
using TextureRelCoord = glm::vec<2, float>;
+using ImageDimensions = glm::vec<2, GLsizei>;
using TextureDimensions = glm::vec<3, GLsizei>;
using TextureRelRegion = glm::vec<4, float>;
using TextureAbsCoord = glm::vec<2, GLsizei>;
diff --git a/game/gamestate.h b/game/gamestate.h
index 189417d..85cb5db 100644
--- a/game/gamestate.h
+++ b/game/gamestate.h
@@ -8,6 +8,7 @@
class WorldObject;
class Terrain;
class Environment;
+class Renderable;
class GameState {
public:
@@ -16,7 +17,7 @@ public:
NO_MOVE(GameState);
NO_COPY(GameState);
- Collection<WorldObject> world;
+ SharedCollection<WorldObject, Renderable> world;
std::shared_ptr<Terrain> terrain;
std::shared_ptr<Environment> environment;
AssetFactory::Assets assets;
diff --git a/game/network/network.h b/game/network/network.h
index 291c4ec..73c3788 100644
--- a/game/network/network.h
+++ b/game/network/network.h
@@ -77,7 +77,7 @@ class NetworkOf : public Network, public Renderable, public NetworkLinkHolder<Li
protected:
using Network::Network;
- Collection<T> links;
+ SharedCollection<T> links;
void joinLinks(const Link::Ptr &) const;
protected:
diff --git a/game/network/network.impl.h b/game/network/network.impl.h
index 0a2f9ca..294f696 100644
--- a/game/network/network.impl.h
+++ b/game/network/network.impl.h
@@ -8,7 +8,7 @@ template<typename T, typename... Links>
void
NetworkOf<T, Links...>::joinLinks(const Link::Ptr & l) const
{
- for (const auto & ol : links.objects) {
+ for (const auto & ol : links) {
Network::joinLinks(l, ol);
}
}
@@ -18,11 +18,11 @@ Link::Ptr
NetworkOf<T, Links...>::intersectRayLinks(const Ray<GlobalPosition3D> & ray) const
{
// Click link
- if (const auto link = std::find_if(links.objects.begin(), links.objects.end(),
+ if (const auto link = std::find_if(links.begin(), links.end(),
[&ray](const std::shared_ptr<T> & link) {
return link->intersectRay(ray);
});
- link != links.objects.end()) {
+ link != links.end()) {
return *link;
}
return {};
@@ -32,7 +32,7 @@ template<typename T, typename... Links>
float
NetworkOf<T, Links...>::findNodeDirection(Node::AnyCPtr n) const
{
- for (const auto & l : links.objects) {
+ for (const auto & l : links) {
for (const auto & e : l->ends) {
// cppcheck-suppress useStlAlgorithm
if (e.node.get() == n.get()) {
diff --git a/game/network/rail.cpp b/game/network/rail.cpp
index 2a18b9a..dfe1dca 100644
--- a/game/network/rail.cpp
+++ b/game/network/rail.cpp
@@ -168,7 +168,7 @@ namespace {
void
RailLinks::render(const SceneShader & shader, const Frustum &) const
{
- if (!links.objects.empty()) {
+ if (!links.empty()) {
texture->bind();
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(-1, 0);
@@ -182,7 +182,7 @@ RailLinks::render(const SceneShader & shader, const Frustum &) const
const Surface *
RailLinks::getBaseSurface() const
{
- return std::dynamic_pointer_cast<Surface>(gameState->assets.at("terrain.surface.gravel")).get();
+ return gameState->assets.at("terrain.surface.gravel").dynamicCast<const Surface>().get();
}
RelativeDistance
diff --git a/game/orders.h b/game/orders.h
index ca5cfdb..840aa3c 100644
--- a/game/orders.h
+++ b/game/orders.h
@@ -5,7 +5,7 @@
class Objective;
-class Orders : public Collection<Objective> {
+class Orders : public SharedCollection<Objective> {
public:
[[nodiscard]] Objective * current() const;
Objective * next();
diff --git a/game/vehicles/train.h b/game/vehicles/train.h
index 4933347..88e30f9 100644
--- a/game/vehicles/train.h
+++ b/game/vehicles/train.h
@@ -15,7 +15,7 @@ class SceneShader;
class ShadowMapper;
template<typename> class Ray;
-class Train : public Vehicle, public Collection<RailVehicle, false>, public Can<Go>, public Can<Idle> {
+class Train : public Vehicle, public UniqueCollection<RailVehicle>, public Can<Go>, public Can<Idle> {
public:
explicit Train(const Link::CPtr & link, float linkDist = 0) : Vehicle {link, linkDist} { }
diff --git a/game/water.h b/game/water.h
index f9fe080..07d9ae1 100644
--- a/game/water.h
+++ b/game/water.h
@@ -29,6 +29,6 @@ private:
void generateMeshes();
std::shared_ptr<GeoData> geoData;
- Collection<MeshT<Vertex>, false> meshes;
+ UniqueCollection<MeshT<Vertex>> meshes;
Texture::Ptr water;
};
diff --git a/gfx/gl/shaders/uiShader.fs b/gfx/gl/shaders/uiShader.fs
deleted file mode 100644
index c5f4e92..0000000
--- a/gfx/gl/shaders/uiShader.fs
+++ /dev/null
@@ -1,11 +0,0 @@
-#version 330 core
-
-in vec2 texCoord0;
-
-uniform sampler2D sampler;
-
-void
-main()
-{
- gl_FragColor = texture(sampler, texCoord0);
-}
diff --git a/gfx/gl/shaders/uiShader.vs b/gfx/gl/shaders/uiShader.vs
deleted file mode 100644
index e9e4373..0000000
--- a/gfx/gl/shaders/uiShader.vs
+++ /dev/null
@@ -1,13 +0,0 @@
-#version 330 core
-
-in vec4 position;
-
-out vec2 texCoord0;
-uniform mat4 uiProjection;
-
-void
-main()
-{
- gl_Position = uiProjection * vec4(position.xy, 0.0, 1.0);
- texCoord0 = position.zw;
-}
diff --git a/gfx/gl/shaders/uiShaderFont.fs b/gfx/gl/shaders/uiShaderFont.fs
deleted file mode 100644
index a1ef6ef..0000000
--- a/gfx/gl/shaders/uiShaderFont.fs
+++ /dev/null
@@ -1,12 +0,0 @@
-#version 330 core
-
-in vec2 texCoord0;
-
-uniform sampler2D sampler;
-uniform vec3 colour;
-
-void
-main()
-{
- gl_FragColor = vec4(colour, texture(sampler, texCoord0).r);
-}
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index 6525f76..3cb73f7 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -88,7 +88,7 @@ ShadowMapper::update(const SceneProvider & scene, const LightDirection & dir, co
shadowStenciller.setLightDirection(dir);
for (const auto & [id, asset] : gameState->assets) {
- if (const auto r = std::dynamic_pointer_cast<const Renderable>(asset)) {
+ if (const auto r = asset.getAs<const Renderable>()) {
r->updateStencil(shadowStenciller);
}
}
diff --git a/gfx/gl/uiShader.cpp b/gfx/gl/uiShader.cpp
deleted file mode 100644
index 23da9dc..0000000
--- a/gfx/gl/uiShader.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "uiShader.h"
-#include "gl_traits.h"
-#include <gfx/gl/program.h>
-#include <gfx/gl/shader.h>
-#include <gfx/gl/shaders/fs-uiShader.h>
-#include <gfx/gl/shaders/fs-uiShaderFont.h>
-#include <gfx/gl/shaders/vs-uiShader.h>
-#include <glm/glm.hpp>
-#include <glm/gtc/type_ptr.hpp>
-
-UIShader::IconProgram::IconProgram(const glm::mat4 & vp) : UIProgram {vp, uiShader_vs, uiShader_fs} { }
-
-UIShader::TextProgram::TextProgram(const glm::mat4 & vp) : UIProgram {vp, uiShader_vs, uiShaderFont_fs} { }
-
-UIShader::UIShader(size_t width, size_t height) :
- UIShader {glm::ortho<float>(0, static_cast<float>(width), 0, static_cast<float>(height))}
-{
-}
-
-UIShader::UIShader(const glm::mat4 & viewProjection) : icon {viewProjection}, text {viewProjection} { }
-
-void
-UIShader::TextProgram::use(const RGB & colour) const
-{
- Program::use();
- glUniform(colorLoc, colour);
-}
diff --git a/gfx/gl/uiShader.h b/gfx/gl/uiShader.h
deleted file mode 100644
index 6d00166..0000000
--- a/gfx/gl/uiShader.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#pragma once
-
-#include "config/types.h"
-#include "gl_traits.h"
-#include "program.h"
-#include <cstddef>
-#include <glad/gl.h>
-#include <glm/glm.hpp>
-#include <glm/gtc/type_ptr.hpp>
-
-class UIShader {
-public:
- UIShader(std::size_t width, std::size_t height);
-
-private:
- explicit UIShader(const glm::mat4 & viewProjection);
-
- class UIProgram : public Program {
- public:
- template<typename... S>
- explicit UIProgram(const glm::mat4 & vp, S &&... srcs) : Program {std::forward<S>(srcs)...}
- {
- const RequiredUniformLocation uiProjectionLoc {*this, "uiProjection"};
- glUseProgram(*this);
- glUniform(uiProjectionLoc, vp);
- }
- };
-
- class IconProgram : public UIProgram {
- public:
- explicit IconProgram(const glm::mat4 & vp);
- using Program::use;
- };
-
- class TextProgram : public UIProgram {
- public:
- explicit TextProgram(const glm::mat4 & vp);
- void use(const RGB & colour) const;
-
- private:
- RequiredUniformLocation colorLoc {*this, "colour"};
- };
-
-public:
- IconProgram icon;
- TextProgram text;
-};
diff --git a/lib/collection.h b/lib/collection.h
index 6802bcb..1c77e1c 100644
--- a/lib/collection.h
+++ b/lib/collection.h
@@ -3,29 +3,62 @@
#include <algorithm>
#include <functional>
#include <memory>
+#include <special_members.h>
#include <type_traits>
#include <vector>
-template<typename Object, bool shared = true> class Collection {
+template<typename Ptr, typename... Others> class Collection {
public:
+ Collection() = default;
virtual ~Collection() = default;
- using Ptr = std::conditional_t<shared, std::shared_ptr<Object>, std::unique_ptr<Object>>;
+ DEFAULT_MOVE_NO_COPY(Collection);
+
+ using Object = Ptr::element_type;
using Objects = std::vector<Ptr>;
- Objects objects;
+ template<typename T> using OtherObjects = std::vector<T *>;
+
+ Collection &
+ operator=(Objects && other)
+ {
+ objects = std::move(other);
+ ((std::get<OtherObjects<Others>>(otherObjects).clear()), ...);
+ for (const auto & other : objects) {
+ addOthersPtr(other.get());
+ }
+ return *this;
+ }
+
+ const Ptr &
+ operator[](size_t idx) const
+ {
+ return objects[idx];
+ }
+
+ template<typename T = Object>
+ requires(std::is_same_v<T, Object> || (std::is_base_of_v<Others, T> || ...))
+ [[nodiscard]] auto
+ size() const noexcept
+ {
+ return containerFor<T>().size();
+ }
template<typename T = Object, typename... Params>
auto
create(Params &&... params)
requires std::is_base_of_v<Object, T>
{
- if constexpr (shared) {
+ if constexpr (requires(Ptr ptr) { ptr = std::make_shared<T>(std::forward<Params>(params)...); }) {
auto obj = std::make_shared<T>(std::forward<Params>(params)...);
objects.emplace_back(obj);
+ addOthersType<T>(obj.get());
return obj;
}
else {
- return static_cast<T *>(objects.emplace_back(std::make_unique<T>(std::forward<Params>(params)...)).get());
+ auto obj = static_cast<T *>(
+ objects.emplace_back(std::make_unique<T>(std::forward<Params>(params)...)).get());
+ addOthersType<T>(obj);
+ return obj;
}
}
@@ -33,12 +66,19 @@ public:
T *
find()
{
- if (auto i = std::find_if(objects.begin(), objects.end(),
- [](auto && o) {
- return (dynamic_cast<T *>(o.get()));
- });
- i != objects.end()) {
- return static_cast<T *>(i->get());
+ const auto & srcObjects = containerFor<T>();
+ if constexpr (std::is_convertible_v<typename std::remove_reference_t<decltype(srcObjects)>::value_type, T *>) {
+ if (srcObjects.empty()) {
+ return nullptr;
+ }
+ return srcObjects.front();
+ }
+ else if (auto i = std::find_if(srcObjects.begin(), srcObjects.end(),
+ [](auto && o) {
+ return dynamic_cast<T *>(std::to_address(o)) != nullptr;
+ });
+ i != srcObjects.end()) {
+ return static_cast<T *>(std::to_address(*i));
}
return nullptr;
}
@@ -58,74 +98,229 @@ public:
auto
apply(const auto & m, Params &&... params) const
{
- return apply_internal<T>(objects.begin(), objects.end(), m, std::forward<Params>(params)...);
+ const auto & srcObjects = containerFor<T>();
+ return apply_internal<T>(srcObjects.begin(), srcObjects.end(), m, std::forward<Params>(params)...);
}
template<typename T = Object, typename... Params>
auto
rapply(const auto & m, Params &&... params) const
{
- return apply_internal<T>(objects.rbegin(), objects.rend(), m, std::forward<Params>(params)...);
+ const auto & srcObjects = containerFor<T>();
+ return apply_internal<T>(srcObjects.rbegin(), srcObjects.rend(), m, std::forward<Params>(params)...);
}
template<typename T = Object, typename... Params>
auto
applyOne(const auto & m, Params &&... params) const
{
- return applyOne_internal<T>(objects.begin(), objects.end(), m, std::forward<Params>(params)...);
+ const auto & srcObjects = containerFor<T>();
+ return applyOne_internal<T>(srcObjects.begin(), srcObjects.end(), m, std::forward<Params>(params)...);
}
template<typename T = Object, typename... Params>
auto
rapplyOne(const auto & m, Params &&... params) const
{
- return applyOne_internal<T>(objects.rbegin(), objects.rend(), m, std::forward<Params>(params)...);
+ const auto & srcObjects = containerFor<T>();
+ return applyOne_internal<T>(srcObjects.rbegin(), srcObjects.rend(), m, std::forward<Params>(params)...);
}
- template<typename T = Object>
+ template<typename T>
+ requires std::is_base_of_v<Object, T>
auto
removeAll()
{
- return std::erase_if(objects, [](auto && op) {
- return dynamic_cast<T *>(op.get());
- });
+ auto removeAllFrom = [](auto & container) {
+ if constexpr (std::is_base_of_v<T, std::decay_t<decltype(*container.front())>>) {
+ const auto size = container.size();
+ container.clear();
+ return size;
+ }
+ else {
+ return std::erase_if(container, [](auto && objPtr) -> bool {
+ return dynamic_cast<const T *>(std::to_address(objPtr));
+ });
+ }
+ };
+ (removeAllFrom(std::get<OtherObjects<Others>>(otherObjects)), ...);
+ return removeAllFrom(objects);
+ }
+
+ void
+ clear()
+ {
+ ((std::get<OtherObjects<Others>>(otherObjects).clear()), ...);
+ objects.clear();
}
- auto
+ [[nodiscard]] auto
+ begin() const
+ {
+ return objects.begin();
+ }
+
+ [[nodiscard]] auto
end() const
{
return objects.end();
}
- auto
+ [[nodiscard]] auto
+ rbegin() const
+ {
+ return objects.rbegin();
+ }
+
+ [[nodiscard]] auto
rend() const
{
return objects.rend();
}
+ [[nodiscard]] bool
+ empty() const
+ {
+ return objects.empty();
+ }
+
+ decltype(auto)
+ emplace(Ptr && ptr)
+ {
+ const auto & object = objects.emplace_back(std::move(ptr));
+ addOthersPtr(object.get());
+ return object;
+ }
+
protected:
+ Objects objects;
+ std::tuple<OtherObjects<Others>...> otherObjects;
+
+ template<typename T>
+ void
+ addOthersType(T * obj)
+ {
+ applyToOthersType<T>(
+ [](auto & others, auto ptr) {
+ others.emplace_back(ptr);
+ },
+ obj);
+ }
+
+ void
+ addOthersPtr(Object * obj)
+ {
+ applyToOthersPtr(
+ [](auto & others, auto ptr) {
+ others.emplace_back(ptr);
+ },
+ obj);
+ }
+
+ template<typename T, typename... Params>
+ requires(sizeof...(Others) == 0)
+ void
+ applyToOthersType(const auto &, Params...)
+ {
+ }
+
+ void
+ applyToOthersPtr(const auto &, Object *)
+ requires(sizeof...(Others) == 0)
+ {
+ }
+
+ template<typename T, typename... Params>
+ requires(sizeof...(Others) > 0)
+ void
+ applyToOthersType(const auto & func, Params &&... params)
+ {
+ (
+ [&]() {
+ if constexpr (std::is_convertible_v<T *, Others *>) {
+ std::invoke(
+ func, std::get<OtherObjects<Others>>(otherObjects), std::forward<Params>(params)...);
+ }
+ }(),
+ ...);
+ }
+
+ void
+ applyToOthersPtr(const auto & func, Object * obj)
+ requires(sizeof...(Others) > 0)
+ {
+ (
+ [&]() {
+ if (auto ptr = dynamic_cast<Others *>(obj)) {
+ std::invoke(func, std::get<OtherObjects<Others>>(otherObjects), ptr);
+ }
+ }(),
+ ...);
+ }
+
+ template<typename T>
+ requires((std::is_base_of_v<Others, T> || ...))
+ [[nodiscard]] consteval static size_t
+ idx()
+ {
+ size_t typeIdx = 0;
+ auto found = ((++typeIdx && std::is_base_of_v<Others, T>) || ...);
+ return typeIdx - found;
+ }
+
+ template<typename T>
+ [[nodiscard]]
+ constexpr const auto &
+ containerFor() const
+ {
+ if constexpr ((std::is_base_of_v<Others, T> || ...)) {
+ return std::get<idx<T>()>(otherObjects);
+ }
+ else {
+ return objects;
+ }
+ }
+
template<typename T = Object, typename... Params>
auto
apply_internal(const auto begin, const auto end, const auto & m, Params &&... params) const
{
- return std::count_if(begin, end, [&m, &params...](auto && op) {
- if (auto o = dynamic_cast<T *>(op.get())) {
- std::invoke(m, o, std::forward<Params>(params)...);
- return true;
- }
- return false;
- });
+ if constexpr (std::is_convertible_v<decltype(std::to_address(*begin)), T *>) {
+ std::for_each(begin, end, [&m, &params...](auto && op) {
+ std::invoke(m, op, std::forward<Params>(params)...);
+ });
+ return std::distance(begin, end);
+ }
+ else {
+ return std::count_if(begin, end, [&m, &params...](auto && op) {
+ if (auto o = dynamic_cast<T *>(std::to_address(op))) {
+ std::invoke(m, o, std::forward<Params>(params)...);
+ return true;
+ }
+ return false;
+ });
+ }
}
template<typename T = Object, typename... Params>
auto
applyOne_internal(const auto begin, const auto end, const auto & m, Params &&... params) const
{
- return std::find_if(begin, end, [&m, &params...](auto && op) {
- if (auto o = dynamic_cast<T *>(op.get())) {
- return std::invoke(m, o, std::forward<Params>(params)...);
- }
- return false;
- });
+ if constexpr (std::is_convertible_v<decltype(std::to_address(*begin)), T *>) {
+ return std::find_if(begin, end, [&m, &params...](auto && op) {
+ return std::invoke(m, op, std::forward<Params>(params)...);
+ });
+ }
+ else {
+ return std::find_if(begin, end, [&m, &params...](auto && op) {
+ if (auto o = dynamic_cast<T *>(std::to_address(op))) {
+ return std::invoke(m, o, std::forward<Params>(params)...);
+ }
+ return false;
+ });
+ }
}
};
+
+template<typename T, typename... Others> using SharedCollection = Collection<std::shared_ptr<T>, Others...>;
+template<typename T, typename... Others> using UniqueCollection = Collection<std::unique_ptr<T>, Others...>;
diff --git a/lib/glArrays.h b/lib/glArrays.h
index 787ea17..842a593 100644
--- a/lib/glArrays.h
+++ b/lib/glArrays.h
@@ -6,6 +6,7 @@
#include <glad/gl.h>
#include <special_members.h>
+// NOLINTNEXTLINE(readability-identifier-naming)
template<size_t N> class glArraysBase {
static_assert(N > 0);
@@ -15,20 +16,30 @@ public:
CUSTOM_MOVE(glArraysBase);
// NOLINTNEXTLINE(hicpp-explicit-conversions)
- inline
operator GLuint() const
+ requires(N == 1)
{
- static_assert(N == 1, "Implicit cast only if N == 1");
return ids.front();
}
- inline auto
+ GLuint
+ operator*() const
+ requires(N == 1)
+ {
+ return ids.front();
+ }
+
+ const auto &
operator[](size_t n) const
{
return ids[n];
}
- constexpr static auto size {N};
+ constexpr static auto
+ size()
+ {
+ return N;
+ }
protected:
glArraysBase() noexcept = default;
@@ -49,6 +60,7 @@ glArraysBase<N>::operator=(glArraysBase<N> && src) noexcept
return *this;
}
+// NOLINTNEXTLINE(readability-identifier-naming)
template<size_t N, auto Gen, auto Del> class glArrays : public glArraysBase<N> {
public:
using glArraysBase<N>::glArraysBase;
@@ -56,12 +68,12 @@ public:
DEFAULT_MOVE_COPY(glArrays);
- inline glArrays() noexcept
+ glArrays() noexcept
{
(*Gen)(N, this->ids.data());
}
- inline ~glArrays() noexcept
+ ~glArrays() noexcept
{
if (this->ids.front()) {
(*Del)(N, this->ids.data());
@@ -69,6 +81,7 @@ public:
}
};
+// NOLINTBEGIN(readability-identifier-naming)
template<size_t N> using glVertexArrays = glArrays<N, &glGenVertexArrays, &glDeleteVertexArrays>;
using glVertexArray = glVertexArrays<1>;
template<size_t N> using glBuffers = glArrays<N, &glGenBuffers, &glDeleteBuffers>;
@@ -79,3 +92,4 @@ template<size_t N> using glFrameBuffers = glArrays<N, &glGenFramebuffers, &glDel
using glFrameBuffer = glFrameBuffers<1>;
template<size_t N> using glRenderBuffers = glArrays<N, &glGenRenderbuffers, &glDeleteRenderbuffers>;
using glRenderBuffer = glRenderBuffers<1>;
+// NOLINTEND(readability-identifier-naming)
diff --git a/lib/manyPtr.h b/lib/manyPtr.h
new file mode 100644
index 0000000..9e08452
--- /dev/null
+++ b/lib/manyPtr.h
@@ -0,0 +1,86 @@
+#pragma once
+
+#include <memory>
+#include <tuple>
+
+template<typename Primary, typename... Others> class ManyPtr : Primary {
+public:
+ using element_type = typename Primary::element_type;
+
+ template<typename... Params> ManyPtr(Params &&... params) : Primary {std::forward<Params>(params)...}
+ {
+ updatePtrs();
+ }
+
+ using Primary::operator->;
+ using Primary::operator*;
+ using Primary::operator bool;
+ using Primary::get;
+
+ template<typename... Params>
+ void
+ reset(Params &&... params)
+ {
+ Primary::reset(std::forward<Params>(params)...);
+ updatePtrs();
+ }
+
+ template<typename Other>
+ [[nodiscard]] consteval static bool
+ couldBe()
+ {
+ return (std::is_convertible_v<Others *, Other *> || ...);
+ }
+
+ template<typename Other>
+ requires(couldBe<Other>())
+ [[nodiscard]] auto
+ getAs() const
+ {
+ return std::get<idx<Other>()>(others);
+ }
+
+ template<typename Other>
+ requires(!couldBe<Other>() && requires { std::dynamic_pointer_cast<Other>(std::declval<Primary>()); })
+ [[nodiscard]] auto
+ dynamicCast() const
+ {
+ return std::dynamic_pointer_cast<Other>(*this);
+ }
+
+ template<typename Other>
+ requires(!couldBe<Other>() && !requires { std::dynamic_pointer_cast<Other>(std::declval<Primary>()); })
+ [[nodiscard]] auto
+ dynamicCast() const
+ {
+ return dynamic_cast<Other *>(get());
+ }
+
+private:
+ using OtherPtrs = std::tuple<Others *...>;
+
+ template<typename Other>
+ requires(couldBe<Other>())
+ [[nodiscard]] consteval static bool
+ idx()
+ {
+ size_t typeIdx = 0;
+ return ((typeIdx++ && std::is_convertible_v<Others *, Other *>) || ...);
+ }
+
+ void
+ updatePtrs()
+ {
+ if (*this) {
+ others = {dynamic_cast<Others *>(get())...};
+ }
+ else {
+ others = {};
+ }
+ }
+
+ OtherPtrs others;
+};
+
+template<typename Primary, typename... Others> using ManySharedPtr = ManyPtr<std::shared_ptr<Primary>, Others...>;
+template<typename Primary, typename... Others> using ManyUniquePtr = ManyPtr<std::unique_ptr<Primary>, Others...>;
diff --git a/lib/persistence.h b/lib/persistence.h
index e385b20..75bcea6 100644
--- a/lib/persistence.h
+++ b/lib/persistence.h
@@ -1,5 +1,6 @@
#pragma once
+#include "manyPtr.h"
#include <charconv>
#include <format>
#include <functional>
@@ -200,7 +201,7 @@ namespace Persistence {
}
[[nodiscard]] virtual NameActionSelection setName(const std::string_view key, SelectionFactory &&) = 0;
- virtual void selHandler() {};
+ virtual void selHandler() { };
virtual void setType(const std::string_view, const Persistable *) = 0;
SelectionPtr sel {};
diff --git a/res/ui/icon/magnifier.svg b/res/ui/icon/magnifier.svg
new file mode 100644
index 0000000..97abe9f
--- /dev/null
+++ b/res/ui/icon/magnifier.svg
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Creator: CorelDRAW -->
+<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="1.70666in" height="1.70666in" version="1.1" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
+viewBox="0 0 1707 1707"
+ xmlns:xlink="http://www.w3.org/1999/xlink">
+ <defs>
+ <style type="text/css">
+ <![CDATA[
+ .fil3 {fill:url(#id0)}
+ .fil0 {fill:url(#id1)}
+ .fil2 {fill:url(#id2)}
+ .fil4 {fill:url(#id3)}
+ .fil1 {fill:url(#id4)}
+ .fil5 {fill:url(#id5)}
+ ]]>
+ </style>
+ <linearGradient id="id0" gradientUnits="userSpaceOnUse" x1="647.772" y1="1185.78" x2="647.772" y2="109.768">
+ <stop offset="0" style="stop-opacity:1; stop-color:#AFAFAF"/>
+ <stop offset="1" style="stop-opacity:1; stop-color:#9C9C9C"/>
+ </linearGradient>
+ <linearGradient id="id1" gradientUnits="userSpaceOnUse" x1="1138.83" y1="1294.33" x2="1138.83" y2="983.327">
+ <stop offset="0" style="stop-opacity:1; stop-color:#949494"/>
+ <stop offset="1" style="stop-opacity:1; stop-color:#858585"/>
+ </linearGradient>
+ <linearGradient id="id2" gradientUnits="userSpaceOnUse" xlink:href="#id1" x1="647.772" y1="1295.55" x2="647.772" y2="0.00393701">
+ </linearGradient>
+ <linearGradient id="id3" gradientUnits="userSpaceOnUse" x1="647.772" y1="1143.81" x2="647.772" y2="151.736">
+ <stop offset="0" style="stop-opacity:1; stop-color:#D2D2D2"/>
+ <stop offset="1" style="stop-opacity:1; stop-color:#BBBBBB"/>
+ </linearGradient>
+ <linearGradient id="id4" gradientUnits="userSpaceOnUse" x1="1411.49" y1="1116.31" x2="1411.49" y2="1706.66">
+ <stop offset="0" style="stop-opacity:1; stop-color:#FF9911"/>
+ <stop offset="1" style="stop-opacity:1; stop-color:#FF6600"/>
+ </linearGradient>
+ <linearGradient id="id5" gradientUnits="userSpaceOnUse" x1="657.22" y1="496.535" x2="657.22" y2="322.63">
+ <stop offset="0" style="stop-opacity:1; stop-color:#E6E6E6"/>
+ <stop offset="1" style="stop-opacity:1; stop-color:#CCCCCC"/>
+ </linearGradient>
+ </defs>
+ <g id="Layer_x0020_1">
+ <metadata id="CorelCorpID_0Corel-Layer"/>
+ <path class="fil0" d="M1161 983l133 133 -178 178 -133 -133c36,-21 69,-47 100,-78 31,-31 57,-64 78,-100z"/>
+ <path class="fil1" d="M1116 1294l178 -178 376 376c49,49 49,129 0,178l0 0c-49,49 -129,49 -178,0l-376 -376z"/>
+ <path class="fil2" d="M190 190c253,-253 663,-253 916,0 253,253 253,663 0,916 -253,253 -663,253 -916,0 -253,-253 -253,-663 0,-916z"/>
+ <path class="fil3" d="M267 267c210,-210 551,-210 761,0 210,210 210,551 0,761 -210,210 -551,210 -761,0 -210,-210 -210,-551 0,-761z"/>
+ <path class="fil4" d="M297 297c194,-194 508,-194 702,0 193,194 193,508 0,702 -194,193 -508,193 -702,0 -194,-194 -194,-508 0,-702z"/>
+ <path class="fil5" d="M440 486c-14,14 -37,14 -52,0 -14,-15 -14,-38 0,-52 75,-74 172,-111 269,-111 97,0 195,37 269,111 14,14 14,38 0,52 -14,14 -37,14 -52,0 -60,-60 -138,-90 -217,-90 -79,0 -157,30 -217,90z"/>
+ </g>
+</svg>
diff --git a/res/ui/icon/network.png b/res/ui/icon/network.png
deleted file mode 100644
index 7a091f3..0000000
--- a/res/ui/icon/network.png
+++ /dev/null
Binary files differ
diff --git a/res/ui/icon/rails.svg b/res/ui/icon/rails.svg
new file mode 100644
index 0000000..81e9b94
--- /dev/null
+++ b/res/ui/icon/rails.svg
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Creator: CorelDRAW -->
+<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="1.99999in" height="1.99999in" version="1.1" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
+viewBox="0 0 2000 2000"
+ xmlns:xlink="http://www.w3.org/1999/xlink">
+ <defs>
+ <style type="text/css">
+ <![CDATA[
+ .fil0 {fill:none}
+ .fil1 {fill:#333333}
+ .fil2 {fill:#C06000}
+ .fil3 {fill:#CCCCCC}
+ ]]>
+ </style>
+ </defs>
+ <rect class="fil0" width="2000" height="2000"/>
+ <g id="Layer_x0020_1">
+ <metadata id="CorelCorpID_0Corel-Layer"/>
+ <path class="fil1" d="M1448 515l-61 0 29 126 108 0c30,0 55,23 63,59l38 168c8,37 -28,69 -63,69l-80 0 28 126 127 0c31,0 55,23 63,59l38 168c9,37 -27,69 -63,69l-98 0 28 126 146 0c31,0 55,22 63,58l38 169c8,37 -27,68 -63,68l-126 0c-8,20 -30,34 -51,34l-81 0c-21,0 -38,-13 -48,-34l-966 0c-10,21 -27,34 -48,34l-81 0c-21,0 -43,-14 -51,-34l-126 0c-36,0 -71,-31 -63,-68l38 -169c8,-36 32,-58 63,-58l146 0 29 -126 -99 0c-36,0 -72,-32 -63,-69l38 -168c8,-36 32,-59 63,-59l127 0 28 -126 -80 0c-35,0 -71,-32 -63,-69l38 -168c8,-36 32,-59 63,-59l109 0 28 -126c-40,0 -87,8 -113,-25 -10,-13 -14,-28 -11,-44 56,-248 29,-226 192,-226 10,-21 27,-34 49,-34l80 0c21,0 43,14 51,34l278 0c8,-20 30,-34 51,-34l81 0c21,0 39,13 48,34 163,0 136,-21 192,226 8,37 -28,69 -63,69zm-971 1239l341 -1516 0 -1c-1,-2 -5,-4 -8,-4l-80 0c-5,0 -8,10 -9,15l-338 1506c-2,7 -5,13 5,13l81 0c4,0 7,-8 8,-13zm108 -269l830 0 -28 -126 -773 0 -29 126zm95 -422l640 0 -28 -126 -584 0 -28 126zm95 -422l450 0 -28 -126 -394 0 -28 126zm-436 1093l46 -202 -136 0 0 0c-12,0 -16,17 -18,22l-37 168c-2,6 12,12 17,12l128 0zm95 -422l45 -202 -116 0 0 0c-12,0 -17,17 -18,22l-38 168c-1,7 13,12 18,12l109 0zm425 -1046l-45 202 373 0 -46 -202 -282 0zm-95 422l-45 202 562 0 -45 -202 -472 0zm-94 422l-46 202 752 0 -45 -202 -661 0zm-95 422l-46 202 942 0 -46 -202 -850 0zm760 -1035l-56 -251c-1,-5 -4,-13 -9,-13l-80 0c-3,0 -6,2 -8,4l341 1517c1,5 5,13 8,13l81 0c3,0 7,-2 8,-4l-285 -1266zm-4 -231l46 202 71 0c5,0 19,-5 17,-11l-37 -169c-2,-5 -6,-22 -18,-22l-79 0zm95 422l45 202 91 0c4,0 19,-5 17,-12l-38 -168c-1,-5 -6,-22 -17,-22l-98 0zm95 422l45 202 109 0c6,0 19,-5 18,-12l-38 -168c-1,-5 -6,-22 -17,-22l-117 0zm95 422l45 202 128 0c6,0 18,-6 18,-12l-38 -168c-1,-5 -6,-22 -18,-22l-135 0zm-1140 -844c-11,0 -16,17 -17,22l-38 168c-2,7 13,12 17,12l91 0 45 -202 -98 0zm114 -422c-12,0 -16,17 -17,22l-38 169c-2,6 12,11 17,11l72 0 45 -202 -79 0z"/>
+ <path class="fil2" d="M339 1734l46 -202 -136 0 0 0c-12,0 -16,17 -18,22l-37 168c-2,6 12,12 17,12l128 0z"/>
+ <path class="fil3" d="M721 248l-338 1506c-2,7 -5,13 5,13l81 0c4,0 7,-8 8,-13l341 -1516 0 -1c-1,-2 -5,-4 -8,-4l-80 0c-5,0 -8,10 -9,15z"/>
+ <polygon class="fil2" points="1425,1532 575,1532 529,1734 1471,1734 "/>
+ <path class="fil3" d="M1182 237l341 1517c1,5 5,13 8,13l81 0c3,0 7,-2 8,-4l-285 -1266 -56 -251c-1,-5 -4,-13 -9,-13l-80 0c-3,0 -6,2 -8,4z"/>
+ <path class="fil2" d="M1751 1532l-135 0 45 202 128 0c6,0 18,-6 18,-12l-38 -168c-1,-5 -6,-22 -18,-22z"/>
+ <path class="fil2" d="M1566 1312l109 0c6,0 19,-5 18,-12l-38 -168c-1,-5 -6,-22 -17,-22l-117 0 45 202z"/>
+ <polygon class="fil2" points="1376,1312 1331,1110 670,1110 624,1312 "/>
+ <path class="fil2" d="M434 1312l45 -202 -116 0 0 0c-12,0 -17,17 -18,22l-38 168c-1,7 13,12 18,12l109 0z"/>
+ <path class="fil2" d="M438 890l91 0 45 -202 -98 0c-11,0 -16,17 -17,22l-38 168c-2,7 13,12 17,12z"/>
+ <polygon class="fil2" points="764,688 719,890 1281,890 1236,688 "/>
+ <path class="fil2" d="M1426 688l45 202 91 0c4,0 19,-5 17,-12l-38 -168c-1,-5 -6,-22 -17,-22l-98 0z"/>
+ <path class="fil2" d="M1377 468l71 0c5,0 19,-5 17,-11l-37 -169c-2,-5 -6,-22 -18,-22l-79 0 46 202z"/>
+ <polygon class="fil2" points="1187,468 1141,266 859,266 814,468 "/>
+ <path class="fil2" d="M624 468l45 -202 -79 0c-12,0 -16,17 -17,22l-38 169c-2,6 12,11 17,11l72 0z"/>
+ </g>
+</svg>
diff --git a/res/ui/icon/road.svg b/res/ui/icon/road.svg
new file mode 100644
index 0000000..3b9ae77
--- /dev/null
+++ b/res/ui/icon/road.svg
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Creator: CorelDRAW -->
+<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="512px" height="512px" version="1.1" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
+viewBox="0 0 512 512"
+ xmlns:xlink="http://www.w3.org/1999/xlink">
+ <defs>
+ <style type="text/css">
+ <![CDATA[
+ .fil0 {fill:#4D4D4D}
+ .fil1 {fill:#99A4AC}
+ .fil2 {fill:#D9F2F2}
+ ]]>
+ </style>
+ </defs>
+ <g id="Layer_x0020_1">
+ <metadata id="CorelCorpID_0Corel-Layer"/>
+ <path class="fil0" d="M491 512l-470 0c-5,0 -8,-4 -7,-8l82 -498c1,-3 4,-6 8,-6l308 0c4,0 7,2 7,6l79 498c1,3 -2,8 -7,8zm-406 -14l56 -484 -31 0 -81 484 56 0zm288 -484l54 484 56 0 -77 -484 -33 0zm40 484l-54 -484 -64 0 0 86c-1,4 -4,7 -8,7l-47 0c-4,0 -7,-3 -7,-7l0 -86 -77 0 -57 484 134 0 0 -86c0,-4 3,-8 7,-8l47 0c4,0 8,4 8,8l0 86 118 0zm-133 0l0 -79 -33 0 0 79 33 0zm7 -121l-47 0c-4,0 -7,-3 -7,-7l0 -93c0,-4 3,-8 7,-8l47 0c4,0 8,4 8,8l0 93c-1,4 -4,7 -8,7zm-40 -14l33 0 0 -79 -33 0 0 79zm40 -121l-47 0c-4,0 -7,-3 -7,-7l0 -93c0,-4 3,-8 7,-8l47 0c4,0 8,4 8,8l0 93c-1,4 -4,7 -8,7zm-40 -14l33 0 0 -79 -33 0 0 79zm0 -135l33 0 0 -79 -33 0 0 79z"/>
+ <path class="fil1" d="M295 498l118 0 -54 -484 -64 0 0 86c-1,4 -4,7 -8,7l-47 0c-4,0 -7,-3 -7,-7l0 -86 -77 0 -57 484 134 0 0 -86c0,-4 3,-8 7,-8l47 0c4,0 8,4 8,8l0 86zm0 -221l0 93c-1,4 -4,7 -8,7l-47 0c-4,0 -7,-3 -7,-7l0 -93c0,-4 3,-8 7,-8l47 0c4,0 8,4 8,8zm-8 -35l-47 0c-4,0 -7,-3 -7,-7l0 -93c0,-4 3,-8 7,-8l47 0c4,0 8,4 8,8l0 93c-1,4 -4,7 -8,7z"/>
+ <polygon class="fil2" points="247,228 280,228 280,149 247,149 "/>
+ <polygon class="fil2" points="280,284 247,284 247,363 280,363 "/>
+ <polygon class="fil2" points="280,419 247,419 247,498 280,498 "/>
+ <polygon class="fil2" points="247,93 280,93 280,14 247,14 "/>
+ <polygon class="fil1" points="373,14 427,498 483,498 406,14 "/>
+ <polygon class="fil1" points="85,498 141,14 110,14 29,498 "/>
+ </g>
+</svg>
diff --git a/test/Jamfile.jam b/test/Jamfile.jam
index 5189add..bdaaa45 100644
--- a/test/Jamfile.jam
+++ b/test/Jamfile.jam
@@ -75,6 +75,7 @@ perfrun perf-instancing.cpp : : test-instancing ;
run test-glContainer.cpp : : : <library>test ;
run test-pack.cpp : : : <library>test ;
run test-environment.cpp : : : <library>test ;
+run test-ui.cpp : : : <library>test ;
compile test-static-enumDetails.cpp ;
compile test-static-stream_support.cpp ;
alias perf : perf-assetFactory perf-persistence perf-geoData perf-instancing perf-terrain ;
diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp
index 9bade82..68ce6a6 100644
--- a/test/test-assetFactory.cpp
+++ b/test/test-assetFactory.cpp
@@ -71,7 +71,7 @@ public:
sceneRenderer.render(*this);
}
- Collection<const Renderable> objects;
+ SharedCollection<const Renderable> objects;
private:
SceneRenderer sceneRenderer;
@@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE(surfaces, *boost::unit_test::timeout(5))
BOOST_CHECK_EQUAL(4, mf->assets.size());
auto gravelAsset = mf->assets.at("terrain.surface.gravel");
BOOST_REQUIRE(gravelAsset);
- auto gravel = std::dynamic_pointer_cast<Surface>(gravelAsset);
+ auto gravel = gravelAsset.dynamicCast<Surface>();
BOOST_REQUIRE(gravel);
BOOST_REQUIRE_EQUAL(gravel->name, "Gravel");
BOOST_REQUIRE_EQUAL(gravel->colorBias, RGB {.9F});
@@ -111,14 +111,14 @@ BOOST_AUTO_TEST_CASE(brush47xml, *boost::unit_test::timeout(5))
BOOST_CHECK_EQUAL(1, mf->assets.size());
auto brush47 = mf->assets.at("brush-47");
BOOST_REQUIRE(brush47);
- auto brush47rvc = std::dynamic_pointer_cast<RailVehicleClass>(brush47);
+ auto brush47rvc = brush47.dynamicCast<RailVehicleClass>();
BOOST_REQUIRE(brush47rvc);
BOOST_REQUIRE(brush47rvc->bodyMesh);
BOOST_REQUIRE(brush47rvc->bogies.front());
BOOST_REQUIRE(brush47rvc->bogies.back());
auto railVehicle = std::make_shared<RailVehicle>(brush47rvc);
- objects.objects.push_back(brush47rvc);
+ objects.emplace(brush47rvc);
render(10000);
}
@@ -130,14 +130,14 @@ BOOST_AUTO_TEST_CASE(foliage, *boost::unit_test::timeout(5))
gameState.assets = mf->assets;
auto tree_01_1 = mf->assets.at("Tree-01-1");
BOOST_REQUIRE(tree_01_1);
- auto tree_01_1_f = std::dynamic_pointer_cast<Foliage>(tree_01_1);
+ auto tree_01_1_f = tree_01_1.dynamicCast<Foliage>();
BOOST_REQUIRE(tree_01_1_f);
auto plant1 = std::make_shared<Plant>(tree_01_1_f, Location {{-2000, 2000, 0}, {0, 0, 0}});
auto plant2 = std::make_shared<Plant>(tree_01_1_f, Location {{3000, -4000, 0}, {0, 1, 0}});
auto plant3 = std::make_shared<Plant>(tree_01_1_f, Location {{-2000, -4000, 0}, {0, 2, 0}});
auto plant4 = std::make_shared<Plant>(tree_01_1_f, Location {{3000, 2000, 0}, {0, 3, 0}});
- objects.objects.push_back(tree_01_1_f);
+ objects.emplace(tree_01_1_f);
render(6000);
}
@@ -151,22 +151,22 @@ BOOST_AUTO_TEST_CASE(lights, *boost::unit_test::timeout(5))
BOOST_REQUIRE(rlight);
auto oldlamp = mf->assets.at("old-lamp");
BOOST_REQUIRE(oldlamp);
- auto rlight_f = std::dynamic_pointer_cast<Illuminator>(rlight);
+ auto rlight_f = rlight.dynamicCast<Illuminator>();
BOOST_REQUIRE(rlight_f);
- auto oldlamp_f = std::dynamic_pointer_cast<Illuminator>(oldlamp);
+ auto oldlamp_f = oldlamp.dynamicCast<Illuminator>();
BOOST_REQUIRE(oldlamp_f);
auto light1 = std::make_shared<Light>(oldlamp_f, Location {{0, 0, 0}, {0, 0, 0}});
auto light2 = std::make_shared<Light>(rlight_f, Location {{-4000, 0, 0}, {0, 2, 0}});
auto light3 = std::make_shared<Light>(rlight_f, Location {{-4000, -4000, 0}, {0, 1, 0}});
auto light4 = std::make_shared<Light>(oldlamp_f, Location {{3000, 4600, 0}, {0, 2, 0}});
- objects.objects.push_back(rlight_f);
- objects.objects.push_back(oldlamp_f);
+ objects.emplace(rlight_f);
+ objects.emplace(oldlamp_f);
// yes I'm hacking some floor to light up as though its a bush
- auto floorf = std::dynamic_pointer_cast<Foliage>(mf->assets.at("floor"));
+ auto floorf = mf->assets.at("floor").dynamicCast<Foliage>();
auto floor = std::make_shared<Plant>(floorf, Location {});
- objects.objects.push_back(floorf);
+ objects.emplace(floorf);
render(6000);
}
diff --git a/test/test-collection.cpp b/test/test-collection.cpp
index 00204fc..620d3ab 100644
--- a/test/test-collection.cpp
+++ b/test/test-collection.cpp
@@ -21,6 +21,12 @@ public:
return false;
}
+ [[nodiscard]] virtual bool
+ yes() const
+ {
+ return true;
+ }
+
unsigned int total {0};
};
@@ -34,27 +40,63 @@ public:
}
};
-using TestCollection = Collection<Base>;
+class Sub1 : public Sub { };
+
+class Sub2 : public Sub { };
+
+class Base2 {
+public:
+ virtual ~Base2() = default;
+};
+
+class Multi : public Sub1, public Base2 { };
+
+using TestCollection = SharedCollection<Base, Sub>;
-BOOST_TEST_DONT_PRINT_LOG_VALUE(Collection<Base>::Objects::const_iterator)
-BOOST_TEST_DONT_PRINT_LOG_VALUE(Collection<Base>::Objects::const_reverse_iterator)
+BOOST_TEST_DONT_PRINT_LOG_VALUE(TestCollection::Objects::iterator)
+BOOST_TEST_DONT_PRINT_LOG_VALUE(TestCollection::Objects::const_iterator)
+BOOST_TEST_DONT_PRINT_LOG_VALUE(TestCollection::Objects::const_reverse_iterator)
+BOOST_TEST_DONT_PRINT_LOG_VALUE(TestCollection::OtherObjects<Sub>::iterator)
+BOOST_TEST_DONT_PRINT_LOG_VALUE(TestCollection::OtherObjects<Sub>::const_iterator)
BOOST_FIXTURE_TEST_SUITE(tc, TestCollection)
BOOST_AUTO_TEST_CASE(empty)
{
+ BOOST_CHECK(TestCollection::empty());
BOOST_REQUIRE(!apply(&Base::add));
const auto i = applyOne(&Base::add);
BOOST_CHECK_EQUAL(i, end());
+ BOOST_CHECK(!find<Base>());
+ BOOST_CHECK(!find<Sub>());
+ BOOST_CHECK(!find<Sub1>());
}
BOOST_AUTO_TEST_CASE(a_base)
{
auto b = create<Base>();
+ BOOST_CHECK_EQUAL(objects.size(), 1);
+ BOOST_CHECK(std::get<OtherObjects<Sub>>(otherObjects).empty());
BOOST_REQUIRE(apply(&Base::add));
BOOST_CHECK_EQUAL(b->total, 1);
const auto i = applyOne(&Base::add);
BOOST_CHECK_EQUAL(i, end());
+ BOOST_CHECK_EQUAL(b.get(), find<Base>());
+ BOOST_CHECK(!find<Sub>());
+ BOOST_CHECK(!find<Sub1>());
+}
+
+BOOST_AUTO_TEST_CASE(emplace_others)
+{
+ auto b = emplace(std::make_shared<Base>());
+ BOOST_CHECK_EQUAL(objects.size(), 1);
+ BOOST_CHECK(std::get<OtherObjects<Sub>>(otherObjects).empty());
+ auto s = emplace(std::make_shared<Sub>());
+ BOOST_CHECK_EQUAL(objects.size(), 2);
+ BOOST_CHECK_EQUAL(std::get<OtherObjects<Sub>>(otherObjects).size(), 1);
+ BOOST_CHECK_EQUAL(b.get(), find<Base>());
+ BOOST_CHECK_EQUAL(s.get(), find<Sub>());
+ BOOST_CHECK(!find<Sub1>());
}
BOOST_AUTO_TEST_CASE(a_rbase)
@@ -69,6 +111,8 @@ BOOST_AUTO_TEST_CASE(a_rbase)
BOOST_AUTO_TEST_CASE(a_sub)
{
auto s = create<Sub>();
+ BOOST_CHECK_EQUAL(objects.size(), 1);
+ BOOST_CHECK_EQUAL(std::get<OtherObjects<Sub>>(otherObjects).size(), 1);
BOOST_REQUIRE(apply(&Base::add));
BOOST_CHECK_EQUAL(s->total, 2);
const auto i = applyOne(&Base::add);
@@ -76,6 +120,243 @@ BOOST_AUTO_TEST_CASE(a_sub)
BOOST_CHECK_EQUAL(*i, s);
}
+BOOST_AUTO_TEST_CASE(filter)
+{
+ static_assert(TestCollection::idx<Sub>() == 0);
+ static_assert(TestCollection::idx<const Sub>() == 0);
+ static_assert(TestCollection::idx<Sub1>() == 0);
+ static_assert(TestCollection::idx<const Sub1>() == 0);
+ create<Base>();
+ BOOST_CHECK_EQUAL(1, apply<Base>(&Base::yes));
+ BOOST_CHECK_EQUAL(0, apply<Sub>(&Base::yes));
+ BOOST_CHECK_EQUAL(0, apply<Sub1>(&Base::yes));
+ BOOST_CHECK_EQUAL(objects.begin(), applyOne<Base>(&Base::yes));
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).end(), applyOne<Sub>(&Base::yes));
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).end(), applyOne<Sub1>(&Base::yes));
+ create<Sub>();
+ BOOST_CHECK_EQUAL(2, apply<Base>(&Base::yes));
+ BOOST_CHECK_EQUAL(1, apply<Sub>(&Base::yes));
+ BOOST_CHECK_EQUAL(0, apply<Sub1>(&Base::yes));
+ BOOST_CHECK_EQUAL(objects.begin(), applyOne<Base>(&Base::yes));
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).begin(), applyOne<Sub>(&Base::yes));
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).end(), applyOne<Sub1>(&Base::yes));
+ create<Sub1>();
+ BOOST_CHECK_EQUAL(3, apply<Base>(&Base::yes));
+ BOOST_CHECK_EQUAL(2, apply<Sub>(&Base::yes));
+ BOOST_CHECK_EQUAL(1, apply<Sub1>(&Base::yes));
+ BOOST_CHECK_EQUAL(objects.begin(), applyOne<Base>(&Base::yes));
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).begin(), applyOne<Sub>(&Base::yes));
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).begin() + 1, applyOne<Sub1>(&Base::yes));
+
+ BOOST_CHECK_EQUAL(std::get<idx<Sub>()>(otherObjects).size(), 2);
+ BOOST_CHECK_EQUAL(std::get<idx<Sub1>()>(otherObjects).size(), 2);
+
+ BOOST_CHECK_EQUAL(&objects, &containerFor<Base>());
+ BOOST_CHECK_EQUAL(&std::get<0>(otherObjects), &containerFor<Sub>());
+ BOOST_CHECK_EQUAL(&std::get<0>(otherObjects), &containerFor<Sub1>());
+}
+
+BOOST_AUTO_TEST_CASE(begin_end)
+{
+ BOOST_CHECK_EQUAL(0, std::distance(begin(), end()));
+ create<Sub>();
+ create<Base>();
+ BOOST_CHECK_EQUAL(2, std::distance(begin(), end()));
+}
+
+BOOST_AUTO_TEST_CASE(rbegin_rend)
+{
+ BOOST_CHECK_EQUAL(0, std::distance(rbegin(), rend()));
+ create<Sub>();
+ create<Base>();
+ BOOST_CHECK_EQUAL(2, std::distance(rbegin(), rend()));
+}
+
+BOOST_AUTO_TEST_CASE(createCreate)
+{
+ auto b = findOrCreate<Base>();
+ BOOST_CHECK(b);
+ auto b2 = findOrCreate<Base>();
+ BOOST_CHECK_EQUAL(b, b2);
+ auto s = findOrCreate<Sub>();
+ BOOST_CHECK_NE(s, b);
+ auto s2 = findOrCreate<Sub>();
+ BOOST_CHECK_EQUAL(s, s2);
+}
+
+BOOST_AUTO_TEST_CASE(createCreateSub)
+{
+ auto s = findOrCreate<Sub>();
+ auto b = findOrCreate<Base>();
+ BOOST_CHECK_EQUAL(s, b);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+using TestUniqueCollection = UniqueCollection<Base, Sub>;
+BOOST_TEST_DONT_PRINT_LOG_VALUE(TestUniqueCollection::Objects::const_iterator)
+BOOST_TEST_DONT_PRINT_LOG_VALUE(TestUniqueCollection::Objects::const_reverse_iterator)
+BOOST_TEST_DONT_PRINT_LOG_VALUE(TestUniqueCollection::Objects::iterator)
+BOOST_TEST_DONT_PRINT_LOG_VALUE(TestUniqueCollection::Objects::reverse_iterator)
+
+BOOST_FIXTURE_TEST_SUITE(utc, TestUniqueCollection)
+
+BOOST_AUTO_TEST_CASE(unique_create)
+{
+ create<Base>();
+ BOOST_CHECK_EQUAL(objects.size(), 1);
+ BOOST_CHECK(std::get<OtherObjects<Sub>>(otherObjects).empty());
+ create<Sub>();
+ BOOST_CHECK_EQUAL(objects.size(), 2);
+ BOOST_CHECK_EQUAL(std::get<OtherObjects<Sub>>(otherObjects).size(), 1);
+}
+
+BOOST_AUTO_TEST_CASE(move_assign)
+{
+ create<Base>();
+ create<Sub>();
+
+ TestUniqueCollection::Objects other;
+ TestUniqueCollection::operator=(std::move(other));
+ BOOST_CHECK(objects.empty());
+ BOOST_CHECK(std::get<OtherObjects<Sub>>(otherObjects).empty());
+
+ other.push_back(std::make_unique<Sub>());
+ other.push_back(std::make_unique<Base>());
+ TestUniqueCollection::operator=(std::move(other));
+ BOOST_CHECK_EQUAL(objects.size(), 2);
+ BOOST_CHECK_EQUAL(std::get<OtherObjects<Sub>>(otherObjects).size(), 1);
+ BOOST_CHECK(other.empty());
+}
+
+BOOST_AUTO_TEST_CASE(clearAll)
+{
+ create<Base>();
+ create<Sub>();
+ emplace(std::make_unique<Base>());
+ emplace(std::make_unique<Sub>());
+
+ clear();
+ BOOST_CHECK(objects.empty());
+ BOOST_CHECK(std::get<OtherObjects<Sub>>(otherObjects).empty());
+}
+
+BOOST_AUTO_TEST_CASE(removeAllOfSub)
+{
+ create<Base>();
+ create<Sub>();
+ emplace(std::make_unique<Base>());
+ emplace(std::make_unique<Sub>());
+ emplace(std::make_unique<Sub1>());
+
+ BOOST_CHECK_EQUAL(removeAll<Sub>(), 3);
+ BOOST_CHECK_EQUAL(objects.size(), 2);
+ BOOST_CHECK(std::get<OtherObjects<Sub>>(otherObjects).empty());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_FIXTURE_TEST_SUITE(btc, UniqueCollection<Base>)
+
+BOOST_AUTO_TEST_CASE(no_others)
+{
+ create<Base>();
+ create<Sub>();
+ emplace(std::make_unique<Base>());
+ emplace(std::make_unique<Sub>());
+}
+
+BOOST_AUTO_TEST_CASE(applyAll)
+{
+ create<Base>();
+ BOOST_CHECK_EQUAL(0, apply<Sub>(&Base::add));
+ BOOST_CHECK_EQUAL(1, apply<Base>(&Base::add));
+ create<Sub>();
+ BOOST_CHECK_EQUAL(1, apply<Sub>(&Base::add));
+ BOOST_CHECK_EQUAL(2, apply<Base>(&Base::add));
+}
+
+BOOST_AUTO_TEST_CASE(applyOneType)
+{
+ create<Base>();
+ BOOST_CHECK_EQUAL(objects.end(), applyOne<Sub>(&Base::yes));
+ BOOST_CHECK_EQUAL(objects.begin(), applyOne<Base>(&Base::yes));
+ create<Sub>();
+ BOOST_CHECK_EQUAL(objects.begin() + 1, applyOne<Sub>(&Base::yes));
+ BOOST_CHECK_EQUAL(objects.begin(), applyOne<Base>(&Base::yes));
+ create<Sub1>();
+ BOOST_CHECK_EQUAL(objects.begin() + 2, applyOne<Sub1>(&Base::yes));
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+using MultiCollection = Collection<std::unique_ptr<Base>, Multi, Sub, Base2>;
+
+BOOST_FIXTURE_TEST_SUITE(multi, MultiCollection)
+
+BOOST_AUTO_TEST_CASE(addMulti)
+{
+ static_assert(MultiCollection::idx<Multi>() == 0);
+ static_assert(MultiCollection::idx<Sub>() == 1);
+ static_assert(MultiCollection::idx<Base2>() == 2);
+ create<Base>();
+ BOOST_CHECK_EQUAL(objects.size(), 1);
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).size(), 0);
+ BOOST_CHECK_EQUAL(std::get<1>(otherObjects).size(), 0);
+ BOOST_CHECK_EQUAL(std::get<2>(otherObjects).size(), 0);
+ create<Sub>();
+ BOOST_CHECK_EQUAL(objects.size(), 2);
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).size(), 0);
+ BOOST_CHECK_EQUAL(std::get<1>(otherObjects).size(), 1);
+ BOOST_CHECK_EQUAL(std::get<2>(otherObjects).size(), 0);
+ create<Sub1>();
+ BOOST_CHECK_EQUAL(objects.size(), 3);
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).size(), 0);
+ BOOST_CHECK_EQUAL(std::get<1>(otherObjects).size(), 2);
+ BOOST_CHECK_EQUAL(std::get<2>(otherObjects).size(), 0);
+ create<Sub2>();
+ BOOST_CHECK_EQUAL(objects.size(), 4);
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).size(), 0);
+ BOOST_CHECK_EQUAL(std::get<1>(otherObjects).size(), 3);
+ BOOST_CHECK_EQUAL(std::get<2>(otherObjects).size(), 0);
+ create<Multi>();
+ BOOST_CHECK_EQUAL(size(), 5);
+ BOOST_CHECK_EQUAL(size<Multi>(), 1);
+ BOOST_CHECK_EQUAL(size<Sub>(), 4);
+ BOOST_CHECK_EQUAL(size<Base2>(), 1);
+}
+
+BOOST_AUTO_TEST_CASE(removeMulti)
+{
+ create<Base>();
+ create<Sub>();
+ create<Sub1>();
+ create<Sub2>();
+ create<Multi>();
+ BOOST_CHECK_EQUAL(objects.size(), 5);
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).size(), 1);
+ BOOST_CHECK_EQUAL(std::get<1>(otherObjects).size(), 4);
+ BOOST_CHECK_EQUAL(std::get<2>(otherObjects).size(), 1);
+
+ BOOST_CHECK_EQUAL(removeAll<Multi>(), 1);
+ BOOST_CHECK_EQUAL(objects.size(), 4);
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).size(), 0);
+ BOOST_CHECK_EQUAL(std::get<1>(otherObjects).size(), 3);
+ BOOST_CHECK_EQUAL(std::get<2>(otherObjects).size(), 0);
+
+ BOOST_CHECK_EQUAL(removeAll<Sub>(), 3);
+ BOOST_CHECK_EQUAL(objects.size(), 1);
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).size(), 0);
+ BOOST_CHECK_EQUAL(std::get<1>(otherObjects).size(), 0);
+ BOOST_CHECK_EQUAL(std::get<2>(otherObjects).size(), 0);
+
+ BOOST_CHECK_EQUAL(removeAll<Base>(), 1);
+ BOOST_CHECK_EQUAL(objects.size(), 0);
+ BOOST_CHECK_EQUAL(std::get<0>(otherObjects).size(), 0);
+ BOOST_CHECK_EQUAL(std::get<1>(otherObjects).size(), 0);
+ BOOST_CHECK_EQUAL(std::get<2>(otherObjects).size(), 0);
+}
+
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(wrapped_ptr_file_cons)
diff --git a/test/test-lib.cpp b/test/test-lib.cpp
index ec91f6e..a1a8c80 100644
--- a/test/test-lib.cpp
+++ b/test/test-lib.cpp
@@ -46,9 +46,9 @@ BOOST_AUTO_TEST_CASE(generate_move_and_delete)
{
{
TestArray a;
- BOOST_CHECK_EQUAL(TestArray::size, active.size());
+ BOOST_CHECK_EQUAL(TestArray::size(), active.size());
const TestArray b {std::move(a)};
- BOOST_CHECK_EQUAL(TestArray::size, active.size());
+ BOOST_CHECK_EQUAL(TestArray::size(), active.size());
}
BOOST_CHECK(active.empty());
}
diff --git a/test/test-network.cpp b/test/test-network.cpp
index 51fea8b..19a740e 100644
--- a/test/test-network.cpp
+++ b/test/test-network.cpp
@@ -139,83 +139,83 @@ BOOST_DATA_TEST_CASE(newNodeAt_new, INVALID_NODES, p)
BOOST_AUTO_TEST_CASE(network_joins)
{
// Ends
- BOOST_CHECK(links.objects[2]->ends[1].nexts.empty());
+ BOOST_CHECK(links[2]->ends[1].nexts.empty());
// Join 0 <-> 1
- BOOST_REQUIRE_EQUAL(links.objects[0]->ends[1].nexts.size(), 2);
- BOOST_CHECK_EQUAL(links.objects[0]->ends[1].nexts[0].first.lock().get(), links.objects[1].get());
- BOOST_CHECK_EQUAL(links.objects[0]->ends[1].nexts[0].second, 0);
- BOOST_CHECK_EQUAL(links.objects[0]->ends[1].nexts[1].first.lock().get(), links.objects[5].get());
- BOOST_CHECK_EQUAL(links.objects[0]->ends[1].nexts[1].second, 0);
- BOOST_REQUIRE_EQUAL(links.objects[1]->ends[0].nexts.size(), 2);
- BOOST_CHECK_EQUAL(links.objects[1]->ends[0].nexts[0].first.lock().get(), links.objects[0].get());
- BOOST_CHECK_EQUAL(links.objects[1]->ends[0].nexts[0].second, 1);
- BOOST_CHECK_EQUAL(links.objects[1]->ends[0].nexts[1].first.lock().get(), links.objects[5].get());
- BOOST_CHECK_EQUAL(links.objects[1]->ends[0].nexts[1].second, 0);
+ BOOST_REQUIRE_EQUAL(links[0]->ends[1].nexts.size(), 2);
+ BOOST_CHECK_EQUAL(links[0]->ends[1].nexts[0].first.lock().get(), links[1].get());
+ BOOST_CHECK_EQUAL(links[0]->ends[1].nexts[0].second, 0);
+ BOOST_CHECK_EQUAL(links[0]->ends[1].nexts[1].first.lock().get(), links[5].get());
+ BOOST_CHECK_EQUAL(links[0]->ends[1].nexts[1].second, 0);
+ BOOST_REQUIRE_EQUAL(links[1]->ends[0].nexts.size(), 2);
+ BOOST_CHECK_EQUAL(links[1]->ends[0].nexts[0].first.lock().get(), links[0].get());
+ BOOST_CHECK_EQUAL(links[1]->ends[0].nexts[0].second, 1);
+ BOOST_CHECK_EQUAL(links[1]->ends[0].nexts[1].first.lock().get(), links[5].get());
+ BOOST_CHECK_EQUAL(links[1]->ends[0].nexts[1].second, 0);
// Join 1 <-> 2
- BOOST_REQUIRE_EQUAL(links.objects[1]->ends[1].nexts.size(), 2);
- BOOST_CHECK_EQUAL(links.objects[1]->ends[1].nexts[0].first.lock().get(), links.objects[2].get());
- BOOST_CHECK_EQUAL(links.objects[1]->ends[1].nexts[0].second, 0);
- BOOST_REQUIRE_EQUAL(links.objects[2]->ends[0].nexts.size(), 2);
- BOOST_CHECK_EQUAL(links.objects[2]->ends[0].nexts[0].first.lock().get(), links.objects[1].get());
- BOOST_CHECK_EQUAL(links.objects[2]->ends[0].nexts[0].second, 1);
+ BOOST_REQUIRE_EQUAL(links[1]->ends[1].nexts.size(), 2);
+ BOOST_CHECK_EQUAL(links[1]->ends[1].nexts[0].first.lock().get(), links[2].get());
+ BOOST_CHECK_EQUAL(links[1]->ends[1].nexts[0].second, 0);
+ BOOST_REQUIRE_EQUAL(links[2]->ends[0].nexts.size(), 2);
+ BOOST_CHECK_EQUAL(links[2]->ends[0].nexts[0].first.lock().get(), links[1].get());
+ BOOST_CHECK_EQUAL(links[2]->ends[0].nexts[0].second, 1);
}
BOOST_DATA_TEST_CASE(routeTo_nodeNotInNetwork, INVALID_NODES, dest)
{
- const auto & start = links.objects.front()->ends[1];
+ const auto & start = links[0]->ends[1];
BOOST_CHECK_THROW((void)routeFromTo(start, dest), std::out_of_range);
}
BOOST_AUTO_TEST_CASE(routeTo_noSteps)
{
- const auto & start = links.objects.front()->ends[1];
+ const auto & start = links[0]->ends[1];
auto r = this->routeFromTo(start, p100);
BOOST_CHECK(r.empty());
}
BOOST_AUTO_TEST_CASE(routeTo_upStream_to2)
{
- const auto & start = links.objects.front()->ends[1];
+ const auto & start = links[0]->ends[1];
auto r = this->routeFromTo(start, p200);
BOOST_REQUIRE_EQUAL(r.size(), 1);
- BOOST_CHECK_EQUAL(r[0].first.lock().get(), links.objects[1].get());
+ BOOST_CHECK_EQUAL(r[0].first.lock().get(), links[1].get());
}
BOOST_AUTO_TEST_CASE(routeTo_upStream_to3)
{
- const auto & start = links.objects[0]->ends[1];
+ const auto & start = links[0]->ends[1];
auto r = this->routeFromTo(start, p300);
BOOST_REQUIRE_EQUAL(r.size(), 2);
- BOOST_CHECK_EQUAL(r[0].first.lock().get(), links.objects[1].get());
- BOOST_CHECK_EQUAL(r[1].first.lock().get(), links.objects[2].get());
+ BOOST_CHECK_EQUAL(r[0].first.lock().get(), links[1].get());
+ BOOST_CHECK_EQUAL(r[1].first.lock().get(), links[2].get());
}
BOOST_AUTO_TEST_CASE(routeTo_downStream_to0)
{
- const auto & start = links.objects[2]->ends[0];
+ const auto & start = links[2]->ends[0];
auto r = this->routeFromTo(start, p000);
BOOST_REQUIRE_EQUAL(r.size(), 2);
- BOOST_CHECK_EQUAL(r[0].first.lock().get(), links.objects[1].get());
- BOOST_CHECK_EQUAL(r[1].first.lock().get(), links.objects[0].get());
+ BOOST_CHECK_EQUAL(r[0].first.lock().get(), links[1].get());
+ BOOST_CHECK_EQUAL(r[1].first.lock().get(), links[0].get());
}
BOOST_AUTO_TEST_CASE(routeTo_upStream_3to300)
{
- const auto & start = links.objects[3]->ends[1];
+ const auto & start = links[3]->ends[1];
auto r = this->routeFromTo(start, p300);
BOOST_REQUIRE_EQUAL(r.size(), 2);
- BOOST_CHECK_EQUAL(r[0].first.lock().get(), links.objects[4].get());
- BOOST_CHECK_EQUAL(r[1].first.lock().get(), links.objects[2].get());
+ BOOST_CHECK_EQUAL(r[0].first.lock().get(), links[4].get());
+ BOOST_CHECK_EQUAL(r[1].first.lock().get(), links[2].get());
}
BOOST_AUTO_TEST_CASE(routeTo_downStream_3to300)
{
- const auto & start = links.objects[3]->ends[0];
+ const auto & start = links[3]->ends[0];
auto r = this->routeFromTo(start, p300);
BOOST_REQUIRE_EQUAL(r.size(), 3);
- BOOST_CHECK_EQUAL(r[0].first.lock().get(), links.objects[0].get());
- BOOST_CHECK_EQUAL(r[1].first.lock().get(), links.objects[1].get());
- BOOST_CHECK_EQUAL(r[2].first.lock().get(), links.objects[2].get());
+ BOOST_CHECK_EQUAL(r[0].first.lock().get(), links[0].get());
+ BOOST_CHECK_EQUAL(r[1].first.lock().get(), links[1].get());
+ BOOST_CHECK_EQUAL(r[2].first.lock().get(), links[2].get());
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/test-render.cpp b/test/test-render.cpp
index 8390d25..a6e28bc 100644
--- a/test/test-render.cpp
+++ b/test/test-render.cpp
@@ -41,7 +41,7 @@ public:
terrain->point(GeoData::VertexHandle {517}).z = 100'000;
terrain->generateMeshes();
gameState->assets = AssetFactory::loadAll(RESDIR);
- brush47rvc = std::dynamic_pointer_cast<RailVehicleClass>(gameState->assets.at("brush-47"));
+ brush47rvc = gameState->assets.at("brush-47").dynamicCast<RailVehicleClass>();
std::random_device randomdev {};
std::uniform_real_distribution<Angle> rotationDistribution {0, two_pi};
std::uniform_int_distribution<GlobalDistance> positionOffsetDistribution {-1500, +1500};
@@ -57,9 +57,10 @@ public:
train2->bogies.back().setPosition(train2->bogies.back().position() + train2->location.position());
for (auto x = 40000; x < 100000; x += 5000) {
for (auto y = 65000; y < 125000; y += 5000) {
- gameState->world.create<Plant>(
- std::dynamic_pointer_cast<Foliage>(gameState->assets.at(std::format(
- "Tree-{:#02}-{}", treeDistribution(randomdev), treeVariantDistribution(randomdev)))),
+ gameState->world.create<Plant>(gameState->assets
+ .at(std::format("Tree-{:#02}-{}", treeDistribution(randomdev),
+ treeVariantDistribution(randomdev)))
+ .dynamicCast<Foliage>(),
Location {{x + positionOffsetDistribution(randomdev), y + positionOffsetDistribution(randomdev),
1},
{0, rotationDistribution(randomdev), 0}});
@@ -76,7 +77,7 @@ public:
water.render(shader, frustum);
rail.render(shader, frustum);
std::ranges::for_each(gameState->assets, [&shader, &frustum](const auto & asset) {
- if (const auto renderable = std::dynamic_pointer_cast<const Renderable>(asset.second)) {
+ if (const auto renderable = asset.second.template getAs<const Renderable>()) {
renderable->render(shader, frustum);
}
});
@@ -98,7 +99,7 @@ public:
{
terrain->shadows(shadowMapper, frustum);
std::ranges::for_each(gameState->assets, [&shadowMapper, &frustum](const auto & asset) {
- if (const auto renderable = std::dynamic_pointer_cast<const Renderable>(asset.second)) {
+ if (const auto renderable = asset.second.template getAs<const Renderable>()) {
renderable->shadows(shadowMapper, frustum);
}
});
diff --git a/test/test-text.cpp b/test/test-text.cpp
index b0a9503..0729ce8 100644
--- a/test/test-text.cpp
+++ b/test/test-text.cpp
@@ -7,7 +7,6 @@
#include "testMainWindow.h"
#include "testRenderOutput.h"
-#include "ui/text.h"
#include <array>
#include <gfx/models/texture.h>
#include <glm/glm.hpp>
@@ -112,19 +111,6 @@ BOOST_AUTO_TEST_CASE(render_font)
}
}
-BOOST_AUTO_TEST_CASE(render_text)
-{
- TestRenderOutput output;
- glBindFramebuffer(GL_FRAMEBUFFER, output.output);
- glViewport(0, 0, 640, 480);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- Text t {"I Like Trains", *this, {{10, 10}, {200, 40}}, {1, 1, 1}};
- UIShader s {640, 480};
- t.render(s, {});
- Texture::save(output.outImage, "/tmp/text.tga");
-}
-
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(stream_vec)
diff --git a/test/test-ui.cpp b/test/test-ui.cpp
new file mode 100644
index 0000000..2810cda
--- /dev/null
+++ b/test/test-ui.cpp
@@ -0,0 +1,20 @@
+#define BOOST_TEST_MODULE UI
+#include <boost/test/unit_test.hpp>
+#include <stream_support.h>
+
+#include "testMainWindow.h"
+#include <gfx/models/texture.h>
+#include <resource.h>
+#include <ui/svgIcon.h>
+
+constexpr GLsizei RENDER_SIZE = 64;
+
+BOOST_GLOBAL_FIXTURE(TestMainWindowAppBase);
+
+BOOST_AUTO_TEST_CASE(LoadFromFile)
+{
+ SvgIcon svg(ImageDimensions {RENDER_SIZE}, Resource::mapPath("ui/icon/rails.svg"));
+ const auto size = Texture::getSize(svg.texture);
+ BOOST_CHECK_EQUAL(size, TextureDimensions(RENDER_SIZE, RENDER_SIZE, 1));
+ Texture::save(svg.texture, "/tmp/rails.tga");
+}
diff --git a/thirdparty/Jamfile.jam b/thirdparty/Jamfile.jam
index b6ed163..26497c9 100644
--- a/thirdparty/Jamfile.jam
+++ b/thirdparty/Jamfile.jam
@@ -28,3 +28,15 @@ lib imguisdl2 :
: :
<include>imgui
;
+
+lib lunasvg :
+ [ glob lunasvg/source/*.cpp lunasvg/plutovg/source/*.c ]
+ :
+ <link>static
+ <include>lunasvg/include
+ <include>lunasvg/plutovg/include
+ <warnings>off
+ <cflags>-fPIC
+ : :
+ <include>lunasvg/include
+ ;
diff --git a/thirdparty/imgui b/thirdparty/imgui
-Subproject 2db79d0868f7b02d26f7557a72504a0b6f84493
+Subproject b4c96355c9b51b54c4deb52e7d7cdfc7bf79bc2
diff --git a/thirdparty/lunasvg b/thirdparty/lunasvg
new file mode 160000
+Subproject f8aabfb444bb37f69df7290790f57e4a27730a9
diff --git a/ui/builders/freeExtend.cpp b/ui/builders/freeExtend.cpp
index ab5a998..aff7cd7 100644
--- a/ui/builders/freeExtend.cpp
+++ b/ui/builders/freeExtend.cpp
@@ -16,17 +16,17 @@ BuilderFreeExtend::move(
{
if (p1) {
if (const auto p = network->intersectRayNodes(ray)) {
- candidateLinks.objects = network->candidateJoins(*p1, p->pos);
+ candidateLinks = network->candidateJoins(*p1, p->pos);
}
else if (const auto p = geoData->intersectRay(ray)) {
- candidateLinks.objects = network->candidateExtend(*p1, p->first);
+ candidateLinks = network->candidateExtend(*p1, p->first);
}
else {
- candidateLinks.removeAll();
+ candidateLinks.clear();
}
}
else {
- candidateLinks.removeAll();
+ candidateLinks.clear();
}
}
diff --git a/ui/builders/join.cpp b/ui/builders/join.cpp
index 6941e23..f6cbce5 100644
--- a/ui/builders/join.cpp
+++ b/ui/builders/join.cpp
@@ -15,10 +15,10 @@ BuilderJoin::move(Network * network, const GeoData *, const SDL_MouseMotionEvent
{
if (p1) {
if (const auto p = network->intersectRayNodes(ray)) {
- candidateLinks.objects = network->candidateJoins(p1->pos, p->pos);
+ candidateLinks = network->candidateJoins(p1->pos, p->pos);
}
else {
- candidateLinks.removeAll();
+ candidateLinks.clear();
}
}
}
@@ -33,7 +33,7 @@ BuilderJoin::click(
if (p1) {
create(network, geoData, p1, p);
p1.reset();
- candidateLinks.removeAll();
+ candidateLinks.clear();
}
else {
p1 = p;
diff --git a/ui/builders/straight.cpp b/ui/builders/straight.cpp
index 338aa8a..e7d83b5 100644
--- a/ui/builders/straight.cpp
+++ b/ui/builders/straight.cpp
@@ -17,10 +17,10 @@ BuilderStraight::move(
{
if (p1) {
if (const auto p = geoData->intersectRay(ray)) {
- candidateLinks.objects = network->candidateStraight(*p1, p->first);
+ candidateLinks = network->candidateStraight(*p1, p->first);
}
else {
- candidateLinks.removeAll();
+ candidateLinks.clear();
}
}
}
@@ -34,7 +34,7 @@ BuilderStraight::click(
if (const auto p = geoData->intersectRay(ray)) {
if (p1) {
create(network, geoData, *p1, p->first);
- candidateLinks.removeAll();
+ candidateLinks.clear();
p1.reset();
}
else {
@@ -44,7 +44,7 @@ BuilderStraight::click(
return;
case SDL_BUTTON_MIDDLE:
p1.reset();
- candidateLinks.removeAll();
+ candidateLinks.clear();
return;
}
}
diff --git a/ui/editNetwork.cpp b/ui/editNetwork.cpp
index 2887491..c900191 100644
--- a/ui/editNetwork.cpp
+++ b/ui/editNetwork.cpp
@@ -2,25 +2,15 @@
#include "builders/freeExtend.h"
#include "builders/join.h"
#include "builders/straight.h"
-#include "text.h"
+#include "imgui_wrap.h"
#include <game/gamestate.h>
#include <game/terrain.h>
#include <gfx/gl/sceneShader.h>
#include <gfx/models/texture.h>
-const std::filesystem::path fontpath {"/usr/share/fonts/hack/Hack-Regular.ttf"};
constexpr const glm::u8vec4 TRANSPARENT_BLUE {30, 50, 255, 200};
-EditNetwork::EditNetwork(Network * n) :
- network {n},
- builderToolbar {
- {"ui/icon/network.png", mode.toggle<BuilderStraight>()},
- {"ui/icon/network.png", mode.toggle<BuilderJoin>()},
- {"ui/icon/network.png", mode.toggle<BuilderFreeExtend>()},
- },
- blue {1, 1, &TRANSPARENT_BLUE}, font {fontpath, 15}
-{
-}
+EditNetwork::EditNetwork(Network * n) : network {n}, blue {1, 1, &TRANSPARENT_BLUE} { }
bool
EditNetwork::click(const SDL_MouseButtonEvent & e, const Ray<GlobalPosition3D> & ray)
@@ -42,9 +32,9 @@ EditNetwork::move(const SDL_MouseMotionEvent & e, const Ray<GlobalPosition3D> &
}
bool
-EditNetwork::handleInput(const SDL_Event & e, const UIComponent::Position & parentPos)
+EditNetwork::handleInput(const SDL_Event &)
{
- return builderToolbar.handleInput(e, parentPos);
+ return false;
}
void
@@ -75,10 +65,20 @@ EditNetwork::Builder::setHeightsFor(Network * network, const Link::CCollection &
}
void
-EditNetwork::render(const UIShader & shader, const UIComponent::Position & parentPos) const
+EditNetwork::render(bool & open)
{
- if (builder) {
- Text {builder->hint(), font, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos);
- }
- builderToolbar.render(shader, parentPos);
+ ImGui::SetNextWindowSize({-1, -1});
+ ImGui::Begin("Edit Network", &open);
+
+ auto builderChoice = [this]<typename Impl>(const char * name) {
+ if (ImGui::RadioButton(name, dynamic_cast<Impl *>(builder.get()))) {
+ builder = std::make_unique<Impl>();
+ }
+ };
+ builderChoice.operator()<BuilderStraight>("Straight");
+ builderChoice.operator()<BuilderJoin>("Join");
+ builderChoice.operator()<BuilderFreeExtend>("Free Extend");
+ ImGui::TextUnformatted(builder ? builder->hint().c_str() : "Select a build mode");
+
+ ImGui::End();
}
diff --git a/ui/editNetwork.h b/ui/editNetwork.h
index ae887bd..4155534 100644
--- a/ui/editNetwork.h
+++ b/ui/editNetwork.h
@@ -2,8 +2,6 @@
#include "game/geoData.h"
#include "gameMainSelector.h"
-#include "modeHelper.h"
-#include "toolbar.h"
#include "worldOverlay.h"
#include <game/gamestate.h>
#include <game/network/network.h>
@@ -17,9 +15,9 @@ public:
bool click(const SDL_MouseButtonEvent & e, const Ray<GlobalPosition3D> &) override;
bool move(const SDL_MouseMotionEvent & e, const Ray<GlobalPosition3D> &) override;
- bool handleInput(const SDL_Event & e, const UIComponent::Position &) override;
+ bool handleInput(const SDL_Event & e) override;
void render(const SceneShader &, const Frustum &) const override;
- void render(const UIShader & shader, const UIComponent::Position & pos) const override;
+ void render(bool & open) override;
using NetworkClickPos = std::variant<GlobalPosition3D, Node::Ptr>;
@@ -36,16 +34,13 @@ public:
using Ptr = std::unique_ptr<Builder>;
protected:
- Collection<const Link> candidateLinks;
+ SharedCollection<const Link> candidateLinks;
};
private:
Network * network;
Builder::Ptr builder;
- Mode<Builder::Ptr, ModeSecondClick::NoAction> mode {builder};
- Toolbar builderToolbar;
Texture blue;
- const Font font;
};
template<typename T> class EditNetworkOf : public EditNetwork {
diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp
index 23ae8c0..0c40abc 100644
--- a/ui/gameMainSelector.cpp
+++ b/ui/gameMainSelector.cpp
@@ -1,6 +1,4 @@
#include "gameMainSelector.h"
-#include "collection.h"
-#include "text.h"
#include "ui/uiComponent.h"
#include <SDL2/SDL.h>
#include <game/gamestate.h>
@@ -8,27 +6,21 @@
#include <game/terrain.h>
#include <game/worldobject.h> // IWYU pragma: keep
#include <gfx/camera.h>
-#include <optional>
#include <stream_support.h>
-#include <typeinfo>
-const std::filesystem::path fontpath {"/usr/share/fonts/hack/Hack-Regular.ttf"};
-
-GameMainSelector::GameMainSelector(const Camera * c, ScreenAbsCoord size) :
- UIComponent {{{}, size}}, camera {c}, font {fontpath, 15}
-{
-}
+GameMainSelector::GameMainSelector(const Camera * c) : camera {c} { }
constexpr ScreenAbsCoord TargetPos {5, 45};
void
-GameMainSelector::render(const UIShader & shader, const Position & parentPos) const
+GameMainSelector::render()
{
if (target) {
- target->render(shader, parentPos + position + TargetPos);
- }
- if (!clicked.empty()) {
- Text {clicked, font, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos);
+ bool open = true;
+ target->render(open);
+ if (!open) {
+ target.reset();
+ }
}
}
@@ -41,10 +33,12 @@ GameMainSelector::render(const SceneShader & shader, const Frustum & frustum) co
}
bool
-GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos)
+GameMainSelector::handleInput(const SDL_Event & e)
{
- const auto getRay = [this](const auto & e) {
- const auto mouse = ScreenRelCoord {e.x, e.y} / position.size;
+ const auto getRay = [this, &window = e.window](const auto & e) {
+ glm::ivec2 size {};
+ SDL_GetWindowSizeInPixels(SDL_GetWindowFromID(window.windowID), &size.x, &size.y);
+ const auto mouse = ScreenRelCoord {e.x, e.y} / ScreenRelCoord {size};
return camera->unProject(mouse);
};
if (target) {
@@ -60,7 +54,7 @@ GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos)
}
break;
}
- return target->handleInput(e, parentPos + position + TargetPos);
+ return target->handleInput(e);
}
else {
switch (e.type) {
@@ -73,22 +67,8 @@ GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos)
}
void
-GameMainSelector::defaultClick(const Ray<GlobalPosition3D> & ray)
+GameMainSelector::defaultClick(const Ray<GlobalPosition3D> &)
{
- BaryPosition baryPos {};
- RelativeDistance distance {};
-
- if (const auto selected = gameState->world.applyOne<Selectable>(&Selectable::intersectRay, ray, baryPos, distance);
- selected != gameState->world.end()) {
- const auto & ref = *selected.base()->get();
- clicked = typeid(ref).name();
- }
- else if (const auto pos = gameState->terrain->intersectRay(ray)) {
- clicked = streamed_string(*pos);
- }
- else {
- clicked.clear();
- }
}
bool
@@ -104,13 +84,13 @@ GameMainSelector::Component::move(const SDL_MouseMotionEvent &, const Ray<Global
}
bool
-GameMainSelector::Component::handleInput(const SDL_Event &, const Position &)
+GameMainSelector::Component::handleInput(const SDL_Event &)
{
return false;
}
void
-GameMainSelector::Component::render(const UIShader &, const UIComponent::Position &) const
+GameMainSelector::Component::render(bool &)
{
}
diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h
index e715823..8c2be4b 100644
--- a/ui/gameMainSelector.h
+++ b/ui/gameMainSelector.h
@@ -2,16 +2,13 @@
#include "SDL_events.h"
#include "config/types.h"
-#include "font.h"
#include "uiComponent.h"
#include "worldOverlay.h"
#include <glm/glm.hpp>
#include <memory>
-#include <string>
class SceneShader;
template<typename> class Ray;
-class UIShader;
class Camera;
class GameMainSelector : public UIComponent, public WorldOverlay {
@@ -22,17 +19,17 @@ public:
virtual bool click(const SDL_MouseButtonEvent &, const Ray<GlobalPosition3D> &);
virtual bool move(const SDL_MouseMotionEvent &, const Ray<GlobalPosition3D> &);
- virtual bool handleInput(const SDL_Event &, const Position & pos);
- virtual void render(const UIShader & shader, const Position & pos) const;
+ virtual bool handleInput(const SDL_Event &);
+ virtual void render(bool & open);
virtual void render(const SceneShader &, const Frustum &) const;
};
- GameMainSelector(const Camera * c, ScreenAbsCoord size);
+ GameMainSelector(const Camera * c);
- void render(const UIShader & shader, const Position & pos) const override;
+ void render() override;
void render(const SceneShader & shader, const Frustum &) const override;
- bool handleInput(const SDL_Event & e, const Position &) override;
+ bool handleInput(const SDL_Event & e) override;
void defaultClick(const Ray<GlobalPosition3D> & ray);
@@ -40,6 +37,4 @@ public:
private:
const Camera * camera;
- const Font font;
- std::string clicked;
};
diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp
index d88bab5..cc74f66 100644
--- a/ui/gameMainWindow.cpp
+++ b/ui/gameMainWindow.cpp
@@ -1,10 +1,10 @@
#include "gameMainWindow.h"
#include "editNetwork.h"
#include "gameMainSelector.h"
+#include "imgui_extras.h"
#include "manualCameraController.h"
-#include "modeHelper.h"
-#include "toolbar.h"
-#include "window.h"
+#include "queryTool.h"
+#include "svgIcon.h"
#include <SDL2/SDL.h>
#include <collection.h>
#include <game/environment.h>
@@ -17,22 +17,44 @@
#include <glm/glm.hpp>
#include <memory>
-class GameMainToolbar : Mode<decltype(GameMainSelector::target)>, public Toolbar {
+class GameMainToolbar : public UIComponent {
public:
- explicit GameMainToolbar(GameMainSelector * gms_) :
- Mode<decltype(GameMainSelector::target)> {gms_->target},
- Toolbar {
- {"ui/icon/network.png", toggle<EditNetworkOf<RailLinks>>()},
+ static constexpr auto TOOLBAR_HEIGHT = 54.F;
+ template<typename T> static constexpr T TOOLBAR_ICON_SIZE {32, 32};
+
+ explicit GameMainToolbar(GameMainSelector * gms) : gms {gms} { }
+
+ void
+ render() override
+ {
+ if (IltGui::BeginToolbar("bottomBar", ImGuiDir_Down, TOOLBAR_HEIGHT)) {
+ if (ImGui::ImageButton("Build rails", *buildRailsIcon, TOOLBAR_ICON_SIZE<ImVec2>)) {
+ gms->target = std::make_unique<EditNetworkOf<RailLinks>>();
+ }
+ if (ImGui::ImageButton("Query", *queryToolIcon, TOOLBAR_ICON_SIZE<ImVec2>)) {
+ gms->target = std::make_unique<QueryTool>();
+ }
+ IltGui::EndToolbar();
}
+ }
+
+ bool
+ handleInput(const SDL_Event &) override
{
+ return false;
}
+
+private:
+ SvgIcon buildRailsIcon {TOOLBAR_ICON_SIZE<ImageDimensions>, "ui/icon/rails.svg"};
+ SvgIcon queryToolIcon {TOOLBAR_ICON_SIZE<ImageDimensions>, "ui/icon/magnifier.svg"};
+ GameMainSelector * gms;
};
-GameMainWindow::GameMainWindow(size_t w, size_t h) : WindowContent {w, h}, SceneRenderer {{w, h}, 0}
+GameMainWindow::GameMainWindow(size_t w, size_t h) : SceneRenderer {{w, h}, 0}
{
uiComponents.create<ManualCameraController>(glm::vec2 {310'727'624, 494'018'810});
- auto gms = uiComponents.create<GameMainSelector>(&camera, ScreenAbsCoord {w, h});
- uiComponents.create<GameMainToolbar>(gms.get());
+ auto gms = uiComponents.create<GameMainSelector>(&camera);
+ uiComponents.create<GameMainToolbar>(gms);
}
GameMainWindow::~GameMainWindow() { }
@@ -69,18 +91,18 @@ GameMainWindow::render() const
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
- uiComponents.apply(&UIComponent::render, uiShader, UIComponent::Position {});
+ uiComponents.apply(&UIComponent::render);
}
void
GameMainWindow::content(const SceneShader & shader, const Frustum & frustum) const
{
- for (const auto & [id, asset] : gameState->assets) {
- if (const auto r = std::dynamic_pointer_cast<const Renderable>(asset)) {
- r->render(shader, frustum);
+ for (const auto & [assetId, asset] : gameState->assets) {
+ if (const auto renderable = asset.getAs<const Renderable>()) {
+ renderable->render(shader, frustum);
}
}
- gameState->world.apply<Renderable>(&Renderable::render, shader, frustum);
+ gameState->world.apply<const Renderable>(&Renderable::render, shader, frustum);
uiComponents.apply<WorldOverlay>(&WorldOverlay::render, shader, frustum);
}
@@ -93,16 +115,16 @@ GameMainWindow::environment(const SceneShader &, const SceneRenderer & r) const
void
GameMainWindow::lights(const SceneShader & shader) const
{
- gameState->world.apply<Renderable>(&Renderable::lights, shader);
+ gameState->world.apply<const Renderable>(&Renderable::lights, shader);
}
void
GameMainWindow::shadows(const ShadowMapper & shadowMapper, const Frustum & frustum) const
{
- for (const auto & [id, asset] : gameState->assets) {
- if (const auto r = std::dynamic_pointer_cast<const Renderable>(asset)) {
- r->shadows(shadowMapper, frustum);
+ for (const auto & [assetId, asset] : gameState->assets) {
+ if (const auto renderable = asset.getAs<const Renderable>()) {
+ renderable->shadows(shadowMapper, frustum);
}
}
- gameState->world.apply<Renderable>(&Renderable::shadows, shadowMapper, frustum);
+ gameState->world.apply<const Renderable>(&Renderable::shadows, shadowMapper, frustum);
}
diff --git a/ui/icon.cpp b/ui/icon.cpp
index c3b5078..0bdc91a 100644
--- a/ui/icon.cpp
+++ b/ui/icon.cpp
@@ -22,9 +22,10 @@ Icon::Icon(const Image & tex) : size {tex.width, tex.height}
GL_RGBA, GL_UNSIGNED_BYTE, tex.data.data());
}
-void
-Icon::Bind() const
+ImTextureID
+Icon::operator*() const
{
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, m_texture);
+ static_assert(sizeof(m_texture) <= sizeof(ImTextureID));
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,performance-no-int-to-ptr) This is how ImGui works
+ return reinterpret_cast<ImTextureID>(*m_texture);
}
diff --git a/ui/icon.h b/ui/icon.h
index 76cd3ae..3d0788a 100644
--- a/ui/icon.h
+++ b/ui/icon.h
@@ -1,5 +1,6 @@
#pragma once
+#include "imgui_wrap.h"
#include <filesystem>
#include <glArrays.h>
#include <glm/glm.hpp>
@@ -11,8 +12,8 @@ public:
explicit Icon(const std::filesystem::path & fileName);
explicit Icon(const Image & image);
- void Bind() const;
const glm::vec2 size;
+ ImTextureID operator*() const;
private:
glTexture m_texture;
diff --git a/ui/iconButton.cpp b/ui/iconButton.cpp
deleted file mode 100644
index fe8c817..0000000
--- a/ui/iconButton.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#include "iconButton.h"
-#include "glArrays.h"
-#include "ui/icon.h"
-#include "ui/uiComponent.h"
-#include <SDL2/SDL.h>
-#include <array>
-#include <filesystem>
-#include <functional>
-#include <glad/gl.h>
-#include <glm/gtc/type_ptr.hpp>
-#include <utility>
-
-IconButton::IconButton(const std::string & icon_, glm::vec2 position_, UIEvent click_) :
- UIComponent {{position_, ICON_SIZE}}, icon {icon_}, click {std::move(click_)}
-{
- glBindVertexArray(m_vertexArrayObject);
-
- glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffer);
- glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizeiptr>(sizeof(glm::vec4) * 4), nullptr, GL_DYNAMIC_DRAW);
-
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(glm::vec4), nullptr);
-
- glBindVertexArray(0);
-}
-
-void
-IconButton::render(const UIShader &, const Position & parentPos) const
-{
- icon.Bind();
- glBindVertexArray(m_vertexArrayObject);
- glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffer);
- const auto abs = parentPos.origin + position.origin;
- const auto limit = abs + ICON_SIZE;
- std::array<glm::vec4, 4> vertices {{
- {abs.x, abs.y, 0, 0},
- {limit.x, abs.y, 1, 0},
- {limit.x, limit.y, 1, 1},
- {abs.x, limit.y, 0, 1},
- }};
- glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), glm::value_ptr(vertices.front()));
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glBindVertexArray(0);
-}
-
-bool
-IconButton::handleInput(const SDL_Event & e, const Position & parentPos)
-{
- const auto absPos = position + parentPos;
- if (absPos & e.button) {
- if (e.button.type == SDL_MOUSEBUTTONUP && e.button.button == SDL_BUTTON_LEFT) {
- click(e);
- }
- }
- return false;
-}
diff --git a/ui/iconButton.h b/ui/iconButton.h
deleted file mode 100644
index 0afe92d..0000000
--- a/ui/iconButton.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#pragma once
-
-#include "icon.h"
-#include "uiComponent.h"
-#include <glArrays.h>
-#include <glm/glm.hpp>
-#include <string>
-
-class UIShader;
-union SDL_Event;
-
-static const constexpr glm::vec2 ICON_SIZE {32.F, 32.F};
-
-class IconButton : public UIComponent {
-public:
- IconButton(const std::string & icon, glm::vec2 position, UIEvent click);
-
- void render(const UIShader &, const Position & parentPos) const override;
-
- bool handleInput(const SDL_Event & e, const Position & parentPos) override;
-
- Icon icon;
- UIEvent click;
- glVertexArray m_vertexArrayObject;
- glBuffer m_vertexArrayBuffer;
-};
diff --git a/ui/imgui_extras.cpp b/ui/imgui_extras.cpp
new file mode 100644
index 0000000..1643f4f
--- /dev/null
+++ b/ui/imgui_extras.cpp
@@ -0,0 +1,33 @@
+#define IMGUI_INTERNAL
+#include "imgui_extras.h"
+
+namespace IltGui {
+ bool
+ BeginToolbar(const char * name, ImGuiDir dir, float axisSize, ImGuiWindowFlags windowFlags)
+ {
+ return BeginToolbar(name, ImGui::GetMainViewport(), dir, axisSize, windowFlags);
+ }
+
+ bool
+ BeginToolbar(
+ const char * name, ImGuiViewport * viewport, ImGuiDir dir, float axisSize, ImGuiWindowFlags windowFlags)
+ {
+ bool isOpen = ImGui::BeginViewportSideBar(name, viewport, dir, axisSize,
+ windowFlags | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings);
+ if (isOpen) {
+ if (dir == ImGuiDir_Up || dir == ImGuiDir_Down) {
+ ImGui::GetCurrentWindow()->DC.LayoutType = ImGuiLayoutType_Horizontal;
+ }
+ }
+ else {
+ ImGui::End();
+ }
+ return isOpen;
+ }
+
+ void
+ EndToolbar()
+ {
+ ImGui::End();
+ }
+}
diff --git a/ui/imgui_extras.h b/ui/imgui_extras.h
new file mode 100644
index 0000000..0babaa3
--- /dev/null
+++ b/ui/imgui_extras.h
@@ -0,0 +1,10 @@
+#include "imgui_wrap.h"
+
+namespace IltGui {
+ // NOLINTBEGIN(readability-identifier-naming)
+ bool BeginToolbar(const char * name, ImGuiViewport * viewport, ImGuiDir dir, float axisSize,
+ ImGuiWindowFlags windowFlags = 0);
+ bool BeginToolbar(const char * name, ImGuiDir dir, float axisSize, ImGuiWindowFlags windowFlags = 0);
+ void EndToolbar();
+ // NOLINTEND(readability-identifier-naming)
+}
diff --git a/ui/imgui_wrap.h b/ui/imgui_wrap.h
index 1d619a4..520d8b8 100644
--- a/ui/imgui_wrap.h
+++ b/ui/imgui_wrap.h
@@ -3,4 +3,11 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#include "imgui.h" // IWYU pragma: export
+#ifdef IMGUI_INTERNAL
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wconversion"
+# pragma GCC diagnostic ignored "-Wsign-conversion"
+# include "imgui_internal.h" // IWYU pragma: export
+# pragma GCC diagnostic pop
+#endif
#pragma GCC diagnostic pop
diff --git a/ui/mainApplication.h b/ui/mainApplication.h
index a6cb126..1489587 100644
--- a/ui/mainApplication.h
+++ b/ui/mainApplication.h
@@ -6,7 +6,7 @@
class MainApplication : public ApplicationBase {
public:
- using Windows = Collection<Window>;
+ using Windows = SharedCollection<Window>;
void mainLoop();
protected:
diff --git a/ui/manualCameraController.cpp b/ui/manualCameraController.cpp
index fbd0ca3..553afc1 100644
--- a/ui/manualCameraController.cpp
+++ b/ui/manualCameraController.cpp
@@ -5,7 +5,7 @@
#include <maths.h>
bool
-ManualCameraController::handleInput(const SDL_Event & e, const Position &)
+ManualCameraController::handleInput(const SDL_Event & e)
{
switch (e.type) {
case SDL_KEYDOWN:
@@ -72,7 +72,7 @@ ManualCameraController::handleInput(const SDL_Event & e, const Position &)
}
void
-ManualCameraController::render(const UIShader &, const Position &) const
+ManualCameraController::render()
{
}
diff --git a/ui/manualCameraController.h b/ui/manualCameraController.h
index 2f955e7..6501762 100644
--- a/ui/manualCameraController.h
+++ b/ui/manualCameraController.h
@@ -6,15 +6,14 @@
#include <glm/glm.hpp>
#include <maths.h>
-class UIShader;
class Camera;
class ManualCameraController : public CameraController, public UIComponent {
public:
- explicit ManualCameraController(GlobalPosition2D f) : UIComponent {{}}, focus {f} { }
+ explicit ManualCameraController(GlobalPosition2D f) : focus {f} { }
- bool handleInput(const SDL_Event & e, const Position &) override;
- void render(const UIShader &, const Position & parentPos) const override;
+ bool handleInput(const SDL_Event & e) override;
+ void render() override;
void updateCamera(Camera * camera) const override;
diff --git a/ui/modeHelper.h b/ui/modeHelper.h
deleted file mode 100644
index d20f2db..0000000
--- a/ui/modeHelper.h
+++ /dev/null
@@ -1,40 +0,0 @@
-#pragma once
-
-#include <memory>
-union SDL_Event;
-
-enum ModeSecondClick { Unset, Reset, NoAction };
-
-template<typename Target, ModeSecondClick msc = ModeSecondClick::Unset> class Mode {
-public:
- explicit Mode(Target & t) : target {t} { }
-
- Target & target;
-
- template<typename Mode, typename... Params>
- auto
- toggle(Params &&... params)
- {
- return [params..., this](const SDL_Event &) {
- toggleSetMode<Mode>(std::forward<Params>(params)...);
- };
- }
-
-private:
- template<typename Mode, typename... Params>
- void
- toggleSetMode(Params &&... params)
- {
- if (dynamic_cast<Mode *>(target.get())) {
- if constexpr (msc == ModeSecondClick::Unset) {
- target.reset();
- }
- if constexpr (msc == ModeSecondClick::Reset) {
- target = std::make_unique<Mode>(std::forward<Params>(params)...);
- }
- }
- else {
- target = std::make_unique<Mode>(std::forward<Params>(params)...);
- }
- }
-};
diff --git a/ui/queryTool.cpp b/ui/queryTool.cpp
new file mode 100644
index 0000000..549bd9e
--- /dev/null
+++ b/ui/queryTool.cpp
@@ -0,0 +1,42 @@
+#include "queryTool.h"
+#include "imgui_wrap.h"
+#include <game/gamestate.h>
+#include <game/selectable.h>
+#include <game/terrain.h>
+#include <game/worldobject.h>
+#include <ray.h>
+#include <stream_support.h>
+
+QueryTool::QueryTool() : clicked {"Click something for details"} { }
+
+bool
+QueryTool::click(const SDL_MouseButtonEvent & event, const Ray<GlobalPosition3D> & ray)
+{
+ if (event.button != SDL_BUTTON_LEFT) {
+ return false;
+ }
+ BaryPosition baryPos {};
+ RelativeDistance distance {};
+
+ if (const auto selected = gameState->world.applyOne<Selectable>(&Selectable::intersectRay, ray, baryPos, distance);
+ selected != gameState->world.end()) {
+ const auto & ref = *selected.base()->get();
+ clicked = typeid(ref).name();
+ }
+ else if (const auto pos = gameState->terrain->intersectRay(ray)) {
+ clicked = streamed_string(*pos);
+ }
+ else {
+ clicked.clear();
+ }
+ return true;
+}
+
+void
+QueryTool::render(bool & open)
+{
+ ImGui::SetNextWindowSize({-1, -1});
+ ImGui::Begin("Query Tool", &open);
+ ImGui::TextUnformatted(clicked.c_str());
+ ImGui::End();
+}
diff --git a/ui/queryTool.h b/ui/queryTool.h
new file mode 100644
index 0000000..74c5380
--- /dev/null
+++ b/ui/queryTool.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "gameMainSelector.h"
+
+class QueryTool : public GameMainSelector::Component {
+public:
+ QueryTool();
+
+protected:
+ using GameMainSelector::Component::render;
+
+ bool click(const SDL_MouseButtonEvent &, const Ray<GlobalPosition3D> &) override;
+ void render(bool & open) override;
+
+private:
+ std::string clicked;
+};
diff --git a/ui/svgIcon.cpp b/ui/svgIcon.cpp
new file mode 100644
index 0000000..499d9cc
--- /dev/null
+++ b/ui/svgIcon.cpp
@@ -0,0 +1,34 @@
+#include "svgIcon.h"
+#include "gl_traits.h"
+#include <resource.h>
+
+SvgIcon::SvgIcon(ImageDimensions dim, const std::filesystem::path & path)
+{
+ const auto svgDoc = lunasvg::Document::loadFromFile(Resource::mapPath(path).native());
+ if (!svgDoc) {
+ throw std::runtime_error("Failed to load SVG from " + path.string());
+ }
+
+ auto bitmap = svgDoc->renderToBitmap(dim.x, dim.y);
+ if (bitmap.isNull()) {
+ throw std::runtime_error("Failed to render SVG " + path.string());
+ }
+ bitmap.convertToRGBA();
+
+ glBindTexture(GL_TEXTURE_2D, texture);
+
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dim.x, dim.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap.data());
+}
+
+ImTextureID
+SvgIcon::operator*() const
+{
+ static_assert(sizeof(glTexture) <= sizeof(ImTextureID));
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,performance-no-int-to-ptr) This is how ImGui works
+ return reinterpret_cast<ImTextureID>(*texture);
+}
diff --git a/ui/svgIcon.h b/ui/svgIcon.h
new file mode 100644
index 0000000..106f97c
--- /dev/null
+++ b/ui/svgIcon.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "glArrays.h"
+#include "imgui_wrap.h"
+#include <config/types.h>
+#include <filesystem>
+#include <lunasvg.h>
+
+class SvgIcon {
+public:
+ SvgIcon(ImageDimensions, const std::filesystem::path &);
+
+ ImTextureID operator*() const;
+
+private:
+ friend class LoadFromFile; // Test case verifying size/content
+ glTexture texture;
+};
diff --git a/ui/text.cpp b/ui/text.cpp
deleted file mode 100644
index bdaaba5..0000000
--- a/ui/text.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#include "text.h"
-#include "font.h"
-#include "gfx/gl/uiShader.h"
-#include "gfx/gl/vertexArrayObject.h"
-#include "uiComponent.h"
-#include <array>
-#include <collections.h>
-#include <glArrays.h>
-#include <glm/gtc/type_ptr.hpp>
-#include <maths.h>
-#include <numeric>
-#include <utility>
-
-Text::Text(std::string_view s, const Font & font, Position pos, glm::vec3 c) :
- UIComponent {pos}, colour {c}, font {font}
-{
- VertexArrayObject {vao}.addAttribs<Font::Quad::value_type>(quads.bufferName(), 0);
- operator=(s);
-}
-
-Text &
-Text::operator=(const std::string_view s)
-{
- auto tquads = font.render(s);
- models.resize(tquads.size());
- const auto glyphCount = std::accumulate(tquads.begin(), tquads.end(), size_t {}, [](auto && init, const auto & q) {
- return init += q.second.size();
- });
- quads.resize(glyphCount);
- GLushort current = 0;
- auto model = models.begin();
- auto quad = quads.begin();
- for (const auto & [texture, fquads] : tquads) {
- model->textureId = texture;
- model->range.resize(fquads.size() * 6);
- for (auto out = model->range.begin(); const auto & q [[maybe_unused]] : fquads) {
- static constexpr std::array<GLushort, 6> quadIndices {0, 1, 2, 2, 3, 0};
- std::transform(quadIndices.begin(), quadIndices.end(), out, [current](auto x) {
- return current + x;
- });
- current += 4;
- out += 6;
- }
- model++;
- quad = std::transform(fquads.begin(), fquads.end(), quad, [this](const Font::Quad & q) {
- return q * [this](const glm::vec4 & corner) {
- return corner + glm::vec4 {this->position.origin, 0, 0};
- };
- });
- }
- quads.unmap();
- return *this;
-}
-
-void
-Text::render(const UIShader & shader, const Position &) const
-{
- shader.text.use(colour);
- glActiveTexture(GL_TEXTURE0);
- glBindVertexArray(vao);
- for (const auto & m : models) {
- glBindTexture(GL_TEXTURE_2D, m.textureId);
- glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(m.range.size()), GL_UNSIGNED_SHORT, m.range.data());
- }
- glBindVertexArray(0);
- glBindTexture(GL_TEXTURE_2D, 0);
-}
-
-bool
-Text::handleInput(const SDL_Event &, const Position &)
-{
- return false;
-}
diff --git a/ui/text.h b/ui/text.h
deleted file mode 100644
index a367456..0000000
--- a/ui/text.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#pragma once
-
-#include "font.h"
-#include "glContainer.h"
-#include "uiComponent.h"
-#include <glArrays.h>
-#include <glad/gl.h>
-#include <glm/glm.hpp>
-#include <string_view>
-
-class UIShader;
-union SDL_Event;
-
-class Text : public UIComponent {
-public:
- Text(std::string_view s, const Font &, Position, glm::vec3 colour);
-
- void render(const UIShader &, const Position & parentPos) const override;
- bool handleInput(const SDL_Event &, const Position & parentPos) override;
-
- Text & operator=(const std::string_view s);
-
-private:
- struct TextData {
- GLuint textureId;
- std::vector<unsigned short> range;
- };
-
- std::vector<TextData> models;
- glContainer<Font::Quad> quads;
- glVertexArray vao;
- glm::vec3 colour;
- const Font & font;
-};
diff --git a/ui/toolbar.cpp b/ui/toolbar.cpp
deleted file mode 100644
index 31d87dc..0000000
--- a/ui/toolbar.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "toolbar.h"
-#include "gfx/gl/uiShader.h"
-#include "ui/iconButton.h"
-#include "ui/uiComponent.h"
-#include "uiComponentPlacer.h"
-#include <SDL2/SDL.h>
-#include <glm/glm.hpp>
-
-Toolbar::Toolbar(const std::initializer_list<InitInfo> & initInfo) : UIComponent {{{}, {}}}
-{
- UIComponentPlacer placer {{10, 10}, 5, 1};
- for (const auto & ii : initInfo) {
- icons.create(ii.first, placer.next(ICON_SIZE), ii.second);
- }
- this->position.size = placer.getLimit();
-}
-
-void
-Toolbar::render(const UIShader & uiShader, const Position & parentPos) const
-{
- uiShader.icon.use();
- const auto absPos = this->position + parentPos;
- icons.apply(&UIComponent::render, uiShader, absPos);
-}
-
-bool
-Toolbar::handleInput(const SDL_Event & e, const Position & parentPos)
-{
- const auto absPos = this->position + parentPos;
- if (absPos & e.button) {
- icons.applyOne(&UIComponent::handleInput, e, absPos);
- return true;
- }
- return false;
-}
diff --git a/ui/toolbar.h b/ui/toolbar.h
deleted file mode 100644
index ea560f5..0000000
--- a/ui/toolbar.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-
-#include "collection.h"
-#include "iconButton.h"
-#include "uiComponent.h"
-#include <initializer_list>
-#include <string>
-#include <utility>
-
-class UIShader;
-union SDL_Event;
-
-class Toolbar : public UIComponent {
-public:
- using InitInfo = std::pair<std::string, UIEvent>;
- explicit Toolbar(const std::initializer_list<InitInfo> & initInfo);
-
- void render(const UIShader & uiShader, const Position & parentPos) const override;
-
- bool handleInput(const SDL_Event & e, const Position & parentPos) override;
-
- Collection<IconButton, false> icons;
-};
diff --git a/ui/uiComponent.cpp b/ui/uiComponent.cpp
deleted file mode 100644
index aa4838d..0000000
--- a/ui/uiComponent.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "uiComponent.h"
-#include <SDL2/SDL.h>
-
-UIComponent::UIComponent(Position position) : position {position} { }
-
-UIComponent::Position
-UIComponent::Position::operator+(const Position & parentPos) const
-{
- return *this + parentPos.origin;
-}
-
-UIComponent::Position
-UIComponent::Position::operator+(const glm::vec2 & parentPos) const
-{
- return {origin + parentPos, size};
-}
-
-bool
-UIComponent::Position::operator&(const glm::vec2 & pos) const
-{
- return (pos.x >= origin.x && pos.y >= origin.y && pos.x < origin.x + size.x && pos.y < origin.y + size.y);
-}
-
-bool
-UIComponent::Position::operator&(const SDL_MouseButtonEvent & pos) const
-{
- switch (pos.type) {
- case SDL_MOUSEBUTTONUP:
- case SDL_MOUSEBUTTONDOWN:
- return *this & glm::vec2 {pos.x, pos.y};
- }
- return false;
-}
diff --git a/ui/uiComponent.h b/ui/uiComponent.h
index 71d2659..b2c1a8f 100644
--- a/ui/uiComponent.h
+++ b/ui/uiComponent.h
@@ -1,32 +1,18 @@
#pragma once
-#include <functional>
#include <glm/glm.hpp>
#include <special_members.h>
-class UIShader;
union SDL_Event;
-struct SDL_MouseButtonEvent;
-using UIEvent = std::function<void(const SDL_Event &)>;
class UIComponent {
public:
- struct Position {
- glm::vec2 origin, size;
- Position operator+(const Position &) const;
- Position operator+(const glm::vec2 &) const;
- bool operator&(const SDL_MouseButtonEvent &) const;
- bool operator&(const glm::vec2 &) const;
- };
-
- explicit UIComponent(Position);
+ UIComponent() = default;
virtual ~UIComponent() = default;
NO_MOVE(UIComponent);
NO_COPY(UIComponent);
- virtual void render(const UIShader &, const Position & parentPos) const = 0;
- virtual bool handleInput(const SDL_Event &, const Position & parentPos) = 0;
-
- Position position;
+ virtual void render() = 0;
+ virtual bool handleInput(const SDL_Event &) = 0;
};
diff --git a/ui/uiComponentPlacer.cpp b/ui/uiComponentPlacer.cpp
deleted file mode 100644
index 5e645d8..0000000
--- a/ui/uiComponentPlacer.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "uiComponentPlacer.h"
-#include <algorithm>
-
-UIComponentPlacer::UIComponentPlacer(glm::vec2 padding, float spacing, glm::length_t axis) :
- padding {padding}, spacing {spacing}, axis {axis}, current {padding[axis]}
-{
-}
-
-glm::vec2
-UIComponentPlacer::next(glm::vec2 size)
-{
- glm::vec2 n {};
- n[axis] = current;
- n[1 - axis] = padding[1 - axis];
- current += spacing + size[axis];
- max = std::max(max, size[1 - axis]);
- return n;
-}
-
-glm::vec2
-UIComponentPlacer::getLimit() const
-{
- glm::vec2 n {};
- n[axis] = current + padding[axis];
- n[1 - axis] = max + padding[1 - axis];
- return n;
-}
diff --git a/ui/uiComponentPlacer.h b/ui/uiComponentPlacer.h
deleted file mode 100644
index 1e64f78..0000000
--- a/ui/uiComponentPlacer.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#pragma once
-
-#include <glm/glm.hpp>
-
-class UIComponentPlacer {
-public:
- UIComponentPlacer(glm::vec2 padding, float spacing, glm::length_t axis = 0);
-
- glm::vec2 next(glm::vec2 size);
- glm::vec2 getLimit() const;
-
-private:
- const glm::vec2 padding;
- const float spacing;
- const glm::length_t axis;
-
- float current {};
- float max {};
-};
diff --git a/ui/windowContent.cpp b/ui/windowContent.cpp
index 91732a7..0f6dc04 100644
--- a/ui/windowContent.cpp
+++ b/ui/windowContent.cpp
@@ -1,8 +1,6 @@
#include "windowContent.h"
#include "SDL_events.h"
-WindowContent::WindowContent(size_t width, size_t height) : uiShader {width, height} { }
-
void
WindowContent::tick(TickDuration)
{
@@ -27,6 +25,6 @@ WindowContent::handleInput(const SDL_Event & e)
eAdjusted.motion.y = size.y - e.motion.y;
break;
}
- uiComponents.rapplyOne(&UIComponent::handleInput, eAdjusted, UIComponent::Position {{}, size});
+ uiComponents.rapplyOne(&UIComponent::handleInput, eAdjusted);
return true;
}
diff --git a/ui/windowContent.h b/ui/windowContent.h
index 474445a..762d1cc 100644
--- a/ui/windowContent.h
+++ b/ui/windowContent.h
@@ -2,16 +2,13 @@
#include "chronology.h"
#include "collection.h"
-#include "gfx/gl/uiShader.h"
#include "special_members.h"
#include "stdTypeDefs.h"
#include "uiComponent.h" // IWYU pragma: keep
-#include <functional>
class WindowContent : public StdTypeDefs<WindowContent> {
public:
- using Factory = std::function<Ptr(size_t width, size_t height)>;
- WindowContent(size_t width, size_t height);
+ WindowContent() = default;
virtual ~WindowContent() = default;
NO_MOVE(WindowContent);
NO_COPY(WindowContent);
@@ -21,6 +18,5 @@ public:
virtual bool handleInput(const SDL_Event & e);
protected:
- ::Collection<UIComponent> uiComponents;
- UIShader uiShader;
+ UniqueCollection<UIComponent> uiComponents;
};