game: add: close game when nobody in
This commit is contained in:
@ -253,7 +253,7 @@ async def update_ball(game: Game, impact_data: dict) -> None:
|
||||
|
||||
await SyncToAsync(game.broadcast)("update_ball", game.ball.to_dict())
|
||||
|
||||
async def render(game: Game):
|
||||
async def render_ball(game: Game):
|
||||
|
||||
while True:
|
||||
|
||||
@ -262,16 +262,30 @@ async def render(game: Game):
|
||||
impact_data: dict = get_impact_data(segments, game.ball)
|
||||
|
||||
await update_ball(game, impact_data)
|
||||
|
||||
|
||||
def routine(game: Game):
|
||||
|
||||
asyncio.run(render(game))
|
||||
|
||||
|
||||
async def render_players(game: Game):
|
||||
|
||||
while True:
|
||||
|
||||
for player in game._updated_players:
|
||||
game.broadcast("update_paddle", player.to_dict(), [player])
|
||||
|
||||
game._updated_players.clear()
|
||||
|
||||
sleep(1 / config.SERVER_TPS)
|
||||
await asyncio.sleep(1 / config.SERVER_TPS)
|
||||
|
||||
async def render(game: Game):
|
||||
|
||||
routine_ball = asyncio.create_task(render_ball(game))
|
||||
routine_players = asyncio.create_task(render_players(game))
|
||||
|
||||
while(True):
|
||||
if (game.stopped):
|
||||
routine_ball.cancel()
|
||||
routine_players.cancel()
|
||||
return
|
||||
await asyncio.sleep(0.3)
|
||||
|
||||
def routine(game: Game):
|
||||
|
||||
asyncio.run(render(game))
|
||||
|
Reference in New Issue
Block a user