Refactor code for invoke_lua_source and world.init. Also, add compile_commands.json to luprex

This commit is contained in:
2025-06-16 19:58:26 -04:00
parent f150b14d30
commit 80ff7d7d92
14 changed files with 279 additions and 331 deletions

View File

@@ -54,6 +54,21 @@ ALuprexGameModeBase::~ALuprexGameModeBase()
//
uint32 ALuprexGameModeBase::Run() {
FlxLockedWrapper lockedwrap(LockableWrapper);
if (lockedwrap->get_rescan_lua_source(lockedwrap.Get()))
{
drvutil::ostringstream srcpak;
std::string srcpakerr = drvutil::package_lua_source(LUPREX_ROOT_PATH, &srcpak);
if (!srcpakerr.empty())
{
FString FMessage((const UTF8CHAR *)(srcpakerr.c_str()));
UE_LOG(LogLuprexIntegration, Error, TEXT("Trying to read Lua source: %s"), *FMessage);
}
else
{
std::string_view srcpakv = srcpak.view();
lockedwrap->play_access(lockedwrap.Get(), AccessKind::INVOKE_LUA_SOURCE, 0, srcpakv.size(), srcpakv.data(), nullptr, nullptr);
}
}
Sockets->Update(lockedwrap);
lockedwrap->play_update(lockedwrap.Get(), EngineSeconds);
Sockets->Update(lockedwrap);
@@ -290,28 +305,15 @@ void ALuprexGameModeBase::InitializeGlobalState()
// If wrapper is initialized, try to initialize the luprex engine.
if (w->play_initialize != nullptr)
{
drvutil::ostringstream srcpak;
std::string srcpakerr = drvutil::package_lua_source(LUPREX_ROOT_PATH, &srcpak);
if (!srcpakerr.empty())
w->play_initialize(w.Get(), "lpxclient", "");
if (w->error[0])
{
FString FMessage((const UTF8CHAR *)(srcpakerr.c_str()));
UE_LOG(LogLuprexIntegration, Error, TEXT("Trying to read Lua source: %s"), *FMessage);
FString FMessage((const UTF8CHAR *)w->error);
UE_LOG(LogLuprexIntegration, Error, TEXT("Calling Luprex play_initialize: %s"), *FMessage);
}
else
{
std::string_view srcpakv = srcpak.view();
char* argv[1];
argv[0] = const_cast<char*>("lpxclient");
w->play_initialize(w.Get(), 1, argv, srcpakv.size(), srcpakv.data(), "");
if (w->error[0])
{
FString FMessage((const UTF8CHAR *)w->error);
UE_LOG(LogLuprexIntegration, Error, TEXT("Calling Luprex play_initialize: %s"), *FMessage);
}
if (w->engine != nullptr) {
UE_LOG(LogLuprexIntegration, Verbose, TEXT("Luprex initialization success."));
Playing = true;
}
if (w->engine != nullptr) {
UE_LOG(LogLuprexIntegration, Verbose, TEXT("Luprex initialization success."));
Playing = true;
}
}