From 779dd1fd05507a29a42b02a183184d811a10de72 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 13 Feb 2022 02:24:01 -0600 Subject: [PATCH] [nostalgia/core] Cleanup --- src/nostalgia/core/context.hpp | 10 +++------- src/nostalgia/core/gfx.hpp | 7 +++++++ src/nostalgia/core/glfw/gfx.cpp | 1 - src/nostalgia/core/ptidxconv.hpp | 15 +++++---------- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index cd842632..95dfbaa2 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -8,6 +8,7 @@ #include "assetmanager.hpp" #include "event.hpp" +#include "input.hpp" namespace nostalgia::common { class Size; @@ -16,13 +17,7 @@ class Size; namespace nostalgia::core { class Context; - -class Drawer { - public: - virtual ~Drawer() = default; - - virtual void draw(Context*) noexcept = 0; -}; +class Drawer; // User Input Output class Context { @@ -31,6 +26,7 @@ class Context { friend constexpr T *applicationData(Context *ctx) noexcept; friend constexpr void setConstantRefresh(Context *ctx, bool) noexcept; friend bool bgStatus(Context *ctx, unsigned bg) noexcept; + friend bool buttonDown(Context *ctx, Key) noexcept; friend common::Size getScreenSize(Context *ctx) noexcept; friend int getScreenHeight(Context *ctx) noexcept; friend int getScreenWidth(Context *ctx) noexcept; diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index ebc797bb..c4a59b8d 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -17,6 +17,13 @@ namespace nostalgia::core { extern char charMap[128]; +class Drawer { + public: + virtual ~Drawer() = default; + + virtual void draw(Context*) noexcept = 0; +}; + enum class TileSheetSpace { Background, Sprite diff --git a/src/nostalgia/core/glfw/gfx.cpp b/src/nostalgia/core/glfw/gfx.cpp index b88302f9..f687e862 100644 --- a/src/nostalgia/core/glfw/gfx.cpp +++ b/src/nostalgia/core/glfw/gfx.cpp @@ -3,7 +3,6 @@ */ #include -#include #include #include diff --git a/src/nostalgia/core/ptidxconv.hpp b/src/nostalgia/core/ptidxconv.hpp index 3c19227c..fe8d4744 100644 --- a/src/nostalgia/core/ptidxconv.hpp +++ b/src/nostalgia/core/ptidxconv.hpp @@ -11,24 +11,19 @@ namespace nostalgia::core { [[nodiscard]] -constexpr std::size_t pointToIdx(int w, int x, int y) noexcept { +constexpr std::size_t ptToIdx(int x, int y, int c) noexcept { constexpr auto colLength = static_cast(PixelsPerTile); - const auto rowLength = static_cast(static_cast(w / TileWidth) * colLength); + const auto rowLength = static_cast(static_cast(c / TileWidth) * colLength); const auto colStart = static_cast(colLength * static_cast(x / TileWidth)); const auto rowStart = static_cast(rowLength * static_cast(y / TileHeight)); const auto colOffset = static_cast(x % TileWidth); - const auto rowOffset = static_cast((y % TileHeight) * TileHeight); + const auto rowOffset = static_cast(static_cast(y % TileHeight) * TileHeight); return static_cast(colStart + colOffset + rowStart + rowOffset); } [[nodiscard]] -constexpr std::size_t ptToIdx(int x, int y, int c) noexcept { - return pointToIdx(c * TileWidth, x, y); -} - -[[nodiscard]] -constexpr std::size_t ptToIdx(common::Point pt, int c) noexcept { - return pointToIdx(c * TileWidth, pt.x, pt.y); +constexpr std::size_t ptToIdx(const common::Point &pt, int c) noexcept { + return ptToIdx(pt.x, pt.y, c * TileWidth); } [[nodiscard]]