1 /*
2 * IceBreaker
3 * Copyright (c) 2002 Matthew Miller <mattdm@mattdm.org>
4 *
5 * <http://www.mattdm.org/icebreaker/>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc., 59
19 * Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23
24
25 #include <SDL.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include "icebreaker.h"
29
30 #if DEVELRELEASE
31
32 #include "cursor.h"
33 #include "penguin.h"
34 #include "line.h"
35 #include "grid.h"
36 #include "sound.h"
37 #include "laundry.h"
38 #include "globals.h"
39 #include "status.h"
40 #include "text.h"
41 #include "themes.h"
42 #include "event.h"
43 #include "fullscreen.h"
44
45 static void setupbenchmark(void);
46
setupbenchmark()47 void setupbenchmark()
48 {
49 int x,y;
50
51 setcursor(CURSORARROW);
52 SDL_FillRect(screen,NULL,color.background);
53
54 for (x=0;x<WIDTH;x++)
55 for (y=0;y<HEIGHT;y++)
56 {
57 if (x<BORDERLEFT || x>=BORDERRIGHT || y <BORDERTOP || y>=BORDERBOTTOM)
58 grid[x][y]='X';
59 else
60 grid[x][y]=' ';
61 }
62
63 drawgridblocks();
64
65 updateall();
66 }
67
68
69
benchmark(void)70 int benchmark(void)
71 {
72 int penguincount=MAXPENGUINS;
73 int i;
74 SDL_Event event;
75 SDL_Rect fpsrect;
76 char fpstext[20];
77 int done = false;
78
79 Penguin flock[MAXPENGUINS];
80 Uint32 starttime, endtime, tmptime, framecount, tmpframecount;
81
82
83 setupbenchmark();
84
85 fpsrect.x=BORDERLEFT; fpsrect.y=BOTTOMSTATUSY;
86 fpsrect.h=CHARHEIGHT*3;; fpsrect.w=CHARWIDTH*2*20;
87
88 for (i=0;i<penguincount;i++)
89 {
90 flock[i] = createpenguin();
91 }
92
93 framecount=0;
94 tmpframecount=0;
95 starttime=SDL_GetTicks();
96 tmptime=starttime;
97 do
98 {
99 while (pollevent(&event))
100 {
101 if (event.type == SDL_QUIT)
102 {
103 done=true;
104 }
105 else if (event.type == SDL_MOUSEBUTTONUP)
106 {
107 done=true;
108 }
109 else if (event.type == SDL_KEYUP)
110 {
111 switch(translatekeyevent(&event))
112 {
113 case KEYCANCEL:
114 done=true;
115 break;
116 default:
117 break;
118 }
119 }
120 }
121
122
123 // move (and get old background)
124
125 for (i=0;i<penguincount;i+=2)
126 {
127 soil(flock[i].geom); // mark the penguin's old position as dirty
128 movepenguin(&flock[i]);
129 soil(flock[i].geom); // mark the penguin's new position as dirty too (it will be soon...)
130 savebehindpenguin(&flock[i]);
131 }
132
133
134 // actually draw
135 for (i=0;i<penguincount;i+=2)
136 {
137 drawpenguin(&flock[i]);
138 }
139
140 // update screen
141 clean();
142
143 for (i=0;i<penguincount;i+=2)
144 {
145 erasepenguin(&flock[i]);
146 }
147
148 if (SDL_GetTicks() >= tmptime+1000)
149 {
150 snprintf(fpstext,20,"FPS: %.2f",((framecount-tmpframecount)*1000.0)/(SDL_GetTicks()-tmptime));
151 tmptime=SDL_GetTicks();
152 tmpframecount=framecount;
153 SDL_FillRect(screen,&fpsrect,color.background);
154 puttext(fpsrect.x,fpsrect.y+3,2,color.normaltext,fpstext);
155 soil(fpsrect);
156 }
157 framecount++;
158
159 } while (!done);
160 endtime=SDL_GetTicks();
161 if (endtime>starttime)
162 printf("Overall: %.2f frames per second.\n", (framecount*1000.0)/(endtime-starttime) );
163
164 clean();
165
166 while (penguincount)
167 {
168 penguincount--;
169 deletepenguin(&flock[penguincount]);
170 }
171
172 return(false);
173 }
174
175 #endif /* DEVELRELEASE */
176