| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/Dmfc/dmfctimer.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003/08/26 03:57:21 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * DMFC timer API functions |
| 26 | * |
| 27 | * $Log: dmfctimer.cpp,v $ |
| 28 | * Revision 1.1.1.1 2003/08/26 03:57:21 kevinb |
| 29 | * initial 1.5 import |
| 30 | * |
| 31 | * |
| 32 | * 8 5/23/99 2:21a Jeff |
| 33 | * fixed timer bugs with intervals |
| 34 | * |
| 35 | * 7 5/13/99 4:56p Ardussi |
| 36 | * changes for compiling on the Mac |
| 37 | * |
| 38 | * 6 3/17/99 12:25p Jeff |
| 39 | * converted DMFC to be COM interface |
| 40 | * |
| 41 | * 5 2/11/99 12:51a Jeff |
| 42 | * changed names of exported variables |
| 43 | * |
| 44 | * 4 9/21/98 7:11p Jeff |
| 45 | * made InputCommand interface API and moved existing input commands to |
| 46 | * the interface. Changed mprintf/ASSERT so they are valid in DMFC |
| 47 | * |
| 48 | * $NoKeywords: $ |
| 49 | */ |
| 50 | |
| 51 | #include "gamedll_header.h"cxx . . $ `<file>/netgames/includes/gamedll_header.h`/ |
| 52 | #include "DMFC.h"cxx . . $ `<file>/netgames/includes/DMFC.h`/ |
| 53 | #include "dmfcinternal.h"cxx . . $ `<file>/netgames/dmfc/dmfcinternal.h`/ |
| 54 | |
| 55 | // DMFCBase::InitTimers |
| 56 | // |
| 57 | // Inializes the timers |
| 58 | void DMFCBasecxx . . $ DMFCBase#::InitTimerscxx . . $ DMFCBase#InitTimers(49f6e7a06ebc5aa8).(void) { |
| 59 | for (int i = 0; i < MAX_DMFC_TIMERScxx . . $ `netgames/includes/DMFC.h:522:9`!; i++) { |
| 60 | Timerscxx . . $ DMFCBase#Timers.[i].inusecxx . . $ tDMFCTimerInfo#inuse. = false; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // DMFCBase::KillAllTimers |
| 65 | // |
| 66 | // Kills all running timers |
| 67 | void DMFCBasecxx . . $ DMFCBase#::KillAllTimerscxx . . $ DMFCBase#KillAllTimers(49f6e7a06ebc5aa8).(void) { |
| 68 | for (int i = 0; i < MAX_DMFC_TIMERScxx . . $ `netgames/includes/DMFC.h:522:9`!; i++) { |
| 69 | KillTimercxx . . $ DMFCBase#KillTimer(d4f767463ce0a6b3).(i); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // DMFCBase::SetTimerInterval |
| 74 | // |
| 75 | // Starts a timer event running |
| 76 | int DMFCBasecxx . . $ DMFCBase#::SetTimerIntervalcxx . . $ DMFCBase#SetTimerInterval(695c251031f3a34d).(void (*func)(void), float intval, float longevity, void (*onkill)()) { |
| 77 | int i; |
| 78 | |
| 79 | // Find a free timer |
| 80 | for (i = 0; i < MAX_DMFC_TIMERScxx . . $ `netgames/includes/DMFC.h:522:9`!; i++) { |
| 81 | if (!Timerscxx . . $ DMFCBase#Timers.[i].inusecxx . . $ tDMFCTimerInfo#inuse.) |
| 82 | break; |
| 83 | } |
| 84 | |
| 85 | if (i >= MAX_DMFC_TIMERScxx . . $ `netgames/includes/DMFC.h:522:9`!) { |
| 86 | return -1; // no free timers |
| 87 | } |
| 88 | |
| 89 | // insert this timer information |
| 90 | Timerscxx . . $ DMFCBase#Timers.[i].inusecxx . . $ tDMFCTimerInfo#inuse. = true; |
| 91 | Timerscxx . . $ DMFCBase#Timers.[i].handlercxx . . $ tDMFCTimerInfo#handler. = func; |
| 92 | Timerscxx . . $ DMFCBase#Timers.[i].starttimecxx . . $ tDMFCTimerInfo#starttime. = *Gametimecxx . . $ DMFCBase#Gametime.; |
| 93 | Timerscxx . . $ DMFCBase#Timers.[i].longevitycxx . . $ tDMFCTimerInfo#longevity. = longevity; |
| 94 | Timerscxx . . $ DMFCBase#Timers.[i].intvalcxx . . $ tDMFCTimerInfo#intval. = intval; |
| 95 | Timerscxx . . $ DMFCBase#Timers.[i].nexttimecxx . . $ tDMFCTimerInfo#nexttime. = Timerscxx . . $ DMFCBase#Timers.[i].starttimecxx . . $ tDMFCTimerInfo#starttime. + Timerscxx . . $ DMFCBase#Timers.[i].intvalcxx . . $ tDMFCTimerInfo#intval.; |
| 96 | Timerscxx . . $ DMFCBase#Timers.[i].onkillcxx . . $ tDMFCTimerInfo#onkill. = onkill; |
| 97 | return i; |
| 98 | } |
| 99 | |
| 100 | // DMFCBase::KillTimer |
| 101 | // |
| 102 | // Kills a timer |
| 103 | void DMFCBasecxx . . $ DMFCBase#::KillTimercxx . . $ DMFCBase#KillTimer(d4f767463ce0a6b3).(int handle) { |
| 104 | if ((handle >= 0) && (handle < MAX_DMFC_TIMERScxx . . $ `netgames/includes/DMFC.h:522:9`!)) { |
| 105 | if (Timerscxx . . $ DMFCBase#Timers.[handle].inusecxx . . $ tDMFCTimerInfo#inuse.) { |
| 106 | Timerscxx . . $ DMFCBase#Timers.[handle].inusecxx . . $ tDMFCTimerInfo#inuse. = false; |
| 107 | if (Timerscxx . . $ DMFCBase#Timers.[handle].onkillcxx . . $ tDMFCTimerInfo#onkill.) |
| 108 | (*Timerscxx . . $ DMFCBase#Timers.[handle].onkillcxx . . $ tDMFCTimerInfo#onkill.)(); |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // DMFCBase::ProcessTimers |
| 114 | // |
| 115 | // Goes through all the timers and updates them if they need to be updated |
| 116 | void DMFCBasecxx . . $ DMFCBase#::ProcessTimerscxx . . $ DMFCBase#ProcessTimers(49f6e7a06ebc5aa8).(void) { |
| 117 | for (int i = 0; i < MAX_DMFC_TIMERScxx . . $ `netgames/includes/DMFC.h:522:9`!; i++) { |
| 118 | if (Timerscxx . . $ DMFCBase#Timers.[i].inusecxx . . $ tDMFCTimerInfo#inuse.) { |
| 119 | // we have a running timer here |
| 120 | float currtime = *Gametimecxx . . $ DMFCBase#Gametime.; |
| 121 | if (Timerscxx . . $ DMFCBase#Timers.[i].nexttimecxx . . $ tDMFCTimerInfo#nexttime. <= currtime) { |
| 122 | // time to call |
| 123 | Timerscxx . . $ DMFCBase#Timers.[i].nexttimecxx . . $ tDMFCTimerInfo#nexttime. += Timerscxx . . $ DMFCBase#Timers.[i].intvalcxx . . $ tDMFCTimerInfo#intval.; |
| 124 | if (Timerscxx . . $ DMFCBase#Timers.[i].handlercxx . . $ tDMFCTimerInfo#handler.) |
| 125 | (*Timerscxx . . $ DMFCBase#Timers.[i].handlercxx . . $ tDMFCTimerInfo#handler.)(); |
| 126 | } |
| 127 | if (Timerscxx . . $ DMFCBase#Timers.[i].longevitycxx . . $ tDMFCTimerInfo#longevity. != -1) { |
| 128 | if (Timerscxx . . $ DMFCBase#Timers.[i].longevitycxx . . $ tDMFCTimerInfo#longevity. + Timerscxx . . $ DMFCBase#Timers.[i].starttimecxx . . $ tDMFCTimerInfo#starttime. < currtime) { |
| 129 | // this timer is over with |
| 130 | KillTimercxx . . $ DMFCBase#KillTimer(d4f767463ce0a6b3).(i); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } // end for |
| 135 | } |