Skip to content

Commit

Permalink
Improved network sync
Browse files Browse the repository at this point in the history
- Fixed the misconnected country in Novingrad
- Added synchronization of flashing across the network.
- Simplified synchronization of flashing, moving countries and the stopping of flashing across network.
  • Loading branch information
ra314 committed Sep 28, 2021
1 parent 5f7e71d commit e73ec58
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 64 deletions.
74 changes: 37 additions & 37 deletions Novingrad.save
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
{"connections":["ff373737","ff414141"],"name":"ff323232","troops":1,"x":1037.793945,"y":198.088013}
{"connections":["ffcd6969","ff323232"],"name":"ff373737","troops":3,"x":942.794006,"y":149.088013}
{"connections":[],"name":"ff373769","troops":2,"x":809.794006,"y":488.088013}
{"connections":["ff414141","ff464646","ff69cd69","ff69c369"],"name":"ff3c3c3c","troops":2,"x":1183.793945,"y":361.088013}
{"connections":["ff323232","ff3c3c3c","ff464646","ff69cd69"],"name":"ff414141","troops":4,"x":1115.793945,"y":291.088013}
{"connections":["ffcd6969","ff323232"],"name":"ff373737","troops":1,"x":942.794006,"y":149.088013}
{"connections":["ff695f69","ff695f69","ff695569","ff693769","ff697369"],"name":"ff373769","troops":1,"x":812.794006,"y":487.088013}
{"connections":["ff414141","ff464646","ff69cd69","ff69c369"],"name":"ff3c3c3c","troops":3,"x":1183.793945,"y":361.088013}
{"connections":["ff323232","ff3c3c3c","ff464646","ff69cd69"],"name":"ff414141","troops":1,"x":1115.793945,"y":291.088013}
{"connections":["ff414141","ff3c3c3c","ff505050"],"name":"ff464646","troops":2,"x":1255.793945,"y":368.088013}
{"connections":["ff69b969","ff555555","ff464646"],"name":"ff505050","troops":2,"x":1284.793945,"y":509.088013}
{"connections":["ff5a5a5a","ff505050"],"name":"ff555555","troops":1,"x":1450.793945,"y":629.088013}
{"connections":["ff555555","ff5f5f5f","ff646464","ff696991"],"name":"ff5a5a5a","troops":2,"x":1432.793945,"y":735.088013}
{"connections":["ff5a5a5a","ff646464","ff696969"],"name":"ff5f5f5f","troops":2,"x":1532.793945,"y":839.088013}
{"connections":["ff5f5f5f","ff5a5a5a","ff696969"],"name":"ff646464","troops":2,"x":1398.793945,"y":816.088013}
{"connections":["ff697369","ff696969","ff694b69","ff695569","ff694169"],"name":"ff693769","troops":1,"x":858.794006,"y":578.088013}
{"connections":["ff698769","ff697369","ff694b69","ff693769","ff699169","ff699b69"],"name":"ff694169","troops":1,"x":791.794006,"y":635.088013}
{"connections":["ff69b969","ff555555","ff464646"],"name":"ff505050","troops":1,"x":1284.793945,"y":509.088013}
{"connections":["ff505050","ff5a5a5a"],"name":"ff555555","troops":1,"x":1450.793945,"y":629.088013}
{"connections":["ff555555","ff696991","ff646464","ff5f5f5f","ff5f5f5f","ff646464"],"name":"ff5a5a5a","troops":1,"x":1418.793945,"y":739.088013}
{"connections":["ff5a5a5a","ff646464","ff5a5a5a","ff696969"],"name":"ff5f5f5f","troops":1,"x":1530.793945,"y":831.088013}
{"connections":["ff5a5a5a","ff5f5f5f","ff696969","ff5a5a5a"],"name":"ff646464","troops":1,"x":1400.793945,"y":816.088013}
{"connections":["ff697369","ff694b69","ff695569","ff694169","ff373769"],"name":"ff693769","troops":1,"x":858.794006,"y":578.088013}
{"connections":["ff698769","ff697369","ff694b69","ff693769","ff699169","ff699b69"],"name":"ff694169","troops":2,"x":791.794006,"y":635.088013}
{"connections":["ff693769","ff695569","ff69af69","ff699b69","ff69a569","ff694169"],"name":"ff694b69","troops":1,"x":927.794006,"y":643.088013}
{"connections":["ff696969","ff695f69","ff69c369","ff69af69","ff694b69","ff693769","ff69b969"],"name":"ff695569","troops":1,"x":938.794006,"y":544.088013}
{"connections":["ff696969","ff9b6969","ff69cd69","ff69c369","ff695569"],"name":"ff695f69","troops":1,"x":905.794006,"y":414.088013}
{"connections":["ff697369","ff695f69","ff693769","ff695569","ff5f5f5f","ff646464"],"name":"ff696969","troops":2,"x":1448.793945,"y":870.088013}
{"connections":["ff696991","ff69699b","ff69a569"],"name":"ff696973","troops":2,"x":1207.793945,"y":773.088013}
{"connections":["ff5a5a5a","ff696973","ff69af69"],"name":"ff696991","troops":1,"x":1237.793945,"y":684.088013}
{"connections":["ff696973","ff6969a5","ff6969b9"],"name":"ff69699b","troops":3,"x":1115.793945,"y":854.088013}
{"connections":["ff69699b","ff6969b9"],"name":"ff6969a5","troops":2,"x":1018.793945,"y":951.088013}
{"connections":["ff69c369","ff69af69","ff694b69","ff693769","ff69b969","ff695f69","ff373769"],"name":"ff695569","troops":1,"x":938.794006,"y":544.088013}
{"connections":["ff9b6969","ff69cd69","ff69c369","ff695569","ff373769","ff373769"],"name":"ff695f69","troops":1,"x":898.794006,"y":419.088013}
{"connections":["ff5f5f5f","ff646464"],"name":"ff696969","troops":1,"x":1428.793945,"y":868.088013}
{"connections":["ff696991","ff69699b","ff69a569"],"name":"ff696973","troops":1,"x":1207.793945,"y":773.088013}
{"connections":["ff696973","ff69af69","ff5a5a5a"],"name":"ff696991","troops":2,"x":1237.793945,"y":684.088013}
{"connections":["ff696973","ff6969a5","ff6969b9"],"name":"ff69699b","troops":1,"x":1115.793945,"y":854.088013}
{"connections":["ff69699b","ff6969b9"],"name":"ff6969a5","troops":1,"x":1018.793945,"y":951.088013}
{"connections":["ff6969b9","ff6969c8","ff6969d2","ff699169"],"name":"ff6969af","troops":2,"x":804.794006,"y":820.088013}
{"connections":["ff6969a5","ff6969af","ff6969c8","ff69699b","ff699b69"],"name":"ff6969b9","troops":4,"x":946.794006,"y":825.088013}
{"connections":["ff6969af","ff6969b9","ff6969d2"],"name":"ff6969c8","troops":2,"x":831.794006,"y":939.088013}
{"connections":["ff6969a5","ff6969af","ff6969c8","ff69699b","ff699b69"],"name":"ff6969b9","troops":2,"x":946.794006,"y":825.088013}
{"connections":["ff6969af","ff6969b9","ff6969d2"],"name":"ff6969c8","troops":1,"x":831.794006,"y":939.088013}
{"connections":["ff6969af","ff6969c8","ff6969fa"],"name":"ff6969d2","troops":2,"x":649.794006,"y":910.088013}
{"connections":["ff6969d2","ff697d69"],"name":"ff6969fa","troops":2,"x":457.794006,"y":831.088013}
{"connections":["ff697d69","ff698769","ff694169","ff696969","ff693769"],"name":"ff697369","troops":1,"x":676.794006,"y":530.088013}
{"connections":["ff6969d2","ff697d69"],"name":"ff6969fa","troops":1,"x":457.794006,"y":831.088013}
{"connections":["ff697d69","ff698769","ff694169","ff693769","ff373769"],"name":"ff697369","troops":2,"x":676.794006,"y":530.088013}
{"connections":["ff6969fa","ff697369","ff698769"],"name":"ff697d69","troops":1,"x":595.794006,"y":591.088013}
{"connections":["ff697d69","ff697369","ff694169","ff699169"],"name":"ff698769","troops":1,"x":692.794006,"y":634.088013}
{"connections":["ff698769","ff699b69","ff6969af","ff694169"],"name":"ff699169","troops":1,"x":819.794006,"y":716.088013}
{"connections":["ff694b69","ff699169","ff6969b9","ff69a569","ff694169"],"name":"ff699b69","troops":1,"x":958.794006,"y":716.088013}
{"connections":["ff696973","ff694b69","ff699b69","ff69af69"],"name":"ff69a569","troops":2,"x":1071.793945,"y":688.088013}
{"connections":["ff69b969","ff695569","ff696991","ff694b69","ff69a569"],"name":"ff69af69","troops":2,"x":1073.793945,"y":595.088013}
{"connections":["ff69c369","ff69af69","ff695569","ff505050"],"name":"ff69b969","troops":1,"x":1154.793945,"y":550.088013}
{"connections":["ff695f69","ff69cd69","ff3c3c3c","ff69b969","ff695569"],"name":"ff69c369","troops":1,"x":1061.793945,"y":442.088013}
{"connections":["ff695f69","ff414141","ff3c3c3c","ff69c369"],"name":"ff69cd69","troops":1,"x":967.794006,"y":346.088013}
{"connections":["ff7d6969","ff876969","ff916969","ff9b6969"],"name":"ff736969","troops":2,"x":682.794006,"y":327.088013}
{"connections":["ffb96969","ff876969","ff736969"],"name":"ff7d6969","troops":1,"x":605.794006,"y":282.088013}
{"connections":["ffb96969","ff7d6969","ffaf6969","ff916969","ff736969"],"name":"ff876969","troops":2,"x":665.794006,"y":261.088013}
{"connections":["ff697d69","ff697369","ff694169","ff699169"],"name":"ff698769","troops":2,"x":692.794006,"y":634.088013}
{"connections":["ff698769","ff699b69","ff6969af","ff694169"],"name":"ff699169","troops":2,"x":819.794006,"y":716.088013}
{"connections":["ff694b69","ff699169","ff6969b9","ff69a569","ff694169"],"name":"ff699b69","troops":4,"x":958.794006,"y":716.088013}
{"connections":["ff696973","ff694b69","ff699b69","ff69af69"],"name":"ff69a569","troops":1,"x":1071.793945,"y":688.088013}
{"connections":["ff69b969","ff695569","ff696991","ff694b69","ff69a569"],"name":"ff69af69","troops":4,"x":1073.793945,"y":595.088013}
{"connections":["ff69c369","ff69af69","ff695569","ff505050"],"name":"ff69b969","troops":2,"x":1154.793945,"y":550.088013}
{"connections":["ff69cd69","ff3c3c3c","ff69b969","ff695569","ff695f69"],"name":"ff69c369","troops":2,"x":1061.793945,"y":442.088013}
{"connections":["ff414141","ff3c3c3c","ff69c369","ff695f69"],"name":"ff69cd69","troops":1,"x":967.794006,"y":346.088013}
{"connections":["ff7d6969","ff876969","ff916969","ff9b6969"],"name":"ff736969","troops":3,"x":682.794006,"y":327.088013}
{"connections":["ffb96969","ff876969","ff736969"],"name":"ff7d6969","troops":3,"x":605.794006,"y":282.088013}
{"connections":["ffb96969","ff7d6969","ffaf6969","ff916969","ff736969"],"name":"ff876969","troops":4,"x":665.794006,"y":261.088013}
{"connections":["ff876969","ff736969","ff9b6969","ffa56969","ffaf6969"],"name":"ff916969","troops":1,"x":725.794006,"y":260.088013}
{"connections":["ff736969","ff916969","ffa56969","ff695f69"],"name":"ff9b6969","troops":1,"x":796.794006,"y":267.088013}
{"connections":["ff9b6969","ff916969","ffaf6969","ffcd6969"],"name":"ffa56969","troops":2,"x":814.794006,"y":202.088013}
{"connections":["ff9b6969","ff916969","ffaf6969","ffcd6969"],"name":"ffa56969","troops":1,"x":814.794006,"y":202.088013}
{"connections":["ffb96969","ffc36969","ff876969","ff916969","ffa56969","ffcd6969"],"name":"ffaf6969","troops":4,"x":701.794006,"y":201.088013}
{"connections":["ff7d6969","ff876969","ffaf6969","ffc36969"],"name":"ffb96969","troops":3,"x":608.794006,"y":182.088013}
{"connections":["ffb96969","ffaf6969","ffcd6969"],"name":"ffc36969","troops":2,"x":690.794006,"y":124.088013}
{"connections":["ffc36969","ffa56969","ffaf6969","ff373737"],"name":"ffcd6969","troops":2,"x":793.794006,"y":129.088013}
{"connections":["ff7d6969","ff876969","ffaf6969","ffc36969"],"name":"ffb96969","troops":1,"x":608.794006,"y":182.088013}
{"connections":["ffb96969","ffaf6969","ffcd6969"],"name":"ffc36969","troops":1,"x":690.794006,"y":124.088013}
{"connections":["ffc36969","ffa56969","ffaf6969","ff373737"],"name":"ffcd6969","troops":1,"x":793.794006,"y":129.088013}
24 changes: 7 additions & 17 deletions Scripts/Levels/Level Components/Country.gd
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ func update_labels():
if Game_Manager:
Game_Manager.update_labels()

func flash_attackable_neighbours(player):
func flash_attackable_neighbours(player_color):
# Creation of a mask sprite to do the flashing
for country in connected_countries:
if not country.flash_mask_sprite:
print(str(country.create_flash_mask_sprite()) + "ms")

# Flash all countries that are not owned by the provided player
for country in connected_countries:
if country.belongs_to != player:
if country.belongs_to.color != player_color:
country.flashing = true

func draw_line_to_country(selected_country):
Expand Down Expand Up @@ -182,10 +184,7 @@ func on_click(event):
Game_Manager.selected_country = null

# Movement animation
attacker.move_to_country(self)
# Networked component of movement animation
if Game_Manager._root.online_game:
Game_Manager.move_country_across_network(attacker.country_name, country_name)
Game_Manager.move_country_across_network(attacker.country_name, country_name)

# Phase change
if Game_Manager.is_attack_over():
Expand All @@ -195,8 +194,8 @@ func on_click(event):
Game_Manager.end_game(defender.color)
else:
print("flashing")
Game_Manager.selected_country = self
flash_attackable_neighbours(Game_Manager.curr_player)
Game_Manager.selected_country = self
Game_Manager.flash_across_network(Game_Manager.curr_player.color, country_name)

"reinforcement":
if belongs_to == Game_Manager.curr_player:
Expand Down Expand Up @@ -289,15 +288,13 @@ func create_flash_mask_sprite():

# Measuring performance
var time_taken = OS.get_ticks_msec() - time_start
#print(str(time_taken) + "ms")
return time_taken

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if flashing:
time_since_last_flash += delta
if time_since_last_flash > flashing_period:

flash_mask_sprite.visible = !flash_mask_sprite.visible

#Flashing the country sprite
Expand All @@ -306,10 +303,3 @@ func _process(delta):
else:
get_node("Sprite").modulate = Color(1,1,1)
time_since_last_flash = 0

# Moving to a spot if the locations_to_move_to list is non empty
# if locations_to_move_to:
# position = position.linear_interpolate(locations_to_move_to[0], movement_speed)
# # Checking if the destination has been reached
# if position.distance_to(locations_to_move_to[0]) < distance_to_stop_moving_at:
# position = locations_to_move_to.pop_front()
30 changes: 20 additions & 10 deletions Scripts/Levels/Level Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ var colors = {"blue": load("res://Assets/blue-square.svg"),
"red": load("res://Assets/red-pentagon.svg"),
"gray": load("res://Assets/neutral-circle.svg")}

func stop_flashing():
for country in all_countries.values():
country.stop_flashing()

var game_over = false
var selected_country = null
var phase = "attack"
Expand Down Expand Up @@ -412,7 +408,6 @@ func _input(event):
return

