Skip to content

Commit

Permalink
address feedback, prefer implicit constructors, better error presenta…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
jcm93 committed Jan 21, 2025
1 parent 4c1e166 commit 4fef720
Show file tree
Hide file tree
Showing 102 changed files with 405 additions and 397 deletions.
6 changes: 4 additions & 2 deletions ares/ares/ares.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ enum ResultEnum {
databaseNotFound,
romNotFoundInDatabase,
romNotFound,
invalidRom,
invalidROM,
couldNotParseManifest,
noFirmware,
otherError
Expand All @@ -100,7 +100,9 @@ struct LoadResult {
string firmwareSystemName;
string firmwareRegion;

LoadResult(ResultEnum r) : result(r), info(0) {}
LoadResult(ResultEnum r) : result(r) {}

LoadResult(ResultEnum r, string i) : result(r), info(i) {}

bool operator==(const LoadResult& other) {
return result == other.result;
Expand Down
12 changes: 6 additions & 6 deletions desktop-ui/emulator/arcade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@ Arcade::Arcade() {
auto Arcade::load() -> LoadResult {
game = mia::Medium::create("Arcade");
string location = Emulator::load(game, configuration.game);
if(!location) return LoadResult(noFileSelected);
if(!location) return noFileSelected;
LoadResult result = game->load(location);
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

system = mia::System::create("Arcade");
result = system->load();
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

//Determine from the game manifest which core to use for the given arcade rom
#ifdef CORE_SG
if(game->pak->attribute("board") == "sega/sg1000a") {
if(!ares::SG1000::load(root, {"[Sega] SG-1000A"})) return LoadResult(otherError);
if(!ares::SG1000::load(root, {"[Sega] SG-1000A"})) return otherError;
systemPakName = "SG-1000A";
gamePakName = "Arcade Cartridge";

if(auto port = root->find<ares::Node::Port>("Cartridge Slot")) {
port->allocate();
port->connect();
}
return LoadResult(successful);
return successful;
}
#endif

return LoadResult(otherError);
return otherError;
}

auto Arcade::save() -> bool {
Expand Down
10 changes: 5 additions & 5 deletions desktop-ui/emulator/atari-2600.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ Atari2600::Atari2600() {
auto Atari2600::load() -> LoadResult {
game = mia::Medium::create("Atari 2600");
string location = Emulator::load(game, configuration.game);
if(!location) return LoadResult(noFileSelected);
if(!location) return couldNotParseManifest;
LoadResult result = game->load(location);
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

system = mia::System::create("Atari 2600");
result = system->load();
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

auto region = Emulator::region();
if(!ares::Atari2600::load(root, {"[Atari] Atari 2600 (", region, ")"})) return LoadResult(otherError);
if(!ares::Atari2600::load(root, {"[Atari] Atari 2600 (", region, ")"})) return otherError;

if(auto port = root->find<ares::Node::Port>("Cartridge Slot")) {
port->allocate();
Expand All @@ -67,7 +67,7 @@ auto Atari2600::load() -> LoadResult {
port->connect();
}

return LoadResult(successful);
return successful;
}

auto Atari2600::save() -> bool {
Expand Down
10 changes: 5 additions & 5 deletions desktop-ui/emulator/colecovision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ ColecoVision::ColecoVision() {
auto ColecoVision::load() -> LoadResult {
game = mia::Medium::create("ColecoVision");
string location = Emulator::load(game, configuration.game);
if(!location) return LoadResult(noFileSelected);
if(!location) return noFileSelected;
LoadResult result = game->load(location);
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

system = mia::System::create("ColecoVision");
if(system->load(firmware[0].location) != LoadResult(successful)) {
if(system->load(firmware[0].location) != successful) {
result.firmwareSystemName = "ColecoVision";
result.firmwareType = firmware[0].type;
result.firmwareRegion = firmware[0].region;
Expand All @@ -56,7 +56,7 @@ auto ColecoVision::load() -> LoadResult {
}

auto region = Emulator::region();
if(!ares::ColecoVision::load(root, {"[Coleco] ColecoVision (", region, ")"})) return LoadResult(otherError);
if(!ares::ColecoVision::load(root, {"[Coleco] ColecoVision (", region, ")"})) return otherError;

if(auto port = root->find<ares::Node::Port>("Cartridge Slot")) {
port->allocate();
Expand All @@ -73,7 +73,7 @@ auto ColecoVision::load() -> LoadResult {
port->connect();
}

return LoadResult(successful);
return successful;
}

auto ColecoVision::save() -> bool {
Expand Down
51 changes: 34 additions & 17 deletions desktop-ui/emulator/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,47 +55,64 @@ auto Emulator::region() -> string {
}

auto Emulator::handleLoadResult(LoadResult result) -> void {
string errorText;
switch (result.result) {
case successful:
break;
return;
case noFileSelected:
return;
case invalidROM:
errorText = { "There was an error trying to parse the selected ROM. \n",
"Your ROM may be corrupt or contain a bad dump." };
break;
case couldNotParseManifest:
error("An error was encountered while parsing the manifest. \n"
"");
errorText = { "An error occurred while parsing the database file. You \n",
"may need to reinstall ares." };
break;
case databaseNotFound:
error("The database file for the system was not found. \n"
"Make sure that you have installed or packaged ares correctly.");
errorText = { "The database file for the system was not found. \n",
"Make sure that you have installed or packaged ares correctly. \n",
"Missing database file: " };
break;
case noFirmware:
if(MessageDialog().setText({
"Error: firmware is missing or invalid.\n",
result.firmwareSystemName, " - ", result.firmwareType, " (", result.firmwareRegion, ") is required to play this game.\n"
"Would you like to configure firmware settings now?"
}).question() == "Yes") {
settingsWindow.show("Firmware");
firmwareSettings.select(emulator->name, result.firmwareType, result.firmwareRegion);
}
errorText = { "Error: firmware is missing or invalid.\n",
result.firmwareSystemName, " - ", result.firmwareType, " (", result.firmwareRegion, ") is required to play this game.\n",
"Would you like to configure firmware settings now?" };
break;
case romNotFound:
error("A required ROM file was not found.");
errorText = "The selected ROM file was not found or could not be opened.";
break;
case romNotFoundInDatabase:
error("The selected ROM was not found in the database.");
errorText = "The selected ROM was not found in the database.";
break;
case otherError:
error("Failed to load the selected system and ROM.");
errorText = "Failed to load the selected system and ROM.";
break;
}

if(result.info) {
errorText = { errorText, result.info };
}

switch (result.result) {
case noFirmware:
if(MessageDialog().setText({
errorText
}).question() == "Yes") {
settingsWindow.show("Firmware");
firmwareSettings.select(emulator->name, result.firmwareType, result.firmwareRegion);
}
default:
error(errorText);
}
}

auto Emulator::load(const string& location) -> bool {
if(inode::exists(location)) locationQueue.append(location);

LoadResult result = load();
handleLoadResult(result);
if(result != LoadResult(successful)) {
if(result != successful) {
return false;
}
setBoolean("Color Emulation", settings.video.colorEmulation);
Expand Down
12 changes: 6 additions & 6 deletions desktop-ui/emulator/famicom-disk-system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ auto FamicomDiskSystem::load(Menu menu) -> void {
auto FamicomDiskSystem::load() -> LoadResult {
game = mia::Medium::create("Famicom Disk System");
string location = Emulator::load(game, configuration.game);
if(!location) return LoadResult(noFileSelected);
if(!location) return noFileSelected;
LoadResult result = game->load(location);
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

bios = mia::Medium::create("Famicom");
result = bios->load(firmware[0].location);
if(result != LoadResult(successful)) {
if(result != successful) {
result.firmwareSystemName = "Famicom";
result.firmwareType = firmware[0].type;
result.firmwareRegion = firmware[0].region;
Expand All @@ -84,9 +84,9 @@ auto FamicomDiskSystem::load() -> LoadResult {

system = mia::System::create("Famicom");
result = system->load();
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

if(!ares::Famicom::load(root, "[Nintendo] Famicom (NTSC-J)")) return LoadResult(otherError);
if(!ares::Famicom::load(root, "[Nintendo] Famicom (NTSC-J)")) return otherError;

if(auto port = root->find<ares::Node::Port>("Cartridge Slot")) {
port->allocate();
Expand All @@ -112,7 +112,7 @@ auto FamicomDiskSystem::load() -> LoadResult {
port->connect();
}

return LoadResult(successful);
return successful;
}

auto FamicomDiskSystem::save() -> bool {
Expand Down
10 changes: 5 additions & 5 deletions desktop-ui/emulator/famicom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ Famicom::Famicom() {
auto Famicom::load() -> LoadResult {
game = mia::Medium::create("Famicom");
string location = Emulator::load(game, configuration.game);
if(!location) return LoadResult(noFileSelected);
if(!location) return noFileSelected;
LoadResult result = game->load(location);
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

system = mia::System::create("Famicom");
result = system->load();
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

auto region = Emulator::region();
if(!ares::Famicom::load(root, {"[Nintendo] Famicom (", region, ")"})) return LoadResult(otherError);
if(!ares::Famicom::load(root, {"[Nintendo] Famicom (", region, ")"})) return otherError;

if(auto port = root->find<ares::Node::Port>("Cartridge Slot")) {
port->allocate();
Expand All @@ -71,7 +71,7 @@ auto Famicom::load() -> LoadResult {
}
}

return LoadResult(successful);
return successful;
}

auto Famicom::save() -> bool {
Expand Down
10 changes: 5 additions & 5 deletions desktop-ui/emulator/game-boy-advance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ auto GameBoyAdvance::load(Menu menu) -> void {
auto GameBoyAdvance::load() -> LoadResult {
game = mia::Medium::create("Game Boy Advance");
string location = Emulator::load(game, configuration.game);
if(!location) return LoadResult(noFileSelected);
if(!location) return noFileSelected;
LoadResult result = game->load(location);
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

system = mia::System::create("Game Boy Advance");
if(system->load(firmware[0].location) != LoadResult(successful)) {
if(system->load(firmware[0].location) != successful) {
result.firmwareSystemName = "Game Boy Advance";
result.firmwareType = firmware[0].type;
result.firmwareRegion = firmware[0].region;
Expand All @@ -68,14 +68,14 @@ auto GameBoyAdvance::load() -> LoadResult {

ares::GameBoyAdvance::option("Pixel Accuracy", settings.video.pixelAccuracy);

if(!ares::GameBoyAdvance::load(root, "[Nintendo] Game Boy Advance")) return LoadResult(otherError);
if(!ares::GameBoyAdvance::load(root, "[Nintendo] Game Boy Advance")) return otherError;

if(auto port = root->find<ares::Node::Port>("Cartridge Slot")) {
port->allocate();
port->connect();
}

return LoadResult(successful);
return successful;
}

auto GameBoyAdvance::save() -> bool {
Expand Down
10 changes: 5 additions & 5 deletions desktop-ui/emulator/game-boy-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ GameBoyColor::GameBoyColor() {
auto GameBoyColor::load() -> LoadResult {
game = mia::Medium::create("Game Boy Color");
string location = Emulator::load(game, configuration.game);
if(!location) return LoadResult(noFileSelected);
if(!location) return noFileSelected;
LoadResult result = game->load(location);
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

system = mia::System::create("Game Boy Color");
result = system->load();
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

if(!ares::GameBoy::load(root, "[Nintendo] Game Boy Color")) return LoadResult(otherError);
if(!ares::GameBoy::load(root, "[Nintendo] Game Boy Color")) return otherError;

if(auto port = root->find<ares::Node::Port>("Cartridge Slot")) {
port->allocate();
Expand All @@ -49,7 +49,7 @@ auto GameBoyColor::load() -> LoadResult {
fastBoot->setValue(settings.boot.fast);
}

return LoadResult(successful);
return successful;
}

auto GameBoyColor::save() -> bool {
Expand Down
10 changes: 5 additions & 5 deletions desktop-ui/emulator/game-boy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ GameBoy::GameBoy() {
auto GameBoy::load() -> LoadResult {
game = mia::Medium::create("Game Boy");
string location = Emulator::load(game, configuration.game);
if(!location) return LoadResult(noFileSelected);
if(!location) return noFileSelected;
LoadResult result = game->load(location);
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

system = mia::System::create("Game Boy");
result = system->load();
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

if(!ares::GameBoy::load(root, "[Nintendo] Game Boy")) return LoadResult(otherError);
if(!ares::GameBoy::load(root, "[Nintendo] Game Boy")) return otherError;

if(auto port = root->find<ares::Node::Port>("Cartridge Slot")) {
port->allocate();
Expand All @@ -50,7 +50,7 @@ auto GameBoy::load() -> LoadResult {
fastBoot->setValue(settings.boot.fast);
}

return LoadResult(successful);
return successful;
}

auto GameBoy::load(Menu menu) -> void {
Expand Down
16 changes: 5 additions & 11 deletions desktop-ui/emulator/game-gear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,24 @@ GameGear::GameGear() {
auto GameGear::load() -> LoadResult {
game = mia::Medium::create("Game Gear");
string location = Emulator::load(game, configuration.game);
if(!location) return LoadResult(noFileSelected);
if(!location) return noFileSelected;
LoadResult result = game->load(location);
if(result != LoadResult(successful)) return result;
if(result != successful) return result;

auto region = Emulator::region();

system = mia::System::create("Game Gear");
result = system->load(firmware[0].location);
if(result != LoadResult(successful)) {
result.firmwareSystemName = "Game Gear";
result.firmwareType = firmware[0].type;
result.firmwareRegion = firmware[0].region;
result.result = noFirmware;
return result;
}
if(result != successful) return otherError;

if(!ares::MasterSystem::load(root, {"[Sega] Game Gear (", region, ")"})) return LoadResult(otherError);
if(!ares::MasterSystem::load(root, {"[Sega] Game Gear (", region, ")"})) return otherError;

if(auto port = root->find<ares::Node::Port>("Cartridge Slot")) {
port->allocate();
port->connect();
}

return LoadResult(successful);
return successful;
}

auto GameGear::save() -> bool {
Expand Down
Loading

0 comments on commit 4fef720

Please sign in to comment.