Checkpoint

This commit is contained in:
XargonWan 2024-12-27 12:00:53 +09:00
parent 003f05ec0e
commit 2dfeccfab7
14 changed files with 73 additions and 41 deletions

Binary file not shown.

View file

@ -1718,6 +1718,7 @@ CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o
/home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/variant/signal.hpp
/home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/variant/string.hpp
/home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/variant/string_name.hpp
/home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/variant/utility_functions.hpp
/home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/variant/variant_size.hpp
/home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/include/godot_cpp/classes/ref.hpp
/home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/include/godot_cpp/classes/wrapped.hpp

View file

@ -1713,6 +1713,7 @@ CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o: src/RegisterExtension.c
extern/godot-cpp/gen/include/godot_cpp/variant/signal.hpp \
extern/godot-cpp/gen/include/godot_cpp/variant/string.hpp \
extern/godot-cpp/gen/include/godot_cpp/variant/string_name.hpp \
extern/godot-cpp/gen/include/godot_cpp/variant/utility_functions.hpp \
extern/godot-cpp/gen/include/godot_cpp/variant/variant_size.hpp \
extern/godot-cpp/include/godot_cpp/classes/ref.hpp \
extern/godot-cpp/include/godot_cpp/classes/wrapped.hpp \

View file

@ -264,6 +264,7 @@ CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o: \
/usr/include/c++/14/bits/hashtable_policy.h \
/usr/include/c++/14/bits/enable_special_members.h \
/home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/classes/engine.hpp \
/home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/variant/utility_functions.hpp \
/home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/src/RetroHost.hpp \
/usr/include/c++/14/filesystem /usr/include/c++/14/bits/fs_fwd.h \
/usr/include/c++/14/bits/chrono.h /usr/include/c++/14/ratio \

View file

