VOX
A little voxel engine
Loading...
Searching...
No Matches
ChunkPacket.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "IPacket.hpp"
4#include "Chunk.hpp"
5
6
7class ChunkPacket : public IPacket
8{
9public:
10 struct ChunkData
11 {
12 ChunkData() = default;
15 {
16 }
17 glm::ivec3 chunk_pos;
21 };
22
24 ChunkPacket(const Chunk & chunk);
26
27 ChunkPacket(ChunkPacket & other);
29 ChunkPacket(ChunkPacket && other);
31
32 void Serialize(uint8_t * buffer) const override;
33 void Deserialize(const uint8_t * buffer) override;
34 uint32_t Size() const override;
35 bool HasDynamicSize() const override;
36 IPacket::Type GetType() const override;
37
38 std::shared_ptr<IPacket> Clone() const override;
39
40 /*******************************
41 * ATTRIBUTES
42 ********************************/
43 std::shared_ptr<Chunk> GetChunk() const;
44
45 void SetChunk(const Chunk & chunk);
46
47private:
48 ChunkData m_chunk_data;
49};
50
Definition: ChunkPacket.hpp:8
ChunkPacket()
Definition: ChunkPacket.cpp:3
ChunkPacket & operator=(ChunkPacket &other)
Definition: ChunkPacket.cpp:27
bool HasDynamicSize() const override
Tell if the packet has a dynamic size.
Definition: ChunkPacket.cpp:74
~ChunkPacket()
Definition: ChunkPacket.cpp:13
IPacket::Type GetType() const override
Get the Type of the packet.
Definition: ChunkPacket.cpp:79
std::shared_ptr< Chunk > GetChunk() const
Definition: ChunkPacket.cpp:89
void Serialize(uint8_t *buffer) const override
will write the packet in the buffer, the buffer must at least be of size Size()
Definition: ChunkPacket.cpp:47
std::shared_ptr< IPacket > Clone() const override
Create a new instance of the packet.
Definition: ChunkPacket.cpp:84
void SetChunk(const Chunk &chunk)
Definition: ChunkPacket.cpp:94
uint32_t Size() const override
return the size of the packet in bytes, usually used to reserve the right amount of memory in the sen...
Definition: ChunkPacket.cpp:69
void Deserialize(const uint8_t *buffer) override
read the packet from the buffer, the buffer must at least be of size Size()
Definition: ChunkPacket.cpp:59
Definition: Chunk.hpp:27
std::array< uint8_t, BLOCKS_PER_CHUNK > LightArray
Definition: Chunk.hpp:69
std::array< biomeInfo, CHUNK_X_SIZE *CHUNK_Z_SIZE > BiomeArray
Definition: Chunk.hpp:73
std::array< BlockInfo::Type, BLOCKS_PER_CHUNK > BlockArray
Definition: Chunk.hpp:68
an abstract class that servers as a base for all network packets
Definition: IPacket.hpp:40
Type
Definition: IPacket.hpp:48
Definition: ChunkPacket.hpp:11
Chunk::BiomeArray biomes
Definition: ChunkPacket.hpp:20
Chunk::LightArray light
Definition: ChunkPacket.hpp:19
glm::ivec3 chunk_pos
Definition: ChunkPacket.hpp:17
Chunk::BlockArray blocks
Definition: ChunkPacket.hpp:18
ChunkData(const glm::ivec3 &chunk_pos, const Chunk::BlockArray &blocks, const Chunk::LightArray &light, const Chunk::BiomeArray &biomes)
Definition: ChunkPacket.hpp:13