Skip to content

Commit

Permalink
Polyobj|Fixed: Seg angles were not kept in-sync with their LineDefs'
Browse files Browse the repository at this point in the history
Also further cleaned up the polyobj implementation.
  • Loading branch information
danij-deng committed Feb 25, 2012
1 parent 97dc854 commit 1d8e922
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 254 deletions.
8 changes: 5 additions & 3 deletions doomsday/engine/api/dd_types.h
Expand Up @@ -178,15 +178,17 @@ typedef int ddboolean_t;

#if BAMS_BITS == 32
typedef uint32_t binangle_t;
#define BANG_TO_ANGLE(bang) ((angle_t)bang)
# define BANG_TO_ANGLE(bang) ((angle_t)bang)
#elif BAMS_BITS == 16
typedef uint16_t binangle_t;
#define BANG_TO_ANGLE(bang) ((angle_t)bang << 16)
# define BANG_TO_ANGLE(bang) ((angle_t)bang << 16)
#else
typedef unsigned char binangle_t;
#define BANG_TO_ANGLE(bang) ((angle_t)bang << 24)
# define BANG_TO_ANGLE(bang) ((angle_t)bang << 24)
#endif

#define ANGLE_TO_BANG(angle) ((binangle_t)((angle_t)angle >> BAMS_BITS))

#define DDMAXCHAR ((char)0x7f)
#define DDMAXSHORT ((int16_t)0x7fff)
#define DDMAXUSHORT ((uint16_t)0xffff)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/api/doomsday.def
Expand Up @@ -589,7 +589,7 @@ EXPORTS
P_PolyobjMoveXY @79 NONAME
P_PolyobjRotate @80 NONAME
P_PolyobjLink @82 NONAME
P_PolyobjUnLink @81 NONAME
P_PolyobjUnlink @81 NONAME

