annotate engine/python/fife/extensions/fife_timer.py @ 606:a5c890f0e757

This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely. [t:483]
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 16 Sep 2010 16:46:17 +0000
parents c8820cc201db
children eab690c748a3
rev   line source
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 # -*- coding: utf-8 -*-
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 # ####################################################################
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
4 # Copyright (C) 2005-2010 by the FIFE team
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
5 # http://www.fifengine.net
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 # This file is part of FIFE.
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 #
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 # FIFE is free software; you can redistribute it and/or
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 # modify it under the terms of the GNU Lesser General Public
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 # License as published by the Free Software Foundation; either
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 # version 2.1 of the License, or (at your option) any later version.
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 #
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 # This library is distributed in the hope that it will be useful,
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 # Lesser General Public License for more details.
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 #
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 # You should have received a copy of the GNU Lesser General Public
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 # License along with this library; if not, write to the
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 # Free Software Foundation, Inc.,
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 # ####################################################################
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 """
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 Convenient timers
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 =================
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 Usage::
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
29 import fife.extensions.fife_timer
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
30 fife_timer.init( my_fife_engine.getTimeManager() )
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 def spam():
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 print "SPAM SPAM ",
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
33 repeater = fife_timer.repeatCall(500,spam)
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 def stop_spam():
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 repeater.stop()
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 print "BACON EGGS AND SPAM"
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
37 fife_timer.delayCall(50000,stop_spam)
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 """
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40
495
ae9f5383f5b1 Added a new log module called Script. This should be used by the python modules.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 494
diff changeset
41 from fife import fife
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 _manager = None
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
44 _alltimers = []
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
45 _deadtimers = []
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47 def init(timemanager):
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 """
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 Initialize timers.
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 @param timemanager: A L{fife.TimeManager} as retuned by L{fife.Engine.getTimeManager}.
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 """
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 global _manager
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 _manager = timemanager
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 class Timer(fife.TimeEvent):
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
57 """
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
58 Timer
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
59
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
60 This class wraps the fife.TimeEvent class to make it easily usable from Python
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
61 It allows for a TimeEvent to be executed once or multiple times.
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
62 """
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
63 def __init__(self,delay=0,callback=None,repeat=0):
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
64 """
494
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
65 @param delay: The delay in milliseconds to execute the callback
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
66 @param callback: The function to execute
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
67 @param repeat: The number of times to execute the callback. 1=once, 0=forever
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
68 """
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
69 super(Timer,self).__init__(delay)
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
70 self._active = False
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
71 self._callback = callback
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
72 self._manager = _manager
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 self.setPeriod(delay)
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
74 self._repeat = repeat
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
75 self._executed = 0
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
76
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 def start(self):
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
78 """
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
79 Call this to start the timer.
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
80
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
81 This registers the timer with the time manager. The time manger then
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
82 calls the timers updateEvent() function when the delay time has passed.
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
83 """
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
84 if self._active:
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 return
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
86 self._active = True
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
87
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
88 self._executed = 0
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
89
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
90 self.setLastUpdateTime(self._manager.getTime())
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
91 self._manager.registerEvent(self)
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
92
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 global _alltimers
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
94 global _deadtimers
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
95
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
96 _alltimers.append(self)
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
97
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 def stop(self):
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
99 """
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
100 Stops the timer
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
101
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
102 This unregisters the timer from the time manager. The time manager does NOT
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
103 delete the timer so make sure you keep a reference to this timer and ensure
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
104 python doesnt delete the timer prematurely.
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
105 """
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
106 if not self._active:
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107 return
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
108
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
109 self._active = False
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
110 self._manager.unregisterEvent(self)
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
111
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
112
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
113 #FIXME: See ticket #483 in trac. This is a temporary solution and needs
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
114 #to be reworked.
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
115
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 global _alltimers
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
117 global _deadtimers
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
118
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
119 #clean up any dead timers
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
120 del _deadtimers[:]
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
121
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
122 #Ddd this timer to the dead timers list to be removed next time a timer
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
123 #is stopped.
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
124 _deadtimers.append(self)
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
125
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
126 #finally remove self from the global timer list
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
127 _alltimers.remove(self)
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
128
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130 def updateEvent(self,delta):
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
131 """
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
132 This is called by FIFE::TimeManager when the delay has passed.
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
133
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
134 Should not be called directly.
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
135 """
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
136
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
137 if self._repeat != 0:
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
138 self._executed += 1
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
139 if self._executed >= self._repeat:
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
140 self.stop()
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
141
507
d6de9ab3ce2a Fixed a small problem with the fife timer library. There was a problem with UH when clicking on certain buttons on the main menu which cased a hang/crash. The timer now stops itself before executing the callback.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 495
diff changeset
142 if callable(self._callback):
d6de9ab3ce2a Fixed a small problem with the fife timer library. There was a problem with UH when clicking on certain buttons on the main menu which cased a hang/crash. The timer now stops itself before executing the callback.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 495
diff changeset
143 self._callback()
606
a5c890f0e757 This is a temporary fix for the timer issue which causes random segfaults. Timers are no longer deleted prematurely.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 508
diff changeset
144
507
d6de9ab3ce2a Fixed a small problem with the fife timer library. There was a problem with UH when clicking on certain buttons on the main menu which cased a hang/crash. The timer now stops itself before executing the callback.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 495
diff changeset
145
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
146 def delayCall(delay,callback):
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
147 """
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148 Delay a function call by a number of milliseconds.
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
149
494
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
150 @param delay: Delay in milliseconds.
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
151 @param callback: The function to call.
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152
495
ae9f5383f5b1 Added a new log module called Script. This should be used by the python modules.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 494
diff changeset
153 @return: The timer.
494
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
154 @rtype: L{Timer}
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155 """
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
156 timer = Timer(delay, callback, 1)
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 timer.start()
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
158 return timer
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
159
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
160
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
161 def repeatCall(period,callback):
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
162 """
495
ae9f5383f5b1 Added a new log module called Script. This should be used by the python modules.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 494
diff changeset
163 Repeat a function call. The call is repeated until the timer is stopped.
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
164
494
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
165 @param period: Period between calls in milliseconds.
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
166 @param callback: The function to call.
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
167
494
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
168 @return: The timer.
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
169 @rtype: L{Timer}
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
170 """
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
171 timer = Timer(period, callback, 0)
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
172 timer.start()
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
173 return timer
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
174
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 488
diff changeset
175 __all__ = ['init','Timer','delayCall','repeatCall']
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176