timer.c
3.6 KB
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
/**************************************************************************
* *
* Copyright (C) 1995, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
*************************************************************************/
#include <ultra64.h>
#include "block.h"
#include "static.h"
#include "timer.h"
extern gtGlobState *ggsp;
Gfx timerMoreRDPCMDS[32];
/* this init's the DP and clears the screen: */
gtState timerObj =
{
0x0, /* renderState */
0x0, /* textureState */
0, /* vtxCount */
0, /* vtxV0 */
0, /* triCount */
0x0, /* pad1 */
&(timerMoreRDPCMDS[0]),
gsDPClearOtherMode(), /* rdpOthermode */
{ /* integer portion: */
0x00010000, 0x00000000, /* transform */
0x00000001, 0x00000000,
0x00000000, 0x00010000,
0x00000000, 0x00000001,
/* fractional portion: */
0x00000000, 0x00000000,
0x00000000, 0x00000000,
0x00000000, 0x00000000,
0x00000000, 0x00000000,
}
};
void SelfScaleTimerBar(void)
{
/* self scaling counter stuff, take out if it's too obnoxious */
if ((1.0/TIMERUNDERFLOW) * TimePerFrame / TIMERINTERVAL + 1.0 < TimerTicks)
while (((1.0/TIMERUNDERFLOW) * TimePerFrame / TIMERINTERVAL + 1.0 < TimerTicks) &&
(TimerTicks != MINTIMERTICKS))
TimerTicks-=2;
else if ((1.0/TIMEROVERFLOW) * TimePerFrame / TIMERINTERVAL + 1.0 > TimerTicks)
while (((1.0/TIMEROVERFLOW) * TimePerFrame / TIMERINTERVAL + 1.0 > TimerTicks) &&
(TimerTicks != MAXTIMERTICKS))
TimerTicks+=2;
}
void WriteTimerBar(void)
{
float TickSpacing, BarPercent;
int i;
Gfx *gptr;
if (SelfScaleTimer) SelfScaleTimerBar();
TickSpacing = (TIMERMAXX - TIMERMINX) / (TimerTicks - 1.0);
gtStateSetOthermode(&(timerObj.sp.rdpOthermode), GT_RENDERMODE,
(G_RM_OPA_SURF | G_RM_OPA_SURF2));
gtStateSetOthermode(&(timerObj.sp.rdpOthermode), GT_CYCLETYPE,
G_CYC_FILL);
gptr = (Gfx *) &(timerObj.sp.rdpCmds[0]);
BarPercent = TimePerFrame / (TIMERINTERVAL * (TimerTicks - 1));
if (BarPercent < 1.0) {
/* Within bar counter */
gDPSetFillColor(gptr++,
GPACK_RGBA5551(0,127,0,1) << 16 |
GPACK_RGBA5551(0,127,0,1));
gDPFillRectangle(gptr++,
TIMERMINX,
TIMERMINY,
TIMERMINX + (int)((TIMERMAXX - TIMERMINX)*BarPercent),
TIMERMAXY);
} else {
/* Overflowed bar counter range */
gDPSetFillColor(gptr++,
GPACK_RGBA5551(127,0,0,1) << 16 |
GPACK_RGBA5551(127,0,0,1));
gDPFillRectangle(gptr++,
TIMERMINX, TIMERMINY,
TIMERMAXX, TIMERMAXY);
}
gDPSetFillColor(gptr++,
GPACK_RGBA5551(0,0,0,1) << 16 |
GPACK_RGBA5551(0,0,0,1));
for (i=0; i<TimerTicks; i++) {
gDPFillRectangle(gptr++,
TIMERMINX + (int) TickSpacing*i, TIMERMINY,
TIMERMINX + (int) TickSpacing*i, TIMERMAXY);
}
gDPPipeSync(gptr++);
gDPEndDisplayList(gptr++);
/* timer state: */
gtlistp->obj.gstatep = ggsp;
gtlistp->obj.statep = &timerObj;
gtlistp->obj.vtxp = (Vtx *) NULL;
gtlistp->obj.trip = (gtTriN *) NULL;
gtlistp++;
}