81 lines
1.7 KiB
C++
81 lines
1.7 KiB
C++
#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);
|
|
w->hook_dprint(engineutil::DPrintHook);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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;
|
|
|
|
void DPrint(const FString& fs) {
|
|
FScopeLock lk(&dprint_mutex);
|
|
dprint_array.Emplace(fs);
|
|
}
|
|
|
|
void DPrint(const char* msg) {
|
|
FScopeLock lk(&dprint_mutex);
|
|
dprint_array.Emplace(msg);
|
|
}
|
|
|
|
void DPrintHook(const char* msg, size_t len) {
|
|
FScopeLock lk(&dprint_mutex);
|
|
dprint_array.Emplace(len, (const UTF8CHAR*)msg);
|
|
}
|
|
|
|
TArray<FString> DPrintGetStored() {
|
|
FScopeLock lk(&dprint_mutex);
|
|
TArray<FString> result = std::move(dprint_array);
|
|
dprint_array.Empty();
|
|
return result;
|
|
}
|
|
|
|
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
|
|
|