upd streetlamp, light, dof, c++ xml parse

This commit is contained in:
2025-09-23 19:37:20 +05:00
parent 7c44a75599
commit 2a6b4c1846
32 changed files with 1002 additions and 35 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ public class GraffModule : ModuleRules
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore","UMG" });
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore","UMG", "EasyXMLParser" });
PrivateDependencyModuleNames.AddRange(new string[] { });
+121 -2
View File
@@ -6,10 +6,12 @@
#include "Misc/paths.h"
#include "Engine/levelstreamingdynamic.h"
#include "cppFuncLibrary.h"
#include "Misc/FileHelper.h"
#include "Async/Async.h"
/*for working tarray::Contains*/
bool operator==(const Fcppcoords& c1, const Fcppcoords& c2) {
static bool operator==(const Fcppcoords& c1, const Fcppcoords& c2) {
return c1.flat == c2.flat &&
c1.floor == c2.floor &&
c1.house == c2.house &&
@@ -18,7 +20,7 @@ bool operator==(const Fcppcoords& c1, const Fcppcoords& c2) {
c1.zone == c2.zone;
}
/*for working tarray::Contains*/
bool operator==(const FcppLevelStruct& c1, const FcppLevelStruct& c2) {
static bool operator==(const FcppLevelStruct& c1, const FcppLevelStruct& c2) {
return c1.anotherLvl == c2.anotherLvl &&
c1.coords == c2.coords &&
c1.dontUnload == c2.dontUnload &&
@@ -27,6 +29,8 @@ bool operator==(const FcppLevelStruct& c1, const FcppLevelStruct& c2) {
c1.Z == c2.Z;
}
TArray<ULevelStreaming*> UcppGI::cppLvlManage(UObject* WorldContextObject, Fcppcoords currentCoords, uint8 currentState)
{
TArray<ULevelStreaming*> outStruct;
@@ -235,4 +239,119 @@ void UcppGI::cppCoordsToCppFlat(UObject* WorldContextObject, Fcppcoords coords,
flat = StaticCastPtr<UcppGI, UGameInstance>(UGameplayStatics::GetGameInstance(WorldContextObject))->findFlatByCoords_(coords, dum);
}
void UcppGI::cpp_parseXmlAsync(UObject* WorldContextObject, const TMap<int32, FIntPoint>& houseIds, FLatentActionInfo LatentInfo) {
UWorld* World = WorldContextObject ? WorldContextObject->GetWorld() : nullptr;
if (!World) return;
struct FParseXmlLatent : public FPendingLatentAction {
FName ExecutionFunction;
int32 OutputLink;
FWeakObjectPtr CallbackTarget;
bool bDone = false;
FParseXmlLatent(const FLatentActionInfo& Info)
: ExecutionFunction(Info.ExecutionFunction)
, OutputLink(Info.Linkage)
, CallbackTarget(Info.CallbackTarget) {}
virtual void UpdateOperation(FLatentResponse& Response) override {
Response.FinishAndTriggerIf(bDone, ExecutionFunction, OutputLink, CallbackTarget);
}
};
FParseXmlLatent* Action = new FParseXmlLatent(LatentInfo);
World->GetLatentActionManager().AddNewAction(LatentInfo.CallbackTarget, LatentInfo.UUID, Action);
Async(EAsyncExecution::ThreadPool, [this, houseIds, Action]() {
EEasyXMLParserFound fou;
EEasyXMLParserErrorCode er;
FString er1;
auto xfile = UEasyXMLParseManager::LoadFromFile(FPaths::ProjectSavedDir() + FString("flatdata.xml"), true, er, er1);
if (!xfile) { AsyncTask(ENamedThreads::GameThread, [Action]() { Action->bDone = true; }); return; }
auto offers = xfile->ReadElements(FString("realty-feed.offer"), fou);
if (fou != EEasyXMLParserFound::Found) { AsyncTask(ENamedThreads::GameThread, [Action]() { Action->bDone = true; }); return; }
TMap<FIntPoint, int32> flatKeyToOfferIdx;
flatKeyToOfferIdx.Reserve(offers.Num());
for (int32 i = 0; i < offers.Num(); ++i) {
auto& offer = offers[i];
const int32 houseId = offer->ReadInt(FString("yandex-house-id"), 0);
if (const FIntPoint* housePoint = houseIds.Find(houseId)) {
const int32 apartment = offer->ReadInt(FString("location.apartment"), 0);
flatKeyToOfferIdx.Add({ housePoint->X, apartment }, i);
}
}
struct FFlatUpdate { int32 Index; int32 Price; float Square; bool Available; FIntPoint Deadline; };
TArray<FFlatUpdate> updates;
updates.Reserve(flatArray.Num());
for (int32 idx = 0; idx < flatArray.Num(); ++idx) {
const auto& flat = flatArray[idx];
const int32* xmlFlatIdPtr = flatKeyToOfferIdx.Find({ flat.Zone, flat.FlatN });
if (!xmlFlatIdPtr) continue;
const int32 xmlFlatId = *xmlFlatIdPtr;
auto& xf = offers[xmlFlatId];
FFlatUpdate u;
u.Index = idx;
u.Price = xf->ReadInt(FString("price.value"), 0);
u.Square = xf->ReadFloat(FString("area.value"), 0);
u.Available = true;
u.Deadline = { xf->ReadInt(FString("ready-quarter"), 0), xf->ReadInt(FString("built-year"), 0) };
updates.Add(MoveTemp(u));
}
AsyncTask(ENamedThreads::GameThread, [this, Action, updates = MoveTemp(updates)]() mutable {
for (const auto& u : updates) {
if (!flatArray.IsValidIndex(u.Index)) continue;
auto& flat = flatArray[u.Index];
flat.Price = u.Price;
if (u.Square) flat.Square = u.Square;
flat.available = u.Available;
flat.deadline = u.Deadline;
flat.price_meter = (flat.Price && flat.Square) ? flat.Price / flat.Square : 0;
}
Action->bDone = true;
});
});
}
void UcppGI::fixXmlAsync(UObject* WorldContextObject, FString xmlPath, FLatentActionInfo LatentInfo) {
UWorld* World = WorldContextObject ? WorldContextObject->GetWorld() : nullptr;
if (!World) return;
struct FFixXmlLatent : public FPendingLatentAction {
FName ExecutionFunction;
int32 OutputLink;
FWeakObjectPtr CallbackTarget;
bool bDone = false;
FFixXmlLatent(const FLatentActionInfo& Info)
: ExecutionFunction(Info.ExecutionFunction)
, OutputLink(Info.Linkage)
, CallbackTarget(Info.CallbackTarget) {}
virtual void UpdateOperation(FLatentResponse& Response) override {
Response.FinishAndTriggerIf(bDone, ExecutionFunction, OutputLink, CallbackTarget);
}
};
FFixXmlLatent* Action = new FFixXmlLatent(LatentInfo);
World->GetLatentActionManager().AddNewAction(LatentInfo.CallbackTarget, LatentInfo.UUID, Action);
Async(EAsyncExecution::ThreadPool, [Action, xmlPath]() {
FString xml;
FFileHelper::LoadFileToString(xml, *xmlPath);
xml.ReplaceInline(L"><!", L">");
xml.ReplaceInline(L"]><", L"]<");
FFileHelper::SaveStringToFile(xml, *xmlPath);
AsyncTask(ENamedThreads::GameThread, [Action]() {
Action->bDone = true;
});
});
}
+7
View File
@@ -4,6 +4,8 @@
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "EasyXMLElement.h"
#include "EasyXMLParseManager.h"
#include "cppGI.generated.h"
/**
@@ -93,6 +95,11 @@ public:
UFUNCTION(blueprintcallable, blueprintPure, category = "Data", meta = (WorldContext = "WorldContextObject", BlueprintAutocast))
static void cppCoordsToCppFlat(UObject* WorldContextObject, Fcppcoords coords, FcppflatStruct& flat, bool onlyCoords = true);
UFUNCTION(blueprintcallable, meta=(WorldContext = "WorldContextObject", Latent, LatentInfo="LatentInfo"), category = "Data")
void cpp_parseXmlAsync(UObject* WorldContextObject, const TMap<int32, FIntPoint>& houseIds, struct FLatentActionInfo LatentInfo);
UFUNCTION(blueprintcallable, meta=(WorldContext = "WorldContextObject", Latent, LatentInfo="LatentInfo"), category = "Data")
void fixXmlAsync(UObject* WorldContextObject, FString xmlPath, struct FLatentActionInfo LatentInfo);
/*list of lvls for anyway loading*/
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "levelLoading")