12void Gather(
const Cells& cells,
Cell cell, std::vector<uint32_t>& ids) {
13 if (
const auto found = cells.find(cell); found != cells.end()) {
14 ids.insert(ids.end(), found->second.begin(), found->second.end());
21 return {.x =
static_cast<int>(std::floor(x /
kCellSize)),
22 .z =
static_cast<int>(std::floor(z /
kCellSize))};
30std::map<Cell, View>
Views(
const std::map<uint32_t, Player>& players,
31 const std::map<uint32_t, Monster>& monsters,
36 std::map<Cell, View> views;
37 for (
const auto& [cell, here] : players_in) {
38 View& view = views[cell];
42 const Cell near{.x = cell.x + dx, .z = cell.z + dz};
43 Gather(players_in, near, view.
players);
44 Gather(monsters_in, near, view.
monsters);
45 Gather(npcs, near, view.
npcs);
Cell CellOf(float x, float z)
bool Near(Cell from, Cell to)
Cells CellsOf(const std::map< uint32_t, Unit > &units)
constexpr int kInterestCells
Cells each way, so that a player gets everyone within 64 metres.
constexpr float kCellSize
In metres, like the client's chunks.
std::map< Cell, std::vector< uint32_t > > Cells
The ids of what's in each cell.
std::map< Cell, View > Views(const std::map< uint32_t, Player > &players, const std::map< uint32_t, Monster > &monsters, const Cells &npcs)
What the players in a cell get: the players, monsters and NPCs near it.
std::vector< uint32_t > here
std::vector< uint32_t > monsters
std::vector< uint32_t > players
std::vector< uint32_t > npcs