-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathp_tick.c
497 lines (405 loc) · 8.3 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
#include "doomdef.h"
#include "p_local.h"
int playertics, thinkertics, sighttics, basetics, latetics;
int tictics;
boolean gamepaused;
jagobj_t *pausepic;
/*
===============================================================================
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 */
mobj_t mobjhead; /* head and tail of mobj list */
int activethinkers; /* debug count */
int activemobjs; /* debug count */
/*
===============
=
= P_InitThinkers
=
===============
*/
void P_InitThinkers (void)
{
thinkercap.prev = thinkercap.next = &thinkercap;
mobjhead.next = mobjhead.prev = &mobjhead;
}
/*
===============
=
= 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
===============
*/
void P_CheckSights2 ();
void P_CheckSights (void)
{
#ifdef JAGUAR
extern int p_sight_start;
DSPFunction (&p_sight_start);
#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_RunMobjLate
=
= Run stuff that doesn't happen every tick
===================
*/
void P_RunMobjLate (void)
{
mobj_t *mo;
mobj_t *next;
for (mo=mobjhead.next ; mo != &mobjhead ; mo=next)
{
next = mo->next; /* in case mo is removed this time */
if (mo->latecall)
{
mo->latecall(mo);
}
}
}
/*============================================================================= */
/*
==============
=
= P_CheckCheats
=
==============
*/
void P_CheckCheats (void)
{
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&JP_PAUSE) || !(buttons & JP_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)
{
gamemap = warpmap;
gameaction = ga_warped;
}
}
int playernum;
void G_DoReborn (int playernum);
/*
=================
=
= P_Ticker
=
=================
*/
int ticphase;
int P_Ticker (void)
{
int start;
int ticstart;
player_t *pl;
ticstart = samplecount;
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
gameaction = ga_nothing;
gametic++;
/* */
/* 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 (gamepaused)
return 0;
/* */
/* run player actions */
/* */
start = samplecount;
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 = samplecount - start;
start = samplecount;
P_RunThinkers ();
thinkertics = samplecount - start;
start = samplecount;
P_CheckSights ();
sighttics = samplecount - start;
start = samplecount;
P_RunMobjBase ();
basetics = samplecount - start;
start = samplecount;
P_RunMobjLate ();
latetics = samplecount - start;
P_UpdateSpecials ();
P_RespawnSpecials ();
ST_Ticker (); /* update status bar */
tictics = samplecount - ticstart;
return gameaction; /* may have been set to ga_died, ga_completed, */
/* or ga_secretexit */
}
/*
=============
=
= DrawPlaque
=
=============
*/
void DrawPlaque (jagobj_t *pl)
{
#ifdef JAGUAR
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;
}
}
#endif
}
/*
=============
=
= DrawPlaque
=
=============
*/
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;
}
}
/*
=============
=
= P_Drawer
=
= draw current display
=============
*/
void P_Drawer (void)
{
static boolean refreshdrawn;
#ifndef MARS
if (players[consoleplayer].automapflags & AF_OPTIONSACTIVE)
{
O_Drawer ();
refreshdrawn = false;
}
else if (gamepaused && refreshdrawn)
DrawPlaque (pausepic);
else if (players[consoleplayer].automapflags & AF_ACTIVE)
{
ST_Drawer ();
AM_Drawer ();
I_Update ();
refreshdrawn = true;
}
else
#endif
{
#ifdef JAGUAR
ST_Drawer ();
#endif
R_RenderPlayerView ();
refreshdrawn = true;
/* assume part of the refresh is now running parallel with main code */
}
}
extern int ticremainder[2];
void P_Start (void)
{
#ifndef MARS
AM_Start ();
S_RestartSounds ();
#endif
players[0].automapflags = 0;
players[1].automapflags = 0;
ticremainder[0] = ticremainder[1] = 0;
M_ClearRandom ();
}
void P_Stop (void)
{
Z_FreeTags (mainzone);
}