Skip to content

Commit b22be23

Browse files
authored
Use Boom's P_UnsetThingPosition()/P_SetThingPosition() for Boom and earlier (#670)
1 parent 8281bff commit b22be23

File tree

3 files changed

+144
-9
lines changed

3 files changed

+144
-9
lines changed

prboom2/src/p_maputl.c

Lines changed: 139 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,58 @@ void P_LineOpening(const line_t *linedef, const mobj_t *actor)
317317
// these structures need to be updated.
318318
//
319319

320-
void P_UnsetThingPosition (mobj_t *thing)
320+
static void P_UnsetThingPosition_Boom (mobj_t *thing)
321+
{
322+
if (!(thing->flags & MF_NOSECTOR))
323+
{
324+
// inert things don't need to be in blockmap?
325+
// unlink from subsector
326+
if (thing->snext)
327+
thing->snext->sprev = thing->sprev;
328+
329+
if (thing->sprev)
330+
((mobj_t *)thing->sprev)->snext = thing->snext;
331+
else
332+
thing->subsector->sector->thinglist = thing->snext;
333+
334+
// phares 3/14/98
335+
//
336+
// Save the sector list pointed to by touching_sectorlist.
337+
// In P_SetThingPosition, we'll keep any nodes that represent
338+
// sectors the Thing still touches. We'll add new ones then, and
339+
// delete any nodes for sectors the Thing has vacated. Then we'll
340+
// put it back into touching_sectorlist. It's done this way to
341+
// avoid a lot of deleting/creating for nodes, when most of the
342+
// time you just get back what you deleted anyway.
343+
//
344+
// If this Thing is being removed entirely, then the calling
345+
// routine will clear out the nodes in sector_list.
346+
347+
sector_list = thing->touching_sectorlist;
348+
thing->touching_sectorlist = NULL; //to be restored by P_SetThingPosition
349+
}
350+
351+
if (!(thing->flags & MF_NOBLOCKMAP))
352+
{
353+
// inert things don't need to be in blockmap
354+
355+
if (thing->bnext) // unlink from block map
356+
thing->bnext->bprev = thing->bprev;
357+
358+
if (thing->bprev)
359+
((mobj_t *)thing->bprev)->bnext = thing->bnext;
360+
else
361+
{
362+
int blockx = (thing->x - bmaporgx)>>MAPBLOCKSHIFT;
363+
int blocky = (thing->y - bmaporgy)>>MAPBLOCKSHIFT;
364+
if (blockx>=0 && blockx < bmapwidth &&
365+
blocky>=0 && blocky <bmapheight)
366+
blocklinks[blocky*bmapwidth+blockx] = thing->bnext;
367+
}
368+
}
369+
}
370+
371+
static void P_UnsetThingPosition_MBF (mobj_t *thing)
321372
{
322373
if (!(thing->flags & MF_NOSECTOR))
323374
{
@@ -377,7 +428,61 @@ void P_UnsetThingPosition (mobj_t *thing)
377428
//
378429
// killough 5/3/98: reformatted, cleaned up
379430

380-
void P_SetThingPosition(mobj_t *thing)
431+
static void P_SetThingPosition_Boom(mobj_t *thing)
432+
{ // link into subsector
433+
subsector_t *ss = thing->subsector = R_PointInSubsector(thing->x, thing->y);
434+
if (!(thing->flags & MF_NOSECTOR))
435+
{
436+
// invisible things don't go into the sector links
437+
sector_t *sec = ss->sector;
438+
439+
thing->sprev = NULL;
440+
thing->snext = sec->thinglist;
441+
442+
if (sec->thinglist)
443+
sec->thinglist->sprev = (mobj_t **)thing;
444+
445+
sec->thinglist = thing;
446+
447+
// phares 3/16/98
448+
//
449+
// If sector_list isn't NULL, it has a collection of sector
450+
// nodes that were just removed from this Thing.
451+
452+
// Collect the sectors the object will live in by looking at
453+
// the existing sector_list and adding new nodes and deleting
454+
// obsolete ones.
455+
456+
// When a node is deleted, its sector links (the links starting
457+
// at sector_t->touching_thinglist) are broken. When a node is
458+
// added, new sector links are created.
459+
460+
P_CreateSecNodeList(thing,thing->x,thing->y);
461+
thing->touching_sectorlist = sector_list; // Attach to Thing's mobj_t
462+
sector_list = NULL; // clear for next time
463+
}
464+
465+
// link into blockmap
466+
if (!(thing->flags & MF_NOBLOCKMAP))
467+
{
468+
// inert things don't need to be in blockmap
469+
int blockx = (thing->x - bmaporgx)>>MAPBLOCKSHIFT;
470+
int blocky = (thing->y - bmaporgy)>>MAPBLOCKSHIFT;
471+
if (blockx>=0 && blockx < bmapwidth && blocky>=0 && blocky < bmapheight)
472+
{
473+
mobj_t **link = &blocklinks[blocky*bmapwidth+blockx];
474+
thing->bprev = NULL;
475+
thing->bnext = *link;
476+
if (*link)
477+
(*link)->bprev = (mobj_t **)thing;
478+
*link = thing;
479+
}
480+
else // thing is off the map
481+
thing->bnext = NULL, thing->bprev = NULL;
482+
}
483+
}
484+
485+
static void P_SetThingPosition_MBF(mobj_t *thing)
381486
{ // link into subsector
382487
subsector_t *ss = thing->subsector = R_PointInSubsector(thing->x, thing->y);
383488
if (!(thing->flags & MF_NOSECTOR))
@@ -435,6 +540,24 @@ void P_SetThingPosition(mobj_t *thing)
435540
}
436541
}
437542

543+
void (*P_UnsetThingPosition)(struct mobj_s *thing) = P_UnsetThingPosition_MBF;
544+
void (*P_SetThingPosition)(struct mobj_s *thing) = P_SetThingPosition_MBF;
545+
546+
void P_SetThingPosition_SetFuncs(void)
547+
{
548+
if (!mbf_features)
549+
{
550+
P_UnsetThingPosition = P_UnsetThingPosition_Boom;
551+
P_SetThingPosition = P_SetThingPosition_Boom;
552+
}
553+
else
554+
{
555+
P_UnsetThingPosition = P_UnsetThingPosition_MBF;
556+
P_SetThingPosition = P_SetThingPosition_MBF;
557+
}
558+
}
559+
560+
438561
//
439562
// BLOCK MAP ITERATORS
440563
// For each line/thing in the given mapblock,
@@ -609,11 +732,20 @@ dboolean P_BlockLinesIterator2(int x, int y, dboolean func(line_t*))
609732

610733
dboolean P_BlockThingsIterator(int x, int y, dboolean func(mobj_t*))
611734
{
612-
mobj_t *mobj;
613-
if (!(x<0 || y<0 || x>=bmapwidth || y>=bmapheight))
614-
for (mobj = blocklinks[y*bmapwidth+x]; mobj; mobj = mobj->bnext)
615-
if (!func(mobj))
616-
return false;
735+
mobj_t *mobj, *first;
736+
737+
if (x < 0 || y < 0 || x >= bmapwidth || y >= bmapheight)
738+
return true;
739+
740+
for (mobj = blocklinks[y*bmapwidth+x]; (first = mobj); mobj = mobj->bnext)
741+
{
742+
if (!func(mobj))
743+
return false;
744+
745+
if (mobj->bnext == first)
746+
I_Error("P_BlockThingsIterator: Infitnite loop detected!");
747+
}
748+
617749
return true;
618750
}
619751

prboom2/src/p_maputl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ extern int (*P_PointOnDivlineSide)(fixed_t x, fixed_t y, const divline_t *line);
9898
void check_intercept(void);
9999

100100
void P_LineOpening (const line_t *linedef, const mobj_t *actor);
101-
void P_UnsetThingPosition(mobj_t *thing);
102-
void P_SetThingPosition(mobj_t *thing);
101+
extern void (*P_UnsetThingPosition)(struct mobj_s *thing);
102+
extern void (*P_SetThingPosition)(struct mobj_s *thing);
103+
void P_SetThingPosition_SetFuncs (void);
103104
dboolean P_BlockLinesIterator (int x, int y, dboolean func(line_t *));
104105
dboolean P_BlockLinesIterator2(int x, int y, dboolean func(line_t *));
105106
dboolean P_BlockThingsIterator(int x, int y, dboolean func(mobj_t *));

prboom2/src/p_setup.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,6 +3835,8 @@ void P_SetupLevel(int episode, int map, int playermask, int skill)
38353835

38363836
P_MapStart();
38373837

3838+
P_SetThingPosition_SetFuncs();
3839+
38383840
if (heretic)
38393841
{
38403842
P_InitAmbientSound();

0 commit comments

Comments
 (0)