Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
TileSlotMap.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstdint>
5#include <unordered_map>
6#include <unordered_set>
7
8#include "core/Resources.hpp"
9#include "core/WorldState.hpp"
10
20 public:
22 static std::pair<float, float> slotOffset(int slotIndex);
23
29 std::array<int, 7> updateResourceSlots(int tileX, int tileY, const Resources& resources);
30
35 void syncEggs(const std::unordered_map<int, Egg>& eggs);
36
38 int eggSlot(int eggId) const;
39
41 float resourceRotation(int tileX, int tileY, int resourceType) const;
42
44 void clear();
45
46 private:
47 static constexpr int SLOT_COUNT = 8;
48 static constexpr float CORNER = 0.35f;
49
51 std::array<bool, 8> occupied = {};
52
55 int acquire();
56
58 void release(int slotIndex);
59 };
60
61 std::unordered_map<uint64_t, TileOccupancy> _tileOccupancy;
62 std::unordered_map<uint64_t, int> _resourceSlots; // resourceKey → slot
63 std::unordered_map<uint64_t, float> _resourceRotations; // resourceKey → rotation
64 std::unordered_map<int, int> _eggSlots; // eggId → slot
65 std::unordered_map<int, std::pair<int, int>> _eggTile; // eggId → {x, y}
66 std::unordered_set<int> _knownEggs;
67
68 static uint64_t tileKey(int x, int y);
69 static uint64_t resourceKey(int x, int y, int resourceType);
70};
Manages 8-slot spatial assignment per tile for resources and eggs.
std::unordered_set< int > _knownEggs
static std::pair< float, float > slotOffset(int slotIndex)
Returns the XZ offset pair {dx, dz} for a slot index (0-7).
std::unordered_map< uint64_t, int > _resourceSlots
float resourceRotation(int tileX, int tileY, int resourceType) const
Returns the stable random Y rotation for a resource slot, or 0 if absent.
static uint64_t tileKey(int x, int y)
void syncEggs(const std::unordered_map< int, Egg > &eggs)
Syncs egg slot assignments against the current egg map. Assigns slots to new eggs,...
std::unordered_map< int, std::pair< int, int > > _eggTile
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,...
void clear()
Resets all state. Call on reconnect.
static constexpr int SLOT_COUNT
std::unordered_map< int, int > _eggSlots
static uint64_t resourceKey(int x, int y, int resourceType)
std::unordered_map< uint64_t, float > _resourceRotations
int eggSlot(int eggId) const
Returns the slot index for an egg id, or -1 if unknown.
static constexpr float CORNER
std::unordered_map< uint64_t, TileOccupancy > _tileOccupancy
void release(int slotIndex)
std::array< bool, 8 > occupied