Implemented --dedicated-server mode. Tested a bit, set it to use less GPU and make no sound, also not capture mouse etc, and display an overview of the game.

This commit is contained in:
unfa 2021-09-28 02:07:30 +02:00
parent 1a40489237
commit 59c68c997b

View file

@ -94,7 +94,7 @@ func _process(delta):
if local_player:
$Label.text += "\n\nLOCAL PLAYER DEAD: " + str(local_player.dead)
$Label.text += "\n\nWEAPON SPREAD: " + str(local_player.weapon.spread)
$Label.text += "\n\nWEAPON SPREAD: " + str(local_player.weapon.spread) #TODO use this to alter crosshair
$Label.text += "\n\nGAME RESET AT: " + str(reset_at)
@ -106,19 +106,19 @@ func _process(delta):
create_player(i, is_local, true)
spawn_queue.erase(i)
# 3 seconds left to new round
if 0 < reset_at and (uptime + 3.5) >= reset_at and (uptime + 3) < reset_at and not $Announcer.is_playing():
$Announcer.speak($Announcer.getready)
# starting new round
if 0 < reset_at and uptime >= reset_at:
hud.scoretab(false)
local_player.dead = false
reset_at = -1
$Announcer.speak($Announcer.go)
for i in player_list.players.keys():
player_list.players[i].score = 0
if local_player:
# 3 seconds left to new round
if 0 < reset_at and (uptime + 3.5) >= reset_at and (uptime + 3) < reset_at and not $Announcer.is_playing():
$Announcer.speak($Announcer.getready)
# starting new round
if 0 < reset_at and uptime >= reset_at:
hud.scoretab(false)
local_player.dead = false
reset_at = -1
$Announcer.speak($Announcer.go)
for i in player_list.players.keys():
player_list.players[i].score = 0
class PlayerList:
var players = {}
@ -178,19 +178,22 @@ func _input(_event) -> void:
hud.scoretab(false)
@rpc(any, sync, reliable) func game_over(winner):
local_player.rpc(&'set_dead', true)
hud.game_over(winner)
if local_player:
local_player.rpc(&'set_dead', true)
hud.game_over(winner)
spawn_queue.clear()
for j in player_list.players.keys():
spawn_queue[j] = uptime + reset_delay
reset_at = uptime + reset_delay
if winner == local_player.get_multiplayer_authority():
$Announcer.speak($Announcer.victory)
elif player_list.get(local_player.get_multiplayer_authority()).score == 0:
$Announcer.speak($Announcer.defeat2) # embarrasing defeat
else:
$Announcer.speak($Announcer.defeat)
if local_player:
if winner == local_player.get_multiplayer_authority():
$Announcer.speak($Announcer.victory)
elif player_list.get(local_player.get_multiplayer_authority()).score == 0:
$Announcer.speak($Announcer.defeat2) # embarrasing defeat
else:
$Announcer.speak($Announcer.defeat)
func check_game_win_condition():
for i in player_list.players.keys():
@ -244,6 +247,8 @@ func update_hud():
var old_name = player_list.get(pid).name
if old_name != new_info.name:
chat.chat_notification("Player [b]" + old_name + "[/b] changed name to [b]" + new_info.name + "[/b]")
else:
create_player(pid, false)
if $Players.has_node(str(pid)):
var player = $Players.get_node(str(pid))
@ -252,7 +257,8 @@ func update_hud():
player_list.set(pid, new_info) # server relays other PID's data
# update local HUD
update_hud()
if local_player:
update_hud()
#check_game_win_condition()
func push_local_player_info(): #
@ -302,7 +308,9 @@ func create_player(pid: int, is_local:= false, respawn:= false) -> void:
var spawnpoint = $Map/SpawnPoints.get_children()[randi() % len($Map/SpawnPoints.get_children())]
player_node.global_transform = spawnpoint.global_transform
player_list.players[pid].health = 100
push_local_player_info()
if local_player:
push_local_player_info()
#focus = GameFocus.GAME # make sure the player has no menu displayed when they respawn
return # avoid running the rest of this function
@ -355,8 +363,36 @@ func create_player(pid: int, is_local:= false, respawn:= false) -> void:
func start_dedicated_server(): # start server without creating a local player
role = MultiplayerRole.DEDICATED_SERVER
peer.create_server(NET_PORT, 16)
get_tree().multiplayer_peer = peer
#create_player(1, true)
get_tree().multiplayer.multiplayer_peer = peer
get_viewport().debug_draw = Viewport.DebugDraw.DEBUG_DRAW_OVERDRAW
get_viewport().msaa = Viewport.MSAA.MSAA_DISABLED
get_viewport().use_debanding = false
get_viewport().screen_space_aa = 0
get_viewport().lod_threshold = 128
get_viewport().get_camera_3d().effects = null
get_viewport().shadow_atlas_size = 64
$Map/Decals.hide()
$Map/Lights.hide()
$Map/ReflectionProbes.hide()
AudioServer.set_bus_mute(0, true) # mute sound
$Label.show()
#get_tree().root.title = "LIBLAST DEDICATED SERVER"
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
gui.hide()
hud.show()
hud.get_node("ScoreRank").hide()
hud.get_node("Stats").hide()
hud.get_node("Crosshair").hide()
hud.scoretab(true)
func host_server():
_on_Host_pressed()
@ -387,9 +423,8 @@ func _on_Connect_pressed():
get_tree().multiplayer.multiplayer_peer = peer
func _player_connected(pid) -> void:
print("player connected, id: ", pid)
create_player(pid, false)
print("peer connected, id: ", pid)
if get_tree().multiplayer.is_server(): # if we're the server
for i in player_list.players.keys(): # send the player_list to the new client
#pass
@ -430,7 +465,7 @@ func _server_disconnected() -> void:
func _ready() -> void:
hud.hide() # start in the menu
print("Commandline arguments: ", OS.get_cmdline_args())
focus = GameFocus.MENU
get_tree().multiplayer.connect("peer_connected", self._player_connected)
get_tree().multiplayer.connect("peer_disconnected", self._player_disconnected)
@ -438,7 +473,7 @@ func _ready() -> void:
get_tree().multiplayer.connect("connection_failed", self._connected_fail)
get_tree().multiplayer.connect("server_disconnected", self._server_disconnected)
if OS.get_cmdline_args().has("dedicated_server"):
if OS.get_cmdline_args().has("--dedicated-server"):
start_dedicated_server()
func change_player_color(color):