Added WorldArea.

This commit is contained in:
Relintai 2019-11-10 01:03:48 +01:00
parent 7ee2017568
commit f0cd4008fc
6 changed files with 150 additions and 0 deletions

2
SCsub
View File

@ -59,3 +59,5 @@ env.add_source_files(env.modules_sources,"world_generator/data/world_generator_p
env.add_source_files(env.modules_sources,"world_generator/world_generator.cpp")
env.add_source_files(env.modules_sources,"areas/world_area.cpp")

65
areas/world_area.cpp Normal file
View File

@ -0,0 +1,65 @@
#include "world_area.h"
AABB WorldArea::get_aabb() const {
return _aabb;
}
void WorldArea::set_aabb(const AABB value) {
_aabb = value;
}
Ref<Texture> WorldArea::get_map_texture() const {
return _map_texture;
}
void WorldArea::set_map_texture(const Ref<Texture> value) {
_map_texture = value;
}
Ref<Texture> WorldArea::get_fov_texture() const {
return _fov_texture;
}
void WorldArea::set_fov_texture(const Ref<Texture> value) {
_fov_texture = value;
}
String WorldArea::get_name() const {
return _name;
}
void WorldArea::set_name(const String value) {
_name = value;
}
int WorldArea::get_level() const {
return _level;
}
void WorldArea::set_level(const int level) {
_level = level;
}
WorldArea::WorldArea() {
_level = 0;
}
WorldArea::~WorldArea() {
}
void WorldArea::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_aabb"), &WorldArea::get_aabb);
ClassDB::bind_method(D_METHOD("set_aabb"), &WorldArea::set_aabb);
ADD_PROPERTY(PropertyInfo(Variant::AABB, "aabb"), "set_aabb", "get_aabb");
ClassDB::bind_method(D_METHOD("get_map_texture"), &WorldArea::get_map_texture);
ClassDB::bind_method(D_METHOD("set_map_texture"), &WorldArea::set_map_texture);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "map_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_map_texture", "get_map_texture");
ClassDB::bind_method(D_METHOD("get_fov_texture"), &WorldArea::get_fov_texture);
ClassDB::bind_method(D_METHOD("set_fov_texture"), &WorldArea::set_fov_texture);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fov_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_fov_texture", "get_fov_texture");
ClassDB::bind_method(D_METHOD("get_name"), &WorldArea::get_name);
ClassDB::bind_method(D_METHOD("set_name"), &WorldArea::set_name);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "name"), "set_name", "get_name");
ClassDB::bind_method(D_METHOD("get_level"), &WorldArea::get_level);
ClassDB::bind_method(D_METHOD("set_level"), &WorldArea::set_level);
ADD_PROPERTY(PropertyInfo(Variant::INT, "level"), "set_level", "get_level");
}

43
areas/world_area.h Normal file
View File

@ -0,0 +1,43 @@
#ifndef WORLD_AREA_H
#define WORLD_AREA_H
#include "core/reference.h"
#include "core/ustring.h"
#include "core/math/aabb.h"
#include "scene/resources/texture.h"
class WorldArea : public Reference {
GDCLASS(WorldArea, Reference);
public:
AABB get_aabb() const;
void set_aabb(const AABB value);
Ref<Texture> get_map_texture() const;
void set_map_texture(const Ref<Texture> value);
Ref<Texture> get_fov_texture() const;
void set_fov_texture(const Ref<Texture> value);
String get_name() const;
void set_name(const String value);
int get_level() const;
void set_level(const int value);
WorldArea();
~WorldArea();
private:
static void _bind_methods();
private:
AABB _aabb;
Ref<Texture> _map_texture;
Ref<Texture> _fov_texture;
String _name;
int _level;
};
#endif

View File

@ -49,6 +49,8 @@
#include "world_generator/world_generator.h"
#include "areas/world_area.h"
void register_voxelman_types() {
ClassDB::register_class<VoxelMesher>();
@ -100,6 +102,8 @@ void register_voxelman_types() {
ClassDB::register_class<Planet>();
ClassDB::register_class<WorldGenerator>();
ClassDB::register_class<WorldArea>();
}
void unregister_voxelman_types() {

View File

@ -69,6 +69,26 @@ void VoxelWorld::set_player_bind(Node *player) {
set_player(Object::cast_to<Spatial>(player));
}
Ref<WorldArea> VoxelWorld::get_world_area(const int index) const {
ERR_FAIL_INDEX_V(index, _world_areas.size(), Ref<WorldArea>());
return _world_areas.get(index);
}
void VoxelWorld::add_world_area(Ref<WorldArea> area) {
_world_areas.push_back(area);
}
void VoxelWorld::remove_world_area(const int index) {
ERR_FAIL_INDEX(index, _world_areas.size());
_world_areas.remove(index);
}
void VoxelWorld::clear_world_areas() {
_world_areas.clear();
}
int VoxelWorld::get_world_area_count() const {
return _world_areas.size();
}
void VoxelWorld::add_chunk(VoxelChunk *chunk, const int x, const int y, const int z) {
chunk->set_chunk_position(x, y, z);
@ -135,6 +155,7 @@ VoxelWorld::VoxelWorld() {
VoxelWorld ::~VoxelWorld() {
_chunks.clear();
_chunks_vector.clear();
_world_areas.clear();
_library.unref();
}
@ -176,6 +197,12 @@ void VoxelWorld::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_player", "player"), &VoxelWorld::set_player_bind);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "player", PROPERTY_HINT_RESOURCE_TYPE, "Spatial"), "set_player", "get_player");
ClassDB::bind_method(D_METHOD("get_world_area", "index"), &VoxelWorld::get_world_area);
ClassDB::bind_method(D_METHOD("add_world_area", "area"), &VoxelWorld::add_world_area);
ClassDB::bind_method(D_METHOD("remove_world_area", "index"), &VoxelWorld::remove_world_area);
ClassDB::bind_method(D_METHOD("clear_world_areas"), &VoxelWorld::clear_world_areas);
ClassDB::bind_method(D_METHOD("get_world_area_count"), &VoxelWorld::get_world_area_count);
ClassDB::bind_method(D_METHOD("add_chunk", "chunk", "x", "y", "z"), &VoxelWorld::add_chunk_bind);
ClassDB::bind_method(D_METHOD("get_chunk", "x", "y", "z"), &VoxelWorld::get_chunk);
ClassDB::bind_method(D_METHOD("remove_chunk", "x", "y", "z"), &VoxelWorld::remove_chunk);

View File

@ -8,6 +8,7 @@
#include "../library/voxelman_library.h"
#include "../level_generator/voxelman_level_generator.h"
#include "voxel_buffer.h"
#include "../areas/world_area.h"
class VoxelChunk;
@ -43,6 +44,12 @@ public:
void set_player(Spatial *player);
void set_player_bind(Node *player);
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;
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;
@ -69,6 +76,8 @@ private:
HashMap<Vector3i, VoxelChunk *, Vector3iHasher> _chunks;
Vector<VoxelChunk *> _chunks_vector;
Vector<Ref<WorldArea> > _world_areas;
NodePath _player_path;
Spatial *_player;
};