fix: 'Timer' logic
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
[project]
|
[project]
|
||||||
name = "common"
|
name = "common"
|
||||||
description = "Commonly reusable code"
|
description = "Commonly reusable code"
|
||||||
version = "0.1.19"
|
version = "0.1.20"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
authors = [
|
authors = [
|
||||||
{ name="BreakerBear", email="breakerbear@autistic.men" },
|
{ name="BreakerBear", email="breakerbear@autistic.men" },
|
||||||
|
|||||||
+6
-6
@@ -6,17 +6,17 @@ class Timer:
|
|||||||
self.clear()
|
self.clear()
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.checkpoint = None
|
|
||||||
self.accumulator = 0
|
self.accumulator = 0
|
||||||
|
self.checkpoint = 0
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
seconds = floor(time())
|
self.accumulator = self.delta()
|
||||||
self.checkpoint = seconds
|
self.checkpoint = floor(time())
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
assert self.checkpoint is not None, "Uninitialized"
|
|
||||||
self.accumulator = self.delta()
|
self.accumulator = self.delta()
|
||||||
|
self.checkpoint = 0
|
||||||
|
|
||||||
def delta(self):
|
def delta(self):
|
||||||
assert self.checkpoint is not None, "Uninitialized"
|
excess = floor(time()) - rhs if (rhs := self.checkpoint) else 0
|
||||||
return floor(time()) - self.checkpoint + self.accumulator
|
return excess + self.accumulator
|
||||||
|
|||||||
Reference in New Issue
Block a user