@@ -36,49 +36,66 @@ def __init__(
36
36
self ._tick_speed : float = tick_speed
37
37
38
38
def tick (self , delta_time : float ):
39
+ """
40
+ Update the clock with the time that has passed since the last tick.
41
+
42
+ Args:
43
+ delta_time (float): The amount of time that has passed since the last tick.
44
+ """
39
45
self ._tick_delta_time = delta_time * self ._tick_speed
40
46
self ._elapsed_time += self ._tick_delta_time
41
47
self ._tick += 1
42
48
43
49
def set_tick_speed (self , new_tick_speed : float ):
50
+ """
51
+ Set the speed of time for this clock.
52
+
53
+ Args:
54
+ new_tick_speed (float): A multiplier on the 'speed' of time.
55
+ i.e. a value of 0.5 means time elapsed half as fast for this clock.
56
+ """
44
57
self ._tick_speed = new_tick_speed
45
58
46
- def time_since (self , time : float ):
59
+ def time_since (self , time : float ) -> float :
60
+ """
61
+ Calculate the amount of time that has passed since the given time.
62
+
63
+ Args:
64
+ time (float): The time to compare against.
65
+ """
47
66
return self ._elapsed_time - time
48
67
49
- def ticks_since (self , tick : int ):
68
+ def ticks_since (self , tick : int ) -> int :
69
+ """
70
+ Calculate the number of ticks that have occurred since the given tick.
71
+
72
+ Args:
73
+ tick (int): The tick to compare against.
74
+ """
50
75
return self ._tick - tick
51
76
52
77
@property
53
- def time (self ):
54
- """
55
- The total number of seconds that have elapsed for this clock
56
- """
78
+ def time (self ) -> float :
79
+ """The total number of seconds that have elapsed for this clock"""
57
80
return self ._elapsed_time
58
81
59
82
@property
60
- def t (self ):
61
- """
62
- Alias to Clock.time
63
- """
83
+ def t (self ) -> float :
84
+ """Alias to Clock.time"""
64
85
return self ._elapsed_time
65
86
66
87
@property
67
- def delta_time (self ):
68
- """
69
- The amount of time that elapsed during the last tick
70
- """
88
+ def delta_time (self ) -> float :
89
+ """The amount of time that elapsed during the last tick"""
71
90
return self ._tick_delta_time
72
91
73
92
@property
74
- def dt (self ):
75
- """
76
- Alias to Clock.delta_time
77
- """
93
+ def dt (self ) -> float :
94
+ """Alias to Clock.delta_time"""
78
95
return self .delta_time
79
96
80
97
@property
81
- def speed (self ):
98
+ def speed (self ) -> float :
82
99
"""
83
100
A modifier on the delta time that elapsed each tick.
84
101
@@ -88,17 +105,13 @@ def speed(self):
88
105
return self ._tick_speed
89
106
90
107
@property
91
- def ticks (self ):
92
- """
93
- The number of ticks that have occurred for this clock
94
- """
108
+ def ticks (self ) -> int :
109
+ """The number of ticks that have occurred for this clock."""
95
110
return self ._tick
96
111
97
112
@property
98
- def tick_count (self ):
99
- """
100
- Alias to Clock.ticks
101
- """
113
+ def tick_count (self ) -> int :
114
+ """Alias to Clock.ticks"""
102
115
return self ._tick
103
116
104
117
@@ -121,11 +134,24 @@ def __init__(self, sibling: Clock, fixed_tick_rate: float = 1.0 / 60.0):
121
134
super ().__init__ ()
122
135
123
136
def set_tick_speed (self , new_tick_speed : float ):
137
+ """
138
+ Set the speed of time for this clock.
139
+
140
+ Args:
141
+ new_tick_speed (float): A multiplier on the 'speed' of time.
142
+ i.e. a value of 0.5 means time elapsed half as fast for this clock
143
+ """
124
144
raise ValueError (
125
145
"It is not safe to change the tick speed of a fixed clock post initialization."
126
146
)
127
147
128
148
def tick (self , delta_time : float ):
149
+ """
150
+ Update the clock with the time that has passed since the last tick.
151
+
152
+ Args:
153
+ delta_time (float): The amount of time that has passed since the last tick.
154
+ """
129
155
if delta_time != self ._fixed_rate :
130
156
raise ValueError (
131
157
f"the delta_time { delta_time } , "
@@ -134,15 +160,18 @@ def tick(self, delta_time: float):
134
160
super ().tick (self ._fixed_rate )
135
161
136
162
@property
137
- def rate (self ):
163
+ def rate (self ) -> float :
164
+ """The fixed number of seconds that pass for this clock every tick."""
138
165
return self ._fixed_rate
139
166
140
167
@property
141
- def accumulated (self ):
168
+ def accumulated (self ) -> float :
169
+ """The total number of seconds that have elapsed for this clock"""
142
170
return self ._sibling_clock .time - self ._elapsed_time
143
171
144
172
@property
145
- def fraction (self ):
173
+ def fraction (self ) -> float :
174
+ """The fraction of a fixed tick that has passed since the last tick."""
146
175
return self .accumulated / self ._fixed_rate
147
176
148
177
0 commit comments