Lots of work on several unrelated things.

This commit is contained in:
2025-03-28 23:31:44 -04:00
parent 3741470b20
commit b26d56048f
30 changed files with 444 additions and 612 deletions

View File

@@ -3,7 +3,7 @@
#include "LuprexGameModeBase.h"
#include "lpx-drvutil.hpp"
#include "lpx-paths.hpp"
#include "DebugPrint.h"
#include "ConsoleOutput.h"
#include "Tangible.h"
#include "TangibleManager.h"
#include "CommonTypes.h"
@@ -11,9 +11,11 @@
#include <string>
#include <string_view>
using namespace DebugPrint;
using namespace CommonTypes;
DEFINE_LOG_CATEGORY(LogLuprex);
DEFINE_LOG_CATEGORY(LogLuprexIntegration);
ALuprexGameModeBase::ALuprexGameModeBase()
{
TangibleManager = NewObject<UlxTangibleManager>();
@@ -24,7 +26,6 @@ ALuprexGameModeBase::ALuprexGameModeBase()
//PrimaryActorTick.TickGroup = TG_PrePhysics; // Probably wrong
SetActorTickEnabled(true);
SetActorTickInterval(0.0f);
DebugPrintControl::EnableCollection();
ResetToInitialState();
OnWorldPreActorTickHandle = FWorldDelegates::OnWorldPreActorTick.AddUObject(this, &ALuprexGameModeBase::OnWorldPreActorTick);
OnWorldPostActorTickHandle = FWorldDelegates::OnWorldPostActorTick.AddUObject(this, &ALuprexGameModeBase::OnWorldPostActorTick);
@@ -103,12 +104,6 @@ void ALuprexGameModeBase::UpdateConsoleOutput() {
ConsoleOutput.Append(lockedwrap.FetchStdout());
}
// Copy Debugging Prints into the console.
TArray<FString> prints = DebugPrintControl::GetStored();
for (const FString& fs : prints) {
ConsoleOutput.AppendLine(fs);
}
// If the Console text has changed, update the widget.
if (ConsoleOutput.IsDirty()) {
ConsoleSetOutput(ConsoleOutput.Get());
@@ -192,21 +187,7 @@ void ALuprexGameModeBase::LuaCallEnd(InvocationKind kind, AActor *place) {
}
void ALuprexGameModeBase::ExecuteDebuggingCommand(FlxLockedWrapper &w, const FString &fs) {
if (fs == "\\invokeplayer") {
DPrint(TEXT("Trying to invoke 'myfunction' in lua"));
FlxStreamBuffer &sb = LuaCallBegin();
sb.write_string("engio");
sb.write_string("myfunction");
sb.write_simple_dynamic_tag(SimpleDynamicTag::NUMBER);
sb.write_double(3.0);
sb.write_simple_dynamic_tag(SimpleDynamicTag::STRING);
sb.write_string("Howdy");
sb.write_simple_dynamic_tag(SimpleDynamicTag::VECTOR);
sb.write_fvector(FVector(2,3,4));
LuaCallEnd(InvocationKind::LUA_INVOKE);
} else {
ConsoleOutput.AppendLine(TEXT("Unknown Command"));
}
// Nothing here right now.
}
void ALuprexGameModeBase::ConsoleSendInput(const FString& fs)
@@ -262,16 +243,13 @@ void ALuprexGameModeBase::Tick(float deltaseconds)
void ALuprexGameModeBase::BeginPlay()
{
Super::BeginPlay();
// Make sure we're starting from a clean slate.
// Note: this claims the wrapper lock, so don't claim
// the lock before calling this.
ResetToInitialState();
InitializeGlobalState();
Super::BeginPlay();
}
// Now we're just going to claim the wrapper
// lock for the remainder. When we create the thread,
// the thread will hang until we release this lock.
void ALuprexGameModeBase::InitializeGlobalState()
{
FlxLockedWrapper w(LockableWrapper);
// Sanity checks. Make sure everything is clean.
@@ -284,7 +262,7 @@ void ALuprexGameModeBase::BeginPlay()
// If we failed to initialize the wrapper, print an error message.
if (w->play_initialize == nullptr)
{
DPrint("Luprex wrapper initialization failed");
UE_LOG(LogLuprexIntegration, Error, TEXT("Luprex wrapper initialization failed"));
}
// If wrapper is initialized, try to initialize the luprex engine.
@@ -294,7 +272,8 @@ void ALuprexGameModeBase::BeginPlay()
std::string srcpakerr = drvutil::package_lua_source(LUPREX_ROOT_PATH, &srcpak);
if (!srcpakerr.empty())
{
DPrint(srcpakerr.c_str());
FString FMessage((const UTF8CHAR *)(srcpakerr.c_str()));
UE_LOG(LogLuprexIntegration, Error, TEXT("Trying to read Lua source: %s"), *FMessage);
}
else
{
@@ -304,10 +283,11 @@ void ALuprexGameModeBase::BeginPlay()
w->play_initialize(w.Get(), 1, argv, srcpakv.size(), srcpakv.data(), "");
if (w->error[0])
{
DPrint(w->error);
FString FMessage((const UTF8CHAR *)w->error);
UE_LOG(LogLuprexIntegration, Error, TEXT("Calling Luprex play_initialize: %s"), *FMessage);
}
if (w->engine != nullptr) {
DPrint("Luprex initialize success");
UE_LOG(LogLuprexIntegration, Verbose, TEXT("Luprex initialization success."));
Playing = true;
}
}