aboutsummaryrefslogtreecommitdiff
path: root/src/server/world/chunk.hh
blob: b8fc73ccb1beab5af6a7d03b982e1c26f3a48d49 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef SERVER_WORLD_CHUNK_HH_
#define SERVER_WORLD_CHUNK_HH_

#include <cstdint>

#include "server/database.hh"
#include "server/shared.hh"
#include "shared/entity/player.hh"
#include "shared/math/math.hh"
#include "shared/net/net.hh"
#include "shared/net/proto.hh"
#include "shared/world/chunk.hh"

namespace server {
namespace world {

class chunk : public shared::world::chunk {
private:
    bool should_write = false;
    bool should_update = true;

public:
    proto::packet packet; // Packet ready for sending, updated in update().
    void arm_should_update() noexcept {
        this->should_update = this->should_write = true;
    }

public:
    template <typename... Args>
    chunk(Args&&... args) noexcept
        : shared::world::chunk(std::forward<Args>(args)...) {
        this->pack(packet.mutable_chunk_packet());
    }
    virtual ~chunk() noexcept;

public:
    // Update the chunk_packet associated with the chunk if necessary.
    void update() noexcept;
    // calling .write before the destrutor will not result in a double write
    void write() noexcept;
};

} // namespace world
} // namespace server

#endif