sdl_effect: Implement NACT_EFFECT_WIPE_*

This commit is contained in:
kichikuou
2022-02-06 12:26:50 +09:00
parent 63c456329f
commit 1c3dccb349
3 changed files with 130 additions and 188 deletions
+15 -188
View File
@@ -176,38 +176,6 @@ static int eCopyArea6(int dx, int dy, int w, int h, int opt) {
return key;
}
#define E7_8X 24
static int eCopyArea7(int dx, int dy, int w, int h, int opt) {
int i, key = 0, cnt;
int waitcnt = opt == 0 ? 40 : opt;
cnt = sdl_getTicks();
for (i = 0; i < (w/2 - E7_8X+1); i+=E7_8X) {
cnt += waitcnt;
eCopyUpdateArea(dx, dy+i*h/w, w, E7_8X*h/w, dx, dy+i*h/w);
eCopyUpdateArea(dx, dy+(h-(i+E7_8X)*h/w), w, E7_8X*h/w, dx, dy+(h-(i+E7_8X)*h/w));
eCopyUpdateArea(dx+i, dy, E7_8X, h, dx+i, dy);
eCopyUpdateArea(dx+(w-i-E7_8X), dy, E7_8X, h, dx+(w-i-E7_8X), dy);
EC_WAIT;
}
eCopyUpdateArea(dx, dy, w, h, dx, dy);
return key;
}
static int eCopyArea8(int dx, int dy, int w, int h, int opt) {
int i, key = 0, cnt;
int waitcnt = opt == 0 ? 40 : opt;
cnt = sdl_getTicks();
for (i = E7_8X; i < (w/2 -E7_8X+1); i+=E7_8X) {
cnt += waitcnt;
eCopyUpdateArea(dx+ w/2 - i , dy + h/2 - i*h/w, 2*i, 2*i*h/w ,dx+ w/2-i, dy + h/2 - i*h/w);
EC_WAIT;
}
eCopyUpdateArea(dx, dy, w, h, dx, dy);
return key;
}
static int eCopyArea9(int sx, int sy, int w, int h, int dx, int dy, int opt) {
int i, x, y, key = 0, cnt;
int waitcnt = opt == 0 ? 80 : opt;
@@ -231,62 +199,6 @@ static int eCopyArea9(int sx, int sy, int w, int h, int dx, int dy, int opt) {
return key;
}
static int eCopyArea12(int dx, int dy, int w, int h, int opt) {
int x, key = 0, cnt;
int waitcnt = opt == 0 ? 20 : opt;
cnt = sdl_getTicks();
for (x = 0; x < (w -7); x += 8) {
cnt += waitcnt;
eCopyUpdateArea(dx + x, dy, 8, h, dx + x, dy);
EC_WAIT;
}
eCopyUpdateArea(dx, dy, w, h, dx, dy);
return key;
}
static int eCopyArea13(int dx, int dy, int w, int h, int opt) {
int x, key = 0, cnt;
int waitcnt = opt == 0 ? 20 : opt;
cnt = sdl_getTicks();
for (x = (w -8); x > 8; x -= 8) {
cnt +=waitcnt;
eCopyUpdateArea(dx + x, dy, 8, h, dx + x, dy);
EC_WAIT;
}
eCopyUpdateArea(dx, dy, w, h, dx, dy);
return key;
}
static int eCopyArea14(int dx, int dy, int w, int h, int opt) {
int y, key = 0, cnt;
int waitcnt = opt == 0 ? 20 : opt;
cnt = sdl_getTicks();
for (y = 0; y < (h -7); y += 8) {
cnt += waitcnt;
eCopyUpdateArea(dx, dy + y, w, 8, dx, dy + y);
EC_WAIT;
}
eCopyUpdateArea(dx, dy, w, h, dx, dy);
return key;
}
static int eCopyArea15(int dx, int dy, int w, int h, int opt) {
int y, key = 0, cnt;
int waitcnt = opt == 0 ? 20 : opt;
cnt = sdl_getTicks();
for (y = (h -8); y > 8; y -= 8) {
cnt += waitcnt;
eCopyUpdateArea(dx, dy + y, w, 8, dx, dy + y);
EC_WAIT;
}
eCopyUpdateArea(dx, dy, w, h, dx, dy);
return key;
}
static int eCopyArea16(int dx, int dy, int w, int h, int opt) {
int i, x, key = 0, cnt;
int waitcnt = opt == 0 ? 30 : opt;
@@ -321,66 +233,6 @@ static int eCopyArea17(int dx, int dy, int w, int h, int opt) {
return key;
}
static int eCopyArea18(int dx, int dy, int w, int h, int opt) {
int x, key = 0, cnt;
int waitcnt = opt == 0 ? 30 : opt;
cnt = sdl_getTicks();
for (x = 0; x < (w/2 -7); x += 8) {
cnt += waitcnt;
eCopyUpdateArea(dx + w/2 - x - 8, dy, 8, h, dx + w/2 - x - 8, dy);
eCopyUpdateArea(dx + w/2 + x , dy, 8, h, dx + w/2 + x , dy);
EC_WAIT;
}
eCopyUpdateArea(dx, dy, w, h, dx, dy);
return key;
}
static int eCopyArea19(int dx, int dy, int w, int h, int opt) {
int x, key = 0, cnt;
int waitcnt = opt == 0 ? 30 : opt;
cnt = sdl_getTicks();
for (x = 0; x < (w/2 -7); x += 8) {
cnt += waitcnt;
eCopyUpdateArea(dx + x, dy, 8, h, dx + x, dy);
eCopyUpdateArea(dx + w - x - 8, dy, 8, h, dx + w - x - 8, dy);
EC_WAIT;
}
eCopyUpdateArea(dx, dy, w, h, dx, dy);
return key;
}
static int eCopyArea20(int dx, int dy, int w, int h, int opt) {
int y, key = 0, cnt;
int waitcnt = opt == 0 ? 30 : opt;
cnt = sdl_getTicks();
for (y = 0; y < (h/2 -7); y += 8) {
cnt += waitcnt;
eCopyUpdateArea(dx, dy + h/2 - y - 8, w, 8, dx, dy + h/2 - y - 8);
eCopyUpdateArea(dx, dy + h/2 + y , w, 8, dx, dy + h/2 + y );
EC_WAIT;
}
eCopyUpdateArea(dx, dy, w, h, dx, dy);
return key;
}
static int eCopyArea21(int dx, int dy, int w, int h, int opt) {
int y, key = 0, cnt;
int waitcnt = opt == 0 ? 30 : opt;
cnt = sdl_getTicks();
for (y = 0; y < (h/2 -7); y += 8) {
cnt += waitcnt;
eCopyUpdateArea(dx, dy + y , w, 8, dx, dy + y);
eCopyUpdateArea(dx, dy + h - y - 8, w, 8, dx, dy + h - y - 8);
EC_WAIT;
}
eCopyUpdateArea(dx, dy, w, h, dx, dy);
return key;
}
static int eCopyArea22(int sx, int sy, int w, int h, int dx, int dy, int opt) {
int i, x, y, key = 0, cnt;
int waitcnt = opt == 0 ? 80 : opt;
@@ -588,6 +440,21 @@ static int duration(enum nact_effect effect, int opt, SDL_Rect *rect) {
case NACT_EFFECT_BLIND_LR:
case NACT_EFFECT_BLIND_RL:
return (opt ? opt : 40) * (rect->w / 16 + 16);
case NACT_EFFECT_WIPE_IN:
case NACT_EFFECT_WIPE_OUT:
return (opt ? opt : 40) * (rect->w / 48);
case NACT_EFFECT_WIPE_LR:
case NACT_EFFECT_WIPE_RL:
return (opt ? opt : 20) * rect->w / 8;
case NACT_EFFECT_WIPE_DOWN:
case NACT_EFFECT_WIPE_UP:
return (opt ? opt : 20) * rect->h / 8;
case NACT_EFFECT_WIPE_OUT_V:
case NACT_EFFECT_WIPE_IN_V:
return (opt ? opt : 30) * rect->w / 16;
case NACT_EFFECT_WIPE_OUT_H:
case NACT_EFFECT_WIPE_IN_H:
return (opt ? opt : 30) * rect->h / 16;
case NACT_EFFECT_MOSAIC:
return (opt ? opt : 100) * 8;
case NACT_EFFECT_FADEIN:
@@ -687,18 +554,8 @@ void ags_eCopyArea(int sx, int sy, int w, int h, int dx, int dy, int sw, int opt
case 3:
case 4:
case 6:
case 7:
case 8:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 54:
if (spCol == -1) {
ags_copyArea(sx, sy, w, h, dx, dy);
@@ -736,45 +593,15 @@ void ags_eCopyArea(int sx, int sy, int w, int h, int dx, int dy, int sw, int opt
case 6:
ret = eCopyArea6(dx, dy, w, h, opt);
break;
case 7:
ret = eCopyArea7(dx, dy, w, h, opt);
break;
case 8:
ret = eCopyArea8(dx, dy, w, h, opt);
break;
case 9:
ret = eCopyArea9(sx, sy, w, h, dx, dy, opt);
break;
case 12:
ret = eCopyArea12(dx, dy, w, h, opt);
break;
case 13:
ret = eCopyArea13(dx, dy, w, h, opt);
break;
case 14:
ret = eCopyArea14(dx, dy, w, h, opt);
break;
case 15:
ret = eCopyArea15(dx, dy, w, h, opt);
break;
case 16:
ret = eCopyArea16(dx, dy, w, h, opt);
break;
case 17:
ret = eCopyArea17(dx, dy, w, h, opt);
break;
case 18:
ret = eCopyArea18(dx, dy, w, h, opt);
break;
case 19:
ret = eCopyArea19(dx, dy, w, h, opt);
break;
case 20:
ret = eCopyArea20(dx, dy, w, h, opt);
break;
case 21:
ret = eCopyArea21(dx, dy, w, h, opt);
break;
case 22:
ret = eCopyArea22(sx, sy, w, h, dx, dy, opt);
break;
+20
View File
@@ -22,8 +22,18 @@
// Effect types of the CE command.
enum nact_effect {
NACT_EFFECT_WIPE_IN = 7,
NACT_EFFECT_WIPE_OUT = 8,
NACT_EFFECT_ZOOM_IN = 10,
NACT_EFFECT_BLIND_DOWN = 11,
NACT_EFFECT_WIPE_LR = 12,
NACT_EFFECT_WIPE_RL = 13,
NACT_EFFECT_WIPE_DOWN = 14,
NACT_EFFECT_WIPE_UP = 15,
NACT_EFFECT_WIPE_OUT_V = 18,
NACT_EFFECT_WIPE_IN_V = 19,
NACT_EFFECT_WIPE_OUT_H = 20,
NACT_EFFECT_WIPE_IN_H = 21,
NACT_EFFECT_MOSAIC = 24,
NACT_EFFECT_FADEIN = 27,
NACT_EFFECT_WHITEIN = 28,
@@ -111,6 +121,16 @@ enum sdl_effect_type {
EFFECT_DITHERING_FADEIN,
EFFECT_DITHERING_WHITEOUT,
EFFECT_DITHERING_WHITEIN,
EFFECT_WIPE_IN,
EFFECT_WIPE_OUT,
EFFECT_WIPE_LR,
EFFECT_WIPE_RL,
EFFECT_WIPE_DOWN,
EFFECT_WIPE_UP,
EFFECT_WIPE_OUT_V,
EFFECT_WIPE_IN_V,
EFFECT_WIPE_OUT_H,
EFFECT_WIPE_IN_H,
EFFECT_BLIND_DOWN,
EFFECT_BLIND_UP,
EFFECT_BLIND_LR,
+95
View File
@@ -31,8 +31,18 @@
enum sdl_effect_type from_nact_effect(enum nact_effect effect) {
switch (effect) {
case NACT_EFFECT_WIPE_IN: return EFFECT_WIPE_IN;
case NACT_EFFECT_WIPE_OUT: return EFFECT_WIPE_OUT;
case NACT_EFFECT_ZOOM_IN: return EFFECT_ZOOM_IN;
case NACT_EFFECT_BLIND_DOWN: return EFFECT_BLIND_DOWN;
case NACT_EFFECT_WIPE_LR: return EFFECT_WIPE_LR;
case NACT_EFFECT_WIPE_RL: return EFFECT_WIPE_RL;
case NACT_EFFECT_WIPE_DOWN: return EFFECT_WIPE_DOWN;
case NACT_EFFECT_WIPE_UP: return EFFECT_WIPE_UP;
case NACT_EFFECT_WIPE_OUT_V: return EFFECT_WIPE_OUT_V;
case NACT_EFFECT_WIPE_IN_V: return EFFECT_WIPE_IN_V;
case NACT_EFFECT_WIPE_OUT_H: return EFFECT_WIPE_OUT_H;
case NACT_EFFECT_WIPE_IN_H: return EFFECT_WIPE_IN_H;
case NACT_EFFECT_MOSAIC: return EFFECT_MOSAIC;
case NACT_EFFECT_FADEIN: return EFFECT_FADEIN;
case NACT_EFFECT_WHITEIN: return EFFECT_WHITEIN;
@@ -550,6 +560,80 @@ static void dithering_fade_free(struct sdl_effect *eff) {
free(eff);
}
// EFFECT_WIPE_*
static void wipe_step(struct sdl_effect *eff, double progress);
static void wipe_free(struct sdl_effect *eff);
static struct sdl_effect *wipe_new(SDL_Rect *rect, SDL_Surface *old, SDL_Surface *new, enum sdl_effect_type type) {
struct sdl_effect *eff = calloc(1, sizeof(struct sdl_effect));
if (!eff)
NOMEMERR();
effect_init(eff, rect, old, new, type);
eff->step = wipe_step;
eff->finish = wipe_free;
return eff;
}
static void wipe_step(struct sdl_effect *eff, double progress) {
SDL_Texture *bg = eff->tx_old;
SDL_Texture *fg = eff->tx_new;
if (eff->type == EFFECT_WIPE_RL ||
eff->type == EFFECT_WIPE_UP ||
eff->type == EFFECT_WIPE_IN ||
eff->type == EFFECT_WIPE_IN_V ||
eff->type == EFFECT_WIPE_IN_H) {
bg = eff->tx_new;
fg = eff->tx_old;
progress = 1 - progress;
}
SDL_RenderCopy(sdl_renderer, bg, NULL, &eff->dst_rect);
SDL_Rect sr = { 0, 0, eff->dst_rect.w, eff->dst_rect.h };
SDL_Rect dr = eff->dst_rect;
switch (eff->type) {
case EFFECT_WIPE_LR:
case EFFECT_WIPE_RL:
sr.w *= progress;
dr.w = sr.w;
break;
case EFFECT_WIPE_DOWN:
case EFFECT_WIPE_UP:
sr.h *= progress;
dr.h = sr.h;
break;
case EFFECT_WIPE_OUT:
case EFFECT_WIPE_IN:
case EFFECT_WIPE_OUT_V:
case EFFECT_WIPE_IN_V:
sr.w *= progress;
sr.x = (dr.w - sr.w) / 2;
dr.w = sr.w;
dr.x += sr.x;
if (eff->type == EFFECT_WIPE_OUT_V || eff->type == EFFECT_WIPE_IN_V)
break;
// fallthrough
case EFFECT_WIPE_OUT_H:
case EFFECT_WIPE_IN_H:
sr.h *= progress;
sr.y = (dr.h - sr.h) / 2;
dr.h = sr.h;
dr.y += sr.y;
break;
default:
assert(!"Cannot happen");
}
SDL_RenderCopy(sdl_renderer, fg, &sr, &dr);
SDL_RenderPresent(sdl_renderer);
}
static void wipe_free(struct sdl_effect *eff) {
effect_finish(eff, true);
free(eff);
}
// EFFECT_BLIND_*
static void blind_step(struct sdl_effect *eff, double progress);
@@ -1435,6 +1519,17 @@ struct sdl_effect *sdl_effect_init(SDL_Rect *rect, agsurface_t *old, int ox, int
case EFFECT_DITHERING_WHITEOUT:
case EFFECT_DITHERING_WHITEIN:
return dithering_fade_new(rect, sf_old, sf_new, type);
case EFFECT_WIPE_IN:
case EFFECT_WIPE_OUT:
case EFFECT_WIPE_LR:
case EFFECT_WIPE_RL:
case EFFECT_WIPE_DOWN:
case EFFECT_WIPE_UP:
case EFFECT_WIPE_OUT_V:
case EFFECT_WIPE_IN_V:
case EFFECT_WIPE_OUT_H:
case EFFECT_WIPE_IN_H:
return wipe_new(rect, sf_old, sf_new, type);
case EFFECT_BLIND_DOWN:
case EFFECT_BLIND_UP:
case EFFECT_BLIND_LR: