yaze_app_main fn: add main application entry point for yaze with command-line argument parsing and controller management

This commit is contained in:
scawful
2025-02-10 11:52:50 -05:00
parent b8d1568b08
commit 004201c594
2 changed files with 28 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ typedef enum yaze_status {
YAZE_ERROR = 1,
} yaze_status;
int yaze_app_main(int argc, char** argv);
void yaze_check_version(const char* version);
yaze_status yaze_init(yaze_editor_context*);

View File

@@ -1,6 +1,7 @@
#include "yaze.h"
#include <iostream>
#include <memory>
#include <sstream>
#include "app/rom.h"
@@ -8,6 +9,32 @@
#include "dungeon.h"
#include "yaze_config.h"
int yaze_app_main(int argc, char **argv) {
yaze::util::FlagParser parser(yaze::util::global_flag_registry());
RETURN_IF_EXCEPTION(parser.Parse(argc, argv));
std::string rom_filename = "";
if (!FLAGS_rom_file->Get().empty()) {
rom_filename = FLAGS_rom_file->Get();
}
#ifdef __APPLE__
return yaze_run_cocoa_app_delegate(rom_filename.c_str());
#endif
auto controller = std::make_unique<core::Controller>();
EXIT_IF_ERROR(controller->OnEntry(rom_filename))
while (controller->IsActive()) {
controller->OnInput();
if (auto status = controller->OnLoad(); !status.ok()) {
std::cerr << status.message() << std::endl;
break;
}
controller->DoRender();
}
controller->OnExit();
return EXIT_SUCCESS;
}
void yaze_check_version(const char *version) {
std::string current_version;
std::stringstream ss;