-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.c
286 lines (232 loc) · 5.93 KB
/
main.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
//3703
/* Profile info, in 1024x768
* 25% vorbis decoding
* 35% blitting
* 15% rundemo
* 20% fillcopy
* */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "argb.h"
#include "line.h"
#include "m2d.h"
#include "layer.h"
#include "demo.h"
#include "ogdecode.h"
#include <math.h>
#include <SDL/SDL.h>
#ifdef OSX
#include <SDL/SDL_main.h>
#endif
#define HEAPSIZE 10000000
int WIDTH=640;
int HEIGHT=480;
char *moduleName="data/italo160.ogg";
volatile unsigned frame;
float fsin2(float);
int stopnow=0;
extern float con, bri;
/* Change this to standard fread() and behold: it's x86 byte order! */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
void fix_fread(void *dest,int dummy,int count,FILE *f)
{
int n;
unsigned char *d=dest;
for(n=0;n<count;n++)
d[3+n/4*4-n%4]=fgetc(f);
}
#else
void fix_fread(void *dest,int dummy,int count,FILE *f)
{
fread(dest,dummy,count,f);
}
#endif
static unsigned hiippi[HEAPSIZE];
static unsigned *hptrs[4096], hpind=1;
void *getmem(int bytes)
{
/* Let's keep it aligned */
int wds=(bytes+4)/4;
return (hptrs[hpind]+=wds)-wds;
}
void mark() { hptrs[hpind+1]=hptrs[hpind]; hpind++; }
void release() { hpind--; }
M2d *new_m2_roto(float x0, float y0, float r, float i) {
M2d *m=getmem(sizeof(M2d));
m->x1=x0; m->y1=y0;
r=exp(r);
m->xx=m->yy=cos(i)*r;
m->xy=-(m->yx=sin(i)*r);
return m;
}
M2d *new_m2_mul(M2d *a, M2d *b) {
M2d *m=getmem(sizeof(M2d));
m->xx=a->xx*b->xx+a->yx*b->xy; m->xy=a->xy*b->xx+a->yy*b->xy; m->x1=a->x1*b->xx+a->y1*b->xy+b->x1;
m->yx=a->xx*b->yx+a->yx*b->yy; m->yy=a->xy*b->yx+a->yy*b->yy; m->y1=a->x1*b->yx+a->y1*b->yy+b->y1;
return m;
}
int aikah=0;
void audioback(void *oggi, unsigned char *stream, int len) {
int i, lkm, foo=0;
if (stopnow) return;
aikah+=len;
while (len>0) {
lkm=ov_read(oggi, stream, len, 0, 2, 1, &foo);
if (lkm<=0) { stopnow++; return; }
len-=lkm; stream+=lkm;
}
}
void fillcopy(SDL_Surface *screen, Uint32* graffa, int fill)
{
int x, y;
int *p32=screen->pixels, *q32=graffa;
char *q8=(char*)graffa;
int nextline=0;
if (fill) {
nextline = WIDTH/4;
}
for (x=1; x<screen->w; x++) q8[x]^=q8[x-1];
for (y=0; y<screen->h-1; y++) {
for (x=0; x<screen->w>>2; x++) {
p32[x]=q32[x];
q32[x+nextline]^=q32[x];
}
p32+=screen->pitch>>2;
q32+=WIDTH/4;
}
}
void fla(int a) {}
int main(int argc, char *argv[]) {
int i, j, bytesleft;
int current_section,fullscreen=0;
int fill=1;
int skip=0;
float t;
static char buffer[200000];
FILE *fp;
OggVorbis_File oggi;
vorbis_info *vi;
int bufsiz;
unsigned time0, timex;
SDL_Surface *screen;
SDL_Color colors[256];
static Uint32* graffa;
static SDL_AudioSpec aanispex;
int frames = 0;
hptrs[0]=hptrs[1]=hiippi;
mark();
printf("dose2 by mfx [-WIDTHxHEIGHT -fullscreen -stretch -nofill] \n");
// This one moved here because of OSX oddities...
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)<0) {
fprintf(stderr, "sdlerror %s\n", SDL_GetError());
return 1;
}
fp=fopen(moduleName, "rb");
if (!fp || ov_open(fp, &oggi, 0, 0)<0) {
fprintf(stderr, "error in %s", moduleName);
return 1;
}
vi=ov_info(&oggi, -1);
fprintf(stderr,"\n%dchn/%ldHz\n",vi->channels,vi->rate);
atexit(SDL_Quit);
aanispex.freq=44100;
aanispex.format=AUDIO_S16;
aanispex.channels=2;
aanispex.samples=4096;
aanispex.callback=audioback;
aanispex.userdata=&oggi;
if (SDL_OpenAudio(&aanispex, 0)<0) {
fprintf(stderr, "SDL Audio Error: %s\n", SDL_GetError());
}
const SDL_VideoInfo *info;
info = SDL_GetVideoInfo();
printf("screen: %dx%d\n", info->current_w, info->current_h);
{
int i,n,w,h;
char *p;
for(i=1; i<argc; i++) {
p = argv[i];
while(*p == '-') p++;
if(strcmp(p, "fullscreen") == 0) {
fullscreen=1;
}
if(strcmp(p, "stretch") == 0) {
fullscreen=1;
WIDTH = info->current_w;
HEIGHT = info->current_h;
}
if(strcmp(p, "nofill") == 0) {
fill=0;
}
n = sscanf(p, "%dx%d", &w, &h);
if(n==2) {
WIDTH = w;
HEIGHT = h;
}
}
}
#ifdef OSX
/* On OSX we have two different applets with separate names. The one
ending with 'w' is windowed */
if(argv[0][strlen(argv[0])-1]!='w')
fullscreen=1;
#endif
printf("will display in: %dx%d %s\n", WIDTH, HEIGHT, fullscreen ? "fullscreen" : "windowed");
graffa = malloc(WIDTH*HEIGHT);
if(fullscreen) {
screen=SDL_SetVideoMode(WIDTH, HEIGHT, 8, SDL_SWSURFACE|SDL_FULLSCREEN);//|SDL_DOUBLEBUF);
SDL_ShowCursor(0);
} else {
screen=SDL_SetVideoMode(WIDTH, HEIGHT, 8, SDL_SWSURFACE);//|SDL_DOUBLEBUF);
}
SDL_WM_SetCaption("dose 2 by mfx",NULL);
t=0;
bytesleft=0;
initdemo();
time0=SDL_GetTicks();
SDL_PauseAudio(0);
SDL_EventState(SDL_KEYDOWN, SDL_ENABLE);
SDL_EventState(SDL_QUIT, SDL_ENABLE);
while (!stopnow) {
float aikaero=.02;
SDL_Event eve;
timex=SDL_GetTicks()-time0;
//if (timex> 20*1000)
// stopnow++;
while (SDL_PollEvent(&eve))
{
if (eve.type==SDL_KEYDOWN||eve.type==SDL_QUIT) stopnow++;
#ifdef OSX
/* On Mac it's normal to exit with mouse press */
if(eve.type==SDL_MOUSEBUTTONDOWN) stopnow++;
#endif
}
if (SDL_LockSurface(screen)<0) continue;
mark();
con=1, bri=0;
init_layers((char*)graffa, new_col(0, 0, 0, 0));
memset(graffa, 0, WIDTH*HEIGHT);
{
float f=(timex/1000.0/60.0)*132.3412*4;
rundemo(f);
}
fillcopy(screen, graffa, fill);
{
char *p=teepal1();
static SDL_Color pp[256];
for (i=0; i<256; i++) pp[i].r=p[i*3], pp[i].g=p[i*3+1], pp[i].b=p[i*3+2];
SDL_SetColors(screen, pp, 0, 256); // this force a blit !!
//SDL_SetPalette(screen, SDL_PHYSPAL, pp, 0, 256);
}
SDL_UnlockSurface(screen);
//SDL_Flip(screen);
frames++;
release();
}
printf("fps:%d\n", 1000*frames/timex);
//fclose(fp);
ov_clear(&oggi);
SDL_CloseAudio();
return 0;
}