diff --git a/cpp/src/pathfindingdemo.cpp b/cpp/src/pathfindingdemo.cpp index 6e06b70..a75cea2 100644 --- a/cpp/src/pathfindingdemo.cpp +++ b/cpp/src/pathfindingdemo.cpp @@ -151,7 +151,8 @@ void PathFindingDemo::HandleActions(const std::vector &actions) { LOG_INFO("Exit requested"); m_ExitRequested = true; } else if (action.type == UserAction::Type::SET_MOVE_TARGET) { - WorldPos target_pos = m_Camera.WindowToWorld(action.Argument.position); + WorldPos target_pos = + m_Camera.WindowToWorld(std::get(action.Argument)); for (auto &selected_entity : m_SelectedEntities) { LOG_INFO("Calculating path to target: ", target_pos); if (auto sp = selected_entity.lock()) { @@ -166,23 +167,24 @@ void PathFindingDemo::HandleActions(const std::vector &actions) { } } else if (action.type == UserAction::Type::SELECT_PATHFINDER) { using namespace pathfinder; - PathFinderType type = static_cast(action.Argument.number); + PathFinderType type = + static_cast(std::get(action.Argument)); m_PathFinder = pathfinder::utils::create(type, (const Map *)&m_Map); LOG_INFO("Switched to path finding method: ", m_PathFinder->GetName()); } else if (action.type == UserAction::Type::CAMERA_PAN) { - const auto &window_pan = action.Argument.position; + const auto &window_pan = std::get(action.Argument); WorldPos world_pan{window_pan.x(), window_pan.y()}; m_Camera.Pan(world_pan); LOG_INFO("Camera pan delta: ", world_pan); } else if (action.type == UserAction::Type::CAMERA_ZOOM) { - m_Camera.Zoom(action.Argument.float_number); - LOG_INFO("Camera zoom: ", action.Argument.float_number); + m_Camera.Zoom(std::get(action.Argument)); + LOG_INFO("Camera zoom: ", std::get(action.Argument)); } else if (action.type == UserAction::Type::SELECTION_START) { m_SelectionBox.active = true; - m_SelectionBox.start = action.Argument.position; - m_SelectionBox.end = action.Argument.position; + m_SelectionBox.start = std::get(action.Argument); + m_SelectionBox.end = std::get(action.Argument); } else if (action.type == UserAction::Type::SELECTION_END) { - m_SelectionBox.end = action.Argument.position; + m_SelectionBox.end = std::get(action.Argument); m_SelectionBox.active = false; auto diff = m_SelectionBox.end - m_SelectionBox.start; // here we explicitly change the vector type from WindowPos to WindowSize @@ -191,7 +193,7 @@ void PathFindingDemo::HandleActions(const std::vector &actions) { WorldPos end = m_Camera.WindowToWorld(m_SelectionBox.end); SelectEntitiesInRectangle(start, end); } else if (action.type == UserAction::Type::SELECTION_CHANGE) { - m_SelectionBox.end = action.Argument.position; + m_SelectionBox.end = std::get(action.Argument); auto diff = m_SelectionBox.end - m_SelectionBox.start; m_SelectionBox.size = diff.ChangeTag(); } diff --git a/cpp/src/user_input.hpp b/cpp/src/user_input.hpp index 630d470..25cd877 100644 --- a/cpp/src/user_input.hpp +++ b/cpp/src/user_input.hpp @@ -24,25 +24,17 @@ public: SELECTION_END }; - UserAction() : type(Type::NONE), Argument{.number = 0} {} - UserAction(Type t) : type(t), Argument{.number = 0} {} - UserAction(Type t, char key) : type(t), Argument{.key = key} {} - UserAction(Type t, WindowPos v) : type(t), Argument{.position = v} {} - UserAction(Type t, int32_t arg) : type(t), Argument{.number = arg} {} - UserAction(Type t, float arg) : type(t), Argument{.float_number = arg} {} + UserAction() : type(Type::NONE), Argument{0} {} + UserAction(Type t) : type(t), Argument{0} {} + UserAction(Type t, char key) : type(t), Argument{key} {} + UserAction(Type t, WindowPos v) : type(t), Argument{v} {} + UserAction(Type t, int32_t arg) : type(t), Argument{arg} {} + UserAction(Type t, float arg) : type(t), Argument{arg} {} ~UserAction() = default; Type type; - union { - WindowPos position; - char key; - int32_t number; - float float_number; - } Argument; - - // TODO use std::variant - // std::variant Argument; + std::variant Argument; }; class UserInput { diff --git a/cpp/src/window.cpp b/cpp/src/window.cpp index 49ad415..2795b0d 100644 --- a/cpp/src/window.cpp +++ b/cpp/src/window.cpp @@ -62,7 +62,6 @@ std::expected Window::Init() { // Set renderer to the Sprite class Sprite::SetRenderer(m_Renderer); - // TODO this needs to be tied to map size SDL_SetRenderScale(m_Renderer.get(), 1.0f, 1.0f); return {}; @@ -105,7 +104,6 @@ void Window::ClearWindow() { void Window::Flush() { SDL_RenderPresent(m_Renderer.get()); } -// TODO use some struct for color void Window::DrawCircle(const WindowPos &position, float radius, uint8_t R, uint8_t G, uint8_t B) { int cx = static_cast(position.x());