Skip to content

Commit

Permalink
Changes to setting position of things in map
Browse files Browse the repository at this point in the history
More testing is required, but this hopefully will fix issue #55...
  • Loading branch information
bradharding committed Nov 9, 2014
1 parent e24cfbc commit acd1b20
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 41 deletions.
8 changes: 5 additions & 3 deletions src/p_map.c
Expand Up @@ -2065,8 +2065,12 @@ void P_CreateSecNodeList(mobj_t *thing, fixed_t x, fixed_t y)
// added or verified as needed, m_thing will be set properly. When
// finished, delete all nodes where m_thing is still NULL. These
// represent the sectors the Thing has vacated.
for (node = thing->old_sectorlist; node; node = node->m_tnext)
node = sector_list;
while (node)
{
node->m_thing = NULL;
node = node->m_tnext;
}

tmthing = thing;
tmflags = thing->flags;
Expand All @@ -2086,8 +2090,6 @@ void P_CreateSecNodeList(mobj_t *thing, fixed_t x, fixed_t y)
yl = (tmbbox[BOXBOTTOM] - bmaporgy) >> MAPBLOCKSHIFT;
yh = (tmbbox[BOXTOP] - bmaporgy) >> MAPBLOCKSHIFT;

sector_list = thing->old_sectorlist;

for (bx = xl; bx <= xh; bx++)
for (by = yl; by <= yh; by++)
P_BlockLinesIterator(bx, by, PIT_GetSectors);
Expand Down
40 changes: 19 additions & 21 deletions src/p_maputl.c
Expand Up @@ -192,13 +192,13 @@ void P_UnsetThingPosition(mobj_t *thing)
{
// inert things don't need to be in blockmap?
// unlink from subsector
if (thing->snext)
thing->snext->sprev = thing->sprev;

if (thing->sprev)
thing->sprev->snext = thing->snext;
else
thing->subsector->sector->thinglist = thing->snext;
//
// killough 8/11/98: simpler scheme using pointers-to-pointers for prev
// pointers, allows head node pointers to be treated like everything else
mobj_t **sprev = thing->sprev;
mobj_t *snext = thing->snext;
if ((*sprev = snext)) // unlink from sector list
snext->sprev = sprev;

// phares 3/14/98
//
Expand All @@ -212,8 +212,8 @@ void P_UnsetThingPosition(mobj_t *thing)
//
// If this Thing is being removed entirely, then the calling
// routine will clear out the nodes in sector_list.
thing->old_sectorlist = thing->touching_sectorlist;
thing->touching_sectorlist = NULL; // to be restored by P_SetThingPosition
sector_list = thing->touching_sectorlist;
thing->touching_sectorlist = NULL; // to be restored by P_SetThingPosition
}

if (!(thing->flags & MF_NOBLOCKMAP))
Expand Down Expand Up @@ -243,24 +243,22 @@ void P_UnsetThingPosition(mobj_t *thing)
//
void P_SetThingPosition(mobj_t *thing)
{
subsector_t *ss;

// link into subsector
ss = R_PointInSubsector(thing->x, thing->y);
thing->subsector = ss;
subsector_t *ss = thing->subsector = R_PointInSubsector(thing->x, thing->y);

if (!(thing->flags & MF_NOSECTOR))
{
// invisible things don't go into the sector links
sector_t *sec = ss->sector;

thing->sprev = NULL;
thing->snext = sec->thinglist;

if (sec->thinglist)
sec->thinglist->sprev = thing;
// killough 8/11/98: simpler scheme using pointer-to-pointer prev
// pointers, allows head nodes to be treated like everything else
mobj_t **link = &ss->sector->thinglist;
mobj_t *snext = *link;

sec->thinglist = thing;
if ((thing->snext = snext))
snext->sprev = &thing->snext;
thing->sprev = link;
*link = thing;

// phares 3/16/98
//
Expand All @@ -276,7 +274,7 @@ void P_SetThingPosition(mobj_t *thing)
// added, new sector links are created.
P_CreateSecNodeList(thing, thing->x, thing->y);
thing->touching_sectorlist = sector_list; // Attach to Thing's mobj_t
thing->old_sectorlist = NULL; // clear for next time
sector_list = NULL; // clear for next time
}

// link into blockmap
Expand Down
8 changes: 5 additions & 3 deletions src/p_mobj.c
Expand Up @@ -679,11 +679,13 @@ void P_RemoveMobj(mobj_t *mobj)
P_UnsetThingPosition(mobj);

// Delete all nodes on the current sector_list
if (mobj->old_sectorlist)
P_DelSeclist(mobj->old_sectorlist);
if (sector_list)
{
P_DelSeclist(sector_list);
sector_list = NULL;
}

mobj->flags |= (MF_NOSECTOR | MF_NOBLOCKMAP);
mobj->old_sectorlist = NULL;

mobj->target = mobj->tracer = mobj->lastenemy = NULL;

Expand Down
17 changes: 8 additions & 9 deletions src/p_mobj.h
Expand Up @@ -279,17 +279,17 @@ typedef struct mobj_s

// More list: links in sector (if needed)
struct mobj_s *snext;
struct mobj_s *sprev;
struct mobj_s **sprev; // killough 8/10/98: change to ptr-to-ptr

//More drawing info: to determine current sprite.
angle_t angle; // orientation
spritenum_t sprite; // used to find patch_t and flip value
int frame; // might be ORed with FF_FULLBRIGHT
angle_t angle; // orientation
spritenum_t sprite; // used to find patch_t and flip value
int frame; // might be ORed with FF_FULLBRIGHT

// Interaction info, by BLOCKMAP.
// Links in blocks (if needed).
struct mobj_s *bnext;
struct mobj_s **bprev; // killough 8/11/98: change to ptr-to-ptr
struct mobj_s **bprev; // killough 8/11/98: change to ptr-to-ptr

struct subsector_s *subsector;

Expand All @@ -315,9 +315,9 @@ typedef struct mobj_s
int validcount;

mobjtype_t type;
mobjinfo_t *info; // &mobjinfo[mobj->type]
mobjinfo_t *info; // &mobjinfo[mobj->type]

int tics; // state tic counter
int tics; // state tic counter
state_t *state;
int flags;
int flags2;
Expand Down Expand Up @@ -362,9 +362,8 @@ typedef struct mobj_s

// a linked list of sectors where this object appears
struct msecnode_s *touching_sectorlist; // phares 3/14/98
struct msecnode_s *old_sectorlist; // haleyjd 04/16/10

short gear; // killough 11/98: used in torque simulation
short gear; // killough 11/98: used in torque simulation

int bloodsplats;

Expand Down
7 changes: 2 additions & 5 deletions src/p_saveg.c
Expand Up @@ -286,8 +286,8 @@ static void saveg_read_mobj_t(mobj_t *str)
// struct mobj_s *snext
str->snext = (mobj_t *)saveg_readp();

// struct mobj_s *sprev
str->sprev = (mobj_t *)saveg_readp();
// struct mobj_s **sprev
str->sprev = (mobj_t **)saveg_readp();

// angle_t angle
str->angle = saveg_read32();
Expand Down Expand Up @@ -400,9 +400,6 @@ static void saveg_read_mobj_t(mobj_t *str)
// struct msecnode_s *touching_sectorlist
str->touching_sectorlist = NULL;

// struct msecnode_s *old_sectorlist
str->old_sectorlist = NULL;

// short gear
str->gear = saveg_read16();

Expand Down

0 comments on commit acd1b20

Please sign in to comment.