@ -7,18 +7,14 @@ set(CMAKE_DEPENDS_GENERATOR "Unix Makefiles")
# The top level Makefile was generated from the following files:
set(CMAKE_MAKEFILE_DEPENDS
"CMakeCache.txt"
".git/HEAD"
".git/refs/heads/master"
"CMakeFiles/3.30.3/CMakeCXXCompiler.cmake"
"CMakeFiles/3.30.3/CMakeSystem.cmake"
"CMakeFiles/VerifyGlobs.cmake"
"CMakeFiles/cmake.verify_globs"
"CMakeFiles/git-data/grabRef.cmake"
"CMakeLists.txt"
"cmake/ClangFormat.cmake"
"cmake/CompilerWarnings.cmake"
"cmake/GetGitRevisionDescription.cmake"
"cmake/GetGitRevisionDescription.cmake.in"
"cmake/GitVersionInfo.cmake"
"cmake/ccache.cmake"
"extern/CMakeLists.txt"
@ -77,12 +73,6 @@ set(CMAKE_MAKEFILE_OUTPUTS
# Byproducts of CMake generate step:
set(CMAKE_MAKEFILE_PRODUCTS
"CMakeFiles/git-data/HEAD"
"CMakeFiles/git-data/grabRef.cmake"
"CMakeFiles/git-data/head-ref"
"CMakeFiles/git-data/HEAD"
"CMakeFiles/git-data/grabRef.cmake"
"CMakeFiles/git-data/head-ref"
"gen/Version.h"
"CMakeFiles/CMakeDirectoryInformation.cmake"
"src/CMakeFiles/CMakeDirectoryInformation.cmake"

View file

@ -30,16 +30,16 @@ namespace VersionInfo {
//
// It uses the form "<project name> <last tag>-<# commits since last tag>-<short commit hash>".
// If there are no commits since the last tag, only the tag is shown.
constexpr std::string_view VERSION_STR = "LibRetroHost 7ebbf84";
constexpr std::string_view VERSION_STR = "LibRetroHost HEAD-HASH-NOTFOUND";
// The version information as a string.
// This is generated using the current git commit information.
//
// It uses the form "<last tag>-<# commits since last tag>-<short commit hash>".
// If there are no commits since the last tag, only the tag is shown.
constexpr std::string_view VERSION_SHORT_STR = "7ebbf84";
constexpr std::string_view VERSION_SHORT_STR = "HEAD-HASH-NOTFOUND";
// The full git SHA1 hash as a string.
// This is generated using the current git commit information.
constexpr std::string_view GIT_SHA1_STR = "7ebbf840187f54466988c0b5b20524ad21ca1d58";
constexpr std::string_view GIT_SHA1_STR = "GITDIR-NOTFOUND";
}

View file

@ -4,7 +4,7 @@
#include "godot_cpp/core/defs.hpp"
#include "godot_cpp/godot.hpp"
#include "godot_cpp/classes/engine.hpp"
//#include "godot_cpp/variant/utility_functions.hpp"
#include "godot_cpp/variant/utility_functions.hpp"
#include "RetroHost.hpp"
@ -18,8 +18,15 @@ namespace {
godot::ClassDB::register_class<RetroHost>();
godot::UtilityFunctions::print("[RetroHost] Initializing extension...");
retro_host_singleton = memnew(RetroHost());
if (!retro_host_singleton) {
godot::UtilityFunctions::printerr("[RetroHost] Failed to allocate memory for singleton.");
return;
}
godot::Engine::get_singleton()->register_singleton("RetroHost", RetroHost::get_singleton());
godot::UtilityFunctions::print("[RetroHost] Singleton registered successfully.");
}
void uninitialize_extension(godot::ModuleInitializationLevel p_level) {
@ -37,12 +44,14 @@ extern "C" {
GDExtensionClassLibraryPtr p_library,
GDExtensionInitialization *r_initialization) {
//godot::UtilityFunctions::print("[LibRetroHost] GDExtensionInit called");
godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
init_obj.register_initializer(initialize_extension);
init_obj.register_terminator(uninitialize_extension);
init_obj.set_minimum_library_initialization_level(godot::MODULE_INITIALIZATION_LEVEL_SCENE);
//godot::UtilityFunctions::print("[LibRetroHost] Initialization setup completed.");
return init_obj.init();
}
}

View file

@ -102,6 +102,7 @@ bool RetroHost::load_core(godot::String name) {
#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] dlopen failed: ", dlerror());
godot::UtilityFunctions::printerr("[RetroHost] Failed to load core \"", lib_path, "\". Error: ", GetLastErrorAsStr().c_str());
return false;
}

19
main.gd
View file

@ -3,25 +3,30 @@ extends Node
@onready var loader = preload("res://scripts/libretro_loader.gd").new()
func _ready():
print("[main] Entering _ready function")
var core_path = "res://cores/genesis_plus_gx_libretro.so" # Replace with your actual core path
if not FileAccess.file_exists(core_path):
push_error("Core not found at: " + core_path)
return false
return false
else:
print("[main] File ", core_path," exists")
var rom_path = "res://roms/megadrive/Sonic the Hedgehog.bin" # Replace with your actual ROM path
if not FileAccess.file_exists(rom_path):
push_error("Rom not found at: " + rom_path)
return false
push_error("[main] Rom not found at: " + rom_path)
return false
else:
print("[main] File ", rom_path," exists")
print("Core path: ", core_path)
print("ROM path: ", rom_path)
print("[main] Core path: ", core_path)
print("[main] ROM path: ", rom_path)
var success = await loader.start_emulation(core_path, rom_path) # Use await to call the coroutine
if success:
print("Game started successfully.")
print("[main] Game started successfully.")
start_emulation_loop()
else:
print("Failed to start the game.")
print("[main] Failed to start the game.")
func start_emulation_loop():
"""

View file

@ -33,10 +33,16 @@ done
write ""
write "My issue now is the following, can you help me to fix it?"
write '
I enter in the scene but the emulated game is not loaded, I just get this log:
[RetroHost] Constructor
Maybe we should enhance the logging to understand what is actually happening
'
When I load godot I get this crash:
godot .
================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.2.2.rc2.mono.official (c61a68614e5b030a4a1e11abaa5a893b8017f78d)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x45250) [0x7ea94c445250] (??:0)
-- END OF BACKTRACE --
================================================================
Annullato (core dump creato)
'

View file

@ -2,13 +2,19 @@ extends Node
@onready var sub_viewport = $room/SubViewport
@onready var texture_rect = $room/SubViewport/TextureRect
@onready var retro_host = Engine.get_singleton("RetroHost") # Get the RetroHost singleton
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("[libretro_loader] Starting emulation with core: ", core_path, ", ROM: ", rom_path)
# Check if RetroHost is available
if not retro_host:
push_error("[libretro_loader] RetroHost singleton not found!")
return false
if not core_path:
push_error("[libretro_loader] Core path is missing.")
return false
@ -17,35 +23,34 @@ func start_emulation(core_path: String, rom_path: String) -> bool:
push_error("[libretro_loader] ROM path is missing.")
return false
# Load the core (emulator)
print("[libretro_loader] Loading core...")
current_core = load(core_path)
if not current_core:
# Load the core (via RetroHost)
print("[libretro_loader] Loading core using RetroHost...")
var core_loaded = retro_host.load_core(core_path)
if not core_loaded:
push_error("[libretro_loader] Failed to load core: " + core_path)
return false
print("[libretro_loader] Core loaded successfully.")
current_core.initialize()
print("[libretro_loader] Core initialized.")
# Load the ROM
print("[libretro_loader] Checking ROM file...")
# Check if ROM file exists
if not FileAccess.file_exists(rom_path):
push_error("[libretro_loader] ROM not found: " + rom_path)
return false
print("[libretro_loader] ROM file exists.")
# Load the ROM
print("[libretro_loader] Opening ROM...")
var file = FileAccess.open(rom_path, FileAccess.READ)
if not file:
push_error("Error opening ROM: " + rom_path)
push_error("[libretro_loader] Failed to open ROM: " + rom_path)
return false
print("ROM file opened successfully.")
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("[libretro_loader] Failed to load ROM: " + rom_path)
# Pass ROM data to the core
if not retro_host.core.load_game(rom_data):
push_error("[libretro_loader] Failed to load ROM into core: " + rom_path)
return false
print("[libretro_loader] ROM loaded successfully.")
@ -99,10 +104,23 @@ func _ready():
"""
print("[libretro_loader] _ready: Initializing SubViewport and TextureRect.")
if sub_viewport and texture_rect:
print("SubViewport and TextureRect initialized successfully.")
print("[libretro_loader] SubViewport and TextureRect initialized successfully.")
else:
push_error("Error: SubViewport or TextureRect is missing.")
return
if not retro_host:
push_error("[libretro_loader] RetroHost singleton not found! Emulation cannot proceed.")
return
print("[libretro_loader] RetroHost singleton initialized successfully.")
# Ensure SubViewport always renders
sub_viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
print("[libretro_loader] SubViewport set to always update.")
# Use await to call the coroutine
var success = await start_emulation("res://cores/genesis_plus_gx_libretro.so", "res://roms/megadrive/Sonic")
if success:
print("[libretro_loader] Emulation started successfully.")
else:
print("[libretro_loader] Failed to start emulation.")