diff options
Diffstat (limited to 'lib/nes/app')
| -rw-r--r-- | lib/nes/app/action.hh | 16 | ||||
| -rw-r--r-- | lib/nes/app/application.cc | 8 | ||||
| -rw-r--r-- | lib/nes/app/application.hh | 5 | ||||
| -rw-r--r-- | lib/nes/app/file-browser.hh | 13 | ||||
| -rw-r--r-- | lib/nes/app/graphics/renderer.cc | 37 | ||||
| -rw-r--r-- | lib/nes/app/graphics/renderer.hh | 8 | ||||
| -rw-r--r-- | lib/nes/app/input/input-device-keyboard.hh | 2 | ||||
| -rw-r--r-- | lib/nes/app/input/input-device.hh | 4 | ||||
| -rw-r--r-- | lib/nes/app/input/input-manager.cc | 2 | ||||
| -rw-r--r-- | lib/nes/app/ui/screen-browser.cc | 3 | ||||
| -rw-r--r-- | lib/nes/app/ui/screen-error.hh | 7 | ||||
| -rw-r--r-- | lib/nes/app/ui/screen-settings.cc | 2 |
12 files changed, 55 insertions, 52 deletions
diff --git a/lib/nes/app/action.hh b/lib/nes/app/action.hh index cca7a35..ed879f3 100644 --- a/lib/nes/app/action.hh +++ b/lib/nes/app/action.hh @@ -1,7 +1,7 @@ #pragma once -#include "../common/status.hh" -#include <string_view> +#include "nes/common/containers/string-view.hh" +#include "nes/common/status.hh" namespace nes::app { @@ -25,8 +25,8 @@ namespace nes::app private: type type_{ type::none }; - std::string_view file_name_; - std::string_view message_; + string_view file_name_; + string_view message_; status error_{ status::success }; public: @@ -40,14 +40,14 @@ namespace nes::app static auto cancel_quit() -> action { return action{ type::cancel_quit }; } static auto confirm_quit() -> action { return action{ type::confirm_quit }; } - static auto launch_game(std::string_view const file_name) -> action + static auto launch_game(string_view const file_name) -> action { auto res = action{ type::launch_game }; res.file_name_ = file_name; return res; } - static auto show_error(std::string_view const message, status const error) -> action + static auto show_error(string_view const message, status const error) -> action { auto res = action{ type::show_error }; res.message_ = message; @@ -56,8 +56,8 @@ namespace nes::app } auto get_type() const -> type { return type_; } - auto get_file_name() const -> std::string_view { return file_name_; } - auto get_message() const -> std::string_view { return message_; } + auto get_file_name() const -> string_view { return file_name_; } + auto get_message() const -> string_view { return message_; } auto get_error() const -> status { return error_; } private: diff --git a/lib/nes/app/application.cc b/lib/nes/app/application.cc index 015e641..ac9f731 100644 --- a/lib/nes/app/application.cc +++ b/lib/nes/app/application.cc @@ -46,9 +46,9 @@ namespace nes::app display_.screen = &screen_title_; } - auto application::frame(std::chrono::microseconds const elapsed_time) -> void + auto application::frame(u32 const elapsed_time_us) -> void { - display_.fps_counter.frame(elapsed_time); + display_.fps_counter.frame(elapsed_time_us); if (display_.popup) { @@ -89,7 +89,7 @@ namespace nes::app // The scene is rendered by the console after the PPU requests a new frame (thus calling // display_proxy::switch_buffers). - console_->step(elapsed_time); + console_->step(sys::cycle_count::from_microseconds(elapsed_time_us)); if (console_->get_status() != status::success) { @@ -171,7 +171,7 @@ namespace nes::app } } - auto application::show_error(std::string_view const message, status const error, action const& action) -> void + auto application::show_error(string_view const message, status const error, action const& action) -> void { screen_error_.set_message(message); screen_error_.set_error(error); diff --git a/lib/nes/app/application.hh b/lib/nes/app/application.hh index c23f654..f0117b1 100644 --- a/lib/nes/app/application.hh +++ b/lib/nes/app/application.hh @@ -13,7 +13,6 @@ #include "nes/common/display.hh" #include "nes/common/fps-counter.hh" #include "nes/common/types.hh" -#include <chrono> namespace nes::app { @@ -71,14 +70,14 @@ namespace nes::app auto operator=(application&&) -> application& = delete; /// Request a new frame for the application. - auto frame(std::chrono::microseconds elapsed_time) -> void; + auto frame(u32 elapsed_time_us) -> void; 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); } private: auto handle_action(action const&) -> void; - auto show_error(std::string_view message, status error, action const& action = action::close_popup()) -> void; + auto show_error(string_view message, status error, action const& action = action::close_popup()) -> void; auto go_to_screen(screen*) -> void; }; } // namespace nes::app
\ No newline at end of file diff --git a/lib/nes/app/file-browser.hh b/lib/nes/app/file-browser.hh index 3465000..1da4cd6 100644 --- a/lib/nes/app/file-browser.hh +++ b/lib/nes/app/file-browser.hh @@ -1,9 +1,10 @@ #pragma once #include "nes/common/containers/span.hh" +#include "nes/common/containers/string-view.hh" #include "nes/common/types.hh" #include "nes/common/status.hh" -#include <string_view> +#include "nes/common/utils.hh" namespace nes { @@ -33,14 +34,14 @@ namespace nes::app public: explicit entry() = default; - explicit entry(entry_type const type, std::string_view const name) + explicit entry(entry_type const type, string_view const name) : type_{ type } { - std::copy_n(name.begin(), std::min(static_cast<u32>(name.length()), max_name_length), name_); + copy(name.get_data(), name_, min(name.get_length(), max_name_length)); } auto get_type() const -> entry_type { return type_; } - auto get_name() const -> std::string_view { return name_; } + auto get_name() const -> string_view { return name_; } }; virtual ~file_browser() = default; @@ -63,10 +64,10 @@ namespace nes::app virtual auto navigate_up() -> status = 0; /// Change the current working directory to an item. - virtual auto navigate(std::string_view) -> status = 0; + virtual auto navigate(string_view) -> status = 0; /// Load a file in the current working directory into memory. - virtual auto load(std::string_view, span<u8>, u32* out_length) -> status = 0; + virtual auto load(string_view, span<u8>, u32* out_length) -> status = 0; protected: explicit file_browser() = default; diff --git a/lib/nes/app/graphics/renderer.cc b/lib/nes/app/graphics/renderer.cc index 4f0d562..1745dd7 100644 --- a/lib/nes/app/graphics/renderer.cc +++ b/lib/nes/app/graphics/renderer.cc @@ -7,6 +7,7 @@ #include "nes/app/graphics/tiles/characters.hh" #include "nes/app/graphics/tiles/borders.hh" #include "nes/common/display.hh" +#include "nes/common/utils.hh" namespace nes::app { @@ -64,32 +65,32 @@ namespace nes::app } auto renderer::render_text( - i32 x, i32 const y, std::string_view const str, color const c, text_attributes const attributes) -> u32 + i32 x, i32 const y, string_view const str, color const c, text_attributes const attributes) -> u32 { // Enforce max length char buffer[width]; - auto const length = std::min(static_cast<u32>(str.length()), std::min(width, attributes.get_max_width())); - auto const ellipsize_dots = std::min(length, u32{ 3 }); + auto const length = min(str.get_length(), min(width, attributes.get_max_width())); + auto const ellipsize_dots = min(length, u32{ 3 }); // Enforce ellipsize mode - if (str.length() > length) + if (str.get_length() > length) { switch (attributes.get_ellipsize_mode()) { case ellipsize_mode::clip: { - std::copy_n(str.begin(), length, buffer); + copy(str.get_data(), buffer, length); break; } case ellipsize_mode::end: { - std::copy_n(str.begin(), length, buffer); + copy(str.get_data(), buffer, length); for (auto i = u32{ 0 }; i < ellipsize_dots; ++i) { buffer[length - 1 - i] = '.'; } break; } case ellipsize_mode::start: { - std::copy_n(str.begin() + str.length() - length, length, buffer); + copy(str.get_data() + str.get_length() - length, buffer, length); for (auto i = u32{ 0 }; i < ellipsize_dots; ++i) { buffer[i] = '.'; } break; } @@ -98,16 +99,16 @@ namespace nes::app auto const visible = length - ellipsize_dots; auto const start = visible / 2; auto const end = visible - start; - std::copy_n(str.begin(), start, buffer); + copy(str.get_data(), buffer, start); for (auto i = u32{ 0 }; i < ellipsize_dots; ++i) { buffer[start + i] = '.'; } - std::copy_n(str.begin() + str.length() - end, end, buffer + start + ellipsize_dots); + copy(str.get_data() + str.get_length() - end, buffer + start + ellipsize_dots, end); break; } } } else { - std::copy_n(str.begin(), length, buffer); + copy(str.get_data(), buffer, length); } // Enforce alignment @@ -132,10 +133,10 @@ namespace nes::app if (c == color::transparent) { return; } auto const resolved = resolve_color(c); - auto const x_stop = std::min(x + static_cast<i32>(width), static_cast<i32>(renderer::width)); - auto const y_stop = std::min(y + static_cast<i32>(height), static_cast<i32>(renderer::height)); - auto const x_start = std::max(x, 0); - auto const y_start = std::max(y, 0); + auto const x_stop = min(x + static_cast<i32>(width), static_cast<i32>(renderer::width)); + auto const y_stop = min(y + static_cast<i32>(height), static_cast<i32>(renderer::height)); + auto const x_start = max(x, 0); + auto const y_start = max(y, 0); for (auto y_px = i32{ y_start * 8 }; y_px < y_stop * 8; ++y_px) { for (auto x_px = i32{ x_start * 8 }; x_px < x_stop * 8; ++x_px) @@ -149,10 +150,10 @@ namespace nes::app { if (width <= 1 || height <= 1) { return; } - auto const x_last = std::min(x + static_cast<i32>(width), static_cast<i32>(renderer::width)) - 1; - auto const y_last = std::min(y + static_cast<i32>(height), static_cast<i32>(renderer::height)) - 1; - auto const x_start = std::max(x, 0); - auto const y_start = std::max(y, 0); + auto const x_last = min(x + static_cast<i32>(width), static_cast<i32>(renderer::width)) - 1; + auto const y_last = min(y + static_cast<i32>(height), static_cast<i32>(renderer::height)) - 1; + auto const x_start = max(x, 0); + auto const y_start = max(y, 0); for (auto border_y = i32{ y_start }; border_y <= y_last; ++border_y) { for (auto border_x = i32{ x_start }; border_x <= x_last; ++border_x) diff --git a/lib/nes/app/graphics/renderer.hh b/lib/nes/app/graphics/renderer.hh index 2e24ad3..50ca092 100644 --- a/lib/nes/app/graphics/renderer.hh +++ b/lib/nes/app/graphics/renderer.hh @@ -3,8 +3,8 @@ #include "nes/app/graphics/color.hh" #include "nes/app/graphics/text-attributes.hh" #include "nes/common/containers/string-builder.hh" +#include "nes/common/containers/string-view.hh" #include "nes/common/types.hh" -#include <string_view> namespace nes { @@ -46,11 +46,11 @@ namespace nes::app /// Render an image at the given tile coordinates. auto render_image(i32 x, i32 y, image_view) -> void; /// Render a string of text at the given tile coordinates (one tile per character). - auto render_text(i32 x, i32 y, std::string_view, color, text_attributes = text_attributes{}) -> u32; + auto render_text(i32 x, i32 y, string_view, color, text_attributes = text_attributes{}) -> u32; template<typename... Args> auto render_text_format( - i32 const x, i32 const y, color const c, text_attributes const attrs, std::string_view const fmt, + i32 const x, i32 const y, color const c, text_attributes const attrs, string_view const fmt, Args... args) -> u32 { string_buffer<width> buffer{}; @@ -60,7 +60,7 @@ namespace nes::app template<typename... Args> auto render_text_format( - i32 const x, i32 const y, color const c, std::string_view const fmt, Args... args) -> u32 + i32 const x, i32 const y, color const c, string_view const fmt, Args... args) -> u32 { return render_text_format(x, y, c, text_attributes{}, fmt, args...); } diff --git a/lib/nes/app/input/input-device-keyboard.hh b/lib/nes/app/input/input-device-keyboard.hh index ef89c59..1365a1b 100644 --- a/lib/nes/app/input/input-device-keyboard.hh +++ b/lib/nes/app/input/input-device-keyboard.hh @@ -43,7 +43,7 @@ namespace nes::app return res; } - auto get_name() const -> std::string_view final { return "Keyboard"; } + auto get_name() const -> string_view final { return "Keyboard"; } protected: explicit input_device_keyboard() = default; diff --git a/lib/nes/app/input/input-device.hh b/lib/nes/app/input/input-device.hh index 008825d..bd2f7c2 100644 --- a/lib/nes/app/input/input-device.hh +++ b/lib/nes/app/input/input-device.hh @@ -1,7 +1,7 @@ #pragma once #include "nes/sys/types/button-mask.hh" -#include <string_view> +#include "nes/common/containers/string-view.hh" namespace nes::app { @@ -20,7 +20,7 @@ namespace nes::app virtual auto read_buttons() -> sys::button_mask = 0; /// Human-readable name for the device. - virtual auto get_name() const -> std::string_view = 0; + virtual auto get_name() const -> string_view = 0; protected: explicit input_device() = default; diff --git a/lib/nes/app/input/input-manager.cc b/lib/nes/app/input/input-manager.cc index e88ac84..27b29e4 100644 --- a/lib/nes/app/input/input-manager.cc +++ b/lib/nes/app/input/input-manager.cc @@ -15,7 +15,7 @@ namespace nes::app return res; } - auto get_name() const -> std::string_view override { return "(None)"; } + auto get_name() const -> string_view override { return "(None)"; } auto read_buttons() -> sys::button_mask override { return sys::button_mask{}; } }; } // namespace diff --git a/lib/nes/app/ui/screen-browser.cc b/lib/nes/app/ui/screen-browser.cc index 1b515bd..50b0060 100644 --- a/lib/nes/app/ui/screen-browser.cc +++ b/lib/nes/app/ui/screen-browser.cc @@ -4,6 +4,7 @@ #include "nes/app/graphics/tiles/icons.hh" #include "nes/app/input/input-device-keyboard.hh" #include "nes/common/containers/path-view.hh" +#include "nes/common/utils.hh" namespace nes::app { @@ -152,6 +153,6 @@ namespace nes::app // Round up to get page count. auto const page_count = (count + (page_size - 1)) / page_size; // Always show at least one page. - selection_.set_page_count(std::max(u32{ 1 }, page_count)); + selection_.set_page_count(max(u32{ 1 }, page_count)); } } // namespace nes::app
\ No newline at end of file diff --git a/lib/nes/app/ui/screen-error.hh b/lib/nes/app/ui/screen-error.hh index 4559942..53b6407 100644 --- a/lib/nes/app/ui/screen-error.hh +++ b/lib/nes/app/ui/screen-error.hh @@ -1,6 +1,7 @@ #pragma once #include "nes/app/ui/screen.hh" +#include "nes/common/containers/string-view.hh" namespace nes::app { @@ -10,17 +11,17 @@ namespace nes::app class screen_error final : public screen { input_device_keyboard& keyboard_; - std::string_view message_; + string_view message_; status error_{ status::success }; action action_{}; public: explicit screen_error(input_device_keyboard&); - auto get_message() const -> std::string_view { return message_; } + auto get_message() const -> string_view { return message_; } auto get_error() const -> status { return error_; } auto get_action() const -> action { return action_; } - auto set_message(std::string_view const v) -> void { message_ = v; } + auto set_message(string_view const v) -> void { message_ = v; } auto set_error(status const v) -> void { error_ = v; } auto set_action(action const& v) -> void { action_ = v; } diff --git a/lib/nes/app/ui/screen-settings.cc b/lib/nes/app/ui/screen-settings.cc index 98070d7..9ba4b50 100644 --- a/lib/nes/app/ui/screen-settings.cc +++ b/lib/nes/app/ui/screen-settings.cc @@ -7,7 +7,7 @@ namespace nes::app auto screen_settings::selection_impl::render_item( renderer& renderer, item const& item, i32 const x, i32 const y, u32 const width, color const c) const -> void { - auto const render = [&](std::string_view const label, std::string_view const value) + auto const render = [&](string_view const label, string_view const value) { auto const label_length = renderer.render_text(x, y, label, c); auto const value_attrs = text_attributes{} |
