Line data Source code
1 0 : /* 2 : 3 : OOScriptTimer.h 4 : 5 : Abstract base class for script timers. An OOScriptTimer does nothing when it 6 : fires; subclasses should override the -timerFired method. 7 : 8 : Timers are immutable. They are retained by the timer subsystem while scheduled. 9 : A timer with a negative interval will only fire once. A negative nexttime when 10 : inited will cause the timer to fire after the specified interval. A persistent 11 : timer will remain if the player dies and respawns; non-persistent timers will 12 : be removed. 13 : 14 : 15 : Oolite 16 : Copyright (C) 2004-2013 Giles C Williams and contributors 17 : 18 : This program is free software; you can redistribute it and/or 19 : modify it under the terms of the GNU General Public License 20 : as published by the Free Software Foundation; either version 2 21 : of the License, or (at your option) any later version. 22 : 23 : This program is distributed in the hope that it will be useful, 24 : but WITHOUT ANY WARRANTY; without even the implied warranty of 25 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 : GNU General Public License for more details. 27 : 28 : You should have received a copy of the GNU General Public License 29 : along with this program; if not, write to the Free Software 30 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 31 : MA 02110-1301, USA. 32 : 33 : */ 34 : 35 : #import "OOCocoa.h" 36 : #import "OOTypes.h" 37 : 38 : 39 0 : @interface OOScriptTimer: NSObject 40 : { 41 : @private 42 0 : OOTimeAbsolute _nextTime; 43 0 : OOTimeDelta _interval; 44 0 : BOOL _isScheduled; 45 0 : BOOL _hasBeenRun; // Needed for one-shot timers. 46 : } 47 : 48 0 : - (id) initWithNextTime:(OOTimeAbsolute)nextTime 49 : interval:(OOTimeDelta)interval; 50 : 51 : // Sets nextTime to current time + delay. 52 0 : - (id) initOneShotTimerWithDelay:(OOTimeDelta)delay; 53 : 54 0 : - (OOTimeAbsolute)nextTime; 55 0 : - (BOOL)setNextTime:(OOTimeAbsolute)nextTime; // Only works when timer is not scheduled. 56 0 : - (OOTimeDelta)interval; 57 0 : - (void)setInterval:(OOTimeDelta)interval; 58 : 59 : // Subclass responsibility: 60 0 : - (void) timerFired; 61 : 62 0 : - (BOOL) scheduleTimer; 63 0 : - (void) unscheduleTimer; 64 0 : - (BOOL) isScheduled; 65 : 66 : 67 0 : + (void) updateTimers; 68 0 : + (void) noteGameReset; 69 : 70 : 71 0 : - (BOOL) isValidForScheduling; 72 : 73 0 : - (NSComparisonResult) compareByNextFireTime:(OOScriptTimer *)other; 74 : 75 : @end