-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathONScripterLabel_effect.cpp
More file actions
421 lines (370 loc) · 15.7 KB
/
ONScripterLabel_effect.cpp
File metadata and controls
421 lines (370 loc) · 15.7 KB
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/* -*- C++ -*-
*
* ONScripterLabel_effect.cpp - Effect executer of ONScripter
*
* Copyright (c) 2001-2007 Ogapee. All rights reserved.
*
* ogapee@aqua.dti2.ne.jp
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ONScripterLabel.h"
#define EFFECT_STRIPE_WIDTH (16 * screen_ratio1 / screen_ratio2)
#define EFFECT_STRIPE_CURTAIN_WIDTH (24 * screen_ratio1 / screen_ratio2)
#define EFFECT_QUAKE_AMP (12 * screen_ratio1 / screen_ratio2)
int ONScripterLabel::setEffect( EffectLink *effect )
{
if ( effect->effect == 0 ) return RET_CONTINUE;
effect_counter = 0;
event_mode = EFFECT_EVENT_MODE;
advancePhase();
return RET_WAIT | RET_REREAD;
}
int ONScripterLabel::doEffect( EffectLink *effect, AnimationInfo *anim, int effect_image, bool clear_dirty_region )
{
#ifdef INSANI
int prevduration = effect->duration;
if ( ctrl_pressed_status || skip_to_wait ) effect->duration = 1;
#endif
effect_start_time = SDL_GetTicks();
if ( effect_counter == 0 ) effect_start_time_old = effect_start_time - 1;
effect_timer_resolution = effect_start_time - effect_start_time_old;
effect_start_time_old = effect_start_time;
int effect_no = effect->effect;
if ( effect_cut_flag && skip_flag ) effect_no = 1;
if ( effect_counter == 0 ){
SDL_BlitSurface( accumulation_surface, NULL, effect_src_surface, NULL );
switch( effect_image ){
case DIRECT_EFFECT_IMAGE:
break;
case COLOR_EFFECT_IMAGE:
case BG_EFFECT_IMAGE:
case TACHI_EFFECT_IMAGE:
int refresh_mode = refreshMode();
if (effect_no == 1) {
refreshSurface(effect_dst_surface, &dirty_rect.bounding_box,
refresh_mode);
if (refresh_mode & REFRESH_SHADOW_MODE)
refreshSurface(accumulation_comp_surface,
&dirty_rect.bounding_box,
(refresh_mode & ~REFRESH_SHADOW_MODE
& ~REFRESH_TEXT_MODE)
| REFRESH_COMP_MODE);
else
refreshSurface(accumulation_comp_surface,
&dirty_rect.bounding_box,
refresh_mode | refresh_shadow_text_mode
| REFRESH_COMP_MODE);
}
else {
refreshSurface(effect_dst_surface, NULL, refresh_mode);
if (refresh_mode & REFRESH_SHADOW_MODE)
refreshSurface(accumulation_comp_surface, NULL,
(refresh_mode & ~REFRESH_SHADOW_MODE
& ~REFRESH_TEXT_MODE)
| REFRESH_COMP_MODE);
else
refreshSurface(accumulation_comp_surface, NULL,
refresh_mode | refresh_shadow_text_mode
| REFRESH_COMP_MODE);
}
break;
}
/* Load mask image */
if ( effect_no == 15 || effect_no == 18 ){
if ( !effect->anim.image_surface ){
parseTaggedString( &effect->anim );
setupAnimationInfo( &effect->anim );
}
}
if ( effect_no == 11 || effect_no == 12 || effect_no == 13 || effect_no == 14 ||
effect_no == 16 || effect_no == 17 )
dirty_rect.fill( screen_width, screen_height );
}
int i;
int width, width2;
int height, height2;
SDL_Rect src_rect={0, 0, screen_width, screen_height};
SDL_Rect dst_rect={0, 0, screen_width, screen_height};
/* ---------------------------------------- */
/* Execute effect */
//printf("Effect number %d %d\n", effect_no, effect->duration );
switch ( effect_no ){
case 0: // Instant display
case 1: // Instant display
//drawEffect( &src_rect, &src_rect, effect_dst_surface );
break;
case 2: // Left shutter
width = EFFECT_STRIPE_WIDTH * effect_counter / effect->duration;
for ( i=0 ; i<screen_width/EFFECT_STRIPE_WIDTH ; i++ ){
src_rect.x = i * EFFECT_STRIPE_WIDTH;
src_rect.y = 0;
src_rect.w = width;
src_rect.h = screen_height;
drawEffect(&src_rect, &src_rect, effect_dst_surface);
}
break;
case 3: // Right shutter
width = EFFECT_STRIPE_WIDTH * effect_counter / effect->duration;
for ( i=1 ; i<=screen_width/EFFECT_STRIPE_WIDTH ; i++ ){
src_rect.x = i * EFFECT_STRIPE_WIDTH - width - 1;
src_rect.y = 0;
src_rect.w = width;
src_rect.h = screen_height;
drawEffect(&src_rect, &src_rect, effect_dst_surface);
}
break;
case 4: // Top shutter
height = EFFECT_STRIPE_WIDTH * effect_counter / effect->duration;
for ( i=0 ; i<screen_height/EFFECT_STRIPE_WIDTH ; i++ ){
src_rect.x = 0;
src_rect.y = i * EFFECT_STRIPE_WIDTH;
src_rect.w = screen_width;
src_rect.h = height;
drawEffect(&src_rect, &src_rect, effect_dst_surface);
}
break;
case 5: // Bottom shutter
height = EFFECT_STRIPE_WIDTH * effect_counter / effect->duration;
for ( i=1 ; i<=screen_height/EFFECT_STRIPE_WIDTH ; i++ ){
src_rect.x = 0;
src_rect.y = i * EFFECT_STRIPE_WIDTH - height - 1;
src_rect.w = screen_width;
src_rect.h = height;
drawEffect(&src_rect, &src_rect, effect_dst_surface);
}
break;
case 6: // Left curtain
width = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect->duration;
for ( i=0 ; i<=screen_width/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){
width2 = width - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_width;
if ( width2 >= 0 ){
src_rect.x = i * EFFECT_STRIPE_CURTAIN_WIDTH;
src_rect.y = 0;
src_rect.w = width2;
src_rect.h = screen_height;
drawEffect(&src_rect, &src_rect, effect_dst_surface);
}
}
break;
case 7: // Right curtain
width = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect->duration;
for ( i=0 ; i<=screen_width/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){
width2 = width - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_width;
if ( width2 >= 0 ){
if ( width2 > EFFECT_STRIPE_CURTAIN_WIDTH ) width2 = EFFECT_STRIPE_CURTAIN_WIDTH;
src_rect.x = screen_width - i * EFFECT_STRIPE_CURTAIN_WIDTH - width2;
src_rect.y = 0;
src_rect.w = width2;
src_rect.h = screen_height;
drawEffect(&src_rect, &src_rect, effect_dst_surface);
}
}
break;
case 8: // Top curtain
height = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect->duration;
for ( i=0 ; i<=screen_height/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){
height2 = height - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_height;
if ( height2 >= 0 ){
src_rect.x = 0;
src_rect.y = i * EFFECT_STRIPE_CURTAIN_WIDTH;
src_rect.w = screen_width;
src_rect.h = height2;
drawEffect(&src_rect, &src_rect, effect_dst_surface);
}
}
break;
case 9: // Bottom curtain
height = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect->duration;
for ( i=0 ; i<=screen_height/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){
height2 = height - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_height;
if ( height2 >= 0 ){
src_rect.x = 0;
src_rect.y = screen_height - i * EFFECT_STRIPE_CURTAIN_WIDTH - height2;
src_rect.w = screen_width;
src_rect.h = height2;
drawEffect(&src_rect, &src_rect, effect_dst_surface);
}
}
break;
default:
//printf("effect No. %d is not implemented. Crossfade is substituted for that.\n",effect_no);
case 10: // Cross fade
height = 256 * effect_counter / effect->duration;
alphaBlend( NULL, ALPHA_BLEND_CONST, height, &dirty_rect.bounding_box );
break;
case 11: // Left scroll
width = screen_width * effect_counter / effect->duration;
src_rect.x = 0;
dst_rect.x = width;
src_rect.y = dst_rect.y = 0;
src_rect.w = dst_rect.w = screen_width - width;
src_rect.h = dst_rect.h = screen_height;
drawEffect(&dst_rect, &src_rect, effect_src_surface);
src_rect.x = screen_width - width - 1;
dst_rect.x = 0;
src_rect.y = dst_rect.y = 0;
src_rect.w = dst_rect.w = width;
src_rect.h = dst_rect.h = screen_height;
drawEffect(&dst_rect, &src_rect, effect_dst_surface);
break;
case 12: // Right scroll
width = screen_width * effect_counter / effect->duration;
src_rect.x = width;
dst_rect.x = 0;
src_rect.y = dst_rect.y = 0;
src_rect.w = dst_rect.w = screen_width - width;
src_rect.h = dst_rect.h = screen_height;
drawEffect(&dst_rect, &src_rect, effect_src_surface);
src_rect.x = 0;
dst_rect.x = screen_width - width - 1;
src_rect.y = dst_rect.y = 0;
src_rect.w = dst_rect.w = width;
src_rect.h = dst_rect.h = screen_height;
drawEffect(&dst_rect, &src_rect, effect_dst_surface);
break;
case 13: // Top scroll
width = screen_height * effect_counter / effect->duration;
src_rect.x = dst_rect.x = 0;
src_rect.y = 0;
dst_rect.y = width;
src_rect.w = dst_rect.w = screen_width;
src_rect.h = dst_rect.h = screen_height - width;
drawEffect(&dst_rect, &src_rect, effect_src_surface);
src_rect.x = dst_rect.x = 0;
src_rect.y = screen_height - width - 1;
dst_rect.y = 0;
src_rect.w = dst_rect.w = screen_width;
src_rect.h = dst_rect.h = width;
drawEffect(&dst_rect, &src_rect, effect_dst_surface);
break;
case 14: // Bottom scroll
width = screen_height * effect_counter / effect->duration;
src_rect.x = dst_rect.x = 0;
src_rect.y = width;
dst_rect.y = 0;
src_rect.w = dst_rect.w = screen_width;
src_rect.h = dst_rect.h = screen_height - width;
drawEffect(&dst_rect, &src_rect, effect_src_surface);
src_rect.x = dst_rect.x = 0;
src_rect.y = 0;
dst_rect.y = screen_height - width - 1;
src_rect.w = dst_rect.w = screen_width;
src_rect.h = dst_rect.h = width;
drawEffect(&dst_rect, &src_rect, effect_dst_surface);
break;
case 15: // Fade with mask
alphaBlend( effect->anim.image_surface, ALPHA_BLEND_FADE_MASK, 256 * effect_counter / effect->duration, &dirty_rect.bounding_box );
break;
case 16: // Mosaic out
generateMosaic( effect_src_surface, 5 - 6 * effect_counter / effect->duration );
break;
case 17: // Mosaic in
generateMosaic( effect_dst_surface, 6 * effect_counter / effect->duration );
break;
case 18: // Cross fade with mask
alphaBlend( effect->anim.image_surface, ALPHA_BLEND_CROSSFADE_MASK, 256 * effect_counter * 2 / effect->duration, &dirty_rect.bounding_box );
break;
case (CUSTOM_EFFECT_NO + 0 ): // quakey
if ( effect_timer_resolution > effect->duration / 4 / effect->no )
effect_timer_resolution = effect->duration / 4 / effect->no;
dst_rect.x = 0;
dst_rect.y = (Sint16)(sin(M_PI * 2.0 * effect->no * effect_counter / effect->duration) *
EFFECT_QUAKE_AMP * effect->no * (effect->duration - effect_counter) / effect->duration);
SDL_FillRect( accumulation_surface, NULL, SDL_MapRGBA( accumulation_surface->format, 0, 0, 0, 0xff ) );
drawEffect(&dst_rect, &src_rect, effect_dst_surface);
break;
case (CUSTOM_EFFECT_NO + 1 ): // quakex
if ( effect_timer_resolution > effect->duration / 4 / effect->no )
effect_timer_resolution = effect->duration / 4 / effect->no;
dst_rect.x = (Sint16)(sin(M_PI * 2.0 * effect->no * effect_counter / effect->duration) *
EFFECT_QUAKE_AMP * effect->no * (effect->duration - effect_counter) / effect->duration);
dst_rect.y = 0;
drawEffect(&dst_rect, &src_rect, effect_dst_surface);
break;
case (CUSTOM_EFFECT_NO + 2 ): // quake
dst_rect.x = effect->no*((int)(3.0*rand()/(RAND_MAX+1.0)) - 1) * 2;
dst_rect.y = effect->no*((int)(3.0*rand()/(RAND_MAX+1.0)) - 1) * 2;
SDL_FillRect( accumulation_surface, NULL, SDL_MapRGBA( accumulation_surface->format, 0, 0, 0, 0xff ) );
drawEffect(&dst_rect, &src_rect, effect_dst_surface);
break;
}
//printf("effect conut %d / dur %d\n", effect_counter, effect->duration);
effect_counter += effect_timer_resolution;
if ( effect_counter < effect->duration && effect_no != 1 ){
if ( effect_no != 0 ) flush( REFRESH_NONE_MODE, NULL, false );
#ifdef INSANI
effect->duration = prevduration;
#endif
return RET_WAIT | RET_REREAD;
}
else {
SDL_BlitSurface(effect_dst_surface, &dirty_rect.bounding_box,
accumulation_surface, &dirty_rect.bounding_box);
if (effect_no)
flush(REFRESH_NONE_MODE, NULL, clear_dirty_region);
if (effect_no == 1)
effect_counter = 0;
#ifdef INSANI
effect->duration = prevduration;
#endif
event_mode = IDLE_EVENT_MODE;
return RET_CONTINUE;
}
}
void ONScripterLabel::drawEffect(SDL_Rect *dst_rect, SDL_Rect *src_rect, SDL_Surface *surface)
{
SDL_Rect clipped_rect;
if (AnimationInfo::doClipping(dst_rect, &dirty_rect.bounding_box, &clipped_rect)) return;
if (src_rect != dst_rect){
src_rect->x += clipped_rect.x;
src_rect->y += clipped_rect.y;
src_rect->w = clipped_rect.w;
src_rect->h = clipped_rect.h;
}
SDL_BlitSurface(surface, src_rect, accumulation_surface, dst_rect);
}
void ONScripterLabel::generateMosaic( SDL_Surface *src_surface, int level )
{
int i, j, ii, jj;
int width = 160;
for ( i=0 ; i<level ; i++ ) width >>= 1;
#ifdef BPP16
int total_width = accumulation_surface->pitch / 2;
#else
int total_width = accumulation_surface->pitch / 4;
#endif
SDL_LockSurface( src_surface );
SDL_LockSurface( accumulation_surface );
ONSBuf *src_buffer = (ONSBuf *)src_surface->pixels;
for ( i=screen_height-1 ; i>=0 ; i-=width ){
for ( j=0 ; j<screen_width ; j+=width ){
ONSBuf p = src_buffer[ i*total_width+j ];
ONSBuf *dst_buffer = (ONSBuf *)accumulation_surface->pixels + i*total_width + j;
int height2 = width;
if (i+1-width < 0) height2 = i+1;
int width2 = width;
if (j+width > screen_width) width2 = screen_width - j;
for ( ii=0 ; ii<height2 ; ii++ ){
for ( jj=0 ; jj<width2 ; jj++ ){
*dst_buffer++ = p;
}
dst_buffer -= total_width + width2;
}
}
}
SDL_UnlockSurface( accumulation_surface );
SDL_UnlockSurface( src_surface );
}