From f0cd4008fc2ea3c00b401a1a4afa4ce1cf3db489 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 10 Nov 2019 01:03:48 +0100 Subject: [PATCH] Added WorldArea. --- SCsub | 2 ++ areas/world_area.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++ areas/world_area.h | 43 ++++++++++++++++++++++++++++ register_types.cpp | 4 +++ world/voxel_world.cpp | 27 ++++++++++++++++++ world/voxel_world.h | 9 ++++++ 6 files changed, 150 insertions(+) create mode 100644 areas/world_area.cpp create mode 100644 areas/world_area.h diff --git a/SCsub b/SCsub index a9b6d75..ad65a71 100644 --- a/SCsub +++ b/SCsub @@ -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") + diff --git a/areas/world_area.cpp b/areas/world_area.cpp new file mode 100644 index 0000000..6bd5c2c --- /dev/null +++ b/areas/world_area.cpp @@ -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 WorldArea::get_map_texture() const { + return _map_texture; +} +void WorldArea::set_map_texture(const Ref value) { + _map_texture = value; +} + +Ref WorldArea::get_fov_texture() const { + return _fov_texture; +} +void WorldArea::set_fov_texture(const Ref 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"); +} diff --git a/areas/world_area.h b/areas/world_area.h new file mode 100644 index 0000000..ad6e787 --- /dev/null +++ b/areas/world_area.h @@ -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 get_map_texture() const; + void set_map_texture(const Ref value); + + Ref get_fov_texture() const; + void set_fov_texture(const Ref 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 _map_texture; + Ref _fov_texture; + String _name; + int _level; +}; + +#endif diff --git a/register_types.cpp b/register_types.cpp index 9aecbeb..3fdf5ba 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -49,6 +49,8 @@ #include "world_generator/world_generator.h" +#include "areas/world_area.h" + void register_voxelman_types() { ClassDB::register_class(); @@ -100,6 +102,8 @@ void register_voxelman_types() { ClassDB::register_class(); ClassDB::register_class(); + + ClassDB::register_class(); } void unregister_voxelman_types() { diff --git a/world/voxel_world.cpp b/world/voxel_world.cpp index 19afe84..70955de 100644 --- a/world/voxel_world.cpp +++ b/world/voxel_world.cpp @@ -69,6 +69,26 @@ void VoxelWorld::set_player_bind(Node *player) { set_player(Object::cast_to(player)); } +Ref VoxelWorld::get_world_area(const int index) const { + ERR_FAIL_INDEX_V(index, _world_areas.size(), Ref()); + + return _world_areas.get(index); +} +void VoxelWorld::add_world_area(Ref 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); diff --git a/world/voxel_world.h b/world/voxel_world.h index 42e5484..3ba5325 100644 --- a/world/voxel_world.h +++ b/world/voxel_world.h @@ -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 get_world_area(const int index) const; + void add_world_area(Ref 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 _chunks; Vector _chunks_vector; + Vector > _world_areas; + NodePath _player_path; Spatial *_player; };