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 (#2261)

Credit to TrinityCore
  • Loading branch information
Gamemechanicwow authored Feb 18, 2024
1 parent abf0be6 commit c89aea3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
23 changes: 7 additions & 16 deletions src/game/Maps/Cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "GameSystem/TypeContainer.h"
#include "GameSystem/TypeContainerVisitor.h"
#include "GridDefines.h"
#include <cmath>

class Map;
class WorldObject;
Expand All @@ -49,8 +48,7 @@ struct CellArea

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

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

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

bool operator==(Cell const& cell) const { return (data.All == cell.data.All); }
bool operator!=(Cell const& 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(CellPair const& cellPair, TypeContainerVisitor<T, CONTAINER>& visitor, Map& m, float x, float y, float radius) const;
Expand Down
3 changes: 1 addition & 2 deletions src/game/Maps/CellImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,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 c89aea3

Please sign in to comment.