diff options
Diffstat (limited to 'racing')
-rw-r--r-- | racing/lobby.gd | 17 | ||||
-rw-r--r-- | racing/manager.gd | 2 | ||||
-rw-r--r-- | racing/multiplayer.gd | 11 |
3 files changed, 29 insertions, 1 deletions
diff --git a/racing/lobby.gd b/racing/lobby.gd index 94fe993..374fc07 100644 --- a/racing/lobby.gd +++ b/racing/lobby.gd | |||
@@ -15,7 +15,7 @@ const MAX_PLAYERS = 250 | |||
15 | const PROTOCOL_VERSION = 2 | 15 | const PROTOCOL_VERSION = 2 |
16 | const RECIPIENT_BROADCAST_ALL = -1 | 16 | const RECIPIENT_BROADCAST_ALL = -1 |
17 | const LOBBY_MAP_NAME = "ll1_racing" | 17 | const LOBBY_MAP_NAME = "ll1_racing" |
18 | const VERSION = "0.0.3" | 18 | const VERSION = "0.0.4" |
19 | 19 | ||
20 | const LL1_AREAS = [ | 20 | const LL1_AREAS = [ |
21 | ["Starting Room", 0, 0, 0], | 21 | ["Starting Room", 0, 0, 0], |
@@ -73,6 +73,7 @@ const LL1_AREAS = [ | |||
73 | 73 | ||
74 | 74 | ||
75 | func _ready(): | 75 | func _ready(): |
76 | global._print("Starting Lobby") | ||
76 | installScriptExtension(ResourceLoader.load("user://maps/racing/load.gd")) | 77 | installScriptExtension(ResourceLoader.load("user://maps/racing/load.gd")) |
77 | 78 | ||
78 | # P2P solve messages should still be received while paused. | 79 | # P2P solve messages should still be received while paused. |
@@ -128,6 +129,7 @@ func _process(_delta: float) -> void: | |||
128 | 129 | ||
129 | func _exit_tree(): | 130 | func _exit_tree(): |
130 | if active_lobby_id != 0 and !is_starting: | 131 | if active_lobby_id != 0 and !is_starting: |
132 | global._print("Lobby Exit Tree") | ||
131 | Steam.leaveLobby(active_lobby_id) | 133 | Steam.leaveLobby(active_lobby_id) |
132 | active_lobby_id = 0 | 134 | active_lobby_id = 0 |
133 | 135 | ||
@@ -145,6 +147,7 @@ func _resend_messages_needing_ack(): | |||
145 | for message_id in messages_needing_ack: | 147 | for message_id in messages_needing_ack: |
146 | var message = messages_needing_ack[message_id] | 148 | var message = messages_needing_ack[message_id] |
147 | if message["recipient_id"] in active_lobby_members: | 149 | if message["recipient_id"] in active_lobby_members: |
150 | global._print("Resending Packet") | ||
148 | _send_p2p_packet(message["data"], message["recipient_id"], message["mode"], true) | 151 | _send_p2p_packet(message["data"], message["recipient_id"], message["mode"], true) |
149 | else: | 152 | else: |
150 | messages_needing_ack.erase(message_id) | 153 | messages_needing_ack.erase(message_id) |
@@ -177,8 +180,10 @@ func _on_lobby_match_list(lobbies: Array) -> void: | |||
177 | best_lobby_id = lobby_id | 180 | best_lobby_id = lobby_id |
178 | best_lobby_size = lobby_size | 181 | best_lobby_size = lobby_size |
179 | if best_lobby_id == 0: | 182 | if best_lobby_id == 0: |
183 | global._print("Creating Lobby") | ||
180 | Steam.createLobby(Steam.LOBBY_TYPE_INVISIBLE, MAX_PLAYERS) | 184 | Steam.createLobby(Steam.LOBBY_TYPE_INVISIBLE, MAX_PLAYERS) |
181 | elif best_lobby_id != active_lobby_id: | 185 | elif best_lobby_id != active_lobby_id: |
186 | global._print("Joining Lobby %d" % best_lobby_id) | ||
182 | Steam.joinLobby(best_lobby_id) | 187 | Steam.joinLobby(best_lobby_id) |
183 | elif best_lobby_size <= 1: | 188 | elif best_lobby_size <= 1: |
184 | _request_lobby_list() | 189 | _request_lobby_list() |
@@ -198,6 +203,7 @@ func _on_lobby_created(result: int, lobby_id: int) -> void: | |||
198 | func _on_lobby_joined(lobby_id: int, _permissions: int, _locked: bool, result: int) -> void: | 203 | func _on_lobby_joined(lobby_id: int, _permissions: int, _locked: bool, result: int) -> void: |
199 | if result != Steam.RESULT_OK: | 204 | if result != Steam.RESULT_OK: |
200 | return | 205 | return |
206 | global._print("Joined Lobby %d" % lobby_id) | ||
201 | if active_lobby_id != 0 && active_lobby_id != lobby_id: | 207 | if active_lobby_id != 0 && active_lobby_id != lobby_id: |
202 | Steam.leaveLobby(active_lobby_id) | 208 | Steam.leaveLobby(active_lobby_id) |
203 | active_lobby_id = lobby_id | 209 | active_lobby_id = lobby_id |
@@ -239,6 +245,8 @@ func _update_lobby_members(): | |||
239 | itemlist.set_item_custom_fg_color(itemlist.get_item_count() - 1, Color.green) | 245 | itemlist.set_item_custom_fg_color(itemlist.get_item_count() - 1, Color.green) |
240 | else: | 246 | else: |
241 | temp_everyone_ready = false | 247 | temp_everyone_ready = false |
248 | if !everyone_ready and everyone_ready: | ||
249 | global._print("Everyone Is Ready") | ||
242 | everyone_ready = temp_everyone_ready | 250 | everyone_ready = temp_everyone_ready |
243 | var main_button = get_node("Panel/main_button") | 251 | var main_button = get_node("Panel/main_button") |
244 | if everyone_ready and is_vip: | 252 | if everyone_ready and is_vip: |
@@ -271,6 +279,7 @@ func _read_p2p_packet() -> void: | |||
271 | race_manager.held_messages.append(packet.duplicate(true)) | 279 | race_manager.held_messages.append(packet.duplicate(true)) |
272 | var serialized: PoolByteArray = packet["data"] | 280 | var serialized: PoolByteArray = packet["data"] |
273 | var data: Dictionary = bytes2var(serialized, false) | 281 | var data: Dictionary = bytes2var(serialized, false) |
282 | global._print("RECEIVED Packet %s" % JSON.print(data)) | ||
274 | if "message_id" in data: | 283 | if "message_id" in data: |
275 | _send_p2p_packet( | 284 | _send_p2p_packet( |
276 | { | 285 | { |
@@ -297,6 +306,9 @@ func _read_p2p_packet() -> void: | |||
297 | messages_needing_ack.erase(data["ack"]) | 306 | messages_needing_ack.erase(data["ack"]) |
298 | 307 | ||
299 | if is_starting: | 308 | if is_starting: |
309 | global._print( | ||
310 | "Members Remaining Before Starting: %s" % JSON.print(members_to_join) | ||
311 | ) | ||
300 | members_to_join.erase(remote_id) | 312 | members_to_join.erase(remote_id) |
301 | 313 | ||
302 | if members_to_join.empty(): | 314 | if members_to_join.empty(): |
@@ -304,6 +316,7 @@ func _read_p2p_packet() -> void: | |||
304 | 316 | ||
305 | 317 | ||
306 | func _send_p2p_packet(data: Dictionary, recipient_id: int, mode: int, needs_ack: bool) -> void: | 318 | func _send_p2p_packet(data: Dictionary, recipient_id: int, mode: int, needs_ack: bool) -> void: |
319 | global._print("SENDING Packet %s" % JSON.print(data)) | ||
307 | if recipient_id == RECIPIENT_BROADCAST_ALL: | 320 | if recipient_id == RECIPIENT_BROADCAST_ALL: |
308 | for member_id in active_lobby_members: | 321 | for member_id in active_lobby_members: |
309 | _send_p2p_packet(data.duplicate(), member_id, mode, needs_ack) | 322 | _send_p2p_packet(data.duplicate(), member_id, mode, needs_ack) |
@@ -389,6 +402,8 @@ func _return_button_pressed(): | |||
389 | 402 | ||
390 | 403 | ||
391 | func _start_game(): | 404 | func _start_game(): |
405 | global._print("Starting Game") | ||
406 | |||
392 | var race_manager = global.get_node("RaceManager") | 407 | var race_manager = global.get_node("RaceManager") |
393 | race_manager.lobby_id = active_lobby_id | 408 | race_manager.lobby_id = active_lobby_id |
394 | 409 | ||
diff --git a/racing/manager.gd b/racing/manager.gd index 24ae409..f8b7ef7 100644 --- a/racing/manager.gd +++ b/racing/manager.gd | |||
@@ -9,6 +9,8 @@ var held_messages = [] | |||
9 | 9 | ||
10 | 10 | ||
11 | func everyone_ready(): | 11 | func everyone_ready(): |
12 | global._print("RM: Everyone Ready") | ||
13 | |||
12 | var player = get_tree().get_root().get_node("Spatial/player") | 14 | var player = get_tree().get_root().get_node("Spatial/player") |
13 | get_node("/root/Spatial").remove_child(get_node("/root/Spatial/blindfold")) | 15 | get_node("/root/Spatial").remove_child(get_node("/root/Spatial/blindfold")) |
14 | var indicator = player.get_node("pivot/camera/achievement_label") | 16 | var indicator = player.get_node("pivot/camera/achievement_label") |
diff --git a/racing/multiplayer.gd b/racing/multiplayer.gd index 2df69c1..e740cee 100644 --- a/racing/multiplayer.gd +++ b/racing/multiplayer.gd | |||
@@ -43,6 +43,7 @@ func _ready(): | |||
43 | 43 | ||
44 | var race_manager = global.get_node("RaceManager") | 44 | var race_manager = global.get_node("RaceManager") |
45 | for packet in race_manager.held_messages: | 45 | for packet in race_manager.held_messages: |
46 | global._print("(MP) Handling held packet") | ||
46 | _handle_packet(packet) | 47 | _handle_packet(packet) |
47 | race_manager.held_messages.clear() | 48 | race_manager.held_messages.clear() |
48 | 49 | ||
@@ -178,8 +179,10 @@ func _update_lobby_members(): | |||
178 | active_lobby_members[member_id].steam_name = steam_name | 179 | active_lobby_members[member_id].steam_name = steam_name |
179 | if Steam.getLobbyMemberData(active_lobby_id, member_id, "loaded") != "true": | 180 | if Steam.getLobbyMemberData(active_lobby_id, member_id, "loaded") != "true": |
180 | everyone_ready = false | 181 | everyone_ready = false |
182 | global._print("%d is not ready" % member_id) | ||
181 | if Steam.getLobbyMemberData(active_lobby_id, member_id, "timeout") != "true": | 183 | if Steam.getLobbyMemberData(active_lobby_id, member_id, "timeout") != "true": |
182 | everyone_activated = false | 184 | everyone_activated = false |
185 | global._print("%d is not activated" % member_id) | ||
183 | for member in prior_lobby_members.values(): | 186 | for member in prior_lobby_members.values(): |
184 | if not member.steam_id in active_lobby_members: | 187 | if not member.steam_id in active_lobby_members: |
185 | member.queue_free() | 188 | member.queue_free() |
@@ -209,6 +212,7 @@ func _handle_packet(packet): | |||
209 | var remote_id = packet["steam_id_remote"] | 212 | var remote_id = packet["steam_id_remote"] |
210 | var serialized: PoolByteArray = packet["data"] | 213 | var serialized: PoolByteArray = packet["data"] |
211 | var data: Dictionary = bytes2var(serialized, false) | 214 | var data: Dictionary = bytes2var(serialized, false) |
215 | global._print("(MP) RECEIVED Packet %s" % JSON.print(data)) | ||
212 | if "global_transform" in data: | 216 | if "global_transform" in data: |
213 | _receive_member_location(remote_id, data["global_transform"]) | 217 | _receive_member_location(remote_id, data["global_transform"]) |
214 | if "message_id" in data: | 218 | if "message_id" in data: |
@@ -228,6 +232,7 @@ func _handle_packet(packet): | |||
228 | _someone_victory(Steam.getFriendPersonaName(remote_id)) | 232 | _someone_victory(Steam.getFriendPersonaName(remote_id)) |
229 | if "ack" in data: | 233 | if "ack" in data: |
230 | messages_needing_ack.erase(data["ack"]) | 234 | messages_needing_ack.erase(data["ack"]) |
235 | _update_lobby_members() | ||
231 | 236 | ||
232 | 237 | ||
233 | func _receive_member_location(member_id: int, global_transform) -> void: | 238 | func _receive_member_location(member_id: int, global_transform) -> void: |
@@ -239,6 +244,7 @@ func _receive_member_location(member_id: int, global_transform) -> void: | |||
239 | 244 | ||
240 | func _send_p2p_packet(data: Dictionary, recipient_id: int, mode: int, needs_ack: bool) -> void: | 245 | func _send_p2p_packet(data: Dictionary, recipient_id: int, mode: int, needs_ack: bool) -> void: |
241 | if recipient_id == RECIPIENT_BROADCAST_ALL: | 246 | if recipient_id == RECIPIENT_BROADCAST_ALL: |
247 | global._print("(MP) SENDING packet %s" % JSON.print(data)) | ||
242 | for member_id in active_lobby_members.keys(): | 248 | for member_id in active_lobby_members.keys(): |
243 | _send_p2p_packet(data.duplicate(), member_id, mode, needs_ack) | 249 | _send_p2p_packet(data.duplicate(), member_id, mode, needs_ack) |
244 | return | 250 | return |
@@ -263,6 +269,7 @@ func _send_p2p_packet(data: Dictionary, recipient_id: int, mode: int, needs_ack: | |||
263 | 269 | ||
264 | 270 | ||
265 | func player_loaded(): | 271 | func player_loaded(): |
272 | global._print("(MP) Player has loaded") | ||
266 | is_loaded = true | 273 | is_loaded = true |
267 | if active_lobby_id != 0: | 274 | if active_lobby_id != 0: |
268 | Steam.setLobbyMemberData(active_lobby_id, "loaded", "true") | 275 | Steam.setLobbyMemberData(active_lobby_id, "loaded", "true") |
@@ -271,6 +278,7 @@ func player_loaded(): | |||
271 | 278 | ||
272 | 279 | ||
273 | func send_timeout(): | 280 | func send_timeout(): |
281 | global._print("(MP) Player is activating") | ||
274 | is_activating = true | 282 | is_activating = true |
275 | Steam.setLobbyMemberData(active_lobby_id, "timeout", "true") | 283 | Steam.setLobbyMemberData(active_lobby_id, "timeout", "true") |
276 | _send_p2p_packet({"timeout": "true"}, RECIPIENT_BROADCAST_ALL, Steam.P2P_SEND_RELIABLE, true) | 284 | _send_p2p_packet({"timeout": "true"}, RECIPIENT_BROADCAST_ALL, Steam.P2P_SEND_RELIABLE, true) |
@@ -278,6 +286,7 @@ func send_timeout(): | |||
278 | 286 | ||
279 | 287 | ||
280 | func time_to_start(): | 288 | func time_to_start(): |
289 | global._print("(MP) Time To Start") | ||
281 | var player = get_tree().get_root().get_node("Spatial/player") | 290 | var player = get_tree().get_root().get_node("Spatial/player") |
282 | player.playable = true | 291 | player.playable = true |
283 | get_node("/root/Spatial/label").text = ( | 292 | get_node("/root/Spatial/label").text = ( |
@@ -288,6 +297,7 @@ func time_to_start(): | |||
288 | 297 | ||
289 | func player_victory(): | 298 | func player_victory(): |
290 | if !is_victory: | 299 | if !is_victory: |
300 | global._print("(MP) Victory!") | ||
291 | is_victory = true | 301 | is_victory = true |
292 | _send_p2p_packet( | 302 | _send_p2p_packet( |
293 | {"victory": "true"}, RECIPIENT_BROADCAST_ALL, Steam.P2P_SEND_RELIABLE, true | 303 | {"victory": "true"}, RECIPIENT_BROADCAST_ALL, Steam.P2P_SEND_RELIABLE, true |
@@ -297,6 +307,7 @@ func player_victory(): | |||
297 | 307 | ||
298 | func _someone_victory(name): | 308 | func _someone_victory(name): |
299 | if !victorious_players.has(name): | 309 | if !victorious_players.has(name): |
310 | global._print("(MP) Someone's victory") | ||
300 | victorious_players.append(name) | 311 | victorious_players.append(name) |
301 | 312 | ||
302 | var label = get_node("/root/Spatial/label") | 313 | var label = get_node("/root/Spatial/label") |