More work on the LuaCall interface
This commit is contained in:
@@ -141,38 +141,32 @@ void AIntegrationGameModeBase::UpdateTangibles() {
|
||||
TangibleManager->DeleteFarawayTangibles();
|
||||
}
|
||||
|
||||
// void AIntegrationGameModeBase::InvokeEngioMove(const FString &action, const FVector &xyz, double facing) {
|
||||
// FTCHARToUTF8 utf8action(action);
|
||||
// std::string uaction(utf8action.Get(), utf8action.Length());
|
||||
// FlxStreamBuffer sb;
|
||||
// sb.write_string("engio");
|
||||
// sb.write_string("move");
|
||||
// sb.write_simple_dynamic_tag(SimpleDynamicTag::STRING);
|
||||
// sb.write_string(uaction);
|
||||
// sb.write_simple_dynamic_tag(SimpleDynamicTag::VECTOR);
|
||||
// sb.write_fvector(xyz);
|
||||
// sb.write_simple_dynamic_tag(SimpleDynamicTag::NUMBER);
|
||||
// sb.write_double(facing);
|
||||
// std::string_view datapk = sb.view();
|
||||
// FlxLockedWrapper w(LockableWrapper);
|
||||
// int64 player = w.GetActor();
|
||||
// w->play_call_function_lua_call(w.Get(), player, datapk.size(), datapk.data());
|
||||
// }
|
||||
|
||||
void AIntegrationGameModeBase::LuaCallInvoke(AActor *place) {
|
||||
void AIntegrationGameModeBase::LuaCallEnd(InvocationKind kind, int64 place_id) {
|
||||
std::string_view datapk = LuaCallBuffer.view();
|
||||
FlxLockedWrapper w(LockableWrapper);
|
||||
int64_t place_id = w.GetActor();
|
||||
if (place != nullptr) {
|
||||
place_id = UlxTangible::GetActorTangible(place)->TangibleId;
|
||||
if (place_id == 0) place_id = w.GetActor();
|
||||
uint32_t retpklen;
|
||||
const char *retpk;
|
||||
w->play_call_function(w.Get(), kind, place_id, datapk.size(), datapk.data(), &retpklen, &retpk);
|
||||
LuaCallResult.open(std::string_view(retpk, retpklen));
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::LuaCallEnd(InvocationKind kind) {
|
||||
LuaCallEnd(kind, int64(0));
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::LuaCallEnd(InvocationKind kind, AActor *place) {
|
||||
if (place == nullptr) {
|
||||
LuaCallEnd(kind, int64(0));
|
||||
} else {
|
||||
LuaCallEnd(kind, UlxTangible::GetActorTangible(place)->TangibleId);
|
||||
}
|
||||
w.PlayCallFunction(InvocationKind::LUA_CALL, place_id, datapk);
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::ExecuteDebuggingCommand(FlxLockedWrapper &w, const FString &fs) {
|
||||
if (fs == "\\invokeplayer") {
|
||||
DPrint(TEXT("Trying to invoke 'myfunction' in lua"));
|
||||
FlxStreamBuffer sb;
|
||||
FlxStreamBuffer &sb = LuaCallBegin();
|
||||
sb.write_string("engio");
|
||||
sb.write_string("myfunction");
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::NUMBER);
|
||||
@@ -181,9 +175,7 @@ void AIntegrationGameModeBase::ExecuteDebuggingCommand(FlxLockedWrapper &w, cons
|
||||
sb.write_string("Howdy");
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::VECTOR);
|
||||
sb.write_fvector(FVector(2,3,4));
|
||||
std::string_view datapk = sb.view();
|
||||
int64 player = w.GetActor();
|
||||
w.PlayCallFunction(InvocationKind::LUA_CALL, player, datapk);
|
||||
LuaCallEnd(InvocationKind::LUA_INVOKE);
|
||||
} else {
|
||||
ConsoleOutput.AppendLine(TEXT("Unknown Command"));
|
||||
}
|
||||
|
||||
@@ -46,14 +46,21 @@ public:
|
||||
// Assemble a lua call. To call into lua:
|
||||
//
|
||||
// * Use LuaCallBegin
|
||||
// * Get the lua call buffer.
|
||||
// * Add a class name and a function name to the buffer.
|
||||
// * Add parameters to the buffer.
|
||||
// * Use LuaCallInvoke.
|
||||
// * Get the lua call buffer:
|
||||
// - add a class name
|
||||
// - add a function name
|
||||
// - add function parameters
|
||||
// * Use LuaCallEnd.
|
||||
// * Get the lua call result.
|
||||
// - parse out any return values
|
||||
//
|
||||
void LuaCallBegin() { LuaCallBuffer.clear(); }
|
||||
FlxStreamBuffer &LuaCallBegin() { LuaCallBuffer.clear(); return LuaCallBuffer; }
|
||||
FlxStreamBuffer &LuaCallGetBuffer() { return LuaCallBuffer; }
|
||||
void LuaCallInvoke(AActor *place);
|
||||
void LuaCallEnd(InvocationKind kind);
|
||||
void LuaCallEnd(InvocationKind kind, int64 place_id);
|
||||
void LuaCallEnd(InvocationKind kind, AActor *place);
|
||||
FlxStreamBuffer &LuaCallGetResult() { return LuaCallResult; }
|
||||
void LuaCallClear() { LuaCallBuffer.clear(); LuaCallResult.clear(); }
|
||||
|
||||
// Execute a debugging command, typed on the GUI.
|
||||
void ExecuteDebuggingCommand(FlxLockedWrapper &w, const FString &fs);
|
||||
@@ -89,6 +96,7 @@ public:
|
||||
|
||||
// The Lua Call assembly buffer.
|
||||
FlxStreamBuffer LuaCallBuffer;
|
||||
FlxStreamBuffer LuaCallResult;
|
||||
|
||||
// This utility runs the luprex update and socket update in a thread.
|
||||
FTriggeredTask LuprexUpdateTask;
|
||||
|
||||
@@ -50,13 +50,6 @@ IdView FlxLockedWrapper::GetNear(int64 id, double rx, double ry, double rz) {
|
||||
return IdView(data, size);
|
||||
}
|
||||
|
||||
std::string_view FlxLockedWrapper::PlayCallFunction(InvocationKind kind, int64 place, std::string_view datapk) {
|
||||
uint32_t retpklen;
|
||||
const char *retpk;
|
||||
Lockable.Wrapper.play_call_function(Get(), kind, place, datapk.size(), datapk.data(), &retpklen, &retpk);
|
||||
return std::string_view(retpk, retpklen);
|
||||
}
|
||||
|
||||
StringViewVec FlxLockedWrapper::GetAnimationQueues(IdView ids) {
|
||||
// How many animation queues are we fetching?
|
||||
int num = ids.Num();
|
||||
|
||||
@@ -84,10 +84,6 @@ public:
|
||||
//
|
||||
IdView GetNear(int64 id, double rx, double ry, double rz);
|
||||
|
||||
// PlayCallFunction - a thin wrapper around play_call_function.
|
||||
//
|
||||
std::string_view PlayCallFunction(InvocationKind kind, int64 place, std::string_view datapk);
|
||||
|
||||
// Get animation queues.
|
||||
//
|
||||
// The array returned by this is valid until the
|
||||
|
||||
@@ -57,14 +57,13 @@ void UlxLuaCallLibrary::LuaCallInvoke(UObject *context, AActor *place) {
|
||||
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
CheckNotEmpty(sb);
|
||||
mode->LuaCallInvoke(place);
|
||||
mode->LuaCallEnd(InvocationKind::LUA_INVOKE, place);
|
||||
}
|
||||
|
||||
|
||||
void UlxLuaCallLibrary::InvokeEngioMove(UObject *context, const FString &action, const FVector &xyz, double facing) {
|
||||
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
mode->LuaCallBegin();
|
||||
FlxStreamBuffer &sb = mode->LuaCallBegin();
|
||||
sb.write_string("engio");
|
||||
sb.write_string("move");
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::STRING);
|
||||
@@ -73,5 +72,5 @@ void UlxLuaCallLibrary::InvokeEngioMove(UObject *context, const FString &action,
|
||||
sb.write_fvector(xyz);
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::NUMBER);
|
||||
sb.write_double(facing);
|
||||
mode->LuaCallInvoke(nullptr);
|
||||
mode->LuaCallEnd(InvocationKind::LUA_INVOKE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user