Refactoring to move things from GameMode into UlxEngineWrapper subsystem.

This commit is contained in:
2026-02-27 17:00:46 -05:00
parent 0aea1e0798
commit 7bb4854844
6 changed files with 99 additions and 119 deletions

View File

@@ -1,6 +1,6 @@
#include "LuaCall.h"
#include "LuprexGameModeBase.h"
#include "LockedWrapper.h"
#include "Tangible.h"
#include "StreamBuffer.h"
@@ -199,8 +199,7 @@ FString UlxLuaCallLibrary::AllFunctionsWithPrefix(const TCHAR *Prefix)
void UlxLuaCallLibrary::InvokeLuaExpr(UObject *context, const FString &Code)
{
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
FlxLockedWrapper w(mode->GetLockableWrapper());
FlxLockedWrapper w;
w.InvokeLuaExpr(Code);
}
@@ -218,8 +217,7 @@ static int64 ResolvePlaceId(AActor *place)
void UlxLuaCallLibrary::LuaCallBegin(UObject *context, const FString &cname, const FString &fname)
{
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
FlxStreamBuffer &sb = UlxEngineWrapper::GetLuaCallBuffer();
sb.clear();
sb.write_string(cname);
sb.write_string(fname);
@@ -227,29 +225,27 @@ void UlxLuaCallLibrary::LuaCallBegin(UObject *context, const FString &cname, con
void UlxLuaCallLibrary::LuaCallInvoke(UObject *context, AActor *place)
{
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
FlxStreamBuffer &sb = UlxEngineWrapper::GetLuaCallBuffer();
if (NotInitialized(sb)) return;
int64 place_id = ResolvePlaceId(place);
if (place_id < 0) { sb.clear(); return; }
FlxLockedWrapper w(mode->GetLockableWrapper());
FlxLockedWrapper w;
w.InvokeLuaFunction(sb.view(), place_id);
sb.clear();
}
bool UlxLuaCallLibrary::LuaCallProbe(UObject *context, AActor *place, UlxLuaValues *&ReturnArray)
{
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
FlxStreamBuffer &sb = UlxEngineWrapper::GetLuaCallBuffer();
if (NotInitialized(sb)) return false;
int64 place_id = ResolvePlaceId(place);
if (place_id < 0) {
sb.clear();
ReturnArray = NewObject<UlxLuaValues>(mode);
ReturnArray = NewObject<UlxLuaValues>();
return false;
}
ReturnArray = NewObject<UlxLuaValues>(mode);
FlxLockedWrapper w(mode->GetLockableWrapper());
ReturnArray = NewObject<UlxLuaValues>();
FlxLockedWrapper w;
w.ProbeLuaFunction(sb.view(), place_id, [&](std::string_view retpk) {
ReturnArray->Initialize(retpk);
});
@@ -285,8 +281,7 @@ bool UlxLuaCallLibrary::LuaCallProbe(UObject *context, AActor *place, UlxLuaValu
/////////////////////////////////////////////////////////////////
void UlxLuaCallLibrary::LuaCallArgument_string(UObject *context, const FString &pstring) {
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
FlxStreamBuffer &sb = UlxEngineWrapper::GetLuaCallBuffer();
if (NotInitialized(sb)) return;
sb.write_lua_value_type(LuaValueType::STRING);
sb.write_string(pstring);
@@ -300,40 +295,35 @@ void UlxLuaCallLibrary::LuaCallArgument_name(UObject *context, const FName &pnam
{
UE_LOG(LogBlueprint, Error, TEXT("Names passed to lua must be short, and must contain only lowercase and digits"));
}
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
FlxStreamBuffer &sb = UlxEngineWrapper::GetLuaCallBuffer();
if (NotInitialized(sb)) return;
sb.write_lua_value_type(LuaValueType::TOKEN);
sb.write_string(namestr);
}
void UlxLuaCallLibrary::LuaCallArgument_float(UObject *context, double pfloat) {
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
FlxStreamBuffer &sb = UlxEngineWrapper::GetLuaCallBuffer();
if (NotInitialized(sb)) return;
sb.write_lua_value_type(LuaValueType::NUMBER);
sb.write_double(pfloat);
}
void UlxLuaCallLibrary::LuaCallArgument_int(UObject *context, int value) {
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
FlxStreamBuffer &sb = UlxEngineWrapper::GetLuaCallBuffer();
if (NotInitialized(sb)) return;
sb.write_lua_value_type(LuaValueType::NUMBER);
sb.write_double(value);
}
void UlxLuaCallLibrary::LuaCallArgument_vector(UObject *context, const FVector &pvector) {
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
FlxStreamBuffer &sb = UlxEngineWrapper::GetLuaCallBuffer();
if (NotInitialized(sb)) return;
sb.write_lua_value_type(LuaValueType::VECTOR);
sb.write_fvector(pvector);
}
void UlxLuaCallLibrary::LuaCallArgument_vector2d(UObject *context, const FVector2D &pvector) {
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
FlxStreamBuffer &sb = UlxEngineWrapper::GetLuaCallBuffer();
if (NotInitialized(sb)) return;
sb.write_lua_value_type(LuaValueType::VECTOR);
sb.write_double(pvector.X);
@@ -342,8 +332,7 @@ void UlxLuaCallLibrary::LuaCallArgument_vector2d(UObject *context, const FVector
}
void UlxLuaCallLibrary::LuaCallArgument_boolean(UObject *context, bool pbool) {
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
FlxStreamBuffer &sb = UlxEngineWrapper::GetLuaCallBuffer();
if (NotInitialized(sb)) return;
sb.write_lua_value_type(LuaValueType::BOOLEAN);
sb.write_bool(pbool);