11#define IMGUI_DEFINE_MATH_OPERATORS
14#include "absl/debugging/symbolize.h"
15#include "absl/strings/ascii.h"
16#include "absl/strings/str_split.h"
17#include "absl/strings/strip.h"
31DEFINE_FLAG(std::string, log_file,
"",
"Output log file path for debugging.");
32DEFINE_FLAG(std::string, rom_file,
"",
"ROM file to load on startup.");
33DEFINE_FLAG(
bool, debug,
false,
"Enable debug logging and verbose output.");
35 "Minimum log level: debug, info, warn, error, or fatal.");
37 "Mirror logs to stderr even when writing to a file.");
39 std::string, log_categories,
"",
40 "Comma-separated list of log categories to enable or disable. "
41 "Prefix with '-' to disable a category. "
42 "Example: \"Room,DungeonEditor\" (allowlist) or \"-Input,-Graphics\" "
47 "The editor to open on startup (e.g., Dungeon, Overworld, Assembly).");
50 "Comma-separated list of panel IDs to open (e.g. 'dungeon.room_list,emulator.cpu_debugger')");
54 "Welcome screen behavior at startup: auto, show, or hide.");
56 "Dashboard panel behavior at startup: auto, show, or hide.");
58 "Panel sidebar visibility at startup: auto, show, or hide.");
60DEFINE_FLAG(
int, room, -1,
"Open Dungeon Editor at specific room ID (0-295).");
61DEFINE_FLAG(
int, map, -1,
"Open Overworld Editor at specific map ID (0-159).");
64DEFINE_FLAG(
bool, enable_api,
false,
"Enable the AI Agent API server.");
65DEFINE_FLAG(
int, api_port, 8080,
"Port for the AI Agent API server.");
70 "Start gRPC test harness server for automated GUI testing.");
72 "Port for gRPC test harness server (default: 50051).");
92 if (ctrl && ctrl->editor_manager()) {
116 const std::string lower = absl::AsciiStrToLower(raw_level);
117 if (lower ==
"debug") {
120 if (lower ==
"warn" || lower ==
"warning") {
123 if (lower ==
"error") {
126 if (lower ==
"fatal") {
133 std::set<std::string> categories;
134 for (absl::string_view token :
135 absl::StrSplit(raw,
',', absl::SkipWhitespace())) {
136 if (!token.empty()) {
137 categories.insert(std::string(absl::StripAsciiWhitespace(token)));
160 std::vector<std::string> tokens;
161 for (absl::string_view token :
162 absl::StrSplit(raw,
',', absl::SkipWhitespace())) {
163 if (!token.empty()) {
164 tokens.emplace_back(absl::StripAsciiWhitespace(token));
176int main(
int argc,
char** argv) {
177 absl::InitializeSymbolizer(argv[0]);
179#ifndef __EMSCRIPTEN__
188 const bool debug_flag = FLAGS_debug->Get();
189 const bool log_to_console_flag = FLAGS_log_to_console->Get();
192 std::set<std::string> log_categories =
195 std::string log_path = FLAGS_log_file->Get();
196 if (log_path.empty()) {
199 log_path = (*logs_dir /
"yaze.log").
string();
206 if (debug_flag || log_to_console_flag) {
210 LOG_INFO(
"Main",
"🚀 YAZE started in debug mode");
213 "Logging configured (level=%s, file=%s, console=%s, categories=%zu)",
215 log_path.empty() ?
"<stderr>" : log_path.c_str(),
216 (debug_flag || log_to_console_flag) ?
"on" :
"off",
217 log_categories.size());
221 config.
rom_file = FLAGS_rom_file->Get();
222 config.log_file = log_path;
224 config.log_categories = FLAGS_log_categories->Get();
225 config.startup_editor = FLAGS_editor->Get();
226 config.jump_to_room = FLAGS_room->Get();
227 config.jump_to_map = FLAGS_map->Get();
228 config.enable_api = FLAGS_enable_api->Get();
229 config.api_port = FLAGS_api_port->Get();
231 config.welcome_mode =
233 config.dashboard_mode =
235 config.sidebar_mode =
238 if (!FLAGS_open_panels->Get().empty()) {
243 config.enable_test_harness = FLAGS_enable_test_harness->Get();
244 config.test_harness_port = FLAGS_test_harness_port->Get();
248 return yaze_run_cocoa_app_delegate(config);
254 yaze::app::wasm::InitializeWasmPlatform();
258 static bool s_wasm_initialized =
false;
261 auto WasmMainLoop = []() {
263 if (!s_wasm_initialized) {
264 if (yaze::app::wasm::IsFileSystemReady()) {
265 LOG_INFO(
"Main",
"Filesystem ready, initializing application...");
267 s_wasm_initialized =
true;
280 emscripten_set_main_loop(WasmMainLoop, 0, 1);
285 std::unique_ptr<yaze::cli::api::HttpServer> api_server;
286 if (config.enable_api) {
287 api_server = std::make_unique<yaze::cli::api::HttpServer>();
288 auto status = api_server->Start(config.api_port);
290 LOG_ERROR(
"Main",
"Failed to start API server: %s", std::string(status.message()).c_str());
292 LOG_INFO(
"Main",
"API Server started on port %d", config.api_port);
Controller * GetController()
static Application & Instance()
void Initialize(const AppConfig &config)
editor::EditorManager * editor_manager()
The EditorManager controls the main editor window and manages the various editor classes.
auto emulator() -> emu::Emulator &
A class for emulating and debugging SNES games.
static void CleanupOldLogs(int keep_count=5)
Clean up old crash logs, keeping only the most recent N logs.
static void Initialize(const std::string &version)
Initialize the crash handler for the application.
void Parse(int argc, char **argv)
static LogManager & instance()
void configure(LogLevel level, const std::string &file_path, const std::set< std::string > &categories)
Configures the logging system.
#define DEFINE_FLAG(type, name, default_val, help_text)
#define YAZE_VERSION_STRING
#define LOG_ERROR(category, format,...)
#define LOG_INFO(category, format,...)
#define RETURN_IF_EXCEPTION(expression)
int main(int argc, char **argv)
const char * LogLevelToString(yaze::util::LogLevel level)
std::set< std::string > ParseLogCategories(const std::string &raw)
yaze::util::LogLevel ParseLogLevelFlag(const std::string &raw_level, bool debug_flag)
std::vector< std::string > ParseCommaList(const std::string &raw)
yaze::editor::EditorManager * GetGlobalEditorManager()
yaze::emu::Emulator * GetGlobalEmulator()
FlagRegistry * global_flag_registry()
LogLevel
Defines the severity levels for log messages. This allows for filtering messages based on their impor...
StartupVisibility StartupVisibilityFromString(absl::string_view value)
Configuration options for the application startup.
Yet Another Zelda3 Editor (YAZE) - Public C API.