chunk class was missing set_tileset() ...
This commit is contained in:
parent
abbaa6f450
commit
fccef57210
7 changed files with 39 additions and 50 deletions
|
@ -9,35 +9,36 @@ extends Node2D
|
|||
# This is done to speed up game loading and avoiding setting one large tilemap in one go
|
||||
# which is extremely slow in godot 4.0, 4096x4096 takes minutes to fill with set_cell() commands
|
||||
|
||||
var map_tiles:Array[Array] = [[]]
|
||||
var chunks:Dictionary = {}
|
||||
var unused_chunks:Dictionary = {}
|
||||
|
||||
func _init() -> void:
|
||||
self.name = "ChunkHandler"
|
||||
|
||||
func _ready():
|
||||
#thread = Thread.new()
|
||||
pass
|
||||
|
||||
#var map_tiles:Array[Array] = [[]]
|
||||
#
|
||||
#func start_handler() -> void:
|
||||
# # Initialize the map tile array with enough chunks to cover the whole map
|
||||
# map_tiles.resize(Globals.map_size/Globals.CHUNK_SIZE)
|
||||
# for y in map_tiles.size():
|
||||
# map_tiles[y].resize(Globals.map_size/Globals.CHUNK_SIZE)
|
||||
# for x in map_tiles.size():
|
||||
# map_tiles[y][x] = chunk.instantiate()
|
||||
|
||||
|
||||
func start_handler() -> void:
|
||||
# Initialize the map tile array with enough chunks to cover the whole map
|
||||
map_tiles.resize(Globals.map_size/Globals.CHUNK_SIZE)
|
||||
for y in map_tiles.size():
|
||||
map_tiles[y].resize(Globals.map_size/Globals.CHUNK_SIZE)
|
||||
|
||||
func add_chunk(x:int, y:int):
|
||||
func add_chunk(x:int, y:int):
|
||||
var chunk = Chunk.new(x,y)
|
||||
|
||||
var start = Time.get_ticks_usec()
|
||||
chunk.generate_chunk()
|
||||
self.add_child(chunk)
|
||||
|
||||
chunk.generate_chunk()
|
||||
chunk.set_position(Vector2(x*Globals.CHUNK_SIZE,y*Globals.CHUNK_SIZE))
|
||||
chunk.set_visible(true)
|
||||
var end = Time.get_ticks_usec()
|
||||
print("generate a chunk ", (end-start)/1000.0, "ms")
|
||||
|
||||
|
||||
|
||||
print("nodes in children: ", self.get_children()[0].get_used_cells(Globals.LAYER_TERRAIN).size())
|
||||
print("chunk visible in tree? : ", self.get_children()[0].is_visible_in_tree())
|
||||
print("handler visible? ", self.is_visible_in_tree())
|
||||
#chunk.set_position(Vector2(x*Globals.CHUNK_SIZE,y*Globals.CHUNK_SIZE))
|
||||
|
||||
|
||||
#map_tiles[chunk_pos.y][chunk_pos.x].clear()
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
extends Node
|
||||
|
||||
# world map chunk size
|
||||
const CHUNK_SIZE:int = 128
|
||||
const CHUNK_SIZE:int = 16
|
||||
|
||||
# tilemap tile types
|
||||
enum {TILE_WATER, TILE_TERRAIN, TILE_FOREST, TILE_BOG}
|
||||
|
@ -12,6 +12,8 @@ enum {TILE_WATER, TILE_TERRAIN, TILE_FOREST, TILE_BOG}
|
|||
# tilemap layers
|
||||
enum {LAYER_TERRAIN, LAYER_BUILDINGS}
|
||||
|
||||
const TILESET_TERRAIN:TileSet = preload("res://scenes/Chunk.tres")
|
||||
|
||||
func are_coords_valid(value:int, bounds:Vector2i, errmsg:String) -> bool:
|
||||
if bounds.x > value or value > bounds.y:
|
||||
errmsg = errmsg % [value, bounds.x, bounds.y]
|
||||
|
|
|
@ -40,13 +40,11 @@ func _ready():
|
|||
var result = _world_generator.generate_world(map_filename)
|
||||
|
||||
if result:
|
||||
#_chunk_handler.start_handler()
|
||||
_chunk_handler.set_visible(true)
|
||||
_chunk_handler.add_chunk(0, 0)
|
||||
#_chunk_handler.show()
|
||||
#_chunk_handler.set_visible(true)
|
||||
print("main visible? ", is_visible_in_tree())
|
||||
|
||||
_chunk_handler.start_handler()
|
||||
for y in Globals.map_size/Globals.CHUNK_SIZE:
|
||||
for x in Globals.map_size/Globals.CHUNK_SIZE:
|
||||
if (y + x) % 2 == 0:
|
||||
_chunk_handler.add_chunk(x, y)
|
||||
else:
|
||||
push_error("World generation failed :-(")
|
||||
|
||||
|
@ -56,10 +54,6 @@ func _ready():
|
|||
Vector2(Globals.map_size / 2.0 * Globals.TILE_SIZE_X,
|
||||
Globals.map_size / 2.0 * Globals.TILE_SIZE_Y)
|
||||
)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(_delta):
|
||||
pass
|
||||
|
||||
func quit_game():
|
||||
get_tree().get_root().propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue