Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added a void* context paramater to the deferred spawn callback.
  • Loading branch information
danij committed Jun 17, 2009
1 parent 21ed3fe commit 5de5081
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
6 changes: 4 additions & 2 deletions doomsday/plugins/common/include/p_actor.h
Expand Up @@ -49,9 +49,11 @@ void P_PurgeDeferredSpawns(void);
void P_DeferSpawnMobj3f(int minTics, mobjtype_t type, float x,
float y, float z, angle_t angle,
int spawnFlags,
void (*callback) (mobj_t* mo));
void (*callback) (mobj_t* mo, void* context),
void* context);
void P_DeferSpawnMobj3fv(int minTics, mobjtype_t type,
const float pos[3], angle_t angle,
int spawnFlags,
void (*callback) (mobj_t* mo));
void (*callback) (mobj_t* mo, void* context),
void* context);
#endif
30 changes: 19 additions & 11 deletions doomsday/plugins/common/src/p_actor.c
Expand Up @@ -63,7 +63,9 @@ typedef struct spawnqueuenode_s {
int startTime;
int minTics; // Minimum number of tics before respawn.
mapspot_t spot;
void (*callback) (mobj_t* mo);
void (*callback) (mobj_t* mo, void* context);
void* context;

struct spawnqueuenode_s* next;
} spawnqueuenode_t;

Expand All @@ -83,7 +85,7 @@ static spawnqueuenode_t* spawnQueueHead = NULL;

// CODE --------------------------------------------------------------------

void P_SpawnTelefog(mobj_t* mo)
void P_SpawnTelefog(mobj_t* mo, void* context)
{
#if __JDOOM__ || __JDOOM64__
S_StartSound(SFX_ITMBK, mo);
Expand Down Expand Up @@ -131,7 +133,7 @@ void P_MobjRemove(mobj_t* mo, boolean noRespawn)
{
P_DeferSpawnMobj3fv(RESPAWNTICS, mo->type, mo->spawnSpot.pos,
mo->spawnSpot.angle, mo->spawnSpot.flags,
P_SpawnTelefog);
P_SpawnTelefog, NULL);
}
}
#endif
Expand Down Expand Up @@ -351,7 +353,8 @@ static void emptySpawnQueue(void)

static void enqueueSpawn(int minTics, mobjtype_t type, float x, float y,
float z, angle_t angle, int spawnFlags,
void (*callback) (mobj_t* mo))
void (*callback) (mobj_t* mo, void* context),
void* context)
{
spawnqueuenode_t* n = Z_Malloc(sizeof(*n), PU_MAP, 0);

Expand All @@ -364,7 +367,9 @@ static void enqueueSpawn(int minTics, mobjtype_t type, float x, float y,

n->startTime = mapTime;
n->minTics = minTics;

n->callback = callback;
n->context = context;

if(spawnQueueHead)
{ // Find the correct insertion point.
Expand Down Expand Up @@ -417,7 +422,7 @@ static mobj_t* doDeferredSpawn(void)
spot->flags)))
{
if(n->callback)
n->callback(mo);
n->callback(mo, n->context);
}

Z_Free(n);
Expand All @@ -432,11 +437,13 @@ static mobj_t* doDeferredSpawn(void)
*/
void P_DeferSpawnMobj3f(int minTics, mobjtype_t type, float x, float y,
float z, angle_t angle, int spawnFlags,
void (*callback) (mobj_t* mo))
void (*callback) (mobj_t* mo, void* context),
void* context)
{
if(minTics > 0)
{
enqueueSpawn(minTics, type, x, y, z, angle, spawnFlags, callback);
enqueueSpawn(minTics, type, x, y, z, angle, spawnFlags, callback,
context);
}
else // Spawn immediately.
{
Expand All @@ -445,19 +452,20 @@ void P_DeferSpawnMobj3f(int minTics, mobjtype_t type, float x, float y,
if((mo = P_SpawnMobj3f(type, x, y, z, angle, spawnFlags)))
{
if(callback)
callback(mo);
callback(mo, context);
}
}
}

void P_DeferSpawnMobj3fv(int minTics, mobjtype_t type, const float pos[3],
angle_t angle, int spawnFlags,
void (*callback) (mobj_t* mo))
void (*callback) (mobj_t* mo, void* context),
void* context)
{
if(minTics > 0)
{
enqueueSpawn(minTics, type, pos[VX], pos[VY], pos[VZ], angle,
spawnFlags, callback);
spawnFlags, callback, context);
}
else // Spawn immediately.
{
Expand All @@ -466,7 +474,7 @@ void P_DeferSpawnMobj3fv(int minTics, mobjtype_t type, const float pos[3],
if((mo = P_SpawnMobj3fv(type, pos, angle, spawnFlags)))
{
if(callback)
callback(mo);
callback(mo, context);
}
}
}
Expand Down

0 comments on commit 5de5081

Please sign in to comment.