Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
TileSlotMap Class Reference

Manages 8-slot spatial assignment per tile for resources and eggs. More...

#include <TileSlotMap.hpp>

+ Collaboration diagram for TileSlotMap:

Classes

struct  TileOccupancy
 

Public Member Functions

std::array< int, 7 > updateResourceSlots (int tileX, int tileY, const Resources &resources)
 Updates slot assignments for all resource types on a tile. Assigns a slot when count goes 0→nonzero, releases when nonzero→0.
 
void syncEggs (const std::unordered_map< int, Egg > &eggs)
 Syncs egg slot assignments against the current egg map. Assigns slots to new eggs, releases slots for eggs that have disappeared.
 
int eggSlot (int eggId) const
 Returns the slot index for an egg id, or -1 if unknown.
 
float resourceRotation (int tileX, int tileY, int resourceType) const
 Returns the stable random Y rotation for a resource slot, or 0 if absent.
 
void clear ()
 Resets all state. Call on reconnect.
 

Static Public Member Functions

static std::pair< float, float > slotOffset (int slotIndex)
 Returns the XZ offset pair {dx, dz} for a slot index (0-7).
 

Static Private Member Functions

static uint64_t tileKey (int x, int y)
 
static uint64_t resourceKey (int x, int y, int resourceType)
 

Private Attributes

std::unordered_map< uint64_t, TileOccupancy_tileOccupancy
 
std::unordered_map< uint64_t, int > _resourceSlots
 
std::unordered_map< uint64_t, float > _resourceRotations
 
std::unordered_map< int, int > _eggSlots
 
std::unordered_map< int, std::pair< int, int > > _eggTile
 
std::unordered_set< int > _knownEggs
 

Static Private Attributes

static constexpr int SLOT_COUNT = 8
 
static constexpr float CORNER = 0.35f
 

Detailed Description

Manages 8-slot spatial assignment per tile for resources and eggs.

Slots are shared between resource types and eggs on the same tile so they never overlap each other or the player-reserved tile center. Slot assignment is detected frame-by-frame from world state changes, mirroring the pattern of the old _resourcePositions cache.

Definition at line 19 of file TileSlotMap.hpp.

Member Function Documentation

◆ clear()

void TileSlotMap::clear ( )

Resets all state. Call on reconnect.

Definition at line 116 of file TileSlotMap.cpp.

References _eggSlots, _eggTile, _knownEggs, _resourceRotations, _resourceSlots, and _tileOccupancy.

Referenced by RaylibRenderer::init().

+ Here is the caller graph for this function:

◆ eggSlot()

int TileSlotMap::eggSlot ( int  eggId) const

Returns the slot index for an egg id, or -1 if unknown.

Definition at line 104 of file TileSlotMap.cpp.

References _eggSlots.

Referenced by RaylibRenderer::_drawSelectionHighlight(), RaylibRenderer::_render3D(), and SelectionFinder::findFromRay().

+ Here is the caller graph for this function:

◆ resourceKey()

uint64_t TileSlotMap::resourceKey ( int  x,
int  y,
int  resourceType 
)
staticprivate

Definition at line 39 of file TileSlotMap.cpp.

Referenced by resourceRotation(), and updateResourceSlots().

+ Here is the caller graph for this function:

◆ resourceRotation()

float TileSlotMap::resourceRotation ( int  tileX,
int  tileY,
int  resourceType 
) const

Returns the stable random Y rotation for a resource slot, or 0 if absent.

Definition at line 110 of file TileSlotMap.cpp.

References _resourceRotations, and resourceKey().

Referenced by RaylibRenderer::_render3D().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ slotOffset()

std::pair< float, float > TileSlotMap::slotOffset ( int  slotIndex)
static

Returns the XZ offset pair {dx, dz} for a slot index (0-7).

Definition at line 16 of file TileSlotMap.cpp.

References SLOT_OFFSETS.

Referenced by RaylibRenderer::_drawSelectionHighlight(), RaylibRenderer::_render3D(), EntityRenderer::drawResources(), and SelectionFinder::findFromRay().

+ Here is the caller graph for this function:

◆ syncEggs()

void TileSlotMap::syncEggs ( const std::unordered_map< int, Egg > &  eggs)

Syncs egg slot assignments against the current egg map. Assigns slots to new eggs, releases slots for eggs that have disappeared.

Definition at line 74 of file TileSlotMap.cpp.

References _eggSlots, _eggTile, _knownEggs, _tileOccupancy, and tileKey().

Referenced by RaylibRenderer::_render3D().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tileKey()

uint64_t TileSlotMap::tileKey ( int  x,
int  y 
)
staticprivate

Definition at line 34 of file TileSlotMap.cpp.

Referenced by syncEggs(), and updateResourceSlots().

+ Here is the caller graph for this function:

◆ updateResourceSlots()

std::array< int, 7 > TileSlotMap::updateResourceSlots ( int  tileX,
int  tileY,
const Resources resources 
)

Updates slot assignments for all resource types on a tile. Assigns a slot when count goes 0→nonzero, releases when nonzero→0.

Returns
Slot index per resource type; -1 if that resource is absent.

Definition at line 46 of file TileSlotMap.cpp.

References _resourceRotations, _resourceSlots, _tileOccupancy, resourceKey(), and tileKey().

Referenced by RaylibRenderer::_render3D().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _eggSlots

std::unordered_map<int, int> TileSlotMap::_eggSlots
private

Definition at line 64 of file TileSlotMap.hpp.

Referenced by clear(), eggSlot(), and syncEggs().

◆ _eggTile

std::unordered_map<int, std::pair<int, int> > TileSlotMap::_eggTile
private

Definition at line 65 of file TileSlotMap.hpp.

Referenced by clear(), and syncEggs().

◆ _knownEggs

std::unordered_set<int> TileSlotMap::_knownEggs
private

Definition at line 66 of file TileSlotMap.hpp.

Referenced by clear(), and syncEggs().

◆ _resourceRotations

std::unordered_map<uint64_t, float> TileSlotMap::_resourceRotations
private

Definition at line 63 of file TileSlotMap.hpp.

Referenced by clear(), resourceRotation(), and updateResourceSlots().

◆ _resourceSlots

std::unordered_map<uint64_t, int> TileSlotMap::_resourceSlots
private

Definition at line 62 of file TileSlotMap.hpp.

Referenced by clear(), and updateResourceSlots().

◆ _tileOccupancy

std::unordered_map<uint64_t, TileOccupancy> TileSlotMap::_tileOccupancy
private

Definition at line 61 of file TileSlotMap.hpp.

Referenced by clear(), syncEggs(), and updateResourceSlots().

◆ CORNER

constexpr float TileSlotMap::CORNER = 0.35f
staticconstexprprivate

Definition at line 48 of file TileSlotMap.hpp.

◆ SLOT_COUNT

constexpr int TileSlotMap::SLOT_COUNT = 8
staticconstexprprivate

Definition at line 47 of file TileSlotMap.hpp.


The documentation for this class was generated from the following files: