#include <core/engine.h>
#include <core/os/os.h>
#include "roads.h"
#include "world_map_data.h"
#include "world_generator.h"

WorldGenerator::WorldGenerator() {
}


float WorldGenerator::height_func(int x, int y, int z)
{
	float sdf = RoadsData::get_singleton()->get_sdf(x, y, z);
	return sdf;
}

VoxelGenerator::Result WorldGenerator::generate_block(VoxelBlockRequest &input) {

	Result result;

	VoxelBufferInternal &out_buffer = input.voxel_buffer;
	result = WorldGenerator::generate(
				out_buffer,
				[this](int x, int y, int z) { return height_func(x, y, z); },
				input.origin_in_voxels, input.lod);

	out_buffer.compress_uniform_channels();
	return result;
}

void WorldGenerator::_bind_methods() {
	ClassDB::bind_method(D_METHOD("set_iso_scale", "scale"), &WorldGenerator::set_iso_scale);
	ClassDB::bind_method(D_METHOD("get_iso_scale"), &WorldGenerator::get_iso_scale);
	ADD_PROPERTY(PropertyInfo(Variant::REAL, "iso_scale"), "set_iso_scale", "get_iso_scale");
}

int WorldGenerator::get_used_channels_mask() const {
	return (1 << VoxelBuffer::CHANNEL_SDF);
}

void WorldGenerator::set_iso_scale(float iso_scale) {
	_iso_scale = iso_scale;
}

float WorldGenerator::get_iso_scale() const {
	return _iso_scale;
}

