Skip to content

Commit

Permalink
Refactor|All Games|libcommon: Use ThinkerT for allocating and copying…
Browse files Browse the repository at this point in the history
… thinkers

Todo: There may be more instances of copying in the C sources, must
look for those and/or convert everything to C++.
  • Loading branch information
skyjake committed Jul 25, 2014
1 parent 3978f7e commit ede6fcb
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion doomsday/plugins/common/include/p_xgline.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ typedef struct {
DENG_EXTERN_C struct xgclass_s xgClasses[];

// Used as the activator if there is no real activator.
DENG_EXTERN_C struct mobj_s dummyThing;
DENG_EXTERN_C struct mobj_s *XG_DummyThing();

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/mapstatereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ DENG2_PIMPL(MapStateReader)
}
else
{
th = reinterpret_cast<thinker_t *>(Z_Calloc(thInfo->size, PU_MAP, 0));
th = Thinker(Thinker::AllocateMemoryZone, thInfo->size).take();
}

bool putThinkerInStasis = (formatHasStasisInfo? CPP_BOOL(Reader_ReadByte(reader)) : false);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/mobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ void mobj_s::write(MapStateWriter *msw) const
Writer *writer = msw->writer();

mobj_t const *original = (mobj_t *) this;
mobj_t temp, *mo = &temp;
ThinkerT<mobj_t> temp(*original);
mobj_t *mo = temp;

std::memcpy(mo, original, sizeof(*mo));
// Mangle it!
mo->state = (state_t *) (mo->state - STATES);
if(mo->player)
Expand Down
8 changes: 4 additions & 4 deletions doomsday/plugins/common/src/p_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,7 @@ static int PTR_ShootTraverse(Intercept const *icpt, void *context)
if(parm.puffType == MT_FLAMEPUFF2)
{
// Cleric FlameStrike does fire damage.
inflictor = &lavaInflictor;
inflictor = P_LavaInflictor();
}
#endif

Expand Down Expand Up @@ -2926,7 +2926,7 @@ mobj_t *P_CheckOnMobj(mobj_t *mo)
*
* @todo Do this properly! Consolidate with how jDoom/jHeretic do on-mobj checks?
*/
mobj_t oldMo = *mo; // Save the old mobj before the fake z movement.
ThinkerT<mobj_t> oldMo(*mo); // Save the old mobj before the fake z movement.

// Adjust Z-origin.
mo->origin[VZ] += mo->mom[MZ];
Expand Down Expand Up @@ -3045,14 +3045,14 @@ mobj_t *P_CheckOnMobj(mobj_t *mo)
if(Mobj_BoxIterator(&aaBox, PIT_CheckOnMobjZ, &parm))
{
// Restore the mobj back to its previous state.
*mo = oldMo;
oldMo.putInto(*mo);

return parm.mountMobj;
}
}

// Restore the mobj back to its previous state.
*mo = oldMo;
oldMo.putInto(*mo);

return 0;
}
Expand Down
11 changes: 8 additions & 3 deletions doomsday/plugins/common/src/p_xgline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ int xgDev = 0; // Print dev messages.

static linetype_t typebuffer;
static char msgbuf[80];
struct mobj_s dummyThing;
ThinkerT<mobj_s> dummyThing;

struct mobj_s *XG_DummyThing()
{
return dummyThing;
}

/* ADD NEW XG CLASSES TO THE END - ORIGINAL INDICES MUST STAY THE SAME!!! */
xgclass_t xgClasses[NUMXGCLASSES] =
Expand Down Expand Up @@ -935,7 +940,7 @@ void XL_SetLineType(Line *line, int id)

// Initial active state.
xline->xg->active = (typebuffer.flags & LTF_ACTIVE) != 0;
xline->xg->activator = &dummyThing;
xline->xg->activator = dummyThing;

XG_Dev("XL_SetLineType: Line %i (%s), ID %i.", P_ToIndex(line),
xgClasses[xline->xg->info.lineClass].className, id);
Expand Down Expand Up @@ -2992,7 +2997,7 @@ void XL_Thinker(void *xlThinkerPtr)
xg->active ? "INACTIVE" : "ACTIVE");

// Swap line state without any checks.
XL_ActivateLine(!xg->active, info, line, 0, &dummyThing, XLE_AUTO);
XL_ActivateLine(!xg->active, info, line, 0, dummyThing, XLE_AUTO);
}
}

Expand Down
10 changes: 5 additions & 5 deletions doomsday/plugins/common/src/p_xgsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,13 @@ void XS_MoverStopped(xgplanemover_t *mover, dd_bool done)
if((mover->flags & PMF_ACTIVATE_WHEN_DONE) && mover->origin)
{
XL_ActivateLine(true, &origin->xg->info, mover->origin, 0,
&dummyThing, XLE_AUTO);
XG_DummyThing(), XLE_AUTO);
}

if((mover->flags & PMF_DEACTIVATE_WHEN_DONE) && mover->origin)
{
XL_ActivateLine(false, &origin->xg->info, mover->origin, 0,
&dummyThing, XLE_AUTO);
XG_DummyThing(), XLE_AUTO);
}

// Remove this thinker.
Expand All @@ -446,13 +446,13 @@ void XS_MoverStopped(xgplanemover_t *mover, dd_bool done)
if((mover->flags & PMF_ACTIVATE_ON_ABORT) && mover->origin)
{
XL_ActivateLine(true, &origin->xg->info, mover->origin, 0,
&dummyThing, XLE_AUTO);
XG_DummyThing(), XLE_AUTO);
}

