aboutsummaryrefslogtreecommitdiff
path: root/src/server/chunk_data.hh
blob: eea5cef0101a9f92ccd2b9e32e5b8d3180d55373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef SERVER_CHUNK_DATA_HH_
#define SERVER_CHUNK_DATA_HH_

#include <memory>
#include <optional>
#include <unordered_set>

#include "server/world.hh"
#include "shared/player.hh"

namespace server {

struct chunk_data {
public:
    // nullopt = constructing/destructing via future operations in thread pool
    // we use shared_ptr here to avoid complex moves in boost::asio::post.
    // There is no good reason to use shared_ptr over unique_ptr, other than
    // boost::asio::post requiring copy_constructable args in std::bind. 
    std::optional<std::shared_ptr<server::world::chunk>> chunk;
    // players associated with the chunk
    std::unordered_set<shared::player::index_t> players;

public:
    server::world::chunk& get_chunk() noexcept { return *(*this->chunk); }
    bool has_initialised() const noexcept { return chunk.has_value(); }
};

} // namespace server

#endif