Skip to content

Commit

Permalink
udm: Move player to a spawn location on another thread
Browse files Browse the repository at this point in the history
Signed-off-by: BackRaw <[email protected]>
  • Loading branch information
BackRaw committed Jul 18, 2018
1 parent 44824d6 commit a43f5ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 13 additions & 0 deletions addons/source-python/plugins/udm/spawnpoints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ def json(self):
}


class SpawnPointDispatcher(object):
"""Class used to move a player to a spawn point location from another thread."""

@staticmethod
def perform_action(player):
"""Move the player to a spawn point location."""
# Choose a random spawn point
spawnpoint = player.get_spawn_location()

# Move the player to the spawn point found
spawnpoint.move_player(player)


class _SpawnPointManager(list):
"""Class used to provide spawn point managing functionality:
Expand Down
13 changes: 7 additions & 6 deletions addons/source-python/plugins/udm/udm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from listeners import OnLevelEnd
from listeners import OnServerActivate
from listeners import OnServerOutput
from listeners.tick import GameThread
# Memory
from memory import make_object
# Weapons
Expand Down Expand Up @@ -70,6 +71,8 @@
from udm.players import player_spawn_locations
from udm.players import player_team_changes
from udm.players import PlayerEntity
# Spawn Points
from udm.spawnpoints import SpawnPointDispatcher
# Weapons
from udm.weapons import is_silencer_option_primary
from udm.weapons import is_silencer_option_secondary
Expand Down Expand Up @@ -116,6 +119,10 @@
# =============================================================================
def prepare_player(player):
"""Prepare the player for battle."""
# Perform setting the player's spawn location on another thread
spawnpoint_dispatch_thread = GameThread(target=SpawnPointDispatcher.perform_action, args=(player, ))
spawnpoint_dispatch_thread.start()

# Give armor
player.give_named_item('item_assaultsuit')

Expand All @@ -132,12 +139,6 @@ def prepare_player(player):
else cvar_spawn_protection_delay.get_float()
)

# Choose a random spawn point
spawnpoint = player.get_spawn_location()

# Move the player to the spawn point found
spawnpoint.move_player(player)

# Equip the current inventory if not currently using the admin menu
if player.userid not in admin_menu.users:
player.equip_inventory()
Expand Down

0 comments on commit a43f5ff

Please sign in to comment.