-
Notifications
You must be signed in to change notification settings - Fork 13
/
p_tick.c
659 lines (541 loc) · 11.5 KB
/
p_tick.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
#include "doomdef.h"
#include "p_local.h"
#ifdef MARS
#include "mars.h"
#endif
int playertics, thinkertics, sighttics, basetics, latetics;
int tictics, drawtics;
boolean gamepaused;
jagobj_t *pausepic;
char clearscreen = 0;
/*
===============================================================================
THINKERS
All thinkers should be allocated by Z_Malloc so they can be operated on uniformly. The actual
structures will vary in size, but the first element must be thinker_t.
Mobjs are similar to thinkers, but kept seperate for more optimal list
processing
===============================================================================
*/
thinker_t thinkercap; /* both the head and tail of the thinker list */
degenmobj_t mobjhead; /* head and tail of mobj list */
degenmobj_t freemobjhead, freestaticmobjhead; /* head and tail of free mobj list */
degenmobj_t limbomobjhead;
//int activethinkers; /* debug count */
//int activemobjs; /* debug count */
/*
===============
=
= P_InitThinkers
=
===============
*/
void P_InitThinkers (void)
{
thinkercap.prev = thinkercap.next = &thinkercap;
mobjhead.next = mobjhead.prev = (void *)&mobjhead;
freemobjhead.next = freemobjhead.prev = (void *)&freemobjhead;
freestaticmobjhead.next = freestaticmobjhead.prev = (void *)&freestaticmobjhead;
limbomobjhead.next = limbomobjhead.prev = (void*)&limbomobjhead;
}
/*
===============
=
= P_AddThinker
=
= Adds a new thinker at the end of the list
=
===============
*/
void P_AddThinker (thinker_t *thinker)
{
thinkercap.prev->next = thinker;
thinker->next = &thinkercap;
thinker->prev = thinkercap.prev;
thinkercap.prev = thinker;
}
/*
===============
=
= P_RemoveThinker
=
= Deallocation is lazy -- it will not actually be freed until its
= thinking turn comes up
=
===============
*/
void P_RemoveThinker (thinker_t *thinker)
{
thinker->function = (think_t)-1;
}
/*
===============
=
= P_RunThinkers
=
===============
*/
void P_RunThinkers (void)
{
thinker_t *currentthinker;
//activethinkers = 0;
currentthinker = thinkercap.next;
while (currentthinker != &thinkercap)
{
if (currentthinker->function == (think_t)-1)
{ /* time to remove it */
currentthinker->next->prev = currentthinker->prev;
currentthinker->prev->next = currentthinker->next;
Z_Free (currentthinker);
}
else
{
if (currentthinker->function)
{
currentthinker->function (currentthinker);
}
//activethinkers++;
}
currentthinker = currentthinker->next;
}
}
/*============================================================================= */
/*
===============
=
= P_CheckSights
=
= Check sights of all mobj thinkers that are going to change state this
= tic and have MF_COUNTKILL set
===============
*/
#ifdef MARS
void P_CheckSights2(int c) ATTR_DATA_CACHE_ALIGN ATTR_OPTIMIZE_SIZE;
#else
void P_CheckSights2(void) ATTR_DATA_CACHE_ALIGN ATTR_OPTIMIZE_SIZE;
#endif
#ifdef MARS
void Mars_Sec_P_CheckSights(void)
{
P_CheckSights2(1);
}
#endif
void P_CheckSights (void)
{
#ifdef JAGUAR
extern int p_sight_start;
DSPFunction (&p_sight_start);
#elif defined(MARS)
Mars_P_BeginCheckSights();
P_CheckSights2(0);
Mars_P_EndCheckSights();
#else
P_CheckSights2();
#endif
}
/*============================================================================= */
/*
===================
=
= P_RunMobjBase
=
= Run stuff that doesn't happen every tick
===================
*/
void P_RunMobjBase (void)
{
#ifdef JAGUAR
extern int p_base_start;
DSPFunction (&p_base_start);
#else
P_RunMobjBase2 ();
#endif
}
/*============================================================================= */
/*
==============
=
= P_CheckCheats
=
==============
*/
void P_CheckCheats (void)
{
#ifdef JAGUAR
int buttons, oldbuttons;
int warpmap;
int i;
player_t *p;
for (i=0 ; i<MAXPLAYERS ; i++)
{
if (!playeringame[i])
continue;
buttons = ticbuttons[i];
oldbuttons = oldticbuttons[i];
if ( (buttons & BT_PAUSE) && !(oldbuttons&BT_PAUSE) )
gamepaused ^= 1;
}
if (netgame)
return;
buttons = ticbuttons[0];
oldbuttons = oldticbuttons[0];
if ( (oldbuttons&BT_PAUSE) || !(buttons & BT_PAUSE ) )
return;
if (buttons&JP_NUM)
{ /* free stuff */
p=&players[0];
for (i=0 ; i<NUMCARDS ; i++)
p->cards[i] = true;
p->armorpoints = 200;
p->armortype = 2;
for (i=0;i<NUMWEAPONS;i++) p->weaponowned[i] = true;
for (i=0;i<NUMAMMO;i++) p->ammo[i] = p->maxammo[i] = 500;
}
if (buttons&JP_STAR)
{ /* godmode */
players[0].cheats ^= CF_GODMODE;
}
warpmap = 0;
if (buttons&JP_1) warpmap = 1;
if (buttons&JP_2) warpmap = 2;
if (buttons&JP_3) warpmap = 3;
if (buttons&JP_4) warpmap = 4;
if (buttons&JP_5) warpmap = 5;
if (buttons&JP_6) warpmap = 6;
if (buttons&JP_7) warpmap = 7;
if (buttons&JP_8) warpmap = 8;
if (buttons&JP_9) warpmap = 9;
if (buttons&JP_A) warpmap += 10;
else if (buttons&JP_B) warpmap += 20;
if (warpmap>0 && warpmap < 27)
{
gamemaplump = G_LumpNumForMapNum(warpmap);
gameaction = ga_warped;
}
#elif defined(MARS)
int i;
int buttons;
int oldbuttons;
const int stuff_combo = BT_A | BT_B | BT_C | BT_UP;
const int godmode_combo = BT_X | BT_Y | BT_Z | BT_UP;
player_t* p;
boolean automap = (players[consoleplayer].automapflags & AF_ACTIVE) != 0;
extern VINT showAllThings;
extern VINT showAllLines;
if (netgame)
return;
if (!gamepaused)
return;
buttons = ticrealbuttons;
oldbuttons = oldticrealbuttons;
if ((buttons & stuff_combo) == stuff_combo
&& (oldbuttons & stuff_combo) != stuff_combo)
{
if (automap)
{
showAllThings ^= 1;
return;
}
/* free stuff */
p = &players[0];
for (i = 0; i < NUMCARDS; i++)
p->cards[i] = true;
p->armorpoints = 200;
p->armortype = 2;
for (i = 0; i < NUMWEAPONS; i++) p->weaponowned[i] = true;
for (i = 0; i < NUMAMMO; i++) p->ammo[i] = p->maxammo[i] = 500;
}
if ((buttons & godmode_combo) == godmode_combo
&& (oldbuttons & godmode_combo) != godmode_combo)
{
if (automap)
{
showAllLines ^= 1;
return;
}
/* godmode */
players[0].cheats ^= CF_GODMODE;
}
#endif
}
int playernum;
void G_DoReborn (int playernum);
void G_DoLoadLevel (void);
/*
=================
=
= P_Ticker
=
=================
*/
int ticphase;
#ifdef MARS
#define frtc I_GetFRTCounter()
#else
#define frtc samplecount
#endif
int P_Ticker (void)
{
int start;
int ticstart;
player_t *pl;
if (demoplayback)
{
if (M_Ticker())
return ga_exitdemo;
}
while (!I_RefreshLatched () )
; /* wait for refresh to latch all needed data before */
/* running the next tick */
#ifdef JAGAUR
while (DSPRead (&dspfinished) != 0xdef6)
; /* wait for sound mixing to complete */
#endif
#ifdef MARS
// bank-switch to the page with map data
W_GetLumpData(gamemaplump);
#endif
gameaction = ga_nothing;
/* */
/* check for pause and cheats */
/* */
P_CheckCheats ();
/* */
/* do option screen processing */
/* */
for (playernum = 0, pl = players; playernum < MAXPLAYERS; playernum++, pl++)
if (playeringame[playernum])
O_Control(pl);
if (gameaction != ga_nothing)
return gameaction;
/* */
/* run player actions */
/* */
if (gamepaused)
return 0;
start = frtc;
for (playernum = 0, pl = players; playernum < MAXPLAYERS; playernum++, pl++)
if (playeringame[playernum])
{
if (pl->playerstate == PST_REBORN)
G_DoReborn(playernum);
AM_Control(pl);
P_PlayerThink(pl);
}
playertics = frtc - start;
#ifdef THINKERS_30HZ
start = frtc;
P_RunThinkers();
thinkertics = frtc - start;
#endif
if (gametic != prevgametic)
{
ticstart = frtc;
#ifndef THINKERS_30HZ
start = frtc;
P_RunThinkers();
thinkertics = frtc - start;
#endif
start = frtc;
P_CheckSights();
sighttics = frtc - start;
start = frtc;
P_RunMobjBase();
basetics = frtc - start;
start = frtc;
P_RunMobjLate();
latetics = frtc - start;
P_UpdateSpecials();
P_RespawnSpecials();
ST_Ticker(); /* update status bar */
tictics = frtc - ticstart;
}
return gameaction; /* may have been set to ga_died, ga_completed, */
/* or ga_secretexit */
}
/*
=============
=
= DrawPlaque
=
=============
*/
void DrawPlaque (jagobj_t *pl)
{
#ifndef MARS
int x,y,w;
short *sdest;
byte *bdest, *source;
extern int isrvmode;
while ( !I_RefreshCompleted () )
;
bufferpage = (byte *)screens[!workpage];
source = pl->data;
if (isrvmode == 0xc1 + (3<<9) )
{ /* 320 mode, stretch pixels */
bdest = (byte *)bufferpage + 80*320 + (160 - pl->width);
w = pl->width;
for (y=0 ; y<pl->height ; y++)
{
for (x=0 ; x<w ; x++)
{
bdest[x*2] = bdest[x*2+1] = *source++;
}
bdest += 320;
}
}
else
{ /* 160 mode, draw directly */
sdest = (short *)bufferpage + 80*160 + (80 - pl->width/2);
w = pl->width;
for (y=0 ; y<pl->height ; y++)
{
for (x=0 ; x<w ; x++)
{
sdest[x] = palette8[*source++];
}
sdest += 160;
}
}
#else
clearscreen = 2;
#endif
}
/*
=============
=
= DrawPlaque
=
=============
*/
#ifndef MARS
void DrawSinglePlaque (jagobj_t *pl)
{
int x,y,w;
byte *bdest, *source;
while ( !I_RefreshCompleted () )
;
bufferpage = (byte *)screens[!workpage];
source = pl->data;
bdest = (byte *)bufferpage + 80*320 + (160 - pl->width/2);
w = pl->width;
for (y=0 ; y<pl->height ; y++)
{
for (x=0 ; x<w ; x++)
bdest[x] = *source++;
bdest += 320;
}
}
#endif
/*
=============
=
= P_Drawer
=
= draw current display
=============
*/
void P_Drawer (void)
{
boolean automapactive = (players[consoleplayer].automapflags & AF_ACTIVE) != 0;
boolean optionsactive = (players[consoleplayer].automapflags & AF_OPTIONSACTIVE) != 0;
static boolean o_wasactive, am_wasactive = false;
#ifdef MARS
extern boolean debugscreenactive;
drawtics = frtc;
if ((!optionsactive && o_wasactive) || (!automapactive && am_wasactive))
clearscreen = 2;
if (clearscreen > 0) {
I_ResetLineTable();
if ((viewportWidth == 160 && lowResMode) || viewportWidth == 320)
I_ClearFrameBuffer();
else
DrawTiledBackground();
I_DrawSbar();
if (clearscreen == 2 || optionsactive)
ST_ForceDraw();
clearscreen--;
}
if (initmathtables)
{
R_InitMathTables();
initmathtables--;
}
/* view the guy you are playing */
R_RenderPlayerView(consoleplayer);
/* view the other guy in split screen mode */
if (splitscreen) {
Mars_R_SecWait();
R_RenderPlayerView(consoleplayer ^ 1);
}
ST_Drawer();
Mars_R_SecWait();
if (automapactive)
AM_Drawer();
if (demoplayback)
M_Drawer();
if (optionsactive)
O_Drawer();
o_wasactive = optionsactive;
am_wasactive = automapactive;
drawtics = frtc - drawtics;
if (debugscreenactive)
I_DebugScreen();
#else
if (optionsactive)
{
O_Drawer ();
}
else if (gamepaused && refreshdrawn)
DrawPlaque (pausepic);
else if (automapactive)
{
ST_Drawer ();
AM_Drawer ();
I_Update ();
}
else
{
#ifdef JAGUAR
ST_Drawer();
#endif
R_RenderPlayerView(consoleplayer);
clearscreen = 0;
}
/* assume part of the refresh is now running parallel with main code */
#endif
}
extern VINT ticremainder[MAXPLAYERS];
void P_Start (void)
{
extern boolean canwipe;
/* load a level */
G_DoLoadLevel();
AM_Start ();
#ifndef MARS
S_RestartSounds ();
#endif
players[0].automapflags = 0;
players[1].automapflags = 0;
ticremainder[0] = ticremainder[1] = 0;
M_ClearRandom ();
if (!demoplayback && !demorecording)
if (!netgame || splitscreen)
P_RandomSeed(I_GetTime());
clearscreen = 2;
canwipe = true;
}
void P_Stop (void)
{
M_Stop();
Z_FreeTags (mainzone);
}
void P_Update (void)
{
int ticratebak;
ticratebak = ticsperframe;
if (viewportWidth >= 320 && ticsperframe < 3)
ticsperframe = 3;
I_Update();
ticsperframe = ticratebak;
}