Skip to content

Commit

Permalink
Refactor|SideDef: Moved all SideDef_* functions to methods of SideDef
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 12, 2013
1 parent 677b619 commit f159256
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 136 deletions.
4 changes: 4 additions & 0 deletions doomsday/client/include/map/linedef.h
Expand Up @@ -73,6 +73,10 @@ class HEdge;
#define LF_POLYOBJ 0x1 ///< Line is part of a polyobject.
#define LF_BSPWINDOW 0x2 ///< Line produced a BSP window. @todo Refactor away.

// Logical sides:
#define FRONT 0
#define BACK 1

/**
* @defgroup sideSectionFlags Side Section Flags
* @ingroup map
Expand Down
167 changes: 95 additions & 72 deletions doomsday/client/include/map/sidedef.h
@@ -1,9 +1,7 @@
/**
* @file sidedef.h
* Map SideDef. @ingroup map
/** @file sidedef.h Map SideDef.
*
* @authors Copyright &copy; 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright &copy; 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -23,16 +21,19 @@
#ifndef LIBDENG_MAP_SIDEDEF
#define LIBDENG_MAP_SIDEDEF

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

#include "MapElement"
#include <de/Error>
#include "resource/r_data.h"
#include "map/p_dmu.h"
#include "map/surface.h"
#include "MapElement"

class LineDef;

// Helper macros for accessing sidedef top/middle/bottom section data elements.
/*
* Helper macros for accessing sidedef top/middle/bottom section data elements:
*/
/// @addtogroup map
///@{
#define SW_surface(n) sections[(n)]
#define SW_surfaceflags(n) SW_surface(n).flags
#define SW_surfaceinflags(n) SW_surface(n).inFlags
Expand Down Expand Up @@ -81,88 +82,110 @@
#define SW_bottomoffset SW_surfaceoffset(SS_BOTTOM)
#define SW_bottomvisoffset SW_surfacevisoffset(SS_BOTTOM)
#define SW_bottomrgba SW_surfacergba(SS_BOTTOM)
///@}

#define FRONT 0
#define BACK 1
/**
* FakeRadio shadow data.
* @ingroup map
*/
struct shadowcorner_t
{
float corner;
Sector *proximity;
float pOffset;
float pHeight;
};

class LineDef;
/**
* @ingroup map
*/
struct edgespan_t
{
float length;
float shift;
};

typedef struct msidedef_s {
/**
* @ingroup map
*/
struct msidedef_t
{
// Sidedef index. Always valid after loading & pruning.
int index;
int refCount;
} msidedef_t;

// FakeRadio shadow data.
typedef struct shadowcorner_s {
float corner;
Sector *proximity;
float pOffset;
float pHeight;
} shadowcorner_t;

typedef struct edgespan_s {
float length;
float shift;
} edgespan_t;
};

/**
* @attention SideDef is in the process of being replaced by lineside_t. All
* data/values which concern the geometry of surfaces should be relocated to
* lineside_t. There is no need to model the side of map's line as an object
* in Doomsday when a flag would suffice. -ds
*
* @ingroup map
*/
class SideDef : public de::MapElement
{
public:
Surface sections[3];
LineDef * line;
short flags;
msidedef_t buildData;
int fakeRadioUpdateCount; // frame number of last update
shadowcorner_t topCorners[2];
shadowcorner_t bottomCorners[2];
shadowcorner_t sideCorners[2];
edgespan_t spans[2]; // [left, right]
/// The referenced property does not exist. @ingroup errors
DENG2_ERROR(UnknownPropertyError);

/// The referenced property is not writeable. @ingroup errors
DENG2_ERROR(WritePropertyError);

public:
SideDef();
};
Surface sections[3];

/**
* Update the SideDef's map space surface base origins according to the points
* defined by the associated LineDef's vertices and the plane heights of the
* Sector on this side. If no LineDef is presently associated this is a no-op.
*
* @param side SideDef instance.
*/
void SideDef_UpdateBaseOrigins(SideDef* side);
LineDef *line;

/**
* Update the SideDef's map space surface tangents according to the points
* defined by the associated LineDef's vertices. If no LineDef is presently
* associated this is a no-op.
*
* @param sideDef SideDef instance.
*/
void SideDef_UpdateSurfaceTangents(SideDef* sideDef);
short flags;

/**
* Get a property value, selected by DMU_* name.
*
* @param sideDef SideDef instance.
* @param args Property arguments.
* @return Always @c 0 (can be used as an iterator).
*/
int SideDef_GetProperty(const SideDef* sideDef, setargs_t* args);
msidedef_t buildData;

