voxelman/world/voxel_world.h

113 lines
2.6 KiB
C
Raw Normal View History

#ifndef VOXEL_WORLD_H
#define VOXEL_WORLD_H
#include "scene/3d/navigation.h"
#include "core/hash_map.h"
#include "../library/voxelman_library.h"
2019-09-03 13:52:32 +02:00
#include "../level_generator/voxelman_level_generator.h"
2019-11-10 01:03:48 +01:00
#include "../areas/world_area.h"
2019-08-12 20:40:05 +02:00
class VoxelChunk;
class VoxelWorld : public Navigation {
GDCLASS(VoxelWorld, Navigation);
public:
int get_chunk_size_x() const;
void set_chunk_size_x(const int value);
int get_chunk_size_y() const;
void set_chunk_size_y(const int value);
int get_chunk_size_z() const;
void set_chunk_size_z(const int value);
Ref<VoxelmanLibrary> get_library() const;
2019-08-12 20:40:05 +02:00
void set_library(const Ref<VoxelmanLibrary> library);
2019-09-03 13:52:32 +02:00
Ref<VoxelmanLevelGenerator> get_level_generator() const;
void set_level_generator(const Ref<VoxelmanLevelGenerator> level_generator);
2019-08-12 20:40:05 +02:00
float get_voxel_scale() const;
void set_voxel_scale(const float value);
int get_chunk_spawn_range() const;
void set_chunk_spawn_range(const int value);
NodePath get_player_path();
void set_player_path(NodePath player_path);
2019-08-12 20:40:05 +02:00
Spatial *get_player() const;
void set_player(Spatial *player);
void set_player_bind(Node *player);
2019-11-10 01:03:48 +01:00
Ref<WorldArea> get_world_area(const int index) const;
void add_world_area(Ref<WorldArea> area);
void remove_world_area(const int index);
void clear_world_areas();
int get_world_area_count() const;
2019-11-06 03:37:22 +01:00
void add_chunk(VoxelChunk *chunk, const int x, const int y, const int z);
void add_chunk_bind(Node *chunk, const int x, const int y, const int z);
VoxelChunk *get_chunk(const int x, const int y, const int z) const;
VoxelChunk *remove_chunk(const int x, const int y, const int z);
2019-08-12 20:40:05 +02:00
2019-11-06 03:37:22 +01:00
VoxelChunk *get_chunk_index(const int index);
2019-08-12 20:40:05 +02:00
int get_chunk_count() const;
void clear_chunks();
VoxelWorld();
~VoxelWorld();
protected:
static void _bind_methods();
2019-11-18 21:53:33 +01:00
struct IntPos {
int x;
int y;
int z;
IntPos() {
x = 0;
y = 0;
z = 0;
}
IntPos(int p_x, int p_y, int p_z) {
x = p_x;
y = p_y;
z = p_z;
}
};
struct IntPosHasher {
static _FORCE_INLINE_ uint32_t hash(const IntPos &v) {
uint32_t hash = hash_djb2_one_32(v.x);
hash = hash_djb2_one_32(v.y, hash);
return hash_djb2_one_32(v.z, hash);
}
};
private:
2019-11-18 21:53:33 +01:00
int _chunk_size_x;
int _chunk_size_y;
int _chunk_size_z;
Ref<VoxelmanLibrary> _library;
2019-09-03 13:52:32 +02:00
Ref<VoxelmanLevelGenerator> _level_generator;
2019-08-12 20:40:05 +02:00
float _voxel_scale;
int _chunk_spawn_range;
2019-11-18 21:53:33 +01:00
HashMap<IntPos, VoxelChunk *, IntPosHasher> _chunks;
2019-11-06 03:37:22 +01:00
Vector<VoxelChunk *> _chunks_vector;
2019-11-10 01:03:48 +01:00
Vector<Ref<WorldArea> > _world_areas;
NodePath _player_path;
Spatial *_player;
};
#endif