Changed V7 to No V7

This commit is contained in:
2023-06-09 14:36:47 -04:00
parent 7fb8c5fefa
commit a436c20037
21 changed files with 27 additions and 65 deletions

View File

@@ -0,0 +1,23 @@
// Copyright Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
public class Integration : ModuleRules
{
public Integration(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
}

View File

@@ -0,0 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "Integration.h"
#include "Modules/ModuleManager.h"
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, Integration, "Integration" );

View File

@@ -0,0 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"

View File

@@ -0,0 +1,106 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "IntegrationGameModeBase.h"
#include "drvutil.hpp"
#include "engineutil.hpp"
#include <string>
#include <string_view>
EngineWrapper AIntegrationGameModeBase::Luprex;
//// Main loop.
//while (!engw.get_stop_driver(&engw)) {
// handle_lua_source();
// handle_console_output();
// handle_new_outgoing_sockets();
// handle_socket_input_output();
// handle_console_input();
// handle_console_output();
// engw.play_invoke_event_update(&engw, drvutil::get_monotonic_clock());
//}
AIntegrationGameModeBase::AIntegrationGameModeBase() {
//PrimaryActorTick.bCanEverTick = true; // Probably wrong
//PrimaryActorTick.bTickEvenWhenPaused = true; // Probably wrong
//PrimaryActorTick.TickGroup = TG_PrePhysics; // Probably wrong
SetActorTickEnabled(true); // Probably wrong
SetActorTickInterval(1.0f); // Probably wrong
}
void AIntegrationGameModeBase::HandleConsoleOutput() {
uint32_t ndata; const char* data;
Luprex.get_outgoing(&Luprex, 0, &ndata, &data);
if (ndata == 0) return;
std::string_view src(data, ndata);
int consumed;
std::u16string cps = drvutil::utf8_to_ucs2(src, &consumed);
Luprex.play_sent_outgoing(&Luprex, 0, consumed);
FString fs(cps.size(), (const UCS2CHAR*)(&cps[0]));
ConsoleOutput.Append(fs);
}
void AIntegrationGameModeBase::Tick(float DeltaSeconds) {
Super::Tick(DeltaSeconds);
if (!luprex_initialized()) {
return;
}
HandleConsoleOutput();
if (Luprex.engine) {
EngineSeconds += DeltaSeconds;
Luprex.play_invoke_event_update(&Luprex, EngineSeconds);
}
for (const FString& fs : engineutil::DPrintGetStored()) {
ConsoleOutput.AppendLine(fs);
}
engineutil::DPrintClearStored();
if (ConsoleOutput.IsDirty()) {
ConsoleSetOutput(ConsoleOutput.Get());
ConsoleOutput.ClearDirty();
}
}
void AIntegrationGameModeBase::ConsoleSendInput(const FString& fs) {
if (Luprex.engine) {
const TCHAR* fstchar = *fs;
if (sizeof(TCHAR) == 2) {
ConsoleOutput.AppendLine(FString("> ") + fs);
std::u16string_view fsview((const char16_t*)fstchar, fs.Len());
std::string utf8 = drvutil::utf16_to_utf8(fsview);
utf8 = utf8 + "\n";
Luprex.play_recv_incoming(&Luprex, 0, utf8.size(), utf8.c_str());
}
}
}
void AIntegrationGameModeBase::BeginPlay() {
Super::BeginPlay();
if (!luprex_initialized()) {
engineutil::init_wrapper(&Luprex);
if (!luprex_initialized()) {
engineutil::DPrint("Luprex wrapper initialization failed");
return;
}
}
Luprex.release(&Luprex);
Luprex.hook_dprint(engineutil::DPrintHook);
drvutil::ostringstream srcpak;
std::string srcpakerr = drvutil::package_lua_source("c:\\Luprex", &srcpak);
if (!srcpakerr.empty()) {
engineutil::DPrint(srcpakerr.c_str());
}
std::string_view srcpakv = srcpak.view();
char* argv[1];
argv[0] = const_cast<char*>("lpxserver");
Luprex.play_initialize(&Luprex, 1, argv, srcpakv.size(), srcpakv.data(), "");
if (Luprex.error[0]) {
ConsoleOutput.AppendLine(FString(Luprex.error));
} else {
ConsoleOutput.AppendLine(FString("Initialize Luprex Success"));
}
EngineSeconds = 0;
}