P_PolyobjByID @424 NONAME
P_PolyobjByTag @827 NONAME
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/api/doomsday.h
Expand Up @@ -520,7 +520,7 @@ void P_SpawnDamageParticleGen(struct mobj_s* mo, struct mobj_s* infli
boolean P_PolyobjMoveXY(struct polyobj_s* po, float x, float y);
boolean P_PolyobjRotate(struct polyobj_s* po, angle_t angle);
void P_PolyobjLink(struct polyobj_s* po);
void P_PolyobjUnLink(struct polyobj_s* po);
void P_PolyobjUnlink(struct polyobj_s* po);

struct polyobj_s* P_PolyobjByID(uint id);
struct polyobj_s* P_PolyobjByTag(int tag);
Expand Down
16 changes: 16 additions & 0 deletions doomsday/engine/portable/include/p_linedef.h
Expand Up @@ -32,6 +32,22 @@
#include "r_data.h"
#include "p_dmu.h"

/**
* Update the LineDef's slopetype and map space angle delta according to
* the points defined by it's vertices.
*
* @param lineDef LineDef instance.
*/
void LineDef_UpdateSlope(linedef_t* lineDef);

/**
* Update the LineDef's map space axis-aligned bounding box to encompass
* the points defined by it's vertices.
*
* @param lineDef LineDef instance.
*/
void LineDef_UpdateAABox(linedef_t* lineDef);

/**
* @return Minimal floor Plane which interfaces with this LineDef's face.
* If both front and back floor Plane interfaces exist and are equal,
Expand Down
19 changes: 15 additions & 4 deletions doomsday/engine/portable/include/p_polyob.h
Expand Up @@ -88,12 +88,23 @@ void P_PolyobjLink(polyobj_t* polyobj);
* Unlink @a polyobj from the current map. To be called prior to moving,
* rotating or any other translation of the Polyobj within the map.
*/
void P_PolyobjUnLink(polyobj_t* polyobj);
void P_PolyobjUnlink(polyobj_t* polyobj);

/**
* Update the polyobj's axis-aligned bounding box.
* Update the Polyobj's map space axis-aligned bounding box to encompass
* the points defined by it's vertices.
*
* @param polyobj Polyobj instance.
*/
void Polyobj_UpdateAABox(polyobj_t* polyobj);

/**
* Update the Polyobj's map space surface tangents according to the points
* defined by the associated LineDef's vertices.
*
* @param polyobj Polyobj instance.
*/
void P_PolyobjUpdateAABox(polyobj_t* polyobj);
void Polyobj_UpdateSurfaceTangents(polyobj_t* polyobj);

/**
* Iterate over the LineDefs of the Polyobj making a callback for each.
Expand All @@ -109,7 +120,7 @@ void P_PolyobjUpdateAABox(polyobj_t* polyobj);
*
* @return @c 0 iff iteration completed wholly.
*/
int P_PolyobjLinesIterator(polyobj_t* polyobj,
int Polyobj_LineDefIterator(polyobj_t* polyobj,
int (*callback) (struct linedef_s*, void* paramaters), void* paramaters);

#endif /// LIBDENG_MAP_POLYOB_H
9 changes: 9 additions & 0 deletions doomsday/engine/portable/include/p_sidedef.h
Expand Up @@ -32,6 +32,15 @@
#include "r_data.h"
#include "p_dmu.h"

/**
* 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_t* sideDef);

/**
* Get the value of a sidedef property, selected by DMU_* name.
*/
Expand Down
4 changes: 1 addition & 3 deletions doomsday/engine/portable/src/p_bmap.c
Expand Up @@ -509,7 +509,6 @@ void Map_LinkPolyobjInBlockmap(gamemap_t* map, polyobj_t* po)
GridmapBlock blockCoords;
uint x, y;

P_PolyobjUpdateAABox(po);
Blockmap_CellBlockCoords(blockmap, &blockCoords, &po->aaBox);

for(y = blockCoords.minY; y <= blockCoords.maxY; ++y)
Expand All @@ -524,7 +523,6 @@ void Map_UnlinkPolyobjInBlockmap(gamemap_t* map, polyobj_t* po)
Blockmap* blockmap = map->polyobjBlockmap;
GridmapBlock blockCoords;

P_PolyobjUpdateAABox(po);
Blockmap_CellBlockCoords(map->polyobjBlockmap, &blockCoords, &po->aaBox);
Gridmap_BlockIterate2(blockmap->gridmap, &blockCoords, unlinkObjectInCell, (void*) po);
}
Expand Down Expand Up @@ -655,7 +653,7 @@ typedef struct poiterparams_s {
int PTR_PolyobjLines(polyobj_t* po, void* data)
{
poiterparams_t* args = (poiterparams_t*) data;
return P_PolyobjLinesIterator(po, args->func, args->param);
return Polyobj_LineDefIterator(po, args->func, args->param);
}

int Map_IterateCellPolyobjLineDefsIterator(gamemap_t* map, const uint coords[2],
Expand Down
10 changes: 5 additions & 5 deletions doomsday/engine/portable/src/p_data.c
Expand Up @@ -118,13 +118,13 @@ static gamemapobjdef_t* gameMapObjDefs;

void P_PolyobjChanged(polyobj_t* po)
{
uint i;
seg_t** segPtr = po->segs;
seg_t** segIter = po->segs;
uint i;

for(i = 0; i < po->numSegs; ++i, segPtr++)
for(i = 0; i < po->numSegs; ++i, segIter++)
{
int j;
seg_t* seg = *segPtr;
seg_t* seg = *segIter;
int j;

// Shadow bias must be told.
for(j = 0; j < 3; ++j)
Expand Down
40 changes: 38 additions & 2 deletions doomsday/engine/portable/src/p_linedef.c
Expand Up @@ -55,8 +55,44 @@ static linedef_t* findBlendNeighbor(const linedef_t* l, byte side, byte right,
return R_FindLineNeighbor(l->L_sector(side), l, farVertOwner, right, diff);
}

void LineDef_UpdateSlope(linedef_t* line)
{
assert(line);

line->dX = line->L_v2pos[VX] - line->L_v1pos[VX];
line->dY = line->L_v2pos[VY] - line->L_v1pos[VY];

if(FEQUAL(line->dX, 0))
{
line->slopeType = ST_VERTICAL;
}
else if(FEQUAL(line->dY, 0))
{
line->slopeType = ST_HORIZONTAL;
}
else if(line->dY / line->dX > 0)
{
line->slopeType = ST_POSITIVE;
}
else
{
line->slopeType = ST_NEGATIVE;
}
}

void LineDef_UpdateAABox(linedef_t* line)
{
assert(line);

line->aaBox.minX = MIN_OF(line->L_v2pos[VX], line->L_v1pos[VX]);
line->aaBox.minY = MIN_OF(line->L_v2pos[VY], line->L_v1pos[VY]);

line->aaBox.maxX = MAX_OF(line->L_v2pos[VX], line->L_v1pos[VX]);
line->aaBox.maxY = MAX_OF(line->L_v2pos[VY], line->L_v1pos[VY]);
}

/**
* \todo Now that we store surface tangent space normals use those rather than angles.
* @todo Now that we store surface tangent space normals use those rather than angles.
*/
void LineDef_LightLevelDelta(const linedef_t* l, int side, float* deltaL, float* deltaR)
{
Expand Down Expand Up @@ -198,7 +234,7 @@ int LineDef_MiddleMaterialCoords(const linedef_t* lineDef, int side,
}

/**
* \fixme No need to do this each frame. Set a flag in sidedef_t->flags to
* @fixme No need to do this each frame. Set a flag in sidedef_t->flags to
* denote this. Is sensitive to plane heights, surface properties
* (e.g. alpha) and surface texture properties.
*/
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/p_maputil.c
Expand Up @@ -1219,7 +1219,7 @@ typedef struct {
static int iteratePolyobjLineDefs(polyobj_t* po, void* paramaters)
{
const iteratepolyobjlinedefs_params_t* p = (iteratepolyobjlinedefs_params_t*)paramaters;
return P_PolyobjLinesIterator(po, p->callback, p->paramaters);
return Polyobj_LineDefIterator(po, p->callback, p->paramaters);
}

static int collectPolyobjLineDefIntercepts(uint const block[2], void* paramaters)
Expand Down

0 comments on commit 1d8e922

Please sign in to comment.