mirror of
https://github.com/RetroDECK/RetroQUEST.git
synced 2025-04-21 01:24:06 +00:00
gdlibretro: enhanced logging
This commit is contained in:
parent
b1e71aa4d8
commit
003f05ec0e
|
@ -62,13 +62,15 @@ std::vector<std::string> split(std::string s, std::string delimiter)
|
|||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
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;
|
||||
cb->log = core_log;
|
||||
}
|
||||
|
@ -85,6 +87,7 @@ bool RetroHost::core_environment(unsigned command, void *data)
|
|||
case RETRO_ENVIRONMENT_GET_VARIABLE:
|
||||
{
|
||||
auto var = (retro_variable *)data;
|
||||
godot::UtilityFunctions::print("[RetroHost] RETRO_ENVIRONMENT_GET_VARIABLE called for key: ", var->key);
|
||||
return this->get_variable(var);
|
||||
}
|
||||
break;
|
||||
|
@ -158,8 +161,7 @@ bool RetroHost::core_environment(unsigned command, void *data)
|
|||
|
||||
default:
|
||||
{
|
||||
godot::UtilityFunctions::print("[RetroHost] Core environment command " +
|
||||
godot::String::num(command) + " not implemented.");
|
||||
godot::UtilityFunctions::print("[RetroHost] Command ", command, " not handled explicitly.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,33 +79,36 @@ RetroHost *RetroHost::get_singleton()
|
|||
|
||||
bool RetroHost::load_core(godot::String name) {
|
||||
this->unload_core();
|
||||
godot::UtilityFunctions::print("[RetroHost] Loading core \"", name, "\"");
|
||||
godot::UtilityFunctions::print("[RetroHost] Starting load_core with name: ", name);
|
||||
|
||||
godot::String lib_path;
|
||||
if (godot::OS::get_singleton()->has_feature("editor")) {
|
||||
this->cwd =
|
||||
godot::ProjectSettings::get_singleton()->globalize_path("res://") + "libretro-cores/";
|
||||
lib_path = cwd + name + ".dll"; // Editor path (Windows assumed default)
|
||||
godot::UtilityFunctions::print("[RetroHost] Editor mode detected. Core path: ", lib_path);
|
||||
} else {
|
||||
this->cwd = godot::OS::get_singleton()->get_executable_path().get_base_dir();
|
||||
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
|
||||
this->core.handle = LoadLibrary(lib_path.utf8().get_data());
|
||||
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;
|
||||
}
|
||||
#elif defined(PLATFORM_LINUX) || defined(PLATFORM_ANDROID)
|
||||
this->core.handle = dlopen(lib_path.utf8().get_data(), RTLD_LAZY);
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
|
||||
godot::UtilityFunctions::print("[RetroHost] Core library loaded successfully.");
|
||||
|
||||
// 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_deinit, retro_deinit);
|
||||
|
@ -174,11 +177,13 @@ void RetroHost::unload_core()
|
|||
godot::UtilityFunctions::print("[RetroHost] Core unloaded successfully.");
|
||||
}
|
||||
|
||||
void RetroHost::run()
|
||||
{
|
||||
void RetroHost::run(){
|
||||
|
||||
godot::UtilityFunctions::print("[RetroHost] Starting core run...");
|
||||
|
||||
if (!this->core.initialized)
|
||||
{
|
||||
godot::UtilityFunctions::printerr("[RetroHost] Core not initialized. Cannot run.");
|
||||
godot::UtilityFunctions::printerr("[RetroHost] Cannot run. Core not initialized.");
|
||||
return;
|
||||
}
|
||||
this->core.retro_run();
|
||||
|
|
|
@ -7,32 +7,32 @@ var current_core : Object = null # The emulator core (passed dynamically)
|
|||
var current_rom : String = "" # Initialize to an empty string
|
||||
|
||||
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:
|
||||
push_error("Core path is missing.")
|
||||
push_error("[libretro_loader] Core path is missing.")
|
||||
return false
|
||||
|
||||
if not rom_path:
|
||||
push_error("ROM path is missing.")
|
||||
push_error("[libretro_loader] ROM path is missing.")
|
||||
return false
|
||||
|
||||
# Load the core (emulator)
|
||||
print("Loading core...")
|
||||
print("[libretro_loader] Loading core...")
|
||||
current_core = load(core_path)
|
||||
if not current_core:
|
||||
push_error("Failed to load core: " + core_path)
|
||||
push_error("[libretro_loader] Failed to load core: " + core_path)
|
||||
return false
|
||||
print("Core loaded successfully.")
|
||||
|
||||
current_core.initialize()
|
||||
print("[libretro_loader] Core initialized.")
|
||||
|
||||
# Load the ROM
|
||||
print("Checking ROM file...")
|
||||
print("[libretro_loader] Checking ROM file...")
|
||||
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
|
||||
print("ROM file exists.")
|
||||
print("[libretro_loader] ROM file exists.")
|
||||
|
||||
var file = FileAccess.open(rom_path, FileAccess.READ)
|
||||
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())
|
||||
file.close()
|
||||
print("[libretro_loader] ROM data loaded successfully.")
|
||||
|
||||
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
|
||||
print("ROM loaded successfully.")
|
||||
|
||||
print("[libretro_loader] ROM loaded successfully.")
|
||||
|
||||
current_rom = rom_path
|
||||
print("Core and ROM loaded successfully.")
|
||||
print("[libretro_loader] Core and ROM loaded successfully.")
|
||||
|
||||
# Ensure SubViewport is ready
|
||||
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
|
||||
elapsed_time += get_process_delta_time()
|
||||
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
|
||||
|
||||
texture_rect.texture = sub_viewport.get_texture()
|
||||
print("SubViewport texture assigned successfully.")
|
||||
print("[libretro_loader] SubViewport texture assigned successfully.")
|
||||
return true
|
||||
|
||||
func _process(delta):
|
||||
|
@ -95,6 +97,7 @@ func _ready():
|
|||
"""
|
||||
Initializes the SubViewport and TextureRect.
|
||||
"""
|
||||
print("[libretro_loader] _ready: Initializing SubViewport and TextureRect.")
|
||||
if sub_viewport and texture_rect:
|
||||
print("SubViewport and TextureRect initialized successfully.")
|
||||
else:
|
||||
|
@ -102,3 +105,4 @@ func _ready():
|
|||
|
||||
# Ensure SubViewport always renders
|
||||
sub_viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
|
||||
print("[libretro_loader] SubViewport set to always update.")
|
||||
|
|
Loading…
Reference in a new issue