-
Notifications
You must be signed in to change notification settings - Fork 7
/
benchmark.c
175 lines (142 loc) · 3.44 KB
/
benchmark.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
/*
* IceBreaker
* Copyright (c) 2002-2020 Matthew Miller <mattdm@mattdm.org>
*
* <http://www.mattdm.org/icebreaker/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include "icebreaker.h"
#if DEVELRELEASE
#include "cursor.h"
#include "penguin.h"
#include "line.h"
#include "grid.h"
#include "sound.h"
#include "laundry.h"
#include "globals.h"
#include "status.h"
#include "text.h"
#include "themes.h"
#include "event.h"
#include "fullscreen.h"
static void setupbenchmark(void);
void setupbenchmark()
{
int x,y;
setcursor(CURSORARROW);
SDL_FillRect(screen,NULL,color.background);
for (x=0;x<WIDTH;x++)
for (y=0;y<HEIGHT;y++)
{
if (x<BORDERLEFT || x>=BORDERRIGHT || y <BORDERTOP || y>=BORDERBOTTOM)
grid[x][y]='X';
else
grid[x][y]=' ';
}
drawgridblocks();
updateall();
}
int benchmark(void)
{
int penguincount=MAXPENGUINS;
int i;
SDL_Event event;
SDL_Rect fpsrect;
char fpstext[20];
int done = false;
Penguin flock[MAXPENGUINS];
Uint32 starttime, endtime, tmptime, framecount, tmpframecount;
setupbenchmark();
fpsrect.x=BORDERLEFT; fpsrect.y=BOTTOMSTATUSY;
fpsrect.h=CHARHEIGHT*3;; fpsrect.w=CHARWIDTH*2*20;
for (i=0;i<penguincount;i++)
{
flock[i] = createpenguin();
}
framecount=0;
tmpframecount=0;
starttime=SDL_GetTicks();
tmptime=starttime;
do
{
while (pollevent(&event))
{
if (event.type == SDL_QUIT)
{
done=true;
}
else if (event.type == SDL_MOUSEBUTTONUP)
{
done=true;
}
else if (event.type == SDL_KEYUP)
{
switch(translatekeyevent(&event))
{
case KEYCANCEL:
done=true;
break;
default:
break;
}
}
}
// move (and get old background)
for (i=0;i<penguincount;i+=2)
{
soil(flock[i].geom); // mark the penguin's old position as dirty
movepenguin(&flock[i]);
soil(flock[i].geom); // mark the penguin's new position as dirty too (it will be soon...)
savebehindpenguin(&flock[i]);
}
// actually draw
for (i=0;i<penguincount;i+=2)
{
drawpenguin(&flock[i]);
}
// update screen
clean();
for (i=0;i<penguincount;i+=2)
{
erasepenguin(&flock[i]);
}
if (SDL_GetTicks() >= tmptime+1000)
{
snprintf(fpstext,20,"FPS: %.2f",((framecount-tmpframecount)*1000.0)/(SDL_GetTicks()-tmptime));
tmptime=SDL_GetTicks();
tmpframecount=framecount;
SDL_FillRect(screen,&fpsrect,color.background);
puttext(fpsrect.x,fpsrect.y+3,2,color.normaltext,fpstext);
soil(fpsrect);
}
framecount++;
} while (!done);
endtime=SDL_GetTicks();
if (endtime>starttime)
printf("Overall: %.2f frames per second.\n", (framecount*1000.0)/(endtime-starttime) );
clean();
while (penguincount)
{
penguincount--;
deletepenguin(&flock[penguincount]);
}
return(false);
}
#endif /* DEVELRELEASE */