Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.34 KB | None | 0 0
  1. /////////////////////////////////// Header
  2. #pragma once
  3.  
  4. #include "Object.h"
  5. #include "BlockStructure.generated.h"
  6.  
  7. struct BlockData {
  8.     bool solid = true;
  9.     uint8 bitmask = 0;
  10. };
  11.  
  12. enum class cutAlong { X_AXIS, Y_AXIS, Z_AXIS };
  13.  
  14. class UBlockStructure;
  15.  
  16. struct PairUBlockStructure {
  17.     UBlockStructure* A;
  18.     UBlockStructure* B;
  19. };
  20.  
  21. UCLASS()
  22. class CARILLON_API UBlockStructure : public UObject{
  23.  
  24.     GENERATED_BODY()
  25.  
  26. public:
  27.     UBlockStructure();
  28.     void init(int32 xSize, int32 ySize, int32 zSize);
  29.     int32 xSiz = 0, ySiz = 0, zSiz = 0;
  30.     BlockData getBlock(int32 x, int32 y, int32 z);
  31.     BlockData getBlockSafe(int32 x, int32 y, int32 z);
  32.     void fillRandom();
  33.     PairUBlockStructure SplitBlocks(int32 splitLocation, cutAlong along);
  34.  
  35. private:
  36.     BlockData*** blocks;
  37.     void setBlockSolid(int32 x, int32 y, int32 z, bool solid);
  38.     void setBlockBitmask(int32 x, int32 y, int32 z, uint8 bmsk);
  39. };
  40.  
  41. /////////////////////////////////// Definitions
  42.  
  43. #include "Carillon.h"
  44. #include "BlockStructure.h"
  45.  
  46.  
  47. UBlockStructure::UBlockStructure() {};
  48. void UBlockStructure::init(int32 xS, int32 yS, int32 zS) {
  49.     xSiz = xS;
  50.     ySiz = yS;
  51.     zSiz = zS;
  52.    
  53.     //Initalized 3D array
  54.     blocks = new BlockData**[xS];
  55.  
  56.     for (int i = 0; i < xS; ++i) {
  57.         blocks[i] = new BlockData*[yS];
  58.         for (int j = 0; j < yS; ++j) {
  59.             blocks[i][j] = new BlockData[zS];
  60.         }
  61.     }
  62.     //GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, FString::FromInt(ySiz) + " F  " + FString::FromInt(zSiz));
  63. }
  64.  
  65. void UBlockStructure::setBlockSolid(int32 x, int32 y, int32 z, bool solid) {
  66.     blocks[x][y][z].solid = solid;
  67. }
  68.  
  69. void UBlockStructure::setBlockBitmask(int32 x, int32 y, int32 z, uint8 bmsk) {
  70.     blocks[x][y][z].bitmask = bmsk;
  71. }
  72.  
  73. BlockData UBlockStructure::getBlock(int32 x, int32 y, int32 z) {
  74.         return blocks[x][y][z];
  75. }
  76.  
  77. BlockData UBlockStructure::getBlockSafe(int32 x, int32 y, int32 z) {
  78.     if (x >= 0 && x < xSiz && y >= 0 && y < ySiz && z >= 0 && z < zSiz) {
  79.         return blocks[x][y][z];
  80.     }
  81.     else {
  82.         BlockData b;
  83.         b.solid = false;
  84.         return b;
  85.     }
  86. }
  87.  
  88. PairUBlockStructure UBlockStructure::SplitBlocks(int32 splitLocation, cutAlong along) {
  89.     //GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, FString::FromInt(ySiz) + " C  " + FString::FromInt(zSiz));
  90.     PairUBlockStructure pair;
  91.     UBlockStructure* left = NewObject<UBlockStructure>();
  92.     UBlockStructure* right = NewObject<UBlockStructure>();
  93.     //int32 x, y, z;
  94.     //bool isInLeft;
  95.  
  96.     //Checks for splitlocation
  97.     //splitLocation = (splitLocation == 0) ? 1 : splitLocation;
  98.     //switch (along) {
  99.     //case cutAlong::X_AXIS:
  100.     //  splitLocation = (splitLocation >= xSiz) ? (xSiz - 1) : splitLocation;
  101.    
  102.         //left->init(splitLocation, ySiz, zSiz);
  103.         //right->init(xSiz - splitLocation, ySiz, zSiz);
  104.  
  105.     //  for (x = 0; x < xSiz; x++) {
  106.     //      isInLeft = x < splitLocation;
  107.     //      for (y = 0; y < ySiz; y++) {
  108.     //          for (z = 0; z < zSiz; z++) {
  109.     //              if (isInLeft) {
  110.     //                  left->setBlockSolid(x, y, z, blocks[x][y][z].solid);
  111.     //              }
  112.     //              else {
  113.     //                  right->setBlockSolid(x - splitLocation, y, z, blocks[x][y][z].solid);
  114.     //              }
  115.     //          }
  116.     //      }
  117.     //  }
  118.     //  break;
  119.     //}
  120.     pair.A = left;
  121.     pair.B = right;
  122.     return pair;
  123. }
  124.  
  125. void UBlockStructure::fillRandom() {
  126.     for (int i = 0; i < xSiz; i++) {
  127.         for (int k = 0; k < ySiz; k++) {
  128.             for (int w = 0; w < zSiz; w++) {
  129.                 setBlockSolid(i, k, w, FMath::RandBool());
  130.             }
  131.         }
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement