diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 697ec0d7..d385b3f7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/app/editor/agent/agent_chat_widget.cc b/src/app/editor/agent/agent_chat_widget.cc index 9d331285..f665e9c4 100644 --- a/src/app/editor/agent/agent_chat_widget.cc +++ b/src/app/editor/agent/agent_chat_widget.cc @@ -1,3 +1,5 @@ +#define IMGUI_DEFINE_MATH_OPERATORS + #include "app/editor/agent/agent_chat_widget.h" #include diff --git a/src/app/editor/agent/automation_bridge.cc b/src/app/editor/agent/automation_bridge.cc index d649fc4c..3bfb9768 100644 --- a/src/app/editor/agent/automation_bridge.cc +++ b/src/app/editor/agent/automation_bridge.cc @@ -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 { diff --git a/src/app_main.cc b/src/app_main.cc new file mode 100644 index 00000000..0c8c1c1e --- /dev/null +++ b/src/app_main.cc @@ -0,0 +1,89 @@ +// Application entry point - separated from C API implementation +#include "yaze.h" + +#include +#include +#include +#include +#include +#include + +#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 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(); + 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; +} diff --git a/src/yaze.cc b/src/yaze.cc index 158236f2..27d15369 100644 --- a/src/yaze.cc +++ b/src/yaze.cc @@ -1,101 +1,20 @@ +// C API implementation - no heavy GUI/editor dependencies #include "yaze.h" -#include #include -#include #include -#include -#include #include #include #include -#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 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(); - 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) {