From 19e60cf08ba8800b7214c0865ebb2fc6b880c7bd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 3 Nov 2023 21:31:35 +0000 Subject: Don't request a specific OpenGL version, just check we get something sufficient from gladLoadGL --- ui/applicationBase.cpp | 3 --- ui/window.cpp | 8 +++----- 2 files changed, 3 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/ui/applicationBase.cpp b/ui/applicationBase.cpp index 32af3af..2be1f6c 100644 --- a/ui/applicationBase.cpp +++ b/ui/applicationBase.cpp @@ -21,9 +21,6 @@ ApplicationBase::ApplicationBase() setGlAttribute(SDL_GL_DEPTH_SIZE, 16); setGlAttribute(SDL_GL_DOUBLEBUFFER, 1); - setGlAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - setGlAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); - setGlAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); setGlAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); } diff --git a/ui/window.cpp b/ui/window.cpp index 93e85bd..6855aa0 100644 --- a/ui/window.cpp +++ b/ui/window.cpp @@ -1,17 +1,15 @@ #include "window.h" #include "uiComponent.h" -#include "worldOverlay.h" #include #include #include -#include -#include Window::GLInitHelper::GLInitHelper() { [[maybe_unused]] static auto init = []() { - if (const auto version = gladLoadGL(reinterpret_cast(SDL_GL_GetProcAddress)); version != 40006) { - throw std::runtime_error {std::to_string(version)}; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + if (const auto version = gladLoadGL(reinterpret_cast(SDL_GL_GetProcAddress)); version < 30003) { + throw std::runtime_error {"Insufficient OpenGL version: " + std::to_string(version)}; } else { return version; -- cgit v1.2.3 From 582ac127f763f512c45f35e17b768487e3b51796 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Nov 2023 17:07:58 +0000 Subject: Rename TerrainMesh to GeoData to drop inplace --- ui/gameMainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index c35c9c6..6981c54 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -31,7 +31,7 @@ public: GameMainWindow::GameMainWindow(size_t w, size_t h) : Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {Window::size, 0} { - uiComponents.create(glm::vec2 {-1150, -1150}); + uiComponents.create(glm::vec2 {315000, 495000}); auto gms = uiComponents.create(&camera, glm::vec2 {w, h}); uiComponents.create(gms.get()); } -- cgit v1.2.3 From d6e99a696aa582b81018078b68f6600c8030d643 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 7 Nov 2023 02:51:42 +0000 Subject: WIP typedefing all the things - headers --- ui/builders/freeExtend.h | 2 +- ui/builders/straight.h | 4 ++-- ui/gameMainSelector.cpp | 2 +- ui/gameMainSelector.h | 3 ++- ui/manualCameraController.h | 4 ++-- ui/window.h | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/ui/builders/freeExtend.h b/ui/builders/freeExtend.h index 55fe7ff..b276426 100644 --- a/ui/builders/freeExtend.h +++ b/ui/builders/freeExtend.h @@ -9,5 +9,5 @@ class BuilderFreeExtend : public EditNetwork::Builder { void click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray) override; void move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray & ray) override; - std::optional p1; + std::optional p1; }; diff --git a/ui/builders/straight.h b/ui/builders/straight.h index 1cde2b0..cf99a1d 100644 --- a/ui/builders/straight.h +++ b/ui/builders/straight.h @@ -9,7 +9,7 @@ class BuilderStraight : public EditNetwork::Builder { void click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray) override; void move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray & ray) override; - void create(Network * network, glm::vec3 p1, glm::vec3 p2) const; + void create(Network * network, Position3D p1, Position3D p2) const; - std::optional p1; + std::optional p1; }; diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp index 6c6935c..808e0e4 100644 --- a/ui/gameMainSelector.cpp +++ b/ui/gameMainSelector.cpp @@ -14,7 +14,7 @@ #include #include -GameMainSelector::GameMainSelector(const Camera * c, glm::vec2 size) : UIComponent {{{}, size}}, camera {c} { } +GameMainSelector::GameMainSelector(const Camera * c, ScreenAbsCoord size) : UIComponent {{{}, size}}, camera {c} { } constexpr glm::vec2 TargetPos {5, 45}; diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h index 98cdf53..88db34b 100644 --- a/ui/gameMainSelector.h +++ b/ui/gameMainSelector.h @@ -1,6 +1,7 @@ #pragma once #include "SDL_events.h" +#include "config/types.h" #include "special_members.h" #include "uiComponent.h" #include "worldOverlay.h" @@ -26,7 +27,7 @@ public: virtual void render(const SceneShader &) const; }; - GameMainSelector(const Camera * c, glm::vec2 size); + GameMainSelector(const Camera * c, ScreenAbsCoord size); void render(const UIShader & shader, const Position & pos) const override; void render(const SceneShader & shader) const override; diff --git a/ui/manualCameraController.h b/ui/manualCameraController.h index d15fa76..46655bc 100644 --- a/ui/manualCameraController.h +++ b/ui/manualCameraController.h @@ -11,7 +11,7 @@ class Camera; class ManualCameraController : public CameraController, public UIComponent { public: - explicit ManualCameraController(glm::vec2 f) : UIComponent {{}}, focus {f} { } + explicit ManualCameraController(Position2D f) : UIComponent {{}}, focus {f} { } bool handleInput(const SDL_Event & e, const Position &) override; void render(const UIShader &, const Position & parentPos) const override; @@ -20,7 +20,7 @@ public: private: bool ctrl {false}, mrb {false}; - glm::vec2 focus; + Position2D focus; float direction {quarter_pi}; float dist {40}, pitch {quarter_pi}; }; diff --git a/ui/window.h b/ui/window.h index 183a65a..8f2b70b 100644 --- a/ui/window.h +++ b/ui/window.h @@ -36,7 +36,7 @@ protected: GLInitHelper(); }; - const glm::ivec2 size; + const ScreenAbsCoord size; SDL_WindowPtr m_window; SDL_GLContextPtr glContext; GLInitHelper glInithelper; -- cgit v1.2.3 From 9c2c3f71065c94a18c02440111b6ff8ca977b90e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 00:40:40 +0000 Subject: WIP typedefing all the things - sources --- ui/builders/straight.cpp | 2 +- ui/gameMainSelector.cpp | 9 +++++---- ui/gameMainWindow.cpp | 4 ++-- ui/manualCameraController.cpp | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/ui/builders/straight.cpp b/ui/builders/straight.cpp index 4fa9585..9b262bb 100644 --- a/ui/builders/straight.cpp +++ b/ui/builders/straight.cpp @@ -47,7 +47,7 @@ BuilderStraight::click(Network * network, const GeoData * geoData, const SDL_Mou } void -BuilderStraight::create(Network * network, glm::vec3 p1, glm::vec3 p2) const +BuilderStraight::create(Network * network, Position3D p1, Position3D p2) const { network->addStraight(p1, p2); } diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp index 808e0e4..a451ee1 100644 --- a/ui/gameMainSelector.cpp +++ b/ui/gameMainSelector.cpp @@ -8,6 +8,7 @@ #include #include // IWYU pragma: keep #include +#include #include #include #include @@ -16,7 +17,7 @@ GameMainSelector::GameMainSelector(const Camera * c, ScreenAbsCoord size) : UIComponent {{{}, size}}, camera {c} { } -constexpr glm::vec2 TargetPos {5, 45}; +constexpr ScreenAbsCoord TargetPos {5, 45}; void GameMainSelector::render(const UIShader & shader, const Position & parentPos) const @@ -41,7 +42,7 @@ bool GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos) { const auto getRay = [this](const auto & e) { - const auto mouse = glm::vec2 {e.x, e.y} / position.size; + const auto mouse = ScreenRelCoord {e.x, e.y} / position.size; return camera->unProject(mouse); }; if (target) { @@ -72,8 +73,8 @@ GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos) void GameMainSelector::defaultClick(const Ray & ray) { - glm::vec2 baryPos {}; - float distance; + Position2D baryPos {}; + float distance {}; if (const auto selected = gameState->world.applyOne(&Selectable::intersectRay, ray, &baryPos, &distance); diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index b94accd..15f1e07 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -31,8 +31,8 @@ public: GameMainWindow::GameMainWindow(size_t w, size_t h) : Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {Window::size, 0} { - uiComponents.create(glm::vec2 {-1150, -1150}); - auto gms = uiComponents.create(&camera, glm::vec2 {w, h}); + uiComponents.create(Position2D {-1150, -1150}); + auto gms = uiComponents.create(&camera, ScreenAbsCoord {w, h}); uiComponents.create(gms.get()); } diff --git a/ui/manualCameraController.cpp b/ui/manualCameraController.cpp index 8e52b0e..05c1fc5 100644 --- a/ui/manualCameraController.cpp +++ b/ui/manualCameraController.cpp @@ -59,7 +59,7 @@ ManualCameraController::handleInput(const SDL_Event & e, const Position &) pitch = std::clamp(pitch - 0.01F * static_cast(e.motion.yrel), 0.1F, half_pi); } else { - focus += rotate_flat(-direction) * glm::vec2 {-e.motion.xrel, e.motion.yrel}; + focus += rotate_flat(-direction) * Position2D {-e.motion.xrel, e.motion.yrel}; } } return true; -- cgit v1.2.3 From d771fbda2c171cfbc36cc0eb3122c1a02ffbb081 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 01:57:27 +0000 Subject: WIP typedefing just about everything else --- ui/editNetwork.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/editNetwork.h b/ui/editNetwork.h index eb1677e..e1aaa61 100644 --- a/ui/editNetwork.h +++ b/ui/editNetwork.h @@ -21,7 +21,7 @@ public: void render(const SceneShader &) const override; void render(const UIShader & shader, const UIComponent::Position & pos) const override; - using NetworkClickPos = std::variant; + using NetworkClickPos = std::variant; class Builder { public: -- cgit v1.2.3 From 685b33980cc7a346574b24732464f0cbe3115a1f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Nov 2023 01:29:24 +0000 Subject: Switch to millimeters for spatial units Mostly a case of changing far too many magic numbers, something else to fix I guess. I probably missed something. Also there's some hackery when loading 3D models, which are still assumed to be in metres. --- ui/gameMainWindow.cpp | 2 +- ui/manualCameraController.cpp | 4 ++-- ui/manualCameraController.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'ui') diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index 15f1e07..7cf143a 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -31,7 +31,7 @@ public: GameMainWindow::GameMainWindow(size_t w, size_t h) : Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {Window::size, 0} { - uiComponents.create(Position2D {-1150, -1150}); + uiComponents.create(Position2D {-1150000, -1150000}); auto gms = uiComponents.create(&camera, ScreenAbsCoord {w, h}); uiComponents.create(gms.get()); } diff --git a/ui/manualCameraController.cpp b/ui/manualCameraController.cpp index 05c1fc5..f6993a8 100644 --- a/ui/manualCameraController.cpp +++ b/ui/manualCameraController.cpp @@ -59,12 +59,12 @@ ManualCameraController::handleInput(const SDL_Event & e, const Position &) pitch = std::clamp(pitch - 0.01F * static_cast(e.motion.yrel), 0.1F, half_pi); } else { - focus += rotate_flat(-direction) * Position2D {-e.motion.xrel, e.motion.yrel}; + focus += rotate_flat(-direction) * (Position2D {-e.motion.xrel, e.motion.yrel} * dist / 2.0F); } } return true; case SDL_MOUSEWHEEL: - dist = std::clamp(dist - static_cast(e.wheel.y) * 4.F, 5.F, 200.F); + dist = std::clamp(dist - static_cast(e.wheel.y) * 400.F, 5.F, 200000.F); break; } return false; diff --git a/ui/manualCameraController.h b/ui/manualCameraController.h index 46655bc..1efaee1 100644 --- a/ui/manualCameraController.h +++ b/ui/manualCameraController.h @@ -22,5 +22,5 @@ private: bool ctrl {false}, mrb {false}; Position2D focus; float direction {quarter_pi}; - float dist {40}, pitch {quarter_pi}; + float dist {4000}, pitch {quarter_pi}; }; -- cgit v1.2.3 From 0841ead91c49a212134f19f7c0b411984b0fda29 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 29 Dec 2023 13:20:55 +0000 Subject: Remove weird operator! on vec2/3 --- ui/manualCameraController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/manualCameraController.cpp b/ui/manualCameraController.cpp index f6993a8..1f6b510 100644 --- a/ui/manualCameraController.cpp +++ b/ui/manualCameraController.cpp @@ -79,5 +79,5 @@ void ManualCameraController::updateCamera(Camera * camera) const { const auto forward = glm::normalize(sincosf(direction) ^ -sin(pitch)); - camera->setView(!focus - forward * 3.F * std::pow(dist, 1.3F), forward); + camera->setView((focus ^ 0.F) - forward * 3.F * std::pow(dist, 1.3F), forward); } -- cgit v1.2.3 From 048f18e2a0b32044525cef41fa053984433c74b9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 29 Dec 2023 14:12:40 +0000 Subject: Remove misleading power operator^ on vec2/3 --- ui/manualCameraController.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/manualCameraController.cpp b/ui/manualCameraController.cpp index 1f6b510..ef26e81 100644 --- a/ui/manualCameraController.cpp +++ b/ui/manualCameraController.cpp @@ -78,6 +78,6 @@ ManualCameraController::render(const UIShader &, const Position &) const void ManualCameraController::updateCamera(Camera * camera) const { - const auto forward = glm::normalize(sincosf(direction) ^ -sin(pitch)); - camera->setView((focus ^ 0.F) - forward * 3.F * std::pow(dist, 1.3F), forward); + const auto forward = glm::normalize(sincosf(direction) || -sin(pitch)); + camera->setView((focus || 0.F) - forward * 3.F * std::pow(dist, 1.3F), forward); } -- cgit v1.2.3