From 5a0b3927a33807cca4c77c40eb873f8a3b51b0b0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 29 Apr 2023 19:07:11 +0100 Subject: Drop .hpp for header only things Half of them acquired a .cpp part anyway --- application/main.cpp | 4 +- assetFactory/asset.h | 2 +- assetFactory/assetFactory.cpp | 2 +- assetFactory/assimp.cpp | 4 +- assetFactory/faceController.cpp | 4 +- assetFactory/factoryMesh.cpp | 4 +- assetFactory/factoryMesh.h | 2 +- assetFactory/object.h | 2 +- assetFactory/shape.cpp | 2 +- assetFactory/shape.h | 2 +- assetFactory/textureFragment.h | 2 +- assetFactory/texturePacker.cpp | 2 +- assetFactory/use.cpp | 2 +- assetFactory/use.h | 2 +- game/activity.h | 2 +- game/gamestate.h | 4 +- game/geoData.cpp | 2 +- game/network/link.cpp | 4 +- game/network/link.h | 6 +- game/network/network.cpp | 2 +- game/network/network.h | 6 +- game/network/rail.cpp | 4 +- game/network/rail.h | 4 +- game/objective.h | 2 +- game/orders.h | 2 +- game/scenary/foliage.cpp | 4 +- game/scenary/plant.cpp | 2 +- game/selectable.h | 2 +- game/terrain.cpp | 4 +- game/terrain.h | 4 +- game/vehicles/railVehicle.cpp | 4 +- game/vehicles/railVehicleClass.cpp | 4 +- game/vehicles/train.cpp | 2 +- game/vehicles/train.h | 6 +- game/vehicles/vehicle.cpp | 2 +- game/vehicles/vehicle.h | 2 +- game/worldobject.h | 4 +- gfx/camera_controller.h | 2 +- gfx/followCameraController.cpp | 2 +- gfx/gl/bufferedLocation.cpp | 2 +- gfx/gl/bufferedLocation.h | 2 +- gfx/gl/camera.cpp | 4 +- gfx/gl/camera.h | 2 +- gfx/gl/instanceVertices.h | 2 +- gfx/gl/program.cpp | 2 +- gfx/gl/program.h | 4 +- gfx/gl/sceneProvider.h | 2 +- gfx/gl/sceneRenderer.cpp | 2 +- gfx/gl/sceneShader.cpp | 4 +- gfx/gl/shader.h | 2 +- gfx/gl/shadowMapper.cpp | 6 +- gfx/gl/vertexArrayObject.h | 109 ++++++++++++++++++++++++ gfx/gl/vertexArrayObject.hpp | 109 ------------------------ gfx/image.h | 2 +- gfx/models/mesh.cpp | 4 +- gfx/models/mesh.h | 2 +- gfx/models/vertex.h | 23 ++++++ gfx/models/vertex.hpp | 23 ------ gfx/renderable.h | 2 +- lib/cache.h | 2 +- lib/chronology.h | 5 ++ lib/chronology.hpp | 5 -- lib/collection.h | 131 +++++++++++++++++++++++++++++ lib/collection.hpp | 131 ----------------------------- lib/collections.h | 159 ++++++++++++++++++++++++++++++++++++ lib/collections.hpp | 159 ------------------------------------ lib/embed-glsl.cpp.m4 | 2 +- lib/enumDetails.h | 143 ++++++++++++++++++++++++++++++++ lib/enumDetails.hpp | 143 -------------------------------- lib/filesystem.h | 4 +- lib/geometricPlane.cpp | 2 +- lib/glArrays.h | 2 +- lib/glRef.h | 62 ++++++++++++++ lib/glRef.hpp | 62 -------------- lib/gl_traits.h | 77 +++++++++++++++++ lib/gl_traits.hpp | 77 ----------------- lib/location.cpp | 2 +- lib/location.h | 14 ++++ lib/location.hpp | 14 ---- lib/persistence.h | 2 +- lib/ptr.h | 67 +++++++++++++++ lib/ptr.hpp | 67 --------------- lib/ray.cpp | 2 +- lib/ray.h | 17 ++++ lib/ray.hpp | 17 ---- lib/sorting.h | 49 +++++++++++ lib/sorting.hpp | 49 ----------- lib/special_members.h | 29 +++++++ lib/special_members.hpp | 29 ------- lib/stdTypeDefs.h | 45 ++++++++++ lib/stdTypeDefs.hpp | 45 ---------- lib/stream_support.h | 86 +++++++++++++++++++ lib/stream_support.hpp | 86 ------------------- lib/strings.h | 13 +++ lib/strings.hpp | 13 --- lib/worker.h | 2 +- test/enumDetailsData.h | 20 +++++ test/enumDetailsData.hpp | 20 ----- test/test-assetFactory.cpp | 6 +- test/test-collection.cpp | 6 +- test/test-enumDetails.cpp | 6 +- test/test-geo.cpp | 4 +- test/test-instancing.cpp | 2 +- test/test-maths.cpp | 2 +- test/test-network.cpp | 4 +- test/test-render.cpp | 4 +- test/test-static-enumDetails.cpp | 4 +- test/test-static-stream_support.cpp | 2 +- test/test-text.cpp | 2 +- test/test-worker.cpp | 2 +- test/testRenderOutput.h | 2 +- ui/applicationBase.h | 2 +- ui/editNetwork.h | 2 +- ui/font.cpp | 2 +- ui/gameMainSelector.cpp | 4 +- ui/gameMainSelector.h | 2 +- ui/gameMainWindow.cpp | 4 +- ui/gameMainWindow.h | 2 +- ui/modeHelper.h | 39 +++++++++ ui/modeHelper.hpp | 39 --------- ui/toolbar.h | 2 +- ui/uiComponent.h | 2 +- ui/window.h | 8 +- 123 files changed, 1217 insertions(+), 1217 deletions(-) create mode 100644 gfx/gl/vertexArrayObject.h delete mode 100644 gfx/gl/vertexArrayObject.hpp create mode 100644 gfx/models/vertex.h delete mode 100644 gfx/models/vertex.hpp create mode 100644 lib/chronology.h delete mode 100644 lib/chronology.hpp create mode 100644 lib/collection.h delete mode 100644 lib/collection.hpp create mode 100644 lib/collections.h delete mode 100644 lib/collections.hpp create mode 100644 lib/enumDetails.h delete mode 100644 lib/enumDetails.hpp create mode 100644 lib/glRef.h delete mode 100644 lib/glRef.hpp create mode 100644 lib/gl_traits.h delete mode 100644 lib/gl_traits.hpp create mode 100644 lib/location.h delete mode 100644 lib/location.hpp create mode 100644 lib/ptr.h delete mode 100644 lib/ptr.hpp create mode 100644 lib/ray.h delete mode 100644 lib/ray.hpp create mode 100644 lib/sorting.h delete mode 100644 lib/sorting.hpp create mode 100644 lib/special_members.h delete mode 100644 lib/special_members.hpp create mode 100644 lib/stdTypeDefs.h delete mode 100644 lib/stdTypeDefs.hpp create mode 100644 lib/stream_support.h delete mode 100644 lib/stream_support.hpp create mode 100644 lib/strings.h delete mode 100644 lib/strings.hpp create mode 100644 test/enumDetailsData.h delete mode 100644 test/enumDetailsData.hpp create mode 100644 ui/modeHelper.h delete mode 100644 ui/modeHelper.hpp diff --git a/application/main.cpp b/application/main.cpp index 177c795..532c23d 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include @@ -22,7 +22,7 @@ #include #include // IWYU pragma: keep #include -#include +#include #include #include #include diff --git a/assetFactory/asset.h b/assetFactory/asset.h index dba4974..5bdd2f2 100644 --- a/assetFactory/asset.h +++ b/assetFactory/asset.h @@ -2,7 +2,7 @@ #include "factoryMesh.h" #include "persistence.h" -#include +#include class TextureAtlas; diff --git a/assetFactory/assetFactory.cpp b/assetFactory/assetFactory.cpp index af0cd54..218c4e7 100644 --- a/assetFactory/assetFactory.cpp +++ b/assetFactory/assetFactory.cpp @@ -1,5 +1,5 @@ #include "assetFactory.h" -#include "collections.hpp" +#include "collections.h" #include "cuboid.h" #include "cylinder.h" #include "filesystem.h" diff --git a/assetFactory/assimp.cpp b/assetFactory/assimp.cpp index 74b1c54..9dc7842 100644 --- a/assetFactory/assimp.cpp +++ b/assetFactory/assimp.cpp @@ -1,7 +1,7 @@ #include "assimp.h" #include "assetFactory.h" -#include "collections.hpp" -#include "ptr.hpp" +#include "collections.h" +#include "ptr.h" #include "resource.h" #include #include diff --git a/assetFactory/faceController.cpp b/assetFactory/faceController.cpp index b305f1c..d045b3c 100644 --- a/assetFactory/faceController.cpp +++ b/assetFactory/faceController.cpp @@ -1,8 +1,8 @@ #include "faceController.h" -#include "collections.hpp" +#include "collections.h" #include "maths.h" #include "modelFactoryMesh.h" -#include "ray.hpp" +#include "ray.h" void FaceController::apply(ModelFactoryMesh & mesh, const StyleStack & parents, const std::string & names, diff --git a/assetFactory/factoryMesh.cpp b/assetFactory/factoryMesh.cpp index 784179f..46bcf6f 100644 --- a/assetFactory/factoryMesh.cpp +++ b/assetFactory/factoryMesh.cpp @@ -1,6 +1,6 @@ #include "factoryMesh.h" -#include "collections.hpp" -#include "gfx/models/vertex.hpp" +#include "collections.h" +#include "gfx/models/vertex.h" #include "modelFactoryMesh.h" Mesh::Ptr diff --git a/assetFactory/factoryMesh.h b/assetFactory/factoryMesh.h index bbeb870..f71c737 100644 --- a/assetFactory/factoryMesh.h +++ b/assetFactory/factoryMesh.h @@ -1,7 +1,7 @@ #pragma once #include "gfx/models/mesh.h" -#include "stdTypeDefs.hpp" +#include "stdTypeDefs.h" #include "use.h" class FactoryMesh : public Persistence::Persistable, public StdTypeDefs { diff --git a/assetFactory/object.h b/assetFactory/object.h index 3f7b640..f47c512 100644 --- a/assetFactory/object.h +++ b/assetFactory/object.h @@ -2,7 +2,7 @@ #include "persistence.h" #include "shape.h" -#include "stdTypeDefs.hpp" +#include "stdTypeDefs.h" #include "use.h" class Object : public StdTypeDefs, public Shape, public Persistence::Persistable { diff --git a/assetFactory/shape.cpp b/assetFactory/shape.cpp index 3261354..1bfbdbb 100644 --- a/assetFactory/shape.cpp +++ b/assetFactory/shape.cpp @@ -1,5 +1,5 @@ #include "shape.h" -#include "gfx/models/vertex.hpp" +#include "gfx/models/vertex.h" #include "maths.h" #include "modelFactoryMesh.h" #include "shape.h" diff --git a/assetFactory/shape.h b/assetFactory/shape.h index fe517c1..ea3e4e7 100644 --- a/assetFactory/shape.h +++ b/assetFactory/shape.h @@ -1,7 +1,7 @@ #pragma once #include "modelFactoryMesh_fwd.h" -#include "stdTypeDefs.hpp" +#include "stdTypeDefs.h" #include #include #include diff --git a/assetFactory/textureFragment.h b/assetFactory/textureFragment.h index e6f07f3..6c99fee 100644 --- a/assetFactory/textureFragment.h +++ b/assetFactory/textureFragment.h @@ -3,7 +3,7 @@ #include "gfx/image.h" #include "gfx/models/texture.h" #include "persistence.h" -#include "stdTypeDefs.hpp" +#include "stdTypeDefs.h" #include "worker.h" class TextureFragment : public Persistence::Persistable, public StdTypeDefs { diff --git a/assetFactory/texturePacker.cpp b/assetFactory/texturePacker.cpp index fcc935f..1d533c1 100644 --- a/assetFactory/texturePacker.cpp +++ b/assetFactory/texturePacker.cpp @@ -1,5 +1,5 @@ #include "texturePacker.h" -#include "collections.hpp" +#include "collections.h" #include #include #include diff --git a/assetFactory/use.cpp b/assetFactory/use.cpp index 9db3495..5314321 100644 --- a/assetFactory/use.cpp +++ b/assetFactory/use.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include Shape::CreatedFaces Use::createMesh(ModelFactoryMesh & mesh, float levelOfDetailFactor) const diff --git a/assetFactory/use.h b/assetFactory/use.h index 9dbf382..a91685b 100644 --- a/assetFactory/use.h +++ b/assetFactory/use.h @@ -4,7 +4,7 @@ #include "modelFactoryMesh_fwd.h" #include "persistence.h" #include "shape.h" -#include "stdTypeDefs.hpp" +#include "stdTypeDefs.h" #include "style.h" class Use : public StdTypeDefs, public Mutation, public Style, public Persistence::Persistable { diff --git a/game/activity.h b/game/activity.h index 6ba3712..e0585f7 100644 --- a/game/activity.h +++ b/game/activity.h @@ -2,7 +2,7 @@ #include #include -#include +#include class Vehicle; diff --git a/game/gamestate.h b/game/gamestate.h index db223c0..6f3f382 100644 --- a/game/gamestate.h +++ b/game/gamestate.h @@ -1,9 +1,9 @@ #pragma once #include "assetFactory/assetFactory.h" -#include +#include #include -#include +#include class WorldObject; class GeoData; diff --git a/game/geoData.cpp b/game/geoData.cpp index 4dd0c40..34a1030 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/game/network/link.cpp b/game/network/link.cpp index aecc2fc..bb27a52 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -1,9 +1,9 @@ #include "link.h" #include #include -#include +#include #include -#include +#include #include Link::Link(End a, End b, float l) : ends {{std::move(a), std::move(b)}}, length {l} { } diff --git a/game/network/link.h b/game/network/link.h index 1f6b780..4a9f83f 100644 --- a/game/network/link.h +++ b/game/network/link.h @@ -2,11 +2,11 @@ #include #include -#include +#include #include #include -#include -#include +#include +#include #include #include diff --git a/game/network/network.cpp b/game/network/network.cpp index 59ef7c8..083b08e 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include diff --git a/game/network/network.h b/game/network/network.h index 4b485cc..b9316eb 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -1,13 +1,13 @@ #pragma once #include "link.h" -#include +#include #include #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/game/network/rail.cpp b/game/network/rail.cpp index e7006cf..4454600 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -3,11 +3,11 @@ #include #include #include -#include +#include #include #include #include // IWYU pragma: keep -#include +#include #include #include #include diff --git a/game/network/rail.h b/game/network/rail.h index 8edc363..611eb67 100644 --- a/game/network/rail.h +++ b/game/network/rail.h @@ -1,6 +1,6 @@ #pragma once -#include "chronology.hpp" +#include "chronology.h" #include "game/worldobject.h" #include "gfx/models/mesh.h" #include "gfx/renderable.h" @@ -9,7 +9,7 @@ #include #include #include -#include +#include class SceneShader; class Vertex; diff --git a/game/objective.h b/game/objective.h index 617b8e9..130015f 100644 --- a/game/objective.h +++ b/game/objective.h @@ -3,7 +3,7 @@ #include "activity.h" #include "network/link.h" #include -#include +#include class Orders; diff --git a/game/orders.h b/game/orders.h index 5ac0abf..f29e208 100644 --- a/game/orders.h +++ b/game/orders.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include class Objective; diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index 0913c6e..9304842 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -1,9 +1,9 @@ #include "foliage.h" #include "gfx/gl/sceneShader.h" #include "gfx/gl/shadowMapper.h" -#include "gfx/gl/vertexArrayObject.hpp" +#include "gfx/gl/vertexArrayObject.h" #include "gfx/models/texture.h" -#include "location.hpp" +#include "location.h" bool Foliage::persist(Persistence::PersistenceStore & store) diff --git a/game/scenary/plant.cpp b/game/scenary/plant.cpp index 2a79807..4fb3cb5 100644 --- a/game/scenary/plant.cpp +++ b/game/scenary/plant.cpp @@ -1,5 +1,5 @@ #include "plant.h" -#include "location.hpp" +#include "location.h" Plant::Plant(std::shared_ptr type, const Location & position) : type {std::move(type)}, location {this->type->instances.acquire(position.getTransform())} diff --git a/game/selectable.h b/game/selectable.h index 3d734f3..31287d8 100644 --- a/game/selectable.h +++ b/game/selectable.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include class Ray; diff --git a/game/terrain.cpp b/game/terrain.cpp index f798254..1753dfe 100644 --- a/game/terrain.cpp +++ b/game/terrain.cpp @@ -10,10 +10,10 @@ #include #include #include -#include +#include #include #include -#include +#include #include #include #include diff --git a/game/terrain.h b/game/terrain.h index 879d173..d62f138 100644 --- a/game/terrain.h +++ b/game/terrain.h @@ -1,7 +1,7 @@ #pragma once -#include "chronology.hpp" -#include "collection.hpp" +#include "chronology.h" +#include "collection.h" #include "game/worldobject.h" #include #include diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index b77b93c..c4a9e96 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -6,10 +6,10 @@ #include #include #include -#include +#include #include #include -#include +#include RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : rvClass {std::move(rvc)}, location {rvClass->instancesBody}, bogies { diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index 82a442e..64a21be 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -1,7 +1,7 @@ #include "railVehicleClass.h" #include "gfx/gl/sceneShader.h" #include "gfx/gl/shadowMapper.h" -#include "gfx/gl/vertexArrayObject.hpp" +#include "gfx/gl/vertexArrayObject.h" #include "gfx/models/mesh.h" #include "gfx/models/texture.h" #include @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/game/vehicles/train.cpp b/game/vehicles/train.cpp index fdfc3e1..6f3b036 100644 --- a/game/vehicles/train.cpp +++ b/game/vehicles/train.cpp @@ -3,7 +3,7 @@ #include "game/vehicles/railVehicle.h" #include "game/vehicles/railVehicleClass.h" #include "gfx/renderable.h" -#include "location.hpp" +#include "location.h" #include #include #include diff --git a/game/vehicles/train.h b/game/vehicles/train.h index 15e2f6e..20c3bc4 100644 --- a/game/vehicles/train.h +++ b/game/vehicles/train.h @@ -1,15 +1,15 @@ #pragma once -#include "chronology.hpp" +#include "chronology.h" #include "game/activities/go.h" // IWYU pragma: keep #include "game/activities/idle.h" // IWYU pragma: keep #include "game/activity.h" #include "game/network/link.h" #include "railVehicle.h" #include "vehicle.h" -#include +#include #include -#include +#include #include #include diff --git a/game/vehicles/vehicle.cpp b/game/vehicles/vehicle.cpp index 6dc8371..0d46017 100644 --- a/game/vehicles/vehicle.cpp +++ b/game/vehicles/vehicle.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/game/vehicles/vehicle.h b/game/vehicles/vehicle.h index 369bd7a..763ade9 100644 --- a/game/vehicles/vehicle.h +++ b/game/vehicles/vehicle.h @@ -1,6 +1,6 @@ #pragma once -#include "chronology.hpp" +#include "chronology.h" #include "linkHistory.h" #include #include diff --git a/game/worldobject.h b/game/worldobject.h index 994545b..e064bc7 100644 --- a/game/worldobject.h +++ b/game/worldobject.h @@ -1,7 +1,7 @@ #pragma once -#include "chronology.hpp" -#include +#include "chronology.h" +#include class WorldObject { public: diff --git a/gfx/camera_controller.h b/gfx/camera_controller.h index fd5c885..83c0d38 100644 --- a/gfx/camera_controller.h +++ b/gfx/camera_controller.h @@ -1,6 +1,6 @@ #pragma once -#include +#include class Camera; diff --git a/gfx/followCameraController.cpp b/gfx/followCameraController.cpp index d15ecda..5b08483 100644 --- a/gfx/followCameraController.cpp +++ b/gfx/followCameraController.cpp @@ -2,7 +2,7 @@ #include "game/vehicles/vehicle.h" #include #include -#include +#include #include #include #include diff --git a/gfx/gl/bufferedLocation.cpp b/gfx/gl/bufferedLocation.cpp index 4484053..7027b4c 100644 --- a/gfx/gl/bufferedLocation.cpp +++ b/gfx/gl/bufferedLocation.cpp @@ -1,5 +1,5 @@ #include "bufferedLocation.h" -#include "location.hpp" +#include "location.h" #include "maths.h" #include diff --git a/gfx/gl/bufferedLocation.h b/gfx/gl/bufferedLocation.h index cf7afed..6d148cd 100644 --- a/gfx/gl/bufferedLocation.h +++ b/gfx/gl/bufferedLocation.h @@ -1,7 +1,7 @@ #pragma once #include "instanceVertices.h" -#include "location.hpp" +#include "location.h" #include #include diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index 5b7269e..f642423 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -1,9 +1,9 @@ #include "camera.h" -#include +#include #include // IWYU pragma: keep #include // IWYU pragma: keep #include -#include +#include Camera::Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar) : position {pos}, forward {::north}, up {::up}, near {zNear}, far {zFar}, projection {glm::perspective( diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h index 5c168e7..3f1c3a7 100644 --- a/gfx/gl/camera.h +++ b/gfx/gl/camera.h @@ -2,7 +2,7 @@ #include #include -#include +#include class Camera { public: diff --git a/gfx/gl/instanceVertices.h b/gfx/gl/instanceVertices.h index 8bb2f21..9df6e12 100644 --- a/gfx/gl/instanceVertices.h +++ b/gfx/gl/instanceVertices.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/gfx/gl/program.cpp b/gfx/gl/program.cpp index 7791e3e..0b60eaa 100644 --- a/gfx/gl/program.cpp +++ b/gfx/gl/program.cpp @@ -2,7 +2,7 @@ #include "shader.h" #include #include -#include +#include #include void diff --git a/gfx/gl/program.h b/gfx/gl/program.h index 787a53c..2708ff0 100644 --- a/gfx/gl/program.h +++ b/gfx/gl/program.h @@ -2,9 +2,9 @@ #include "shader.h" #include -#include +#include #include -#include +#include class Location; diff --git a/gfx/gl/sceneProvider.h b/gfx/gl/sceneProvider.h index 1d9ba57..f5e8e99 100644 --- a/gfx/gl/sceneProvider.h +++ b/gfx/gl/sceneProvider.h @@ -1,6 +1,6 @@ #pragma once -#include +#include class SceneRenderer; class ShadowMapper; diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 6542bea..aa9453a 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -1,6 +1,6 @@ #include "sceneRenderer.h" #include "maths.h" -#include "vertexArrayObject.hpp" +#include "vertexArrayObject.h" #include #include #include diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index 00d9826..1354611 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -13,10 +13,10 @@ #include #include #include -#include +#include #include #include -#include +#include #include SceneShader::SceneShader() : diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h index c1e3981..cb8065b 100644 --- a/gfx/gl/shader.h +++ b/gfx/gl/shader.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index 9f1e420..55d986c 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -1,14 +1,14 @@ #include "shadowMapper.h" #include "camera.h" -#include "collections.hpp" +#include "collections.h" #include "gfx/gl/shaders/vs-shadowDynamicPoint.h" #include "gfx/gl/shaders/vs-shadowDynamicPointInst.h" #include "gfx/gl/shaders/vs-shadowFixedPoint.h" -#include "location.hpp" +#include "location.h" #include "maths.h" #include "sceneProvider.h" #include "sceneShader.h" -#include "sorting.hpp" +#include "sorting.h" #include #include #include diff --git a/gfx/gl/vertexArrayObject.h b/gfx/gl/vertexArrayObject.h new file mode 100644 index 0000000..085cba6 --- /dev/null +++ b/gfx/gl/vertexArrayObject.h @@ -0,0 +1,109 @@ +#pragma once + +#include "collections.h" +#include "gl_traits.h" +#include "special_members.h" +#include + +class VertexArrayObject { +public: + template [[nodiscard]] VertexArrayObject(const T & arrayObject) + { + glBindVertexArray(arrayObject); + } + ~VertexArrayObject() + { + glBindVertexArray(0); + } + NO_MOVE(VertexArrayObject); + NO_COPY(VertexArrayObject); + + template struct MP { + constexpr MP(m T::*p) : P {p} { } + operator void *() const + { + return &(static_cast(nullptr)->*P); + } + m T::*P; + using value_type = m; + }; + template MP(m T::*) -> MP; + + template + VertexArrayObject & + addAttribs(const GLuint arrayBuffer, const SequentialCollection auto & vertices, const GLuint divisor = 0) + { + addAttribs(arrayBuffer, divisor); + data(vertices, arrayBuffer, GL_ARRAY_BUFFER); + return *this; + } + + template + VertexArrayObject & + addAttribs(const GLuint arrayBuffer, const GLuint divisor = 0) + { + configure_attribs(arrayBuffer, divisor); + return *this; + } + + template + VertexArrayObject & + addIndices(const GLuint arrayBuffer, const Indices & indices) + { + data(indices, arrayBuffer, GL_ELEMENT_ARRAY_BUFFER); + return *this; + } + + VertexArrayObject & + addIndices(const GLuint arrayBuffer) + { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, arrayBuffer); + return *this; + } + + template + static void + data(const Data & data, const GLuint arrayBuffer, GLenum target) + { + using Value = typename Data::value_type; + glBindBuffer(target, arrayBuffer); + glBufferData(target, static_cast(sizeof(Value) * data.size()), data.data(), GL_STATIC_DRAW); + } + +private: + template + static auto + set_pointer(const GLuint vertexArrayId, const void * ptr, const GLuint divisor) + { + using traits = gl_traits; + const auto usedAttribs + = traits::vertexAttribFunc(vertexArrayId, traits::size, traits::type, sizeof(VertexT), ptr); + for (GLuint i {}; i < usedAttribs; i++) { + glEnableVertexAttribArray(vertexArrayId + i); + glVertexAttribDivisor(vertexArrayId + i, divisor); + } + return usedAttribs; + } + + template + static auto + set_pointer(const GLuint vertexArrayId, const GLuint divisor) + { + return set_pointer(vertexArrayId, attrib, divisor); + } + + template + void + configure_attribs(const GLuint arrayBuffer, const GLuint divisor) + { + glBindBuffer(GL_ARRAY_BUFFER, arrayBuffer); + if constexpr (sizeof...(attribs) == 0) { + vertexArrayId += set_pointer(vertexArrayId, nullptr, divisor); + } + else { + ((vertexArrayId += set_pointer(vertexArrayId, divisor)), ...); + } + } + + GLuint vertexArrayId {}; +}; diff --git a/gfx/gl/vertexArrayObject.hpp b/gfx/gl/vertexArrayObject.hpp deleted file mode 100644 index 7ded03e..0000000 --- a/gfx/gl/vertexArrayObject.hpp +++ /dev/null @@ -1,109 +0,0 @@ -#pragma once - -#include "collections.hpp" -#include "gl_traits.hpp" -#include "special_members.hpp" -#include - -class VertexArrayObject { -public: - template [[nodiscard]] VertexArrayObject(const T & arrayObject) - { - glBindVertexArray(arrayObject); - } - ~VertexArrayObject() - { - glBindVertexArray(0); - } - NO_MOVE(VertexArrayObject); - NO_COPY(VertexArrayObject); - - template struct MP { - constexpr MP(m T::*p) : P {p} { } - operator void *() const - { - return &(static_cast(nullptr)->*P); - } - m T::*P; - using value_type = m; - }; - template MP(m T::*) -> MP; - - template - VertexArrayObject & - addAttribs(const GLuint arrayBuffer, const SequentialCollection auto & vertices, const GLuint divisor = 0) - { - addAttribs(arrayBuffer, divisor); - data(vertices, arrayBuffer, GL_ARRAY_BUFFER); - return *this; - } - - template - VertexArrayObject & - addAttribs(const GLuint arrayBuffer, const GLuint divisor = 0) - { - configure_attribs(arrayBuffer, divisor); - return *this; - } - - template - VertexArrayObject & - addIndices(const GLuint arrayBuffer, const Indices & indices) - { - data(indices, arrayBuffer, GL_ELEMENT_ARRAY_BUFFER); - return *this; - } - - VertexArrayObject & - addIndices(const GLuint arrayBuffer) - { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, arrayBuffer); - return *this; - } - - template - static void - data(const Data & data, const GLuint arrayBuffer, GLenum target) - { - using Value = typename Data::value_type; - glBindBuffer(target, arrayBuffer); - glBufferData(target, static_cast(sizeof(Value) * data.size()), data.data(), GL_STATIC_DRAW); - } - -private: - template - static auto - set_pointer(const GLuint vertexArrayId, const void * ptr, const GLuint divisor) - { - using traits = gl_traits; - const auto usedAttribs - = traits::vertexAttribFunc(vertexArrayId, traits::size, traits::type, sizeof(VertexT), ptr); - for (GLuint i {}; i < usedAttribs; i++) { - glEnableVertexAttribArray(vertexArrayId + i); - glVertexAttribDivisor(vertexArrayId + i, divisor); - } - return usedAttribs; - } - - template - static auto - set_pointer(const GLuint vertexArrayId, const GLuint divisor) - { - return set_pointer(vertexArrayId, attrib, divisor); - } - - template - void - configure_attribs(const GLuint arrayBuffer, const GLuint divisor) - { - glBindBuffer(GL_ARRAY_BUFFER, arrayBuffer); - if constexpr (sizeof...(attribs) == 0) { - vertexArrayId += set_pointer(vertexArrayId, nullptr, divisor); - } - else { - ((vertexArrayId += set_pointer(vertexArrayId, divisor)), ...); - } - } - - GLuint vertexArrayId {}; -}; diff --git a/gfx/image.h b/gfx/image.h index 97c2731..8bb4067 100644 --- a/gfx/image.h +++ b/gfx/image.h @@ -1,7 +1,7 @@ #pragma once #include // IWYU pragma: export -#include +#include #include class Image { diff --git a/gfx/models/mesh.cpp b/gfx/models/mesh.cpp index 7c5ddd4..a1ce991 100644 --- a/gfx/models/mesh.cpp +++ b/gfx/models/mesh.cpp @@ -1,7 +1,7 @@ #include "mesh.h" -#include "gfx/gl/vertexArrayObject.hpp" +#include "gfx/gl/vertexArrayObject.h" #include "glArrays.h" -#include "vertex.hpp" +#include "vertex.h" #include Mesh::Mesh(const std::span vertices, const std::span indices, GLenum m) : diff --git a/gfx/models/mesh.h b/gfx/models/mesh.h index 9b22b02..f022c2a 100644 --- a/gfx/models/mesh.h +++ b/gfx/models/mesh.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include class Vertex; class VertexArrayObject; diff --git a/gfx/models/vertex.h b/gfx/models/vertex.h new file mode 100644 index 0000000..181e7e7 --- /dev/null +++ b/gfx/models/vertex.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +class Vertex { +public: +#ifndef __cpp_aggregate_paren_init + constexpr Vertex(glm::vec3 pos, glm::vec2 texCoord, glm::vec3 normal, glm::vec4 colour = {}, GLuint material = 0) : + pos {std::move(pos)}, texCoord {std::move(texCoord)}, normal {std::move(normal)}, colour {std::move(colour)}, + material {material} + { + } +#endif + + bool operator==(const Vertex &) const = default; + + glm::vec3 pos; + glm::vec2 texCoord; + glm::vec3 normal; + glm::vec4 colour {}; + GLuint material {}; +}; diff --git a/gfx/models/vertex.hpp b/gfx/models/vertex.hpp deleted file mode 100644 index 181e7e7..0000000 --- a/gfx/models/vertex.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include -#include - -class Vertex { -public: -#ifndef __cpp_aggregate_paren_init - constexpr Vertex(glm::vec3 pos, glm::vec2 texCoord, glm::vec3 normal, glm::vec4 colour = {}, GLuint material = 0) : - pos {std::move(pos)}, texCoord {std::move(texCoord)}, normal {std::move(normal)}, colour {std::move(colour)}, - material {material} - { - } -#endif - - bool operator==(const Vertex &) const = default; - - glm::vec3 pos; - glm::vec2 texCoord; - glm::vec3 normal; - glm::vec4 colour {}; - GLuint material {}; -}; diff --git a/gfx/renderable.h b/gfx/renderable.h index 5a9b1cd..e126fff 100644 --- a/gfx/renderable.h +++ b/gfx/renderable.h @@ -1,6 +1,6 @@ #pragma once -#include +#include class SceneShader; class ShadowMapper; diff --git a/lib/cache.h b/lib/cache.h index 5ab9469..2c3975b 100644 --- a/lib/cache.h +++ b/lib/cache.h @@ -1,6 +1,6 @@ #pragma once -#include "special_members.hpp" +#include "special_members.h" #include #include #include diff --git a/lib/chronology.h b/lib/chronology.h new file mode 100644 index 0000000..1980116 --- /dev/null +++ b/lib/chronology.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +using TickDuration = std::chrono::duration; diff --git a/lib/chronology.hpp b/lib/chronology.hpp deleted file mode 100644 index 1980116..0000000 --- a/lib/chronology.hpp +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -using TickDuration = std::chrono::duration; diff --git a/lib/collection.h b/lib/collection.h new file mode 100644 index 0000000..6802bcb --- /dev/null +++ b/lib/collection.h @@ -0,0 +1,131 @@ +#pragma once + +#include +#include +#include +#include +#include + +template class Collection { +public: + virtual ~Collection() = default; + + using Ptr = std::conditional_t, std::unique_ptr>; + using Objects = std::vector; + Objects objects; + + template + auto + create(Params &&... params) + requires std::is_base_of_v + { + if constexpr (shared) { + auto obj = std::make_shared(std::forward(params)...); + objects.emplace_back(obj); + return obj; + } + else { + return static_cast(objects.emplace_back(std::make_unique(std::forward(params)...)).get()); + } + } + + template + T * + find() + { + if (auto i = std::find_if(objects.begin(), objects.end(), + [](auto && o) { + return (dynamic_cast(o.get())); + }); + i != objects.end()) { + return static_cast(i->get()); + } + return nullptr; + } + + template + auto + findOrCreate(Params &&... params) + requires std::is_base_of_v + { + if (auto o = find()) { + return o; + } + return create(std::forward(params)...).get(); + } + + template + auto + apply(const auto & m, Params &&... params) const + { + return apply_internal(objects.begin(), objects.end(), m, std::forward(params)...); + } + + template + auto + rapply(const auto & m, Params &&... params) const + { + return apply_internal(objects.rbegin(), objects.rend(), m, std::forward(params)...); + } + + template + auto + applyOne(const auto & m, Params &&... params) const + { + return applyOne_internal(objects.begin(), objects.end(), m, std::forward(params)...); + } + + template + auto + rapplyOne(const auto & m, Params &&... params) const + { + return applyOne_internal(objects.rbegin(), objects.rend(), m, std::forward(params)...); + } + + template + auto + removeAll() + { + return std::erase_if(objects, [](auto && op) { + return dynamic_cast(op.get()); + }); + } + + auto + end() const + { + return objects.end(); + } + + auto + rend() const + { + return objects.rend(); + } + +protected: + template + auto + apply_internal(const auto begin, const auto end, const auto & m, Params &&... params) const + { + return std::count_if(begin, end, [&m, ¶ms...](auto && op) { + if (auto o = dynamic_cast(op.get())) { + std::invoke(m, o, std::forward(params)...); + return true; + } + return false; + }); + } + + template + auto + applyOne_internal(const auto begin, const auto end, const auto & m, Params &&... params) const + { + return std::find_if(begin, end, [&m, ¶ms...](auto && op) { + if (auto o = dynamic_cast(op.get())) { + return std::invoke(m, o, std::forward(params)...); + } + return false; + }); + } +}; diff --git a/lib/collection.hpp b/lib/collection.hpp deleted file mode 100644 index 6802bcb..0000000 --- a/lib/collection.hpp +++ /dev/null @@ -1,131 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -template class Collection { -public: - virtual ~Collection() = default; - - using Ptr = std::conditional_t, std::unique_ptr>; - using Objects = std::vector; - Objects objects; - - template - auto - create(Params &&... params) - requires std::is_base_of_v - { - if constexpr (shared) { - auto obj = std::make_shared(std::forward(params)...); - objects.emplace_back(obj); - return obj; - } - else { - return static_cast(objects.emplace_back(std::make_unique(std::forward(params)...)).get()); - } - } - - template - T * - find() - { - if (auto i = std::find_if(objects.begin(), objects.end(), - [](auto && o) { - return (dynamic_cast(o.get())); - }); - i != objects.end()) { - return static_cast(i->get()); - } - return nullptr; - } - - template - auto - findOrCreate(Params &&... params) - requires std::is_base_of_v - { - if (auto o = find()) { - return o; - } - return create(std::forward(params)...).get(); - } - - template - auto - apply(const auto & m, Params &&... params) const - { - return apply_internal(objects.begin(), objects.end(), m, std::forward(params)...); - } - - template - auto - rapply(const auto & m, Params &&... params) const - { - return apply_internal(objects.rbegin(), objects.rend(), m, std::forward(params)...); - } - - template - auto - applyOne(const auto & m, Params &&... params) const - { - return applyOne_internal(objects.begin(), objects.end(), m, std::forward(params)...); - } - - template - auto - rapplyOne(const auto & m, Params &&... params) const - { - return applyOne_internal(objects.rbegin(), objects.rend(), m, std::forward(params)...); - } - - template - auto - removeAll() - { - return std::erase_if(objects, [](auto && op) { - return dynamic_cast(op.get()); - }); - } - - auto - end() const - { - return objects.end(); - } - - auto - rend() const - { - return objects.rend(); - } - -protected: - template - auto - apply_internal(const auto begin, const auto end, const auto & m, Params &&... params) const - { - return std::count_if(begin, end, [&m, ¶ms...](auto && op) { - if (auto o = dynamic_cast(op.get())) { - std::invoke(m, o, std::forward(params)...); - return true; - } - return false; - }); - } - - template - auto - applyOne_internal(const auto begin, const auto end, const auto & m, Params &&... params) const - { - return std::find_if(begin, end, [&m, ¶ms...](auto && op) { - if (auto o = dynamic_cast(op.get())) { - return std::invoke(m, o, std::forward(params)...); - } - return false; - }); - } -}; diff --git a/lib/collections.h b/lib/collections.h new file mode 100644 index 0000000..8f5a43d --- /dev/null +++ b/lib/collections.h @@ -0,0 +1,159 @@ +#pragma once + +#include +#include +#include +#include +#include + +template +concept SequentialCollection = requires(T c) { + { + c.size() + } -> std::integral; + { + c.data() + } -> std::same_as; + }; +template +concept IterableCollection = std::is_same_v().begin()), decltype(std::declval().end())>; + +template +[[nodiscard]] constexpr std::array +operator+(const std::array & a, const std::array & b) +{ + std::array r; + auto out = r.begin(); + out = std::copy(a.begin(), a.end(), out); + std::copy(b.begin(), b.end(), out); + return r; +} + +template +[[nodiscard]] constexpr std::array, first * second> +operator*(const std::array & a, const std::array & b) +{ + std::array, first * second> r; + auto out = r.begin(); + for (const auto & ae : a) { + for (const auto & be : b) { + *out++ = {ae, be}; + } + } + return r; +} + +template +[[nodiscard]] constexpr auto +operator*(const std::array & in, auto && f) +{ + std::array out; + + for (auto outitr = out.begin(); const auto & v : in) { + *outitr++ = f(v); + } + return out; +} + +constexpr auto & +operator*=(IterableCollection auto & in, auto && f) +{ + for (auto & v : in) { + f(v); + } + return in; +} + +template typename C, typename... T> + requires IterableCollection> +[[nodiscard]] constexpr auto +operator*(const C & in, auto && f) +{ + C out; + if constexpr (requires { out.reserve(in.size()); }) { + out.reserve(in.size()); + } + + std::transform(in.begin(), in.end(), std::inserter(out, out.end()), f); + return out; +} + +template +[[nodiscard]] constexpr auto +operator*(const std::span in, auto && f) +{ + std::array())), N> out; + + std::transform(in.begin(), in.end(), out.begin(), f); + return out; +} + +template +[[nodiscard]] constexpr auto +operator*(const std::span in, auto && f) +{ + std::vector()))> out; + + out.reserve(in.size()); + std::transform(in.begin(), in.end(), std::inserter(out, out.end()), f); + return out; +} + +template +constexpr auto & +operator+=(std::vector & in, std::vector && src) +{ + in.reserve(in.size() + src.size()); + std::move(src.begin(), src.end(), std::back_inserter(in)); + return in; +} + +template +[[nodiscard]] constexpr auto +operator+(const std::vector & in, Vn && vn) +{ + auto out(in); + out.emplace_back(std::forward(vn)); + return out; +} + +template typename Direction = std::plus, typename T = unsigned int> +[[nodiscard]] static auto +vectorOfN(std::integral auto N, T start = {}, T step = 1) +{ + std::vector v; + v.resize(N); + std::generate_n(v.begin(), N, [&start, step, adj = Direction {}]() { + return std::exchange(start, adj(start, step)); + }); + return v; +} + +template typename Rtn = std::vector, IterableCollection In> +[[nodiscard]] auto +materializeRange(In && in) +{ + return Rtn(in.begin(), in.end()); +} + +template typename Rtn = std::vector, typename In> +[[nodiscard]] auto +materializeRange(const std::pair & in) +{ + return Rtn(in.first, in.second); +} + +template struct pair_range { + constexpr auto & + begin() const noexcept + { + return pair.first; + } + constexpr auto & + end() const noexcept + { + return pair.second; + } + const std::pair & pair; +}; +template pair_range(std::pair) -> pair_range; diff --git a/lib/collections.hpp b/lib/collections.hpp deleted file mode 100644 index 8f5a43d..0000000 --- a/lib/collections.hpp +++ /dev/null @@ -1,159 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -template -concept SequentialCollection = requires(T c) { - { - c.size() - } -> std::integral; - { - c.data() - } -> std::same_as; - }; -template -concept IterableCollection = std::is_same_v().begin()), decltype(std::declval().end())>; - -template -[[nodiscard]] constexpr std::array -operator+(const std::array & a, const std::array & b) -{ - std::array r; - auto out = r.begin(); - out = std::copy(a.begin(), a.end(), out); - std::copy(b.begin(), b.end(), out); - return r; -} - -template -[[nodiscard]] constexpr std::array, first * second> -operator*(const std::array & a, const std::array & b) -{ - std::array, first * second> r; - auto out = r.begin(); - for (const auto & ae : a) { - for (const auto & be : b) { - *out++ = {ae, be}; - } - } - return r; -} - -template -[[nodiscard]] constexpr auto -operator*(const std::array & in, auto && f) -{ - std::array out; - - for (auto outitr = out.begin(); const auto & v : in) { - *outitr++ = f(v); - } - return out; -} - -constexpr auto & -operator*=(IterableCollection auto & in, auto && f) -{ - for (auto & v : in) { - f(v); - } - return in; -} - -template typename C, typename... T> - requires IterableCollection> -[[nodiscard]] constexpr auto -operator*(const C & in, auto && f) -{ - C out; - if constexpr (requires { out.reserve(in.size()); }) { - out.reserve(in.size()); - } - - std::transform(in.begin(), in.end(), std::inserter(out, out.end()), f); - return out; -} - -template -[[nodiscard]] constexpr auto -operator*(const std::span in, auto && f) -{ - std::array())), N> out; - - std::transform(in.begin(), in.end(), out.begin(), f); - return out; -} - -template -[[nodiscard]] constexpr auto -operator*(const std::span in, auto && f) -{ - std::vector()))> out; - - out.reserve(in.size()); - std::transform(in.begin(), in.end(), std::inserter(out, out.end()), f); - return out; -} - -template -constexpr auto & -operator+=(std::vector & in, std::vector && src) -{ - in.reserve(in.size() + src.size()); - std::move(src.begin(), src.end(), std::back_inserter(in)); - return in; -} - -template -[[nodiscard]] constexpr auto -operator+(const std::vector & in, Vn && vn) -{ - auto out(in); - out.emplace_back(std::forward(vn)); - return out; -} - -template typename Direction = std::plus, typename T = unsigned int> -[[nodiscard]] static auto -vectorOfN(std::integral auto N, T start = {}, T step = 1) -{ - std::vector v; - v.resize(N); - std::generate_n(v.begin(), N, [&start, step, adj = Direction {}]() { - return std::exchange(start, adj(start, step)); - }); - return v; -} - -template typename Rtn = std::vector, IterableCollection In> -[[nodiscard]] auto -materializeRange(In && in) -{ - return Rtn(in.begin(), in.end()); -} - -template typename Rtn = std::vector, typename In> -[[nodiscard]] auto -materializeRange(const std::pair & in) -{ - return Rtn(in.first, in.second); -} - -template struct pair_range { - constexpr auto & - begin() const noexcept - { - return pair.first; - } - constexpr auto & - end() const noexcept - { - return pair.second; - } - const std::pair & pair; -}; -template pair_range(std::pair) -> pair_range; diff --git a/lib/embed-glsl.cpp.m4 b/lib/embed-glsl.cpp.m4 index 5b25e0a..3503f75 100644 --- a/lib/embed-glsl.cpp.m4 +++ b/lib/embed-glsl.cpp.m4 @@ -3,7 +3,7 @@ changecom()dnl #include "substr(TYPE,1)-NAME.h" #include #include "gfx/gl/shader.h" -#include "lib/strings.hpp" +#include "lib/strings.h" constexpr const GLchar * src { R"GLSL-EMBED(dnl include(SOURCE))GLSL-EMBED" }; diff --git a/lib/enumDetails.h b/lib/enumDetails.h new file mode 100644 index 0000000..5966be2 --- /dev/null +++ b/lib/enumDetails.h @@ -0,0 +1,143 @@ +#pragma once + +#include +#include +#include +#include +#include + +/// EnumDetailsBase +// Shared helpers +struct EnumDetailsBase { + template + constexpr static auto + strArr(auto input, auto start, auto end) + { + std::array out; + input.copy(out.begin(), end - start, start); + return out; + } +}; + +/// EnumTypeDetails +// Extracts the fully qualified name of the enumeration +template struct EnumTypeDetails : EnumDetailsBase { +#ifndef ENUM_PROBE +protected: +#endif + constexpr static std::string_view SEARCH_TYPE {"E = "}; + constexpr static auto + typeraw() + { + return std::string_view {__PRETTY_FUNCTION__}; + }; + constexpr static auto typeNameStart {typeraw().find(SEARCH_TYPE) + SEARCH_TYPE.length()}; + constexpr static auto typeNameEnd {typeraw().find_first_of("];", typeNameStart)}; + constexpr static auto typeNameLen {typeNameEnd - typeNameStart}; + constexpr static auto typeNameArr {strArr(typeraw(), typeNameStart, typeNameEnd)}; + +public: + constexpr static std::string_view typeName {typeNameArr.data(), typeNameArr.size()}; +}; + +/// EnumValueDetails +// Extracts the value name and constructs string_views of the parts +template struct EnumValueDetails : public EnumTypeDetails { +#ifndef ENUM_PROBE +private: +#endif + using T = EnumTypeDetails; + constexpr static auto + raw() + { + return std::string_view {__PRETTY_FUNCTION__}; + }; + constexpr static auto nameStart {raw().find_last_of(": ") + 1}; + constexpr static auto nameEnd {raw().find_first_of("];", nameStart)}; + constexpr static auto nameLen {nameEnd - nameStart}; + constexpr static auto nameArr {EnumValueDetails::template strArr(raw(), nameStart, nameEnd)}; + +public: + constexpr static std::string_view valueName {nameArr.data(), nameArr.size()}; + constexpr static auto valid {valueName.back() < '0' || valueName.back() > '9'}; + constexpr static auto raw_value {value}; +}; + +/// EnumValueCollection +// Customisation point for specifying the range of underlying values your enum can have +template struct EnumValueCollection { + using Vs = std::make_integer_sequence; +}; + +/// EnumDetails +// Interface for lookups/checks/etc at runtime +template struct EnumDetails { +#ifndef ENUM_PROBE +private: +#endif + template + constexpr static auto + get_valids(std::integer_sequence) + { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + return std::array {EnumValueDetails(n)>::valid...}; +#pragma GCC diagnostic pop + } + template + constexpr static auto + get_values(std::integer_sequence) + { + return std::array {EnumValueDetails(n)>::raw_value...}; + } + template + constexpr static auto + get_valueNames(std::integer_sequence) + { + return std::array {EnumValueDetails::valueName...}; + } + + using EVC = EnumValueCollection; + constexpr static auto valid_flags {get_valids(typename EVC::Vs {})}; + constexpr static auto valid_count {std::count_if(valid_flags.begin(), valid_flags.end(), std::identity {})}; + + constexpr static auto + lookup(const auto key, const auto & search, const auto & out) + -> std::optional::value_type> + { + if (const auto itr = std::find(search.begin(), search.end(), key); itr != search.end()) { + return out[static_cast(std::distance(search.begin(), itr))]; + } + return std::nullopt; + } + +public: + constexpr static auto values {[]() { + constexpr auto values {get_values(typename EVC::Vs {})}; + static_assert(std::is_sorted(values.begin(), values.end()), "Candidate values must be sorted"); + std::array out; + std::copy_if(values.begin(), values.end(), out.begin(), [valid = valid_flags.begin()](auto) mutable { + return *valid++; + }); + return out; + }()}; + constexpr static auto names {get_valueNames(std::make_integer_sequence {})}; + + constexpr static bool + is_valid(E value) noexcept + { + return std::binary_search(values.begin(), values.end(), value); + } + + constexpr static std::optional + parse(std::string_view name) noexcept + { + return lookup(name, names, values); + } + + constexpr static std::optional + to_string(E value) noexcept + { + return lookup(value, values, names); + } +}; diff --git a/lib/enumDetails.hpp b/lib/enumDetails.hpp deleted file mode 100644 index 5966be2..0000000 --- a/lib/enumDetails.hpp +++ /dev/null @@ -1,143 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -/// EnumDetailsBase -// Shared helpers -struct EnumDetailsBase { - template - constexpr static auto - strArr(auto input, auto start, auto end) - { - std::array out; - input.copy(out.begin(), end - start, start); - return out; - } -}; - -/// EnumTypeDetails -// Extracts the fully qualified name of the enumeration -template struct EnumTypeDetails : EnumDetailsBase { -#ifndef ENUM_PROBE -protected: -#endif - constexpr static std::string_view SEARCH_TYPE {"E = "}; - constexpr static auto - typeraw() - { - return std::string_view {__PRETTY_FUNCTION__}; - }; - constexpr static auto typeNameStart {typeraw().find(SEARCH_TYPE) + SEARCH_TYPE.length()}; - constexpr static auto typeNameEnd {typeraw().find_first_of("];", typeNameStart)}; - constexpr static auto typeNameLen {typeNameEnd - typeNameStart}; - constexpr static auto typeNameArr {strArr(typeraw(), typeNameStart, typeNameEnd)}; - -public: - constexpr static std::string_view typeName {typeNameArr.data(), typeNameArr.size()}; -}; - -/// EnumValueDetails -// Extracts the value name and constructs string_views of the parts -template struct EnumValueDetails : public EnumTypeDetails { -#ifndef ENUM_PROBE -private: -#endif - using T = EnumTypeDetails; - constexpr static auto - raw() - { - return std::string_view {__PRETTY_FUNCTION__}; - }; - constexpr static auto nameStart {raw().find_last_of(": ") + 1}; - constexpr static auto nameEnd {raw().find_first_of("];", nameStart)}; - constexpr static auto nameLen {nameEnd - nameStart}; - constexpr static auto nameArr {EnumValueDetails::template strArr(raw(), nameStart, nameEnd)}; - -public: - constexpr static std::string_view valueName {nameArr.data(), nameArr.size()}; - constexpr static auto valid {valueName.back() < '0' || valueName.back() > '9'}; - constexpr static auto raw_value {value}; -}; - -/// EnumValueCollection -// Customisation point for specifying the range of underlying values your enum can have -template struct EnumValueCollection { - using Vs = std::make_integer_sequence; -}; - -/// EnumDetails -// Interface for lookups/checks/etc at runtime -template struct EnumDetails { -#ifndef ENUM_PROBE -private: -#endif - template - constexpr static auto - get_valids(std::integer_sequence) - { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" - return std::array {EnumValueDetails(n)>::valid...}; -#pragma GCC diagnostic pop - } - template - constexpr static auto - get_values(std::integer_sequence) - { - return std::array {EnumValueDetails(n)>::raw_value...}; - } - template - constexpr static auto - get_valueNames(std::integer_sequence) - { - return std::array {EnumValueDetails::valueName...}; - } - - using EVC = EnumValueCollection; - constexpr static auto valid_flags {get_valids(typename EVC::Vs {})}; - constexpr static auto valid_count {std::count_if(valid_flags.begin(), valid_flags.end(), std::identity {})}; - - constexpr static auto - lookup(const auto key, const auto & search, const auto & out) - -> std::optional::value_type> - { - if (const auto itr = std::find(search.begin(), search.end(), key); itr != search.end()) { - return out[static_cast(std::distance(search.begin(), itr))]; - } - return std::nullopt; - } - -public: - constexpr static auto values {[]() { - constexpr auto values {get_values(typename EVC::Vs {})}; - static_assert(std::is_sorted(values.begin(), values.end()), "Candidate values must be sorted"); - std::array out; - std::copy_if(values.begin(), values.end(), out.begin(), [valid = valid_flags.begin()](auto) mutable { - return *valid++; - }); - return out; - }()}; - constexpr static auto names {get_valueNames(std::make_integer_sequence {})}; - - constexpr static bool - is_valid(E value) noexcept - { - return std::binary_search(values.begin(), values.end(), value); - } - - constexpr static std::optional - parse(std::string_view name) noexcept - { - return lookup(name, names, values); - } - - constexpr static std::optional - to_string(E value) noexcept - { - return lookup(value, values, names); - } -}; diff --git a/lib/filesystem.h b/lib/filesystem.h index 5315183..b076f43 100644 --- a/lib/filesystem.h +++ b/lib/filesystem.h @@ -1,7 +1,7 @@ #pragma once -#include "ptr.hpp" -#include "special_members.hpp" +#include "ptr.h" +#include "special_members.h" #include #include #include diff --git a/lib/geometricPlane.cpp b/lib/geometricPlane.cpp index 71216c1..ea4f02d 100644 --- a/lib/geometricPlane.cpp +++ b/lib/geometricPlane.cpp @@ -1,5 +1,5 @@ #include "geometricPlane.h" -#include "ray.hpp" +#include "ray.h" #include #include diff --git a/lib/glArrays.h b/lib/glArrays.h index 42f1d0f..8c8c0bc 100644 --- a/lib/glArrays.h +++ b/lib/glArrays.h @@ -4,7 +4,7 @@ #include // IWYU pragma: keep #include #include -#include +#include template class glArraysBase { static_assert(N > 0); diff --git a/lib/glRef.h b/lib/glRef.h new file mode 100644 index 0000000..3031cf5 --- /dev/null +++ b/lib/glRef.h @@ -0,0 +1,62 @@ +#pragma once + +#include +#include + +template class glRef { +public: + // cppcheck-suppress redundantPointerOp + template explicit glRef(Args &&... args) : id {(*get)(fixed..., std::forward(args)...)} + { + if (!id) { + throw std::runtime_error("Get function failed"); + } + } + + glRef(glRef && other) : id {other.id} + { + other.id = {}; + } + + ~glRef() + { + if (id) { + // cppcheck-suppress redundantPointerOp + (*release)(id); + } + } + + NO_COPY(glRef); + + const auto & + operator=(glRef && other) + { + if (id) { + // cppcheck-suppress redundantPointerOp + (*release)(id); + } + id = other.id; + other.id = {}; + return *this; + } + + auto + operator*() const + { + return id; + } + + auto + operator->() const + { + return id; + } + + operator IdType() const + { + return id; + } + +private: + IdType id; +}; diff --git a/lib/glRef.hpp b/lib/glRef.hpp deleted file mode 100644 index 1ab239d..0000000 --- a/lib/glRef.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#include -#include - -template class glRef { -public: - // cppcheck-suppress redundantPointerOp - template explicit glRef(Args &&... args) : id {(*get)(fixed..., std::forward(args)...)} - { - if (!id) { - throw std::runtime_error("Get function failed"); - } - } - - glRef(glRef && other) : id {other.id} - { - other.id = {}; - } - - ~glRef() - { - if (id) { - // cppcheck-suppress redundantPointerOp - (*release)(id); - } - } - - NO_COPY(glRef); - - const auto & - operator=(glRef && other) - { - if (id) { - // cppcheck-suppress redundantPointerOp - (*release)(id); - } - id = other.id; - other.id = {}; - return *this; - } - - auto - operator*() const - { - return id; - } - - auto - operator->() const - { - return id; - } - - operator IdType() const - { - return id; - } - -private: - IdType id; -}; diff --git a/lib/gl_traits.h b/lib/gl_traits.h new file mode 100644 index 0000000..6ff8905 --- /dev/null +++ b/lib/gl_traits.h @@ -0,0 +1,77 @@ +#pragma once + +#include +#include +#include +#include + +template struct gl_traits; +struct gl_traits_base { + static constexpr GLint size {1}; +}; +struct gl_traits_float : public gl_traits_base { + static constexpr auto vertexAttribFunc { + [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { + glVertexAttribPointer(index, size, type, GL_FALSE, stride, pointer); + return 1; + }}; +}; +struct gl_traits_longfloat : public gl_traits_base { + static constexpr auto vertexAttribFunc { + [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { + glVertexAttribLPointer(index, size, type, stride, pointer); + return 1; + }}; +}; +struct gl_traits_integer : public gl_traits_base { + static constexpr auto vertexAttribFunc { + [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { + glVertexAttribIPointer(index, size, type, stride, pointer); + return 1; + }}; +}; +template<> struct gl_traits : public gl_traits_float { + static constexpr GLenum type {GL_FLOAT}; +}; +template<> struct gl_traits : public gl_traits_longfloat { + static constexpr GLenum type {GL_DOUBLE}; +}; +template<> struct gl_traits : public gl_traits_integer { + static constexpr GLenum type {GL_BYTE}; +}; +template<> struct gl_traits : public gl_traits_integer { + static constexpr GLenum type {GL_SHORT}; +}; +template<> struct gl_traits : public gl_traits_integer { + static constexpr GLenum type {GL_INT}; +}; +template<> struct gl_traits : public gl_traits_integer { + static constexpr GLenum type {GL_UNSIGNED_BYTE}; +}; +template<> struct gl_traits : public gl_traits_integer { + static constexpr GLenum type {GL_UNSIGNED_SHORT}; +}; +template<> struct gl_traits : public gl_traits_integer { + static constexpr GLenum type {GL_UNSIGNED_INT}; +}; + +template struct gl_traits> : public gl_traits { + static constexpr GLint size {S * gl_traits::size}; +}; + +template struct gl_traits> : public gl_traits { + static constexpr GLint size {L}; +}; + +template +struct gl_traits> : public gl_traits { + static constexpr GLint size {C * R}; + static constexpr auto vertexAttribFunc { + [](GLuint index, GLint, GLenum type, GLsizei stride, const void * pointer) -> GLuint { + const auto base = static_cast(pointer); + for (GLuint r = 0; r < R; r++) { + glVertexAttribPointer(index + r, C, type, GL_FALSE, stride, base + (r * C)); + } + return R; + }}; +}; diff --git a/lib/gl_traits.hpp b/lib/gl_traits.hpp deleted file mode 100644 index 6ff8905..0000000 --- a/lib/gl_traits.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -template struct gl_traits; -struct gl_traits_base { - static constexpr GLint size {1}; -}; -struct gl_traits_float : public gl_traits_base { - static constexpr auto vertexAttribFunc { - [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { - glVertexAttribPointer(index, size, type, GL_FALSE, stride, pointer); - return 1; - }}; -}; -struct gl_traits_longfloat : public gl_traits_base { - static constexpr auto vertexAttribFunc { - [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { - glVertexAttribLPointer(index, size, type, stride, pointer); - return 1; - }}; -}; -struct gl_traits_integer : public gl_traits_base { - static constexpr auto vertexAttribFunc { - [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { - glVertexAttribIPointer(index, size, type, stride, pointer); - return 1; - }}; -}; -template<> struct gl_traits : public gl_traits_float { - static constexpr GLenum type {GL_FLOAT}; -}; -template<> struct gl_traits : public gl_traits_longfloat { - static constexpr GLenum type {GL_DOUBLE}; -}; -template<> struct gl_traits : public gl_traits_integer { - static constexpr GLenum type {GL_BYTE}; -}; -template<> struct gl_traits : public gl_traits_integer { - static constexpr GLenum type {GL_SHORT}; -}; -template<> struct gl_traits : public gl_traits_integer { - static constexpr GLenum type {GL_INT}; -}; -template<> struct gl_traits : public gl_traits_integer { - static constexpr GLenum type {GL_UNSIGNED_BYTE}; -}; -template<> struct gl_traits : public gl_traits_integer { - static constexpr GLenum type {GL_UNSIGNED_SHORT}; -}; -template<> struct gl_traits : public gl_traits_integer { - static constexpr GLenum type {GL_UNSIGNED_INT}; -}; - -template struct gl_traits> : public gl_traits { - static constexpr GLint size {S * gl_traits::size}; -}; - -template struct gl_traits> : public gl_traits { - static constexpr GLint size {L}; -}; - -template -struct gl_traits> : public gl_traits { - static constexpr GLint size {C * R}; - static constexpr auto vertexAttribFunc { - [](GLuint index, GLint, GLenum type, GLsizei stride, const void * pointer) -> GLuint { - const auto base = static_cast(pointer); - for (GLuint r = 0; r < R; r++) { - glVertexAttribPointer(index + r, C, type, GL_FALSE, stride, base + (r * C)); - } - return R; - }}; -}; diff --git a/lib/location.cpp b/lib/location.cpp index bff27a2..732dd6d 100644 --- a/lib/location.cpp +++ b/lib/location.cpp @@ -1,4 +1,4 @@ -#include "location.hpp" +#include "location.h" #include "maths.h" #include diff --git a/lib/location.h b/lib/location.h new file mode 100644 index 0000000..078f5d3 --- /dev/null +++ b/lib/location.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +class Location { +public: + explicit Location(glm::vec3 pos = {}, glm::vec3 rot = {}) : pos {pos}, rot {rot} { } + + glm::mat4 getTransform() const; + + glm::vec3 pos; + glm::vec3 rot; +}; diff --git a/lib/location.hpp b/lib/location.hpp deleted file mode 100644 index 078f5d3..0000000 --- a/lib/location.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include - -class Location { -public: - explicit Location(glm::vec3 pos = {}, glm::vec3 rot = {}) : pos {pos}, rot {rot} { } - - glm::mat4 getTransform() const; - - glm::vec3 pos; - glm::vec3 rot; -}; diff --git a/lib/persistence.h b/lib/persistence.h index cc2e4e5..5d71d4c 100644 --- a/lib/persistence.h +++ b/lib/persistence.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/lib/ptr.h b/lib/ptr.h new file mode 100644 index 0000000..b7d15a1 --- /dev/null +++ b/lib/ptr.h @@ -0,0 +1,67 @@ +#pragma once + +#include +#include + +template class wrapped_ptr { +public: + template + explicit wrapped_ptr(Obj * (*factory)(Params...), Args &&... args) : obj {factory(std::forward(args)...)} + { + } + + explicit wrapped_ptr(wrapped_ptr && p) : obj {p.obj} + { + p.obj = nullptr; + } + + ~wrapped_ptr() + { + if (obj) { + Destroy(obj); + } + } + + NO_COPY(wrapped_ptr); + + wrapped_ptr & + operator=(wrapped_ptr && p) + { + if (obj) { + Destroy(obj); + } + obj = p.obj; + p.obj = nullptr; + return *this; + } + + [[nodiscard]] inline + operator Obj *() const noexcept + { + return obj; + } + + [[nodiscard]] inline auto + operator->() const noexcept + { + return obj; + } + + [[nodiscard]] inline auto + get() const noexcept + { + return obj; + } + +protected: + explicit wrapped_ptr(Obj * o) : obj {o} { } + Obj * obj; +}; + +template class wrapped_ptrt : public wrapped_ptr { +public: + template + explicit wrapped_ptrt(Args &&... args) : wrapped_ptr {Create(std::forward(args)...)} + { + } +}; diff --git a/lib/ptr.hpp b/lib/ptr.hpp deleted file mode 100644 index 931df39..0000000 --- a/lib/ptr.hpp +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once - -#include -#include - -template class wrapped_ptr { -public: - template - explicit wrapped_ptr(Obj * (*factory)(Params...), Args &&... args) : obj {factory(std::forward(args)...)} - { - } - - explicit wrapped_ptr(wrapped_ptr && p) : obj {p.obj} - { - p.obj = nullptr; - } - - ~wrapped_ptr() - { - if (obj) { - Destroy(obj); - } - } - - NO_COPY(wrapped_ptr); - - wrapped_ptr & - operator=(wrapped_ptr && p) - { - if (obj) { - Destroy(obj); - } - obj = p.obj; - p.obj = nullptr; - return *this; - } - - [[nodiscard]] inline - operator Obj *() const noexcept - { - return obj; - } - - [[nodiscard]] inline auto - operator->() const noexcept - { - return obj; - } - - [[nodiscard]] inline auto - get() const noexcept - { - return obj; - } - -protected: - explicit wrapped_ptr(Obj * o) : obj {o} { } - Obj * obj; -}; - -template class wrapped_ptrt : public wrapped_ptr { -public: - template - explicit wrapped_ptrt(Args &&... args) : wrapped_ptr {Create(std::forward(args)...)} - { - } -}; diff --git a/lib/ray.cpp b/lib/ray.cpp index f9e3311..c4e0d8c 100644 --- a/lib/ray.cpp +++ b/lib/ray.cpp @@ -1,4 +1,4 @@ -#include "ray.hpp" +#include "ray.h" #include Ray diff --git a/lib/ray.h b/lib/ray.h new file mode 100644 index 0000000..9bf47af --- /dev/null +++ b/lib/ray.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +class Ray { +public: + Ray(glm::vec3 start, glm::vec3 direction) : start {start}, direction {direction} { } + + static Ray fromPoints(glm::vec3, glm::vec3); + + glm::vec3 start; + glm::vec3 direction; + + float distanceToLine(const glm::vec3 & a, const glm::vec3 & b) const; + bool passesCloseToEdges(const std::span positions, float distance) const; +}; diff --git a/lib/ray.hpp b/lib/ray.hpp deleted file mode 100644 index 9bf47af..0000000 --- a/lib/ray.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include - -class Ray { -public: - Ray(glm::vec3 start, glm::vec3 direction) : start {start}, direction {direction} { } - - static Ray fromPoints(glm::vec3, glm::vec3); - - glm::vec3 start; - glm::vec3 direction; - - float distanceToLine(const glm::vec3 & a, const glm::vec3 & b) const; - bool passesCloseToEdges(const std::span positions, float distance) const; -}; diff --git a/lib/sorting.h b/lib/sorting.h new file mode 100644 index 0000000..777de00 --- /dev/null +++ b/lib/sorting.h @@ -0,0 +1,49 @@ +#pragma once + +#include +#include + +template struct PtrSorter { + bool + operator()(const T & a, const T & b) const + { + return *a < *b; + } +}; + +template struct PtrMemberSorter : public PtrSorter { + using MT = std::decay_t; + using is_transparent = MT; + + using PtrSorter::operator(); + + bool + operator()(const MT & a, const T & b) const + { + return a < (*b).*M; + } + + bool + operator()(const T & a, const MT & b) const + { + return (*a).*M < b; + } +}; + +struct CompareBy { + glm::length_t index; + + template + auto + operator()(const T & a, const T & b) const + { + return get(a) < get(b); + } + + template + auto + get(const T & a) const + { + return a[index]; + } +}; diff --git a/lib/sorting.hpp b/lib/sorting.hpp deleted file mode 100644 index 777de00..0000000 --- a/lib/sorting.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include -#include - -template struct PtrSorter { - bool - operator()(const T & a, const T & b) const - { - return *a < *b; - } -}; - -template struct PtrMemberSorter : public PtrSorter { - using MT = std::decay_t; - using is_transparent = MT; - - using PtrSorter::operator(); - - bool - operator()(const MT & a, const T & b) const - { - return a < (*b).*M; - } - - bool - operator()(const T & a, const MT & b) const - { - return (*a).*M < b; - } -}; - -struct CompareBy { - glm::length_t index; - - template - auto - operator()(const T & a, const T & b) const - { - return get(a) < get(b); - } - - template - auto - get(const T & a) const - { - return a[index]; - } -}; diff --git a/lib/special_members.h b/lib/special_members.h new file mode 100644 index 0000000..312862b --- /dev/null +++ b/lib/special_members.h @@ -0,0 +1,29 @@ +#pragma once + +#define NO_COPY(TYPE) \ + TYPE(const TYPE &) = delete; \ + void operator=(const TYPE &) = delete + +#define NO_MOVE(TYPE) \ + TYPE(TYPE &&) = delete; \ + void operator=(TYPE &&) = delete + +#define DEFAULT_MOVE(TYPE) \ + TYPE(TYPE &&) noexcept = default; \ + TYPE & operator=(TYPE &&) noexcept = default + +#define DEFAULT_COPY(TYPE) \ + TYPE(const TYPE &) = default; \ + TYPE & operator=(const TYPE &) = default + +#define DEFAULT_MOVE_COPY(TYPE) \ + DEFAULT_MOVE(TYPE); \ + DEFAULT_COPY(TYPE) + +#define DEFAULT_MOVE_NO_COPY(TYPE) \ + DEFAULT_MOVE(TYPE); \ + NO_COPY(TYPE) + +#define CUSTOM_MOVE(TYPE) \ + TYPE(TYPE &&) noexcept; \ + TYPE & operator=(TYPE &&) noexcept diff --git a/lib/special_members.hpp b/lib/special_members.hpp deleted file mode 100644 index 312862b..0000000 --- a/lib/special_members.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#define NO_COPY(TYPE) \ - TYPE(const TYPE &) = delete; \ - void operator=(const TYPE &) = delete - -#define NO_MOVE(TYPE) \ - TYPE(TYPE &&) = delete; \ - void operator=(TYPE &&) = delete - -#define DEFAULT_MOVE(TYPE) \ - TYPE(TYPE &&) noexcept = default; \ - TYPE & operator=(TYPE &&) noexcept = default - -#define DEFAULT_COPY(TYPE) \ - TYPE(const TYPE &) = default; \ - TYPE & operator=(const TYPE &) = default - -#define DEFAULT_MOVE_COPY(TYPE) \ - DEFAULT_MOVE(TYPE); \ - DEFAULT_COPY(TYPE) - -#define DEFAULT_MOVE_NO_COPY(TYPE) \ - DEFAULT_MOVE(TYPE); \ - NO_COPY(TYPE) - -#define CUSTOM_MOVE(TYPE) \ - TYPE(TYPE &&) noexcept; \ - TYPE & operator=(TYPE &&) noexcept diff --git a/lib/stdTypeDefs.h b/lib/stdTypeDefs.h new file mode 100644 index 0000000..317cdb3 --- /dev/null +++ b/lib/stdTypeDefs.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include + +template struct AnyPtr { + // cppcheck-suppress noExplicitConstructor + AnyPtr(T * p) : ptr {p} { } + // cppcheck-suppress noExplicitConstructor + template AnyPtr(const S & p) : ptr {p.get()} { } + auto + get() const + { + return ptr; + } + auto + operator->() const + { + return ptr; + } + auto & + operator*() const + { + return *ptr; + } + +private: + T * ptr; +}; + +template struct StdTypeDefs { + using AnyPtr = ::AnyPtr; + using AnyCPtr = ::AnyPtr; + using Ptr = std::shared_ptr; + using CPtr = std::shared_ptr; + using WPtr = std::weak_ptr; + using Collection = std::vector; + using CCollection = std::vector; + using WCollection = std::vector; +}; + +template struct ConstTypeDefs { + using Ptr = std::shared_ptr; + using Collection = std::vector; +}; diff --git a/lib/stdTypeDefs.hpp b/lib/stdTypeDefs.hpp deleted file mode 100644 index 317cdb3..0000000 --- a/lib/stdTypeDefs.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include -#include - -template struct AnyPtr { - // cppcheck-suppress noExplicitConstructor - AnyPtr(T * p) : ptr {p} { } - // cppcheck-suppress noExplicitConstructor - template AnyPtr(const S & p) : ptr {p.get()} { } - auto - get() const - { - return ptr; - } - auto - operator->() const - { - return ptr; - } - auto & - operator*() const - { - return *ptr; - } - -private: - T * ptr; -}; - -template struct StdTypeDefs { - using AnyPtr = ::AnyPtr; - using AnyCPtr = ::AnyPtr; - using Ptr = std::shared_ptr; - using CPtr = std::shared_ptr; - using WPtr = std::weak_ptr; - using Collection = std::vector; - using CCollection = std::vector; - using WCollection = std::vector; -}; - -template struct ConstTypeDefs { - using Ptr = std::shared_ptr; - using Collection = std::vector; -}; diff --git a/lib/stream_support.h b/lib/stream_support.h new file mode 100644 index 0000000..7fb256c --- /dev/null +++ b/lib/stream_support.h @@ -0,0 +1,86 @@ +#pragma once + +#include "enumDetails.h" +#include +#include +#include +#include +#include +#include + +template +concept stringlike = requires(const S & s) { s.substr(0); }; +template +concept spanable = std::is_constructible_v, T> && ! +stringlike && !std::is_same_v, T>; + +namespace std { + template + std::ostream & + operator<<(std::ostream & s, const span v) + { + s << '('; + for (const auto & i : v) { + if (&i != &v.front()) { + s << ", "; + } + s << i; + } + return s << ')'; + } + + template + std::ostream & + operator<<(std::ostream & s, const glm::mat & m) + { + return (s << std::span {&m[0], L}); + } + + template + std::ostream & + operator<<(std::ostream & s, const glm::vec & v) + { + return (s << std::span {&v[0], L}); + } + + template + std::ostream & + operator<<(std::ostream & s, const T & v) + { + return (s << std::span {v}); + } + + template + std::ostream & + operator<<(std::ostream & s, const std::pair & v) + { + return (s << '(' << v.first << ", " << v.second << ')'); + } + + inline std::ostream & + operator<<(std::ostream & s, const Arc & arc) + { + return s << arc.first << " ↺ " << arc.second; + } + + template + concept IsEnum = std::is_enum_v; + + template + inline std::ostream & + operator<<(std::ostream & s, const E & e) + { + return s << EnumTypeDetails::typeName << "::" << EnumDetails::to_string(e).value(); + } +} + +template +std::string +streamed_string(const T & v) +{ + std::stringstream ss; + ss << v; + return std::move(ss).str(); +} + +#define CLOG(x) std::cerr << __LINE__ << " : " #x " : " << x << "\n"; diff --git a/lib/stream_support.hpp b/lib/stream_support.hpp deleted file mode 100644 index 52cc9d9..0000000 --- a/lib/stream_support.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#pragma once - -#include "enumDetails.hpp" -#include -#include -#include -#include -#include -#include - -template -concept stringlike = requires(const S & s) { s.substr(0); }; -template -concept spanable = std::is_constructible_v, T> && ! -stringlike && !std::is_same_v, T>; - -namespace std { - template - std::ostream & - operator<<(std::ostream & s, const span v) - { - s << '('; - for (const auto & i : v) { - if (&i != &v.front()) { - s << ", "; - } - s << i; - } - return s << ')'; - } - - template - std::ostream & - operator<<(std::ostream & s, const glm::mat & m) - { - return (s << std::span {&m[0], L}); - } - - template - std::ostream & - operator<<(std::ostream & s, const glm::vec & v) - { - return (s << std::span {&v[0], L}); - } - - template - std::ostream & - operator<<(std::ostream & s, const T & v) - { - return (s << std::span {v}); - } - - template - std::ostream & - operator<<(std::ostream & s, const std::pair & v) - { - return (s << '(' << v.first << ", " << v.second << ')'); - } - - inline std::ostream & - operator<<(std::ostream & s, const Arc & arc) - { - return s << arc.first << " ↺ " << arc.second; - } - - template - concept IsEnum = std::is_enum_v; - - template - inline std::ostream & - operator<<(std::ostream & s, const E & e) - { - return s << EnumTypeDetails::typeName << "::" << EnumDetails::to_string(e).value(); - } -} - -template -std::string -streamed_string(const T & v) -{ - std::stringstream ss; - ss << v; - return std::move(ss).str(); -} - -#define CLOG(x) std::cerr << __LINE__ << " : " #x " : " << x << "\n"; diff --git a/lib/strings.h b/lib/strings.h new file mode 100644 index 0000000..9dca9ac --- /dev/null +++ b/lib/strings.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +constexpr auto +constexpr_strlen(const GLchar * const s) +{ + std::size_t ch {}; + while (s[ch]) { + ch++; + } + return ch; +} diff --git a/lib/strings.hpp b/lib/strings.hpp deleted file mode 100644 index 9dca9ac..0000000 --- a/lib/strings.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -constexpr auto -constexpr_strlen(const GLchar * const s) -{ - std::size_t ch {}; - while (s[ch]) { - ch++; - } - return ch; -} diff --git a/lib/worker.h b/lib/worker.h index d9a5a6f..0d15ca2 100644 --- a/lib/worker.h +++ b/lib/worker.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/test/enumDetailsData.h b/test/enumDetailsData.h new file mode 100644 index 0000000..713d742 --- /dev/null +++ b/test/enumDetailsData.h @@ -0,0 +1,20 @@ +#pragma once +#include + +enum GlobalUnscoped { aa, b, c }; +enum class GlobalScoped { aa, b, c }; +namespace ns { + enum Unscoped { aa, b, c }; + enum class Scoped { aa, b, c }; +} +namespace test1 { + enum class DefaultDense { a, bee, ci, de }; +} +namespace test2 { + enum class NumberedSparse { a = 0, bee = 3, ci = -20, de = 100 }; +} + +template<> struct EnumValueCollection { + // Any ordered integer_sequence which includes all enumeration values + using Vs = std::integer_sequence; +}; diff --git a/test/enumDetailsData.hpp b/test/enumDetailsData.hpp deleted file mode 100644 index 0e98af5..0000000 --- a/test/enumDetailsData.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include - -enum GlobalUnscoped { aa, b, c }; -enum class GlobalScoped { aa, b, c }; -namespace ns { - enum Unscoped { aa, b, c }; - enum class Scoped { aa, b, c }; -} -namespace test1 { - enum class DefaultDense { a, bee, ci, de }; -} -namespace test2 { - enum class NumberedSparse { a = 0, bee = 3, ci = -20, de = 100 }; -} - -template<> struct EnumValueCollection { - // Any ordered integer_sequence which includes all enumeration values - using Vs = std::integer_sequence; -}; diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index c0edd66..18dc778 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -14,9 +14,9 @@ #include "game/vehicles/railVehicleClass.h" #include "gfx/gl/sceneRenderer.h" #include "gfx/renderable.h" -#include "lib/collection.hpp" -#include "lib/location.hpp" -#include "lib/stream_support.hpp" +#include "lib/collection.h" +#include "lib/location.h" +#include "lib/stream_support.h" #include "testMainWindow.h" #include "ui/applicationBase.h" diff --git a/test/test-collection.cpp b/test/test-collection.cpp index 9884812..16db792 100644 --- a/test/test-collection.cpp +++ b/test/test-collection.cpp @@ -2,10 +2,10 @@ #include -#include +#include #include -#include -#include +#include +#include #include class Base { diff --git a/test/test-enumDetails.cpp b/test/test-enumDetails.cpp index db2d6d0..0e759e5 100644 --- a/test/test-enumDetails.cpp +++ b/test/test-enumDetails.cpp @@ -1,11 +1,11 @@ #define BOOST_TEST_MODULE test_enumDetails -#include "enumDetailsData.hpp" +#include "enumDetailsData.h" #include "testHelpers.h" #include #include -#include -#include +#include +#include constexpr std::array INVALID_NAMES {"", "missing", "GlobalScoped::aa", "GlobalScoped", "ns::aa", "a", "bb"}; constexpr std::array VALID_NAMES {"aa", "b", "c"}; diff --git a/test/test-geo.cpp b/test/test-geo.cpp index bc442e9..e672e54 100644 --- a/test/test-geo.cpp +++ b/test/test-geo.cpp @@ -3,10 +3,10 @@ #include "testHelpers.h" #include #include -#include +#include #include -#include +#include struct TestGeoData : public GeoData { TestGeoData() : GeoData {{{-10, -5}, {30, 40}}, 5.F} { } diff --git a/test/test-instancing.cpp b/test/test-instancing.cpp index c743ce0..8745484 100644 --- a/test/test-instancing.cpp +++ b/test/test-instancing.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE instancing -#include "stream_support.hpp" +#include "stream_support.h" #include "testHelpers.h" #include "testMainWindow.h" #include "ui/applicationBase.h" diff --git a/test/test-maths.cpp b/test/test-maths.cpp index 6ee2113..a4a881d 100644 --- a/test/test-maths.cpp +++ b/test/test-maths.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/test/test-network.cpp b/test/test-network.cpp index 19c0977..e6241e4 100644 --- a/test/test-network.cpp +++ b/test/test-network.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include #include // IWYU pragma: keep @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/test/test-render.cpp b/test/test-render.cpp index d5e2d87..4bfcad2 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -14,9 +14,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include diff --git a/test/test-static-enumDetails.cpp b/test/test-static-enumDetails.cpp index 03c2203..5f81753 100644 --- a/test/test-static-enumDetails.cpp +++ b/test/test-static-enumDetails.cpp @@ -1,6 +1,6 @@ #define ENUM_PROBE -#include "enumDetailsData.hpp" -#include +#include "enumDetailsData.h" +#include // Test type name static_assert(EnumTypeDetails::typeName == "GlobalUnscoped"); diff --git a/test/test-static-stream_support.cpp b/test/test-static-stream_support.cpp index 367d5a2..3002ccc 100644 --- a/test/test-static-stream_support.cpp +++ b/test/test-static-stream_support.cpp @@ -1,4 +1,4 @@ -#include "stream_support.hpp" +#include "stream_support.h" #include #include diff --git a/test/test-text.cpp b/test/test-text.cpp index 0c73021..3a23818 100644 --- a/test/test-text.cpp +++ b/test/test-text.cpp @@ -3,7 +3,7 @@ #include "testHelpers.h" #include #include -#include +#include #include #include diff --git a/test/test-worker.cpp b/test/test-worker.cpp index 76b7138..cadc366 100644 --- a/test/test-worker.cpp +++ b/test/test-worker.cpp @@ -3,7 +3,7 @@ #include "testHelpers.h" #include #include -#include +#include #include uint32_t diff --git a/test/testRenderOutput.h b/test/testRenderOutput.h index 8a8bdaf..f5cd56b 100644 --- a/test/testRenderOutput.h +++ b/test/testRenderOutput.h @@ -2,7 +2,7 @@ #include "glArrays.h" #include -#include +#include class TestRenderOutput { public: diff --git a/ui/applicationBase.h b/ui/applicationBase.h index 57995ca..9d9b66b 100644 --- a/ui/applicationBase.h +++ b/ui/applicationBase.h @@ -1,6 +1,6 @@ #pragma once -#include +#include class ApplicationBase { public: diff --git a/ui/editNetwork.h b/ui/editNetwork.h index 1ba2e13..eb1677e 100644 --- a/ui/editNetwork.h +++ b/ui/editNetwork.h @@ -1,7 +1,7 @@ #pragma once #include "gameMainSelector.h" -#include "modeHelper.hpp" +#include "modeHelper.h" #include "toolbar.h" #include "worldOverlay.h" #include diff --git a/ui/font.cpp b/ui/font.cpp index 43991f0..108f905 100644 --- a/ui/font.cpp +++ b/ui/font.cpp @@ -5,7 +5,7 @@ #include #include FT_FREETYPE_H #include "glArrays.h" -#include +#include #include #include #include diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp index 0fbf687..081718d 100644 --- a/ui/gameMainSelector.cpp +++ b/ui/gameMainSelector.cpp @@ -1,5 +1,5 @@ #include "gameMainSelector.h" -#include "collection.hpp" +#include "collection.h" #include "text.h" #include "ui/uiComponent.h" #include @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h index aacd67a..98cdf53 100644 --- a/ui/gameMainSelector.h +++ b/ui/gameMainSelector.h @@ -1,7 +1,7 @@ #pragma once #include "SDL_events.h" -#include "special_members.hpp" +#include "special_members.h" #include "uiComponent.h" #include "worldOverlay.h" #include diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index 3f85a4f..30cdada 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -3,12 +3,12 @@ #include "gameMainSelector.h" #include "gfx/camera_controller.h" #include "manualCameraController.h" -#include "modeHelper.hpp" +#include "modeHelper.h" #include "toolbar.h" #include "window.h" #include #include -#include +#include #include #include #include // IWYU pragma: keep diff --git a/ui/gameMainWindow.h b/ui/gameMainWindow.h index d5bcf41..a4e822e 100644 --- a/ui/gameMainWindow.h +++ b/ui/gameMainWindow.h @@ -1,6 +1,6 @@ #pragma once -#include "chronology.hpp" +#include "chronology.h" #include "gfx/gl/sceneRenderer.h" #include "window.h" #include diff --git a/ui/modeHelper.h b/ui/modeHelper.h new file mode 100644 index 0000000..77707f2 --- /dev/null +++ b/ui/modeHelper.h @@ -0,0 +1,39 @@ +#pragma once + +#include +union SDL_Event; + +enum ModeSecondClick { Unset, Reset, NoAction }; +template class Mode { +public: + explicit Mode(Target & t) : target {t} { } + + Target & target; + + template + auto + toggle(Params &&... params) + { + return [params..., this](const SDL_Event &) { + toggleSetMode(std::forward(params)...); + }; + } + +private: + template + void + toggleSetMode(Params &&... params) + { + if (dynamic_cast(target.get())) { + if constexpr (msc == ModeSecondClick::Unset) { + target.reset(); + } + if constexpr (msc == ModeSecondClick::Reset) { + target = std::make_unique(std::forward(params)...); + } + } + else { + target = std::make_unique(std::forward(params)...); + } + } +}; diff --git a/ui/modeHelper.hpp b/ui/modeHelper.hpp deleted file mode 100644 index 77707f2..0000000 --- a/ui/modeHelper.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include -union SDL_Event; - -enum ModeSecondClick { Unset, Reset, NoAction }; -template class Mode { -public: - explicit Mode(Target & t) : target {t} { } - - Target & target; - - template - auto - toggle(Params &&... params) - { - return [params..., this](const SDL_Event &) { - toggleSetMode(std::forward(params)...); - }; - } - -private: - template - void - toggleSetMode(Params &&... params) - { - if (dynamic_cast(target.get())) { - if constexpr (msc == ModeSecondClick::Unset) { - target.reset(); - } - if constexpr (msc == ModeSecondClick::Reset) { - target = std::make_unique(std::forward(params)...); - } - } - else { - target = std::make_unique(std::forward(params)...); - } - } -}; diff --git a/ui/toolbar.h b/ui/toolbar.h index d141139..ea560f5 100644 --- a/ui/toolbar.h +++ b/ui/toolbar.h @@ -1,6 +1,6 @@ #pragma once -#include "collection.hpp" +#include "collection.h" #include "iconButton.h" #include "uiComponent.h" #include diff --git a/ui/uiComponent.h b/ui/uiComponent.h index 8a9613e..75c2284 100644 --- a/ui/uiComponent.h +++ b/ui/uiComponent.h @@ -2,7 +2,7 @@ #include #include -#include +#include class UIShader; union SDL_Event; diff --git a/ui/window.h b/ui/window.h index 8b7d870..be9e114 100644 --- a/ui/window.h +++ b/ui/window.h @@ -1,13 +1,13 @@ #pragma once -#include "chronology.hpp" -#include "collection.hpp" +#include "chronology.h" +#include "collection.h" #include "gfx/gl/uiShader.h" -#include "ptr.hpp" +#include "ptr.h" #include "uiComponent.h" // IWYU pragma: keep #include #include -#include +#include #include using SDL_WindowPtr = wrapped_ptrt; -- cgit v1.2.3