From 1db4a87a55710c4c0581b747892d8da5332dbe43 Mon Sep 17 00:00:00 2001 From: "@racascou" Date: Thu, 23 Jun 2022 15:42:11 -0300 Subject: [PATCH 1/2] fog test --- prototype/map/fog.gd | 64 +++++++++++++++-------------------------- prototype/utils/test.gd | 2 +- 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/prototype/map/fog.gd b/prototype/map/fog.gd index 8d3a60f8..9966cc9d 100644 --- a/prototype/map/fog.gd +++ b/prototype/map/fog.gd @@ -21,37 +21,22 @@ func _ready(): func skip_start(): clear_frame = (clear_frame + 1) % clear_skip - if clear_frame%(clear_skip*2) == 0: cover_map() + if clear_frame % clear_skip == 0 : cover_map() -var quarter = 0 - func cover_map(): - if quarter == 0: - for y in floor(tile_map_size/2): - for x in floor(tile_map_size/2): - game.map.fog.set_cell(x, y, 0) - - if quarter == 1: - for y in range(floor(tile_map_size/2), tile_map_size): - for x in floor(tile_map_size/2): - game.map.fog.set_cell(x, y, 0) - - if quarter == 2: - for y in tile_map_size: - for x in range(floor(tile_map_size/2), tile_map_size): - game.map.fog.set_cell(x, y, 0) - - if quarter == 3: - for y in tile_map_size: - for x in range(floor(tile_map_size/2), tile_map_size): - game.map.fog.set_cell(x, y, 0) - - quarter = (quarter + 1) % 4 + for y in floor(tile_map_size): + for x in floor(tile_map_size): + game.map.fog.set_cell(x, y, 0) var sight_mem:Dictionary = {} - +# computes and caches 2d arrays with circle booleans eg: +# 00100 +# 01110 +# 11111 +# 01110 +# 00100 func compute_sight(unit): var id = game.unit.modifiers.get_value(unit, "vision") if id in sight_mem: return sight_mem[id] @@ -63,14 +48,13 @@ func compute_sight(unit): for x in range(0, 2*rad): var r = Vector2(x-rad, y-rad) var d = r.length() - a[a.size()-1].append(d < rad) + a[a.size()-1].append(d <= rad) sight_mem[id] = a return a func clear_sigh_skip(unit): - if clear_frame%clear_skip == 0: - clear_sight(unit) + if clear_frame % clear_skip == 0 : clear_sight(unit) func clear_sight(unit): @@ -84,19 +68,17 @@ func clear_sight(unit): for x in a[y].size(): if (a[y][x]): var p = pos - Vector2(rad,rad) + Vector2(x,y) - if (unit.type == "building"): - game.map.fog.set_cellv(p, -1) - else: - if game.map.fog.get_cellv(p) >= 0: - var line = game.unit.follow.path_finder.expandPath([[pos.x, pos.y], [p.x, p.y]]) - var blocked = false - for point in line: - var tree = trees.get_cell(point[0]/3, point[1]/3) - if tree > 0: - blocked = true - - if not blocked: game.map.fog.set_cellv(p, -1) - +# if (unit.type == "building"): + game.map.fog.set_cellv(p, -1) +# else: +# if game.map.fog.get_cellv(p) >= 0: +# var line = game.unit.follow.path_finder.expandPath([[pos.x, pos.y], [p.x, p.y]]) +# var blocked = false +# for point in line: +# var tree = trees.get_cell(point[0]/3, point[1]/3) +# if tree > 0: blocked = true +# if not blocked: game.map.fog.set_cellv(p, -1) +# # var la = PI/6 # var a = abs(game.utils.limit_angle(r.angle() - unit.angle)) # if d > rad and (unit.type == "building" or a Date: Thu, 30 Jun 2022 15:15:47 -0300 Subject: [PATCH 2/2] fog pre shader --- prototype/map/fog.gd | 84 ++++++++++++++++++++++++++----------- prototype/unit/collision.gd | 11 +++-- prototype/unit/unit.gd | 2 + 3 files changed, 70 insertions(+), 27 deletions(-) diff --git a/prototype/map/fog.gd b/prototype/map/fog.gd index 9966cc9d..6e2de9c4 100644 --- a/prototype/map/fog.gd +++ b/prototype/map/fog.gd @@ -4,7 +4,7 @@ var game:Node var tile_map_size:int var trees:TileMap -var clear_skip:int = 10 +var clear_skip:int = 16 var clear_frame:int = 0 @@ -30,16 +30,20 @@ func cover_map(): game.map.fog.set_cell(x, y, 0) -var sight_mem:Dictionary = {} -# computes and caches 2d arrays with circle booleans eg: +# computes and caches 2d arrays with circle as booleans eg: # 00100 -# 01110 -# 11111 -# 01110 +# 01010 +# 10001 +# 01010 # 00100 -func compute_sight(unit): +var border_sight_mem:Dictionary = {} +var sight_mem:Dictionary = {} +func compute_sight(unit, border): var id = game.unit.modifiers.get_value(unit, "vision") - if id in sight_mem: return sight_mem[id] + if border: + if id in border_sight_mem: return border_sight_mem[id] + else: + if id in sight_mem: return sight_mem[id] var a = [] if id > 0: var rad = round(id/cell_size.x) @@ -48,8 +52,12 @@ func compute_sight(unit): for x in range(0, 2*rad): var r = Vector2(x-rad, y-rad) var d = r.length() - a[a.size()-1].append(d <= rad) - sight_mem[id] = a + if border: + a[a.size()-1].append(d <= rad && d > rad - 1.5) + else: + a[a.size()-1].append(d <= rad) + if border: border_sight_mem[id] = a + else: sight_mem[id] = a return a @@ -58,28 +66,56 @@ func clear_sigh_skip(unit): func clear_sight(unit): - var id = game.unit.modifiers.get_value(unit, "vision") - if id > 0: + if unit.team == game.player_team: + var id = game.unit.modifiers.get_value(unit, "vision") var rad = round(id/cell_size.x) var pos = world_to_map(unit.global_position) - var a = compute_sight(unit) + if id > 0: + #if unit.type != "leader": + var a = compute_sight(unit, false) + for y in a.size(): + for x in a[y].size(): + if (a[y][x]): + var p = pos - Vector2(rad,rad) + Vector2(x,y) + game.map.fog.set_cellv(p, -1) + + # adds tree shadows - for y in a.size(): - for x in a[y].size(): - if (a[y][x]): - var p = pos - Vector2(rad,rad) + Vector2(x,y) -# if (unit.type == "building"): - game.map.fog.set_cellv(p, -1) -# else: -# if game.map.fog.get_cellv(p) >= 0: +# else: +# var a = compute_sight(unit, true) +# for y in a.size(): +# for x in a[y].size(): +# if (a[y][x]): +# var p = pos - Vector2(rad,rad) + Vector2(x,y) # var line = game.unit.follow.path_finder.expandPath([[pos.x, pos.y], [p.x, p.y]]) # var blocked = false # for point in line: +# var point_pos = Vector2(point[0], point[1]) # var tree = trees.get_cell(point[0]/3, point[1]/3) # if tree > 0: blocked = true -# if not blocked: game.map.fog.set_cellv(p, -1) -# +# if not blocked: game.map.fog.set_cellv(point_pos, -1) +# +# adds sight angle limit +# +# if unit has sight angle: # var la = PI/6 # var a = abs(game.utils.limit_angle(r.angle() - unit.angle)) -# if d > rad and (unit.type == "building" or a rad and a