diff --git a/voxel.cpp b/voxel.cpp index 141b717..caf29ce 100644 --- a/voxel.cpp +++ b/voxel.cpp @@ -10,13 +10,21 @@ Voxel::Voxel() : Reference(), _color(1.f, 1.f, 1.f) {} +Ref Voxel::set_name(String name) { + _name = name; + return Ref(this); +} + Ref Voxel::set_id(int id) { ERR_FAIL_COND_V(id < 0 || id >= 256, Ref(this)); // Cannot modify ID after creation ERR_FAIL_COND_V(_id != -1, Ref(this)); - _id = id; + return Ref(this); +} +Ref Voxel::set_color(Color color) { + _color = color; return Ref(this); } @@ -26,6 +34,11 @@ Ref Voxel::set_material_id(unsigned int id) { return Ref(this); } +Ref Voxel::set_transparent(bool t) { + _is_transparent = t; + return Ref(this); +} + Ref Voxel::set_cube_geometry(float sy) { const Vector3 vertices[SIDE_COUNT][6] = { { diff --git a/voxel.h b/voxel.h index 0a4bd78..52370e2 100644 --- a/voxel.h +++ b/voxel.h @@ -23,45 +23,23 @@ public: SIDE_COUNT }; -private: - VoxelLibrary * _library; - - // Identifiers - int _id; - String _name; - - // Properties - int _material_id; - bool _is_transparent; - - // Model - Color _color; - DVector _model_vertices; - DVector _model_normals; - DVector _model_uv; - DVector _model_side_vertices[SIDE_COUNT]; - DVector _model_side_uv[SIDE_COUNT]; - - // TODO Child voxel types - -public: Voxel(); // Properties - _FORCE_INLINE_ Ref set_name(String name) { _name = name; return Ref(this); } + Ref set_name(String name); _FORCE_INLINE_ String get_name() const { return _name; } Ref set_id(int id); _FORCE_INLINE_ int get_id() const { return _id; } - _FORCE_INLINE_ Ref set_color(Color color) { _color = color; return Ref(this); } + Ref set_color(Color color); _FORCE_INLINE_ Color get_color() const { return _color; } Ref set_material_id(unsigned int id); _FORCE_INLINE_ unsigned int get_material_id() const { return _material_id; } - _FORCE_INLINE_ Ref set_transparent(bool t = true) { _is_transparent = t; return Ref(this); } + Ref set_transparent(bool t = true); _FORCE_INLINE_ bool is_transparent() const { return _is_transparent; } // Built-in geometry generators @@ -86,6 +64,27 @@ protected: static void _bind_methods(); +private: + VoxelLibrary * _library; + + // Identifiers + int _id; + String _name; + + // Properties + int _material_id; + bool _is_transparent; + + // Model + Color _color; + DVector _model_vertices; + DVector _model_normals; + DVector _model_uv; + DVector _model_side_vertices[SIDE_COUNT]; + DVector _model_side_uv[SIDE_COUNT]; + + // TODO Child voxel types + }; #endif // VOXEL_TYPE_H diff --git a/voxel_buffer.h b/voxel_buffer.h index 086284b..125d450 100644 --- a/voxel_buffer.h +++ b/voxel_buffer.h @@ -16,27 +16,6 @@ public: // Arbitrary value, 8 should be enough. Tweak for your needs. static const int MAX_CHANNELS = 8; -private: - - struct Channel { - // Allocated when the channel is populated. - // Flat array, in order [z][x][y] because it allows faster vertical-wise access (the engine is Y-up). - uint8_t * data; - - // Default value when data is null - uint8_t defval; - - Channel() : data(NULL), defval(0) {} - }; - - // Each channel can store arbitary data. - // For example, you can decide to store colors (R, G, B, A), gameplay types (type, state, light) or both. - Channel _channels[MAX_CHANNELS]; - - // How many voxels are there in the three directions. All populated channels have the same size. - Vector3i _size; - -public: VoxelBuffer(); ~VoxelBuffer(); @@ -98,6 +77,25 @@ protected: void _copy_from_area_binding(Ref other, Vector3 src_min, Vector3 src_max, Vector3 dst_min, unsigned int channel); _FORCE_INLINE_ void _fill_area_binding(int defval, Vector3 min, Vector3 max, unsigned int channel_index) { fill_area(defval, Vector3i(min), Vector3i(max), channel_index); } +private: + struct Channel { + // Allocated when the channel is populated. + // Flat array, in order [z][x][y] because it allows faster vertical-wise access (the engine is Y-up). + uint8_t * data; + + // Default value when data is null + uint8_t defval; + + Channel() : data(NULL), defval(0) {} + }; + + // Each channel can store arbitary data. + // For example, you can decide to store colors (R, G, B, A), gameplay types (type, state, light) or both. + Channel _channels[MAX_CHANNELS]; + + // How many voxels are there in the three directions. All populated channels have the same size. + Vector3i _size; + }; #endif // VOXEL_BUFFER_H diff --git a/voxel_map.h b/voxel_map.h index c1c0239..96f0fc0 100644 --- a/voxel_map.h +++ b/voxel_map.h @@ -39,19 +39,6 @@ private: // Infinite voxel storage by means of octants like Gridmap class VoxelMap : public Reference { OBJ_TYPE(VoxelMap, Reference) - - // Voxel values that will be returned if access is out of map bounds - uint8_t _default_voxel[VoxelBuffer::MAX_CHANNELS]; - - // Blocks stored with a spatial hash in all 3D directions - HashMap, Vector3iHasher> _blocks; - - // Voxel access will most frequently be in contiguous areas, so the same blocks are accessed. - // To prevent too much hashing, this reference is checked before. - VoxelBlock * _last_accessed_block; - - //IVoxelMapObserver * _observer; - public: VoxelMap(); ~VoxelMap(); @@ -111,6 +98,18 @@ private: void _get_buffer_copy_binding(Vector3 pos, Ref dst_buffer_ref, unsigned int channel = 0); void _set_block_buffer_binding(Vector3 bpos, Ref buffer) { set_block_buffer(Vector3i(bpos), buffer); } +private: + // Voxel values that will be returned if access is out of map bounds + uint8_t _default_voxel[VoxelBuffer::MAX_CHANNELS]; + + // Blocks stored with a spatial hash in all 3D directions + HashMap, Vector3iHasher> _blocks; + + // Voxel access will most frequently be in contiguous areas, so the same blocks are accessed. + // To prevent too much hashing, this reference is checked before. + VoxelBlock * _last_accessed_block; + + //IVoxelMapObserver * _observer; }; //class VoxelSector { diff --git a/voxel_terrain.h b/voxel_terrain.h index c813e85..469e329 100644 --- a/voxel_terrain.h +++ b/voxel_terrain.h @@ -10,18 +10,6 @@ // It is loaded around VoxelTerrainStreamers. class VoxelTerrain : public Node /*, public IVoxelMapObserver*/ { OBJ_TYPE(VoxelTerrain, Node) - - // Parameters - int _min_y; // In blocks, not voxels - int _max_y; - - // Voxel storage - Ref _map; - - Vector _block_update_queue; - Ref _mesher; - Ref _provider; - public: VoxelTerrain(); @@ -50,6 +38,18 @@ protected: Vector3 _block_to_voxel_binding(Vector3 pos) { return Vector3i(VoxelMap::block_to_voxel(pos)).to_vec3(); } void _force_load_blocks_binding(Vector3 center, Vector3 extents) { force_load_blocks(center, extents); } +private: + // Parameters + int _min_y; // In blocks, not voxels + int _max_y; + + // Voxel storage + Ref _map; + + Vector _block_update_queue; + Ref _mesher; + Ref _provider; + }; #endif // VOXEL_TERRAIN_H