diff options
author | Livio Recchia <recchialivio@libero.it> | 2020-02-10 23:06:34 +0100 |
---|---|---|
committer | Livio Recchia <recchialivio@libero.it> | 2020-02-10 23:06:34 +0100 |
commit | 9a13903a2f7d3a65fdf15a65fb59cccd622e2066 (patch) | |
tree | 9403b7dff39eb5e5d7fa0f79efb69b496add4c4b /logicmanager.py | |
parent | 11cc316b74d5f3f283413a33e7693b314741aa4a (diff) | |
download | manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.gz manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.bz2 manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.xz manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.zip |
Initial commit
Diffstat (limited to 'logicmanager.py')
-rw-r--r-- | logicmanager.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/logicmanager.py b/logicmanager.py new file mode 100644 index 0000000..1745948 --- /dev/null +++ b/logicmanager.py @@ -0,0 +1,21 @@ +import time + + +class LogicManager: + def __init__(self, min_dt=0.1): + self._logic_handlers = [] + self._last_ts = 0 + self._min_dt = min_dt + + def add_logic(self, func): + self._logic_handlers.append(func) + + def tick(self, **kwargs): + now = time.time() + if now - self._last_ts >= self._min_dt: + self._last_ts = now + for f in self._logic_handlers: + f(now, **kwargs) + + +logic_manager = LogicManager() |