diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-01-31 23:30:56 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-01-31 23:30:56 +0100 |
| commit | ccb81b60dac888e44079fb0228c1d5d8542ceade (patch) | |
| tree | 297b672e2cd4de2ce4203c19b973274c5750e60d | |
| parent | cd8ae0e4f628bd491fcaf1dd4778bc283d619065 (diff) | |
move components into dedicated namespaces
| -rw-r--r-- | app/mac/scene.mm | 8 | ||||
| -rw-r--r-- | lib/nes/app/application.cc | 20 | ||||
| -rw-r--r-- | lib/nes/app/application.hh | 7 | ||||
| -rw-r--r-- | lib/nes/app/input/input-device-controller.hh | 4 | ||||
| -rw-r--r-- | lib/nes/app/input/input-device-keyboard.hh | 4 | ||||
| -rw-r--r-- | lib/nes/app/input/input-device.hh | 24 | ||||
| -rw-r--r-- | lib/nes/app/input/input-manager.cc | 4 | ||||
| -rw-r--r-- | lib/nes/app/input/input-manager.hh | 4 | ||||
| -rw-r--r-- | lib/nes/sys/cartridge.cc | 4 | ||||
| -rw-r--r-- | lib/nes/sys/cartridge.hh | 4 | ||||
| -rw-r--r-- | lib/nes/sys/controller.cc | 4 | ||||
| -rw-r--r-- | lib/nes/sys/controller.hh | 4 | ||||
| -rw-r--r-- | lib/nes/sys/cpu.cc | 4 | ||||
| -rw-r--r-- | lib/nes/sys/cpu.hh | 4 | ||||
| -rw-r--r-- | lib/nes/sys/mapper.cc | 4 | ||||
| -rw-r--r-- | lib/nes/sys/mapper.hh | 4 | ||||
| -rw-r--r-- | lib/nes/sys/nes.cc | 4 | ||||
| -rw-r--r-- | lib/nes/sys/nes.hh | 6 | ||||
| -rw-r--r-- | lib/nes/sys/ppu.cc | 4 | ||||
| -rw-r--r-- | lib/nes/sys/ppu.hh | 10 | ||||
| -rw-r--r-- | lib/nes/sys/types/address.hh | 4 | ||||
| -rw-r--r-- | lib/nes/sys/types/button-mask.hh | 4 | ||||
| -rw-r--r-- | lib/nes/sys/types/cycle-count.hh | 4 | ||||
| -rw-r--r-- | lib/nes/sys/types/snapshot.hh | 4 | ||||
| -rw-r--r-- | lib/nes/sys/types/status.hh | 4 |
25 files changed, 78 insertions, 73 deletions
diff --git a/app/mac/scene.mm b/app/mac/scene.mm index de9c587..aced63b 100644 --- a/app/mac/scene.mm +++ b/app/mac/scene.mm @@ -65,7 +65,7 @@ namespace } }; - class input_device_keyboard_impl final : public nes::input_device_keyboard + class input_device_keyboard_impl final : public nes::app::input_device_keyboard { GCKeyboardInput* profile_; @@ -88,7 +88,7 @@ namespace auto read_key_escape() -> bool override { return [[profile_ buttonForKeyCode:GCKeyCodeEscape] isPressed]; } }; - class input_device_controller_impl final : public nes::input_device_controller + class input_device_controller_impl final : public nes::app::input_device_controller { GCExtendedGamepad* profile_; @@ -150,7 +150,7 @@ namespace std::unique_ptr<display_impl> _display; std::unique_ptr<input_device_keyboard_impl> _keyboard; std::vector<std::unique_ptr<input_device_controller_impl>> _controllers; - std::unique_ptr<nes::application> _app; + std::unique_ptr<nes::app::application> _app; std::optional<NSTimeInterval> _lastTimestamp; } @@ -168,7 +168,7 @@ namespace _display = std::make_unique<display_impl>(node); _keyboard = std::make_unique<input_device_keyboard_impl>([[GCKeyboard coalescedKeyboard] keyboardInput]); - _app = std::make_unique<nes::application>(*_display, *_keyboard); + _app = std::make_unique<nes::app::application>(*_display, *_keyboard); for (GCController* controller in [GCController controllers]) { diff --git a/lib/nes/app/application.cc b/lib/nes/app/application.cc index ad3c1af..4da3848 100644 --- a/lib/nes/app/application.cc +++ b/lib/nes/app/application.cc @@ -8,7 +8,7 @@ #include "nes/common/display.hh" #include <iostream> -namespace nes +namespace nes::app { namespace { @@ -18,9 +18,9 @@ namespace nes application::application(display& display, input_device_keyboard& keyboard) : display_{ display } , input_manager_{ keyboard } - , console_{ cartridge::from_file(file), display_ } + , console_{ sys::cartridge::from_file(file), display_ } { - if (console_.get_status() != status::success) + if (console_.get_status() != sys::status::success) { std::cerr << "Unable to load cartridge: " << to_string(console_.get_status()) << std::endl; std::abort(); @@ -29,21 +29,15 @@ namespace nes auto application::frame(std::chrono::microseconds const elapsed_time) -> void { - /*console_.ref_controller_1().set_pressed(input_manager_.get_input_1().read_mask()); + console_.ref_controller_1().set_pressed(input_manager_.get_input_1().read_mask()); console_.ref_controller_2().set_pressed(input_manager_.get_input_2().read_mask()); console_.step(elapsed_time); - if (console_.get_status() != status::success) + if (console_.get_status() != sys::status::success) { std::cerr << "Invalid state: " << to_string(console_.get_status()) << std::endl; std::abort(); - }*/ - - auto r = app::renderer{ display_ }; - r.render_fill(app::color::background_primary); - r.render_mask_tile(10, 5, app::tiles::letter_a, app::color::foreground_primary); - r.render_image_tile(5, 5, app::tiles::test); - display_.switch_buffers(); + } } -} // namespace nes
\ No newline at end of file +} // namespace nes::app
\ No newline at end of file diff --git a/lib/nes/app/application.hh b/lib/nes/app/application.hh index 9f6bd16..5cd6ac7 100644 --- a/lib/nes/app/application.hh +++ b/lib/nes/app/application.hh @@ -7,7 +7,10 @@ namespace nes { class display; +} // namespace nes +namespace nes::app +{ /// Entrypoint for the application. /// /// This class takes care of presenting a UI screen or the emulator, handling any errors and implementing the main @@ -18,7 +21,7 @@ namespace nes { display& display_; input_manager input_manager_; - nes console_; + sys::nes console_; public: explicit application(display&, input_device_keyboard&); @@ -34,4 +37,4 @@ namespace nes auto add_controller(input_device_controller& c) -> void { input_manager_.add_controller(c); } auto remove_controller(input_device_controller& c) -> void { input_manager_.remove_controller(c); } }; -} // namespace nes
\ No newline at end of file +} // namespace nes::app
\ No newline at end of file diff --git a/lib/nes/app/input/input-device-controller.hh b/lib/nes/app/input/input-device-controller.hh index 6adb79c..b4e6570 100644 --- a/lib/nes/app/input/input-device-controller.hh +++ b/lib/nes/app/input/input-device-controller.hh @@ -4,7 +4,7 @@ #include "nes/common/list.hh" #include <string_view> -namespace nes +namespace nes::app { /// A game controller input device. class input_device_controller : public input_device, public list<input_device_controller>::node @@ -35,4 +35,4 @@ namespace nes protected: explicit input_device_controller() = default; }; -} // namespace nes
\ No newline at end of file +} // namespace nes::app
\ No newline at end of file diff --git a/lib/nes/app/input/input-device-keyboard.hh b/lib/nes/app/input/input-device-keyboard.hh index d61417d..dddcab6 100644 --- a/lib/nes/app/input/input-device-keyboard.hh +++ b/lib/nes/app/input/input-device-keyboard.hh @@ -2,7 +2,7 @@ #include "nes/app/input/input-device.hh" -namespace nes +namespace nes::app { /// A keyboard input device. class input_device_keyboard : public input_device @@ -13,4 +13,4 @@ namespace nes protected: explicit input_device_keyboard() = default; }; -} // namespace nes
\ No newline at end of file +} // namespace nes::app
\ No newline at end of file diff --git a/lib/nes/app/input/input-device.hh b/lib/nes/app/input/input-device.hh index 9ac7423..8e54f61 100644 --- a/lib/nes/app/input/input-device.hh +++ b/lib/nes/app/input/input-device.hh @@ -2,7 +2,7 @@ #include "nes/sys/types/button-mask.hh" -namespace nes +namespace nes::app { /// An abstract input device which can be used to play games. class input_device @@ -24,21 +24,21 @@ namespace nes virtual auto read_key_select() -> bool = 0; virtual auto read_key_start() -> bool = 0; - auto read_mask() -> button_mask + auto read_mask() -> sys::button_mask { - auto res = button_mask{}; - if (read_key_up()) { res.add(buttons::up); } - if (read_key_down()) { res.add(buttons::down); } - if (read_key_left()) { res.add(buttons::left); } - if (read_key_right()) { res.add(buttons::right); } - if (read_key_a()) { res.add(buttons::a); } - if (read_key_b()) { res.add(buttons::b); } - if (read_key_select()) { res.add(buttons::select); } - if (read_key_start()) { res.add(buttons::start); } + auto res = sys::button_mask{}; + if (read_key_up()) { res.add(sys::buttons::up); } + if (read_key_down()) { res.add(sys::buttons::down); } + if (read_key_left()) { res.add(sys::buttons::left); } + if (read_key_right()) { res.add(sys::buttons::right); } + if (read_key_a()) { res.add(sys::buttons::a); } + if (read_key_b()) { res.add(sys::buttons::b); } + if (read_key_select()) { res.add(sys::buttons::select); } + if (read_key_start()) { res.add(sys::buttons::start); } return res; } protected: explicit input_device() = default; }; -} // namespace nes
\ No newline at end of file +} // namespace nes::app
\ No newline at end of file diff --git a/lib/nes/app/input/input-manager.cc b/lib/nes/app/input/input-manager.cc index 1c9db9e..dec899a 100644 --- a/lib/nes/app/input/input-manager.cc +++ b/lib/nes/app/input/input-manager.cc @@ -1,6 +1,6 @@ #include "nes/app/input/input-manager.hh" -namespace nes +namespace nes::app { namespace { @@ -99,4 +99,4 @@ namespace nes } } } -} // namespace nes
\ No newline at end of file +} // namespace nes::app
\ No newline at end of file diff --git a/lib/nes/app/input/input-manager.hh b/lib/nes/app/input/input-manager.hh index 10308c7..525debc 100644 --- a/lib/nes/app/input/input-manager.hh +++ b/lib/nes/app/input/input-manager.hh @@ -4,7 +4,7 @@ #include "nes/app/input/input-device-controller.hh" #include "nes/common/list.hh" -namespace nes +namespace nes::app { /// Manages input devices. /// @@ -42,4 +42,4 @@ namespace nes private: auto fill_unassigned_inputs() -> void; }; -} // namespace nes
\ No newline at end of file +} // namespace nes::app
\ No newline at end of file diff --git a/lib/nes/sys/cartridge.cc b/lib/nes/sys/cartridge.cc index d60ea8b..9697185 100644 --- a/lib/nes/sys/cartridge.cc +++ b/lib/nes/sys/cartridge.cc @@ -2,7 +2,7 @@ #include "nes/sys/types/status.hh" #include <fstream> -namespace nes +namespace nes::sys { cartridge::cartridge(status const status) : status_{ status } @@ -65,4 +65,4 @@ namespace nes return from_data(data.data(), data.size()); } -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/cartridge.hh b/lib/nes/sys/cartridge.hh index a8b61a2..d82af84 100644 --- a/lib/nes/sys/cartridge.hh +++ b/lib/nes/sys/cartridge.hh @@ -6,7 +6,7 @@ #include <vector> #include <string_view> -namespace nes +namespace nes::sys { enum class name_table_arrangement { @@ -75,4 +75,4 @@ namespace nes private: explicit cartridge(status); }; -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/controller.cc b/lib/nes/sys/controller.cc index 910ef57..92dd897 100644 --- a/lib/nes/sys/controller.cc +++ b/lib/nes/sys/controller.cc @@ -1,6 +1,6 @@ #include "nes/sys/controller.hh" -namespace nes +namespace nes::sys { auto controller::read() -> std::uint8_t { @@ -15,4 +15,4 @@ namespace nes strobing_ = value & 1; if (strobing_) { index_ = 0; } } -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/controller.hh b/lib/nes/sys/controller.hh index 441e236..d3a32fd 100644 --- a/lib/nes/sys/controller.hh +++ b/lib/nes/sys/controller.hh @@ -2,7 +2,7 @@ #include "nes/sys/types/button-mask.hh" -namespace nes +namespace nes::sys { class controller { @@ -27,4 +27,4 @@ namespace nes auto read() -> std::uint8_t; auto write(std::uint8_t) -> void; }; -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/cpu.cc b/lib/nes/sys/cpu.cc index 84fbe78..8b05f66 100644 --- a/lib/nes/sys/cpu.cc +++ b/lib/nes/sys/cpu.cc @@ -4,7 +4,7 @@ #include "nes/sys/cartridge.hh" #include "nes/sys/types/snapshot.hh" -namespace nes +namespace nes::sys { cpu::cpu(ppu& ppu, cartridge& cartridge, controller& controller_1, controller& controller_2) : ppu_{ ppu } @@ -1422,4 +1422,4 @@ namespace nes write8(addr + 0, low); write8(addr + 1, high); } -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/cpu.hh b/lib/nes/sys/cpu.hh index d0901c0..2702c20 100644 --- a/lib/nes/sys/cpu.hh +++ b/lib/nes/sys/cpu.hh @@ -4,7 +4,7 @@ #include "nes/sys/types/address.hh" #include "nes/sys/types/status.hh" -namespace nes +namespace nes::sys { class ppu; class controller; @@ -297,4 +297,4 @@ namespace nes template<> auto fetch_operand<addressing_mode::immediate>(force_page_crossing) -> operand<addressing_mode::immediate>; }; -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/mapper.cc b/lib/nes/sys/mapper.cc index 4951966..fc6ec6c 100644 --- a/lib/nes/sys/mapper.cc +++ b/lib/nes/sys/mapper.cc @@ -1,7 +1,7 @@ #include "nes/sys/mapper.hh" #include "nes/sys/cartridge.hh" -namespace nes +namespace nes::sys { namespace { @@ -169,4 +169,4 @@ namespace nes } } } -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/mapper.hh b/lib/nes/sys/mapper.hh index e196b25..5db198b 100644 --- a/lib/nes/sys/mapper.hh +++ b/lib/nes/sys/mapper.hh @@ -3,7 +3,7 @@ #include "nes/sys/types/address.hh" #include "nes/sys/types/status.hh" -namespace nes +namespace nes::sys { class cartridge; @@ -29,4 +29,4 @@ namespace nes protected: explicit mapper() = default; }; -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/nes.cc b/lib/nes/sys/nes.cc index 1504100..6caf6de 100644 --- a/lib/nes/sys/nes.cc +++ b/lib/nes/sys/nes.cc @@ -3,7 +3,7 @@ #include "nes/common/display.hh" #include "nes/common/rgb.hh" -namespace nes +namespace nes::sys { nes::nes(cartridge cartridge, display& display) : cartridge_{ std::move(cartridge) } @@ -59,4 +59,4 @@ namespace nes ppu_.build_snapshot(res); return res; } -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/nes.hh b/lib/nes/sys/nes.hh index b421a5f..4e0fd63 100644 --- a/lib/nes/sys/nes.hh +++ b/lib/nes/sys/nes.hh @@ -9,6 +9,10 @@ namespace nes { class display; +} // namespace nes + +namespace nes::sys +{ struct snapshot; /// The main console abstraction. @@ -44,4 +48,4 @@ namespace nes auto get_snapshot() -> snapshot; }; -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/ppu.cc b/lib/nes/sys/ppu.cc index 2a5f01c..00cddbe 100644 --- a/lib/nes/sys/ppu.cc +++ b/lib/nes/sys/ppu.cc @@ -7,7 +7,7 @@ #include "nes/common/rgb.hh" #include "nes/common/debug.hh" -namespace nes +namespace nes::sys { ppu::ppu(cpu& cpu, cartridge& cartridge, display& display) : cpu_{ cpu } @@ -694,4 +694,4 @@ namespace nes default: return rgb::from_hex(0x000000); } } -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/ppu.hh b/lib/nes/sys/ppu.hh index b1b8842..cdca0ae 100644 --- a/lib/nes/sys/ppu.hh +++ b/lib/nes/sys/ppu.hh @@ -4,11 +4,15 @@ namespace nes { + class display; + class rgb; +} // namespace nes + +namespace nes::sys +{ class address; class cpu; class cartridge; - class display; - class rgb; struct snapshot; class ppu @@ -276,4 +280,4 @@ namespace nes auto ref_color(color_index) -> color&; auto resolve_color(color) const -> rgb; }; -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/types/address.hh b/lib/nes/sys/types/address.hh index c2e1352..dde9c94 100644 --- a/lib/nes/sys/types/address.hh +++ b/lib/nes/sys/types/address.hh @@ -2,7 +2,7 @@ #include <cstdint> -namespace nes +namespace nes::sys { /// An address on the NES (for simplicity, we share the same type for CPU and PPU, even though the PPU only uses /// 14 bit addresses). @@ -71,4 +71,4 @@ namespace nes { return address{ static_cast<std::uint16_t>(a.get_absolute() % b) }; } -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/types/button-mask.hh b/lib/nes/sys/types/button-mask.hh index 94c6a2b..64be0b6 100644 --- a/lib/nes/sys/types/button-mask.hh +++ b/lib/nes/sys/types/button-mask.hh @@ -2,7 +2,7 @@ #include <cstdint> -namespace nes +namespace nes::sys { /// Buttons pressed on a controller. class button_mask @@ -41,4 +41,4 @@ namespace nes inline constexpr auto left = button_mask::from_raw_value(1 << 6); inline constexpr auto right = button_mask::from_raw_value(1 << 7); } // namespace buttons -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/types/cycle-count.hh b/lib/nes/sys/types/cycle-count.hh index f1a4a7e..95ce9e5 100644 --- a/lib/nes/sys/types/cycle-count.hh +++ b/lib/nes/sys/types/cycle-count.hh @@ -2,7 +2,7 @@ #include <chrono> -namespace nes +namespace nes::sys { /// A cycle count that can be used for multiple components. /// @@ -84,4 +84,4 @@ namespace nes constexpr auto operator*(std::uint64_t const a, cycle_count const b) -> cycle_count { return cycle_count{ a * b.get_units() }; } constexpr auto operator*(cycle_count const a, std::uint64_t const b) -> cycle_count { return cycle_count{ a.get_units() * b }; } constexpr auto operator/(cycle_count const a, cycle_count const b) -> std::uint64_t { return a.get_units() / b.get_units(); } -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/types/snapshot.hh b/lib/nes/sys/types/snapshot.hh index 683e862..3b1b3b4 100644 --- a/lib/nes/sys/types/snapshot.hh +++ b/lib/nes/sys/types/snapshot.hh @@ -4,7 +4,7 @@ #include <vector> #include <cstdint> -namespace nes +namespace nes::sys { /// System snapshot used for comparison with a reference implementation. struct snapshot @@ -60,4 +60,4 @@ namespace nes } inline auto operator!=(snapshot const& a, snapshot const& b) -> bool { return !(a == b); } -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/types/status.hh b/lib/nes/sys/types/status.hh index 64f5969..c622ffb 100644 --- a/lib/nes/sys/types/status.hh +++ b/lib/nes/sys/types/status.hh @@ -1,6 +1,6 @@ #pragma once -namespace nes +namespace nes::sys { /// A status code. enum class status @@ -33,4 +33,4 @@ namespace nes return "(invalid)"; } -} // namespace nes
\ No newline at end of file +} // namespace nes::sys
\ No newline at end of file |
