shithub: sce

Download patch

ref: 1eaa7d33dcccb7de34031d0c8f3d59d2d010de95
parent: 85b57565181c61e2fafbc0ed1fa9a7026930d824
author: qwx <qwx@sciops.net>
date: Fri Oct 2 03:17:23 EDT 2020

fs: remove gfx db records, useless

the idea was to spawn a mutable object on top of the moving
unit, but it's really pointless and more complicated than
just an additional sprite layer in the draw order.
the sprite we're trying to add is scv's engine glow, which
is an effect other units may have in other ways, so call it
that.
generalize loading and drawing the various layers of the
same pic, record whether sprite has team colors or not.
when fixing obj sprites, skip buildings and set shadows as
well.
rename tscglow to an scv glow sprite, this simplifies the
db records.

--- a/dat.h
+++ b/dat.h
@@ -3,7 +3,6 @@
 typedef struct Attack Attack;
 typedef struct Pic Pic;
 typedef struct Pics Pics;
-typedef struct OState OState;
 typedef struct Obj Obj;
 typedef struct Path Path;
 typedef struct Mobj Mobj;
@@ -69,7 +68,7 @@
 	PFterrain = 1<<0,
 	PFidle = 1<<1,
 	PFmove = 1<<2,
-	PFfloat = 1<<13,
+	PFglow = 1<<13,
 	PFalpha = 1<<14,
 	PFshadow = 1<<15,
 };
@@ -82,9 +81,10 @@
 };
 struct Pics{
 	Pic **pic;
-	Pic **shadow;
+	int teamcol;
 	int nf;
 	int nr;
+	int iscopy;
 };
 
 enum{
@@ -94,18 +94,18 @@
 	Fbuild = 1<<3,
 };
 enum{
-	OSidle,
+	PTbase,
+	PTshadow,
+	PTglow,
+	PTend,
+
+	OSidle = 0,
 	OSmove,
-	OSend
+	OSend,
 };
-struct OState{
-	Pics pics;
-	Obj *gfx;
-	Mobj *mgfx;
-};
 struct Obj{
 	char *name;
-	OState state[OSend];
+	Pics pics[OSend][PTend];
 	int w;
 	int h;
 	int f;
--- a/drw.c
+++ b/drw.c
@@ -171,6 +171,8 @@
 	u32int v, *p, *e, *q;
 	Rectangle r;
 
+	if(pic->p == nil)
+		sysfatal("drawshawdow: empty pic");
 	q = pic->p;
 	r = Rect(x + pic->dx, y + pic->dy, pic->w, pic->h);
 	if(boundpic(&r, &q) < 0)
@@ -259,7 +261,7 @@
 }
 
 static Pic *
-frm(Mobj *mo, int notshadow)
+frm(Mobj *mo, int type)
 {
 	static int rot17[Nrot] = {
 		0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,
@@ -269,21 +271,19 @@
 	Pics *pp;
 	Pic *p;
 
-	pp = &mo->o->state[mo->state].pics;
-	frm = mo->state == OSidle ? mo->freezefrm : tc % pp->nf;
-	assert(pp->pic != nil && pp->shadow != nil);
+	pp = &mo->o->pics[mo->state][type];
+	assert(pp->pic != nil);
+	frm = pp->iscopy ? mo->freezefrm : tc % pp->nf;
 	θ = mo->θ * 32.0 / 256;
 	switch(pp->nr){
 	case 17: θ = rot17[θ]; break;
 	default: θ = 0; break;
 	}
-	if(notshadow){
-		p = pp->pic[frm];
+	p = pp->pic[frm];
+	if(pp->teamcol)
 		p += nteam * θ + mo->team - 1;
-	}else{
-		p = pp->shadow[frm];
+	else
 		p += θ;
-	}
 	return p;
 }
 
@@ -323,13 +323,13 @@
 				mo = ml->mo;
 				if(mo->o->f & Fair)
 					break;
-				drawshadow(mo->px, mo->py, frm(mo, 0));
+				drawshadow(mo->px, mo->py, frm(mo, PTshadow));
 			}
 			for(ml=m->ml.l; ml!=&m->ml; ml=ml->l){
 				mo = ml->mo;
 				if(mo->o->f & Fair)
 					break;
-				drawpic(mo->px, mo->py, frm(mo, 1), addvis(mo));
+				drawpic(mo->px, mo->py, frm(mo, PTbase), addvis(mo));
 			}
 		}
 		m += mapwidth - (mr.max.x - mr.min.x);
@@ -340,13 +340,13 @@
 				mo = ml->mo;
 				if((mo->o->f & Fair) == 0)
 					continue;
-				drawshadow(mo->px, mo->py, frm(mo, 0));
+				drawshadow(mo->px, mo->py, frm(mo, PTshadow));
 			}
 			for(ml=m->ml.l; ml!=&m->ml; ml=ml->l){
 				mo = ml->mo;
 				if((mo->o->f & Fair) == 0)
 					continue;
-				drawpic(mo->px, mo->py, frm(mo, 1), addvis(mo));
+				drawpic(mo->px, mo->py, frm(mo, PTbase), addvis(mo));
 			}
 		}
 		m += mapwidth - (mr.max.x - mr.min.x);
