Skip to content
Snippets Groups Projects
Commit a4ba452a authored by Canopteks's avatar Canopteks
Browse files

start game sync

parent a7fcaa80
Branches super-loading-screen
Tags
No related merge requests found
...@@ -10,6 +10,8 @@ var isPlaying:int = NOT_PLAYING ...@@ -10,6 +10,8 @@ var isPlaying:int = NOT_PLAYING
var serverNetworkId:int = 0 var serverNetworkId:int = 0
var isInServer:bool = false var isInServer:bool = false
signal gameFullyLoaded
################################################################# #################################################################
### GODOT SIGNALS ### GODOT SIGNALS
...@@ -116,12 +118,20 @@ func serverAlert(text:String): ...@@ -116,12 +118,20 @@ func serverAlert(text:String):
# --- Called by network --- # --- Called by network ---
# Start the game # Start the game
func startGame(players): func loadGame(players):
for playerId in players: for playerId in players:
registerPlayer(playerId) registerPlayer(playerId)
interfaces.loadNewScene(interfaces.GAME_PATH) interfaces.loadNewScene(interfaces.GAME_PATH)
func startGame():
emit_signal("gameFullyLoaded")
func clientGameLoaded():
network.clientGameLoaded(self.serverNetworkId)
# --- Called by network --- # --- Called by network ---
# Register the players of the same game # Register the players of the same game
func registerPlayer(networkId:int): func registerPlayer(networkId:int):
......
...@@ -118,11 +118,19 @@ remote func serverAlert(text:String): ...@@ -118,11 +118,19 @@ remote func serverAlert(text:String):
gamestate.serverAlert(text) gamestate.serverAlert(text)
remote func startGame(players:Array): remote func loadGame(players:Array):
if get_tree().get_rpc_sender_id()==gamestate.serverNetworkId: if get_tree().get_rpc_sender_id()==gamestate.serverNetworkId:
gamestate.startGame(players) gamestate.loadGame(players)
remote func startGame():
if get_tree().get_rpc_sender_id()==gamestate.serverNetworkId:
gamestate.startGame()
func clientGameLoaded(serverId:int):
rpc_id(serverId, "clientGameLoaded")
################################################################# #################################################################
### !!! THIS SET OF FUNCTIONS HAS TO BE UPDATED ACCORDINGLY TO THE MAIN NETWORK TEAM WORK !!! ### !!! THIS SET OF FUNCTIONS HAS TO BE UPDATED ACCORDINGLY TO THE MAIN NETWORK TEAM WORK !!!
### (still rpc there for testing purpose) ### (still rpc there for testing purpose)
......
...@@ -38,9 +38,6 @@ var itemsType = ["beer","hot_dog"] ...@@ -38,9 +38,6 @@ var itemsType = ["beer","hot_dog"]
func _ready(): func _ready():
var player_scene:PackedScene = preload("res://entities/characters/player.tscn") var player_scene:PackedScene = preload("res://entities/characters/player.tscn")
# TODO: check (and perhaps) the scene changing functionality
# get_tree().change_scene("res://scenes/levels/game/game.tscn")
#Next evey player will spa every other player including the server's own client! Try to move this to server only #Next evey player will spa every other player including the server's own client! Try to move this to server only
for peer_id in gamestate.players: for peer_id in gamestate.players:
var player:Node = player_scene.instance() var player:Node = player_scene.instance()
...@@ -61,6 +58,16 @@ func _ready(): ...@@ -61,6 +58,16 @@ func _ready():
initialSize = safeZone.scale initialSize = safeZone.scale
initialTr = killArea.translation initialTr = killArea.translation
gamestate.clientGameLoaded()
print("prepause true")
get_tree().set_pause(true)
print("postpause true")
yield(gamestate, "gameFullyLoaded")
print("gameFullyLoaded")
get_tree().set_pause(false)
### NEEDS REFACTORING ### NEEDS REFACTORING
......
...@@ -61,6 +61,11 @@ secondaryAttack={ ...@@ -61,6 +61,11 @@ secondaryAttack={
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":2,"pressed":false,"doubleclick":false,"script":null) "events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":2,"pressed":false,"doubleclick":false,"script":null)
] ]
} }
itemInput={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":69,"unicode":0,"echo":false,"script":null)
]
}
[rendering] [rendering]
......
...@@ -10,9 +10,15 @@ var maxClients:int ...@@ -10,9 +10,15 @@ var maxClients:int
var awaitedClients:Array = [] var awaitedClients:Array = []
var registeredClients:Array = [] var registeredClients:Array = []
var missingClients:Array = []
const START_UP_DELAY:int = 5 const START_UP_DELAY:int = 5
signal serverValidation signal serverValidation
const LOADING_DELAY:float = 10.0
var clientsLoaded:Timer
signal readyToProcess
const GAMEPATH:String = "/root/game/" const GAMEPATH:String = "/root/game/"
enum Layer { enum Layer {
ENVIRONMENT = 0, ENVIRONMENT = 0,
...@@ -186,23 +192,51 @@ func spawnPlayer(): ...@@ -186,23 +192,51 @@ func spawnPlayer():
# Wait for server validation and start the game # Wait for server validation and start the game
# => TODO: server validation timeout ? # => TODO: server validation timeout ?
func startGame(): func startGame() -> void:
network.gameHasStarted() network.gameHasStarted()
yield(self, "serverValidation") yield(self, "serverValidation")
missingClients = registeredClients.duplicate()
clientsLoaded = Timer.new()
add_child(clientsLoaded)
clientsLoaded.set_wait_time(LOADING_DELAY)
clientsLoaded.start()
# Instancing the map and adding it to the scene tree # Instancing the map and adding it to the scene tree
var game:Object = preload("res://levels/test/game.tscn").instance() var game:Object = preload("res://levels/test/game.tscn").instance()
get_tree().get_root().add_child(game) get_tree().get_root().add_child(game)
spawnPlayer() spawnPlayer()
# Broadcast the beginning of the game # Broadcast the beginning of the game to the clients loaded
for clientNetworkId in registeredClients: for clientNetworkId in registeredClients:
network.startGame(clientNetworkId, registeredClients) network.loadGame(clientNetworkId, registeredClients)
yield(clientsLoaded, "timeout")
print("loading timeout")
emit_signal("readyToProcess")
# Screw the latecomers
for clientNetworkId in missingClients:
kickPlayer(clientNetworkId)
for clientNetworkId in registeredClients:
network.startGame(clientNetworkId)
game.spawnInitItem() game.spawnInitItem()
print("Game started with peers ", registeredClients) print("S:", serverId, "Game started with peers ", registeredClients)
func clientGameLoaded(clientId:int):
var index:int = missingClients.find(clientId)
if index==-1:
print("S:", self.serverId, " Client loaded, but unknown client tho (WTF)")
return
missingClients.erase(clientId)
# Kick a client from the game with a message # Kick a client from the game with a message
...@@ -218,7 +252,11 @@ func endGame(): ...@@ -218,7 +252,11 @@ func endGame():
network.gameHasEnded(registeredClients[0]) network.gameHasEnded(registeredClients[0])
registeredClients.clear() registeredClients.clear()
get_node("/root/game").queue_free()
print("S:", serverId, " Game has ended, self-destruction initiated !")
get_node("/root/").queue_free()
get_tree().quit()
### ###
......
...@@ -93,10 +93,18 @@ func serverAlert(clientNetworkId:int, text:String): ...@@ -93,10 +93,18 @@ func serverAlert(clientNetworkId:int, text:String):
rpc_id(clientNetworkId, "serverAlert", text) rpc_id(clientNetworkId, "serverAlert", text)
# Start the game in the client app # Load the game in the client app
# => will probably change after the network merge !!! # => will probably change after the network merge !!!
func startGame(clientNetworkId:int, registeredClients:Array): func loadGame(clientNetworkId:int, registeredClients:Array):
rpc_id(clientNetworkId, "startGame", registeredClients) rpc_id(clientNetworkId, "loadGame", registeredClients)
func startGame(clientNetworkId:int):
rpc_id(clientNetworkId, "startGame")
remote func clientGameLoaded():
gamestate.clientGameLoaded(get_tree().get_rpc_sender_id())
# Make the client leave the game with a message displayed # Make the client leave the game with a message displayed
......
...@@ -59,17 +59,19 @@ func _ready(): ...@@ -59,17 +59,19 @@ func _ready():
initialIslandSize = islandsShape.scale initialIslandSize = islandsShape.scale
initialAreaTr = killArea.translation initialAreaTr = killArea.translation
initialIAreaTr = islandArea.translation initialIAreaTr = islandArea.translation
yield(gamestate, "readyToProcess")
waitZoning() waitZoning()
func _physics_process(delta): func _physics_process(delta):
# Check for the endgame conditions
if (gamestate.registeredClients.size()==1):
gamestate.endGame()
if (zoning): if (zoning):
# Check for the endgame conditions
if (gamestate.registeredClients.size()==1):
gamestate.endGame()
safeShape.scale = initialShapeSize.linear_interpolate(Vector3(ZONESIZE,ZONESIZE,initialShapeSize.z),timeToTarget) safeShape.scale = initialShapeSize.linear_interpolate(Vector3(ZONESIZE,ZONESIZE,initialShapeSize.z),timeToTarget)
safeZone.scale = initialZoneSize.linear_interpolate(Vector3(ZONESIZE,ZONESIZE,initialZoneSize.z),timeToTarget) safeZone.scale = initialZoneSize.linear_interpolate(Vector3(ZONESIZE,ZONESIZE,initialZoneSize.z),timeToTarget)
islandsShape.scale = initialIslandSize.linear_interpolate(Vector3(ISLANDSIZE,ISLANDSIZE,initialIslandSize.z),timeToTarget) islandsShape.scale = initialIslandSize.linear_interpolate(Vector3(ISLANDSIZE,ISLANDSIZE,initialIslandSize.z),timeToTarget)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment