2019-11-20 14:19:41 +01:00
|
|
|
extends Biome
|
|
|
|
|
2020-01-31 20:01:34 +01:00
|
|
|
# Copyright (c) 2019-2020 Péter Magyar
|
2019-12-22 19:20:38 +01:00
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
2019-11-20 14:19:41 +01:00
|
|
|
|
|
|
|
func _generate_chunk(chunk: VoxelChunk, spawn_mobs: bool) -> void:
|
|
|
|
# var chunk : VoxelChunk = chunk.get_chunk()
|
|
|
|
|
|
|
|
generate_terrarin(chunk, spawn_mobs)
|
|
|
|
|
|
|
|
func generate_terrarin(chunk : VoxelChunk, spawn_mobs: bool) -> void:
|
|
|
|
var noise : OpenSimplexNoise = OpenSimplexNoise.new()
|
|
|
|
noise.seed = 10 * current_seed
|
|
|
|
noise.octaves = 4
|
2020-01-14 23:15:46 +01:00
|
|
|
noise.period = 280.0
|
2019-11-20 14:19:41 +01:00
|
|
|
noise.persistence = 0.8
|
|
|
|
|
|
|
|
var terr_noise : OpenSimplexNoise = OpenSimplexNoise.new()
|
|
|
|
terr_noise.seed = 10 * 321 + 112 * current_seed
|
|
|
|
terr_noise.octaves = 4
|
2020-01-14 23:15:46 +01:00
|
|
|
terr_noise.period = 90.0
|
2019-11-20 14:19:41 +01:00
|
|
|
terr_noise.persistence = 0.9
|
|
|
|
|
|
|
|
var det_noise : OpenSimplexNoise = OpenSimplexNoise.new()
|
|
|
|
det_noise.seed = 10 * 3231 + 112 * current_seed
|
|
|
|
det_noise.octaves = 6
|
2020-01-14 23:15:46 +01:00
|
|
|
det_noise.period = 80.0
|
2019-11-20 14:19:41 +01:00
|
|
|
det_noise.persistence = 0.3
|
|
|
|
|
2020-02-14 03:25:41 +01:00
|
|
|
for x in range(-chunk.get_margin_start(), chunk.size_x + chunk.get_margin_end()):
|
|
|
|
for z in range(-chunk.get_margin_start(), chunk.size_z + chunk.get_margin_end()):
|
2019-11-20 14:19:41 +01:00
|
|
|
var val : float = noise.get_noise_2d(x + (chunk.position_x * chunk.size_x), z + (chunk.position_z * chunk.size_z))
|
|
|
|
val *= val
|
2020-01-13 00:43:45 +01:00
|
|
|
val *= 200
|
2019-11-20 14:19:41 +01:00
|
|
|
val += 2
|
|
|
|
|
|
|
|
var tv : float = terr_noise.get_noise_2d(x + (chunk.position_x * chunk.size_x), z + (chunk.position_z * chunk.size_z))
|
2019-12-06 23:17:12 +01:00
|
|
|
tv *= tv * tv * tv
|
2019-11-20 14:19:41 +01:00
|
|
|
val += tv * 2
|
|
|
|
|
|
|
|
var dval : float = noise.get_noise_2d(x + (chunk.position_x * chunk.size_x), z + (chunk.position_z * chunk.size_z))
|
|
|
|
|
|
|
|
val += dval * 6
|
|
|
|
|
|
|
|
var v : int = (int(val))
|
|
|
|
|
|
|
|
v -= chunk.position_y * (chunk.size_y)
|
|
|
|
|
2020-02-14 03:25:41 +01:00
|
|
|
if v > chunk.size_y + chunk.get_margin_end():
|
|
|
|
v = chunk.size_y + chunk.get_margin_end()
|
2019-11-20 14:19:41 +01:00
|
|
|
|
2020-02-14 03:25:41 +01:00
|
|
|
for y in range(-chunk.get_margin_start(), v):
|
2019-11-20 14:19:41 +01:00
|
|
|
seed(x + (chunk.position_x * chunk.size_x) + z + (chunk.position_z * chunk.size_z) + y + (chunk.position_y * chunk.size_y))
|
|
|
|
|
2020-01-13 00:43:45 +01:00
|
|
|
|
2019-11-20 14:19:41 +01:00
|
|
|
if v < 2:
|
2020-03-12 23:26:19 +01:00
|
|
|
chunk.set_voxel(1, x, y, z, VoxelChunkDefault.DEFAULT_CHANNEL_TYPE)
|
2019-11-20 14:19:41 +01:00
|
|
|
elif v == 2:
|
2020-03-12 23:26:19 +01:00
|
|
|
chunk.set_voxel(3, x, y, z, VoxelChunkDefault.DEFAULT_CHANNEL_TYPE)
|
2019-11-20 14:19:41 +01:00
|
|
|
else:
|
2020-03-12 23:26:19 +01:00
|
|
|
chunk.set_voxel(2, x, y, z, VoxelChunkDefault.DEFAULT_CHANNEL_TYPE)
|
2019-12-28 17:55:10 +01:00
|
|
|
|
2020-01-14 13:26:15 +01:00
|
|
|
# if y == v - 1:
|
|
|
|
# chunk.set_voxel(int(255.0 * (val - int(val))), x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
# else:
|
|
|
|
# chunk.set_voxel(255, x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
#
|
2019-11-20 14:19:41 +01:00
|
|
|
|
2020-01-14 13:26:15 +01:00
|
|
|
var val2 : float = (val - int(val)) * 4.0
|
|
|
|
val2 = int(val2)
|
|
|
|
val2 /= 4.0
|
2020-01-13 00:43:45 +01:00
|
|
|
|
2020-03-12 23:26:19 +01:00
|
|
|
chunk.set_voxel(int(255.0 * val2), x, y, z, VoxelChunkDefault.DEFAULT_CHANNEL_ISOLEVEL)
|
2019-12-06 23:17:12 +01:00
|
|
|
# chunk.set_voxel(int(255.0 * (val - int(val)) / 180.0) * 180, x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
2019-12-28 17:55:10 +01:00
|
|
|
# chunk.set_voxel(int(255.0 * (val - int(val))), x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
2019-11-20 14:19:41 +01:00
|
|
|
|
2019-12-07 15:54:46 +01:00
|
|
|
# box_blur(chunk)
|
|
|
|
|
2019-11-20 14:19:41 +01:00
|
|
|
# chunk.build()
|
2020-01-13 00:43:45 +01:00
|
|
|
|
2019-11-20 14:19:41 +01:00
|
|
|
if not Engine.editor_hint and chunk.position_y == 0 and spawn_mobs:
|
2020-04-18 14:35:28 +02:00
|
|
|
ESS.entity_spawner.spawn_mob(1, randi() % 3, Vector3(chunk.position_x * chunk.size_x * chunk.voxel_scale + chunk.size_x / 2,\
|
2019-11-20 14:19:41 +01:00
|
|
|
(chunk.position_y + 1) * chunk.size_y * chunk.voxel_scale, \
|
2020-03-04 18:47:20 +01:00
|
|
|
chunk.position_z * chunk.size_z * chunk.voxel_scale + chunk.size_z / 2))
|
2019-11-20 14:19:41 +01:00
|
|
|
|
2019-12-07 15:54:46 +01:00
|
|
|
func box_blur(chunk : VoxelChunk):
|
|
|
|
for x in range(0, chunk.size_x):
|
|
|
|
for z in range(0, chunk.size_z):
|
|
|
|
for y in range(0, chunk.size_z):
|
|
|
|
|
|
|
|
var avg : float = 0
|
2020-01-13 00:43:45 +01:00
|
|
|
var avgc : int = 0
|
|
|
|
|
|
|
|
var curr : int = chunk.get_voxel(x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
|
|
|
|
if curr > 0:
|
|
|
|
avg += curr
|
|
|
|
avgc += 1
|
|
|
|
|
|
|
|
curr = chunk.get_voxel(x + 1, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
|
|
|
|
if curr > 0:
|
|
|
|
avg += curr
|
|
|
|
avgc += 1
|
|
|
|
|
|
|
|
curr = chunk.get_voxel(x, y, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
|
|
|
|
if curr > 0:
|
|
|
|
avg += curr
|
|
|
|
avgc += 1
|
|
|
|
|
|
|
|
curr = chunk.get_voxel(x + 1, y, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
|
|
|
|
if curr > 0:
|
|
|
|
avg += curr
|
|
|
|
avgc += 1
|
|
|
|
|
|
|
|
curr = chunk.get_voxel(x, y + 1, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
|
|
|
|
if curr > 0:
|
|
|
|
avg += curr
|
|
|
|
avgc += 1
|
|
|
|
|
|
|
|
curr = chunk.get_voxel(x + 1, y + 1, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
|
|
|
|
if curr > 0:
|
|
|
|
avg += curr
|
|
|
|
avgc += 1
|
|
|
|
|
|
|
|
curr = chunk.get_voxel(x, y + 1, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
|
|
|
|
if curr > 0:
|
|
|
|
avg += curr
|
|
|
|
avgc += 1
|
|
|
|
|
|
|
|
curr = chunk.get_voxel(x + 1, y + 1, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
|
|
|
|
if curr > 0:
|
|
|
|
avg += curr
|
|
|
|
avgc += 1
|
|
|
|
|
2019-12-07 15:54:46 +01:00
|
|
|
|
2020-01-13 00:43:45 +01:00
|
|
|
avg /= float(avgc)
|
2019-12-07 15:54:46 +01:00
|
|
|
|
2019-12-24 10:22:56 +01:00
|
|
|
var aavg: int = int(avg)
|
2019-12-07 15:54:46 +01:00
|
|
|
|
2019-12-24 10:22:56 +01:00
|
|
|
chunk.set_voxel(aavg, x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
chunk.set_voxel(aavg, x + 1, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
chunk.set_voxel(aavg, x, y, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
chunk.set_voxel(aavg, x + 1, y, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
chunk.set_voxel(aavg, x, y + 1, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
chunk.set_voxel(aavg, x + 1, y + 1, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
chunk.set_voxel(aavg, x, y + 1, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|
|
|
|
chunk.set_voxel(aavg, x + 1, y + 1, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
|