From 9f066887bdaeaaf0e8caa0fb62f610a398ea1666 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Wed, 23 Mar 2016 11:21:52 +0200 Subject: [PATCH] splash particles --- d2dparts.d | 24 ++++++++++++++++----- data/scripts/actor.dacs | 6 ++++++ data/scripts/mapapi.dacs | 2 ++ data/scripts/moveapi.dacs | 55 +++++++++++++++++++++++++++++++++++++++++------ dengapi.d | 11 ++++++++++ 5 files changed, 87 insertions(+), 11 deletions(-) diff --git a/d2dparts.d b/d2dparts.d index 2601836..71f4380 100644 --- a/d2dparts.d +++ b/d2dparts.d @@ -36,9 +36,11 @@ import dengapi : map, unsyncrandu31; public void dotInit () { imgParts = new TrueColorImage(map.width*8, map.height*8); + imgPartsOld = new TrueColorImage(map.width*8, map.height*8); foreach (int y; 0..map.height*8) { foreach (int x; 0..map.width*8) { putPixel(x, y, Color(0, 0, 0, 0)); + putPixelOld(x, y, Color(0, 0, 0, 0)); } } texParts = new Texture(imgParts, Texture.Option.Nearest, Texture.Option.Clamp); @@ -55,7 +57,15 @@ public void dotInit () { // ////////////////////////////////////////////////////////////////////////// // __gshared public Texture texParts; // texture for particles; can be blended on bg -__gshared TrueColorImage imgParts; +__gshared TrueColorImage imgParts, imgPartsOld; + + +void putPixelOld (int x, int y, Color clr) { + pragma(inline, true); + if (/*clr.a != 0 &&*/ x >= 0 && y >= 0 && x < imgPartsOld.width && y < imgPartsOld.height) { + imgPartsOld.imageData.colors.ptr[y*imgPartsOld.width+x] = clr; + } +} void putPixel (int x, int y, Color clr) { @@ -91,7 +101,7 @@ struct DotParticle { ubyte time; ubyte color; // from D2D palette Color drawColor; - Color prevColor; // on image; a=0: was empty + //Color prevColor; // on image; a=0: was empty @disable this (this); // no copy } @@ -106,6 +116,8 @@ void dotRemove (usize idx, bool leftOnPic) { if (idx >= dotsUsed) return; import core.stdc.string : memmove; auto dt = dots.ptr+idx; + if (leftOnPic) putPixelOld(dt.x, dt.y, dt.drawColor); + /* auto pclr = (leftOnPic ? dt.drawColor : dt.prevColor); bool found = false; int px = (leftOnPic ? dt.x : dt.lastX); @@ -120,6 +132,7 @@ void dotRemove (usize idx, bool leftOnPic) { } // if not found, just draw it if (!found) putPixel(px, py, pclr); + */ // move dots --dotsUsed; if (idx < dotsUsed) memmove(dots.ptr+idx, dots.ptr+idx+1, (dotsUsed-idx)*dots[0].sizeof); @@ -148,7 +161,7 @@ void dotAdd (int x, int y, int xv, int yv, ubyte color, ubyte time) { dot.color = color; dot.time = time; dot.vx = dot.vy = 0; - dot.prevColor = getPixel(x, y); + //dot.prevColor = getPixel(x, y); dot.drawColor = d2dpal[color]; dot.drawColor.a = 180; } @@ -158,7 +171,8 @@ void dotAdd (int x, int y, int xv, int yv, ubyte color, ubyte time) { public void dotDraw (float itp) { import core.stdc.math : roundf; // remove dots from image (in reverse order) - foreach_reverse (ref dt; dots[0..dotsUsed]) putPixel(dt.lastX, dt.lastY, dt.prevColor); + //foreach_reverse (ref dt; dots[0..dotsUsed]) putPixel(dt.lastX, dt.lastY, dt.prevColor); + imgParts.imageData.colors[] = imgPartsOld.imageData.colors[]; //imgParts.imageData.colors[] = Color(0, 0, 0, 0); // draw dots foreach (ref dt; dots[0..dotsUsed]) { @@ -166,7 +180,7 @@ public void dotDraw (float itp) { int ny = cast(int)(dt.y+roundf((dt.y-dt.prevY)*itp)); dt.lastX = nx; dt.lastY = ny; - dt.prevColor = getPixel(nx, ny); + //dt.prevColor = getPixel(nx, ny); putPixel(nx, ny, dt.drawColor); } // update texture diff --git a/data/scripts/actor.dacs b/data/scripts/actor.dacs index e4338f1..728e881 100644 --- a/data/scripts/actor.dacs +++ b/data/scripts/actor.dacs @@ -156,10 +156,16 @@ public const Z_HITWATER = BIT(5); public const Z_HITAIR = BIT(6); public const Z_BLOCK = BIT(7); +// "real" water type (for Z_HITWATER) public const Z_WATER_0 = BIT(16); public const Z_WATER_1 = BIT(17); public const Z_WATER_2 = BIT(18); +// "texture" water type (for Z_HITWATER) +public const Z_WATER_T0 = BIT(19); +public const Z_WATER_T1 = BIT(20); +public const Z_WATER_T2 = BIT(21); + public extern uint gameMode () pure; // game modes diff --git a/data/scripts/mapapi.dacs b/data/scripts/mapapi.dacs index ae9dbeb..010a832 100644 --- a/data/scripts/mapapi.dacs +++ b/data/scripts/mapapi.dacs @@ -64,6 +64,8 @@ public extern int mapGetTile (uint layer, int x, int y) pure; public extern void mapSetTypeTile (int x, int y, int tid); public extern void mapSetTile (uint layer, int x, int y, int tid); +// [0..3] (0: not a water) +public extern int mapGetWaterTexture (int fg); public extern int getMapViewHeight () pure; public extern void setMapViewPos (int x, int y); diff --git a/data/scripts/moveapi.dacs b/data/scripts/moveapi.dacs index 28b8615..eb971b2 100644 --- a/data/scripts/moveapi.dacs +++ b/data/scripts/moveapi.dacs @@ -27,6 +27,25 @@ public int Z_checkerRHHalf (int x, int y, int r, int h, int function (int tilety } +public int Z_checkerRHHalfEx (int x, int y, int r, int h, int function (int tilefg, int tiletype) ccb) { + // start tile + int sx = max((x-r)/CELW, 0); + int sy = max((y-h+1)/CELH, 0); + // end tile + x = min((x+r)/CELW, FLDW-1); + y = min((y-h/2)/CELH, FLDH-1); + if (sx > x || sy > y) return -1; // counts as true anyway + while (sx <= x) { + for (int j = sy; j <= y; ++j) { + int res = ccb(mapGetTile(LAYER_FRONT, sx, j), mapGetTypeTile(sx, j)); + if (res) return res; + } + ++sx; + } + return 0; +} + + // check "under feet" / "above head" public int Z_checkerRHFeetHead (int x, int y, int r, int h, int function (int tiletype) ccb) { //int origx = x; @@ -145,6 +164,30 @@ int Z_inwaterCCB (int fv) { public int Z_inwater (int x, int y, int r, int h/*, ref int wfront*/) { return Z_checkerRHHalf(x, y, r, h, &Z_inwaterCCB); } +int Z_inwaterCCBEx (int fg, int fv) { + //return (fv >= TILE_WATER && fv <= TILE_ACID2 ? 1 : 0); /* wfront = fv;*/ + int res = 0; + switch (fv) { + case TILE_WATER: res = Z_WATER_0; break; + case TILE_ACID1: res = Z_WATER_1; break; + case TILE_ACID2: res = Z_WATER_2; break; + default: + } + if (res) { + int wt = mapGetWaterTexture(fg); + switch (wt) { + case 1: res |= Z_WATER_T0; break; + case 2: res |= Z_WATER_T1; break; + case 3: res |= Z_WATER_T2; break; + default: + } + } + return res; +} + +public int Z_inwaterEx (int x, int y, int r, int h/*, ref int wfront*/) { return Z_checkerRHHalfEx(x, y, r, h, &Z_inwaterCCBEx); } + + // ////////////////////////////////////////////////////////////////////////// // int clamp7 (int v) { return (abs(v) <= 7 ? v : (v > 0 ? 7 : -7)); } @@ -278,7 +321,7 @@ public int Z_moveobj (Actor me) { me.y = y; //writeln(" x=", x, "; y=", y); - int wtr = Z_inwater(x, y, r, h); + int wtr = Z_inwaterEx(x, y, r, h); if (wtr) { st |= Z_INWATER; if (!inw) st |= Z_HITWATER; @@ -295,12 +338,12 @@ public int Z_moveobj (Actor me) { public void Z_splash (Actor me, int n, int st) { //Z_sound(bulsnd[0], 128); //DOT_water(p->x, p->y-p->h/2, p->xv+p->vx, p->yv+p->vy, n, /*(int)walp[wfront]*/walp[wfront]->wanim-1); - writeln("Z_splash: n=", n, "; wtx=", (st&(Z_WATER_0|Z_WATER_1|Z_WATER_2))); + //writeln("Z_splash: n=", n, "; wtx=", (st&(Z_WATER_0|Z_WATER_1|Z_WATER_2))); int wtt; - if (st&Z_WATER_0) wtt = 0; - else if (st&Z_WATER_1) wtt = 1; - else if (st&Z_WATER_2) wtt = 2; + if (st&Z_WATER_T0) wtt = 0; + else if (st&Z_WATER_T1) wtt = 1; + else if (st&Z_WATER_T2) wtt = 2; else return; - writeln("Z_splash: n=", n, "; wtt=", wtt); + //writeln("Z_splash: n=", n, "; wtt=", wtt); dotAddWater(me.x, me.y-me.height/2, me.xv+me.vx, me.yv+me.vy, n, wtt); } diff --git a/dengapi.d b/dengapi.d index a4e0e88..e9e8632 100644 --- a/dengapi.d +++ b/dengapi.d @@ -366,6 +366,17 @@ void setupDAPI () { } }; + FuncPool["mapGetWaterTexture"] = function int (int fg) { + if (fg < 0 || fg >= map.wallnames.length) return 0; + switch (map.wallnames.ptr[fg]) { + case "_water_0": return 1; + case "_water_1": return 2; + case "_water_2": return 3; + default: + } + return 0; + }; + FuncPool["getMapViewHeight"] = function int () { import xmain_d2d : vlWidth, vlHeight, scale; return vlHeight/scale; -- 2.11.4.GIT