From 0329d62bfc40ef8d54d9df8f5d9119515a871cf6 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 3 Dec 2020 01:47:13 +0100 Subject: [PATCH] Only send out new gamestate every 1/25 second. --- plomrogue/game.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plomrogue/game.py b/plomrogue/game.py index dd9c50a..3c927db 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -3,6 +3,7 @@ from plomrogue.io import GameIO from plomrogue.misc import quote from plomrogue.mapping import YX, MapGeometrySquare, MapGeometryHex, Map import string +import datetime @@ -129,6 +130,9 @@ class Game(GameBase): self.player_chars = string.digits + string.ascii_letters self.player_char_i = -1 self.admin_passwords = [] + self.send_gamestate_interval = datetime.timedelta(seconds=0.04) + self.last_send_gamestate = datetime.datetime.now() -\ + self.send_gamestate_interval self.terrains = { '.': 'floor', 'X': 'wall', @@ -261,9 +265,12 @@ class Game(GameBase): self.io.send('PLAY_ERROR ' + quote(str(e)), connection_id) if self.changed: self.turn += 1 - self.send_gamestate() - self.changed = False - self.save() + if self.last_send_gamestate < \ + datetime.datetime.now() -self.send_gamestate_interval: + self.send_gamestate() + self.changed = False + self.save() + self.last_send_gamestate = datetime.datetime.now() def get_command(self, command_name): -- 2.30.2