|
|
1.1 root 1: #include "doomdef.h"
2: #include "p_local.h"
3:
4: int playertics, thinkertics, sighttics, basetics, latetics;
5: int tictics;
6:
7: boolean gamepaused;
8: jagobj_t *pausepic;
9:
10: /*
11: ===============================================================================
12:
13: THINKERS
14:
15: All thinkers should be allocated by Z_Malloc so they can be operated on uniformly. The actual
16: structures will vary in size, but the first element must be thinker_t.
17:
18: Mobjs are similar to thinkers, but kept seperate for more optimal list
19: processing
20: ===============================================================================
21: */
22:
23: thinker_t thinkercap; /* both the head and tail of the thinker list */
24: mobj_t mobjhead; /* head and tail of mobj list */
25: int activethinkers; /* debug count */
26: int activemobjs; /* debug count */
27:
28: /*
29: ===============
30: =
31: = P_InitThinkers
32: =
33: ===============
34: */
35:
36: void P_InitThinkers (void)
37: {
38: thinkercap.prev = thinkercap.next = &thinkercap;
39: mobjhead.next = mobjhead.prev = &mobjhead;
40: }
41:
42:
43: /*
44: ===============
45: =
46: = P_AddThinker
47: =
48: = Adds a new thinker at the end of the list
49: =
50: ===============
51: */
52:
53: void P_AddThinker (thinker_t *thinker)
54: {
55: thinkercap.prev->next = thinker;
56: thinker->next = &thinkercap;
57: thinker->prev = thinkercap.prev;
58: thinkercap.prev = thinker;
59: }
60:
61:
62: /*
63: ===============
64: =
65: = P_RemoveThinker
66: =
67: = Deallocation is lazy -- it will not actually be freed until its
68: = thinking turn comes up
69: =
70: ===============
71: */
72:
73: void P_RemoveThinker (thinker_t *thinker)
74: {
75: thinker->function = (think_t)-1;
76: }
77:
78: /*
79: ===============
80: =
81: = P_RunThinkers
82: =
83: ===============
84: */
85:
86: void P_RunThinkers (void)
87: {
88: thinker_t *currentthinker;
89:
90: activethinkers = 0;
91:
92: currentthinker = thinkercap.next;
93: while (currentthinker != &thinkercap)
94: {
95: if (currentthinker->function == (think_t)-1)
96: { /* time to remove it */
97: currentthinker->next->prev = currentthinker->prev;
98: currentthinker->prev->next = currentthinker->next;
99: Z_Free (currentthinker);
100: }
101: else
102: {
103: if (currentthinker->function)
104: {
105: currentthinker->function (currentthinker);
106: }
107: activethinkers++;
108: }
109: currentthinker = currentthinker->next;
110: }
111: }
112:
113:
114: /*============================================================================= */
115:
116: /*
117: ===============
118: =
119: = P_CheckSights
120: =
121: = Check sights of all mobj thinkers that are going to change state this
122: = tic and have MF_COUNTKILL set
123: ===============
124: */
125:
126: void P_CheckSights2 ();
127:
128: void P_CheckSights (void)
129: {
130: #ifdef JAGUAR
131: extern int p_sight_start;
132: DSPFunction (&p_sight_start);
133: #else
134: P_CheckSights2 ();
135: #endif
136: }
137:
138: /*============================================================================= */
139:
140: /*
141: ===================
142: =
143: = P_RunMobjBase
144: =
145: = Run stuff that doesn't happen every tick
146: ===================
147: */
148:
149: void P_RunMobjBase (void)
150: {
151: #ifdef JAGUAR
152: extern int p_base_start;
153:
154: DSPFunction (&p_base_start);
155: #else
156: P_RunMobjBase2 ();
157: #endif
158: }
159:
160: /*============================================================================= */
161:
162: /*
163: ===================
164: =
165: = P_RunMobjLate
166: =
167: = Run stuff that doesn't happen every tick
168: ===================
169: */
170:
171: void P_RunMobjLate (void)
172: {
173: mobj_t *mo;
174: mobj_t *next;
175:
176: for (mo=mobjhead.next ; mo != &mobjhead ; mo=next)
177: {
178: next = mo->next; /* in case mo is removed this time */
179: if (mo->latecall)
180: {
181: mo->latecall(mo);
182: }
183: }
184: }
185:
186: /*============================================================================= */
187:
188: /*
189: ==============
190: =
191: = P_CheckCheats
192: =
193: ==============
194: */
195:
196: void P_CheckCheats (void)
197: {
198: int buttons, oldbuttons;
199: int warpmap;
200: int i;
201: player_t *p;
202:
203: for (i=0 ; i<MAXPLAYERS ; i++)
204: {
205: if (!playeringame[i])
206: continue;
207: buttons = ticbuttons[i];
208: oldbuttons = oldticbuttons[i];
209:
210: if ( (buttons & BT_PAUSE) && !(oldbuttons&BT_PAUSE) )
211: gamepaused ^= 1;
212: }
213:
214: if (netgame)
215: return;
216:
217: buttons = ticbuttons[0];
218: oldbuttons = oldticbuttons[0];
219:
220: if ( (oldbuttons&JP_PAUSE) || !(buttons & JP_PAUSE ) )
221: return;
222:
223:
224: if (buttons&JP_NUM)
225: { /* free stuff */
226: p=&players[0];
227: for (i=0 ; i<NUMCARDS ; i++)
228: p->cards[i] = true;
229: p->armorpoints = 200;
230: p->armortype = 2;
231: for (i=0;i<NUMWEAPONS;i++) p->weaponowned[i] = true;
232: for (i=0;i<NUMAMMO;i++) p->ammo[i] = p->maxammo[i] = 500;
233: }
234:
235: if (buttons&JP_STAR)
236: { /* godmode */
237: players[0].cheats ^= CF_GODMODE;
238: }
239: warpmap = 0;
240: if (buttons&JP_1) warpmap = 1;
241: if (buttons&JP_2) warpmap = 2;
242: if (buttons&JP_3) warpmap = 3;
243: if (buttons&JP_4) warpmap = 4;
244: if (buttons&JP_5) warpmap = 5;
245: if (buttons&JP_6) warpmap = 6;
246: if (buttons&JP_7) warpmap = 7;
247: if (buttons&JP_8) warpmap = 8;
248: if (buttons&JP_9) warpmap = 9;
249: if (buttons&JP_A) warpmap += 10;
250: else if (buttons&JP_B) warpmap += 20;
251:
252: if (warpmap>0 && warpmap < 27)
253: {
254: gamemap = warpmap;
255: gameaction = ga_warped;
256: }
257: }
258:
259:
260: int playernum;
261:
262: void G_DoReborn (int playernum);
263:
264: /*
265: =================
266: =
267: = P_Ticker
268: =
269: =================
270: */
271:
272: int ticphase;
273:
274: int P_Ticker (void)
275: {
276: int start;
277: int ticstart;
278: player_t *pl;
279:
280: ticstart = samplecount;
281:
282: while (!I_RefreshLatched () )
283: ; /* wait for refresh to latch all needed data before */
284: /* running the next tick */
285:
286: #ifdef JAGAUR
287: while (DSPRead (&dspfinished) != 0xdef6)
288: ; /* wait for sound mixing to complete */
289: #endif
290:
291: gameaction = ga_nothing;
292:
293: gametic++;
294:
295: /* */
296: /* check for pause and cheats */
297: /* */
298: P_CheckCheats ();
299:
300: /* */
301: /* do option screen processing */
302: /* */
303:
304: for (playernum=0,pl=players ; playernum<MAXPLAYERS ; playernum++,pl++)
305: if (playeringame[playernum])
306: O_Control (pl);
307:
308:
309: if (gamepaused)
310: return 0;
311:
312: /* */
313: /* run player actions */
314: /* */
315: start = samplecount;
316: for (playernum=0,pl=players ; playernum<MAXPLAYERS ; playernum++,pl++)
317: if (playeringame[playernum])
318: {
319: if (pl->playerstate == PST_REBORN)
320: G_DoReborn (playernum);
321: AM_Control (pl);
322: P_PlayerThink (pl);
323: }
324: playertics = samplecount - start;
325:
326:
327: start = samplecount;
328: P_RunThinkers ();
329: thinkertics = samplecount - start;
330:
331: start = samplecount;
332: P_CheckSights ();
333: sighttics = samplecount - start;
334:
335: start = samplecount;
336: P_RunMobjBase ();
337: basetics = samplecount - start;
338:
339: start = samplecount;
340: P_RunMobjLate ();
341: latetics = samplecount - start;
342:
343: P_UpdateSpecials ();
344:
345: P_RespawnSpecials ();
346:
347: ST_Ticker (); /* update status bar */
348:
349: tictics = samplecount - ticstart;
350:
351: return gameaction; /* may have been set to ga_died, ga_completed, */
352: /* or ga_secretexit */
353: }
354:
355:
356: /*
357: =============
358: =
359: = DrawPlaque
360: =
361: =============
362: */
363:
364: void DrawPlaque (jagobj_t *pl)
365: {
366: #ifdef JAGUAR
367: int x,y,w;
368: short *sdest;
369: byte *bdest, *source;
370: extern int isrvmode;
371:
372: while ( !I_RefreshCompleted () )
373: ;
374:
375: bufferpage = (byte *)screens[!workpage];
376: source = pl->data;
377:
378: if (isrvmode == 0xc1 + (3<<9) )
379: { /* 320 mode, stretch pixels */
380: bdest = (byte *)bufferpage + 80*320 + (160 - pl->width);
381: w = pl->width;
382: for (y=0 ; y<pl->height ; y++)
383: {
384: for (x=0 ; x<w ; x++)
385: {
386: bdest[x*2] = bdest[x*2+1] = *source++;
387: }
388: bdest += 320;
389: }
390: }
391: else
392: { /* 160 mode, draw directly */
393: sdest = (short *)bufferpage + 80*160 + (80 - pl->width/2);
394: w = pl->width;
395: for (y=0 ; y<pl->height ; y++)
396: {
397: for (x=0 ; x<w ; x++)
398: {
399: sdest[x] = palette8[*source++];
400: }
401: sdest += 160;
402: }
403: }
404:
405: #endif
406: }
407:
408: /*
409: =============
410: =
411: = DrawPlaque
412: =
413: =============
414: */
415:
416: void DrawSinglePlaque (jagobj_t *pl)
417: {
418: int x,y,w;
419: byte *bdest, *source;
420:
421: while ( !I_RefreshCompleted () )
422: ;
423:
424: bufferpage = (byte *)screens[!workpage];
425: source = pl->data;
426:
427: bdest = (byte *)bufferpage + 80*320 + (160 - pl->width/2);
428: w = pl->width;
429: for (y=0 ; y<pl->height ; y++)
430: {
431: for (x=0 ; x<w ; x++)
432: bdest[x] = *source++;
433: bdest += 320;
434: }
435: }
436:
437:
438: /*
439: =============
440: =
441: = P_Drawer
442: =
443: = draw current display
444: =============
445: */
446:
447:
448: void P_Drawer (void)
449: {
450: static boolean refreshdrawn;
451: #ifndef MARS
452: if (players[consoleplayer].automapflags & AF_OPTIONSACTIVE)
453: {
454: O_Drawer ();
455: refreshdrawn = false;
456: }
457: else if (gamepaused && refreshdrawn)
458: DrawPlaque (pausepic);
459: else if (players[consoleplayer].automapflags & AF_ACTIVE)
460: {
461: ST_Drawer ();
462: AM_Drawer ();
463: I_Update ();
464: refreshdrawn = true;
465: }
466: else
467: #endif
468: {
469: #ifdef JAGUAR
470: ST_Drawer ();
471: #endif
472: R_RenderPlayerView ();
473: refreshdrawn = true;
474: /* assume part of the refresh is now running parallel with main code */
475: }
476: }
477:
478:
479: extern int ticremainder[2];
480:
481: void P_Start (void)
482: {
483: #ifndef MARS
484: AM_Start ();
485: S_RestartSounds ();
486: #endif
487: players[0].automapflags = 0;
488: players[1].automapflags = 0;
489: ticremainder[0] = ticremainder[1] = 0;
490: M_ClearRandom ();
491: }
492:
493: void P_Stop (void)
494: {
495: Z_FreeTags (mainzone);
496: }
497:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.