feat: Add Application Entry Point for Yaze
- Introduced app_main.cc as the main entry point for the Yaze application, separating it from the C API implementation. - Implemented command-line flag parsing for ROM file loading, logging level, log file path, and log categories. - Configured the logging system to enhance traceability and user feedback during application startup and execution. - Integrated the core controller for managing application state and rendering, improving overall application structure and functionality.
This commit is contained in:
@@ -477,11 +477,16 @@ endif()
|
||||
|
||||
# Yaze Core Library (for testing and C API)
|
||||
if (YAZE_BUILD_LIB)
|
||||
# Sources shared by the C API library
|
||||
# Sources shared by the C API library (minimal dependencies)
|
||||
set(YAZE_C_SOURCES
|
||||
./yaze.cc
|
||||
cli/service/gui/gui_automation_client.cc
|
||||
)
|
||||
|
||||
# Application main entry point (uses controller and full dependencies)
|
||||
set(YAZE_APP_MAIN_SOURCES
|
||||
./app_main.cc
|
||||
)
|
||||
|
||||
if(YAZE_USE_MODULAR_BUILD)
|
||||
# Aggregate modular libraries into an interface target for backward compatibility
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
#include "app/editor/agent/agent_chat_widget.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
#include "app/editor/agent/automation_bridge.h"
|
||||
|
||||
#if defined(YAZE_WITH_GRPC)
|
||||
|
||||
#include "absl/time/time.h"
|
||||
#include "app/editor/agent/agent_chat_widget.h"
|
||||
#include "app/test/test_manager.h"
|
||||
|
||||
// test_manager.h already included in automation_bridge.h
|
||||
|
||||
namespace yaze {
|
||||
namespace editor {
|
||||
|
||||
89
src/app_main.cc
Normal file
89
src/app_main.cc
Normal file
@@ -0,0 +1,89 @@
|
||||
// Application entry point - separated from C API implementation
|
||||
#include "yaze.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "app/core/controller.h"
|
||||
#include "app/core/platform/app_delegate.h"
|
||||
#include "util/flag.h"
|
||||
#include "util/log.h"
|
||||
#include "yaze_config.h"
|
||||
|
||||
DEFINE_FLAG(std::string, rom_file, "",
|
||||
"Path to the ROM file to load. "
|
||||
"If not specified, the app will run without a ROM.");
|
||||
|
||||
DEFINE_FLAG(
|
||||
std::string, log_level, "info",
|
||||
"Minimum log level to output (e.g., debug, info, warn, error, fatal).");
|
||||
DEFINE_FLAG(std::string, log_file, "",
|
||||
"Path to the log file. If empty, logs to stderr.");
|
||||
DEFINE_FLAG(std::string, log_categories, "",
|
||||
"Comma-separated list of log categories to enable.");
|
||||
|
||||
int yaze_app_main(int argc, char** argv) {
|
||||
yaze::util::FlagParser parser(yaze::util::global_flag_registry());
|
||||
RETURN_IF_EXCEPTION(parser.Parse(argc, argv));
|
||||
|
||||
// --- Configure Logging System ---
|
||||
auto string_to_log_level = [](const std::string& s) {
|
||||
std::string upper_s;
|
||||
std::transform(s.begin(), s.end(), std::back_inserter(upper_s),
|
||||
::toupper);
|
||||
if (upper_s == "YAZE_DEBUG") return yaze::util::LogLevel::YAZE_DEBUG;
|
||||
if (upper_s == "INFO") return yaze::util::LogLevel::INFO;
|
||||
if (upper_s == "WARN" || upper_s == "WARNING")
|
||||
return yaze::util::LogLevel::WARNING;
|
||||
if (upper_s == "ERROR") return yaze::util::LogLevel::ERROR;
|
||||
if (upper_s == "FATAL") return yaze::util::LogLevel::FATAL;
|
||||
return yaze::util::LogLevel::INFO; // Default
|
||||
};
|
||||
|
||||
auto split_categories = [](const std::string& s) {
|
||||
std::set<std::string> result;
|
||||
std::stringstream ss(s);
|
||||
std::string item;
|
||||
while (std::getline(ss, item, ',')) {
|
||||
if (!item.empty()) {
|
||||
result.insert(item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
yaze::util::LogManager::instance().configure(
|
||||
string_to_log_level(FLAGS_log_level->Get()), FLAGS_log_file->Get(),
|
||||
split_categories(FLAGS_log_categories->Get()));
|
||||
|
||||
LOG_INFO("App", "Yaze starting up...");
|
||||
LOG_INFO("App", "Version: %s", YAZE_VERSION_STRING);
|
||||
|
||||
std::string rom_filename = "";
|
||||
if (!FLAGS_rom_file->Get().empty()) {
|
||||
rom_filename = FLAGS_rom_file->Get();
|
||||
LOG_INFO("App", "Loading ROM file: %s", rom_filename);
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
return yaze_run_cocoa_app_delegate(rom_filename.c_str());
|
||||
#endif
|
||||
|
||||
auto controller = std::make_unique<yaze::core::Controller>();
|
||||
EXIT_IF_ERROR(controller->OnEntry(rom_filename))
|
||||
while (controller->IsActive()) {
|
||||
controller->OnInput();
|
||||
if (auto status = controller->OnLoad(); !status.ok()) {
|
||||
LOG_ERROR("App", "Controller OnLoad failed: %s", status.message());
|
||||
break;
|
||||
}
|
||||
controller->DoRender();
|
||||
}
|
||||
controller->OnExit();
|
||||
LOG_INFO("App", "Yaze shutting down.");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
83
src/yaze.cc
83
src/yaze.cc
@@ -1,101 +1,20 @@
|
||||
// C API implementation - no heavy GUI/editor dependencies
|
||||
#include "yaze.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "app/core/controller.h"
|
||||
#include "app/core/platform/app_delegate.h"
|
||||
#include "app/editor/message/message_data.h"
|
||||
#include "app/rom.h"
|
||||
#include "app/zelda3/overworld/overworld.h"
|
||||
#include "util/flag.h"
|
||||
#include "util/log.h"
|
||||
#include "yaze_config.h"
|
||||
|
||||
DEFINE_FLAG(std::string, rom_file, "",
|
||||
"Path to the ROM file to load. "
|
||||
"If not specified, the app will run without a ROM.");
|
||||
|
||||
DEFINE_FLAG(
|
||||
std::string, log_level, "info",
|
||||
"Minimum log level to output (e.g., debug, info, warn, error, fatal).");
|
||||
DEFINE_FLAG(std::string, log_file, "",
|
||||
"Path to the log file. If empty, logs to stderr.");
|
||||
DEFINE_FLAG(std::string, log_categories, "",
|
||||
"Comma-separated list of log categories to enable.");
|
||||
|
||||
// Static variables for library state
|
||||
static bool g_library_initialized = false;
|
||||
|
||||
int yaze_app_main(int argc, char** argv) {
|
||||
yaze::util::FlagParser parser(yaze::util::global_flag_registry());
|
||||
RETURN_IF_EXCEPTION(parser.Parse(argc, argv));
|
||||
|
||||
// --- Configure Logging System ---
|
||||
auto string_to_log_level = [](const std::string& s) {
|
||||
std::string upper_s;
|
||||
std::transform(s.begin(), s.end(), std::back_inserter(upper_s),
|
||||
::toupper);
|
||||
if (upper_s == "YAZE_DEBUG") return yaze::util::LogLevel::YAZE_DEBUG;
|
||||
if (upper_s == "INFO") return yaze::util::LogLevel::INFO;
|
||||
if (upper_s == "WARN" || upper_s == "WARNING")
|
||||
return yaze::util::LogLevel::WARNING;
|
||||
if (upper_s == "ERROR") return yaze::util::LogLevel::ERROR;
|
||||
if (upper_s == "FATAL") return yaze::util::LogLevel::FATAL;
|
||||
return yaze::util::LogLevel::INFO; // Default
|
||||
};
|
||||
|
||||
auto split_categories = [](const std::string& s) {
|
||||
std::set<std::string> result;
|
||||
std::stringstream ss(s);
|
||||
std::string item;
|
||||
while (std::getline(ss, item, ',')) {
|
||||
if (!item.empty()) {
|
||||
result.insert(item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
yaze::util::LogManager::instance().configure(
|
||||
string_to_log_level(FLAGS_log_level->Get()), FLAGS_log_file->Get(),
|
||||
split_categories(FLAGS_log_categories->Get()));
|
||||
|
||||
LOG_INFO("App", "Yaze starting up...");
|
||||
LOG_INFO("App", "Version: %s", YAZE_VERSION_STRING);
|
||||
|
||||
std::string rom_filename = "";
|
||||
if (!FLAGS_rom_file->Get().empty()) {
|
||||
rom_filename = FLAGS_rom_file->Get();
|
||||
LOG_INFO("App", "Loading ROM file: %s", rom_filename);
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
return yaze_run_cocoa_app_delegate(rom_filename.c_str());
|
||||
#endif
|
||||
|
||||
auto controller = std::make_unique<yaze::core::Controller>();
|
||||
EXIT_IF_ERROR(controller->OnEntry(rom_filename))
|
||||
while (controller->IsActive()) {
|
||||
controller->OnInput();
|
||||
if (auto status = controller->OnLoad(); !status.ok()) {
|
||||
LOG_ERROR("App", "Controller OnLoad failed: %s", status.message());
|
||||
break;
|
||||
}
|
||||
controller->DoRender();
|
||||
}
|
||||
controller->OnExit();
|
||||
LOG_INFO("App", "Yaze shutting down.");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// Version and initialization functions
|
||||
yaze_status yaze_library_init() {
|
||||
if (g_library_initialized) {
|
||||
|
||||
Reference in New Issue
Block a user