p_tick.c (7321B)
1 #include "doomdef.h" 2 #include "p_local.h" 3 #include "st_main.h" 4 5 boolean gamepaused = true; // 800A6270 6 7 /* 8 =============================================================================== 9 10 THINKERS 11 12 All thinkers should be allocated by Z_Malloc so they can be operated on uniformly. The actual 13 structures will vary in size, but the first element must be thinker_t. 14 15 Mobjs are similar to thinkers, but kept seperate for more optimal list 16 processing 17 =============================================================================== 18 */ 19 20 thinker_t thinkercap; /* both the head and tail of the thinker list */ //80096378 21 mobj_t mobjhead; /* head and tail of mobj list */ //800A8C74, 22 //int activethinkers; /* debug count */ 23 //int activemobjs; /* debug count */ 24 25 /* 26 =============== 27 = 28 = P_InitThinkers 29 = 30 =============== 31 */ 32 #if 0 33 void P_InitThinkers (void) 34 { 35 thinkercap.prev = thinkercap.next = &thinkercap; 36 mobjhead.next = mobjhead.prev = &mobjhead; 37 } 38 #endif // 0 39 40 /* 41 =============== 42 = 43 = P_AddThinker 44 = 45 = Adds a new thinker at the end of the list 46 = 47 =============== 48 */ 49 50 void P_AddThinker (thinker_t *thinker) // 80021770 51 { 52 thinkercap.prev->next = thinker; 53 thinker->next = &thinkercap; 54 thinker->prev = thinkercap.prev; 55 thinkercap.prev = thinker; 56 } 57 58 /* 59 =============== 60 = 61 = P_RemoveThinker 62 = 63 = Deallocation is lazy -- it will not actually be freed until its 64 = thinking turn comes up 65 = 66 =============== 67 */ 68 69 void P_RemoveThinker (thinker_t *thinker) // 8002179C 70 { 71 thinker->function = (think_t)-1; 72 73 if (thinker == macrothinker) { // [D64] New lines 74 macrothinker = NULL; 75 } 76 } 77 78 /* 79 =============== 80 = 81 = P_RunThinkers 82 = 83 =============== 84 */ 85 86 void P_RunThinkers (void) // 800217C8 87 { 88 thinker_t *currentthinker; 89 90 //activethinkers = 0; 91 92 currentthinker = thinkercap.next; 93 if (thinkercap.next != &thinkercap) 94 { 95 while (currentthinker != &thinkercap) 96 { 97 if (currentthinker->function == (think_t)-1) 98 { // time to remove it 99 currentthinker->next->prev = currentthinker->prev; 100 currentthinker->prev->next = currentthinker->next; 101 Z_Free (currentthinker); 102 } 103 else 104 { 105 if (currentthinker->function) 106 { 107 currentthinker->function (currentthinker); 108 } 109 //activethinkers++; 110 } 111 currentthinker = currentthinker->next; 112 } 113 } 114 } 115 116 /* 117 =================== 118 = 119 = P_RunMobjLate 120 = 121 = Run stuff that doesn't happen every tick 122 =================== 123 */ 124 #if 0 125 void P_RunMobjLate (void) 126 { 127 mobj_t *mo; 128 mobj_t *next; 129 130 for (mo=mobjhead.next ; mo != &mobjhead ; mo=next) 131 { 132 next = mo->next; /* in case mo is removed this time */ 133 if (mo->latecall) 134 { 135 mo->latecall(mo); 136 } 137 } 138 } 139 #endif // 0 140 141 /* 142 ============== 143 = 144 = P_CheckCheats 145 = 146 ============== 147 */ 148 149 void P_CheckCheats (void) // 8002187C 150 { 151 unsigned int buttons; 152 int exit; 153 154 buttons = ticbuttons[0] & 0xffff0000; 155 156 if (!gamepaused) 157 { 158 if ((buttons & PAD_START) && !(oldticbuttons[0] & PAD_START)) 159 { 160 gamepaused = true; 161 162 S_PauseSound(); 163 164 lastticon = ticon; 165 166 MenuCall = M_MenuTitleDrawer; 167 MenuItem = Menu_Game; 168 cursorpos = 0; 169 170 if (FeaturesUnlocked == false) 171 itemlines = 3; 172 else 173 itemlines = 4; // Enable cheat menu 174 175 MenuIdx = 0; 176 text_alpha = 255; 177 MenuAnimationTic = 0; 178 } 179 180 return; 181 } 182 183 exit = M_MenuTicker(); 184 185 if (exit) 186 M_MenuClearCall(); 187 188 if (exit == ga_warped) { 189 gameaction = ga_warped; 190 } 191 else if (exit == ga_exitdemo) { 192 gameaction = ga_exitdemo; 193 } 194 else if (exit == ga_restart) { 195 gameaction = ga_restart; 196 } 197 else if (exit == ga_exit) 198 { 199 gamepaused = false; 200 S_ResumeSound(); 201 ticon = lastticon; 202 ticsinframe = lastticon >> 2; 203 } 204 } 205 206 void G_DoReborn (int playernum);//extern 207 208 /* 209 ================= 210 = 211 = P_Ticker 212 = 213 ================= 214 */ 215 216 //extern functions 217 void P_CheckSights (void); 218 void P_RunMobjBase (void); 219 220 int P_Ticker (void)//80021A00 221 { 222 player_t *pl; 223 224 gameaction = ga_nothing; 225 226 // 227 // check for pause and cheats 228 // 229 P_CheckCheats(); 230 231 if ((!gamepaused) && (gamevbls < gametic)) 232 { 233 P_RunThinkers(); 234 P_CheckSights(); 235 P_RunMobjBase(); 236 237 P_UpdateSpecials(); 238 P_RunMacros(); 239 240 ST_Ticker(); // update status bar 241 } 242 243 //ST_DebugPrint("%d",Z_FreeMemory (mainzone)); 244 245 // 246 // run player actions 247 // 248 pl = players; 249 250 if (pl->playerstate == PST_REBORN) 251 gameaction = ga_died; 252 253 AM_Control(pl); 254 P_PlayerThink(pl); 255 256 return gameaction; // may have been set to ga_died, ga_completed, or ga_secretexit 257 } 258 259 /* 260 ============= 261 = 262 = P_Drawer 263 = 264 = draw current display 265 ============= 266 */ 267 268 extern Mtx R_ProjectionMatrix; // 800A68B8 269 extern Mtx R_ModelMatrix; // 8005b0C8 270 271 void P_Drawer (void) // 80021AC8 272 { 273 I_ClearFrame(); 274 275 gMoveWd(GFX1++, G_MW_CLIP, G_MWO_CLIP_RNX, 1); 276 gMoveWd(GFX1++, G_MW_CLIP, G_MWO_CLIP_RNY, 1); 277 gMoveWd(GFX1++, G_MW_CLIP, G_MWO_CLIP_RPX, 65535); 278 gMoveWd(GFX1++, G_MW_CLIP, G_MWO_CLIP_RPY, 65535); 279 gMoveWd(GFX1++, G_MW_PERSPNORM, G_MWO_MATRIX_XX_XY_I, 68); 280 281 // create a projection matrix 282 gSPMatrix(GFX1++, OS_K0_TO_PHYSICAL(&R_ProjectionMatrix), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH); 283 284 // create a model matrix 285 gSPMatrix(GFX1++, OS_K0_TO_PHYSICAL(&R_ModelMatrix), G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH); 286 287 if (players[0].automapflags & (AF_LINES|AF_SUBSEC)) 288 { 289 AM_Drawer(); 290 } 291 else 292 { 293 R_RenderPlayerView(); 294 //ST_DebugPrint("x %d || y %d", players[0].mo->x >> 16, players[0].mo->y >> 16); 295 296 if (demoplayback == false) 297 ST_Drawer(); 298 } 299 300 if (MenuCall) 301 { 302 M_DrawOverlay(0, 0, 320, 240, 96); 303 MenuCall(); 304 } 305 306 I_DrawFrame(); 307 } 308 309 extern void T_FadeInBrightness(fadebright_t *fb); 310 extern int start_time; // 80063390 311 extern int end_time; // 80063394 312 313 void P_Start (void) // 80021C50 314 { 315 fadebright_t *fb; 316 317 DrawerStatus = 1; 318 319 if (gamemap == 33) /* Add by default God Mode in player */ 320 players[0].cheats |= CF_GODMODE; 321 else if (gamemap == 32) /* Remove by default God Mode in player */ 322 players[0].cheats &= ~CF_GODMODE; 323 324 gamepaused = false; 325 validcount = 1; 326 327 AM_Start(); 328 M_ClearRandom(); 329 330 /* do a nice little fade in effect */ 331 fb = Z_Malloc(sizeof(*fb), PU_LEVSPEC, 0); 332 P_AddThinker(&fb->thinker); 333 fb->thinker.function = T_FadeInBrightness; 334 fb->factor = 0; 335 336 /* autoactivate line specials */ 337 P_ActivateLineByTag(999, players[0].mo); 338 339 start_time = ticon; 340 341 MusicID = MapInfo[gamemap].MusicSeq-92; 342 S_StartMusic(MapInfo[gamemap].MusicSeq); 343 } 344 345 void P_Stop (int exit) // 80021D58 346 { 347 /* [d64] stop plasma buzz */ 348 S_StopSound(0, sfx_electric); 349 350 end_time = ticon; 351 gamepaused = false; 352 DrawerStatus = 0; 353 354 G_PlayerFinishLevel(0); 355 356 /* free all tags except the PU_STATIC tag */ 357 Z_FreeTags(mainzone, ~PU_STATIC); // (PU_LEVEL | PU_LEVSPEC | PU_CACHE) 358 359 if ((gamemap != 33) || (exit == 8)) 360 S_StopMusic(); 361 362 if ((demoplayback) && (exit == 8)) 363 I_WIPE_FadeOutScreen(); 364 else 365 I_WIPE_MeltScreen(); 366 367 S_StopAll(); 368 } 369