From cbde52a60605a4fe853d3a3562b2a059e2143e6e Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Sat, 1 Feb 2025 01:25:15 +0100 Subject: avoid copy construction for cartridge --- lib/nes/app/application.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'lib/nes/app') diff --git a/lib/nes/app/application.cc b/lib/nes/app/application.cc index 0c1a4cb..264e07a 100644 --- a/lib/nes/app/application.cc +++ b/lib/nes/app/application.cc @@ -4,7 +4,7 @@ #include "nes/app/ui/screen.hh" #include "nes/app/graphics/renderer.hh" #include "ui/action.hh" - +#include #include namespace nes::app @@ -74,7 +74,20 @@ namespace nes::app } case action::load_game: { - console_.emplace(sys::cartridge::from_file(file), display_); + auto stream = std::ifstream{ file, std::ios::binary }; + if (!stream.good()) + { + std::cerr << "Unable to open cartridge file!" << std::endl; + std::abort(); + } + + stream.seekg(0, std::ios::end); + auto const length = stream.tellg(); + stream.seekg(0, std::ios::beg); + auto data = std::vector(static_cast(length)); + stream.read(reinterpret_cast(data.data()), length); + + console_.emplace(display_, data.data(), static_cast(length)); if (console_->get_status() != sys::status::success) { std::cerr << "Unable to load cartridge: " << to_string(console_->get_status()) << std::endl; -- cgit v1.3.1