blob: 3a383ac9a9ddd0868af5f000759f67c857af4d71 (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#ifndef SHARED_DIMENSION_HH
#define SHARED_DIMENSION_HH 1
#pragma once
#include "shared/const.hh"
#include "shared/types.hh"
namespace io
{
class ConfigMap;
} // namespace io
namespace world
{
class Chunk;
class VoxelStorage;
} // namespace world
namespace world
{
using dimension_entropy_map = std::array<std::uint64_t, CHUNK_AREA>;
using dimension_height_map = std::array<voxel_pos::value_type, CHUNK_AREA>;
} // namespace world
namespace world
{
class Dimension {
public:
explicit Dimension(std::string_view name, float gravity);
virtual ~Dimension(void);
std::string_view get_name(void) const;
float get_gravity(void) const;
public:
Chunk* create_chunk(const chunk_pos& cpos);
Chunk* find_chunk(entt::entity entity) const;
Chunk* find_chunk(const chunk_pos& cpos) const;
void remove_chunk(entt::entity entity);
void remove_chunk(const chunk_pos& cpos);
void remove_chunk(Chunk* chunk);
public:
voxel_id get_voxel(const voxel_pos& vpos) const;
voxel_id get_voxel(const chunk_pos& cpos, const local_pos& lpos) const;
bool set_voxel(voxel_id voxel, const voxel_pos& vpos);
bool set_voxel(voxel_id voxel, const chunk_pos& cpos, const local_pos& lpos);
public:
virtual void init(io::ConfigMap& config);
virtual void init_late(std::uint64_t global_seed);
virtual bool generate(const chunk_pos& cpos, VoxelStorage& voxels);
public:
entt::registry chunks;
entt::registry entities;
private:
std::string m_name;
emhash8::HashMap<chunk_pos, Chunk*> m_chunkmap;
float m_gravity;
};
} // namespace world
namespace world
{
struct ChunkComponent final {
chunk_pos cpos;
Chunk* chunk;
};
} // namespace world
namespace world
{
struct ChunkCreateEvent final {
Dimension* dimension;
chunk_pos cpos;
Chunk* chunk;
};
struct ChunkDestroyEvent final {
Dimension* dimension;
chunk_pos cpos;
Chunk* chunk;
};
struct ChunkUpdateEvent final {
Dimension* dimension;
chunk_pos cpos;
Chunk* chunk;
};
struct VoxelSetEvent final {
Dimension* dimension;
chunk_pos cpos;
local_pos lpos;
voxel_id voxel;
Chunk* chunk;
};
} // namespace world
#endif // SHARED_DIMENSION_HH
|