From f2ac08f7bc7dba800faf18eedffd54ccbe236e24 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 4 Mar 2020 16:38:18 +0100 Subject: [PATCH] Now mobs actually won't move/fall when outside of the loaded and meshed area. Fix to mob spawning coordinates in simple biome. Also update Voxelman to grab the is_position_walkable fix. --- HEADS | 2 +- game/player/Mob.gd | 18 +++++++++++ game/scenes/World.tscn | 1 + game/voxelman/world/TVVoxelWorld.gd | 49 +++++++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/HEADS b/HEADS index 2ea955b5..1fd48517 100644 --- a/HEADS +++ b/HEADS @@ -1 +1 @@ -{"engine": {"3.2": "f4e3701893bdf6b304ee114745def2f8ac4aa822", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "a08917370cdef0884042bdb49fb80ece0b2e76ec"}, "entity_spell_system": {"master": "3e10779dbc5258d1e1b08eab287189f9c1ccec64"}, "ui_extensions": {"master": "38acc650db260a831dc26ca96fe9d9a087230bdc"}, "voxelman": {"master": "ac75c78be10e0f7d60b7a6f26189523347732276"}, "texture_packer": {"master": "b17c174906f84de93d84aa60d010ffe603efaa28"}, "fastnoise": {"master": "41b7ea05a1f7aa2b8ecddaa1fd739e64d6970f7e"}, "mesh_data_resource": {"master": "4bda19b12be2c2a79a6121de6d22e48f3934e726"}, "procedural_animations": {"master": "ba464ef04500aa01b2638cf1f890f3f6582ead84"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}} \ No newline at end of file +{"engine": {"3.2": "0d5e483a90c41c433056b8cf6e4e8def6316690f", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "a08917370cdef0884042bdb49fb80ece0b2e76ec"}, "entity_spell_system": {"master": "3e10779dbc5258d1e1b08eab287189f9c1ccec64"}, "ui_extensions": {"master": "38acc650db260a831dc26ca96fe9d9a087230bdc"}, "voxelman": {"master": "fbd2903477bc810fba8abec48f9cd6f9252e2fe5"}, "texture_packer": {"master": "b17c174906f84de93d84aa60d010ffe603efaa28"}, "fastnoise": {"master": "41b7ea05a1f7aa2b8ecddaa1fd739e64d6970f7e"}, "mesh_data_resource": {"master": "4bda19b12be2c2a79a6121de6d22e48f3934e726"}, "procedural_animations": {"master": "ba464ef04500aa01b2638cf1f890f3f6582ead84"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}} \ No newline at end of file diff --git a/game/player/Mob.gd b/game/player/Mob.gd index 7807062e..a39c30bd 100644 --- a/game/player/Mob.gd +++ b/game/player/Mob.gd @@ -64,6 +64,24 @@ func _ready() -> void: set_process(true) set_physics_process(true) +func _enter_tree(): + var world : VoxelWorld = get_node("..") as VoxelWorld + + if world != null: + if not world.is_position_walkable(get_body().transform.origin): + world.connect("chunk_mesh_generation_finished", self, "chunk_mesh_generation_finished", [], CONNECT_DEFERRED) + set_process(false) + set_physics_process(false) + +func chunk_mesh_generation_finished(chunk): + var world : VoxelWorld = get_node("..") as VoxelWorld + + if world.is_position_walkable(get_body().transform.origin): + world.disconnect("chunk_mesh_generation_finished", self, "chunk_mesh_generation_finished") + set_process(true) + set_physics_process(true) + + func _process(delta : float) -> void: if dead: death_timer += delta diff --git a/game/scenes/World.tscn b/game/scenes/World.tscn index a9474e9f..f4cbf40a 100644 --- a/game/scenes/World.tscn +++ b/game/scenes/World.tscn @@ -59,6 +59,7 @@ adjustment_enabled = true data_margin_start = 1 data_margin_end = 2 max_concurrent_generations = 4 +max_frame_chunk_build_steps = 1 library = ExtResource( 2 ) level_generator = SubResource( 1 ) voxel_scale = 1.6 diff --git a/game/voxelman/world/TVVoxelWorld.gd b/game/voxelman/world/TVVoxelWorld.gd index 74c8f20f..68bf572e 100644 --- a/game/voxelman/world/TVVoxelWorld.gd +++ b/game/voxelman/world/TVVoxelWorld.gd @@ -39,6 +39,9 @@ var _editor_generate : bool var _player_file_name : String var _player : Entity +const VIS_UPDATE_INTERVAL = 5 +var vis_update : float = 0 + func _enter_tree(): for ch in get_children(): if ch is VoxelChunk: @@ -51,14 +54,52 @@ func _enter_tree(): add_chunk(c, c.position_x, c.position_y, c.position_z) c.build_deferred() - - if generate_on_ready and not Engine.is_editor_hint(): if level_generator != null: level_generator.setup(self, 80, false, library) spawn() + +func _process(delta): + if _player == null: + set_process(false) + return + + vis_update += delta + + if vis_update >= VIS_UPDATE_INTERVAL: + vis_update = 0 + + var ppos : Vector3 = _player.get_body().transform.origin + + var cpos : Vector3 = ppos + cpos.x = int(cpos.x / (chunk_size_x * voxel_scale)) + cpos.y = int(cpos.y / (chunk_size_y * voxel_scale)) + cpos.z = int(cpos.z / (chunk_size_z * voxel_scale)) + + var count : int = get_chunk_count() + var i : int = 0 + while i < count: + var c : VoxelChunk = get_chunk_index(i) + + var l : float = (Vector2(cpos.x, cpos.z) - Vector2(c.position_x, c.position_z)).length() + + if l > chunk_spawn_range + 2: +# print("despawn " + str(Vector3(c.position_x, c.position_y, c.position_z))) + remove_chunk_index(i) + c.queue_free() + i -= 1 + count -= 1 + + i += 1 + + for x in range(-chunk_spawn_range + int(cpos.x), chunk_spawn_range + int(cpos.x)): + for z in range(-chunk_spawn_range + int(cpos.z), chunk_spawn_range + int(cpos.z)): + for y in range(-1, 2): + if not has_chunk(x, y, z): +# print("spawn " + str(Vector3(x, y, z))) + create_chunk(x, y, z) #func _process(delta : float) -> void: # if not generation_queue.empty(): @@ -128,7 +169,7 @@ func _create_chunk(x : int, y : int, z : int, pchunk : Node) -> VoxelChunk: #chunk.meshing_create_collider = false chunk.lod_size = 1 - +# print("added " + str(Vector3(x, y, z))) return ._create_chunk(x, y, z, chunk) func spawn() -> void: @@ -199,6 +240,8 @@ func load_character(file_name : String) -> void: spawn() + set_process(true) + func needs_loading_screen() -> bool: return show_loading_screen