Got the refactor building
This commit is contained in:
@@ -7,19 +7,14 @@
|
||||
#include "Cube.h"
|
||||
#include "Vector3D.h"
|
||||
|
||||
template <V3D &BOARD_DIMS>
|
||||
template <const V3D &BOARD_DIMS>
|
||||
class Board{
|
||||
public:
|
||||
enum PLANE_NORMAL : uint32_t{
|
||||
X = 0,
|
||||
Y,
|
||||
Z
|
||||
};
|
||||
|
||||
Board();
|
||||
~Board() = default;
|
||||
|
||||
constexpr V3D &GetSize() const{return BOARD_DIMS;}
|
||||
constexpr const V3D &GetSize() const{return BOARD_DIMS;}
|
||||
constexpr uint32_t GetNumberCubes() const{return BOARD_DIMS.x * BOARD_DIMS.y * BOARD_DIMS.z;}
|
||||
|
||||
/**
|
||||
@@ -42,7 +37,7 @@ class Board{
|
||||
void SetCubeOccupation(const V3D &position, bool occupation);
|
||||
|
||||
bool BoardStateChanged(){return this->boardStateHasChanged;}
|
||||
void ClearBoardStateChanged(){this->boardStateHasChanged = false;}
|
||||
void SetStateChanged(bool boardState){this->boardStateHasChanged = boardState;}
|
||||
|
||||
/**
|
||||
* @brief Get a column along any axis
|
||||
@@ -51,7 +46,7 @@ class Board{
|
||||
* to fill. IE To fill one stack at 0,2 I would say give V3D(0,2,PLANE_NORMAL::Z)
|
||||
* @returns an array of cubes along that column
|
||||
*/
|
||||
Cube * SliceBoard(const V3D &column);
|
||||
Cube ** SliceBoard(const V3D &column);
|
||||
|
||||
private:
|
||||
// this is a 3d array of cubes to represent the board. Good luck visualizing it
|
||||
@@ -65,36 +60,34 @@ class Board{
|
||||
| | /
|
||||
|____________|/
|
||||
*/
|
||||
std::array<std::array<std::array<Cube, Z_SIZE>, Y_SIZE>, X_SIZE> cubes;
|
||||
std::array<std::array<std::array<Cube, BOARD_DIMS.z>, BOARD_DIMS.y>, BOARD_DIMS.x> cubes;
|
||||
|
||||
bool boardStateHasChanged;
|
||||
};
|
||||
|
||||
template <V3D &BOARD_DIMS>
|
||||
template <const V3D &BOARD_DIMS>
|
||||
Board<BOARD_DIMS>::Board(){
|
||||
this->FillColor(Color(0,0,0));
|
||||
this->FillColor(V3D{});
|
||||
}
|
||||
|
||||
template <V3D &BOARD_DIMS>
|
||||
template <const V3D &BOARD_DIMS>
|
||||
void Board<BOARD_DIMS>::ToStackString(String &stringBuffer) const{
|
||||
std::array<uint32_t, X_SIZE*Y_SIZE> linearizedBoard = this->LinearizeBoard();
|
||||
std::array<uint32_t, BOARD_DIMS.x*BOARD_DIMS.y> linearizedBoard = this->LinearizeBoard();
|
||||
|
||||
stringBuffer += "!" + String(linearizedBoard[0]);
|
||||
stringBuffer += String(linearizedBoard[0]);
|
||||
|
||||
for(uint32_t i = 0; i < X_SIZE * Y_SIZE; i++){
|
||||
for(uint32_t i = 0; i < BOARD_DIMS.x * BOARD_DIMS.y; i++){
|
||||
stringBuffer += "," + String(linearizedBoard[i]);
|
||||
}
|
||||
|
||||
stringBuffer += ";";
|
||||
}
|
||||
|
||||
template <V3D &BOARD_DIMS>
|
||||
template <const V3D &BOARD_DIMS>
|
||||
std::array<uint32_t, BOARD_DIMS.x * BOARD_DIMS.y> & Board<BOARD_DIMS>::LinearizeBoard() const{
|
||||
// convert the board into one array where each entry represents the height of one stack
|
||||
std::array<uint32_t, BOARD_DIMS.x * BOARD_DIMS.y> linearizedBoard;
|
||||
for(uint32_t x{0}; x < X_SIZE; x++){
|
||||
for(uint32_t y{0}; y < Y_SIZE; y++){
|
||||
for(uint32_t z{0}; z < Z_SIZE; z++){
|
||||
for(uint32_t x{0}; x < BOARD_DIMS.x; x++){
|
||||
for(uint32_t y{0}; y < BOARD_DIMS.y; y++){
|
||||
for(uint32_t z{0}; z < BOARD_DIMS.z; z++){
|
||||
bool isOccupied{this->cubes[x][y][z].isOccupied};
|
||||
linearizedBoard[x + y*3] += static_cast<uint32_t>(isOccupied);
|
||||
}
|
||||
@@ -103,63 +96,63 @@ std::array<uint32_t, BOARD_DIMS.x * BOARD_DIMS.y> & Board<BOARD_DIMS>::Linearize
|
||||
return linearizedBoard;
|
||||
}
|
||||
|
||||
template <V3D &BOARD_DIMS>
|
||||
template <const V3D &BOARD_DIMS>
|
||||
void Board<BOARD_DIMS>::FillColor(const V3D &color){
|
||||
for(uint32_t x{0}; x < X_SIZE; x++){
|
||||
for(uint32_t y{0}; y < Y_SIZE; y++){
|
||||
for(uint32_t z{0}; z < Z_SIZE; z++){
|
||||
for(uint32_t x{0}; x < BOARD_DIMS.x; x++){
|
||||
for(uint32_t y{0}; y < BOARD_DIMS.y; y++){
|
||||
for(uint32_t z{0}; z < BOARD_DIMS.z; z++){
|
||||
this->cubes[x][y][z].color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <V3D &BOARD_DIMS>
|
||||
template <const V3D &BOARD_DIMS>
|
||||
void Board<BOARD_DIMS>::SetCubeColor(const V3D &position, const V3D &color){
|
||||
this->cubes[position.x][position.y][position.z].color = color;
|
||||
}
|
||||
|
||||
template <V3D &BOARD_DIMS>
|
||||
template <const V3D &BOARD_DIMS>
|
||||
void Board<BOARD_DIMS>::SetCubeOccupation(const V3D &position, bool occupation){
|
||||
bool oldOccupation{this->cubes[position.x][position.y][position.z].occupied};
|
||||
this->cubes[position.x][position.y][position.z].occupied = occupation;
|
||||
bool oldOccupation{this->cubes[position.x][position.y][position.z].isOccupied};
|
||||
this->cubes[position.x][position.y][position.z].isOccupied = occupation;
|
||||
if(occupation != oldOccupation) this->boardStateHasChanged = true;
|
||||
}
|
||||
|
||||
template <V3D &BOARD_DIMS>
|
||||
Cube * Board<BOARD_DIMS>::SliceBoard(const V3D &column){
|
||||
template <const V3D &BOARD_DIMS>
|
||||
Cube ** Board<BOARD_DIMS>::SliceBoard(const V3D &column){
|
||||
uint32_t columnLength{0};
|
||||
V3D indexIncriment{};
|
||||
V3D position{};
|
||||
switch(column.z){
|
||||
case Board::PLANE_NORMAL::X:
|
||||
case BOARD_TYPES::PLANE_NORMAL::X:
|
||||
columnLength = BOARD_DIMS.x;
|
||||
indexIncriment.x = 1;
|
||||
position.z = column.x;
|
||||
position.y = column.y;
|
||||
break;
|
||||
case Board::PLANE_NORMAL::Y:
|
||||
columnLength = BOARD_DIMS.Y;
|
||||
case BOARD_TYPES::PLANE_NORMAL::Y:
|
||||
columnLength = BOARD_DIMS.y;
|
||||
indexIncriment.y = 1;
|
||||
position.x = column.x;
|
||||
position.z = column.y;
|
||||
break;
|
||||
|
||||
default:
|
||||
case Board::PLANE_NORMAL::Z:
|
||||
columnLength = BOARD_DIMS.Z;
|
||||
case BOARD_TYPES::PLANE_NORMAL::Z:
|
||||
columnLength = BOARD_DIMS.z;
|
||||
indexIncriment.z = 1;
|
||||
position.x = column.x;
|
||||
position.y = column.y;
|
||||
break;
|
||||
}
|
||||
|
||||
std::array<Cube *, columnLength> columnSlice;
|
||||
Cube* columnSlice[columnLength];
|
||||
for(uint32_t i = 0; i < columnLength; i++){
|
||||
V3D cubePosition = indexIncriment * i + position;
|
||||
columnSlice[i] = &(this->cubes[cubePosition.x][cubePosition.y][cubePosition.z]);
|
||||
}
|
||||
|
||||
return columnSlice.data();
|
||||
return columnSlice;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user