Started moving common things in VoxelWorld to c++.

This commit is contained in:
Relintai 2019-08-12 13:12:42 +02:00
parent 2ed334dade
commit b0dc290c20
2 changed files with 69 additions and 1 deletions

View File

@ -1,5 +1,33 @@
#include "voxel_world.h"
int VoxelWorld::get_chunk_size_x() const {
return _chunk_size.x;
}
void VoxelWorld::set_chunk_size_x(const int value) {
_chunk_size.x = value;
}
int VoxelWorld::get_chunk_size_y() const {
return _chunk_size.y;
}
void VoxelWorld::set_chunk_size_y(const int value) {
_chunk_size.y = value;
}
int VoxelWorld::get_chunk_size_z() const {
return _chunk_size.z;
}
void VoxelWorld::set_chunk_size_z(const int value) {
_chunk_size.z = value;
}
Ref<VoxelmanLibrary> VoxelWorld::get_library() const {
return _library;
}
void VoxelWorld::set_library(const ref<VoxelmanLibrary> library) {
_library = library;
}
NodePath VoxelWorld::get_player_path() {
return _player_path;
}
@ -8,11 +36,32 @@ void VoxelWorld::set_player_path(NodePath player_path) {
_player_path = player_path;
}
VoxelWorld::VoxelWorld() {
_chunk_size = Vector3i(16, 16, 16);
}
VoxelWorld ::~VoxelWorld() {
_chunks.clear();
_library.unref();
}
void VoxelWorld::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_chunk_size_x"), &VoxelWorld::get_chunk_size_x);
ClassDB::bind_method(D_METHOD("set_chunk_size_x", "value"), &VoxelWorld::set_chunk_size_x);
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_x"), "set_chunk_size_x", "get_chunk_size_x");
ClassDB::bind_method(D_METHOD("get_chunk_size_y"), &VoxelWorld::get_chunk_size_y);
ClassDB::bind_method(D_METHOD("set_chunk_size_y", "value"), &VoxelWorld::set_chunk_size_y);
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_y"), "set_chunk_size_y", "get_chunk_size_y");
ClassDB::bind_method(D_METHOD("get_chunk_size_z"), &VoxelWorld::get_chunk_size_z);
ClassDB::bind_method(D_METHOD("set_chunk_size_z", "value"), &VoxelWorld::set_chunk_size_z);
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_z"), "set_chunk_size_z", "get_chunk_size_z");
ClassDB::bind_method(D_METHOD("get_library"), &VoxelWorld::get_library);
ClassDB::bind_method(D_METHOD("set_library", "value"), &VoxelWorld::set_library);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE), "set_library", "get_library");
ClassDB::bind_method(D_METHOD("get_player_path"), &VoxelWorld::get_player_path);
ClassDB::bind_method(D_METHOD("set_player_path", "value"), &VoxelWorld::set_player_path);
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "player_path"), "set_player_path", "get_player_path");

View File

@ -5,23 +5,42 @@
#include "core/hash_map.h"
#include "../math/vector3i.h"
#include "../library/voxelman_library.h"
#include "voxel_buffer.h"
class VoxelWorld : public Spatial {
GDCLASS(VoxelWorld, Spatial);
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;
void set_library(const ref<VoxelmanLibrary> library);
NodePath get_player_path();
void set_player_path(NodePath player_path);
VoxelWorld() {}
VoxelWorld();
~VoxelWorld();
protected:
static void _bind_methods();
private:
Vector3i _chunk_size;
Ref<VoxelmanLibrary> _library;
HashMap<Vector3i, Ref<VoxelBuffer> > _chunks;
Vector<Ref<VoxelBuffer> > _chunks_vector;
NodePath _player_path;
Spatial *_player;