mirror of
https://github.com/Relintai/godot_voxel.git
synced 2024-11-11 20:35:08 +01:00
Code style
This commit is contained in:
parent
c75d1e78b2
commit
c38a822664
15
voxel.cpp
15
voxel.cpp
@ -10,13 +10,21 @@ Voxel::Voxel() : Reference(),
|
|||||||
_color(1.f, 1.f, 1.f)
|
_color(1.f, 1.f, 1.f)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
Ref<Voxel> Voxel::set_name(String name) {
|
||||||
|
_name = name;
|
||||||
|
return Ref<Voxel>(this);
|
||||||
|
}
|
||||||
|
|
||||||
Ref<Voxel> Voxel::set_id(int id) {
|
Ref<Voxel> Voxel::set_id(int id) {
|
||||||
ERR_FAIL_COND_V(id < 0 || id >= 256, Ref<Voxel>(this));
|
ERR_FAIL_COND_V(id < 0 || id >= 256, Ref<Voxel>(this));
|
||||||
// Cannot modify ID after creation
|
// Cannot modify ID after creation
|
||||||
ERR_FAIL_COND_V(_id != -1, Ref<Voxel>(this));
|
ERR_FAIL_COND_V(_id != -1, Ref<Voxel>(this));
|
||||||
|
|
||||||
_id = id;
|
_id = id;
|
||||||
|
return Ref<Voxel>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<Voxel> Voxel::set_color(Color color) {
|
||||||
|
_color = color;
|
||||||
return Ref<Voxel>(this);
|
return Ref<Voxel>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +34,11 @@ Ref<Voxel> Voxel::set_material_id(unsigned int id) {
|
|||||||
return Ref<Voxel>(this);
|
return Ref<Voxel>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ref<Voxel> Voxel::set_transparent(bool t) {
|
||||||
|
_is_transparent = t;
|
||||||
|
return Ref<Voxel>(this);
|
||||||
|
}
|
||||||
|
|
||||||
Ref<Voxel> Voxel::set_cube_geometry(float sy) {
|
Ref<Voxel> Voxel::set_cube_geometry(float sy) {
|
||||||
const Vector3 vertices[SIDE_COUNT][6] = {
|
const Vector3 vertices[SIDE_COUNT][6] = {
|
||||||
{
|
{
|
||||||
|
49
voxel.h
49
voxel.h
@ -23,45 +23,23 @@ public:
|
|||||||
SIDE_COUNT
|
SIDE_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
|
||||||
VoxelLibrary * _library;
|
|
||||||
|
|
||||||
// Identifiers
|
|
||||||
int _id;
|
|
||||||
String _name;
|
|
||||||
|
|
||||||
// Properties
|
|
||||||
int _material_id;
|
|
||||||
bool _is_transparent;
|
|
||||||
|
|
||||||
// Model
|
|
||||||
Color _color;
|
|
||||||
DVector<Vector3> _model_vertices;
|
|
||||||
DVector<Vector3> _model_normals;
|
|
||||||
DVector<Vector2> _model_uv;
|
|
||||||
DVector<Vector3> _model_side_vertices[SIDE_COUNT];
|
|
||||||
DVector<Vector2> _model_side_uv[SIDE_COUNT];
|
|
||||||
|
|
||||||
// TODO Child voxel types
|
|
||||||
|
|
||||||
public:
|
|
||||||
Voxel();
|
Voxel();
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
|
|
||||||
_FORCE_INLINE_ Ref<Voxel> set_name(String name) { _name = name; return Ref<Voxel>(this); }
|
Ref<Voxel> set_name(String name);
|
||||||
_FORCE_INLINE_ String get_name() const { return _name; }
|
_FORCE_INLINE_ String get_name() const { return _name; }
|
||||||
|
|
||||||
Ref<Voxel> set_id(int id);
|
Ref<Voxel> set_id(int id);
|
||||||
_FORCE_INLINE_ int get_id() const { return _id; }
|
_FORCE_INLINE_ int get_id() const { return _id; }
|
||||||
|
|
||||||
_FORCE_INLINE_ Ref<Voxel> set_color(Color color) { _color = color; return Ref<Voxel>(this); }
|
Ref<Voxel> set_color(Color color);
|
||||||
_FORCE_INLINE_ Color get_color() const { return _color; }
|
_FORCE_INLINE_ Color get_color() const { return _color; }
|
||||||
|
|
||||||
Ref<Voxel> set_material_id(unsigned int id);
|
Ref<Voxel> set_material_id(unsigned int id);
|
||||||
_FORCE_INLINE_ unsigned int get_material_id() const { return _material_id; }
|
_FORCE_INLINE_ unsigned int get_material_id() const { return _material_id; }
|
||||||
|
|
||||||
_FORCE_INLINE_ Ref<Voxel> set_transparent(bool t = true) { _is_transparent = t; return Ref<Voxel>(this); }
|
Ref<Voxel> set_transparent(bool t = true);
|
||||||
_FORCE_INLINE_ bool is_transparent() const { return _is_transparent; }
|
_FORCE_INLINE_ bool is_transparent() const { return _is_transparent; }
|
||||||
|
|
||||||
// Built-in geometry generators
|
// Built-in geometry generators
|
||||||
@ -86,6 +64,27 @@ protected:
|
|||||||
|
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
|
private:
|
||||||
|
VoxelLibrary * _library;
|
||||||
|
|
||||||
|
// Identifiers
|
||||||
|
int _id;
|
||||||
|
String _name;
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
int _material_id;
|
||||||
|
bool _is_transparent;
|
||||||
|
|
||||||
|
// Model
|
||||||
|
Color _color;
|
||||||
|
DVector<Vector3> _model_vertices;
|
||||||
|
DVector<Vector3> _model_normals;
|
||||||
|
DVector<Vector2> _model_uv;
|
||||||
|
DVector<Vector3> _model_side_vertices[SIDE_COUNT];
|
||||||
|
DVector<Vector2> _model_side_uv[SIDE_COUNT];
|
||||||
|
|
||||||
|
// TODO Child voxel types
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VOXEL_TYPE_H
|
#endif // VOXEL_TYPE_H
|
||||||
|
@ -16,27 +16,6 @@ public:
|
|||||||
// Arbitrary value, 8 should be enough. Tweak for your needs.
|
// Arbitrary value, 8 should be enough. Tweak for your needs.
|
||||||
static const int MAX_CHANNELS = 8;
|
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();
|
||||||
~VoxelBuffer();
|
~VoxelBuffer();
|
||||||
|
|
||||||
@ -98,6 +77,25 @@ protected:
|
|||||||
void _copy_from_area_binding(Ref<VoxelBuffer> other, Vector3 src_min, Vector3 src_max, Vector3 dst_min, unsigned int channel);
|
void _copy_from_area_binding(Ref<VoxelBuffer> 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); }
|
_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
|
#endif // VOXEL_BUFFER_H
|
||||||
|
25
voxel_map.h
25
voxel_map.h
@ -39,19 +39,6 @@ private:
|
|||||||
// Infinite voxel storage by means of octants like Gridmap
|
// Infinite voxel storage by means of octants like Gridmap
|
||||||
class VoxelMap : public Reference {
|
class VoxelMap : public Reference {
|
||||||
OBJ_TYPE(VoxelMap, 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<Vector3i, Ref<VoxelBlock>, 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:
|
public:
|
||||||
VoxelMap();
|
VoxelMap();
|
||||||
~VoxelMap();
|
~VoxelMap();
|
||||||
@ -111,6 +98,18 @@ private:
|
|||||||
void _get_buffer_copy_binding(Vector3 pos, Ref<VoxelBuffer> dst_buffer_ref, unsigned int channel = 0);
|
void _get_buffer_copy_binding(Vector3 pos, Ref<VoxelBuffer> dst_buffer_ref, unsigned int channel = 0);
|
||||||
void _set_block_buffer_binding(Vector3 bpos, Ref<VoxelBuffer> buffer) { set_block_buffer(Vector3i(bpos), buffer); }
|
void _set_block_buffer_binding(Vector3 bpos, Ref<VoxelBuffer> 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<Vector3i, Ref<VoxelBlock>, 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 {
|
//class VoxelSector {
|
||||||
|
@ -10,18 +10,6 @@
|
|||||||
// It is loaded around VoxelTerrainStreamers.
|
// It is loaded around VoxelTerrainStreamers.
|
||||||
class VoxelTerrain : public Node /*, public IVoxelMapObserver*/ {
|
class VoxelTerrain : public Node /*, public IVoxelMapObserver*/ {
|
||||||
OBJ_TYPE(VoxelTerrain, Node)
|
OBJ_TYPE(VoxelTerrain, Node)
|
||||||
|
|
||||||
// Parameters
|
|
||||||
int _min_y; // In blocks, not voxels
|
|
||||||
int _max_y;
|
|
||||||
|
|
||||||
// Voxel storage
|
|
||||||
Ref<VoxelMap> _map;
|
|
||||||
|
|
||||||
Vector<Vector3i> _block_update_queue;
|
|
||||||
Ref<VoxelMesher> _mesher;
|
|
||||||
Ref<VoxelProvider> _provider;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VoxelTerrain();
|
VoxelTerrain();
|
||||||
|
|
||||||
@ -50,6 +38,18 @@ protected:
|
|||||||
Vector3 _block_to_voxel_binding(Vector3 pos) { return Vector3i(VoxelMap::block_to_voxel(pos)).to_vec3(); }
|
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); }
|
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<VoxelMap> _map;
|
||||||
|
|
||||||
|
Vector<Vector3i> _block_update_queue;
|
||||||
|
Ref<VoxelMesher> _mesher;
|
||||||
|
Ref<VoxelProvider> _provider;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VOXEL_TERRAIN_H
|
#endif // VOXEL_TERRAIN_H
|
||||||
|
Loading…
Reference in New Issue
Block a user