Added blank worker thread
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "IntegrationGameModeBase.h"
|
||||
#include "drvutil.hpp"
|
||||
#include "engineutil.hpp"
|
||||
#include "WorkerRunnable.hpp"
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
@@ -21,7 +22,10 @@ EngineWrapper AIntegrationGameModeBase::Luprex;
|
||||
// engw.play_invoke_event_update(&engw, drvutil::get_monotonic_clock());
|
||||
//}
|
||||
|
||||
AIntegrationGameModeBase::AIntegrationGameModeBase() {
|
||||
AIntegrationGameModeBase::AIntegrationGameModeBase()
|
||||
{
|
||||
Worker = nullptr;
|
||||
Thread = nullptr;
|
||||
//PrimaryActorTick.bCanEverTick = true; // Probably wrong
|
||||
//PrimaryActorTick.bTickEvenWhenPaused = true; // Probably wrong
|
||||
//PrimaryActorTick.TickGroup = TG_PrePhysics; // Probably wrong
|
||||
@@ -29,7 +33,8 @@ AIntegrationGameModeBase::AIntegrationGameModeBase() {
|
||||
SetActorTickInterval(1.0f); // Probably wrong
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::HandleConsoleOutput() {
|
||||
void AIntegrationGameModeBase::HandleConsoleOutput()
|
||||
{
|
||||
uint32_t ndata; const char* data;
|
||||
Luprex.get_outgoing(&Luprex, 0, &ndata, &data);
|
||||
if (ndata == 0) return;
|
||||
@@ -41,7 +46,19 @@ void AIntegrationGameModeBase::HandleConsoleOutput() {
|
||||
ConsoleOutput.Append(fs);
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::Tick(float DeltaSeconds) {
|
||||
void AIntegrationGameModeBase::WaitForWorkerThread()
|
||||
{
|
||||
if (Thread == nullptr) return;
|
||||
//Worker->Stop();
|
||||
//Thread->WaitForCompletion();
|
||||
delete Thread;
|
||||
delete Worker;
|
||||
Worker = nullptr;
|
||||
Thread = nullptr;
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::Tick(float DeltaSeconds)
|
||||
{
|
||||
Super::Tick(DeltaSeconds);
|
||||
if (!luprex_initialized()) {
|
||||
return;
|
||||
@@ -61,7 +78,8 @@ void AIntegrationGameModeBase::Tick(float DeltaSeconds) {
|
||||
}
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::ConsoleSendInput(const FString& fs) {
|
||||
void AIntegrationGameModeBase::ConsoleSendInput(const FString& fs)
|
||||
{
|
||||
if (Luprex.engine) {
|
||||
const TCHAR* fstchar = *fs;
|
||||
if (sizeof(TCHAR) == 2) {
|
||||
@@ -74,7 +92,9 @@ void AIntegrationGameModeBase::ConsoleSendInput(const FString& fs) {
|
||||
}
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::BeginPlay() {
|
||||
void AIntegrationGameModeBase::BeginPlay()
|
||||
{
|
||||
engineutil::RawPrint("In BeginPlay");
|
||||
Super::BeginPlay();
|
||||
if (!luprex_initialized()) {
|
||||
engineutil::init_wrapper(&Luprex);
|
||||
@@ -102,5 +122,16 @@ void AIntegrationGameModeBase::BeginPlay() {
|
||||
ConsoleOutput.AppendLine(FString("Initialize Luprex Success"));
|
||||
}
|
||||
EngineSeconds = 0;
|
||||
|
||||
if (Thread == nullptr) {
|
||||
Worker = new FWorkerRunnable();
|
||||
Thread = FRunnableThread::Create(Worker, TEXT("Worker Thread"));
|
||||
}
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::EndPlay(const EEndPlayReason::Type EndPlayReason) {
|
||||
engineutil::RawPrint("In EndPlay");
|
||||
WaitForWorkerThread();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "GameFramework/GameModeBase.h"
|
||||
#include "enginewrapper.hpp"
|
||||
#include "engineutil.hpp"
|
||||
#include "WorkerRunnable.hpp"
|
||||
#include "IntegrationGameModeBase.generated.h"
|
||||
|
||||
/**
|
||||
@@ -20,6 +21,7 @@ public:
|
||||
AIntegrationGameModeBase();
|
||||
virtual void BeginPlay() override;
|
||||
virtual void Tick(float) override;
|
||||
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason);
|
||||
|
||||
inline bool luprex_initialized() {
|
||||
return Luprex.play_initialize != nullptr;
|
||||
@@ -34,7 +36,11 @@ public:
|
||||
|
||||
void HandleConsoleOutput();
|
||||
|
||||
void WaitForWorkerThread();
|
||||
|
||||
// Refresh the console output.
|
||||
FWorkerRunnable* Worker;
|
||||
FRunnableThread* Thread;
|
||||
engineutil::ConsoleOutput ConsoleOutput;
|
||||
static EngineWrapper Luprex;
|
||||
float EngineSeconds;
|
||||
|
||||
26
Source/Integration/WorkerRunnable.cpp
Normal file
26
Source/Integration/WorkerRunnable.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
#include "WorkerRunnable.hpp"
|
||||
#include "engineutil.hpp"
|
||||
|
||||
|
||||
bool FWorkerRunnable::Init()
|
||||
{
|
||||
engineutil::RawPrint("WorkerRunnable::Init");
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32 FWorkerRunnable::Run()
|
||||
{
|
||||
while (!StopRequested)
|
||||
{
|
||||
engineutil::RawPrint("WorkerRunnable::Run");
|
||||
FPlatformProcess::Sleep(1.0);
|
||||
}
|
||||
engineutil::RawPrint("WorkerRunnable Done");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FWorkerRunnable::Stop()
|
||||
{
|
||||
StopRequested = true;
|
||||
}
|
||||
15
Source/Integration/WorkerRunnable.hpp
Normal file
15
Source/Integration/WorkerRunnable.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
class FWorkerRunnable : public FRunnable
|
||||
{
|
||||
public:
|
||||
FWorkerRunnable() : StopRequested(false) {}
|
||||
virtual bool Init() override;
|
||||
virtual uint32 Run() override;
|
||||
virtual void Stop() override;
|
||||
private:
|
||||
bool StopRequested;
|
||||
};
|
||||
|
||||
@@ -14,6 +14,14 @@ void init_wrapper(EngineWrapper* w) {
|
||||
}
|
||||
}
|
||||
|
||||
// Print text using GEngine->Add...
|
||||
void RawPrint(const char* text) {
|
||||
if (GEngine)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString(text));
|
||||
}
|
||||
}
|
||||
|
||||
static TArray<FString> dprints;
|
||||
|
||||
void DPrint(const FString& fs) {
|
||||
|
||||
@@ -6,6 +6,9 @@ namespace engineutil {
|
||||
// Load the DLL and initialize the wrapper, if possible.
|
||||
void init_wrapper(EngineWrapper* w);
|
||||
|
||||
// Print text using GEngine->Add...
|
||||
void RawPrint(const char* text);
|
||||
|
||||
// Print text on the console.
|
||||
void DPrint(const FString& fs);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user