var country_name = str(get_color_in_mask())
print(all_countries)
if country_name in all_countries:
all_countries[country_name].on_click(event)

Expand Down Expand Up @@ -453,12 +448,27 @@ remote func synchronise_meta_info(_curr_player_index, _round_number, _game_start
update_labels()

# Below functions are for the movement of countries during the attack phase to propagate across network
func move_country_across_network(origin_country_name, destination_country_name):
rpc_id(get_next_player().network_id, "move_to_country", origin_country_name, destination_country_name)
synchronize(get_next_player().network_id)

remote func move_to_country(origin_country_name, destination_country_name):
remote func move_country_across_network(origin_country_name, destination_country_name):
all_countries[origin_country_name].move_to_country(all_countries[destination_country_name])
# If the game is online and the the function wasn't called via RPC
if _root.online_game and (get_tree().get_rpc_sender_id() == 0):
rpc_id(get_next_player().network_id, "move_country_across_network", origin_country_name, destination_country_name)
synchronize(get_next_player().network_id)

# Below functions are for the flashing of countries during the attack phase to propagate across network
remote func flash_across_network(player_color, country_name):
all_countries[country_name].flash_attackable_neighbours(player_color)
# If the game is online and the the function wasn't called via RPC
if _root.online_game and (get_tree().get_rpc_sender_id() == 0):
rpc_id(get_next_player().network_id, "flash_across_network", player_color, country_name)

# Below functions to stop the flashing of countries to propagate across network
remote func stop_flashing():
for country in all_countries.values():
country.stop_flashing()
# If the game is online and the the function wasn't called via RPC
if _root.online_game and (get_tree().get_rpc_sender_id() == 0):
rpc_id(get_next_player().network_id, "stop_flashing")
#######

const sync_period = 2
Expand Down

0 comments on commit e73ec58

Please sign in to comment.