Skip to content

Commit

Permalink
Refactor|GameMap: Moved more GameMap_* functions to methods of GameMap
Browse files Browse the repository at this point in the history
Line of sight tests, BSP lookups, generator collection.
  • Loading branch information
danij-deng committed Apr 2, 2013
1 parent 179f00f commit 2d4791d
Show file tree
Hide file tree
Showing 35 changed files with 210 additions and 295 deletions.
1 change: 0 additions & 1 deletion doomsday/client/client.pro
Expand Up @@ -263,7 +263,6 @@ DENG_HEADERS += \
include/map/p_particle.h \
include/map/p_players.h \
include/map/p_polyobjs.h \
include/map/p_sight.h \
include/map/p_ticker.h \
include/map/plane.h \
include/map/polyobj.h \
Expand Down
1 change: 0 additions & 1 deletion doomsday/client/include/de_play.h
Expand Up @@ -41,7 +41,6 @@
#include "map/p_intercept.h"
#include "map/p_maputil.h"
#include "map/p_particle.h"
#include "map/p_sight.h"
#include "map/p_ticker.h"
#include "map/p_players.h"
#include "map/p_objlink.h"
Expand Down
105 changes: 62 additions & 43 deletions doomsday/client/include/map/gamemap.h
Expand Up @@ -91,8 +91,6 @@ class GameMap
boolean inited;
} thinkers;

struct generators_s *generators;

// Client only data:
cmhash_t clMobjHash[CLIENT_MOBJ_HASH_SIZE];

Expand All @@ -108,7 +106,7 @@ class GameMap
uint numPolyObjs;
Polyobj **polyObjs;

de::MapElement *bsp;
de::MapElement *_bspRoot;

/// BSP object LUTs:
HEdges hedges;
Expand All @@ -118,6 +116,8 @@ class GameMap
EntityDatabase *entityDatabase;

private:
struct generators_s *_generators;

PlaneSet _trackedPlanes;
SurfaceSet _scrollingSurfaces;
#ifdef __CLIENT__
Expand All @@ -132,7 +132,7 @@ class GameMap
struct blockmap_s *bspLeafBlockmap;

nodepile_t mobjNodes, lineNodes; // All kinds of wacky links.
nodeindex_t* lineLinks; // Indices to roots.
nodeindex_t *lineLinks; // Indices to roots.

coord_t globalGravity; // The defined gravity for this map.
coord_t effectiveGravity; // The effective gravity for this map.
Expand All @@ -159,12 +159,62 @@ class GameMap

uint lineCount() const { return lines.size(); }

/**
* Returns the root element for the map's BSP tree.
*/
de::MapElement *bspRoot() const;

uint hedgeCount() const { return hedges.count(); }

uint bspNodeCount() const { return bspNodes.count(); }

uint bspLeafCount() const { return bspLeafs.count(); }

/**
* Determine the BSP leaf on the back side of the BS partition that lies in front
* of the specified point within the map's coordinate space.
*
* @note Always returns a valid BspLeaf although the point may not actually lay
* within it (however it is on the same side of the space partition)!
*
* @param point XY coordinates of the point to test.
*
* @return BspLeaf instance for that BSP node's leaf.
*/
BspLeaf *bspLeafAtPoint(const_pvec2d_t point);

/**
* @copybrief bspLeafAtPoint()
* @param x X coordinate of the point to test.
* @param y Y coordinate of the point to test.
* @return BspLeaf instance for that BSP node's leaf.
*/
inline BspLeaf *bspLeafAtPoint(coord_t x, coord_t y) {
coord_t point[2] = { x, y };
return bspLeafAtPoint(point);
}

/**
* Traces a line of sight.
*
* @param from World position, trace origin coordinates.
* @param to World position, trace target coordinates.
* @param flags Line Sight Flags (LS_*) @ref lineSightFlags
*
* @return @c true if the traverser function returns @c true
* for all visited lines.
*/
bool lineOfSight(const_pvec3d_t from, const_pvec3d_t to, coord_t bottomSlope,
coord_t topSlope, int flags);

/**
* Retrieve a pointer to the Generators collection for the map. If no collection
* has yet been constructed a new empty collection will be initialized.
*
* @return Generators collection for the map.
*/
struct generators_s *generators();

#ifdef __CLIENT__

/**
Expand Down Expand Up @@ -674,16 +724,6 @@ boolean GameMap_ClMobjIterator(GameMap *map, boolean (*callback) (struct mobj_s
struct clplane_s *GameMap_NewClPlane(GameMap *map, uint sectornum, clplanetype_t type,
coord_t dest, float speed);

/**
* Retrieve a pointer to the Generators collection for this map.
* If no collection has yet been constructed a new empty collection will be
* initialized as a result of this call.
*
* @param map GameMap instance.
* @return Generators collection for this map.
*/
struct generators_s *GameMap_Generators(GameMap *map);

/**
* Initialize all Polyobjs in the map. To be called after map load.
*
Expand Down Expand Up @@ -801,37 +841,16 @@ int GameMap_BspNodeIterator(GameMap *map, int (*callback) (BspNode *, void *), v
* interceptable object linked within Blockmap cells which cover the path this
* defines.
*/
int GameMap_PathTraverse2(GameMap *map, const_pvec2d_t from, const_pvec2d_t to,
int flags, traverser_t callback, void *parameters);
int GameMap_PathTraverse(GameMap *map, const_pvec2d_t from, const_pvec2d_t to,
int flags, traverser_t callback/* void* parameters=NULL*/);

int GameMap_PathXYTraverse2(GameMap *map, coord_t fromX, coord_t fromY, coord_t toX, coord_t toY,
int flags, traverser_t callback, void *parameters);
int GameMap_PathXYTraverse(GameMap *map, coord_t fromX, coord_t fromY, coord_t toX, coord_t toY,
int flags, traverser_t callback);
int flags, traverser_t callback, void *parameters = 0);

/**
* Determine the BSP leaf on the back side of the BS partition that lies in front
* of the specified point within the map's coordinate space.
*
* @note Always returns a valid BspLeaf although the point may not actually lay
* within it (however it is on the same side of the space partition)!
*
* @param map GameMap instance.
* @param x X coordinate of the point to test.
* @param y Y coordinate of the point to test.
* @return BspLeaf instance for that BSP node's leaf.
*/
BspLeaf *GameMap_BspLeafAtPointXY(GameMap *map, coord_t x, coord_t y);

/**
* @copybrief GameMap_BspLeafAtPointXY()
* @param map GameMap instance.
* @param point XY coordinates of the point to test.
* @return BspLeaf instance for that BSP node's leaf.
*/
BspLeaf *GameMap_BspLeafAtPoint(GameMap *map, coord_t const point[2]);
inline int GameMap_PathTraverse(GameMap *map, coord_t fromX, coord_t fromY,
coord_t toX, coord_t toY, int flags, traverser_t callback, void *parameters = 0)
{
coord_t from[2] = { fromX, fromY };
coord_t to[2] = { toX, toY };
return GameMap_PathTraverse(map, from, to, flags, callback, parameters);
}

/**
* Private member functions:
Expand Down
41 changes: 0 additions & 41 deletions doomsday/client/include/map/p_sight.h

This file was deleted.

2 changes: 1 addition & 1 deletion doomsday/client/src/audio/s_environ.cpp
Expand Up @@ -306,7 +306,7 @@ static boolean calcBspLeafReverb(BspLeaf *bspLeaf)
bspLeaf->_reverb[SRD_DAMPING] = v;

/* DEBUG_Message(("bspLeaf %04i: vol:%3i sp:%3i dec:%3i dam:%3i\n",
GameMap_BspLeafIndex(theMap, (bspLeaf), bspLeaf->reverb[SRD_VOLUME],
GameMap_BspLeafIndex(theMap, bspLeaf), bspLeaf->reverb[SRD_VOLUME],
bspLeaf->reverb[SRD_SPACE], bspLeaf->reverb[SRD_DECAY],
bspLeaf->reverb[SRD_DAMPING])); */

Expand Down
27 changes: 2 additions & 25 deletions doomsday/client/src/client/cl_main.cpp
@@ -1,4 +1,4 @@
/** @file
/** @file cl_main.cpp Network Client
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -17,12 +17,6 @@
* http://www.gnu.org/licenses</small>
*/

/**
* cl_main.c: Network Client
*/

// HEADER FILES ------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Expand All @@ -35,35 +29,18 @@
#include "de_misc.h"
#include "de_play.h"

#include "map/gamemap.h"
#include "render/r_main.h"

// MACROS ------------------------------------------------------------------

// TYPES -------------------------------------------------------------------

// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------

// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------

// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------

// EXTERNAL DATA DECLARATIONS ----------------------------------------------

extern int gotFrame;

// PUBLIC DATA DEFINITIONS -------------------------------------------------

ident_t clientID;
boolean handshakeReceived = false;
int gameReady = false;
int serverTime;
boolean netLoggedIn = false; // Logged in to the server.
int clientPaused = false; // Set by the server.

// PRIVATE DATA DEFINITIONS ------------------------------------------------

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

void Cl_InitID(void)
{
int i;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/client/cl_sound.cpp
Expand Up @@ -253,7 +253,7 @@ ifdef _DEBUG
Con_Printf("Cl_ReadSoundDelta2(%i): Start snd=%i [%x] vol=%.2f",
type, sound, flags, volume);
if(cmo) Con_Printf(", mo=%i\n", cmo->mo.thinker.id);
else if(sector) Con_Printf(", sector=%i\n", GameMap_SectorIndex(theMap, (sector));
else if(sector) Con_Printf(", sector=%i\n", GameMap_SectorIndex(theMap, sector));
else if(poly) Con_Printf(", poly=%i\n", GET_POLYOBJ_IDX(poly));
else Con_Printf("\n");
#endif
Expand All @@ -272,7 +272,7 @@ else Con_Printf("\n");
Con_Printf("Cl_ReadSoundDelta2(%i): Stop sound %i",
type, sound);
if(cmo) Con_Printf(", mo=%i\n", cmo->mo.thinker.id);
else if(sector) Con_Printf(", sector=%i\n", GameMap_SectorIndex(theMap, (sector));
else if(sector) Con_Printf(", sector=%i\n", GameMap_SectorIndex(theMap, sector));
else if(poly) Con_Printf(", poly=%i\n", GET_POLYOBJ_IDX(poly));
else Con_Printf("\n");
#endif
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/src/client/cl_world.cpp
Expand Up @@ -31,6 +31,7 @@
#include "api_map.h"
#include "api_materialarchive.h"

#include "map/gamemap.h"
#include "client/cl_world.h"
#include "r_util.h"

Expand Down
6 changes: 4 additions & 2 deletions doomsday/client/src/edit_bias.cpp
Expand Up @@ -20,6 +20,9 @@
* 02110-1301 USA</small>
*/

#include <cmath>
#include <de/mathutil.h>

#include "de_base.h"
#include "de_edit.h"
#include "de_system.h"
Expand All @@ -31,8 +34,7 @@
#include "de_play.h"
#include "de_filesys.h"

#include <math.h>
#include <de/mathutil.h>
#include "map/gamemap.h"

D_CMD(BLEditor);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/edit_map.cpp
Expand Up @@ -1458,7 +1458,7 @@ static bool buildBsp(GameMap &map)
collateVertexes(nodeBuilder, map, e_mapNumVertexes, e_mapVertexesArray);

BspTreeNode *rootNode = nodeBuilder.root();
map.bsp = rootNode->userData(); // We'll formally take ownership shortly...
map._bspRoot = rootNode->userData(); // We'll formally take ownership shortly...

// Iterative pre-order traversal of the BspBuilder's map element tree.
BspTreeNode *cur = rootNode;
Expand Down
9 changes: 6 additions & 3 deletions doomsday/client/src/map/blockmapvisual.cpp
Expand Up @@ -19,7 +19,9 @@
* 02110-1301 USA</small>
*/

#include <math.h>
#include <cmath>

#include <de/concurrency.h>

#include "de_base.h"
#include "de_console.h"
Expand All @@ -28,9 +30,10 @@
#include "de_play.h"
#include "de_ui.h"

#include <de/concurrency.h>
#include "map/blockmapvisual.h"
#include "map/blockmap.h"
#include "map/gamemap.h"

#include "map/blockmapvisual.h"

byte bmapShowDebug = 0; // 1 = mobjs, 2 = linedefs, 3 = BSP leafs, 4 = polyobjs.
float bmapDebugSize = 1.5f;
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/src/map/dam_file.cpp
Expand Up @@ -30,6 +30,7 @@
#include "de_misc.h"
#include "de_filesys.h"

#include "map/gamemap.h"
#include "map/p_mapdata.h"

// Global archived map format version identifier. Increment when making
Expand Down
4 changes: 4 additions & 0 deletions doomsday/client/src/map/dam_main.cpp
Expand Up @@ -28,6 +28,10 @@
#include "de_network.h"
#include "de_render.h"

#include "map/gamemap.h"

#include "map/dam_main.h"

using namespace de;

// Should we be caching successfully loaded maps?
Expand Down

0 comments on commit 2d4791d

Please sign in to comment.