mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-22 10:57:30 +01:00
Moved more properties.
This commit is contained in:
parent
b0dc290c20
commit
34e109a54b
20
meshes/mesh_registry.cpp
Normal file
20
meshes/mesh_registry.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "mesh_data_resource.h"
|
||||||
|
|
||||||
|
Array MeshDataResource::get_array() {
|
||||||
|
return _arrays;
|
||||||
|
}
|
||||||
|
void MeshDataResource::set_array(const Array &p_arrays) {
|
||||||
|
_arrays.clear();
|
||||||
|
|
||||||
|
_arrays = p_arrays.duplicate(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
MeshDataResource::MeshDataResource() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeshDataResource::_bind_methods() {
|
||||||
|
ClassDB::bind_method(D_METHOD("get_array"), &MeshDataResource::get_array);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_array", "array"), &MeshDataResource::set_array);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "array"), "set_array", "get_array");
|
||||||
|
}
|
27
meshes/mesh_registry.h
Normal file
27
meshes/mesh_registry.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef PROP_MESH_DATA_REOURCE_H
|
||||||
|
#define PROP_MESH_DATA_REOURCE_H
|
||||||
|
|
||||||
|
#include "core/resource.h"
|
||||||
|
#include "core/array.h"
|
||||||
|
#include "scene/resources/mesh.h"
|
||||||
|
|
||||||
|
class PropMeshDataResource : public Resource {
|
||||||
|
|
||||||
|
GDCLASS(PropMeshDataResource, Resource);
|
||||||
|
RES_BASE_EXTENSION("pmdres");
|
||||||
|
|
||||||
|
public:
|
||||||
|
Array get_array();
|
||||||
|
void set_array(const Array &p_arrays);
|
||||||
|
|
||||||
|
PropMeshDataResource();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void _bind_methods();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Array _arrays;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -1,5 +1,7 @@
|
|||||||
#include "voxel_chunk.h"
|
#include "voxel_chunk.h"
|
||||||
|
|
||||||
|
#include "voxel_world.h"
|
||||||
|
|
||||||
int VoxelChunk::get_chunk_position_x() {
|
int VoxelChunk::get_chunk_position_x() {
|
||||||
return _chunk_position.x;
|
return _chunk_position.x;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
#include "../props/voxelman_prop.h"
|
#include "../props/voxelman_prop.h"
|
||||||
#include "../props/voxelman_prop_data.h"
|
#include "../props/voxelman_prop_data.h"
|
||||||
|
|
||||||
|
class VoxelWorld;
|
||||||
|
|
||||||
class VoxelChunk : public Reference {
|
class VoxelChunk : public Reference {
|
||||||
GDCLASS(VoxelChunk, Reference);
|
GDCLASS(VoxelChunk, Reference);
|
||||||
|
|
||||||
|
@ -1,31 +1,47 @@
|
|||||||
#include "voxel_world.h"
|
#include "voxel_world.h"
|
||||||
|
|
||||||
|
#include "voxel_chunk.h"
|
||||||
|
|
||||||
int VoxelWorld::get_chunk_size_x() const {
|
int VoxelWorld::get_chunk_size_x() const {
|
||||||
return _chunk_size.x;
|
return _chunk_size.x;
|
||||||
}
|
}
|
||||||
void VoxelWorld::set_chunk_size_x(const int value) {
|
void VoxelWorld::set_chunk_size_x(const int value) {
|
||||||
_chunk_size.x = value;
|
_chunk_size.x = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VoxelWorld::get_chunk_size_y() const {
|
int VoxelWorld::get_chunk_size_y() const {
|
||||||
return _chunk_size.y;
|
return _chunk_size.y;
|
||||||
}
|
}
|
||||||
void VoxelWorld::set_chunk_size_y(const int value) {
|
void VoxelWorld::set_chunk_size_y(const int value) {
|
||||||
_chunk_size.y = value;
|
_chunk_size.y = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VoxelWorld::get_chunk_size_z() const {
|
int VoxelWorld::get_chunk_size_z() const {
|
||||||
return _chunk_size.z;
|
return _chunk_size.z;
|
||||||
}
|
}
|
||||||
void VoxelWorld::set_chunk_size_z(const int value) {
|
void VoxelWorld::set_chunk_size_z(const int value) {
|
||||||
_chunk_size.z = value;
|
_chunk_size.z = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<VoxelmanLibrary> VoxelWorld::get_library() const {
|
Ref<VoxelmanLibrary> VoxelWorld::get_library() const {
|
||||||
return _library;
|
return _library;
|
||||||
}
|
}
|
||||||
void VoxelWorld::set_library(const ref<VoxelmanLibrary> library) {
|
void VoxelWorld::set_library(const Ref<VoxelmanLibrary> library) {
|
||||||
_library = library;
|
_library = library;
|
||||||
|
}
|
||||||
|
|
||||||
|
float VoxelWorld::get_voxel_scale() const {
|
||||||
|
return _voxel_scale;
|
||||||
|
}
|
||||||
|
void VoxelWorld::set_voxel_scale(const float value) {
|
||||||
|
_voxel_scale = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int VoxelWorld::get_chunk_spawn_range() const {
|
||||||
|
return _chunk_spawn_range;
|
||||||
|
}
|
||||||
|
void VoxelWorld::set_chunk_spawn_range(const int value) {
|
||||||
|
_chunk_spawn_range = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodePath VoxelWorld::get_player_path() {
|
NodePath VoxelWorld::get_player_path() {
|
||||||
@ -36,33 +52,118 @@ void VoxelWorld::set_player_path(NodePath player_path) {
|
|||||||
_player_path = player_path;
|
_player_path = player_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spatial *VoxelWorld::get_player() const {
|
||||||
|
return _player;
|
||||||
|
}
|
||||||
|
void VoxelWorld::set_player(Spatial *player) {
|
||||||
|
_player = player;
|
||||||
|
}
|
||||||
|
void VoxelWorld::set_player_bind(Node *player) {
|
||||||
|
set_player(Object::cast_to<Spatial>(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoxelWorld::add_chunk(Ref<VoxelChunk> chunk, const int x, const int y, const int z) {
|
||||||
|
chunk->set_chunk_position(x, y, z);
|
||||||
|
|
||||||
|
_chunks.set(Vector3i(x, y, z), chunk);
|
||||||
|
_chunks_vector.push_back(chunk);
|
||||||
|
}
|
||||||
|
Ref<VoxelChunk> VoxelWorld::get_chunk(const int x, const int y, const int z) const {
|
||||||
|
const Ref<VoxelChunk> *chunk = _chunks.getptr(Vector3i(x, y, z));
|
||||||
|
|
||||||
|
return Ref<VoxelChunk>(chunk);
|
||||||
|
}
|
||||||
|
Ref<VoxelChunk> VoxelWorld::remove_chunk(const int x, const int y, const int z) {
|
||||||
|
Ref<VoxelChunk> *chunk = _chunks.getptr(Vector3i(x, y, z));
|
||||||
|
|
||||||
|
Ref<VoxelChunk> c(chunk);
|
||||||
|
|
||||||
|
if (c.is_valid()) {
|
||||||
|
|
||||||
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
||||||
|
if (_chunks_vector.get(i) == c) {
|
||||||
|
_chunks_vector.remove(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<VoxelChunk> VoxelWorld::get_chunk_index(const int index) {
|
||||||
|
return _chunks_vector.get(index);
|
||||||
|
}
|
||||||
|
int VoxelWorld::get_chunk_count() const {
|
||||||
|
return _chunks_vector.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoxelWorld::clear_chunks() {
|
||||||
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
||||||
|
_chunks_vector.get(i)->free_chunk();
|
||||||
|
}
|
||||||
|
|
||||||
|
_chunks_vector.clear();
|
||||||
|
|
||||||
|
_chunks.clear();
|
||||||
|
}
|
||||||
|
|
||||||
VoxelWorld::VoxelWorld() {
|
VoxelWorld::VoxelWorld() {
|
||||||
_chunk_size = Vector3i(16, 16, 16);
|
_chunk_size = Vector3i(16, 16, 16);
|
||||||
|
|
||||||
|
_voxel_scale = 1;
|
||||||
|
_chunk_spawn_range = 4;
|
||||||
|
|
||||||
|
_player_path;
|
||||||
|
_player = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelWorld ::~VoxelWorld() {
|
VoxelWorld ::~VoxelWorld() {
|
||||||
_chunks.clear();
|
_chunks.clear();
|
||||||
_library.unref();
|
_chunks_vector.clear();
|
||||||
|
|
||||||
|
_library.unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelWorld::_bind_methods() {
|
void VoxelWorld::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("get_chunk_size_x"), &VoxelWorld::get_chunk_size_x);
|
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);
|
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");
|
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("get_chunk_size_y"), &VoxelWorld::get_chunk_size_y);
|
||||||
ClassDB::bind_method(D_METHOD("set_chunk_size_y", "value"), &VoxelWorld::set_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");
|
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("get_chunk_size_z"), &VoxelWorld::get_chunk_size_z);
|
||||||
ClassDB::bind_method(D_METHOD("set_chunk_size_z", "value"), &VoxelWorld::set_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");
|
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("get_library"), &VoxelWorld::get_library);
|
||||||
ClassDB::bind_method(D_METHOD("set_library", "value"), &VoxelWorld::set_library);
|
ClassDB::bind_method(D_METHOD("set_library", "library"), &VoxelWorld::set_library);
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE), "set_library", "get_library");
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanLibrary"), "set_library", "get_library");
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_voxel_scale"), &VoxelWorld::get_voxel_scale);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_voxel_scale", "value"), &VoxelWorld::set_voxel_scale);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "voxel_scale"), "set_voxel_scale", "get_voxel_scale");
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_chunk_spawn_range"), &VoxelWorld::get_chunk_spawn_range);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_chunk_spawn_range", "value"), &VoxelWorld::set_chunk_spawn_range);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_spawn_range"), "set_chunk_spawn_range", "get_chunk_spawn_range");
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_player_path"), &VoxelWorld::get_player_path);
|
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);
|
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");
|
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "player_path"), "set_player_path", "get_player_path");
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_player"), &VoxelWorld::get_player);
|
||||||
|
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("add_chunk", "chunk", "x", "y", "z"), &VoxelWorld::add_chunk);
|
||||||
|
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);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_chunk_index", "index"), &VoxelWorld::get_chunk_index);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_chunk_count"), &VoxelWorld::get_chunk_count);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("clear_chunks"), &VoxelWorld::clear_chunks);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include "../library/voxelman_library.h"
|
#include "../library/voxelman_library.h"
|
||||||
#include "voxel_buffer.h"
|
#include "voxel_buffer.h"
|
||||||
|
|
||||||
|
class VoxelChunk;
|
||||||
|
|
||||||
class VoxelWorld : public Spatial {
|
class VoxelWorld : public Spatial {
|
||||||
GDCLASS(VoxelWorld, Spatial);
|
GDCLASS(VoxelWorld, Spatial);
|
||||||
|
|
||||||
@ -22,12 +24,29 @@ public:
|
|||||||
void set_chunk_size_z(const int value);
|
void set_chunk_size_z(const int value);
|
||||||
|
|
||||||
Ref<VoxelmanLibrary> get_library() const;
|
Ref<VoxelmanLibrary> get_library() const;
|
||||||
void set_library(const ref<VoxelmanLibrary> library);
|
void set_library(const Ref<VoxelmanLibrary> library);
|
||||||
|
|
||||||
|
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();
|
NodePath get_player_path();
|
||||||
void set_player_path(NodePath player_path);
|
void set_player_path(NodePath player_path);
|
||||||
|
|
||||||
|
Spatial *get_player() const;
|
||||||
|
void set_player(Spatial *player);
|
||||||
|
void set_player_bind(Node *player);
|
||||||
|
|
||||||
|
void add_chunk(Ref<VoxelChunk> chunk, const int x, const int y, const int z);
|
||||||
|
Ref<VoxelChunk> get_chunk(const int x, const int y, const int z) const;
|
||||||
|
Ref<VoxelChunk> remove_chunk(const int x, const int y, const int z);
|
||||||
|
|
||||||
|
Ref<VoxelChunk> get_chunk_index(const int index);
|
||||||
|
int get_chunk_count() const;
|
||||||
|
|
||||||
|
void clear_chunks();
|
||||||
|
|
||||||
VoxelWorld();
|
VoxelWorld();
|
||||||
~VoxelWorld();
|
~VoxelWorld();
|
||||||
@ -38,9 +57,11 @@ protected:
|
|||||||
private:
|
private:
|
||||||
Vector3i _chunk_size;
|
Vector3i _chunk_size;
|
||||||
Ref<VoxelmanLibrary> _library;
|
Ref<VoxelmanLibrary> _library;
|
||||||
|
float _voxel_scale;
|
||||||
|
int _chunk_spawn_range;
|
||||||
|
|
||||||
HashMap<Vector3i, Ref<VoxelBuffer> > _chunks;
|
HashMap<Vector3i, Ref<VoxelChunk>, Vector3iHasher> _chunks;
|
||||||
Vector<Ref<VoxelBuffer> > _chunks_vector;
|
Vector<Ref<VoxelChunk> > _chunks_vector;
|
||||||
|
|
||||||
NodePath _player_path;
|
NodePath _player_path;
|
||||||
Spatial *_player;
|
Spatial *_player;
|
||||||
|
Loading…
Reference in New Issue
Block a user