Files
SibIntel1/Source/MasharovDev/cppGI.cpp
T

113 lines
3.8 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "cppGI.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/levelstreamingdynamic.h"
/*for working tarray::Contains*/
bool operator==(const Fcppcoords& c1, const Fcppcoords& c2) {
return c1.flat == c2.flat &&
c1.floor == c2.floor &&
c1.house == c2.house &&
c1.section == c2.section &&
c1.type == c2.type &&
c1.zone == c2.zone;
}
void UcppGI::cppLvlManage(UObject* WorldContextObject, Fcppcoords currentCoords, uint8 currentState, TArray<ULevelStreaming*>& Levelss)
{
bool loadthis = false;
int32 temp1[5] = { currentCoords.flat,currentCoords.zone,currentCoords.house,currentCoords.section,currentCoords.floor };
/*complete lvls for loading*/
for (auto& lvl : cpplvlsForLoading) {
int32* temp[5] = { &lvl.flat,&lvl.zone,&lvl.house,&lvl.section,&lvl.floor };
int8 n = 0;
for (auto i : temp) {
if (*i == -2) *i = temp1[n];
n++;
}
}
cpplvlsForLoading.AddUnique(currentCoords);
for (auto& lvl : cpplevelLIst) {
if (currentCoords.floor == 100);
else {
loadthis = false;
for (auto& lvl1 : cpplvlsForLoading) {
bool ceq[6];
/*cppCoordEq(lvl1,lvl,ceq[0],ceq[1],ceq[2],ceq[3],ceq[4],ceq[5],false,true)*/
if (((lvl.coords.flat == -1) || ceq[0] || ((lvl1.flat == lvl.anotherLvl) && (lvl.anotherLvl >= 0)))
&& ceq[1]
&& ceq[2]
&& ceq[3]
&& (ceq[4] || ((lvl1.flat == lvl.anotherLvl) && (lvl.anotherLvl >= 0) && (currentState == 11/*3d tour*/)) || ((lvl1.flat == lvl.anotherLvl) && (lvl.anotherLvl >= 0) && ((currentState == 9) || (currentState == 10)/*sel or view plan*/) && (lvl1.flat > lvl.coords.flat)))) loadthis = true;
}
}
TArray<FString> blya;
blya.Add(FString::FromInt(lvl.coords.flat));
blya.Add(FString::FromInt(lvl.coords.zone));
blya.Add(FString::FromInt(lvl.coords.house));
blya.Add(FString::FromInt(lvl.coords.section));
blya.Add(FString::FromInt(lvl.coords.floor));
FString instanceStr = FString::Join(blya, L"_");
FString temp2;
FString* temp3=&temp2;
lvl.path.Split(FString(L"."), nullptr, temp3);
instanceStr.Append(L"_").Append(*temp3);
FName instanceName = FName(instanceStr);
if (loadthis) {
if (cppdynamicLvls.Contains(instanceName)) {
ULevelStreaming* lvl1 = UGameplayStatics::GetStreamingLevel(WorldContextObject, instanceName);
lvl1->bShouldBlockOnLoad = (currentState != 11) && lvl.dontUnload;
lvl1->SetShouldBeLoaded(true);
lvl1->SetShouldBeVisible(true);
Levelss.Add(lvl1);
}
else {
bool b;
if (ULevelStreamingDynamic* newlvl = ULevelStreamingDynamic::LoadLevelInstance(WorldContextObject, lvl.path, FVector(0, 0, lvl.Z), FRotator(), b, instanceStr)) {
newlvl->SetPriority(lvl.coords.flat == -1 ? 1 : 0);
newlvl->bShouldBlockOnLoad = lvl.dontUnload;
cppdynamicLvls.Add(instanceName);
Levelss.Add(newlvl);
}
}
}
else {
if (cppdynamicLvls.Contains(instanceName)) UGameplayStatics::GetStreamingLevel(WorldContextObject, instanceName)->SetShouldBeLoaded(false);
}
}
return;
}
void UcppGI::cppCoordsEq(Fcppcoords coords, Fcppcoords coords1, bool relevantMinus2, bool fastEq, bool& flat_, bool& type_, bool& zone_, bool& house_, bool& section_, bool& floor_, bool& fullEq)
{
bool* outLvl[6] = { &flat_, &type_, &zone_, &house_, &section_, &floor_ };
int32 c1[6] = { coords.flat,coords.type, coords.zone, coords.house, coords.section, coords.floor };
int32 c2[6] = { coords1.flat,coords1.type, coords1.zone, coords1.house, coords1.section, coords1.floor };
int32 mins[6] = { 0,0,1,1,1,0 };
if (fastEq) {
for (int32 i = 0; i < 6; i++)
{
*outLvl[i] = (c1[i] == c2[i]);
}
}
else {
for (int32 i = 0; i < 6; i++) {
*outLvl[i] = ((c1[i] < mins[i]) && (c2[i] < mins[i])) || (c1[i] == c2[i]) || (c1[i] == -2) || ((c2[i] == -2) && relevantMinus2);
}
}
fullEq = true;
for (const auto var : outLvl)
{
if (!*var)fullEq = false;
}
}