yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
main.cc
Go to the documentation of this file.
1#if __APPLE__
3#endif
4
5#define IMGUI_DEFINE_MATH_OPERATORS
6#include "absl/debugging/failure_signal_handler.h"
7#include "absl/debugging/symbolize.h"
9#include "app/core/features.h"
10#include "util/flag.h"
11#include "util/log.h"
12
13#ifdef YAZE_WITH_GRPC
16#endif
17
22using namespace yaze;
23
24// Enhanced flags for debugging
25DEFINE_FLAG(std::string, rom_file, "", "The ROM file to load.");
26DEFINE_FLAG(std::string, log_file, "", "Output log file path for debugging.");
27DEFINE_FLAG(bool, debug, false, "Enable debug logging and verbose output.");
28DEFINE_FLAG(std::string, log_categories, "",
29 "Comma-separated list of log categories to enable. "
30 "If empty, all categories are logged. "
31 "Example: --log_categories=\"Room,DungeonEditor\" to filter noisy logs.");
32DEFINE_FLAG(std::string, editor, "",
33 "The editor to open on startup. "
34 "Available editors: Assembly, Dungeon, Graphics, Music, Overworld, "
35 "Palette, Screen, Sprite, Message, Hex, Agent, Settings. "
36 "Example: --editor=Dungeon");
37DEFINE_FLAG(std::string, cards, "",
38 "A comma-separated list of cards to open within the specified editor. "
39 "For Dungeon editor: 'Rooms List', 'Room Matrix', 'Entrances List', "
40 "'Room Graphics', 'Object Editor', 'Palette Editor', or 'Room N' (where N is room ID). "
41 "Example: --cards=\"Rooms List,Room 0,Room 105\"");
42
43#ifdef YAZE_WITH_GRPC
44// gRPC test harness flags
45DEFINE_FLAG(bool, enable_test_harness, false,
46 "Start gRPC test harness server for automated GUI testing.");
47DEFINE_FLAG(int, test_harness_port, 50051,
48 "Port for gRPC test harness server (default: 50051).");
49#endif
50
51int main(int argc, char **argv) {
52 absl::InitializeSymbolizer(argv[0]);
53
54 // Configure failure signal handler to be less aggressive
55 // This prevents false positives during SDL/graphics cleanup
56 absl::FailureSignalHandlerOptions options;
57 options.symbolize_stacktrace = true;
58 options.use_alternate_stack =
59 false; // Avoid conflicts with normal stack during cleanup
60 options.alarm_on_failure_secs =
61 false; // Don't set alarms that can trigger on natural leaks
62 options.call_previous_handler = true; // Allow system handlers to also run
63 options.writerfn =
64 nullptr; // Use default writer to avoid custom handling issues
65 absl::InstallFailureSignalHandler(options);
66
67 // Parse command line flags with custom parser
69 RETURN_IF_EXCEPTION(parser.Parse(argc, argv));
70
71 // Set up logging
72 yaze::util::LogLevel log_level = FLAGS_debug->Get()
75
76 // Parse log categories from comma-separated string
77 std::set<std::string> log_categories;
78 std::string categories_str = FLAGS_log_categories->Get();
79 if (!categories_str.empty()) {
80 size_t start = 0;
81 size_t end = categories_str.find(',');
82 while (end != std::string::npos) {
83 log_categories.insert(categories_str.substr(start, end - start));
84 start = end + 1;
85 end = categories_str.find(',', start);
86 }
87 log_categories.insert(categories_str.substr(start));
88 }
89
90 yaze::util::LogManager::instance().configure(log_level, FLAGS_log_file->Get(),
91 log_categories);
92
93 // Enable console logging via feature flag if debug is enabled.
94 if (FLAGS_debug->Get()) {
96 LOG_INFO("Main", "šŸš€ YAZE started in debug mode");
97 }
98
99 std::string rom_filename = "";
100 if (!FLAGS_rom_file->Get().empty()) {
101 rom_filename = FLAGS_rom_file->Get();
102 }
103
104#ifdef YAZE_WITH_GRPC
105 // Start gRPC test harness server if requested
106 if (FLAGS_enable_test_harness->Get()) {
107 // Get TestManager instance (initializes UI testing if available)
108 auto& test_manager = yaze::test::TestManager::Get();
109
110 auto& server = yaze::test::ImGuiTestHarnessServer::Instance();
111 int port = FLAGS_test_harness_port->Get();
112
113 std::cout << "\nšŸš€ Starting ImGui Test Harness on port " << port << "..." << std::endl;
114 auto status = server.Start(port, &test_manager);
115 if (!status.ok()) {
116 std::cerr << "āŒ ERROR: Failed to start test harness server on port " << port << std::endl;
117 std::cerr << " " << status.message() << std::endl;
118 return 1;
119 }
120 std::cout << "āœ… Test harness ready on 127.0.0.1:" << port << std::endl;
121 std::cout << " Available RPCs: Ping, Click, Type, Wait, Assert, Screenshot\n" << std::endl;
122 }
123#endif
124
125#ifdef __APPLE__
126 return yaze_run_cocoa_app_delegate(rom_filename.c_str());
127#elif defined(_WIN32)
128 // We set SDL_MAIN_HANDLED for Win32 to avoid SDL hijacking main()
129 SDL_SetMainReady();
130#endif
131
132 auto controller = std::make_unique<core::Controller>();
133 EXIT_IF_ERROR(controller->OnEntry(rom_filename))
134
135 // Set startup editor and cards from flags (after OnEntry initializes editor manager)
136 if (!FLAGS_editor->Get().empty()) {
137 controller->SetStartupEditor(FLAGS_editor->Get(), FLAGS_cards->Get());
138 }
139
140 while (controller->IsActive()) {
141 controller->OnInput();
142 if (auto status = controller->OnLoad(); !status.ok()) {
143 std::cerr << status.message() << std::endl;
144 break;
145 }
146 controller->DoRender();
147 }
148 controller->OnExit();
149
150#ifdef YAZE_WITH_GRPC
151 // Shutdown gRPC server if running
152 yaze::test::ImGuiTestHarnessServer::Instance().Shutdown();
153#endif
154
155 return EXIT_SUCCESS;
156}
static Flags & get()
Definition features.h:79
static TestManager & Get()
void Parse(int argc, char **argv)
Definition flag.h:135
static LogManager & instance()
Definition log.cc:29
void configure(LogLevel level, const std::string &file_path, const std::set< std::string > &categories)
Configures the logging system.
Definition log.cc:43
#define DEFINE_FLAG(type, name, default_val, help_text)
Definition flag.h:122
#define LOG_INFO(category, format,...)
Definition log.h:106
#define RETURN_IF_EXCEPTION(expression)
Definition macro.h:103
#define EXIT_IF_ERROR(expression)
Definition macro.h:35
FlagRegistry * global_flag_registry()
Definition flag.h:115
LogLevel
Defines the severity levels for log messages. This allows for filtering messages based on their impor...
Definition log.h:27
Main namespace for the application.