--- a/fs.c
+++ b/fs.c
@@ -95,21 +95,8 @@
 }
 
 static void
-loadshadpic(Pic *pic, Picl *pl)
+loadobjpic(Pic *pic, Picl *pl, char *suff)
 {
-	int i;
-	char path[128];
-
-	for(i=0; i<pl->nr; i++){
-		snprint(path, sizeof path, "%s.%02d.%02d.s.bit",
-			pl->name, pl->frm, rot17idx[i]);
-		loadpic(path, pic++, 0);
-	}
-}
-
-static void
-loadobjpic(Pic *pic, Picl *pl)
-{
 	int n, i, j;
 	char path[128];
 	u32int *p0;
@@ -116,11 +103,11 @@
 	Pic pic0;
 
 	for(i=0; i<pl->nr; i++){
-		snprint(path, sizeof path, "%s.%02d.%02d.bit",
-			pl->name, pl->frm, rot17idx[i]);
+		snprint(path, sizeof path, "%s.%02d.%02d%s.bit",
+			pl->name, pl->frm, rot17idx[i], suff);
 		loadpic(path, &pic0, pl->type & PFalpha);
 		if(!pl->teamcol){		
-			memcpy(pic, &pic0, sizeof *pic);
+			memcpy(pic++, &pic0, sizeof *pic);
 			continue;
 		}
 		if(pic0.h % Nteam != 0)
@@ -174,9 +161,11 @@
 		if(pl->type & PFterrain)
 			loadterpic(p, pl);
 		else if(pl->type & PFshadow)
-			loadshadpic(p, pl);
+			loadobjpic(p, pl, ".s");
+		else if(pl->type & PFglow)
+			loadobjpic(p, pl, ".g");
 		else
-			loadobjpic(p, pl);
+			loadobjpic(p, pl, "");
 		pic->l = pl->l;
 		free(pl);
 	}
@@ -184,7 +173,7 @@
 }
 
 static Pic *
-pushpic(char *name, int frm, int type, int nr)
+pushpic(char *name, int frm, int type, int nr, int hasteam)
 {
 	int n;
 	char iname[64];
@@ -201,12 +190,13 @@
 		pl->type = type;
 		pl->name = name;
 		pl->nr = nr;
+		pl->teamcol = hasteam;
 		if(nr != 17 && nr != 1)
 			sysfatal("pushpic %s: invalid number of rotations", iname);
 		n = nr;
 		/* nteam isn't guaranteed to be set correctly by now, so
 		 * just set to max */
-		if(pl->teamcol = (type & (PFshadow|PFterrain|PFfloat)) == 0)
+		if(hasteam)
 			n *= Nteam;
 		pl->p = emalloc(n * sizeof *pl->p);
 		pl->l = pic->l;
@@ -227,7 +217,7 @@
 		tl = emalloc(sizeof *tl);
 		tl->id = id;
 		tl->t = emalloc(sizeof *tl->t);
-		tl->t->p = pushpic("/tile/", id - 1, PFterrain, 1);
+		tl->t->p = pushpic("/tile/", id - 1, PFterrain, 1, 0);
 		tl->l = terrainl->l;
 		terrainl->l = tl;
 	}
@@ -395,28 +385,6 @@
 }
 
 static void
-readgfx(char **fld, int, Table *tab)
-{
-	int f;
-	Obj *fxo, *o;
-	OState *s;
-
-	if(obj == nil)
-		obj = emalloc(nobj * sizeof *obj);
-	fxo = obj + nobj - 1 - tab->row;
-	fxo->name = estrdup(*fld++);
-	unpack(fld, "od", &o, &f);
-	fxo->f = f;
-	s = nil;
-	switch(f){
-	case PFidle: s = o->state + OSidle; break;
-	case PFmove: s = o->state + OSmove; break;
-	default: sysfatal("readgfx: %s unknown flag", fxo->name);
-	}
-	s->gfx = fxo;
-}
-
-static void
 readobj(char **fld, int, Table *tab)
 {
 	Obj *o;
@@ -452,15 +420,22 @@
 	n -= 3;
 	ps = nil;
 	switch(type & 0xf){
-	case PFidle: ps = &o->state[OSidle].pics; break;
-	case PFmove: ps = &o->state[OSmove].pics; break;
+	case PFidle: ps = o->pics[OSidle]; break;
+	case PFmove: ps = o->pics[OSmove]; break;
 	default: sysfatal("readspr %s: invalid type %#02ux", o->name, type & 0x7e);
 	}
-	ppp = type & PFshadow ? &ps->shadow : &ps->pic;
+	if(type & PFshadow)
+		ps += PTshadow;
+	else if(type & PFglow)
+		ps += PTglow;
+	else
+		ps += PTbase;
+	ppp = &ps->pic;
 	if(*ppp != nil)
 		sysfatal("readspr %s: pic type %#ux already allocated", o->name, type);
 	if(ps->nf != 0 && ps->nf != n || ps->nr != 0 && ps->nr != nr)
 		sysfatal("readspr %s: spriteset phase error", o->name);
+	ps->teamcol = (type & (PFshadow|PFterrain|PFglow)) == 0;
 	ps->nf = n;
 	ps->nr = nr;
 	p = emalloc(n * sizeof *ppp);
@@ -467,7 +442,7 @@
 	*ppp = p;
 	for(pe=p+n; p<pe; p++){
 		unpack(fld++, "d", &frm);
-		*p = pushpic(o->name, frm, type, nr);
+		*p = pushpic(o->name, frm, type, nr, ps->teamcol);
 	}
 }
 
