ref: 85b57565181c61e2fafbc0ed1fa9a7026930d824
parent: 9fba9b42bfc9df98b00fa01753cdfeb9bc214ca8
author: qwx <qwx@sciops.net>
date: Thu Oct 1 07:23:41 EDT 2020
sim: track mobj state, simplify sprite frame selection somewhat do one-time setup in fs.c after loading everything, to make sure all sprite pointers are set. if there's no movement sprite, use idle sprite and vice-versa. don't do more checks later to simplify things a bit, and don't have sim.c deciding what to draw.
--- a/dat.h
+++ b/dat.h
@@ -134,7 +134,7 @@
};
struct Mobj{
Obj *o;
- Pics *pics;
+ int state;
int freezefrm;
Point;
int px;
--- a/drw.c
+++ b/drw.c
@@ -269,13 +269,8 @@
Pics *pp;
Pic *p;
- pp = mo->pics;
- if(pp->pic != nil)
- frm = tc % pp->nf;
- else{
- pp = &mo->o->state[OSmove].pics;
- frm = mo->freezefrm;
- }
+ pp = &mo->o->state[mo->state].pics;
+ frm = mo->state == OSidle ? mo->freezefrm : tc % pp->nf;
assert(pp->pic != nil && pp->shadow != nil);
θ = mo->θ * 32.0 / 256;
switch(pp->nr){
--- a/fs.c
+++ b/fs.c
@@ -590,6 +590,24 @@
}
static void
+fixobjspr(void)
+{
+ Obj *o;
+ 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)
+ 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);
+ }
+}
+
+static void
checkdb(void)
{
if(tileset == nil)
@@ -610,6 +628,7 @@
initmap();
initmapobj();
cleanup();
+ fixobjspr();
}
void
--- a/sim.c
+++ b/sim.c
@@ -88,9 +88,8 @@
{
unlinkmobj(mo->movingp);
mo->pathp = nil;
- if(mo->pics->nf > 0)
- mo->freezefrm = tc % mo->pics->nf;
- mo->pics = &mo->o->state[OSidle].pics;
+ mo->freezefrm = tc % mo->o->state[mo->state].pics.nf;
+ mo->state = OSidle;
resetcoords(mo);
}
@@ -112,8 +111,7 @@
}
mo->movingp = linkmobj(moving, mo, mo->movingp);
mo->pathp = mo->paths;
- mo->pics = mo->o->state[OSmove].pics.pic != nil
- ? &mo->o->state[OSmove].pics : &mo->o->state[OSidle].pics;
+ mo->state = OSmove;
nextmove(mo);
return 0;
}
@@ -142,7 +140,7 @@
if((mo = mapspawn(x, y, o)) == nil)
return -1;
mo->team = n;
- mo->pics = &mo->o->state[OSidle].pics;
+ mo->state = OSidle;
if(mo->f & Fbuild)
team[n].nbuild++;
else