VoxelProvider now receives an offset in voxels instead of blocks

This commit is contained in:
Marc Gilleron 2017-08-28 15:42:54 +02:00
parent 126f367c50
commit 07b7e083dd
5 changed files with 22 additions and 24 deletions

View File

@ -1,38 +1,38 @@
#include "voxel_provider.h"
#include "voxel_map.h"
void VoxelProvider::emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i block_pos) {
void VoxelProvider::emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i origin_in_voxels) {
ERR_FAIL_COND(out_buffer.is_null());
ScriptInstance *script = get_script_instance();
if (script) {
// Call script to generate buffer
Variant arg1 = out_buffer;
Variant arg2 = block_pos.to_vec3();
Variant arg2 = origin_in_voxels.to_vec3();
const Variant *args[2] = { &arg1, &arg2 };
//Variant::CallError err; // wut
script->call_multilevel("emerge_block", args, 2);
}
}
void VoxelProvider::immerge_block(Ref<VoxelBuffer> buffer, Vector3i block_pos) {
void VoxelProvider::immerge_block(Ref<VoxelBuffer> buffer, Vector3i origin_in_voxels) {
ERR_FAIL_COND(buffer.is_null());
ScriptInstance *script = get_script_instance();
if (script) {
// Call script to save buffer
Variant arg1 = buffer;
Variant arg2 = block_pos.to_vec3();
Variant arg2 = origin_in_voxels.to_vec3();
const Variant *args[2] = { &arg1, &arg2 };
//Variant::CallError err; // wut
script->call_multilevel("immerge_block", args, 2);
}
}
void VoxelProvider::_emerge_block(Ref<VoxelBuffer> out_buffer, Vector3 block_pos) {
emerge_block(out_buffer, Vector3i(block_pos));
void VoxelProvider::_emerge_block(Ref<VoxelBuffer> out_buffer, Vector3 origin_in_voxels) {
emerge_block(out_buffer, Vector3i(origin_in_voxels));
}
void VoxelProvider::_immerge_block(Ref<VoxelBuffer> buffer, Vector3 block_pos) {
immerge_block(buffer, Vector3i(block_pos));
void VoxelProvider::_immerge_block(Ref<VoxelBuffer> buffer, Vector3 origin_in_voxels) {
immerge_block(buffer, Vector3i(origin_in_voxels));
}
void VoxelProvider::_bind_methods() {

View File

@ -7,14 +7,14 @@
class VoxelProvider : public Resource {
GDCLASS(VoxelProvider, Resource)
public:
virtual void emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i block_pos);
virtual void immerge_block(Ref<VoxelBuffer> buffer, Vector3i block_pos);
virtual void emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i origin_in_voxels);
virtual void immerge_block(Ref<VoxelBuffer> buffer, Vector3i origin_in_voxels);
protected:
static void _bind_methods();
void _emerge_block(Ref<VoxelBuffer> out_buffer, Vector3 block_pos);
void _immerge_block(Ref<VoxelBuffer> buffer, Vector3 block_pos);
void _emerge_block(Ref<VoxelBuffer> out_buffer, Vector3 origin_in_voxels);
void _immerge_block(Ref<VoxelBuffer> buffer, Vector3 origin_in_voxels);
};
#endif // VOXEL_PROVIDER_H

View File

@ -30,26 +30,25 @@ void VoxelProviderTest::set_pattern_offset(Vector3i offset) {
_pattern_offset = offset;
}
void VoxelProviderTest::emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i block_pos) {
void VoxelProviderTest::emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i origin) {
ERR_FAIL_COND(out_buffer.is_null());
switch (_mode) {
case MODE_FLAT:
generate_block_flat(**out_buffer, block_pos);
generate_block_flat(**out_buffer, origin);
break;
case MODE_WAVES:
generate_block_waves(**out_buffer, block_pos);
generate_block_waves(**out_buffer, origin);
break;
}
}
void VoxelProviderTest::generate_block_flat(VoxelBuffer &out_buffer, Vector3i block_pos) {
void VoxelProviderTest::generate_block_flat(VoxelBuffer &out_buffer, Vector3i origin) {
// TODO Don't expect a block pos, but a voxel pos!
Vector3i size = out_buffer.get_size();
Vector3i origin = size * block_pos;
int rh = _pattern_offset.y - origin.y;
if (rh > size.y)
@ -64,11 +63,11 @@ void VoxelProviderTest::generate_block_flat(VoxelBuffer &out_buffer, Vector3i bl
}
}
void VoxelProviderTest::generate_block_waves(VoxelBuffer &out_buffer, Vector3i block_pos) {
void VoxelProviderTest::generate_block_waves(VoxelBuffer &out_buffer, Vector3i origin) {
// TODO Don't expect a block pos, but a voxel pos!
Vector3i size = out_buffer.get_size();
Vector3i origin = size * block_pos + _pattern_offset;
//origin += _pattern_offset;
float amplitude = static_cast<float>(_pattern_size.y);
float period_x = 1.f / static_cast<float>(_pattern_size.x);

View File

@ -14,7 +14,7 @@ public:
VoxelProviderTest();
virtual void emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i block_pos);
virtual void emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i origin);
void set_mode(Mode mode);
Mode get_mode() const { return _mode; }
@ -29,8 +29,8 @@ public:
void set_pattern_offset(Vector3i offset);
protected:
void generate_block_flat(VoxelBuffer &out_buffer, Vector3i block_pos);
void generate_block_waves(VoxelBuffer &out_buffer, Vector3i block_pos);
void generate_block_flat(VoxelBuffer &out_buffer, Vector3i origin);
void generate_block_waves(VoxelBuffer &out_buffer, Vector3i origin);
static void _bind_methods();

View File

@ -458,7 +458,6 @@ void VoxelTerrain::update_blocks() {
//printf("Remaining: %i\n", _block_update_queue.size());
// TODO Move this to a thread
// TODO Have VoxelTerrainGenerator in C++
// Get request
Vector3i block_pos = _block_update_queue[_block_update_queue.size() - 1];
@ -479,7 +478,7 @@ void VoxelTerrain::update_blocks() {
VOXEL_PROFILE_BEGIN("block_generation")
// Query voxel provider
_provider->emerge_block(buffer_ref, block_pos);
_provider->emerge_block(buffer_ref, _map->block_to_voxel(block_pos));
// Check script return
// TODO Shouldn't halt execution though, as it can bring the map in an invalid state!