Files
integration/Source/Integration/engineutil.cpp

81 lines
1.7 KiB
C++
Raw Normal View History

2023-06-08 17:10:14 -04:00
#include "CoreMinimal.h"
#include "engineutil.hpp"
namespace engineutil {
void init_wrapper(EngineWrapper* w) {
void* DLL = FPlatformProcess::GetDllHandle(TEXT("c:\\Luprex\\build\\visual\\luprexlib.dll"));
if (DLL != nullptr) {
using InitFn = void (*)(EngineWrapper*);
InitFn init = (InitFn)FPlatformProcess::GetDllExport(DLL, TEXT("init_engine_wrapper"));
if (init != nullptr) {
init(w);
2023-06-23 16:27:23 -04:00
w->hook_dprint(engineutil::DPrintHook);
2023-06-08 17:10:14 -04:00
}
}
}
// The DPrint array. This stores the dprints
// until they can be collected by the console implementation.
static TArray<FString> dprint_array;
static FCriticalSection dprint_mutex;
2023-06-08 17:10:14 -04:00
void DPrint(const FString& fs) {
FScopeLock lk(&dprint_mutex);
dprint_array.Emplace(fs);
2023-06-08 17:10:14 -04:00
}
void DPrint(const char* msg) {
FScopeLock lk(&dprint_mutex);
dprint_array.Emplace(msg);
2023-06-08 17:10:14 -04:00
}
void DPrintHook(const char* msg, size_t len) {
FScopeLock lk(&dprint_mutex);
dprint_array.Emplace(len, (const UTF8CHAR*)msg);
2023-06-08 17:10:14 -04:00
}
TArray<FString> DPrintGetStored() {
FScopeLock lk(&dprint_mutex);
TArray<FString> result = std::move(dprint_array);
dprint_array.Empty();
return result;
2023-06-08 17:10:14 -04:00
}
void ConsoleOutput::Append(const FString& text) {
if (!text.IsEmpty()) {
Content += text;
Truncate();
Dirty = true;
}
}
void ConsoleOutput::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 ConsoleOutput::Truncate() {
int lines = 50;
int csize = Content.Len();
int total = 0;
for (int i = csize - 1; i >= 0; i--) {
if (Content[i] == '\n') {
total += 1;
if (total == lines) {
Content = Content.RightChop(i + 1);
return;
}
}
}
}
} // namespace engineutil