View File

@@ -0,0 +1,41 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "enginewrapper.hpp"
#include "engineutil.hpp"
#include "IntegrationGameModeBase.generated.h"
/**
*
*/
UCLASS()
class INTEGRATION_API AIntegrationGameModeBase : public AGameModeBase
{
GENERATED_BODY()
public:
AIntegrationGameModeBase();
virtual void BeginPlay() override;
virtual void Tick(float) override;
inline bool luprex_initialized() {
return Luprex.play_initialize != nullptr;
}
// Set the entire contents of the console output box.
UFUNCTION(BlueprintImplementableEvent)
void ConsoleSetOutput(const FString& text);
UFUNCTION(BlueprintCallable)
void ConsoleSendInput(const FString& text);
void HandleConsoleOutput();
// Refresh the console output.
engineutil::ConsoleOutput ConsoleOutput;
static EngineWrapper Luprex;
float EngineSeconds;
};

View File

@@ -0,0 +1,17 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyLuprexGameStateBase.h"
static void printq(const char* msg) {
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString(msg));
}
void AMyLuprexGameStateBase::Tick(float DeltaSeconds) {
printq("Tick");
}
void AMyLuprexGameStateBase::BeginPlay() {
printq("AMyLuprexGameStateBase OK");
}

View File

@@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameStateBase.h"
#include "MyLuprexGameStateBase.generated.h"
/**
*
*/
UCLASS()
class INTEGRATION_API AMyLuprexGameStateBase : public AGameStateBase
{
GENERATED_BODY()
public:
virtual void BeginPlay() override;
virtual void Tick(float) override;
};

View File

@@ -0,0 +1 @@
#include "c:/luprex/cpp/drv/drvutil.cpp"

View File

@@ -0,0 +1 @@
#include "c:/luprex/cpp/drv/drvutil.hpp"

View File

@@ -0,0 +1,75 @@
#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);
}
}
}
static TArray<FString> dprints;
void DPrint(const FString& fs) {
dprints.Emplace(fs);
}
void DPrint(const char* msg) {
dprints.Emplace(msg);
}
void DPrintHook(const char* msg, size_t len) {
dprints.Emplace(len, (const UTF8CHAR*)msg);
}
const TArray<FString>& DPrintGetStored() {
return dprints;
}
void DPrintClearStored() {
dprints.Reset();
}
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

View File

@@ -0,0 +1,50 @@
#pragma once
#include "enginewrapper.hpp"
namespace engineutil {
// Load the DLL and initialize the wrapper, if possible.
void init_wrapper(EngineWrapper* w);
// Print text on the console.
void DPrint(const FString& fs);
// Print text on the console.
void DPrint(const char* msg);
// Print text on the console.
void DPrintHook(const char* msg, size_t len);
// Get all the stored dprints.
const TArray<FString>& DPrintGetStored();
// Clear the stored dprints.
void DPrintClearStored();
class ConsoleOutput {
private:
FString Content;
bool Dirty;
// Truncate the console to a reasonable number of
// lines. The length is hardwired.
void Truncate();
public:
// Append a line of text to the console.
void Append(const FString& text);
// Append a line of text to the console on a line by itself.
void AppendLine(const FString& text);
// Get the console text as a string.
const FString& Get() const { return Content; }
// Return if the dirty flag is set.
bool IsDirty() const { return Dirty; }
// Clear the dirty flag.
void ClearDirty() { Dirty = false; }
};
} // namespace engineutil

View File

@@ -0,0 +1 @@
#include "c:/luprex/cpp/core/enginewrapper.hpp"