/**
* Update a property value, selected by DMU_* name.
*
* @param sideDef SideDef instance.
* @param args Property arguments.
* @return Always @c 0 (can be used as an iterator).
*/
int SideDef_SetProperty(SideDef* sideDef, const setargs_t* args);
/// Frame number of last update
int fakeRadioUpdateCount;

shadowcorner_t topCorners[2];

shadowcorner_t bottomCorners[2];

shadowcorner_t sideCorners[2];

/// [left, right]
edgespan_t spans[2];

public:
SideDef();
~SideDef();

/**
* Update the side's map space surface base origins according to the points
* defined by the associated LineDef's vertices and the plane heights of the
* Sector on this side. If no LineDef is presently associated this is a no-op.
*/
void updateBaseOrigins();

/**
* Update the side's map space surface tangents according to the points
* defined by the associated LineDef's vertices. If no LineDef is presently
* associated this is a no-op.
*/
void updateSurfaceTangents();

/**
* Get a property value, selected by DMU_* name.
*
* @param args Property arguments.
* @return Always @c 0 (can be used as an iterator).
*/
int property(setargs_t &args) const;

/**
* Update a property value, selected by DMU_* name.
*
* @param args Property arguments.
* @return Always @c 0 (can be used as an iterator).
*/
int setProperty(setargs_t const &args);
};

#endif // LIBDENG_MAP_SIDEDEF
8 changes: 4 additions & 4 deletions doomsday/client/src/edit_map.cpp
Expand Up @@ -702,16 +702,16 @@ static void chainSectorBases(GameMap* map)
}
}

static void finishSideDefs(GameMap* map)
static void finishSideDefs(GameMap *map)
{
DENG_ASSERT(map);

// Calculate the tangent space surface vectors.
for(uint i = 0; i < map->sideDefCount(); ++i)
{
SideDef* side = &map->sideDefs[i];
SideDef_UpdateSurfaceTangents(side);
SideDef_UpdateBaseOrigins(side);
SideDef &side = map->sideDefs[i];
side.updateSurfaceTangents();
side.updateBaseOrigins();
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/map/dam_file.cpp
Expand Up @@ -394,7 +394,7 @@ static void readSide(GameMap *map, uint idx)
}
s->flags = readShort();

SideDef_UpdateBaseOrigins(s);
s->updateBaseOrigins();
}

static void archiveSides(GameMap *map, boolean write)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/map/p_dmu.cpp
Expand Up @@ -1030,7 +1030,7 @@ static int setProperty(void *ptr, void *context)
break;

case DMU_SIDEDEF:
SideDef_SetProperty(elem->castTo<SideDef>(), args);
elem->castTo<SideDef>()->setProperty(*args);
break;

case DMU_BSPLEAF:
Expand Down Expand Up @@ -1524,7 +1524,7 @@ static int getProperty(void *ptr, void *context)
break;

case DMU_SIDEDEF:
SideDef_GetProperty(elem->castTo<SideDef>(), args);
elem->castTo<SideDef>()->property(*args);
break;

case DMU_BSPLEAF:
Expand Down
13 changes: 6 additions & 7 deletions doomsday/client/src/map/polyobj.cpp
Expand Up @@ -50,19 +50,18 @@ void Polyobj_UpdateAABox(Polyobj* po)
}
}

void Polyobj_UpdateSurfaceTangents(Polyobj* po)
void Polyobj_UpdateSurfaceTangents(Polyobj *po)
{
LineDef** lineIter;
assert(po);
DENG2_ASSERT(po);

for(lineIter = po->lines; *lineIter; lineIter++)
for(LineDef **lineIter = po->lines; *lineIter; lineIter++)
{
LineDef* line = *lineIter;
LineDef *line = *lineIter;

SideDef_UpdateSurfaceTangents(line->L_frontsidedef);
line->L_frontsidedef->updateSurfaceTangents();
if(line->L_backsidedef)
{
SideDef_UpdateSurfaceTangents(line->L_backsidedef);
line->L_backsidedef->updateSurfaceTangents();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/map/r_world.cpp
Expand Up @@ -1412,11 +1412,11 @@ boolean R_UpdatePlane(Plane *pln, boolean forceUpdate)
LineDef *line = sec->lineDefs[i];
if(line->L_frontsidedef) // $degenleaf
{
SideDef_UpdateBaseOrigins(line->L_frontsidedef);
line->L_frontsidedef->updateBaseOrigins();
}
if(line->L_backsidedef)
{
SideDef_UpdateBaseOrigins(line->L_backsidedef);
line->L_backsidedef->updateBaseOrigins();
}
}

Expand Down

0 comments on commit f159256

Please sign in to comment.