annotate grease/impl/mode.py @ 7:710f299ed275

Made sure that the modules in the current directory are imported, and not those in the python path
author KarstenBock@gmx.net
date Tue, 12 Jul 2011 12:30:41 +0200
parents bc88f7d5ca8b
children
rev   line source
5
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
1 #############################################################################
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
2 #
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
3 # Copyright (c) 2010 by Casey Duncan and contributors
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
4 # All Rights Reserved.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
5 #
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
6 # This software is subject to the provisions of the MIT License
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
7 # A copy of the license should accompany this distribution.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
8 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
9 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
10 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
11 #
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
12 #############################################################################
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
13 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
14 Modes manage the state and transition between different application modes.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
15 Typically such modes are presented as different screens that the user can
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
16 navigate between, similar to the way a browser navigates web pages. Individual
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
17 modes may be things like:
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
18
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
19 - Title screen
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
20 - Options dialog
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
21 - About screen
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
22 - In-progress game
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
23 - Inventory interface
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
24
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
25 The modal framework provides a simple mechanism to ensure that modes are
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
26 activated and deactivated properly. An activated mode is running and receives
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
27 events. A deactivated mode is paused and does not receive events.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
28
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
29 Modes may be managed as a *last-in-first-out* stack, or as a list, or ring
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
30 of modes in sequence, or some combination of all.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
31
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
32 For example usage see: :ref:`the mode section of the tutorial <tut-mode-section>`.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
33 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
34
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
35 __version__ = '$Id$'
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
36
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
37 import abc
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
38 import pyglet
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
39 from grease.mode import *
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
40
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
41 class PygletManager(BaseManager):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
42 """Mode manager abstract base class using pyglet.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
43
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
44 The mode manager keeps a stack of modes where a single mode
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
45 is active at one time. As modes are pushed on and popped from
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
46 the stack, the mode at the top is always active. The current
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
47 active mode receives events from the manager's event dispatcher.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
48 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
49
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
50 event_dispatcher = None
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
51 """:class:`pyglet.event.EventDispatcher` object that the
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
52 active mode receive events from.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
53 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
54
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
55 def activate_mode(self, mode):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
56 """Perform actions to activate a node
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
57
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
58 :param mode: The :class: 'Mode' object to activate
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
59 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
60 BaseManager.activate_mode(self, mode)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
61 self.event_dispatcher.push_handlers(mode)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
62
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
63 def deactivate_mode(self, mode):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
64 """Perform actions to deactivate a node
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
65
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
66 :param mode: The :class: 'Mode' object to deactivate
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
67 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
68 BaseManager.deactivate_mode(self, mode)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
69 self.event_dispatcher.remove_handlers(mode)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
70
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
71 class Manager(PygletManager):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
72 """A basic mode manager that wraps a single
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
73 :class:`pyglet.event.EventDispatcher` object for use by its modes.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
74 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
75
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
76 def __init__(self, event_dispatcher):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
77 self.modes = []
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
78 self.event_dispatcher = event_dispatcher
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
79
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
80
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
81 class ManagerWindow(PygletManager, pyglet.window.Window):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
82 """An integrated mode manager and pyglet window for convenience.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
83 The window is the event dispatcher used by modes pushed to
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
84 this manager.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
85
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
86 Constructor arguments are identical to :class:`pyglet.window.Window`
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
87 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
88
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
89 def __init__(self, *args, **kw):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
90 super(ManagerWindow, self).__init__(*args, **kw)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
91 self.modes = []
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
92 self.event_dispatcher = self
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
93
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
94 def on_key_press(self, symbol, modifiers):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
95 """Default :meth:`on_key_press handler`, pops the current mode on ``ESC``"""
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
96 if symbol == pyglet.window.key.ESCAPE:
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
97 self.pop_mode()
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
98
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
99 def on_last_mode_pop(self, mode):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
100 """Hook executed when the last mode is popped from the manager.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
101 When the last mode is popped from a window, an :meth:`on_close` event
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
102 is dispatched.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
103
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
104 :param mode: The :class:`Mode` object just popped from the manager
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
105 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
106 self.dispatch_event('on_close')
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
107
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
108
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
109 class Mode(BaseMode):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
110 """Application mode abstract base class using pyglet
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
111
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
112 Subclasses must implement the :meth:`step` method
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
113
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
114 :param step_rate: The rate of :meth:`step()` calls per second.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
115
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
116 :param master_clock: The :class:`pyglet.clock.Clock` interface used
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
117 as the master clock that ticks the world's clock. This
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
118 defaults to the main pyglet clock.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
119 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
120 clock = None
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
121 """The :class:`pyglet.clock.Clock` instance used as this mode's clock.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
122 You should use this clock to schedule tasks for this mode, so they
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
123 properly respect when the mode is active or inactive
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
124
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
125 Example::
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
126
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
127 my_mode.clock.schedule_once(my_cool_function, 4)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
128 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
129
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
130 def __init__(self, step_rate=60, master_clock=pyglet.clock,
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
131 clock_factory=pyglet.clock.Clock):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
132 BaseMode.__init__(self)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
133 self.step_rate = step_rate
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
134 self.time = 0.0
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
135 self.master_clock = master_clock
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
136 self.clock = clock_factory(time_function=lambda: self.time)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
137 self.clock.schedule_interval(self.step, 1.0 / step_rate)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
138
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
139 def on_activate(self):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
140 """Being called when the Mode is activated"""
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
141 self.master_clock.schedule(self.tick)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
142
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
143 def on_deactivate(self):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
144 """Being called when the Mode is deactivated"""
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
145 self.master_clock.unschedule(self.tick)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
146
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
147 def tick(self, dt):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
148 """Tick the mode's clock.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
149
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
150 :param dt: The time delta since the last tick
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
151 :type dt: float
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
152 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
153 self.time += dt
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
154 self.clock.tick(poll=False)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
155
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
156 @abc.abstractmethod
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
157 def step(self, dt):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
158 """Execute a timestep for this mode. Must be defined by subclasses.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
159
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
160 :param dt: The time delta since the last time step
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
161 :type dt: float
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
162 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
163
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
164 class Multi(BaseMulti, Mode):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
165 """A mode with multiple submodes. One submode is active at one time.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
166 Submodes can be switched to directly or switched in sequence. If
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
167 the Multi is active, then one submode is always active.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
168
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
169 Multis are useful when modes can switch in an order other than
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
170 a LIFO stack, such as in "hotseat" multiplayer games, a
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
171 "wizard" style ui, or a sequence of slides.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
172
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
173 Note unlike a normal :class:`Mode`, a :class:`Multi` doesn't have it's own
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
174 :attr:`clock` and :attr:`step_rate`. The active submode's are used
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
175 instead.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
176 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
177
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
178 def __init__(self, submodes):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
179 BaseMulti.__init__(self, submodes)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
180 self.time = 0.0
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
181
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
182
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
183 def _set_active_submode(self, submode):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
184 BaseMulti._set_active_submode(self, submode)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
185 self.master_clock = submode.master_clock
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
186 self.clock = submode.clock
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
187
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
188 def clear_subnode(self):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
189 """Clear any subnmode data"""
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
190 BaseMulti.clear_subnode(self)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
191 self.master_clock = None
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
192 self.clock = None
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
193
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
194 def tick(self, dt):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
195 """Tick the active submode's clock.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
196
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
197 :param dt: The time delta since the last tick
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
198 :type dt: float
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
199 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
200 self.time += dt
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
201 if self.active_submode is not None:
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
202 self.active_submode.clock.tick(poll=False)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
203