ref: 6be8fbebaa275caf6b43c26a41d2328e04a034c3
parent: d980a1c4e5f4f5d524eff17b9957b3a2a73f1af1
author: qwx <qwx@sciops.net>
date: Mon Mar 16 02:51:35 EDT 2020
implement object shadows pretty hacky for the time being, there's a lot of redundancy a sprite db should be implemented to reduce duplication and simplify things a bit
--- a/dat.h
+++ b/dat.h
@@ -42,6 +42,7 @@
};
struct Pics{
Pic *p;
+ Pic *shadow;
int nf;
int nr;
int n;
--- a/drw.c
+++ b/drw.c
@@ -133,6 +133,39 @@
}
static void
+drawshadow(int x, int y, Pic *pic)
+{
+ int n, w, Δp, Δq;
+ u32int v, *p, *q;
+ Rectangle r;
+
+ q = pic->p;
+ r = Rect(x + pic->dx, y + pic->dy, pic->w, pic->h);
+ if(boundpic(&r, &q) < 0)
+ return;
+ Δq = pic->w - r.max.x;
+ p = fb + r.min.y * fbw + r.min.x;
+ Δp = fbw - r.max.x * scale;
+ while(r.max.y-- > 0){
+ w = r.max.x;
+ while(w-- > 0){
+ v = *q++;
+ if(v & 0xff << 24){
+ v = p[0];
+ v = (v & 0xff0000) * 0x96 / 0xff & 0xff0000
+ | (v & 0xff00) * 0x96 / 0xff & 0xff00
+ | (v & 0xff) * 0x96 / 0xff & 0xff;
+ for(n=0; n<scale; n++)
+ *p++ = v;
+ }else
+ p += scale;
+ }
+ q += Δq;
+ p += Δp;
+ }
+}
+
+static void
compose(Path *pp, u32int c)
{
int n, w, Δp;
@@ -159,6 +192,15 @@
}
static Pic *
+shafrm(Mobj *mo)
+{
+ Pics *p;
+
+ p = mo->pics;
+ return p->shadow + p->nf * mo->θ + tc % p->nf;
+}
+
+static Pic *
frm(Mobj *mo)
{
Pics *p;
@@ -182,14 +224,19 @@
drawpic(m->x, m->y, &m->t->pic);
/* FIXME: draw overlay (creep) */
/* FIXME: draw corpses */
- for(m=map; m<map+mapwidth*mapheight; m++)
+ for(m=map; m<map+mapwidth*mapheight; m++){
for(lo=m->lo.lo; lo!=&m->lo; lo=lo->lo){
mo = lo->mo;
+ drawshadow(mo->p.x, mo->p.y, shafrm(mo));
+ }
+ for(lo=m->lo.lo; lo!=&m->lo; lo=lo->lo){
+ mo = lo->mo;
drawpic(mo->p.x, mo->p.y, frm(mo));
}
- for(pp=path; pp<path+pathwidth*pathheight; pp++)
- if(pp->blk != nil)
- compose(pp, 0xff00ff);
+ }
+ //for(pp=path; pp<path+pathwidth*pathheight; pp++)
+ // if(pp->blk != nil)
+ // compose(pp, 0xff00ff);
/* FIXME: draw hud */
draw(screen, Rpt(p0, screen->r.max), display->black, nil, ZP);
mo = selected[0];
--- a/fs.c
+++ b/fs.c
@@ -96,7 +96,7 @@
{
int i, r, f, nf;
char s[128];
- Pic *pp;
+ Pic *pp, *ps;
if((nf = getfrm(name, id)) == 0)
return -1;
@@ -103,7 +103,8 @@
p->nf = nf;
p->nr = nr;
p->n = nf * nr;
- pp = p->p = emalloc(nteam * nf * nr * sizeof *pp);
+ pp = p->p = emalloc(nteam * p->n * sizeof *pp);
+ ps = p->shadow = emalloc(p->n * sizeof *pp);
for(i=0; i<nteam; i++){
for(r=0; r<nr; r++)
for(f=0; f<nf; f++){
@@ -111,6 +112,11 @@
loadpic(s, pp++);
}
}
+ for(r=0; r<nr; r++)
+ for(f=0; f<nf; f++){
+ snprint(s, sizeof s, "%ss%s.%02d.%02d.bit", name, id, f, r);
+ loadpic(s, ps++);
+ }
return 0;
}