Skip to content

Commit

Permalink
Align Cell.data.Part fields by 8 bits and enlarge Cell structure to 8…
Browse files Browse the repository at this point in the history
… bytes (#83)
  • Loading branch information
i-am-fyre authored Feb 20, 2024
1 parent a0651b3 commit 0fb4829
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
22 changes: 7 additions & 15 deletions src/game/WorldHandlers/Cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ struct CellArea

struct Cell
{
Cell() { data.All = 0; }
Cell(const Cell& cell) { data.All = cell.data.All; }
Cell() : data() { };
explicit Cell(CellPair const& p);

void Compute(uint32& x, uint32& y) const
Expand Down Expand Up @@ -88,26 +87,19 @@ struct Cell
data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y);
}

Cell& operator=(const Cell& cell)
{
data.All = cell.data.All;
return *this;
}

bool operator==(const Cell& cell) const { return (data.All == cell.data.All); }
bool operator!=(const Cell& cell) const { return !operator==(cell); }
union
{
struct
{
unsigned grid_x : 6;
unsigned grid_y : 6;
unsigned cell_x : 6;
unsigned cell_y : 6;
unsigned nocreate : 1;
unsigned reserved : 7;
uint8 grid_x : 8;
uint8 grid_y : 8;
uint8 cell_x : 8;
uint8 cell_y : 8;
uint8 nocreate : 8;
} Part;
uint32 All;
uint64 All;
} data;

template<class T, class CONTAINER> void Visit(const CellPair& cellPair, TypeContainerVisitor<T, CONTAINER> &visitor, Map& m, float x, float y, float radius) const;
Expand Down
3 changes: 1 addition & 2 deletions src/game/WorldHandlers/CellImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
#include "Map.h"
#include <cmath>

inline Cell::Cell(CellPair const& p)
inline Cell::Cell(CellPair const& p) : data()
{
data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS;
data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS;
data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS;
data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS;
data.Part.nocreate = 0;
data.Part.reserved = 0;
}

inline CellArea Cell::CalculateCellArea(float x, float y, float radius)
Expand Down

0 comments on commit 0fb4829

Please sign in to comment.