comparison demo.c @ 3:37b33851cfbb

Joo.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 22 May 2015 01:39:04 +0300
parents 496b9ab9238c
children dcec61df1633
comparison
equal deleted inserted replaced
2:496b9ab9238c 3:37b33851cfbb
94 94
95 static inline float dmQY(DMEngineData *engine, SDL_Surface *img, const float y) 95 static inline float dmQY(DMEngineData *engine, SDL_Surface *img, const float y)
96 { 96 {
97 return engine->optVidNative ? (img->h * y) : (img->h * engine->screen->h * y) / 480.0f; 97 return engine->optVidNative ? (img->h * y) : (img->h * engine->screen->h * y) / 480.0f;
98 } 98 }
99
100
101 typedef struct
102 {
103 char *filename;
104 float xc, yc;
105 SDL_Surface *img;
106 } DMTextItem;
107
108
109 static DMTextItem textItems[] =
110 {
111 { "text01.png", 0.05, 0.10, NULL },
112 { "text02.png", 0.10, 0.30, NULL },
113 { "text03.png", 0.60, 0.30, NULL },
114 { "text04.png", 0.20, 0.60, NULL },
115 { "text05.png", 0.30, 0.70, NULL },
116 };
117
118 static const int ntextItems = sizeof(textItems) / sizeof(textItems[0]);
119
120
121 static DMTextItem textItems2[] =
122 {
123 { "text11.png", 0.05, 0.10, NULL },
124 { "text02.png", 0.30, 0.25, NULL },
125 { "text12.png", 0.10, 0.40, NULL },
126 { "text13.png", 0.20, 0.60, NULL },
127 { "text14.png", 0.30, 0.70, NULL },
128 };
129
130 static const int ntextItems2 = sizeof(textItems2) / sizeof(textItems2[0]);
131
132
133 static DMTextItem textItems3[] =
134 {
135 { "teki.png" , 0.25, 0.20, NULL },
136 { "mitvit.png" , 0.05, 0.40, NULL },
137 { "ja.png" , 0.05, 0.65, NULL },
138 { "kemisti.png", 0.15, 0.65, NULL },
139 };
140
141 static const int ntextItems3 = sizeof(textItems3) / sizeof(textItems3[0]);
142
143
144 99
145 100
146 #define DM_RADIAL_BLUR(YC, XC) \ 101 #define DM_RADIAL_BLUR(YC, XC) \
147 DMVector p1 = { xc, yc, 0, 0 }, p2 = { cx, cy, 0, 0 }, v; \ 102 DMVector p1 = { xc, yc, 0, 0 }, p2 = { cx, cy, 0, 0 }, v; \
148 dm_vector_sub_r(&v, &p2, &p1); \ 103 dm_vector_sub_r(&v, &p2, &p1); \
208 } 163 }
209 } 164 }
210 } 165 }
211 166
212 167
213 static int hitlerText(DMEngineData *engine, const int dt, float fftPow, DMTextItem *items, const int nitems, BOOL *nollattu) 168
214 { 169 static int demoRender(DMEngineData *engine)
215 int i, vis; 170 {
216 if (!(*nollattu)) 171 float t = engineGetTimeDT(engine);
217 {
218 for (i = 0; i < nitems; i++)
219 engineGetResImage(engine, items[i].img, items[i].filename);
220
221 *nollattu = TRUE;
222 }
223 172
224 float q = fftPow * 0.05f; 173
225 vis = dt / 1000; 174 //
226 for (i = 0; i < nitems; i++)
227 {
228 DMTextItem *item = &items[i];
229 if (i < vis)
230 {
231 dmScaledBlitSurface32to32TransparentGA(
232 item->img,
233 dmCX(engine, item->xc - q),
234 dmCY(engine, item->yc - q),
235
236 dmQX(engine, item->img, 1.0f + q * 2.0f),
237 dmQY(engine, item->img, 1.0f + q * 2.0f),
238
239 engine->screen,
240
241 100 + 80 * fftPow);
242 }
243 }
244
245 return DMERR_OK;
246 }
247
248
249 static int demoRender(DMEngineData *engine)
250 {
251 float t = engineGetTimeDT(engine);
252 static DMScaledBlitFunc cblit = NULL;
253
254 // Do FFT 175 // Do FFT
176 //
255 DMFFTType fftPow = 0; 177 DMFFTType fftPow = 0;
256 BOOL fftOK = FALSE; 178 BOOL fftOK = FALSE;
257 static DMFFTType fftAmp[FFT_SIZE / 2]; 179 static DMFFTType fftAmp[FFT_SIZE / 2];
258 static DMFFTType fftData[FFT_SIZE]; 180 static DMFFTType fftData[FFT_SIZE];
259 181
275 { 197 {
276 dmRealFFT(&fft, fftData); 198 dmRealFFT(&fft, fftData);
277 dmConvertFFTtoPowerAndSum(&fft, fftData, fftAmp, 1.0, &fftPow, 0.00004f); 199 dmConvertFFTtoPowerAndSum(&fft, fftData, fftAmp, 1.0, &fftPow, 0.00004f);
278 } 200 }
279 201
280 // Demokoodi 202
281 if (t < 5) 203 //
282 { 204 // Taustaskrolli
283 // Alkufeidi sisään 205 //
284 int dt = engineGetTime(engine, 0); 206 {
207 static SDL_Surface *tausta = NULL,
208 *aurinko = NULL,
209 *puu1 = NULL,
210 *puu2 = NULL,
211 *bussi = NULL,
212 *rengas = NULL;
213
214 static DMScaledBlitFunc cblit = NULL, ablit = NULL;
215 static BOOL nollattu = FALSE;
216 static DMLerpContext fadeLerp, fadeLerp2, fadeLerp3;
217
218 if (!nollattu)
219 {
220 dmLerpInit(&fadeLerp, 0, 255, 3000);
221 dmLerpInit(&fadeLerp2, 0, 255, 4000);
222 dmLerpInit(&fadeLerp3, 0, 1.2, 3000);
223 engineGetResImage(engine, tausta, "tausta_pv.png");
224 engineGetResImage(engine, aurinko, "aurinko.png");
225 engineGetResImage(engine, puu1, "puu_pv_1.png");
226 engineGetResImage(engine, puu2, "puu_pv_2.png");
227 engineGetResImage(engine, bussi, "auto.png");
228 engineGetResImage(engine, rengas, "rengas.png");
229 cblit = dmGetScaledBlitFunc(tausta->format, engine->screen->format, DMD_NONE);
230 ablit = dmGetScaledBlitFunc(bussi->format, engine->screen->format, DMD_TRANSPARENT);
231 }
232
233 int x1 = - ((int)dmQX(engine, tausta, t * 0.2) % tausta->w),
234 x2 = x1 + tausta->w;
235
236 int fadeVal;
237 if (t < 3 || t > 64)
238 {
239 if (t < 3)
240 fadeVal = dmLerpSCurveClamp(&fadeLerp, engineGetTime(engine, 0));
241 else
242 fadeVal = dmLerpSCurveClamp(&fadeLerp2, engineGetTime(engine, 64));
243
244 dmClearSurface(engine->screen, dmMapRGB(engine->screen, 0,0,0));
245 dmScaledBlitSurface32to32TransparentGA(tausta, x1, 0, tausta->w, tausta->h, engine->screen, fadeVal);
246 dmScaledBlitSurface32to32TransparentGA(tausta, x2, 0, tausta->w, tausta->h, engine->screen, fadeVal);
247 }
248 else
249 {
250 fadeVal = 255;
251 cblit(tausta, x1, 0, tausta->w, tausta->h, engine->screen);
252 cblit(tausta, x2, 0, tausta->w, tausta->h, engine->screen);
253 }
254
255 float qm = sin(t * 0.1 + fftPow * 5) * 15, qm2 = qm*2;
256 dmScaledBlitSurface32to32TransparentGA(aurinko,
257 dmCX(engine, 0.8 - dmLerpSCurveClamp(&fadeLerp3, engineGetTime(engine, 0) * 0.01) * 0.3 ) - qm,
258 dmCY(engine, 0.05) - qm,
259 aurinko->w + qm2, aurinko->h + qm2,
260 engine->screen, fadeVal);
261
262
263 // Bussi ajaa sisään
264 if (t > 4)
265 {
266 float
267 dt = engineGetTime(engine, 4),
268 ajelu = dmLerpSCurveClamp(&fadeLerp3, dt),
269 xc = dmCX(engine, -1 + ajelu),
270 yc = dmCY(engine, 0.35 + sin(t * 10) * 0.005),
271 yc2 = yc + dmQY(engine, bussi, 0.7) + dmCY(engine, sin(t * 20) * 0.001);
272
273 ablit(rengas, xc + dmQX(engine, bussi, 0.07), yc2, dmQX(engine, rengas, 1), dmQY(engine, rengas, 1), engine->screen);
274 ablit(rengas, xc + dmQX(engine, bussi, 0.80), yc2, dmQX(engine, rengas, 1), dmQY(engine, rengas, 1), engine->screen);
275 ablit(bussi, xc, yc, dmQX(engine, bussi, 1), dmQY(engine, bussi, 1), engine->screen);
276 }
277 }
278
279 //
280 // AP logo
281 //
282 if (t > 4 && t < 8)
283 {
284 int dt = engineGetTime(engine, 4);
285 static DMLerpContext fadeLerp; 285 static DMLerpContext fadeLerp;
286 static SDL_Surface *tausta = NULL; 286 static SDL_Surface *logo = NULL;
287 static BOOL nollattu = FALSE; 287 static BOOL nollattu = FALSE;
288 if (!nollattu) 288 if (!nollattu)
289 { 289 {
290 engineGetResImage(engine, tausta, "tausta_pv.png"); 290 dmLerpInit(&fadeLerp, 0, 255, 1000);
291 cblit = dmGetScaledBlitFunc(tausta->format, engine->screen->format, DMD_NONE); 291 engineGetResImage(engine, logo, "ap.png");
292
293 dmLerpInit(&fadeLerp, 0, 255, 5000);
294 nollattu = TRUE; 292 nollattu = TRUE;
295 } 293 }
296 294
297 dmClearSurface(engine->screen, dmMapRGB(engine->screen, 0,0,0)); 295 int fadeVal;
298 296 if (dt < 1000)
299 dmScaledBlitSurface32to32TransparentGA(tausta, 297 fadeVal = dmLerpSCurveClamp(&fadeLerp, dt);
300 0, 298 else
301 0, 299 if (dt > 3000)
302 300 fadeVal = 255 - dmLerpSCurveClamp(&fadeLerp, dt - 3000);
301 else
302 fadeVal = 255;
303
304 dmScaledBlitSurface32to32TransparentGA(logo,
305 dmQX(engine, logo, 0.2),
306 dmQY(engine, logo, 0.3),
307 dmQX(engine, logo, 1),
308 dmQY(engine, logo, 1),
309 engine->screen, fadeVal);
310 }
311
312 //
313 // BUSSI logo
314 //
315 if (t > 10 && t < 14)
316 {
317 int dt = engineGetTime(engine, 10);
318 static DMLerpContext fadeLerp;
319 static SDL_Surface *logo = NULL, *logo2 = NULL;
320 static BOOL nollattu = FALSE;
321 if (!nollattu)
322 {
323 dmLerpInit(&fadeLerp, 0, 255, 1000);
324 engineGetResImage(engine, logo, "bussi_logo.png");
325 engineGetResImage(engine, logo2, "dosa.png");
326 nollattu = TRUE;
327 }
328
329 int fadeVal, fadeVal2;
330 if (dt < 1000)
331 fadeVal = dmLerpSCurveClamp(&fadeLerp, dt);
332 else
333 if (dt > 3000)
334 fadeVal = 255 - dmLerpSCurveClamp(&fadeLerp, dt - 3000);
335 else
336 fadeVal = 255;
337
338 if (dt > 1000)
339 {
340 if (dt < 2000)
341 fadeVal2 = dmLerpSCurveClamp(&fadeLerp, dt - 1000);
342 else
343 if (dt > 3000)
344 fadeVal2 = 255 - dmLerpSCurveClamp(&fadeLerp, dt - 3000);
345 else
346 fadeVal2 = 255;
347 }
348 else
349 fadeVal2 = 0;
350
351 dmScaledBlitSurface32to32TransparentGA(logo,
352 dmCX(engine, 0.10),
353 dmCY(engine, 0.2),
354 dmQX(engine, logo, 1),
355 dmQY(engine, logo, 1),
356 engine->screen, fadeVal);
357
358 dmScaledBlitSurface32to32TransparentGA(logo2,
359 dmCX(engine, 0.6),
360 dmCY(engine, 0.6),
361 dmQX(engine, logo2, 1),
362 dmQY(engine, logo2, 1),
363 engine->screen, fadeVal2);
364 }
365
366
367 {
368 static DMScaledBlitFunc cblit = NULL;
369 static SDL_Surface *maski = NULL;
370 static BOOL nollattu = FALSE;
371
372 if (!nollattu)
373 {
374 engineGetResImage(engine, maski, "maze.png");
375 cblit = dmGetScaledBlitFunc(maski->format, engine->screen->format, DMD_TRANSPARENT);
376 }
377
378 cblit(maski,
379 0, 0,
380 dmQX(engine, maski, 1),
381 dmQY(engine, maski, 1),
382 engine->screen);
383 }
303 384
304 return DMERR_OK; 385 return DMERR_OK;
305 } 386 }