home · contact · privacy
Only send out new gamestate every 1/25 second.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 3 Dec 2020 00:47:13 +0000 (01:47 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 3 Dec 2020 00:47:13 +0000 (01:47 +0100)
plomrogue/game.py

index dd9c50a76a7e65c211f9425d413c18911611200d..3c927dbb7dc92e2718b08185f71e496f469694e1 100755 (executable)
@@ -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):