Clean up of mostly actors.c, but some other files along the way too.

- Rewrite some sprites-of-{stat,sector} loops using the SPRITES_OF,
  SPRITES_OF_SECT and new SPRITES_OF_SECT_SAFE macros.
- In passing, identify some problems and mark them with 'XXX', but don't
  attempt to fix them yet.
- The usual readability improvements...

git-svn-id: https://svn.eduke32.com/eduke32@3679 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-04-15 10:48:09 +00:00
parent 52fc0bdfc5
commit 8064bd2f30
7 changed files with 434 additions and 464 deletions

View file

@ -93,9 +93,13 @@ enum rendmode_t {
#define PR_LIGHT_PRIO_LOW 4 #define PR_LIGHT_PRIO_LOW 4
#define PR_LIGHT_PRIO_LOW_GAME 5 #define PR_LIGHT_PRIO_LOW_GAME 5
// Convenient sprite iterators, must not be used if any sprites are potentially deleted! // Convenient sprite iterators, must not be used if any sprites inside the loop
// are potentially deleted or their sector changed...
#define SPRITES_OF(Statnum, Iter) Iter=headspritestat[Statnum]; Iter>=0; Iter=nextspritestat[Iter] #define SPRITES_OF(Statnum, Iter) Iter=headspritestat[Statnum]; Iter>=0; Iter=nextspritestat[Iter]
#define SPRITES_OF_SECT(Sectnum, Iter) Iter=headspritesect[Sectnum]; Iter>=0; Iter=nextspritesect[Iter] #define SPRITES_OF_SECT(Sectnum, Iter) Iter=headspritesect[Sectnum]; Iter>=0; Iter=nextspritesect[Iter]
// ... in which case this iterator may be used:
#define SPRITES_OF_SECT_SAFE(Sectnum, Iter, Next) Iter=headspritesect[Sectnum]; \
Iter>=0 && (Next=nextspritestat[Iter], 1); Iter=Next
#define CLEARLINES2D(Startline, Numlines, Color) \ #define CLEARLINES2D(Startline, Numlines, Color) \
clearbuf((char *)(frameplace + ((Startline)*bytesperline)), (bytesperline*(Numlines))>>2, (Color)) clearbuf((char *)(frameplace + ((Startline)*bytesperline)), (bytesperline*(Numlines))>>2, (Color))

View file

@ -11387,15 +11387,15 @@ restart_grand:
#ifdef YAX_ENABLE #ifdef YAX_ENABLE
if (bn[0]<0 && bn[1]<0) if (bn[0]<0 && bn[1]<0)
#endif #endif
if ((nexts < 0) || (wal->cstat&32)) if (nexts < 0 || wal->cstat&32)
return(0); return 0;
t = divscale24(t,bot); t = divscale24(t,bot);
x = x1 + mulscale24(x21,t); x = x1 + mulscale24(x21,t);
y = y1 + mulscale24(y21,t); y = y1 + mulscale24(y21,t);
z = z1 + mulscale24(z21,t); z = z1 + mulscale24(z21,t);
getzsofslope((int16_t)dasectnum, x,y, &cfz[0],&cfz[1]); getzsofslope(dasectnum, x,y, &cfz[0],&cfz[1]);
if (z <= cfz[0] || z >= cfz[1]) if (z <= cfz[0] || z >= cfz[1])
{ {
@ -11425,16 +11425,16 @@ restart_grand:
} }
#endif #endif
return(0); return 0;
} }
#ifdef YAX_ENABLE #ifdef YAX_ENABLE
if ((nexts < 0) || (wal->cstat&32)) if (nexts < 0 || (wal->cstat&32))
return 0; return 0;
#endif #endif
getzsofslope((int16_t)nexts,x,y,&cfz[0],&cfz[1]); getzsofslope(nexts, x,y, &cfz[0],&cfz[1]);
if ((z <= cfz[0]) || (z >= cfz[1])) if (z <= cfz[0] || z >= cfz[1])
return(0); return 0;
add_nextsector: add_nextsector:
if (!(sectbitmap[nexts>>3] & (1<<(nexts&7)))) if (!(sectbitmap[nexts>>3] & (1<<(nexts&7))))
@ -11456,10 +11456,10 @@ add_nextsector:
#endif #endif
} }
if ((sectbitmap[sect2>>3] & (1<<(sect2&7)))) if (sectbitmap[sect2>>3] & (1<<(sect2&7)))
return 1; return 1;
return(0); return 0;
} }
static inline void hit_set(hitdata_t *hit, int32_t sectnum, int32_t wallnum, int32_t spritenum, static inline void hit_set(hitdata_t *hit, int32_t sectnum, int32_t wallnum, int32_t spritenum,

File diff suppressed because it is too large Load diff

View file

@ -29,6 +29,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define SLEEPTIME 1536 #define SLEEPTIME 1536
#define ZOFFSET (1<<8) #define ZOFFSET (1<<8)
#define ACTOR_MAXFALLINGZVEL 6144
#define ACTOR_ONWATER_ADDZ (24<<8)
// KEEPINSYNC lunatic/con_lang.lua // KEEPINSYNC lunatic/con_lang.lua
#define STAT_DEFAULT 0 #define STAT_DEFAULT 0
#define STAT_ACTOR 1 #define STAT_ACTOR 1

View file

@ -58,17 +58,19 @@ EXTERN_INLINE void G_RestoreInterpolations(void) //Stick at end of drawscreen
EXTERN_INLINE int32_t G_CheckForSpaceCeiling(int32_t sectnum) EXTERN_INLINE int32_t G_CheckForSpaceCeiling(int32_t sectnum)
{ {
return ((sector[sectnum].ceilingstat&1) && sector[sectnum].ceilingpal == 0 && (sector[sectnum].ceilingpicnum==MOONSKY1 || sector[sectnum].ceilingpicnum==BIGORBIT1)?1:0); return ((sector[sectnum].ceilingstat&1) && sector[sectnum].ceilingpal == 0 &&
(sector[sectnum].ceilingpicnum==MOONSKY1 || sector[sectnum].ceilingpicnum==BIGORBIT1));
} }
EXTERN_INLINE int32_t G_CheckForSpaceFloor(int32_t sectnum) EXTERN_INLINE int32_t G_CheckForSpaceFloor(int32_t sectnum)
{ {
return ((sector[sectnum].floorstat&1) && sector[sectnum].ceilingpal == 0 && ((sector[sectnum].floorpicnum==MOONSKY1)||(sector[sectnum].floorpicnum==BIGORBIT1))?1:0); return ((sector[sectnum].floorstat&1) && sector[sectnum].ceilingpal == 0 &&
(sector[sectnum].floorpicnum==MOONSKY1 || sector[sectnum].floorpicnum==BIGORBIT1));
} }
EXTERN_INLINE int32_t A_CheckEnemySprite(const spritetype *s) EXTERN_INLINE int32_t A_CheckEnemySprite(const spritetype *s)
{ {
return(A_CheckEnemyTile(s->picnum)); return A_CheckEnemyTile(s->picnum);
} }
#endif #endif

View file

@ -872,19 +872,21 @@ static void VM_Fall(int32_t g_i, spritetype *g_sp)
actor[g_i].cgg = 3; actor[g_i].cgg = 3;
} }
if (g_sp->z < (actor[g_i].floorz-ZOFFSET)) if (g_sp->z < actor[g_i].floorz-ZOFFSET)
{ {
g_sp->z += g_sp->zvel = min(6144, g_sp->zvel+j); g_sp->zvel = min(g_sp->zvel+j, ACTOR_MAXFALLINGZVEL);
g_sp->z += g_sp->zvel;
#ifdef YAX_ENABLE #ifdef YAX_ENABLE
j = yax_getbunch(g_sp->sectnum, YAX_FLOOR); if (yax_getbunch(g_sp->sectnum, YAX_FLOOR) >= 0 &&
if (j >= 0 && (sector[g_sp->sectnum].floorstat&512)==0) (sector[g_sp->sectnum].floorstat&512)==0)
setspritez(g_i, (vec3_t *)g_sp); setspritez(g_i, (vec3_t *)g_sp);
else else
#endif #endif
if (g_sp->z > (actor[g_i].floorz - ZOFFSET)) if (g_sp->z > actor[g_i].floorz - ZOFFSET)
g_sp->z = (actor[g_i].floorz - ZOFFSET); g_sp->z = actor[g_i].floorz - ZOFFSET;
return; return;
} }
g_sp->z = actor[g_i].floorz - ZOFFSET; g_sp->z = actor[g_i].floorz - ZOFFSET;
if (A_CheckEnemySprite(g_sp) || (g_sp->picnum == APLAYER && g_sp->owner >= 0)) if (A_CheckEnemySprite(g_sp) || (g_sp->picnum == APLAYER && g_sp->owner >= 0))
@ -899,17 +901,20 @@ static void VM_Fall(int32_t g_i, spritetype *g_sp)
A_PlaySound(SQUISHED,g_i); A_PlaySound(SQUISHED,g_i);
A_Spawn(g_i,BLOODPOOL); A_Spawn(g_i,BLOODPOOL);
} }
actor[g_i].picnum = SHOTSPARK1; actor[g_i].picnum = SHOTSPARK1;
actor[g_i].extra = 1; actor[g_i].extra = 1;
g_sp->zvel = 0; g_sp->zvel = 0;
} }
else if (g_sp->zvel > 2048 && sector[g_sp->sectnum].lotag != ST_1_ABOVE_WATER) else if (g_sp->zvel > 2048 && sector[g_sp->sectnum].lotag != ST_1_ABOVE_WATER)
{ {
j = g_sp->sectnum; int16_t newsect = g_sp->sectnum;
pushmove((vec3_t *)g_sp,(int16_t *)&j,128L,(4L<<8),(4L<<8),CLIPMASK0);
if ((unsigned)j < MAXSECTORS) pushmove((vec3_t *)g_sp, &newsect, 128, 4<<8, 4<<8, CLIPMASK0);
changespritesect(g_i,j); if ((unsigned)newsect < MAXSECTORS)
A_PlaySound(THUD,g_i); changespritesect(g_i, newsect);
A_PlaySound(THUD, g_i);
} }
} }
} }
@ -925,13 +930,18 @@ static void VM_Fall(int32_t g_i, spritetype *g_sp)
{ {
switch (DYNAMICTILEMAP(g_sp->picnum)) switch (DYNAMICTILEMAP(g_sp->picnum))
{ {
case OCTABRAIN__STATIC:
case COMMANDER__STATIC:
case DRONE__STATIC:
break;
default: default:
// fix for flying/jumping monsters getting stuck in water
{ {
#if !defined LUNATIC #if !defined LUNATIC
int32_t moveScriptOfs = vm.g_t[1]; int32_t moveScriptOfs = vm.g_t[1];
#endif #endif
// fix for flying/jumping monsters getting stuck in water
if ((g_sp->hitag & jumptoplayer) || if ((g_sp->hitag & jumptoplayer) ||
(G_HaveActor(g_sp->picnum) && (G_HaveActor(g_sp->picnum) &&
#if !defined LUNATIC #if !defined LUNATIC
@ -944,15 +954,13 @@ static void VM_Fall(int32_t g_i, spritetype *g_sp)
// OSD_Printf("%d\n", script[moveScriptOfs + 1]); // OSD_Printf("%d\n", script[moveScriptOfs + 1]);
break; break;
} }
}
// OSD_Printf("hitag: %d\n",g_sp->hitag); // OSD_Printf("hitag: %d\n",g_sp->hitag);
g_sp->z += (24<<8); g_sp->z += ACTOR_ONWATER_ADDZ;
case OCTABRAIN__STATIC:
case COMMANDER__STATIC:
case DRONE__STATIC:
break; break;
} }
}
return; return;
} }

View file

@ -204,6 +204,7 @@ int32_t __fastcall A_FindPlayer(const spritetype *s, int32_t *d)
if (!g_netServer && ud.multimode < 2) if (!g_netServer && ud.multimode < 2)
{ {
DukePlayer_t *const myps = g_player[myconnectindex].ps; DukePlayer_t *const myps = g_player[myconnectindex].ps;
*d = A_FP_ManhattanDist(myps, s); *d = A_FP_ManhattanDist(myps, s);
return myconnectindex; return myconnectindex;
} }
@ -2954,7 +2955,8 @@ int32_t A_CheckHitSprite(int32_t i, int16_t *hitsp)
if (A_CheckEnemySprite(&sprite[i])) if (A_CheckEnemySprite(&sprite[i]))
zoff = (42<<8); zoff = (42<<8);
else if (PN == APLAYER) zoff = (39<<8); else if (PN == APLAYER)
zoff = (39<<8);
SZ -= zoff; SZ -= zoff;
hitscan((const vec3_t *)&sprite[i],SECT, hitscan((const vec3_t *)&sprite[i],SECT,
@ -2966,9 +2968,9 @@ int32_t A_CheckHitSprite(int32_t i, int16_t *hitsp)
*hitsp = hit.sprite; *hitsp = hit.sprite;
if (hit.wall >= 0 && (wall[hit.wall].cstat&16) && A_CheckEnemySprite(&sprite[i])) if (hit.wall >= 0 && (wall[hit.wall].cstat&16) && A_CheckEnemySprite(&sprite[i]))
return((1<<30)); return 1<<30;
return (FindDistance2D(hit.pos.x-SX,hit.pos.y-SY)); return FindDistance2D(hit.pos.x-SX,hit.pos.y-SY);
} }
static int32_t P_FindWall(DukePlayer_t *p,int16_t *hitw) static int32_t P_FindWall(DukePlayer_t *p,int16_t *hitw)
@ -2984,7 +2986,7 @@ static int32_t P_FindWall(DukePlayer_t *p,int16_t *hitw)
if (hit.wall < 0) if (hit.wall < 0)
return INT32_MAX; return INT32_MAX;
return (FindDistance2D(hit.pos.x-p->pos.x,hit.pos.y-p->pos.y)); return FindDistance2D(hit.pos.x-p->pos.x,hit.pos.y-p->pos.y);
} }
// returns 1 if sprite i should not be considered by neartag // returns 1 if sprite i should not be considered by neartag