startAgain. c++ functions, search
This commit is contained in:
@@ -0,0 +1,325 @@
|
||||
// Fill outLvl your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "cppFuncLibrary.h"
|
||||
#include "Kismet/KismetStringLibrary.h"
|
||||
#include "Kismet/KismetmathLibrary.h"
|
||||
|
||||
|
||||
TArray<FString> UcppFuncLibrary::cppUniversalParser(FString string, TArray<FString> keys, FString delimiter, bool caseSensitive)
|
||||
{
|
||||
TArray<FString> arr;
|
||||
TArray<FString> out;
|
||||
out.SetNum(keys.Num());
|
||||
|
||||
string.ParseIntoArray(arr, *delimiter, false);
|
||||
for (const auto& str : arr) {
|
||||
int n = 0;
|
||||
for (const auto& str1 : keys) {
|
||||
if (str1.IsEmpty()) continue;
|
||||
FString left_;
|
||||
FString right_;
|
||||
if (str.Split(str1, &left_, &right_, caseSensitive ? ESearchCase::CaseSensitive : ESearchCase::IgnoreCase)) {
|
||||
|
||||
if (out[n].IsEmpty()) out[n] = right_;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
FString UcppFuncLibrary::cppIntToStrPad(int32 int_, int32 minDigits)
|
||||
{
|
||||
FString temp = FString::FromInt(int_);
|
||||
for (int32 i = temp.Len(); i < minDigits; i++) {
|
||||
temp = L"0" + temp;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
TSoftObjectPtr<UTexture2D> UcppFuncLibrary::castSoftTex2D(TSoftObjectPtr<UObject> ptr)
|
||||
{
|
||||
|
||||
return TSoftObjectPtr<UTexture2D>(ptr.ToSoftObjectPath());//somewhy cant construct from another <T> and cant cast
|
||||
}
|
||||
|
||||
double UcppFuncLibrary::NegateF(double in)
|
||||
{
|
||||
return in * -1;
|
||||
}
|
||||
|
||||
int32 UcppFuncLibrary::NegateI(int32 in)
|
||||
{
|
||||
return in * -1;
|
||||
}
|
||||
|
||||
double UcppFuncLibrary::OneMinus(double in)
|
||||
{
|
||||
return 1 - in;
|
||||
}
|
||||
|
||||
|
||||
|
||||
double UcppFuncLibrary::AddRefF(UPARAM(ref) double& A, double B)
|
||||
{
|
||||
A += B;
|
||||
return A;
|
||||
}
|
||||
|
||||
int32 UcppFuncLibrary::AddRefI(UPARAM(ref) int32& A, int32 B)
|
||||
{
|
||||
A += B;
|
||||
return A;
|
||||
}
|
||||
|
||||
double UcppFuncLibrary::SubRefF(UPARAM(ref) double& A, double B)
|
||||
{
|
||||
A -= B;
|
||||
return A;
|
||||
}
|
||||
|
||||
int32 UcppFuncLibrary::SubRefI(UPARAM(ref) int32& A, int32 B)
|
||||
{
|
||||
A -= B;
|
||||
return A;
|
||||
}
|
||||
|
||||
double UcppFuncLibrary::saturate(double in)
|
||||
{
|
||||
return in < 0 ? 0 : (in > 1 ? 1 : in);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32 UcppFuncLibrary::clamp0(int32 in)
|
||||
{
|
||||
return (in < 0) ? 0 : in;
|
||||
}
|
||||
|
||||
void UcppFuncLibrary::cppssw(int32 int_, FString trueInts, bool& true_, bool& false_)
|
||||
{
|
||||
FJsonSerializableArray arr;
|
||||
trueInts.ParseIntoArray(arr, L",");
|
||||
for (auto& obj : arr) {
|
||||
|
||||
FString lft;
|
||||
FString* lftp = &lft;
|
||||
FString rht;
|
||||
FString* rhtp = &rht;
|
||||
if (obj.Split(L"-", &lft, &rht)) {
|
||||
if ((int_ >= UKismetStringLibrary::Conv_StringToInt(lft)) && (int_ <= UKismetStringLibrary::Conv_StringToInt(rht))) {
|
||||
true_ = true;
|
||||
false_ = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (int_ == UKismetStringLibrary::Conv_StringToInt(obj)) {
|
||||
true_ = true;
|
||||
false_ = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
true_ = false;
|
||||
false_ = true;
|
||||
return;
|
||||
}
|
||||
|
||||
FString UcppFuncLibrary::stringAdd(UPARAM(ref)FString& str, FString add)
|
||||
{
|
||||
return str.Append(add);
|
||||
}
|
||||
|
||||
void UcppFuncLibrary::parseOptions(FString SourceString, FString key, FString Delimiter, FString& value, bool& found)
|
||||
{
|
||||
FJsonSerializableArray arr;
|
||||
SourceString.ParseIntoArray(arr, *Delimiter);
|
||||
for (auto& ar : arr) {
|
||||
FString lft;
|
||||
FString rht;
|
||||
if (ar.Split(L"=", &lft, &rht)) {
|
||||
if (lft == key) {
|
||||
value = rht;
|
||||
found = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
value = FString();
|
||||
found = false;
|
||||
return;
|
||||
}
|
||||
|
||||
int32 UcppFuncLibrary::customStringToInt(FString string)
|
||||
{
|
||||
return (string.IsEmpty() || !string.IsNumeric()) ? -1 : UKismetStringLibrary::Conv_StringToInt(string);
|
||||
}
|
||||
|
||||
void UcppFuncLibrary::multiContains(FString source, UPARAM(ref)TArray<FString>& substrings, bool bAnd, bool bUseCase, bool& bTrue, bool& bFalse)
|
||||
{
|
||||
TArray<bool> temp;
|
||||
for (auto& st : substrings) {
|
||||
bool temp1 = source.Contains(st, bUseCase ? ESearchCase::CaseSensitive : ESearchCase::IgnoreCase);
|
||||
temp.Add(temp1);
|
||||
if (temp1) {
|
||||
if (!bAnd) {
|
||||
bTrue = true;
|
||||
bFalse = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
bTrue = !temp.Contains(false);
|
||||
bFalse = !bTrue;
|
||||
return;
|
||||
}
|
||||
|
||||
void UcppFuncLibrary::containStringSwitch(FString string, UPARAM(ref)TArray<FString>& keys, bool bUseCase, int32& bInt, TArray<bool>& bools)
|
||||
{
|
||||
bools.Empty();
|
||||
bInt = -1;
|
||||
bool lock = false;
|
||||
|
||||
for (auto& key : keys) {
|
||||
bool temp2 = string.Contains(key, bUseCase ? ESearchCase::CaseSensitive : ESearchCase::IgnoreCase);
|
||||
bools.Add(temp2);
|
||||
if (temp2 && !lock) {
|
||||
lock = true;
|
||||
bInt = bools.Num() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FString UcppFuncLibrary::multiRemove(FString source, UPARAM(ref)TArray<FString>& substrings, bool bUseCase)
|
||||
{
|
||||
for (auto& ss : substrings) source.ReplaceInline(*ss, L"", bUseCase ? ESearchCase::CaseSensitive : ESearchCase::IgnoreCase);
|
||||
return source;
|
||||
}
|
||||
|
||||
FString UcppFuncLibrary::quoteString(FString string)
|
||||
{
|
||||
return FString("""").Append(string).Append("""");
|
||||
}
|
||||
|
||||
void UcppFuncLibrary::getRange(double value, double minMult, double maxMult, double& bMin, double& bValue, double& bMax)
|
||||
{
|
||||
bMin = value * minMult;
|
||||
bMax = value * maxMult;
|
||||
bValue = value;
|
||||
}
|
||||
|
||||
void UcppFuncLibrary::updateFilterList(TArray<FcppflatStruct> flats, int floorMin, int floorMax, float sqMin, float sqMax, int priceMin, int priceMax, TArray<bool> houses, TArray<bool> sections, TArray<bool> rooms, int sortType, TArray<FcppflatStruct>& filtered)
|
||||
{
|
||||
TArray<int> tempfloor, tempprice;
|
||||
TArray<float> tempsq;
|
||||
for (auto& flat : flats) {
|
||||
if (inRange(flat.Floor, floorMin, floorMax)
|
||||
&& inRange(flat.Price, priceMin, priceMax)
|
||||
&& inRange(flat.Square, sqMin, sqMax)
|
||||
&& boolGet(houses, flat.House)
|
||||
&& boolGet(sections, flat.Section)
|
||||
&& boolGet(rooms, flat.Rooms)) {
|
||||
filtered.Add(flat);
|
||||
tempfloor.Add(flat.Floor);
|
||||
tempprice.Add(flat.Price);
|
||||
tempsq.Add(flat.Square);
|
||||
}
|
||||
}
|
||||
if (tempfloor.Num() > 1) {
|
||||
switch (sortType) {
|
||||
case 0:
|
||||
case 1:
|
||||
for (int i = 0; i <= (tempprice.Num() - 1) / 2; i++) {
|
||||
int minid, maxid;
|
||||
minmaxInRange(tempprice, i, tempprice.Num() - 1 - i, minid, maxid);
|
||||
tempprice.Swap(sortType == 0 ? minid : maxid, i);
|
||||
filtered.Swap(sortType == 0 ? minid : maxid, i);
|
||||
minmaxInRange(tempprice, i, tempprice.Num() - 1 - i, minid, maxid);
|
||||
tempprice.Swap(sortType == 1 ? minid : maxid, tempprice.Num() - 1 - i);
|
||||
filtered.Swap(sortType == 1 ? minid : maxid, tempprice.Num() - 1 - i);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
for (int i = 0; i <= (tempsq.Num() - 1) / 2; i++) {
|
||||
int minid, maxid;
|
||||
minmaxInRange(tempsq, i, tempsq.Num() - 1 - i, minid, maxid);
|
||||
tempsq.Swap(sortType == 2 ? minid : maxid, i);
|
||||
filtered.Swap(sortType == 2 ? minid : maxid, i);
|
||||
minmaxInRange(tempsq, i, tempsq.Num() - 1 - i, minid, maxid);
|
||||
tempsq.Swap(sortType == 3 ? minid : maxid, tempsq.Num() - 1 - i);
|
||||
filtered.Swap(sortType == 3 ? minid : maxid, tempsq.Num() - 1 - i);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
for (int i = 0; i <= (tempfloor.Num() - 1) / 2; i++) {
|
||||
int minid, maxid;
|
||||
minmaxInRange(tempfloor, i, tempfloor.Num() - 1 - i, minid, maxid);
|
||||
tempfloor.Swap(sortType == 4 ? minid : maxid, i);
|
||||
filtered.Swap(sortType == 4 ? minid : maxid, i);
|
||||
minmaxInRange(tempfloor, i, tempfloor.Num() - 1 - i, minid, maxid);
|
||||
tempfloor.Swap(sortType == 5 ? minid : maxid, tempfloor.Num() - 1 - i);
|
||||
filtered.Swap(sortType == 5 ? minid : maxid, tempfloor.Num() - 1 - i);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool UcppFuncLibrary::inRange(float in, float min, float max)
|
||||
{
|
||||
return (in >= min) && (in <= max);
|
||||
}
|
||||
|
||||
bool UcppFuncLibrary::inRange(int in, int min, int max)
|
||||
{
|
||||
return (in >= min) && (in <= max);
|
||||
}
|
||||
|
||||
bool UcppFuncLibrary::boolGet(TArray<bool> arr, int index)
|
||||
{
|
||||
if (arr.Contains(true)) {
|
||||
if (arr.IsValidIndex(index))return arr[index];
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void UcppFuncLibrary::minmaxInRange(TArray<int> arr, int min, int max, int& minid, int& maxid)
|
||||
{
|
||||
int temp;
|
||||
max = (max > (arr.Num() - 1)) ? arr.Num() - 1 : (max < 0 ? 0 : max);
|
||||
min = (min > (arr.Num() - 1)) ? arr.Num() - 1 : (min < 0 ? 0 : min);
|
||||
arr.SetNum(max + 1); //delete overmax ids
|
||||
for (int i = 0; i < min; i++)arr.RemoveAt(0);// delete belowmin ids
|
||||
UKismetMathLibrary::MinOfIntArray(arr, minid, temp);
|
||||
minid += min; //return original order
|
||||
UKismetMathLibrary::MaxOfIntArray(arr, maxid, temp);
|
||||
maxid += min;
|
||||
}
|
||||
|
||||
void UcppFuncLibrary::minmaxInRange(TArray<float> arr, int min, int max, int& minid, int& maxid)
|
||||
{
|
||||
float temp;
|
||||
max = (max > (arr.Num() - 1)) ? arr.Num() - 1 : (max < 0 ? 0 : max);
|
||||
min = (min > (arr.Num() - 1)) ? arr.Num() - 1 : (min < 0 ? 0 : min);
|
||||
arr.SetNum(max + 1); //delete overmax ids
|
||||
for (int i = 0; i < min; i++)arr.RemoveAt(0);// delete belowmin ids
|
||||
UKismetMathLibrary::MinOfFloatArray(arr, minid, temp);
|
||||
minid += min; //return original order
|
||||
UKismetMathLibrary::MaxOfFloatArray(arr, maxid, temp);
|
||||
maxid += min;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "cppGI.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Misc/paths.h"
|
||||
#include "Engine/levelstreamingdynamic.h"
|
||||
#include "cppFuncLibrary.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;
|
||||
}
|
||||
/*for working tarray::Contains*/
|
||||
bool operator==(const FcppLevelStruct& c1, const FcppLevelStruct& c2) {
|
||||
return c1.anotherLvl == c2.anotherLvl &&
|
||||
c1.coords == c2.coords &&
|
||||
c1.dontUnload == c2.dontUnload &&
|
||||
c1.path == c2.path &&
|
||||
c1.uniqName == c2.uniqName &&
|
||||
c1.Z == c2.Z;
|
||||
}
|
||||
|
||||
TArray<ULevelStreaming*> UcppGI::cppLvlManage(UObject* WorldContextObject, Fcppcoords currentCoords, uint8 currentState)
|
||||
{
|
||||
TArray<ULevelStreaming*> outStruct;
|
||||
bool loadthis;
|
||||
auto temp = Fcppcoords();
|
||||
temp.house = -2;
|
||||
temp.section = -2;
|
||||
temp.floor = 1;
|
||||
|
||||
cppLoadList.AddUnique(currentCoords);
|
||||
cppLoadList.AddUnique(temp);
|
||||
|
||||
for (const auto& lvl : cppLevels)
|
||||
{
|
||||
loadthis = 0;
|
||||
|
||||
if (cppBlackList.Contains(lvl));
|
||||
else if (cppWhiteList.Contains(lvl)) loadthis = true;
|
||||
else {
|
||||
bool ceq[7];
|
||||
for (const auto& crd : cppLoadList) // here is filter code
|
||||
{
|
||||
cppCoordsEq(crd, lvl.coords, true, false, ceq[0], ceq[1], ceq[2], ceq[3], ceq[4], ceq[5], ceq[6]);
|
||||
if (ceq[3] && ceq[4] && ceq[5] && !lvl.uniqName.ToString().EndsWith(L"refl")) loadthis = true; //reflections setup separately, load all on floor
|
||||
if (ceq[6] && lvl.uniqName.ToString().EndsWith(L"refl")) loadthis = true;
|
||||
//if (ceq[6]) loadthis = true; //classic load with parallax
|
||||
}
|
||||
}
|
||||
|
||||
if (loadthis) {
|
||||
if (cppCreatedList.Contains(lvl.uniqName)) { /*if already created level*/
|
||||
ULevelStreaming* outlvl_ = nullptr;
|
||||
if ((outlvl_ = UGameplayStatics::GetStreamingLevel(WorldContextObject, lvl.uniqName)) != nullptr) {
|
||||
outlvl_->SetShouldBeLoaded(true);
|
||||
outlvl_->SetShouldBeVisible(true);
|
||||
cpploadedList.Add(lvl.uniqName);
|
||||
outStruct.Add(outlvl_);
|
||||
}
|
||||
}
|
||||
else { /*load new level instance*/
|
||||
|
||||
bool b;
|
||||
if (ULevelStreamingDynamic* newlvl = ULevelStreamingDynamic::LoadLevelInstance(WorldContextObject, lvl.path, FVector(0, 0, lvl.Z), FRotator(), b, lvl.uniqName.ToString())) {
|
||||
newlvl->SetPriority(lvl.coords.flat == -1 ? 1 : 0);
|
||||
newlvl->bShouldBlockOnLoad = lvl.dontUnload;
|
||||
cpploadedList.Add(lvl.uniqName);
|
||||
outStruct.Add(newlvl);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if (cppCreatedList.Contains(lvl.uniqName)) {
|
||||
ULevelStreaming* outlvl_ = nullptr;
|
||||
if ((outlvl_ = UGameplayStatics::GetStreamingLevel(WorldContextObject, lvl.uniqName)) != nullptr) {
|
||||
//if (lvl.path.EndsWith("refl")) outlvl_->bShouldBlockOnUnload = true;
|
||||
outlvl_->SetShouldBeLoaded(lvl.dontUnload);
|
||||
outlvl_->SetShouldBeVisible(false);
|
||||
cpploadedList.Remove(lvl.uniqName);
|
||||
outStruct.Add(outlvl_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cppWhiteList.Empty();
|
||||
cppBlackList.Empty();
|
||||
cppLoadList.Empty();
|
||||
return outStruct;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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_, §ion_, &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 (int8 i = 0; i < 6; i++)
|
||||
{
|
||||
*outLvl[i] = (c1[i] == c2[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int8 i = 0; i < 6; i++) {
|
||||
*outLvl[i] = ((c1[i] < mins[i]) && (c2[i] < mins[i])) || (c1[i] == c2[i]) || ((c1[i] == -2) && relevantMinus2) || ((c2[i] == -2) && relevantMinus2);
|
||||
}
|
||||
}
|
||||
fullEq = true;
|
||||
for (const auto var : outLvl)
|
||||
{
|
||||
if (!*var)fullEq = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user