summaryrefslogtreecommitdiff
path: root/lib/nes/app
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2025-02-01 01:14:03 +0100
committerHannes Schulze <haschu0103@outlook.de>2025-02-01 01:14:03 +0100
commit9ca793417149cbaa7b5f4b7797bc929e6e191f28 (patch)
tree3f067cad3fe7e606e5e9ea1dd8079874de3f048c /lib/nes/app
parent1d5f5482f91391a6dfee9ec0e7cb0a22ee5f0464 (diff)
use custom integer types
Diffstat (limited to 'lib/nes/app')
-rw-r--r--lib/nes/app/application.hh5
-rw-r--r--lib/nes/app/graphics/color.hh4
-rw-r--r--lib/nes/app/graphics/image-view.hh14
-rw-r--r--lib/nes/app/graphics/mask-tile.hh4
-rw-r--r--lib/nes/app/graphics/renderer.cc24
-rw-r--r--lib/nes/app/graphics/renderer.hh24
-rw-r--r--lib/nes/app/input/input-manager.cc4
-rw-r--r--lib/nes/app/input/input-manager.hh3
8 files changed, 43 insertions, 39 deletions
diff --git a/lib/nes/app/application.hh b/lib/nes/app/application.hh
index 1fc1c6b..91ab35f 100644
--- a/lib/nes/app/application.hh
+++ b/lib/nes/app/application.hh
@@ -5,6 +5,7 @@
#include "nes/sys/nes.hh"
#include "nes/common/box.hh"
#include "nes/common/display.hh"
+#include "nes/common/types.hh"
#include <chrono>
namespace nes::app
@@ -32,8 +33,8 @@ namespace nes::app
{
}
- auto get(unsigned const x, unsigned const y) const -> rgb override { return base.get(x, y); }
- auto set(unsigned const x, unsigned const y, rgb const value) -> void override { base.set(x, y, value); }
+ auto get(u32 const x, u32 const y) const -> rgb override { return base.get(x, y); }
+ auto set(u32 const x, u32 const y, rgb const value) -> void override { base.set(x, y, value); }
auto switch_buffers() -> void override;
};
diff --git a/lib/nes/app/graphics/color.hh b/lib/nes/app/graphics/color.hh
index 572ac25..ae9a1c2 100644
--- a/lib/nes/app/graphics/color.hh
+++ b/lib/nes/app/graphics/color.hh
@@ -1,11 +1,11 @@
#pragma once
-#include <cstdint>
+#include "nes/common/types.hh"
namespace nes::app
{
/// One of the predefined colors in the color palette used for the UI.
- enum class color : std::uint8_t
+ enum class color : u8
{
transparent, ///< No color.
background_primary, ///< The primary background color.
diff --git a/lib/nes/app/graphics/image-view.hh b/lib/nes/app/graphics/image-view.hh
index a9b8e94..cde4989 100644
--- a/lib/nes/app/graphics/image-view.hh
+++ b/lib/nes/app/graphics/image-view.hh
@@ -1,5 +1,7 @@
#pragma once
+#include "nes/common/types.hh"
+
namespace nes::app
{
struct image_tile;
@@ -10,13 +12,13 @@ namespace nes::app
class image_view
{
image_tile const* data_{ nullptr };
- unsigned width_{ 0 };
- unsigned height_{ 0 };
+ u32 width_{ 0 };
+ u32 height_{ 0 };
public:
explicit image_view() = default;
- explicit image_view(image_tile const* data, unsigned const width, unsigned const height)
+ explicit image_view(image_tile const* data, u32 const width, u32 const height)
: data_{ data }
, width_{ width }
, height_{ height }
@@ -24,8 +26,8 @@ namespace nes::app
}
auto get_data() const -> image_tile const* { return data_; }
- auto get_width() const -> unsigned { return width_; }
- auto get_height() const -> unsigned { return height_; }
- auto get(unsigned const x, unsigned const y) const -> image_tile const& { return data_[y * height_ + x]; }
+ auto get_width() const -> u32 { return width_; }
+ auto get_height() const -> u32 { return height_; }
+ auto get(u32 const x, u32 const y) const -> image_tile const& { return data_[y * height_ + x]; }
};
} // namespace nes::app \ No newline at end of file
diff --git a/lib/nes/app/graphics/mask-tile.hh b/lib/nes/app/graphics/mask-tile.hh
index c811003..deb750a 100644
--- a/lib/nes/app/graphics/mask-tile.hh
+++ b/lib/nes/app/graphics/mask-tile.hh
@@ -1,6 +1,6 @@
#pragma once
-#include <cstdint>
+#include "nes/common/types.hh"
namespace nes::app
{
@@ -10,7 +10,7 @@ namespace nes::app
/// integer's row.
struct mask_tile
{
- std::uint8_t data[8]{};
+ u8 data[8]{};
};
namespace tiles
diff --git a/lib/nes/app/graphics/renderer.cc b/lib/nes/app/graphics/renderer.cc
index 8d1a168..1a4dc4d 100644
--- a/lib/nes/app/graphics/renderer.cc
+++ b/lib/nes/app/graphics/renderer.cc
@@ -12,13 +12,13 @@ namespace nes::app
{
}
- auto renderer::render_image_tile(unsigned const x, unsigned const y, image_tile const tile) -> void
+ auto renderer::render_image_tile(u32 const x, u32 const y, image_tile const& tile) -> void
{
if (x >= width || y >= height) { return; }
- for (auto y_px = unsigned{ 0 }; y_px < 8; ++y_px)
+ for (auto y_px = u32{ 0 }; y_px < 8; ++y_px)
{
- for (auto x_px = unsigned{ 0 }; x_px < 8; ++x_px)
+ for (auto x_px = u32{ 0 }; x_px < 8; ++x_px)
{
auto const c = tile.data[y_px * 8 + x_px];
if (c != color::transparent)
@@ -29,16 +29,16 @@ namespace nes::app
}
}
- auto renderer::render_mask_tile(unsigned const x, unsigned const y, mask_tile const tile, color const c) -> void
+ auto renderer::render_mask_tile(u32 const x, u32 const y, mask_tile const tile, color const c) -> void
{
if (c == color::transparent) { return; }
if (x >= width || y >= height) { return; }
auto const resolved = resolve_color(c);
- for (auto y_px = unsigned{ 0 }; y_px < 8; ++y_px)
+ for (auto y_px = u32{ 0 }; y_px < 8; ++y_px)
{
auto row = tile.data[y_px];
- for (auto x_px = unsigned{ 0 }; x_px < 8; ++x_px)
+ for (auto x_px = u32{ 0 }; x_px < 8; ++x_px)
{
if (row & 0b10000000)
{
@@ -49,11 +49,11 @@ namespace nes::app
}
}
- auto renderer::render_image(unsigned const x, unsigned const y, image_view const image) -> void
+ auto renderer::render_image(u32 const x, u32 const y, image_view const image) -> void
{
- for (auto y_img = unsigned{ 0 }; y_img < image.get_height(); ++y_img)
+ for (auto y_img = u32{ 0 }; y_img < image.get_height(); ++y_img)
{
- for (auto x_img = unsigned{ 0 }; x_img < image.get_width(); ++x_img)
+ for (auto x_img = u32{ 0 }; x_img < image.get_width(); ++x_img)
{
render_image_tile(x + x_img, y + y_img, image.get(x, y));
}
@@ -61,7 +61,7 @@ namespace nes::app
}
auto renderer::render_rect(
- unsigned const x, unsigned const y, unsigned const width, unsigned const height, color const c) -> void
+ u32 const x, u32 const y, u32 const width, u32 const height, color const c) -> void
{
if (c == color::transparent) { return; }
if (x >= width || y >= height) { return; }
@@ -69,9 +69,9 @@ namespace nes::app
auto const resolved = resolve_color(c);
auto const x_stop = std::min(x + width, renderer::width);
auto const y_stop = std::min(y + height, renderer::height);
- for (auto y_px = unsigned{ y * 8 }; y_px < y_stop * 8; ++y_px)
+ for (auto y_px = u32{ y * 8 }; y_px < y_stop * 8; ++y_px)
{
- for (auto x_px = unsigned{ x * 8 }; x_px < x_stop * 8; ++x_px)
+ for (auto x_px = u32{ x * 8 }; x_px < x_stop * 8; ++x_px)
{
display_.set(x_px, y_px, resolved);
}
diff --git a/lib/nes/app/graphics/renderer.hh b/lib/nes/app/graphics/renderer.hh
index 7b46461..5de3dcd 100644
--- a/lib/nes/app/graphics/renderer.hh
+++ b/lib/nes/app/graphics/renderer.hh
@@ -1,7 +1,7 @@
#pragma once
+#include "nes/common/types.hh"
#include <string_view>
-#include <cstdint>
namespace nes
{
@@ -14,7 +14,7 @@ namespace nes::app
struct image_tile;
struct mask_tile;
class image_view;
- enum class color : std::uint8_t;
+ enum class color : u8;
/// Renders tiles and other primitive shapes onto a display.
///
@@ -25,8 +25,8 @@ namespace nes::app
display& display_;
public:
- static constexpr auto width = unsigned{ 32 };
- static constexpr auto height = unsigned{ 30 };
+ static constexpr auto width = u32{ 32 };
+ static constexpr auto height = u32{ 30 };
explicit renderer(display&);
@@ -36,23 +36,23 @@ namespace nes::app
auto operator=(renderer&&) -> renderer& = delete;
/// If set, add a drop shadow behind newly drawn opaque elements.
- auto set_shadow(unsigned x_px, unsigned y_px, color) -> void;
+ auto set_shadow(u32 x_px, u32 y_px, color) -> void;
/// If set, add an inner border inside newly drawn opaque elements.
- auto set_border(unsigned px, color) -> void;
+ auto set_border(u32 px, color) -> void;
/// Render a colored tile at the given tile coordinates.
- auto render_image_tile(unsigned x, unsigned y, image_tile) -> void;
+ auto render_image_tile(u32 x, u32 y, image_tile const&) -> void;
/// Render an alpha-only tile at the given tile coordinates with the given color.
- auto render_mask_tile(unsigned x, unsigned y, mask_tile, color) -> void;
+ auto render_mask_tile(u32 x, u32 y, mask_tile, color) -> void;
/// Render an image at the given tile coordinates.
- auto render_image(unsigned x, unsigned y, image_view) -> void;
+ auto render_image(u32 x, u32 y, image_view) -> void;
/// Render a string of text at the given tile coordinates (one tile per character).
- auto render_text(unsigned x, unsigned y, std::string_view, color) -> void;
+ auto render_text(u32 x, u32 y, std::string_view, color) -> void;
/// Render a string of text at the given tile coordinates, limiting its length to the given width and
/// ellipsizing afterward.
- auto render_text(unsigned x, unsigned y, std::string_view, unsigned width, color) -> void;
+ auto render_text(u32 x, u32 y, std::string_view, u32 width, color) -> void;
/// Render a rectangle at the given tile coordinates with a given size (measured in tiles).
- auto render_rect(unsigned x, unsigned y, unsigned width, unsigned height, color) -> void;
+ auto render_rect(u32 x, u32 y, u32 width, u32 height, color) -> void;
/// Completely fill the screen.
auto render_fill(color) -> void;
diff --git a/lib/nes/app/input/input-manager.cc b/lib/nes/app/input/input-manager.cc
index dec899a..8131283 100644
--- a/lib/nes/app/input/input-manager.cc
+++ b/lib/nes/app/input/input-manager.cc
@@ -42,7 +42,7 @@ namespace nes::app
{
// This controller was previously used and assigned an index -> replace the current device with this
// (known) controller.
- auto const i = static_cast<std::size_t>(index);
+ auto const i = static_cast<u32>(index);
if (inputs_[i].controller)
{
inputs_[i].controller->set_index(input_device_controller::index::unused);
@@ -68,7 +68,7 @@ namespace nes::app
auto it = controllers_.begin();
input_device* fallback = keyboard_;
- for (auto i = std::size_t{ 0 }; i < input_count; ++i)
+ for (auto i = u32{ 0 }; i < input_count; ++i)
{
if (inputs_[i].controller != nullptr) { continue; }
diff --git a/lib/nes/app/input/input-manager.hh b/lib/nes/app/input/input-manager.hh
index 525debc..8bc75b8 100644
--- a/lib/nes/app/input/input-manager.hh
+++ b/lib/nes/app/input/input-manager.hh
@@ -3,6 +3,7 @@
#include "nes/app/input/input-device-keyboard.hh"
#include "nes/app/input/input-device-controller.hh"
#include "nes/common/list.hh"
+#include "nes/common/types.hh"
namespace nes::app
{
@@ -12,7 +13,7 @@ namespace nes::app
/// back to the keyboard if needed.
class input_manager
{
- static constexpr auto input_count = std::size_t{ 2 };
+ static constexpr auto input_count = u32{ 2 };
input_device_keyboard* keyboard_;
list<input_device_controller> controllers_;