@@ -474,7 +449,6 @@
 enum{
 	Tmapobj,
 	Tobj,
-	Tgfx,
 	Tattack,
 	Tresource,
 	Tspawn,
@@ -485,7 +459,6 @@
 Table table[] = {
 	[Tmapobj] {"mapobj", readmapobj, 4, &nobjp},
 	[Tobj] {"obj", readobj, 17, &nobj},
-	[Tgfx] {"gfx", readgfx, 3, &nobj},
 	[Tattack] {"attack", readattack, 4, &nattack},
 	[Tresource] {"resource", readresource, 2, &nresource},
 	[Tspawn] {"spawn", readspawn, -1, nil},
@@ -596,14 +569,23 @@
 	Pics *idle, *move;
 
 	for(o=obj; o<obj+nobj; o++){
-		idle = &o->state[OSidle].pics;
-		move = &o->state[OSmove].pics;
-		if(idle->pic == nil && move->pic == nil)
+		if(o->f & Fbuild)
+			continue;
+		idle = o->pics[OSidle];
+		move = o->pics[OSmove];
+		if(idle[PTbase].pic == nil && move[PTbase].pic == nil)
 			sysfatal("obj %s: no base sprites loaded", o->name);
-		if(idle->pic == nil)
-			memcpy(idle, move, sizeof *idle);
-		else if(move->pic == nil)
-			memcpy(move, idle, sizeof *move);
+		if(idle[PTbase].pic == nil){
+			memcpy(idle+PTbase, move+PTbase, sizeof *idle);
+			memcpy(idle+PTshadow, move+PTshadow, sizeof *idle);
+			idle[PTbase].iscopy = 1;
+			idle[PTshadow].iscopy = 1;
+		}else if(move[PTbase].pic == nil){
+			memcpy(move+PTbase, idle+PTbase, sizeof *move);
+			memcpy(move+PTshadow, idle+PTshadow, sizeof *move);
+			move[PTbase].iscopy = 1;
+			move[PTshadow].iscopy = 1;
+		}
 	}
 }
 
--- a/sce/sce.db
+++ b/sce/sce.db
@@ -10,13 +10,12 @@
 obj,drone,0x1,4,4,40,0,7,1,50,0,20,spines,,4.97,67,12227,40
 obj,control,0x8,16,12,1500,1,1,10,400,0,1800,,,0,0,0,0
 obj,hatchery,0x8,16,12,1250,1,1,10,300,0,1800,,,0,0,0,0
-# gfx: name, obj, flags (PF enum)
-gfx,tscglow,scv,0x4
 # spawn: objname, [obj..]
 spawn,control,scv
 # spr: objname, flags (PF enum), rotations, [frame..]
 spr,scv,0x2,17,0
 spr,scv,0x8002,17,0
+spr,scv,0x6004,17,0,1,2,3
 spr,control,0x2,1,0
 spr,control,0x8002,1,0
 spr,drone,0x4,17,0,1,2,3,4
@@ -23,4 +22,3 @@
 spr,drone,0x8004,17,0,1,2,3,4
 spr,hatchery,2,1,0,1,2,3,3,2,1,0
 spr,hatchery,0x8002,1,0,0,0,0,0,0,0,0
-spr,tscglow,0x6004,17,0,1,2,3
--- a/sim.c
+++ b/sim.c
@@ -88,7 +88,7 @@
 {
 	unlinkmobj(mo->movingp);
 	mo->pathp = nil;
-	mo->freezefrm = tc % mo->o->state[mo->state].pics.nf;
+	mo->freezefrm = tc % mo->o->pics[mo->state][PTbase].nf;
 	mo->state = OSidle;
 	resetcoords(mo);
 }
--- a/utils/scefix
+++ b/utils/scefix
@@ -71,6 +71,15 @@
 		rm $1^.??.^$rot^.bit
 }
 
+fn rename{
+	if(! ~ $3 '')
+		suf=';s/\.bit/.'^$3^'&/'
+	if not
+		suf=''
+	for(i in $1^.*)
+		mv $i `{echo $i | sed 's/'^$1^'/'^$2^'/'^$suf}
+}
+
 cat <<! >/env/fuckrc
 !r /tmp/a.bit a
 r = a
@@ -94,6 +103,7 @@
 gen32 scv 00
 gen32 drone 00 01 02 03 04
 clean tscglow
+rename tscglow scv g
 gen1 control 00
 gen1 hatchery 00 01 02 03
 terrain badlands