0
|
1 #include "dmengine.h"
|
|
2 #include "dmtext.h"
|
|
3 #include "dmfft.h"
|
|
4 #include "dmvecmat.h"
|
|
5 #include <math.h>
|
|
6
|
|
7 static int demoInit(DMEngineData *engine);
|
|
8 static void demoShutdown(DMEngineData *engine);
|
|
9 static int demoRender(DMEngineData *engine);
|
|
10
|
|
11
|
|
12 int demoPreInit(DMEngineData *engine)
|
|
13 {
|
|
14 dmInitProg("bussi",
|
2
|
15 "Bussi by AnCiat ProDucTionz",
|
0
|
16 "0", "ENGINE INITTIALISSSIZING!!!!!", NULL);
|
|
17
|
|
18 engine->optPackFilename = "bussi.dat";
|
|
19 engine->optDataPath = NULL;
|
|
20 engine->optResFlags = DRF_USE_PACK | DRF_PRELOAD_RES | DRF_USE_STDIO;
|
|
21
|
|
22 engine->optAudioSetup = DM_ASETUP_JSS;
|
|
23
|
|
24 engine->optVidSetup = DM_VSETUP_ASPECT;
|
|
25 engine->optVidWidth = 640;
|
|
26 engine->optVidHeight = 480;
|
|
27 engine->optVidDepth = 32;
|
|
28 engine->optVFlags = SDL_SWSURFACE;
|
|
29
|
|
30 engine->demoInit = demoInit;
|
|
31 engine->demoRender = demoRender;
|
|
32 engine->demoShutdown = demoShutdown;
|
|
33
|
|
34 return DMERR_OK;
|
|
35 }
|
|
36
|
|
37
|
|
38 #define FFT_SIZE 128
|
|
39 DMFFTContext fft;
|
5
|
40 DMResource *teksti = NULL;
|
|
41 DMBitmapFont *font = NULL;
|
|
42
|
|
43 typedef struct
|
|
44 {
|
|
45 int layer;
|
|
46 char *filename;
|
|
47 SDL_Surface *img;
|
|
48 } DMItemDef;
|
|
49
|
|
50
|
|
51 DMItemDef items[] =
|
|
52 {
|
|
53 { 1, "viitta.png", NULL },
|
|
54 { 1, "puu_pv_1.png", NULL },
|
|
55 { 0, "puu_pv_2.png", NULL },
|
|
56 };
|
|
57
|
|
58 static const int nitems = sizeof(items) / sizeof(items[0]);
|
|
59
|
|
60
|
0
|
61
|
|
62
|
|
63 static int demoInit(DMEngineData *engine)
|
|
64 {
|
|
65 int i;
|
|
66 JSSModule *mod = NULL;
|
5
|
67 SDL_Color pal[DMFONT_NPALETTE];
|
|
68 DMResource *tmp;
|
0
|
69
|
5
|
70 // FFT init
|
0
|
71 dmInitializeFFT(&fft, FFT_SIZE);
|
|
72
|
5
|
73 // Skrolliteksti
|
|
74 if ((teksti = engineFindResource(engine, "skrolli.txt")) == NULL)
|
|
75 return DMERR_INIT_FAIL;
|
|
76
|
|
77 // Skrollerin fontti
|
|
78 if ((tmp = engineFindResource(engine, "fontti.dmf")) == NULL)
|
|
79 return DMERR_INIT_FAIL;
|
|
80
|
|
81 if ((i = dmLoadBitmapFont(tmp, &font)) != DMERR_OK)
|
|
82 return i;
|
|
83
|
|
84 for (i = 0; i < DMFONT_NPALETTE; i++)
|
|
85 {
|
|
86 pal[i].r = pal[i].g = pal[i].b = i * 8;
|
|
87 pal[i].unused = i > 0 ? 255 : 0;
|
|
88 }
|
|
89
|
|
90 dmSetBitmapFontPalette(font, pal, 0, DMFONT_NPALETTE);
|
|
91
|
|
92 // Musa
|
0
|
93 engineGetResModule(engine, mod, "pas2.xm");
|
|
94
|
|
95 if ((i = jssConvertModuleForPlaying(mod)) != DMERR_OK)
|
|
96 {
|
|
97 dmErrorMsg("Could not convert module for playing, %d: %s\n",
|
|
98 i, dmErrorStr(i));
|
|
99 return DMERR_INIT_FAIL;
|
|
100 }
|
|
101
|
|
102 jvmSetCallback(engine->jssDev, jmpExec, engine->jssPlr);
|
|
103 jmpSetModule(engine->jssPlr, mod);
|
|
104 jmpPlayOrder(engine->jssPlr, 0);
|
|
105 jvmSetGlobalVol(engine->jssDev, 55);
|
|
106
|
5
|
107
|
|
108 // Osa kuvadatasta
|
|
109 for (i = 0; i < nitems; i++)
|
|
110 engineGetResImage(engine, items[i].img, items[i].filename);
|
|
111
|
0
|
112 // Jne
|
|
113 srand(15);
|
|
114
|
|
115 return DMERR_OK;
|
|
116 }
|
|
117
|
|
118
|
|
119 static void demoShutdown(DMEngineData *engine)
|
|
120 {
|
|
121 (void) engine;
|
|
122 dmEndFFT(&fft);
|
5
|
123 dmFreeBitmapFont(font);
|
0
|
124 }
|
|
125
|
|
126
|
|
127 static inline float dmCX(DMEngineData *engine, const float x)
|
|
128 {
|
|
129 return (x * engine->screen->w);
|
|
130 }
|
|
131
|
|
132
|
|
133 static inline float dmCY(DMEngineData *engine, const float y)
|
|
134 {
|
|
135 return (y * engine->screen->h);
|
|
136 }
|
|
137
|
|
138
|
|
139 static inline float dmQX(DMEngineData *engine, SDL_Surface *img, const float x)
|
|
140 {
|
|
141 return engine->optVidNative ? (img->w * x) : (img->w * engine->screen->w * x) / 640.0f;
|
|
142 }
|
|
143
|
|
144
|
|
145 static inline float dmQY(DMEngineData *engine, SDL_Surface *img, const float y)
|
|
146 {
|
|
147 return engine->optVidNative ? (img->h * y) : (img->h * engine->screen->h * y) / 480.0f;
|
|
148 }
|
|
149
|
|
150
|
|
151 #define DM_RADIAL_BLUR(YC, XC) \
|
|
152 DMVector p1 = { xc, yc, 0, 0 }, p2 = { cx, cy, 0, 0 }, v; \
|
|
153 dm_vector_sub_r(&v, &p2, &p1); \
|
|
154 dm_vector_scale(&v, scale); \
|
|
155 dm_vector_add(&v, &p1); \
|
|
156 if (v.y YC || v.x XC) continue; \
|
|
157 DMColor *dp = pix + xc, \
|
|
158 *q = ((DMColor *)img->pixels) + ((int)(v.y) * pitch) + (int)v.x; \
|
|
159 dp->r = (q->r + dp->r) / 2; \
|
|
160 dp->g = (q->g + dp->g) / 2; \
|
|
161 dp->b = (q->b + dp->b) / 2;
|
|
162
|
|
163
|
|
164
|
|
165 void dmRadialBlur(SDL_Surface *img, const int cx, const int cy, const DMFloat scale)
|
|
166 {
|
|
167 const int pitch = img->pitch / sizeof(DMColor);
|
|
168 int xc, yc;
|
|
169
|
|
170 #pragma omp parallel private(yc, xc) shared(img)
|
|
171 {
|
|
172 #pragma omp sections nowait
|
|
173 {
|
|
174 #pragma omp section
|
|
175 for (yc = cy; yc >= 0; yc--)
|
|
176 {
|
|
177 DMColor *pix = ((DMColor *)img->pixels) + yc * pitch;
|
|
178 for (xc = cx + 1; xc < img->w; xc++)
|
|
179 {
|
|
180 DM_RADIAL_BLUR(< 0, >= img->w)
|
|
181 }
|
|
182 }
|
|
183
|
|
184 #pragma omp section
|
|
185 for (yc = cy; yc >= 0; yc--)
|
|
186 {
|
|
187 DMColor *pix = ((DMColor *)img->pixels) + yc * pitch;
|
|
188 for (xc = cx; xc > 0; xc--)
|
|
189 {
|
|
190 DM_RADIAL_BLUR(< 0, < 0)
|
|
191 }
|
|
192 }
|
|
193
|
|
194 #pragma omp section
|
|
195 for (yc = cy + 1; yc < img->h; yc++)
|
|
196 {
|
|
197 DMColor *pix = ((DMColor *)img->pixels) + yc * pitch;
|
|
198 for (xc = cx; xc > 0; xc--)
|
|
199 {
|
|
200 DM_RADIAL_BLUR(>= img->h, < 0)
|
|
201 }
|
|
202 }
|
|
203
|
|
204 #pragma omp section
|
|
205 for (yc = cy + 1; yc < img->h; yc++)
|
|
206 {
|
|
207 DMColor *pix = ((DMColor *)img->pixels) + yc * pitch;
|
|
208 for (xc = cx + 1; xc < img->w; xc++)
|
|
209 {
|
|
210 DM_RADIAL_BLUR(>= img->h, >= img->w)
|
|
211 }
|
|
212 }
|
|
213 }
|
|
214 }
|
|
215 }
|
|
216
|
|
217
|
|
218 static int demoRender(DMEngineData *engine)
|
|
219 {
|
|
220 float t = engineGetTimeDT(engine);
|
|
221
|
3
|
222 //
|
0
|
223 // Do FFT
|
3
|
224 //
|
0
|
225 DMFFTType fftPow = 0;
|
|
226 BOOL fftOK = FALSE;
|
|
227 static DMFFTType fftAmp[FFT_SIZE / 2];
|
|
228 static DMFFTType fftData[FFT_SIZE];
|
|
229
|
|
230 dmMutexLock(engine->audioStreamMutex);
|
|
231 if (engine->audioStreamBuf != 0 && engine->audioStreamLen > FFT_SIZE)
|
|
232 {
|
|
233 int i;
|
|
234 Sint16 *buf = (Sint16 *) engine->audioStreamBuf;
|
|
235 for (i = 0; i < FFT_SIZE; i++)
|
|
236 {
|
|
237 fftData[i] = *buf;
|
|
238 buf += 2;
|
|
239 }
|
|
240 fftOK = TRUE;
|
|
241 }
|
|
242 dmMutexUnlock(engine->audioStreamMutex);
|
|
243
|
|
244 if (fftOK)
|
|
245 {
|
|
246 dmRealFFT(&fft, fftData);
|
|
247 dmConvertFFTtoPowerAndSum(&fft, fftData, fftAmp, 1.0, &fftPow, 0.00004f);
|
|
248 }
|
|
249
|
3
|
250
|
|
251 //
|
|
252 // Taustaskrolli
|
|
253 //
|
0
|
254 {
|
3
|
255 static SDL_Surface *tausta = NULL,
|
|
256 *aurinko = NULL,
|
|
257 *bussi = NULL,
|
|
258 *rengas = NULL;
|
|
259
|
|
260 static DMScaledBlitFunc cblit = NULL, ablit = NULL;
|
|
261 static BOOL nollattu = FALSE;
|
|
262 static DMLerpContext fadeLerp, fadeLerp2, fadeLerp3;
|
|
263
|
|
264 if (!nollattu)
|
|
265 {
|
|
266 dmLerpInit(&fadeLerp, 0, 255, 3000);
|
|
267 dmLerpInit(&fadeLerp2, 0, 255, 4000);
|
|
268 dmLerpInit(&fadeLerp3, 0, 1.2, 3000);
|
|
269 engineGetResImage(engine, tausta, "tausta_pv.png");
|
|
270 engineGetResImage(engine, aurinko, "aurinko.png");
|
|
271 engineGetResImage(engine, bussi, "auto.png");
|
|
272 engineGetResImage(engine, rengas, "rengas.png");
|
|
273 cblit = dmGetScaledBlitFunc(tausta->format, engine->screen->format, DMD_NONE);
|
|
274 ablit = dmGetScaledBlitFunc(bussi->format, engine->screen->format, DMD_TRANSPARENT);
|
|
275 }
|
|
276
|
|
277 int x1 = - ((int)dmQX(engine, tausta, t * 0.2) % tausta->w),
|
|
278 x2 = x1 + tausta->w;
|
|
279
|
|
280 int fadeVal;
|
|
281 if (t < 3 || t > 64)
|
|
282 {
|
|
283 if (t < 3)
|
|
284 fadeVal = dmLerpSCurveClamp(&fadeLerp, engineGetTime(engine, 0));
|
|
285 else
|
|
286 fadeVal = dmLerpSCurveClamp(&fadeLerp2, engineGetTime(engine, 64));
|
|
287
|
|
288 dmClearSurface(engine->screen, dmMapRGB(engine->screen, 0,0,0));
|
|
289 dmScaledBlitSurface32to32TransparentGA(tausta, x1, 0, tausta->w, tausta->h, engine->screen, fadeVal);
|
|
290 dmScaledBlitSurface32to32TransparentGA(tausta, x2, 0, tausta->w, tausta->h, engine->screen, fadeVal);
|
|
291 }
|
|
292 else
|
|
293 {
|
|
294 fadeVal = 255;
|
|
295 cblit(tausta, x1, 0, tausta->w, tausta->h, engine->screen);
|
|
296 cblit(tausta, x2, 0, tausta->w, tausta->h, engine->screen);
|
|
297 }
|
|
298
|
|
299 float qm = sin(t * 0.1 + fftPow * 5) * 15, qm2 = qm*2;
|
|
300 dmScaledBlitSurface32to32TransparentGA(aurinko,
|
|
301 dmCX(engine, 0.8 - dmLerpSCurveClamp(&fadeLerp3, engineGetTime(engine, 0) * 0.01) * 0.3 ) - qm,
|
|
302 dmCY(engine, 0.05) - qm,
|
|
303 aurinko->w + qm2, aurinko->h + qm2,
|
|
304 engine->screen, fadeVal);
|
|
305
|
|
306
|
|
307 // Bussi ajaa sisään
|
5
|
308 if (t > 14)
|
3
|
309 {
|
|
310 float
|
5
|
311 dt = engineGetTime(engine, 14),
|
3
|
312 ajelu = dmLerpSCurveClamp(&fadeLerp3, dt),
|
|
313 xc = dmCX(engine, -1 + ajelu),
|
|
314 yc = dmCY(engine, 0.35 + sin(t * 10) * 0.005),
|
|
315 yc2 = yc + dmQY(engine, bussi, 0.7) + dmCY(engine, sin(t * 20) * 0.001);
|
|
316
|
|
317 ablit(rengas, xc + dmQX(engine, bussi, 0.07), yc2, dmQX(engine, rengas, 1), dmQY(engine, rengas, 1), engine->screen);
|
|
318 ablit(rengas, xc + dmQX(engine, bussi, 0.80), yc2, dmQX(engine, rengas, 1), dmQY(engine, rengas, 1), engine->screen);
|
|
319 ablit(bussi, xc, yc, dmQX(engine, bussi, 1), dmQY(engine, bussi, 1), engine->screen);
|
|
320 }
|
5
|
321
|
|
322
|
|
323 // Puut ym. liikennejutut
|
|
324 if (t > 10)
|
|
325 {
|
|
326 }
|
3
|
327 }
|
|
328
|
|
329 //
|
|
330 // AP logo
|
|
331 //
|
|
332 if (t > 4 && t < 8)
|
|
333 {
|
|
334 int dt = engineGetTime(engine, 4);
|
0
|
335 static DMLerpContext fadeLerp;
|
3
|
336 static SDL_Surface *logo = NULL;
|
0
|
337 static BOOL nollattu = FALSE;
|
|
338 if (!nollattu)
|
|
339 {
|
3
|
340 dmLerpInit(&fadeLerp, 0, 255, 1000);
|
|
341 engineGetResImage(engine, logo, "ap.png");
|
|
342 nollattu = TRUE;
|
|
343 }
|
|
344
|
|
345 int fadeVal;
|
|
346 if (dt < 1000)
|
|
347 fadeVal = dmLerpSCurveClamp(&fadeLerp, dt);
|
|
348 else
|
|
349 if (dt > 3000)
|
|
350 fadeVal = 255 - dmLerpSCurveClamp(&fadeLerp, dt - 3000);
|
|
351 else
|
|
352 fadeVal = 255;
|
0
|
353
|
3
|
354 dmScaledBlitSurface32to32TransparentGA(logo,
|
|
355 dmQX(engine, logo, 0.2),
|
|
356 dmQY(engine, logo, 0.3),
|
|
357 dmQX(engine, logo, 1),
|
|
358 dmQY(engine, logo, 1),
|
|
359 engine->screen, fadeVal);
|
|
360 }
|
|
361
|
|
362 //
|
|
363 // BUSSI logo
|
|
364 //
|
|
365 if (t > 10 && t < 14)
|
|
366 {
|
|
367 int dt = engineGetTime(engine, 10);
|
|
368 static DMLerpContext fadeLerp;
|
|
369 static SDL_Surface *logo = NULL, *logo2 = NULL;
|
|
370 static BOOL nollattu = FALSE;
|
|
371 if (!nollattu)
|
|
372 {
|
|
373 dmLerpInit(&fadeLerp, 0, 255, 1000);
|
|
374 engineGetResImage(engine, logo, "bussi_logo.png");
|
|
375 engineGetResImage(engine, logo2, "dosa.png");
|
0
|
376 nollattu = TRUE;
|
|
377 }
|
|
378
|
3
|
379 int fadeVal, fadeVal2;
|
|
380 if (dt < 1000)
|
|
381 fadeVal = dmLerpSCurveClamp(&fadeLerp, dt);
|
|
382 else
|
|
383 if (dt > 3000)
|
|
384 fadeVal = 255 - dmLerpSCurveClamp(&fadeLerp, dt - 3000);
|
|
385 else
|
|
386 fadeVal = 255;
|
|
387
|
|
388 if (dt > 1000)
|
|
389 {
|
|
390 if (dt < 2000)
|
|
391 fadeVal2 = dmLerpSCurveClamp(&fadeLerp, dt - 1000);
|
|
392 else
|
|
393 if (dt > 3000)
|
|
394 fadeVal2 = 255 - dmLerpSCurveClamp(&fadeLerp, dt - 3000);
|
|
395 else
|
|
396 fadeVal2 = 255;
|
|
397 }
|
|
398 else
|
|
399 fadeVal2 = 0;
|
0
|
400
|
3
|
401 dmScaledBlitSurface32to32TransparentGA(logo,
|
|
402 dmCX(engine, 0.10),
|
|
403 dmCY(engine, 0.2),
|
|
404 dmQX(engine, logo, 1),
|
|
405 dmQY(engine, logo, 1),
|
|
406 engine->screen, fadeVal);
|
|
407
|
|
408 dmScaledBlitSurface32to32TransparentGA(logo2,
|
|
409 dmCX(engine, 0.6),
|
|
410 dmCY(engine, 0.6),
|
|
411 dmQX(engine, logo2, 1),
|
|
412 dmQY(engine, logo2, 1),
|
|
413 engine->screen, fadeVal2);
|
|
414 }
|
|
415
|
0
|
416
|
3
|
417 {
|
|
418 static DMScaledBlitFunc cblit = NULL;
|
|
419 static SDL_Surface *maski = NULL;
|
|
420 static BOOL nollattu = FALSE;
|
|
421
|
|
422 if (!nollattu)
|
|
423 {
|
5
|
424 engineGetResImage(engine, maski, "maski.png");
|
3
|
425 cblit = dmGetScaledBlitFunc(maski->format, engine->screen->format, DMD_TRANSPARENT);
|
|
426 }
|
|
427
|
|
428 cblit(maski,
|
|
429 0, 0,
|
|
430 dmQX(engine, maski, 1),
|
|
431 dmQY(engine, maski, 1),
|
|
432 engine->screen);
|
|
433 }
|
0
|
434
|
5
|
435 if (t > 70)
|
|
436 return 1;
|
|
437 else
|
|
438 return DMERR_OK;
|
0
|
439 }
|