Godot 4.4
In my game, I generate tiles using Perlin noise. To improve performance during the tile installation process, I moved it to a separate thread. However, some voids are still appearing. These voids do not occur when running the game without multithreading. I am not sure what the problem might be.
func _process(delta):
PlayerCords = get_owner().find_child("Player").global_position
chunk()
if ThreadTileTerrain.is_started():
ThreadTileTerrain.wait_to_finish()
if detChunk.x != PastCords.x or detChunk.y != PastCords.y:
PastCords = detChunk
#SpawnArea(MultiplerChunk)
ThreadTileTerrain.start(SpawnArea.bind(MultiplerChunk),Thread.PRIORITY_HIGH)
func chunk():
detChunk = Vector2i(int(PlayerCords.x)/LengthChunk, int(PlayerCords.y)/LengthChunk)
MultiplerChunk = detChunk
#MultiplerChunk = Vector2i(int(PlayerCords.x)/LengthChunk, int(PlayerCords.y)/LengthChunk)
if PlayerCords.x < 0 and PlayerCords.x != 0:
MultiplerChunk.x -= 1
if PlayerCords.y < 0 and PlayerCords.y != 0:
MultiplerChunk.y -= 1
detChunk = MultiplerChunk * LengthChunk
func SpawnArea(Multi):
if ChunkCount > 10:
genTileEnv.clear()
genTileMap.clear()
ChunkArray.clear()
ChunkCount = 0
for x in range(-1,2):
for y in range(-1,2):
if !ChunkArray.has((Multi + Vector2i(x, y))):
ChunkCount += 1
ChunkArray.append((Multi + Vector2i(x, y)))
GenerateMap((Multi + Vector2i(x, y))*LengthChunk/16)
GenerateEnvironment((Multi + Vector2i(x, y))*LengthChunk/16)
func GenerateMap(Cords):
for x in range(Cords.x, Cords.x + Width):
for y in range(Cords.y, Cords.y + Heigth):
temp1 = abs((x + y) % 10) % 4
NoiseValues = shum.get_noise_2d(x,y)
if NoiseValues > -0.2 and NoiseValues < -0.1:
genTileMap.set_cell(Vector2i(x,y), AtlasID, Vector2i(0, 1), temp1)
else:
genTileMap.set_cell(Vector2i(x,y), AtlasID, Vector2i(0, 0), temp1)