yaze_app_main fn: add main application entry point for yaze with command-line argument parsing and controller management
This commit is contained in:
@@ -27,6 +27,7 @@ typedef enum yaze_status {
|
|||||||
YAZE_ERROR = 1,
|
YAZE_ERROR = 1,
|
||||||
} yaze_status;
|
} yaze_status;
|
||||||
|
|
||||||
|
int yaze_app_main(int argc, char** argv);
|
||||||
void yaze_check_version(const char* version);
|
void yaze_check_version(const char* version);
|
||||||
|
|
||||||
yaze_status yaze_init(yaze_editor_context*);
|
yaze_status yaze_init(yaze_editor_context*);
|
||||||
|
|||||||
27
src/yaze.cc
27
src/yaze.cc
@@ -1,6 +1,7 @@
|
|||||||
#include "yaze.h"
|
#include "yaze.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
@@ -8,6 +9,32 @@
|
|||||||
#include "dungeon.h"
|
#include "dungeon.h"
|
||||||
#include "yaze_config.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) {
|
void yaze_check_version(const char *version) {
|
||||||
std::string current_version;
|
std::string current_version;
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|||||||
Reference in New Issue
Block a user