gdlibretro: enhanced logging

This commit is contained in:
XargonWan 2024-12-27 10:53:34 +09:00
parent b1e71aa4d8
commit 003f05ec0e
3 changed files with 37 additions and 26 deletions

View file

@ -62,13 +62,15 @@ std::vector<std::string> split(std::string s, std::string delimiter)
} }
// Handles various core environment commands // Handles various core environment commands
bool RetroHost::core_environment(unsigned command, void *data) bool RetroHost::core_environment(unsigned command, void *data){
{
godot::UtilityFunctions::print("[RetroHost] core_environment called with command: ", command);
switch (command) switch (command)
{ {
case RETRO_ENVIRONMENT_GET_LOG_INTERFACE: case RETRO_ENVIRONMENT_GET_LOG_INTERFACE:
{ {
godot::UtilityFunctions::print("[RetroHost] Core log interface set."); godot::UtilityFunctions::print("[RetroHost] RETRO_ENVIRONMENT_GET_LOG_INTERFACE called.");
struct retro_log_callback *cb = (struct retro_log_callback *)data; struct retro_log_callback *cb = (struct retro_log_callback *)data;
cb->log = core_log; cb->log = core_log;
} }
@ -85,6 +87,7 @@ bool RetroHost::core_environment(unsigned command, void *data)
case RETRO_ENVIRONMENT_GET_VARIABLE: case RETRO_ENVIRONMENT_GET_VARIABLE:
{ {
auto var = (retro_variable *)data; auto var = (retro_variable *)data;
godot::UtilityFunctions::print("[RetroHost] RETRO_ENVIRONMENT_GET_VARIABLE called for key: ", var->key);
return this->get_variable(var); return this->get_variable(var);
} }
break; break;
@ -158,8 +161,7 @@ bool RetroHost::core_environment(unsigned command, void *data)
default: default:
{ {
godot::UtilityFunctions::print("[RetroHost] Core environment command " + godot::UtilityFunctions::print("[RetroHost] Command ", command, " not handled explicitly.");
godot::String::num(command) + " not implemented.");
return false; return false;
} }
} }

View file

@ -79,33 +79,36 @@ RetroHost *RetroHost::get_singleton()
bool RetroHost::load_core(godot::String name) { bool RetroHost::load_core(godot::String name) {
this->unload_core(); this->unload_core();
godot::UtilityFunctions::print("[RetroHost] Loading core \"", name, "\""); godot::UtilityFunctions::print("[RetroHost] Starting load_core with name: ", name);
godot::String lib_path; godot::String lib_path;
if (godot::OS::get_singleton()->has_feature("editor")) { if (godot::OS::get_singleton()->has_feature("editor")) {
this->cwd = this->cwd =
godot::ProjectSettings::get_singleton()->globalize_path("res://") + "libretro-cores/"; godot::ProjectSettings::get_singleton()->globalize_path("res://") + "libretro-cores/";
lib_path = cwd + name + ".dll"; // Editor path (Windows assumed default) lib_path = cwd + name + ".dll"; // Editor path (Windows assumed default)
godot::UtilityFunctions::print("[RetroHost] Editor mode detected. Core path: ", lib_path);
} else { } else {
this->cwd = godot::OS::get_singleton()->get_executable_path().get_base_dir(); this->cwd = godot::OS::get_singleton()->get_executable_path().get_base_dir();
lib_path = cwd + "/" + name; lib_path = cwd + "/" + name;
godot::UtilityFunctions::print("[RetroHost] Runtime mode detected. Core path: ", lib_path);
} }
godot::UtilityFunctions::print("[RetroHost] Resolved core path: ", lib_path);
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
this->core.handle = LoadLibrary(lib_path.utf8().get_data()); this->core.handle = LoadLibrary(lib_path.utf8().get_data());
if (this->core.handle == NULL) { if (this->core.handle == NULL) {
godot::UtilityFunctions::printerr("[RetroHost] Failed to load core \"", lib_path, "\""); godot::UtilityFunctions::printerr("[RetroHost] Failed to load core \"", lib_path, "\". Error: ", GetLastErrorAsStr().c_str());
return false; return false;
} }
#elif defined(PLATFORM_LINUX) || defined(PLATFORM_ANDROID) #elif defined(PLATFORM_LINUX) || defined(PLATFORM_ANDROID)
this->core.handle = dlopen(lib_path.utf8().get_data(), RTLD_LAZY); this->core.handle = dlopen(lib_path.utf8().get_data(), RTLD_LAZY);
if (this->core.handle == nullptr) { if (this->core.handle == nullptr) {
godot::UtilityFunctions::printerr("[RetroHost] Failed to load core \"", lib_path, "\": ", GetLastErrorAsStr().c_str()); godot::UtilityFunctions::printerr("[RetroHost] Failed to load core \"", lib_path, "\". Error: ", GetLastErrorAsStr().c_str());
return false; return false;
} }
#endif #endif
godot::UtilityFunctions::print("[RetroHost] Core library loaded successfully.");
// Load RetroArch symbols dynamically // Load RetroArch symbols dynamically
load_symbol_return_false_on_err(this->core.handle, this->core.retro_init, retro_init); load_symbol_return_false_on_err(this->core.handle, this->core.retro_init, retro_init);
load_symbol_return_false_on_err(this->core.handle, this->core.retro_deinit, retro_deinit); load_symbol_return_false_on_err(this->core.handle, this->core.retro_deinit, retro_deinit);
@ -174,11 +177,13 @@ void RetroHost::unload_core()
godot::UtilityFunctions::print("[RetroHost] Core unloaded successfully."); godot::UtilityFunctions::print("[RetroHost] Core unloaded successfully.");
} }
void RetroHost::run() void RetroHost::run(){
{
godot::UtilityFunctions::print("[RetroHost] Starting core run...");
if (!this->core.initialized) if (!this->core.initialized)
{ {
godot::UtilityFunctions::printerr("[RetroHost] Core not initialized. Cannot run."); godot::UtilityFunctions::printerr("[RetroHost] Cannot run. Core not initialized.");
return; return;
} }
this->core.retro_run(); this->core.retro_run();

View file

@ -7,32 +7,32 @@ var current_core : Object = null # The emulator core (passed dynamically)
var current_rom : String = "" # Initialize to an empty string var current_rom : String = "" # Initialize to an empty string
func start_emulation(core_path: String, rom_path: String) -> bool: func start_emulation(core_path: String, rom_path: String) -> bool:
print("Starting emulation with core: ", core_path, ", ROM: ", rom_path) print("[libretro_loader] Starting emulation with core: ", core_path, ", ROM: ", rom_path)
if not core_path: if not core_path:
push_error("Core path is missing.") push_error("[libretro_loader] Core path is missing.")
return false return false
if not rom_path: if not rom_path:
push_error("ROM path is missing.") push_error("[libretro_loader] ROM path is missing.")
return false return false
# Load the core (emulator) # Load the core (emulator)
print("Loading core...") print("[libretro_loader] Loading core...")
current_core = load(core_path) current_core = load(core_path)
if not current_core: if not current_core:
push_error("Failed to load core: " + core_path) push_error("[libretro_loader] Failed to load core: " + core_path)
return false return false
print("Core loaded successfully.")
current_core.initialize() current_core.initialize()
print("[libretro_loader] Core initialized.")
# Load the ROM # Load the ROM
print("Checking ROM file...") print("[libretro_loader] Checking ROM file...")
if not FileAccess.file_exists(rom_path): if not FileAccess.file_exists(rom_path):
push_error("ROM not found: " + rom_path) push_error("[libretro_loader] ROM not found: " + rom_path)
return false return false
print("ROM file exists.") print("[libretro_loader] ROM file exists.")
var file = FileAccess.open(rom_path, FileAccess.READ) var file = FileAccess.open(rom_path, FileAccess.READ)
if not file: if not file:
@ -42,14 +42,16 @@ func start_emulation(core_path: String, rom_path: String) -> bool:
var rom_data = file.get_buffer(file.get_length()) var rom_data = file.get_buffer(file.get_length())
file.close() file.close()
print("[libretro_loader] ROM data loaded successfully.")
if not current_core.load_game(rom_data): if not current_core.load_game(rom_data):
push_error("Failed to load ROM: " + rom_path) push_error("[libretro_loader] Failed to load ROM: " + rom_path)
return false return false
print("ROM loaded successfully.")
print("[libretro_loader] ROM loaded successfully.")
current_rom = rom_path current_rom = rom_path
print("Core and ROM loaded successfully.") print("[libretro_loader] Core and ROM loaded successfully.")
# Ensure SubViewport is ready # Ensure SubViewport is ready
sub_viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS sub_viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
@ -61,11 +63,11 @@ func start_emulation(core_path: String, rom_path: String) -> bool:
await get_tree().idle_frame # Waits for the next frame await get_tree().idle_frame # Waits for the next frame
elapsed_time += get_process_delta_time() elapsed_time += get_process_delta_time()
if not sub_viewport.get_texture(): if not sub_viewport.get_texture():
push_error("Error: SubViewport texture is not ready after waiting.") push_error("[libretro_loader] Error: SubViewport texture is not ready after waiting.")
return false return false
texture_rect.texture = sub_viewport.get_texture() texture_rect.texture = sub_viewport.get_texture()
print("SubViewport texture assigned successfully.") print("[libretro_loader] SubViewport texture assigned successfully.")
return true return true
func _process(delta): func _process(delta):
@ -95,6 +97,7 @@ func _ready():
""" """
Initializes the SubViewport and TextureRect. Initializes the SubViewport and TextureRect.
""" """
print("[libretro_loader] _ready: Initializing SubViewport and TextureRect.")
if sub_viewport and texture_rect: if sub_viewport and texture_rect:
print("SubViewport and TextureRect initialized successfully.") print("SubViewport and TextureRect initialized successfully.")
else: else:
@ -102,3 +105,4 @@ func _ready():
# Ensure SubViewport always renders # Ensure SubViewport always renders
sub_viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS sub_viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
print("[libretro_loader] SubViewport set to always update.")