Skip to content

Commit

Permalink
Refactor: Moved the global gravity multiplier into GameMap
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 7, 2012
1 parent 49c56e7 commit 85ab13a
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 12 deletions.
29 changes: 28 additions & 1 deletion doomsday/engine/portable/include/gamemap.h
Expand Up @@ -112,7 +112,9 @@ typedef struct gamemap_s {
nodepile_t mobjNodes, lineNodes; // All kinds of wacky links.
nodeindex_t* lineLinks; // Indices to roots.

float globalGravity; // Gravity for the current map.
float globalGravity; // The defined gravity for this map.
float effectiveGravity; // The effective gravity for this map.

int ambientLightLevel; // Ambient lightlevel for the current map.

/// Current LOS trace state.
Expand All @@ -132,6 +134,31 @@ const char* GameMap_OldUniqueId(GameMap* map);

void GameMap_Bounds(GameMap* map, float* min, float* max);

/**
* Retrieve the current effective gravity multiplier for this map.
*
* @param map GameMap instance.
* @return Effective gravity multiplier for this map.
*/
float GameMap_Gravity(GameMap* map);

/**
* Change the effective gravity multiplier for this map.
*
* @param map GameMap instance.
* @param gravity New gravity multiplier.
* @return Same as @a map for caller convenience.
*/
GameMap* GameMap_SetGravity(GameMap* map, float gravity);

/**
* Return the effective gravity multiplier to that originally defined for this map.
*
* @param map GameMap instance.
* @return Same as @a map for caller convenience.
*/
GameMap* GameMap_RestoreGravity(GameMap* map);

/**
* Retrieve an immutable copy of the LOS trace line.
*
Expand Down
2 changes: 0 additions & 2 deletions doomsday/engine/portable/include/p_mapdata.h
Expand Up @@ -187,8 +187,6 @@ extern surfacelist_t* movingSurfaceList;
extern surfacelist_t* decoratedSurfaceList;
extern surfacelist_t* glowingSurfaceList;

extern float mapGravity;

#include "gamemap.h"

// The current map.
Expand Down
2 changes: 2 additions & 0 deletions doomsday/engine/portable/src/dam_main.c
Expand Up @@ -600,6 +600,8 @@ boolean DAM_AttemptMapLoad(const Uri* uri)
map->ambientLightLevel = 0;
}

map->effectiveGravity = map->globalGravity;

// @todo should be called from P_LoadMap() but R_InitMap requires the
// theMap to be set first.
P_SetCurrentMap(map);
Expand Down
5 changes: 3 additions & 2 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -2215,7 +2215,8 @@ void* DD_GetVariable(int ddvalue)
return &cplrThrustMul;*/

case DD_GRAVITY:
return &mapGravity;
valueF = theMap? GameMap_Gravity(theMap) : 0;
return &valueF;

case DD_TORCH_RED:
return &torchColor[CR];
Expand Down Expand Up @@ -2289,7 +2290,7 @@ void DD_SetVariable(int ddvalue, void *parm)
return;*/

case DD_GRAVITY:
mapGravity = *(float*) parm;
if(theMap) GameMap_SetGravity(theMap, *(float*) parm);
return;

case DD_PSPRITE_OFFSET_X:
Expand Down
20 changes: 20 additions & 0 deletions doomsday/engine/portable/src/gamemap.c
Expand Up @@ -54,6 +54,26 @@ void GameMap_Bounds(GameMap* map, float* min, float* max)
max[VY] = map->bBox[BOXTOP];
}

float GameMap_Gravity(GameMap* map)
{
assert(map);
return map->effectiveGravity;
}

GameMap* GameMap_SetGravity(GameMap* map, float gravity)
{
assert(map);
map->effectiveGravity = gravity;
return map;
}

GameMap* GameMap_RestoreGravity(GameMap* map)
{
assert(map);
map->effectiveGravity = map->globalGravity;
return map;
}

const divline_t* GameMap_TraceLOS(GameMap* map)
{
assert(map);
Expand Down
6 changes: 0 additions & 6 deletions doomsday/engine/portable/src/p_data.c
Expand Up @@ -64,8 +64,6 @@ surfacelist_t* movingSurfaceList = NULL;
surfacelist_t* decoratedSurfaceList = NULL;
surfacelist_t* glowingSurfaceList = NULL;

float mapGravity;

GameMap* theMap = NULL;

// Bad texture list
Expand Down Expand Up @@ -139,8 +137,6 @@ void P_SetCurrentMap(GameMap* map)
decoratedSurfaceList = 0;
glowingSurfaceList = 0;

mapGravity = 0;

theMap = map;
return;
}
Expand All @@ -161,8 +157,6 @@ void P_SetCurrentMap(GameMap* map)
decoratedSurfaceList = &map->decoratedSurfaceList;
glowingSurfaceList = &map->glowingSurfaceList;

mapGravity = map->globalGravity;

theMap = map;
}

Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/src/p_particle.c
Expand Up @@ -1083,7 +1083,8 @@ static void P_MoveParticle(ptcgen_t* gen, particle_t* pt)
P_SpinParticle(gen, pt);

// Changes to momentum.
pt->mov[VZ] -= FixedMul(FLT2FIX(mapGravity), st->gravity);
/// @fixme Do not assume generator is from the CURRENT map.
pt->mov[VZ] -= FixedMul(FLT2FIX(GameMap_Gravity(theMap)), st->gravity);

// Vector force.
if(stDef->vectorForce[VX] != 0 || stDef->vectorForce[VY] != 0 ||
Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/common/src/d_netcl.c
Expand Up @@ -139,6 +139,7 @@ void NetCl_UpdateGameState(Reader* msg)
}

// Set gravity.
/// @fixme This is a map-property, not a global property.
DD_SetVariable(DD_GRAVITY, &gsGravity);

// Camera init included?
Expand Down

0 comments on commit 85ab13a

Please sign in to comment.