// Fill out your copyright notice in the Description page of Project Settings. #include "cppGI.h" #include "Kismet/GameplayStatics.h" #include "Misc/paths.h" #include "commands_model.h" #include "Engine/levelstreamingdynamic.h" CSocket* soc; char ipc[100]; /*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& Levelss) { bool loadthis = false; auto is3DTour = currentState == 11; int32 temp1[5] = { currentCoords.flat,currentCoords.zone,currentCoords.house,currentCoords.section,currentCoords.floor }; //cpplvlsForLoading.Add(Fcppcoords(1, -2, -2, 1, -1)); /*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++; } }*/ if (is3DTour && currentCoords.house < 1) cpplvlsForLoading.AddUnique(Fcppcoords(1, -2, -2, 1, -1)); cpplvlsForLoading.AddUnique(currentCoords); for (const FcppLevelStruct& lvl : cpplevelLIst) { FString tt = lvl.path; if (currentCoords.floor == 100); else { loadthis = false; bool ceq[7]; for (const auto& crd : cpplvlsForLoading) // 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[0] || !is3DTour || lvl.coords.flat == -1) && ceq[5]) || (is3DTour ? lvl.anotherLvl >= 1 && lvl.anotherLvl == crd.flat : lvl.anotherLvl >= 1 && (crd.flat>=0 ? lvl.anotherLvl == crd.flat:true) && lvl.coords.floor < crd.floor) ) && ceq[3] && ceq[4] ) loadthis = true; //load all on floor and under 2-floor flat, and full 2-floor flat in 3d tour //if (ceq[6]) loadthis = true; //classic load with parallax } } TArray 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)); blya.Add(FString::FromInt(lvl.Z)); FString instanceStr = FString::Join(blya, L"_"); instanceStr.Append(L"_").Append(FPaths::GetCleanFilename(lvl.path)); 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(0), 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); } } cpplvlsForLoading.Empty(); 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_, §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 (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; } } void UcppGI::avoidAutoState() { if (!soc)return; DECLARE_CMD(CMD_NOP, cmd); sendCommand(*soc, cmd); } void UcppGI::makeSocket(FString ip, int port) { //static char ipc[100]; wcstombs(&ipc[0], *ip, ip.Len() + 1); //size_t sz; //wcstombs_s(&sz, ipc, ip.Len(),*ip,ip.Len()); soc = new CSocket(&ipc[0], port); } void UcppGI::setColor(uint8 code, FColor color) { if (!soc)return; DECLARE_CMD(CMD_SET_COLOR, cmd); cmd.code = code; cmd.r = color.R, cmd.g = color.G, cmd.b = color.B; sendCommand(*soc, cmd); } void UcppGI::setLight(int house, int floor, int strip, uint8 state) { if (!soc)return; if (strip < 0) { if (floor < 0) { if (house < 0) { DECLARE_CMD(CMD_SET_ALL_STATE, cmd); cmd.state = state; sendCommand(*soc, cmd); return; } DECLARE_CMD(CMD_SET_BUILDING_STATE, cmd); cmd.state = state; cmd.building = house; sendCommand(*soc, cmd); return; } DECLARE_CMD(CMD_SET_FLOOR_STATE, cmd); cmd.state = state; cmd.building = house; cmd.floor = floor; sendCommand(*soc, cmd); return; } DECLARE_CMD(CMD_SET_ROOM_STATE, cmd); cmd.state = state; cmd.building = house; cmd.floor = floor; cmd.strip = strip; sendCommand(*soc, cmd); } void UcppGI::setPartState(uint8 part, uint8 state) { if (!soc)return; DECLARE_CMD(CMD_SET_PART_MODE, cmd); cmd.mode = state; cmd.part = part; sendCommand(*soc, cmd); }