Skip to content

Commit

Permalink
Fixed|All Games: Update Mobj "selector" health bits immediately on spawn
Browse files Browse the repository at this point in the history
The "selector" is used when determining which skin to use for any
3D model defined for some mobj state. The health bits were not being
setup until P_MobjThinker was run for the first time, resulting in
the wrong skin being used during the screenwipe/transition.

Todo: There is likely a similar issue with the player - check that the
weapon bits are being set correctly.
  • Loading branch information
danij-deng committed Jun 28, 2012
1 parent ac1a3ef commit d93e298
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
5 changes: 5 additions & 0 deletions doomsday/plugins/common/include/p_actor.h
Expand Up @@ -44,7 +44,12 @@ void P_MobjAngleSRVOTicker(mobj_t* mo);

boolean P_MobjIsCamera(const mobj_t* mo);

/**
* The first three bits of the selector special byte contain a relative
* health level.
*/
void P_UpdateHealthBits(mobj_t* mo);

statenum_t P_GetState(mobjtype_t mobjType, statename_t name);

void P_ProcessDeferredSpawns(void);
Expand Down
24 changes: 10 additions & 14 deletions doomsday/plugins/common/src/p_actor.c
Expand Up @@ -270,23 +270,19 @@ boolean P_MobjIsCamera(const mobj_t* mo)
(mo->player->plr->flags & DDPF_CAMERA));
}

/**
* The first three bits of the selector special byte contain a relative
* health level.
*/
void P_UpdateHealthBits(mobj_t* mobj)
void P_UpdateHealthBits(mobj_t* mo)
{
int i;
int i;
if(!mo || !mo->info) return;

if(mobj->info && mobj->info->spawnHealth > 0)
if(mo->info->spawnHealth > 0)
{
mobj->selector &= DDMOBJ_SELECTOR_MASK; // Clear high byte.
i = (mobj->health << 3) / mobj->info->spawnHealth;
if(i > 7)
i = 7;
if(i < 0)
i = 0;
mobj->selector |= i << DDMOBJ_SELECTOR_SHIFT;
mo->selector &= DDMOBJ_SELECTOR_MASK; // Clear high byte.

i = (mo->health << 3) / mo->info->spawnHealth;
i = MINMAX_OF(0, i, 7);

mo->selector |= i << DDMOBJ_SELECTOR_SHIFT;
}
}

Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/jdoom/src/p_mobj.c
Expand Up @@ -819,6 +819,7 @@ mobj_t* P_SpawnMobjXYZ(mobjtype_t type, coord_t x, coord_t y, coord_t z, angle_t

// Spectres get selector = 1.
mo->selector = (type == MT_SHADOWS)? 1 : 0;
P_UpdateHealthBits(mo); // Set the health bits of the selector.

// Let the engine know about solid objects.
P_SetDoomsdayFlags(mo);
Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/jdoom64/src/p_mobj.c
Expand Up @@ -839,6 +839,7 @@ mobj_t* P_SpawnMobjXYZ(mobjtype_t type, coord_t x, coord_t y, coord_t z, angle_t

// Spectres get selector = 1.
mo->selector = (type == MT_SHADOWS)? 1 : 0;
P_UpdateHealthBits(mo); // Set the health bits of the selector.

mo->reactionTime = info->reactionTime;

Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/jheretic/src/p_mobj.c
Expand Up @@ -1065,6 +1065,7 @@ mobj_t* P_SpawnMobjXYZ(mobjtype_t type, coord_t x, coord_t y, coord_t z,
mo->health = info->spawnHealth * (IS_NETGAME ? cfg.netMobHealthModifier : 1);
mo->moveDir = DI_NODIR;
mo->selector = 0;
P_UpdateHealthBits(mo); // Set the health bits of the selector.

if(gameSkill != SM_NIGHTMARE)
mo->reactionTime = info->reactionTime;
Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/jhexen/src/p_mobj.c
Expand Up @@ -1251,6 +1251,7 @@ mobj_t* P_SpawnMobjXYZ(mobjtype_t type, coord_t x, coord_t y, coord_t z,
mo->health = info->spawnHealth * (IS_NETGAME ? cfg.netMobHealthModifier : 1);
mo->moveDir = DI_NODIR;
mo->selector = 0;
P_UpdateHealthBits(mo); // Set the health bits of the selector.

if(gameSkill != SM_NIGHTMARE)
{
Expand Down

0 comments on commit d93e298

Please sign in to comment.