if((mover->flags & PMF_DEACTIVATE_ON_ABORT) && mover->origin)
{
XL_ActivateLine(false, &origin->xg->info, mover->origin, 0,
&dummyThing, XLE_AUTO);
XG_DummyThing(), XLE_AUTO);
}

if(mover->flags & (PMF_ACTIVATE_ON_ABORT | PMF_DEACTIVATE_ON_ABORT))
Expand Down Expand Up @@ -2907,7 +2907,7 @@ void XS_Thinker(xsthinker_t* xs)
{
XS_DoChain(sector, XSCE_TICKER,
!(info->chainFlags[XSCE_TICKER] & SCEF_TICKER_D),
&dummyThing);
XG_DummyThing());
}

// Play ambient sounds.
Expand Down
14 changes: 7 additions & 7 deletions doomsday/plugins/heretic/src/p_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ enum afxcmd_t
static void P_CrossSpecialLine(Line *line, int side, mobj_t *thing);
static void P_ShootSpecialLine(mobj_t *thing, Line *line);

mobj_t LavaInflictor;
ThinkerT<mobj_t> LavaInflictor;

int *LevelAmbientSfx[MAX_AMBIENT_SFX];
int *AmbSfxPtr;
Expand Down Expand Up @@ -638,7 +638,7 @@ void P_PlayerInSpecialSector(player_t *player)
// LAVA DAMAGE WEAK
if(!(mapTime & 15))
{
P_DamageMobj(player->plr->mo, &LavaInflictor, NULL, 5, false);
P_DamageMobj(player->plr->mo, LavaInflictor, NULL, 5, false);
P_HitFloor(player->plr->mo);
}
break;
Expand All @@ -653,7 +653,7 @@ void P_PlayerInSpecialSector(player_t *player)
// LAVA DAMAGE HEAVY
if(!(mapTime & 15))
{
P_DamageMobj(player->plr->mo, &LavaInflictor, NULL, 8, false);
P_DamageMobj(player->plr->mo, LavaInflictor, NULL, 8, false);
P_HitFloor(player->plr->mo);
}
break;
Expand All @@ -663,7 +663,7 @@ void P_PlayerInSpecialSector(player_t *player)
P_Thrust(player, 0, FIX2FLT(2048 * 28));
if(!(mapTime & 15))
{
P_DamageMobj(player->plr->mo, &LavaInflictor, NULL, 5, false);
P_DamageMobj(player->plr->mo, LavaInflictor, NULL, 5, false);
P_HitFloor(player->plr->mo);
}
break;
Expand Down Expand Up @@ -786,9 +786,9 @@ void P_SpawnAllSpecialThinkers()

void P_InitLava()
{
std::memset(&LavaInflictor, 0, sizeof(mobj_t));
LavaInflictor.type = MT_PHOENIXFX2;
LavaInflictor.flags2 = MF2_FIREDAMAGE | MF2_NODMGTHRUST;
LavaInflictor = ThinkerT<mobj_t>();
LavaInflictor->type = MT_PHOENIXFX2;
LavaInflictor->flags2 = MF2_FIREDAMAGE | MF2_NODMGTHRUST;
}

void P_PlayerInWindSector(player_t *player)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/hexen/include/p_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#define MO_TELEPORTMAN 14

DENG_EXTERN_C mobj_t lavaInflictor;
DENG_EXTERN_C mobj_t *P_LavaInflictor();
DENG_EXTERN_C mobjtype_t TranslateThingType[];

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/hexen/src/p_mobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ dd_bool P_HitFloor(mobj_t *thing)
S_StartSound(SFX_LAVA_SIZZLE, mo);
if(thing->player && mapTime & 31)
{
P_DamageMobj(thing, &lavaInflictor, NULL, 5, false);
P_DamageMobj(thing, P_LavaInflictor(), NULL, 5, false);
}
return true;
}
Expand Down
15 changes: 10 additions & 5 deletions doomsday/plugins/hexen/src/p_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ using namespace common;
static void P_LightningFlash(void);
static dd_bool CheckedLockedDoor(mobj_t* mo, byte lock);

mobj_t lavaInflictor;
ThinkerT<mobj_t> lavaInflictor;

mobj_t *P_LavaInflictor()
{
return lavaInflictor;
}

materialid_t sky1Material;
materialid_t sky2Material;
Expand All @@ -71,10 +76,10 @@ static float *lightningLightLevels;

void P_InitLava(void)
{
memset(&lavaInflictor, 0, sizeof(mobj_t));
lavaInflictor = ThinkerT<mobj_t>();

lavaInflictor.type = MT_CIRCLEFLAME;
lavaInflictor.flags2 = MF2_FIREDAMAGE | MF2_NODMGTHRUST;
lavaInflictor->type = MT_CIRCLEFLAME;
lavaInflictor->flags2 = MF2_FIREDAMAGE | MF2_NODMGTHRUST;
}

void P_InitSky(de::Uri const &mapUri)
Expand Down Expand Up @@ -811,7 +816,7 @@ void P_PlayerOnSpecialFloor(player_t* player)

if(!(mapTime & 31))
{
P_DamageMobj(player->plr->mo, &lavaInflictor, NULL, 10, false);
P_DamageMobj(player->plr->mo, P_LavaInflictor(), NULL, 10, false);
S_StartSound(SFX_LAVA_SIZZLE, player->plr->mo);
}
}
Expand Down

0 comments on commit ede6fcb

Please sign in to comment.