Fix up them there ghosts!

* Stop orphaning their memory. They ARE PU_LEVEL, so they'll disappear eventually, but, like... it's not good memory management practice to just *orphan* them when you're literally never going to do anything with them ever again. Y'know?
* Make ghosts spawn properly on slopes.
This commit is contained in:
toaster 2018-08-25 17:11:49 +01:00
parent 9d3aad9036
commit 91eb248e46
1 changed files with 21 additions and 15 deletions

View File

@ -4362,6 +4362,7 @@ void G_GhostTicker(void)
p->next = g->next; p->next = g->next;
else else
ghosts = g->next; ghosts = g->next;
Z_Free(g);
continue; continue;
} }
p = g; p = g;
@ -5314,29 +5315,28 @@ void G_AddGhost(char *defdemoname)
mthing = playerstarts[0]; mthing = playerstarts[0];
I_Assert(mthing); I_Assert(mthing);
{ // A bit more complex than P_SpawnPlayer because ghosts aren't solid and won't just push themselves out of the ceiling. { // A bit more complex than P_SpawnPlayer because ghosts aren't solid and won't just push themselves out of the ceiling.
fixed_t x,y,z; fixed_t z,f,c;
sector_t *sector; gh->mo = P_SpawnMobj(mthing->x << FRACBITS, mthing->y << FRACBITS, 0, MT_GHOST);
x = mthing->x << FRACBITS; gh->mo->angle = FixedAngle(mthing->angle*FRACUNIT);
y = mthing->y << FRACBITS; f = gh->mo->floorz;
sector = R_PointInSubsector(x, y)->sector; c = gh->mo->ceilingz - mobjinfo[MT_PLAYER].height;
if (!!(mthing->options & MTF_AMBUSH) ^ !!(mthing->options & MTF_OBJECTFLIP)) if (!!(mthing->options & MTF_AMBUSH) ^ !!(mthing->options & MTF_OBJECTFLIP))
{ {
z = sector->ceilingheight - mobjinfo[MT_PLAYER].height; z = c;
if (mthing->options >> ZSHIFT) if (mthing->options >> ZSHIFT)
z -= ((mthing->options >> ZSHIFT) << FRACBITS); z -= ((mthing->options >> ZSHIFT) << FRACBITS);
if (z < sector->floorheight) if (z < f)
z = sector->floorheight; z = f;
} }
else else
{ {
z = sector->floorheight; z = f;
if (mthing->options >> ZSHIFT) if (mthing->options >> ZSHIFT)
z += ((mthing->options >> ZSHIFT) << FRACBITS); z += ((mthing->options >> ZSHIFT) << FRACBITS);
if (z > sector->ceilingheight - mobjinfo[MT_PLAYER].height) if (z > c)
z = sector->ceilingheight - mobjinfo[MT_PLAYER].height; z = c;
} }
gh->mo = P_SpawnMobj(x, y, z, MT_GHOST); gh->mo->z = z;
gh->mo->angle = FixedAngle(mthing->angle*FRACUNIT);
} }
gh->mo->state = states+S_PLAY_STND; gh->mo->state = states+S_PLAY_STND;
gh->mo->sprite = gh->mo->state->sprite; gh->mo->sprite = gh->mo->state->sprite;
@ -5534,8 +5534,14 @@ boolean G_CheckDemoStatus(void)
{ {
boolean saved; boolean saved;
if(ghosts) // ... ... ... while (ghosts)
ghosts = NULL; // :) {
demoghost *next = ghosts->next;
Z_Free(ghosts);
ghosts = next;
}
ghosts = NULL;
// DO NOT end metal sonic demos here // DO NOT end metal sonic demos here