parent
c73ff8f84a
commit
0542fcd339
@ -1,5 +1,5 @@ |
||||
[folding] |
||||
|
||||
node_unfolds=[NodePath("Grid"), PackedStringArray("Transform", "Cell", "Navigation", "Collision", "Process"), NodePath("Ocean"), PackedStringArray("Collision", "Transform"), NodePath("Ocean/Mesh"), PackedStringArray("Transform", "Skeleton", "mesh"), NodePath("Ocean/CollisionShape3D"), PackedStringArray("shape"), NodePath("DirectionalLight3D"), PackedStringArray("Transform", "Light", "Shadow", "Directional Shadow"), NodePath("Highlighter"), PackedStringArray("Transform"), NodePath("Camera3D"), PackedStringArray("Transform"), NodePath("WorldEnvironment"), PackedStringArray("environment")] |
||||
resource_unfolds=["res://scenes/3DWorld.tscn::PlaneMesh_7x62x", PackedStringArray("Resource"), "res://scenes/3DWorld.tscn::BoxShape3D_g3t7x", PackedStringArray()] |
||||
node_unfolds=[NodePath("DirectionalLight3D"), PackedStringArray("Transform", "Light", "Shadow", "Directional Shadow"), NodePath("Highlighter"), PackedStringArray("Transform"), NodePath("WorldEnvironment"), PackedStringArray("environment"), NodePath("Camera3D"), PackedStringArray("Transform"), NodePath("GridMap"), PackedStringArray("Cell")] |
||||
resource_unfolds=[] |
||||
nodes_folded=[] |
||||
|
||||
@ -0,0 +1,3 @@ |
||||
[folding] |
||||
|
||||
sections_unfolded=PackedStringArray() |
||||
@ -0,0 +1,3 @@ |
||||
[folding] |
||||
|
||||
sections_unfolded=PackedStringArray() |
||||
@ -0,0 +1,3 @@ |
||||
[folding] |
||||
|
||||
sections_unfolded=PackedStringArray() |
||||
@ -1,5 +1,5 @@ |
||||
[folding] |
||||
|
||||
node_unfolds=[NodePath("."), PackedStringArray("Transform"), NodePath("Pivot"), PackedStringArray("Transform"), NodePath("Pivot/fox"), PackedStringArray("Visibility", "Transform"), NodePath("CollisionShape3D"), PackedStringArray("shape", "Transform"), NodePath("RayCast3D"), PackedStringArray("Transform", "Collide With")] |
||||
node_unfolds=[NodePath("."), PackedStringArray("Transform"), NodePath("Pivot"), PackedStringArray("Transform"), NodePath("Pivot/fox"), PackedStringArray("Visibility", "Transform"), NodePath("CollisionShape3D"), PackedStringArray("shape", "Transform"), NodePath("RayCast3D"), PackedStringArray("Transform")] |
||||
resource_unfolds=["res://scenes/Instance.tscn::ArrayMesh_e2578", PackedStringArray(), "res://scenes/Instance.tscn::Skin_ue8ij", PackedStringArray(), "res://scenes/Instance.tscn::ArrayMesh_atpyt", PackedStringArray(), "res://scenes/Instance.tscn::ArrayMesh_6pt58", PackedStringArray(), "res://scenes/Instance.tscn::ArrayMesh_dsilq", PackedStringArray(), "res://scenes/Instance.tscn::ArrayMesh_hauf1", PackedStringArray(), "res://scenes/Instance.tscn::ArrayMesh_46uut", PackedStringArray(), "res://scenes/Instance.tscn::ArrayMesh_cxm68", PackedStringArray(), "res://scenes/Instance.tscn::CapsuleShape3D_ed37x", PackedStringArray(), "res://scenes/Instance.tscn::AnimationNodeStateMachine_wao7v", PackedStringArray(), "res://scenes/Instance.tscn::AnimationNodeStateMachinePlayback_r217c", PackedStringArray()] |
||||
nodes_folded=[NodePath("Pivot/fox")] |
||||
|
||||
@ -0,0 +1,3 @@ |
||||
[folding] |
||||
|
||||
sections_unfolded=PackedStringArray() |
||||
@ -1,3 +1,3 @@ |
||||
[folding] |
||||
|
||||
sections_unfolded=PackedStringArray("Background", "Volumetric Fog", "SDFGI", "Reflected Light", "SSAO", "Sky", "SSIL", "Tonemap") |
||||
sections_unfolded=PackedStringArray("Background", "Volumetric Fog", "SDFGI", "Reflected Light", "SSAO", "Sky", "SSIL", "Tonemap", "Fog", "Volumetric Fog/Temporal Reprojection", "Adjustments") |
||||
|
||||
@ -0,0 +1,3 @@ |
||||
[folding] |
||||
|
||||
sections_unfolded=PackedStringArray() |
||||
@ -1,10 +1,10 @@ |
||||
res://assets |
||||
/home/valentin/Documents/Gridmap/scripts |
||||
res://scripts |
||||
res:// |
||||
res://scenes |
||||
res://scripts |
||||
res://assets/entities |
||||
res://assets/test/falaise |
||||
res://assets/blocs |
||||
res://assets/test |
||||
/home/valentin/Documents/Gridmap/scripts |
||||
res://assets |
||||
/home/valentin/Documents/Gridmap |
||||
|
||||
@ -0,0 +1,3 @@ |
||||
[folding] |
||||
|
||||
sections_unfolded=PackedStringArray("Shader Parameters") |
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,158 +0,0 @@ |
||||
|
||||
|
||||
/* TODO: Recalculate normals, cleanup |
||||
|
||||
*/ |
||||
|
||||
shader_type spatial; |
||||
|
||||
// player_pos updated in Ground.gd, used to calculate distance from player |
||||
|
||||
uniform vec3 player_pos = vec3(0.0, 0.0, 0.0); |
||||
|
||||
// Set "active" to false to turn off the displacement shader. |
||||
|
||||
uniform bool active = true; |
||||
|
||||
// Set "remap_normals" to true if you want lighting to take place after displacement |
||||
|
||||
uniform bool remap_normals = true; |
||||
|
||||
// Use RADIUS to determine how warped the world should be. |
||||
|
||||
uniform float RADIUS = 10.0; |
||||
|
||||
uniform bool hang = false; |
||||
|
||||
void fragment() { |
||||
|
||||
// Add color |
||||
|
||||
ALBEDO = vec3(0.1, 0.3, 0.05); |
||||
|
||||
} |
||||
|
||||
void vertex() { |
||||
|
||||
// Vertex displacement math, as a function of dist_z, dist_y |
||||
|
||||
float dist_z = VERTEX.z - player_pos.z; |
||||
|
||||
float dist_y = VERTEX.y; |
||||
|
||||
// Dz and theta is calculated from RADIUS for use in the transform. |
||||
|
||||
float Dz = PI*RADIUS/2.0; |
||||
|
||||
float theta = dist_z / RADIUS; |
||||
|
||||
|
||||
|
||||
// Calculate which "side" we're on |
||||
|
||||
// 1 and -1 represent "hanging towel" |
||||
|
||||
// 0 represents the "rolling log" part |
||||
|
||||
int side; |
||||
|
||||
if (active) { |
||||
|
||||
if (dist_z > Dz) { |
||||
|
||||
side = 1; |
||||
|
||||
} else if (dist_z < -Dz) { |
||||
|
||||
side = -1; |
||||
|
||||
} else { |
||||
|
||||
side = 0; |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
// set side = 0 if you want a log without "hanging sides" |
||||
|
||||
if (!hang) { side = 0; } |
||||
|
||||
if (side == 1) { |
||||
|
||||
// positive vertical side |
||||
|
||||
VERTEX.y = -(dist_z - Dz) - RADIUS; |
||||
|
||||
VERTEX.z = dist_y + RADIUS; |
||||
|
||||
} |
||||
|
||||
if (side == -1) { |
||||
|
||||
// negative vertical side |
||||
|
||||
VERTEX.y = (dist_z + Dz) - RADIUS; |
||||
|
||||
VERTEX.z = - (dist_y + RADIUS); |
||||
|
||||
} |
||||
|
||||
if (side == 0) { |
||||
|
||||
// rolling log |
||||
|
||||
VERTEX.y = (dist_y + RADIUS)*cos(theta) - RADIUS; |
||||
|
||||
VERTEX.z = (dist_y + RADIUS)*sin(theta) ; |
||||
|
||||
} |
||||
|
||||
// reposition world vertices |
||||
|
||||
VERTEX.z += player_pos.z; |
||||
|
||||
} |
||||
|
||||
// todo - recalculate normals |
||||
|
||||
if (remap_normals) { |
||||
|
||||
if (side == 1) { |
||||
|
||||
//vec3 normal = normalize(vec3(NORMAL.x, -NORMAL.z, NORMAL.y)); |
||||
|
||||
vec3 normal = normalize(vec3(0.0, 1.0, 0.0)); |
||||
|
||||
NORMAL = normal; |
||||
|
||||
} else if (side == -1) { |
||||
|
||||
//vec3 normal = normalize(vec3(NORMAL.x, NORMAL.z, -NORMAL.y)); |
||||
|
||||
vec3 normal = normalize(vec3(0.0, 1.0, 0.0)); |
||||
|
||||
NORMAL = normal; |
||||
|
||||
} else if (side == 0) { |
||||
|
||||
// todo - check this math! |
||||
|
||||
vec3 normal = normalize(vec3( |
||||
|
||||
NORMAL.x, |
||||
|
||||
NORMAL.y * cos(theta) - NORMAL.z * sin(theta), |
||||
|
||||
NORMAL.z * cos(theta) + NORMAL.z * sin(theta) |
||||
|
||||
)); |
||||
|
||||
NORMAL = normal; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
Binary file not shown.
File diff suppressed because one or more lines are too long
@ -0,0 +1,16 @@ |
||||
[gd_resource type="ShaderMaterial" load_steps=4 format=2] |
||||
|
||||
[ext_resource path="res://MultiColorFog/MultiColorFog.shader" type="Shader" id=1] |
||||
|
||||
[sub_resource type="Gradient" id=1] |
||||
offsets = PoolRealArray( 0, 0.257862, 1 ) |
||||
colors = PoolColorArray( 0.572549, 1, 0.639216, 0, 0.967743, 0.410156, 1, 0.647799, 1, 0.517647, 0.517647, 1 ) |
||||
|
||||
[sub_resource type="GradientTexture" id=2] |
||||
gradient = SubResource( 1 ) |
||||
|
||||
[resource] |
||||
shader = ExtResource( 1 ) |
||||
shader_param/fog_intensity = 0.919 |
||||
shader_param/fog_amount = 0.011 |
||||
shader_param/gradient = SubResource( 2 ) |
||||
@ -0,0 +1,12 @@ |
||||
[gd_scene load_steps=3 format=2] |
||||
|
||||
[ext_resource path="res://MultiColorFog/MultiColorFogMaterial.tres" type="Material" id=1] |
||||
|
||||
[sub_resource type="QuadMesh" id=1] |
||||
material = ExtResource( 1 ) |
||||
size = Vector2( 2, 2 ) |
||||
|
||||
[node name="MultiColorFogOverlay" type="MeshInstance"] |
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.1 ) |
||||
mesh = SubResource( 1 ) |
||||
material/0 = null |
||||
@ -0,0 +1,28 @@ |
||||
shader_type spatial; |
||||
render_mode unshaded; |
||||
|
||||
uniform sampler2D gradient: hint_albedo; |
||||
uniform float fog_intensity: hint_range(0.0, 1.0); |
||||
uniform float fog_amount: hint_range(0.0, 1.0); |
||||
|
||||
void vertex() { |
||||
POSITION = vec4(VERTEX, 1.0); |
||||
} |
||||
|
||||
void fragment() { |
||||
vec4 original = texture(SCREEN_TEXTURE, SCREEN_UV); |
||||
|
||||
float depth = texture(DEPTH_TEXTURE, SCREEN_UV).x; |
||||
vec3 ndc= vec3(SCREEN_UV, depth) * 2.0 - 1.0; |
||||
vec4 view = INV_PROJECTION_MATRIX* vec4(ndc, 1.0); |
||||
view.xyz /= view.w; |
||||
depth = -view.z; |
||||
|
||||
float fog = depth * fog_amount; |
||||
|
||||
vec4 fog_color = texture(gradient, vec2(fog, 0.0)); |
||||
if (depth > 1.0) |
||||
ALBEDO = mix(original.rgb, fog_color.rgb, fog_color.a * fog_intensity); |
||||
else |
||||
ALBEDO = fog_color.rgb; |
||||
} |
||||
@ -0,0 +1,30 @@ |
||||
shader_type spatial; |
||||
render_mode unshaded; |
||||
|
||||
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; |
||||
uniform sampler2D DEPTH_TEXTURE : hint_depth_texture, filter_linear_mipmap; |
||||
uniform sampler2D gradient: source_color; |
||||
uniform float fog_intensity: hint_range(0.0, 1.0); |
||||
uniform float fog_amount: hint_range(0.0, 1.0); |
||||
|
||||
void vertex() { |
||||
POSITION = vec4(VERTEX, 1.0); |
||||
} |
||||
|
||||
void fragment() { |
||||
vec4 original = texture(SCREEN_TEXTURE, SCREEN_UV); |
||||
|
||||
float depth = texture(DEPTH_TEXTURE, SCREEN_UV).x; |
||||
vec3 ndc= vec3(SCREEN_UV, depth) * 2.0 - 1.0; |
||||
vec4 view = INV_PROJECTION_MATRIX* vec4(ndc, 1.0); |
||||
view.xyz /= view.w; |
||||
depth = -view.z; |
||||
|
||||
float fog = depth * fog_amount; |
||||
|
||||
vec4 fog_color = texture(gradient, vec2(fog, 0.0)); |
||||
if (depth > 1.0) |
||||
ALBEDO = mix(original.rgb, fog_color.rgb, fog_color.a * fog_intensity); |
||||
else |
||||
ALBEDO = fog_color.rgb; |
||||
} |
||||
@ -0,0 +1,253 @@ |
||||
extends Node3D |
||||
|
||||
const Entity3D = preload("res://scenes/Instance.tscn") |
||||
|
||||
var thread |
||||
var displayed_chunks = {} # displayed_chunks |
||||
var unready_chunks = {} |
||||
|
||||
#@onready var camera = get_node("Camera3D") |
||||
#@export @onready var camera = get_node(camera) |
||||
@export var camera: Camera3D |
||||
|
||||
var chunks: Array |
||||
|
||||
|
||||
func _ready(): |
||||
thread = Thread.new() |
||||
# pass |
||||
init_chunks() |
||||
# setFloor() |
||||
# setEntities() |
||||
|
||||
func init_chunks(): |
||||
for x in Global.world.width / Global.world.chunk_size: |
||||
chunks.append([]) |
||||
for y in Global.world.height / Global.world.chunk_size: |
||||
chunks[x].append([]) |
||||
chunks[x][y] = Chunk.new(x, y, Global.world.chunk_size) |
||||
chunks[x][y].set_name("Chunk") |
||||
# print(chunks) |
||||
# |
||||
#func create_chunk(coord: Vector2i): |
||||
# var chunk = GridMap.new() |
||||
# for mx in Global.world.chunk_size: |
||||
# for mz in Global.world.chunk_size: |
||||
# var bloc = Global.world.get_bloc(Vector2i(mx * Global.world.chunk_size, mz * Global.world.chunk_size)) |
||||
# var my: float = bloc.position.y |
||||
# var meshID |
||||
# var mesh_rotation |
||||
# if bloc.type != 0: |
||||
# var neighbours = Global.world.get_neighbours_4_at_same_height(Vector2i(mx, mz)) |
||||
# if neighbours == Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_3 |
||||
# mesh_rotation = Global.GRID_ROTATION[3] |
||||
# elif neighbours == Global.directions_4.LEFT: |
||||
# meshID = Global.bloc_sides_id.SIDE_3 |
||||
# mesh_rotation = Global.GRID_ROTATION[1] |
||||
# elif neighbours == Global.directions_4.LEFT + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_2_OPPOSITE |
||||
# mesh_rotation = Global.GRID_ROTATION[0] |
||||
# elif neighbours == Global.directions_4.BOTTOM: |
||||
# meshID = Global.bloc_sides_id.SIDE_3 |
||||
# mesh_rotation = Global.GRID_ROTATION[0] |
||||
# elif neighbours == Global.directions_4.BOTTOM + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_2_ANGLE |
||||
# mesh_rotation = Global.GRID_ROTATION[3] |
||||
# elif neighbours == Global.directions_4.BOTTOM + Global.directions_4.LEFT: |
||||
# meshID = Global.bloc_sides_id.SIDE_2_ANGLE |
||||
# mesh_rotation = Global.GRID_ROTATION[0] |
||||
# elif neighbours == Global.directions_4.BOTTOM + Global.directions_4.LEFT + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_1 |
||||
# mesh_rotation = Global.GRID_ROTATION[0] |
||||
# elif neighbours == Global.directions_4.TOP: |
||||
# meshID = Global.bloc_sides_id.SIDE_3 |
||||
# mesh_rotation = Global.GRID_ROTATION[2] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_2_ANGLE |
||||
# mesh_rotation = Global.GRID_ROTATION[2] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.LEFT: |
||||
# meshID = Global.bloc_sides_id.SIDE_2_ANGLE |
||||
# mesh_rotation = Global.GRID_ROTATION[1] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.LEFT + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_1 |
||||
# mesh_rotation = Global.GRID_ROTATION[2] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM: |
||||
# meshID = Global.bloc_sides_id.SIDE_2_OPPOSITE |
||||
# mesh_rotation = Global.GRID_ROTATION[1] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_1 |
||||
# mesh_rotation = Global.GRID_ROTATION[3] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM + Global.directions_4.LEFT: |
||||
# meshID = Global.bloc_sides_id.SIDE_1 |
||||
# mesh_rotation = Global.GRID_ROTATION[1] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM + Global.directions_4.LEFT + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_0 |
||||
# mesh_rotation = Global.GRID_ROTATION[0] |
||||
# elif neighbours == 0: |
||||
# meshID = Global.bloc_sides_id.SIDE_4 |
||||
# mesh_rotation = Global.GRID_ROTATION[0] |
||||
# |
||||
# chunk.set_cell_item( Vector3(mx, my, mz) , meshID, mesh_rotation) |
||||
# return chunk |
||||
|
||||
#func setFloor(): |
||||
# clear() |
||||
# for mz in range(0, Global.world.width - 1): |
||||
# for mx in range(0, Global.world.height - 1): |
||||
# var bloc = Global.world.get_bloc(Vector2i(mx, mz)) |
||||
# var my: float = bloc.position.y |
||||
# var meshID |
||||
# var mesh_rotation |
||||
# if bloc.type != 0: |
||||
# var neighbours = Global.world.get_neighbours_4_at_same_height(Vector2i(mx, mz)) |
||||
# if neighbours == Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_3 |
||||
# mesh_rotation = Global.GRID_ROTATION[3] |
||||
# elif neighbours == Global.directions_4.LEFT: |
||||
# meshID = Global.bloc_sides_id.SIDE_3 |
||||
# mesh_rotation = Global.GRID_ROTATION[1] |
||||
# elif neighbours == Global.directions_4.LEFT + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_2_OPPOSITE |
||||
# mesh_rotation = Global.GRID_ROTATION[0] |
||||
# elif neighbours == Global.directions_4.BOTTOM: |
||||
# meshID = Global.bloc_sides_id.SIDE_3 |
||||
# mesh_rotation = Global.GRID_ROTATION[0] |
||||
# elif neighbours == Global.directions_4.BOTTOM + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_2_ANGLE |
||||
# mesh_rotation = Global.GRID_ROTATION[3] |
||||
# elif neighbours == Global.directions_4.BOTTOM + Global.directions_4.LEFT: |
||||
# meshID = Global.bloc_sides_id.SIDE_2_ANGLE |
||||
# mesh_rotation = Global.GRID_ROTATION[0] |
||||
# elif neighbours == Global.directions_4.BOTTOM + Global.directions_4.LEFT + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_1 |
||||
# mesh_rotation = Global.GRID_ROTATION[0] |
||||
# elif neighbours == Global.directions_4.TOP: |
||||
# meshID = Global.bloc_sides_id.SIDE_3 |
||||
# mesh_rotation = Global.GRID_ROTATION[2] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_2_ANGLE |
||||
# mesh_rotation = Global.GRID_ROTATION[2] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.LEFT: |
||||
# meshID = Global.bloc_sides_id.SIDE_2_ANGLE |
||||
# mesh_rotation = Global.GRID_ROTATION[1] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.LEFT + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_1 |
||||
# mesh_rotation = Global.GRID_ROTATION[2] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM: |
||||
# meshID = Global.bloc_sides_id.SIDE_2_OPPOSITE |
||||
# mesh_rotation = Global.GRID_ROTATION[1] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_1 |
||||
# mesh_rotation = Global.GRID_ROTATION[3] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM + Global.directions_4.LEFT: |
||||
# meshID = Global.bloc_sides_id.SIDE_1 |
||||
# mesh_rotation = Global.GRID_ROTATION[1] |
||||
# elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM + Global.directions_4.LEFT + Global.directions_4.RIGHT: |
||||
# meshID = Global.bloc_sides_id.SIDE_0 |
||||
# mesh_rotation = Global.GRID_ROTATION[0] |
||||
# elif neighbours == 0: |
||||
# meshID = Global.bloc_sides_id.SIDE_4 |
||||
# mesh_rotation = Global.GRID_ROTATION[0] |
||||
# |
||||
# set_cell_item( Vector3(mx, my, mz) , meshID, mesh_rotation) |
||||
# |
||||
#func setEntities(): |
||||
# for entity in Global.world.entities: |
||||
# var entity_instance = Entity3D.instantiate() |
||||
# entity_instance.id = entity.id |
||||
# entity_instance.position = map_to_local(Vector3(entity.position.x, entity.position.y, entity.position.z)) |
||||
# entity_instance.connect_to_world(entity_instance.id) |
||||
# add_child(entity_instance) |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func add_chunk(x, z): |
||||
var key = str(x) + "," + str(z) |
||||
if displayed_chunks.has(key) or unready_chunks.has(key): |
||||
return |
||||
if not thread.is_started(): |
||||
|
||||
thread.start(Callable(self, "load_chunk").bind([thread, x, z])) |
||||
# thread.start(self, "load_chunk", [thread, x, z]) |
||||
unready_chunks[key] = 1 |
||||
# |
||||
#func gen_chunk(array): |
||||
# var thread = array[0] |
||||
# var x = array[1] |
||||
# var z = array[2] |
||||
# var chunk = { |
||||
# "x": x, |
||||
# "y": z, |
||||
# "should_remove": true |
||||
# } |
||||
# |
||||
# call_deferred("load_done", chunk, thread) |
||||
|
||||
|
||||
func load_chunk(array): |
||||
var thread = array[0] |
||||
var posX = array[1] |
||||
var posZ = array[2] |
||||
|
||||
var x = fmod(posX, Global.world.width / Global.world.chunk_size) |
||||
var z = fmod(posZ, Global.world.height / Global.world.chunk_size) |
||||
# |
||||
# # Chargement du chunk |
||||
var chunk = chunks[x][z] |
||||
## var chunk = Chunk.new() |
||||
# chunk.translate(Vector3(posX * Global.world.chunk_size, 0, posZ * Global.world.chunk_size)) |
||||
var chunk_position = Vector2(posX, posZ) |
||||
chunk.position = Vector3(posX * Global.world.chunk_size, 0, posZ * Global.world.chunk_size) |
||||
call_deferred("load_done", chunk, thread, chunk_position) |
||||
|
||||
func load_done(chunk, thread, position): |
||||
add_child(chunk) |
||||
var key = str(position.x) + "," + str(position.y) |
||||
displayed_chunks[key] = chunk |
||||
unready_chunks.erase(key) |
||||
thread.wait_to_finish() |
||||
|
||||
func get_chunk(x, z): |
||||
var key = str(x) + "," + str(z) |
||||
if displayed_chunks.has(key): |
||||
return displayed_chunks.get(key) |
||||
|
||||
return null |
||||
|
||||
func _process(delta): |
||||
update_chunks() |
||||
clean_up_chunks() |
||||
reset_chunks() |
||||
|
||||
func update_chunks(): |
||||
var camera_translation = camera.position |
||||
var c_x = int(camera_translation.x) / Global.world.chunk_size |
||||
var c_z = int(camera_translation.z) / Global.world.chunk_size |
||||
|
||||
for x in range(c_x - Global.world.chunk_number * 0.5, c_x + Global.world.chunk_number * 0.53): |
||||
for z in range(c_z - Global.world.chunk_number * 0.5, c_z + Global.world.chunk_number * 0.53): |
||||
add_chunk(x, z) |
||||
var chunk = get_chunk(x, z) |
||||
if chunk != null: |
||||
chunk.should_remove = false |
||||
|
||||
func clean_up_chunks(): |
||||
for key in displayed_chunks: |
||||
var chunk = displayed_chunks[key] |
||||
if chunk.should_remove: |
||||
remove_child(chunk) |
||||
displayed_chunks.erase(key) |
||||
|
||||
func reset_chunks(): |
||||
for key in displayed_chunks: |
||||
var chunk = displayed_chunks[key] |
||||
chunk.should_remove = true |
||||
Loading…
Reference in new issue