diff options
| author | untodesu <kirill@untode.su> | 2025-03-15 16:22:09 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-03-15 16:22:09 +0500 |
| commit | 3bf42c6ff3805a0d42bbc661794a95ff31bedc26 (patch) | |
| tree | 05049955847504808d6bed2bb7b155f8b03807bb /game/shared/dimension.hh | |
| parent | 02294547dcde0d4ad76e229106702261e9f10a51 (diff) | |
| download | voxelius-3bf42c6ff3805a0d42bbc661794a95ff31bedc26.tar.bz2 voxelius-3bf42c6ff3805a0d42bbc661794a95ff31bedc26.zip | |
Add whatever I was working on for the last month
Diffstat (limited to 'game/shared/dimension.hh')
| -rw-r--r-- | game/shared/dimension.hh | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/game/shared/dimension.hh b/game/shared/dimension.hh new file mode 100644 index 0000000..eb6f896 --- /dev/null +++ b/game/shared/dimension.hh @@ -0,0 +1,81 @@ +#ifndef SHARED_DIMENSION_HH +#define SHARED_DIMENSION_HH 1 +#pragma once + +#include "shared/types.hh" + +class Chunk; +class Config; +class VoxelStorage; + +class Dimension { +public: + explicit Dimension(const char *name, float gravity); + virtual ~Dimension(void); + + const char *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(Config &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_hashmap; + float m_gravity; +}; + +struct ChunkComponent final { + chunk_pos cpos; + Chunk *chunk; +}; + +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; +}; + +#endif /* SHARED_DIMENSION_HH */ |
