Lots of refactoring in IntegrationGameModeBase
This commit is contained in:
@@ -144,24 +144,6 @@ namespace DebugPrintControl {
|
|||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void FConsoleOutput::Append(const FString& text) {
|
|
||||||
if (!text.IsEmpty()) {
|
|
||||||
Content += text;
|
|
||||||
Truncate();
|
|
||||||
Dirty = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FConsoleOutput::AppendLine(const FString& text) {
|
|
||||||
int csize = Content.Len();
|
|
||||||
if ((csize > 0) && (Content[csize - 1] != '\n')) {
|
|
||||||
Content += TEXT("\n");
|
|
||||||
}
|
|
||||||
Content += text;
|
|
||||||
Content += TEXT("\n");
|
|
||||||
Truncate();
|
|
||||||
Dirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FConsoleOutput::Truncate() {
|
void FConsoleOutput::Truncate() {
|
||||||
int lines = 50;
|
int lines = 50;
|
||||||
@@ -178,3 +160,41 @@ void FConsoleOutput::Truncate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FConsoleOutput::MaybeAppendNewline() {
|
||||||
|
int csize = Content.Len();
|
||||||
|
if ((csize > 0) && (Content[csize - 1] != '\n')) {
|
||||||
|
Content += TEXT("\n");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FConsoleOutput::MaybeAppendText(const FString& text) {
|
||||||
|
if (!text.IsEmpty()) {
|
||||||
|
Content += text;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FConsoleOutput::Append(const FString& text) {
|
||||||
|
bool modified = MaybeAppendText(text);
|
||||||
|
if (modified) {
|
||||||
|
Dirty = true;
|
||||||
|
Truncate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FConsoleOutput::AppendLine(const FString& text) {
|
||||||
|
bool modified = MaybeAppendNewline();
|
||||||
|
modified |= MaybeAppendText(text);
|
||||||
|
modified |= MaybeAppendNewline();
|
||||||
|
if (modified) {
|
||||||
|
Dirty = true;
|
||||||
|
Truncate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -121,6 +121,13 @@ private:
|
|||||||
// Truncate the console to a reasonable number of
|
// Truncate the console to a reasonable number of
|
||||||
// lines. The length is hardwired.
|
// lines. The length is hardwired.
|
||||||
void Truncate();
|
void Truncate();
|
||||||
|
|
||||||
|
// Add a newline if there isn't one. Returns true if it changed anything.
|
||||||
|
bool MaybeAppendNewline();
|
||||||
|
|
||||||
|
// Append text. Returns true if it changed anything.
|
||||||
|
bool MaybeAppendText(const FString& text);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Append a line of text to the console.
|
// Append a line of text to the console.
|
||||||
void Append(const FString& text);
|
void Append(const FString& text);
|
||||||
|
|||||||
@@ -65,44 +65,42 @@ void AIntegrationGameModeBase::ResetToInitialState()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AIntegrationGameModeBase::HandleLuprexConsoleOutput(FLockedWrapper &w)
|
void AIntegrationGameModeBase::UpdateConsoleOutput() {
|
||||||
{
|
// Copy Luprex Stdout into the console.
|
||||||
uint32_t ndata; const char* data;
|
|
||||||
w->get_outgoing(w.Get(), 0, &ndata, &data);
|
|
||||||
if (ndata == 0) return;
|
|
||||||
std::string_view src(data, ndata);
|
|
||||||
int consumed;
|
|
||||||
std::u16string cps = drvutil::utf8_to_ucs2(src, &consumed);
|
|
||||||
w->play_sent_outgoing(w.Get(), 0, consumed);
|
|
||||||
FString fs(cps.size(), (const UCS2CHAR*)(&cps[0]));
|
|
||||||
ConsoleOutput.Append(fs);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AIntegrationGameModeBase::Tick(float DeltaSeconds)
|
|
||||||
{
|
|
||||||
Super::Tick(DeltaSeconds);
|
|
||||||
{
|
|
||||||
FLockedWrapper lockedwrap(LockableWrapper);
|
FLockedWrapper lockedwrap(LockableWrapper);
|
||||||
if (lockedwrap->engine != nullptr)
|
ConsoleOutput.Append(lockedwrap.FetchStdout());
|
||||||
{
|
|
||||||
EngineSeconds += DeltaSeconds;
|
// Copy Debugging Prints into the console.
|
||||||
HandleLuprexConsoleOutput(lockedwrap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TArray<FString> prints = DebugPrintControl::GetStored();
|
TArray<FString> prints = DebugPrintControl::GetStored();
|
||||||
for (const FString& fs : prints) {
|
for (const FString& fs : prints) {
|
||||||
ConsoleOutput.AppendLine(fs);
|
ConsoleOutput.AppendLine(fs);
|
||||||
}
|
}
|
||||||
if (ConsoleOutput.IsDirty())
|
|
||||||
{
|
// If the Console text has changed, update the widget.
|
||||||
|
if (ConsoleOutput.IsDirty()) {
|
||||||
ConsoleSetOutput(ConsoleOutput.Get());
|
ConsoleSetOutput(ConsoleOutput.Get());
|
||||||
ConsoleOutput.ClearDirty();
|
ConsoleOutput.ClearDirty();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AIntegrationGameModeBase::MaybeTriggerUpdateTask(float deltaseconds) {
|
||||||
|
FLockedWrapper lockedwrap(LockableWrapper);
|
||||||
|
if (lockedwrap->engine != nullptr)
|
||||||
|
{
|
||||||
|
EngineSeconds += deltaseconds;
|
||||||
if (EngineSeconds >= NextThreadTrigger)
|
if (EngineSeconds >= NextThreadTrigger)
|
||||||
{
|
{
|
||||||
LuprexUpdateTask.Trigger();
|
LuprexUpdateTask.Trigger();
|
||||||
NextThreadTrigger += 0.05;
|
NextThreadTrigger += 0.05;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AIntegrationGameModeBase::Tick(float deltaseconds)
|
||||||
|
{
|
||||||
|
Super::Tick(deltaseconds);
|
||||||
|
UpdateConsoleOutput();
|
||||||
|
MaybeTriggerUpdateTask(deltaseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AIntegrationGameModeBase::ConsoleSendInput(const FString& fs)
|
void AIntegrationGameModeBase::ConsoleSendInput(const FString& fs)
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ public:
|
|||||||
TSubclassOf<AActor> ClassTangibleActor;
|
TSubclassOf<AActor> ClassTangibleActor;
|
||||||
|
|
||||||
// Transfer console output from the Luprex engine to unreal.
|
// Transfer console output from the Luprex engine to unreal.
|
||||||
void HandleLuprexConsoleOutput(FLockedWrapper &w);
|
void UpdateConsoleOutput();
|
||||||
|
|
||||||
|
// Trigger the update task, if enough time has passed.
|
||||||
|
void MaybeTriggerUpdateTask(float deltaseconds);
|
||||||
|
|
||||||
// The run function is called by a background thread
|
// The run function is called by a background thread
|
||||||
// to update luprex sockets and update luprex itself.
|
// to update luprex sockets and update luprex itself.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include "LockedWrapper.h"
|
#include "LockedWrapper.h"
|
||||||
#include "DebugPrint.h"
|
#include "DebugPrint.h"
|
||||||
|
#include "drvutil.hpp"
|
||||||
|
|
||||||
void FLockedWrapper::InitWrapper() {
|
void FLockedWrapper::InitWrapper() {
|
||||||
if (Lockable.Wrapper.play_initialize != nullptr) {
|
if (Lockable.Wrapper.play_initialize != nullptr) {
|
||||||
@@ -17,3 +18,23 @@ void FLockedWrapper::InitWrapper() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FString FLockedWrapper::FetchStdout() {
|
||||||
|
if (Lockable.Wrapper.engine == nullptr) {
|
||||||
|
return FString();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ndata; const char* data;
|
||||||
|
Lockable.Wrapper.get_outgoing(Get(), 0, &ndata, &data);
|
||||||
|
|
||||||
|
if (ndata == 0) {
|
||||||
|
return FString();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string_view src(data, ndata);
|
||||||
|
int consumed;
|
||||||
|
std::u16string cps = drvutil::utf8_to_ucs2(src, &consumed);
|
||||||
|
Lockable.Wrapper.play_sent_outgoing(Get(), 0, consumed);
|
||||||
|
return FString(cps.size(), (const UCS2CHAR*)(&cps[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,9 +33,6 @@ public:
|
|||||||
Lockable.Mutex.Unlock();
|
Lockable.Mutex.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the engine wrapper if it's not already.
|
|
||||||
void InitWrapper();
|
|
||||||
|
|
||||||
// Operator right arrow accesses the EngineWrapper.
|
// Operator right arrow accesses the EngineWrapper.
|
||||||
EngineWrapper* operator ->() {
|
EngineWrapper* operator ->() {
|
||||||
return &Lockable.Wrapper;
|
return &Lockable.Wrapper;
|
||||||
@@ -47,4 +44,16 @@ public:
|
|||||||
EngineWrapper* Get() {
|
EngineWrapper* Get() {
|
||||||
return &Lockable.Wrapper;
|
return &Lockable.Wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize the engine wrapper if it's not already.
|
||||||
|
//
|
||||||
|
// All this does is open the DLL and hook up all
|
||||||
|
// the function pointers in the wrapper to point into
|
||||||
|
// the DLL.
|
||||||
|
//
|
||||||
|
void InitWrapper();
|
||||||
|
|
||||||
|
// Fetch Stdout as a string.
|
||||||
|
//
|
||||||
|
FString FetchStdout();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user