Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////// Header
- #pragma once
- #include "Object.h"
- #include "BlockStructure.generated.h"
- struct BlockData {
- bool solid = true;
- uint8 bitmask = 0;
- };
- enum class cutAlong { X_AXIS, Y_AXIS, Z_AXIS };
- class UBlockStructure;
- struct PairUBlockStructure {
- UBlockStructure* A;
- UBlockStructure* B;
- };
- UCLASS()
- class CARILLON_API UBlockStructure : public UObject{
- GENERATED_BODY()
- public:
- UBlockStructure();
- void init(int32 xSize, int32 ySize, int32 zSize);
- int32 xSiz = 0, ySiz = 0, zSiz = 0;
- BlockData getBlock(int32 x, int32 y, int32 z);
- BlockData getBlockSafe(int32 x, int32 y, int32 z);
- void fillRandom();
- PairUBlockStructure SplitBlocks(int32 splitLocation, cutAlong along);
- private:
- BlockData*** blocks;
- void setBlockSolid(int32 x, int32 y, int32 z, bool solid);
- void setBlockBitmask(int32 x, int32 y, int32 z, uint8 bmsk);
- };
- /////////////////////////////////// Definitions
- #include "Carillon.h"
- #include "BlockStructure.h"
- UBlockStructure::UBlockStructure() {};
- void UBlockStructure::init(int32 xS, int32 yS, int32 zS) {
- xSiz = xS;
- ySiz = yS;
- zSiz = zS;
- //Initalized 3D array
- blocks = new BlockData**[xS];
- for (int i = 0; i < xS; ++i) {
- blocks[i] = new BlockData*[yS];
- for (int j = 0; j < yS; ++j) {
- blocks[i][j] = new BlockData[zS];
- }
- }
- //GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, FString::FromInt(ySiz) + " F " + FString::FromInt(zSiz));
- }
- void UBlockStructure::setBlockSolid(int32 x, int32 y, int32 z, bool solid) {
- blocks[x][y][z].solid = solid;
- }
- void UBlockStructure::setBlockBitmask(int32 x, int32 y, int32 z, uint8 bmsk) {
- blocks[x][y][z].bitmask = bmsk;
- }
- BlockData UBlockStructure::getBlock(int32 x, int32 y, int32 z) {
- return blocks[x][y][z];
- }
- BlockData UBlockStructure::getBlockSafe(int32 x, int32 y, int32 z) {
- if (x >= 0 && x < xSiz && y >= 0 && y < ySiz && z >= 0 && z < zSiz) {
- return blocks[x][y][z];
- }
- else {
- BlockData b;
- b.solid = false;
- return b;
- }
- }
- PairUBlockStructure UBlockStructure::SplitBlocks(int32 splitLocation, cutAlong along) {
- //GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, FString::FromInt(ySiz) + " C " + FString::FromInt(zSiz));
- PairUBlockStructure pair;
- UBlockStructure* left = NewObject<UBlockStructure>();
- UBlockStructure* right = NewObject<UBlockStructure>();
- //int32 x, y, z;
- //bool isInLeft;
- //Checks for splitlocation
- //splitLocation = (splitLocation == 0) ? 1 : splitLocation;
- //switch (along) {
- //case cutAlong::X_AXIS:
- // splitLocation = (splitLocation >= xSiz) ? (xSiz - 1) : splitLocation;
- //left->init(splitLocation, ySiz, zSiz);
- //right->init(xSiz - splitLocation, ySiz, zSiz);
- // for (x = 0; x < xSiz; x++) {
- // isInLeft = x < splitLocation;
- // for (y = 0; y < ySiz; y++) {
- // for (z = 0; z < zSiz; z++) {
- // if (isInLeft) {
- // left->setBlockSolid(x, y, z, blocks[x][y][z].solid);
- // }
- // else {
- // right->setBlockSolid(x - splitLocation, y, z, blocks[x][y][z].solid);
- // }
- // }
- // }
- // }
- // break;
- //}
- pair.A = left;
- pair.B = right;
- return pair;
- }
- void UBlockStructure::fillRandom() {
- for (int i = 0; i < xSiz; i++) {
- for (int k = 0; k < ySiz; k++) {
- for (int w = 0; w < zSiz; w++) {
- setBlockSolid(i, k, w, FMath::RandBool());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement