Skip to content

Commit

Permalink
Refactor: Added C++ Plane class, replaced planelist_t with a QSet
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 14, 2013
1 parent 835d212 commit 3517eca
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 101 deletions.
1 change: 0 additions & 1 deletion doomsday/engine/api/dd_types.h
Expand Up @@ -66,7 +66,6 @@ typedef void (*con_textfilter_t) (char* text);
struct hedge_s;
struct polyblock_s;
struct polyobj_s;
struct plane_s;
struct surface_s;
struct material_s;

Expand Down
5 changes: 3 additions & 2 deletions doomsday/engine/include/map/gamemap.h
Expand Up @@ -29,6 +29,7 @@

#include "p_maptypes.h"
#include "p_particle.h"
#include "plane.h"
#include <EntityDatabase>
#include <de/mathutil.h>

Expand Down Expand Up @@ -110,7 +111,7 @@ class GameMap

EntityDatabase* entityDatabase;

planelist_t trackedPlanes;
PlaneSet trackedPlanes;
surfacelist_t scrollingSurfaces;
surfacelist_t decoratedSurfaces;
surfacelist_t glowingSurfaces;
Expand Down Expand Up @@ -632,7 +633,7 @@ surfacelist_t* GameMap_ScrollingSurfaces(GameMap* map);
* @param map GameMap instance.
* @return List of tracked planes.
*/
planelist_t* GameMap_TrackedPlanes(GameMap* map);
PlaneSet* GameMap_TrackedPlanes(GameMap* map);

/**
* Initialize all Polyobjs in the map. To be called after map load.
Expand Down
49 changes: 28 additions & 21 deletions doomsday/engine/include/map/plane.h
Expand Up @@ -23,6 +23,12 @@
#ifndef LIBDENG_MAP_PLANE
#define LIBDENG_MAP_PLANE

#ifndef __cplusplus
# error "map/plane.h requires C++"
#endif

#include <QSet>
#include "MapElement"
#include "resource/r_data.h"
#include "map/p_dmu.h"
#include "map/surface.h"
Expand All @@ -45,29 +51,34 @@ typedef enum {
#define PS_flags surface.flags
#define PS_inflags surface.inFlags

typedef struct plane_s {
runtime_mapdata_header_t header;
Sector *sector; ///< Owner of the plane.
Surface surface;
coord_t height; /// Current height.
coord_t oldHeight[2];
coord_t target; /// Target height.
coord_t speed; /// Move speed.
coord_t visHeight; /// Visible plane height (smoothed).
coord_t visHeightDelta;
planetype_t type; /// PLN_* type.
int planeID;
} Plane;
class Plane : public de::MapElement
{
public:
Sector *sector; ///< Owner of the plane.
Surface surface;
coord_t height; ///< Current height.
coord_t oldHeight[2];
coord_t target; ///< Target height.
coord_t speed; ///< Move speed.
coord_t visHeight; ///< Visible plane height (smoothed).
coord_t visHeightDelta;
planetype_t type; ///< PLN_* type.
int planeID;

public:
Plane();
~Plane();
};

typedef QSet<Plane *> PlaneSet;

/*
typedef struct planelist_s {
uint num;
uint maxNum;
Plane **array;
} planelist_t;

#ifdef __cplusplus
extern "C" {
#endif
*/

// Return the index of plane within a sector's planes array.
#define GET_PLANE_IDX(pln) ( (int) ((pln) - (pln)->sector->planes[0]) )
Expand All @@ -90,8 +101,4 @@ int Plane_GetProperty(const Plane* plane, setargs_t* args);
*/
int Plane_SetProperty(Plane* plane, const setargs_t* args);

#ifdef __cplusplus
} // extern "C"
#endif

#endif /// LIBDENG_MAP_PLANE
15 changes: 4 additions & 11 deletions doomsday/engine/include/map/r_world.h
Expand Up @@ -32,10 +32,7 @@
#include "resource/r_data.h"
#include "map/vertex.h"
#include "map/sector.h"

#ifdef __cplusplus
extern "C" {
#endif
#include "map/plane.h"

// Used for vertex sector owners, side line owners and reverb BSP leafs.
typedef struct ownernode_s {
Expand Down Expand Up @@ -165,16 +162,16 @@ void R_ClearSurfaceDecorations(Surface* suf);
void R_UpdateTrackedPlanes(void);
void R_InterpolateTrackedPlanes(boolean resetNextViewer);

void R_AddTrackedPlane(planelist_t* plist, Plane* pln);
boolean R_RemoveTrackedPlane(planelist_t* plist, const Plane* pln);
void R_AddTrackedPlane(PlaneSet* plist, Plane* pln);
boolean R_RemoveTrackedPlane(PlaneSet* plist, Plane* pln);

void R_UpdateSurfaceScroll(void);
void R_InterpolateSurfaceScroll(boolean resetNextViewer);

boolean R_UpdateSector(Sector *sec, boolean forceUpdate);
boolean R_UpdateLinedef(LineDef *line, boolean forceUpdate);
boolean R_UpdateSidedef(SideDef *side, boolean forceUpdate);
boolean R_UpdatePlane(struct plane_s *pln, boolean forceUpdate);
boolean R_UpdatePlane(Plane *pln, boolean forceUpdate);
boolean R_UpdateSurface(struct surface_s *suf, boolean forceUpdate);

/**
Expand Down Expand Up @@ -248,8 +245,4 @@ LineDef* R_FindLineBackNeighbor(const Sector* sector, const LineDef* line,

coord_t R_SkyCapZ(BspLeaf* bspLeaf, int skyCap);

#ifdef __cplusplus
} // extern "C"
#endif

#endif /* LIBDENG_REFRESH_WORLD_H */
4 changes: 3 additions & 1 deletion doomsday/engine/include/map/sector.h
Expand Up @@ -88,6 +88,8 @@ typedef struct msector_s {
int refCount;
} msector_t;

class Plane;

class Sector : public de::MapElement
{
public:
Expand All @@ -108,7 +110,7 @@ class Sector : public de::MapElement
BspLeaf** reverbBspLeafs; // [numReverbBspLeafAttributors] size.
ddmobj_base_t base;
unsigned int planeCount;
struct plane_s** planes; // [planeCount+1] size.
Plane **planes; // [planeCount+1] size.
unsigned int blockCount; // Number of gridblocks in the sector.
unsigned int changedBlockCount; // Number of blocks to mark changed.
unsigned short* blocks; // Light grid block indices.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/edit_map.cpp
Expand Up @@ -1953,7 +1953,7 @@ uint MPE_PlaneCreate(uint sector, coord_t height, const ddstring_t* materialUri,

Sector* s = e_map->sectors[sector - 1];

Plane* pln = (Plane*) M_Calloc(sizeof(Plane));
Plane* pln = new Plane;
pln->surface.owner = (void*) pln;
pln->height = height;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/map/gamemap.cpp
Expand Up @@ -478,7 +478,7 @@ surfacelist_t* GameMap_ScrollingSurfaces(GameMap* map)
return &map->scrollingSurfaces;
}

planelist_t* GameMap_TrackedPlanes(GameMap* map)
PlaneSet* GameMap_TrackedPlanes(GameMap* map)
{
assert(map);
return &map->trackedPlanes;
Expand Down
5 changes: 2 additions & 3 deletions doomsday/engine/src/map/p_dmu.cpp
Expand Up @@ -400,15 +400,14 @@ uint P_ToIndex(void const *ptr)
return GET_BSPNODE_IDX(elem->castTo<BspNode>());

case DMU_PLANE:
DENG2_ASSERT(false); // TODO: update this!
//return GET_PLANE_IDX((Plane *) ptr);
return GET_PLANE_IDX(elem->castTo<Plane>());

case DMU_MATERIAL:
DENG2_ASSERT(false); // TODO: update this!
//return Materials_Id((material_t *) ptr);

default:
DENG2_ASSERT(false); // Unknown DMU type.
DENG2_ASSERT(false); // Unknown/non-indexable DMU type.
return 0;
}
}
Expand Down
18 changes: 18 additions & 0 deletions doomsday/engine/src/map/plane.cpp
Expand Up @@ -24,6 +24,24 @@
#include "de_console.h"
#include "de_play.h"

Plane::Plane() : de::MapElement(DMU_PLANE)
{
sector = 0;
memset(&surface, 0, sizeof(surface)); // TODO: remove when Surface is a C++ type!
height = 0;
memset(oldHeight, 0, sizeof(oldHeight));
target = 0;
speed = 0;
visHeight = 0;
visHeightDelta = 0;
type = (planetype_t) 0;
planeID = 0;
}

Plane::~Plane()
{
}

int Plane_SetProperty(Plane* pln, const setargs_t* args)
{
switch(args->prop)
Expand Down

0 comments on commit 3517eca

Please sign in to comment.