Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.25 KB | None | 0 0
  1.  
  2. patri@DESKTOP-F81JRPJ MINGW64 /d/git/UrbanHeat (master)
  3. $ git diff
  4. diff --git a/Source/UrbanHeat/CityManager.h b/Source/UrbanHeat/CityManager.h
  5. index 08b1870..2cb1bb8 100644
  6. --- a/Source/UrbanHeat/CityManager.h
  7. +++ b/Source/UrbanHeat/CityManager.h
  8. @@ -43,7 +43,7 @@ public:
  9.         // IMaterialInterface* TT;
  10.  
  11.         UPROPERTY(VisibleAnywhere)
  12. -               TArray<ATile*> Tiles;
  13. +       TArray<ATile*> Tiles;
  14.  
  15.  protected:
  16.  
  17. diff --git a/Source/UrbanHeat/Tile.h b/Source/UrbanHeat/Tile.h
  18. index bb23b4d..0b65135 100644
  19. --- a/Source/UrbanHeat/Tile.h
  20. +++ b/Source/UrbanHeat/Tile.h
  21. @@ -50,10 +50,10 @@ public:
  22.         void Initialize(VoronoiGenerator::Site & Site);
  23.  
  24.         UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
  25. -               UBaseTileSceneComp* TileContent = nullptr;
  26. +       UBaseTileSceneComp* TileContent = nullptr;
  27.  
  28.         UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
  29. -               TArray<UBaseTileSceneComp*> SubComponents;
  30. +       TArray<UBaseTileSceneComp*> SubComponents;
  31.  
  32.         UPROPERTY(VisibleAnywhere)
  33.                 float AirHindrance;
  34. diff --git a/Source/UrbanHeat/TileComponents/BaseTileSceneComp.cpp b/Source/UrbanHeat/TileComponents/BaseTileSceneComp.cpp
  35. index 6514781..42344d3 100644
  36. --- a/Source/UrbanHeat/TileComponents/BaseTileSceneComp.cpp
  37. +++ b/Source/UrbanHeat/TileComponents/BaseTileSceneComp.cpp
  38. @@ -24,14 +24,12 @@ void UBaseTileSceneComp::Init(FString type)
  39.  {
  40.         AUrbanHeatGameState* gameStateRef = Cast<AUrbanHeatGameState>(GetWorld()->GetGameState());
  41.  
  42. -       TArray<UDataTable*>* arrayRef = &gameStateRef->DataTableReferences;
  43. -
  44.         UDataTable* RootDataTableRef = gameStateRef->GetDataTableByName("ComponentData");
  45.  
  46.         UScriptStruct* Struct = RootDataTableRef->RowStruct;
  47.  
  48.         uint8* DataAddr = RootDataTableRef->FindRowUnchecked(FName(*type));
  49. -
  50. +
  51.         UProperty* Prop = Struct->CustomFindProperty(FName("EnvironmentalValues"));
  52.         if (Prop)
  53.         {
  54. @@ -43,7 +41,6 @@ void UBaseTileSceneComp::Init(FString type)
  55.                         float* subFound = subProp->ContainerPtrToValuePtr<float>(Prop->ContainerPtrToValuePtr<void>(DataAddr));
  56.                         if (subFound) {
  57.                                 BalanceInfluence = *subFound;
  58. -                               UE_LOG(LogTemp, Warning, TEXT("found Float %f"), subFound);
  59.                         }
  60.  
  61.                         subProp = Found->CustomFindProperty(FName("AirQualityValue"));
  62. @@ -51,7 +48,6 @@ void UBaseTileSceneComp::Init(FString type)
  63.                         subFound = subProp->ContainerPtrToValuePtr<float>(Prop->ContainerPtrToValuePtr<void>(DataAddr));                        if (subFound) {
  64.                                 AirQualityInfluence = *subFound;
  65. -                               UE_LOG(LogTemp, Warning, TEXT("found Float %f"), subFound);
  66.                         }
  67.  
  68.                         subProp = Found->CustomFindProperty(FName("WaterRetentionRate"));
  69. @@ -59,7 +55,6 @@ void UBaseTileSceneComp::Init(FString type)
  70.                         subFound = subProp->ContainerPtrToValuePtr<float>(Prop->ContainerPtrToValuePtr<void>(DataAddr));                        if (subFound) {
  71.                                 WaterRetentionInfluence = *subFound;
  72. -                               UE_LOG(LogTemp, Warning, TEXT("found Float %f"), subFound);
  73.                         }
  74.  
  75.                         subProp = Found->CustomFindProperty(FName("AirHindrance"));
  76. @@ -67,7 +62,6 @@ void UBaseTileSceneComp::Init(FString type)
  77.                         subFound = subProp->ContainerPtrToValuePtr<float>(Prop->ContainerPtrToValuePtr<void>(DataAddr));                        if (subFound) {
  78.                                 AirHindranceInfluence = *subFound;
  79. -                               UE_LOG(LogTemp, Warning, TEXT("found Float %f"), subFound);
  80.                         }
  81.                 }
  82.         }
  83. @@ -105,12 +99,18 @@ void UBaseTileSceneComp::Init(FString type)
  84.                         meshComp->SetRelativeTransform(modelTransform);
  85.                 }
  86.         }
  87. +       SpecializationInit(type);
  88. +}
  89. +
  90. +void UBaseTileSceneComp::SpecializationInit(FString tileType)
  91. +{
  92. +       //Fill in special Init things here in Subclasses
  93.  }
  94.  
  95.  void UBaseTileSceneComp::PostLoad()
  96.  {
  97.         Super::PostLoad();
  98.  
  99. -       UE_LOG(LogTemp, Warning, TEXT("PostLoad"));
  100. -       Init("Office");
  101. +       //UE_LOG(LogTemp, Warning, TEXT("PostLoad"));
  102. +       //Init("Office");
  103.  }
  104. diff --git a/Source/UrbanHeat/TileComponents/BaseTileSceneComp.h b/Source/UrbanHeat/TileComponents/BaseTileSceneComp.h
  105. index b6cfe05..de6e359 100644
  106. --- a/Source/UrbanHeat/TileComponents/BaseTileSceneComp.h
  107. +++ b/Source/UrbanHeat/TileComponents/BaseTileSceneComp.h
  108. @@ -8,21 +8,6 @@
  109.  #include "Engine/UserDefinedStruct.h"
  110.  #include "BaseTileSceneComp.generated.h"
  111.  
  112. -
  113. -/*
  114. -#define GETPROP(T, M) \
  115. -{ \
  116. -    UProperty* M##Prop = Struct->FindField<UProperty>(TEXT(#M)); \
  117. -    if (M##Prop) \
  118. -    { \
  119. -        T* Found = M##Prop->ContainerPtrToValuePtr<T>(DataAddr); \
  120. -        if (Found) \
  121. -        { \
  122. -            Mirr.M = *Found; \
  123. -        } \
  124. -    } \
  125. -}*/
  126. -
  127.  UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
  128.  class URBANHEAT_API UBaseTileSceneComp : public USceneComponent
  129.  {
  130. @@ -35,6 +20,7 @@ public:
  131.         virtual void BeginPlay() override;
  132.  
  133.         void Init(FString type);
  134. +       virtual void SpecializationInit(FString tileType);
  135.  
  136.         virtual void PostLoad() override;
  137.  
  138. diff --git a/Source/UrbanHeat/TileComponents/BuildingSceneComp.cpp b/Source/UrbanHeat/TileComponents/BuildingSceneComp.cpp
  139. index ff657f2..6c2652f 100644
  140. --- a/Source/UrbanHeat/TileComponents/BuildingSceneComp.cpp
  141. +++ b/Source/UrbanHeat/TileComponents/BuildingSceneComp.cpp
  142. @@ -32,6 +32,30 @@ void UBuildingSceneComp::TickComponent(float DeltaTime, ELevelTick TickType, FAc
  143.         // ...
  144.  }*/
  145.  
  146. +void UBuildingSceneComp::SpecializationInit(FString tileType)
  147. +{
  148. +       roofSubComp = NewObject<USubTileSceneComp>(GetOwner()->GetRootComponent());
  149. +       fasadeSubComp = NewObject<USubTileSceneComp>(GetOwner()->GetRootComponent());
  150. +
  151. +
  152. +       AUrbanHeatGameState* gameStateRef = Cast<AUrbanHeatGameState>(GetWorld()->GetGameState());
  153. +
  154. +       if (tileType == "Office") {
  155. +               roofSubComp->Init(gameStateRef->GetDataTableByName("Office_RoofsData"),meshComp);
  156. +               fasadeSubComp->Init(gameStateRef->GetDataTableByName("Office_FasadeData"), meshComp);
  157. +       }
  158. +
  159. +       if (tileType == "Shops") {
  160. +               roofSubComp->Init(gameStateRef->GetDataTableByName("Shop_RoofsData"), meshComp);
  161. +               fasadeSubComp->Init(gameStateRef->GetDataTableByName("Shop_FasadeData"), meshComp);
  162. +       }
  163. +
  164. +       if (tileType == "House") {
  165. +               roofSubComp->Init(gameStateRef->GetDataTableByName("House_RoofsData"), meshComp);
  166. +               fasadeSubComp->Init(gameStateRef->GetDataTableByName("House_FasadeData"), meshComp);
  167. +       }
  168. +}
  169. +
  170.  void UBuildingSceneComp::setRoof(FString type)
  171.  {
  172.  }
  173. diff --git a/Source/UrbanHeat/TileComponents/BuildingSceneComp.h b/Source/UrbanHeat/TileComponents/BuildingSceneComp.h
  174. index c9ea087..8a8458e 100644
  175. --- a/Source/UrbanHeat/TileComponents/BuildingSceneComp.h
  176. +++ b/Source/UrbanHeat/TileComponents/BuildingSceneComp.h
  177. @@ -6,6 +6,7 @@
  178.  #include "Components/SceneComponent.h"
  179.  #include "SubTileSceneComp.h"
  180.  #include "BaseTileSceneComp.h"
  181. +#include "UrbanHeatGameState.h"
  182.  #include "BuildingSceneComp.generated.h"
  183.  
  184.  
  185. @@ -18,9 +19,14 @@ public:
  186.         // Sets default values for this component's properties
  187.         UBuildingSceneComp();
  188.  
  189. +       UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
  190.         USubTileSceneComp* roofSubComp;
  191. +
  192. +       UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
  193.         USubTileSceneComp* fasadeSubComp;
  194.  
  195. +       virtual void SpecializationInit(FString tileType) override;
  196. +
  197.  protected:
  198.         // Called when the game starts
  199.         //virtual void BeginPlay() override;
  200. diff --git a/Source/UrbanHeat/TileComponents/SubTileSceneComp.cpp b/Source/UrbanHeat/TileComponents/SubTileSceneComp.cppindex 64f4ef4..355c54a 100644
  201. --- a/Source/UrbanHeat/TileComponents/SubTileSceneComp.cpp
  202. +++ b/Source/UrbanHeat/TileComponents/SubTileSceneComp.cpp
  203. @@ -13,9 +13,104 @@ USubTileSceneComp::USubTileSceneComp()
  204.  }
  205.  
  206.  
  207. -void USubTileSceneComp::Init(UDataTable * table)
  208. +void USubTileSceneComp::Init(UDataTable * table, UStaticMeshComponent* MeshReference)
  209.  {
  210.         DataTable = table;
  211. +
  212. +       meshComp = MeshReference;
  213. +
  214. +       LoadType("Default");
  215. +}
  216. +
  217. +void USubTileSceneComp::LoadType(FString name)
  218. +{
  219. +       UScriptStruct* Struct = DataTable->RowStruct;
  220. +
  221. +       uint8* DataAddr = DataTable->FindRowUnchecked(FName(*name));
  222. +
  223. +       UProperty* Prop = Struct->CustomFindProperty(FName("EnvironmentalValues"));
  224. +       if (Prop)
  225. +       {
  226. +               UScriptStruct* Found = Cast<UStructProperty>(Prop)->Struct;
  227. +               if (Found)
  228. +               {
  229. +                       UProperty* subProp = Found->CustomFindProperty(FName("EconomicValue"));
  230. +
  231. +                       float* subFound = subProp->ContainerPtrToValuePtr<float>(Prop->ContainerPtrToValuePtr<void>(DataAddr));
  232. +                       if (subFound) {
  233. +                               BalanceInfluence = *subFound;
  234. +                               UE_LOG(LogTemp, Warning, TEXT("found Float %f"), subFound);
  235. +                       }
  236. +
  237. +                       subProp = Found->CustomFindProperty(FName("AirQualityValue"));
  238. +
  239. +                       subFound = subProp->ContainerPtrToValuePtr<float>(Prop->ContainerPtrToValuePtr<void>(DataAddr));+                       if (subFound) {
  240. +                               AirQualityInfluence = *subFound;
  241. +                               UE_LOG(LogTemp, Warning, TEXT("found Float %f"), subFound);
  242. +                       }
  243. +
  244. +                       subProp = Found->CustomFindProperty(FName("WaterRetentionRate"));
  245. +
  246. +                       subFound = subProp->ContainerPtrToValuePtr<float>(Prop->ContainerPtrToValuePtr<void>(DataAddr));+                       if (subFound) {
  247. +                               WaterRetentionInfluence = *subFound;
  248. +                               UE_LOG(LogTemp, Warning, TEXT("found Float %f"), subFound);
  249. +                       }
  250. +
  251. +                       subProp = Found->CustomFindProperty(FName("AirHindrance"));
  252. +
  253. +                       subFound = subProp->ContainerPtrToValuePtr<float>(Prop->ContainerPtrToValuePtr<void>(DataAddr));+                       if (subFound) {
  254. +                               AirHindranceInfluence = *subFound;
  255. +                               UE_LOG(LogTemp, Warning, TEXT("found Float %f"), subFound);
  256. +                       }
  257. +               }
  258. +       }
  259. +
  260. +       Prop = Struct->CustomFindProperty(FName("ReplaceModel"));
  261. +       if (Prop)
  262. +       {
  263. +               bool* ShouldReplaceObject = Prop->ContainerPtrToValuePtr<bool>(DataAddr);
  264. +               if (ShouldReplaceObject && *ShouldReplaceObject)
  265. +               {
  266. +                       //ToDo following part should be replaced through proper authentic building placement
  267. +                       FTransform modelTransform = FTransform();
  268. +                       Prop = Struct->CustomFindProperty(FName("ModelTransform"));
  269. +                       if (Prop)
  270. +                       {
  271. +                               FTransform* Found = Prop->ContainerPtrToValuePtr<FTransform>(DataAddr);
  272. +                               if (Found)
  273. +                               {
  274. +                                       modelTransform = *Found;
  275. +                               }
  276. +                       }
  277. +
  278. +                       Prop = Struct->CustomFindProperty(FName("Model"));
  279. +                       if (Prop)
  280. +                       {
  281. +                               FSoftObjectPath* Found = Prop->ContainerPtrToValuePtr<FSoftObjectPath>(DataAddr);
  282. +
  283. +                               if (Found)
  284. +                               {
  285. +
  286. +                                       if (meshComp)
  287. +                                               meshComp->DestroyComponent();
  288. +
  289. +                                       meshComp = NewObject<UStaticMeshComponent>(this);
  290. +                                       meshComp->RegisterComponent();
  291. +                                       meshComp->AttachToComponent(this, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
  292. +                                       UStaticMesh* Mesh = LoadObject<UStaticMesh>(nullptr, *Found->ToString());
  293. +                                       if (Mesh) {
  294. +                                               meshComp->SetStaticMesh(Mesh);
  295. +                                       }
  296. +                                       meshComp->SetRelativeTransform(modelTransform);
  297. +                               }
  298. +                       }
  299. +               }
  300. +       }
  301. +
  302. +
  303.  }
  304.  
  305.  // Called when the game starts
  306. diff --git a/Source/UrbanHeat/TileComponents/SubTileSceneComp.h b/Source/UrbanHeat/TileComponents/SubTileSceneComp.h
  307. index 733c4dd..a74a536 100644
  308. --- a/Source/UrbanHeat/TileComponents/SubTileSceneComp.h
  309. +++ b/Source/UrbanHeat/TileComponents/SubTileSceneComp.h
  310. @@ -5,6 +5,7 @@
  311.  #include "CoreMinimal.h"
  312.  #include "Components/SceneComponent.h"
  313.  #include "Engine/DataTable.h"
  314. +#include "Components/StaticMeshComponent.h"
  315.  #include "SubTileSceneComp.generated.h"
  316.  
  317.  
  318. @@ -17,10 +18,11 @@ public:
  319.         // Sets default values for this component's properties
  320.         USubTileSceneComp();
  321.  
  322. +       UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
  323.         UDataTable* DataTable;
  324.  
  325. -       void Init(UDataTable* table);
  326. -       void SetType(FString name);
  327. +       void Init(UDataTable* table, UStaticMeshComponent* MeshReference);
  328. +       void LoadType(FString name);
  329.  
  330.         UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
  331.         float BalanceInfluence = 0;
  332. @@ -34,6 +36,7 @@ public:
  333.         UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
  334.         float AirHindranceInfluence = 0;
  335.  
  336. +
  337.  protected:
  338.         // Called when the game starts
  339.         virtual void BeginPlay() override;
  340. @@ -41,4 +44,8 @@ protected:
  341.  public:
  342.         // Called every frame
  343.         virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
  344. +
  345. +private:
  346. +
  347. +       UStaticMeshComponent * meshComp;
  348.  };
  349. (END)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement