diff options
| author | Markus Gerber <markus.gerber@fau.de> | 2025-02-07 12:51:29 +0100 |
|---|---|---|
| committer | Markus Gerber <markus.gerber@fau.de> | 2025-02-07 12:51:46 +0100 |
| commit | 95a039c8d1f926365c8bf3c20b09ec6250e60d8a (patch) | |
| tree | d13af527cf4b59794448308d92574290c352aed8 /lib/nes/app | |
| parent | e39508e6f2bac8ae171b496bc3ece7eaa2e63114 (diff) | |
added internal buffer to get rid of display::get
Diffstat (limited to 'lib/nes/app')
| -rw-r--r-- | lib/nes/app/application.cc | 15 | ||||
| -rw-r--r-- | lib/nes/app/application.hh | 8 | ||||
| -rw-r--r-- | lib/nes/app/ui/screen-freeze.cc | 10 | ||||
| -rw-r--r-- | lib/nes/app/ui/screen-freeze.hh | 2 |
4 files changed, 22 insertions, 13 deletions
diff --git a/lib/nes/app/application.cc b/lib/nes/app/application.cc index 4498f98..bb2f1e4 100644 --- a/lib/nes/app/application.cc +++ b/lib/nes/app/application.cc @@ -7,6 +7,16 @@ namespace nes::app { + auto application::display_proxy::get_front() const -> span<rgb, display::width * display::height> + { + return buffer_front_; + } + + auto application::display_proxy::set(u32 const x, u32 const y, rgb const value) -> void { + buffer_back_[y * display::width + x] = value; + base.set(x, y, value); + } + auto application::display_proxy::switch_buffers() -> void { auto r = renderer{ base }; @@ -30,6 +40,7 @@ namespace nes::app r.render_text_format(32, 29, color::fixed_white, attrs, "{}", fps_counter.get_fps()); } + swap(buffer_front_, buffer_back_); base.switch_buffers(); } @@ -74,7 +85,7 @@ namespace nes::app { if (event == input_event::key_down(key::escape)) { - screen_freeze_.freeze(display_); + screen_freeze_.freeze(display_.get_front()); screen_confirm_quit_.set_confirm(false); display_.screen = &screen_freeze_; display_.popup = &screen_confirm_quit_; @@ -93,7 +104,7 @@ namespace nes::app if (console_->get_status() != status::success) { - screen_freeze_.freeze(display_); + screen_freeze_.freeze(display_.get_front()); display_.screen = &screen_freeze_; show_error("Runtime error", console_->get_status(), action::go_to_browser()); console_.clear(); diff --git a/lib/nes/app/application.hh b/lib/nes/app/application.hh index f0117b1..d0973e8 100644 --- a/lib/nes/app/application.hh +++ b/lib/nes/app/application.hh @@ -31,6 +31,9 @@ namespace nes::app class display_proxy final : public display { preferences& preferences_; + rgb buffers_[2][display::width * display::height]{}; + span<rgb, display::width * display::height> buffer_front_ = buffers_[0]; + span<rgb, display::width * display::height> buffer_back_ = buffers_[1]; public: fps_counter fps_counter; @@ -44,8 +47,9 @@ namespace nes::app { } - 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 set(u32 const x, u32 const y, rgb const value) -> void override; + auto get_front() const -> span<rgb, display::width * display::height>; + auto switch_buffers() -> void override; }; diff --git a/lib/nes/app/ui/screen-freeze.cc b/lib/nes/app/ui/screen-freeze.cc index 60410dd..68507db 100644 --- a/lib/nes/app/ui/screen-freeze.cc +++ b/lib/nes/app/ui/screen-freeze.cc @@ -3,15 +3,9 @@ namespace nes::app { - auto screen_freeze::freeze(display const& disp) -> void + auto screen_freeze::freeze(span<rgb, display::width * display::height> front_buffer) -> void { - for (auto y = u32{ 0 }; y < display::height; ++y) - { - for (auto x = u32{ 0 }; x < display::width; ++x) - { - frozen_data_[y * display::width + x] = disp.get(x, y); - } - } + copy(front_buffer.get_data(), frozen_data_, front_buffer.get_length()); } auto screen_freeze::render(renderer& renderer) -> void diff --git a/lib/nes/app/ui/screen-freeze.hh b/lib/nes/app/ui/screen-freeze.hh index fe67aad..2ae1eb2 100644 --- a/lib/nes/app/ui/screen-freeze.hh +++ b/lib/nes/app/ui/screen-freeze.hh @@ -20,6 +20,6 @@ namespace nes::app auto process_events() -> action override; /// Update the image shown to the back buffer of the given display. - auto freeze(display const&) -> void; + auto freeze(span<rgb, display::width * display::height> front_buffer) -> void; }; } // namespace nes::app
\ No newline at end of file |
