Skip to content

Commit

Permalink
Refactor: Moved sector and sidedef origins to members of Sector and S…
Browse files Browse the repository at this point in the history
…ideDef

Also fixed a bug with polyobjects in that the sidedef origins were
not being updated after a polyobject has moved (resulting in the
distance based delta queueing using the old origins when subsequent
changes to those sidedefs occur).

Todo for later: These origin points can be trivially calculated so
is there really a need to cache them?
  • Loading branch information
danij-deng committed Mar 7, 2012
1 parent 20c63f3 commit 929ef00
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 57 deletions.
7 changes: 7 additions & 0 deletions doomsday/engine/portable/include/mapdata.hs
Expand Up @@ -6,6 +6,11 @@ public
end

internal
// Each Sector and SideDef has an origin in the world (used for distance based delta queuing)
typedef struct origin_s {
float pos[2];
} origin_t;

#define LO_prev link[0]
#define LO_next link[1]

Expand Down Expand Up @@ -324,6 +329,7 @@ struct sector
- uint changedBlockCount // Number of blocks to mark changed.
- ushort* blocks // Light grid block indices.
FLOAT float[NUM_REVERB_DATA] reverb
- origin_t origin
- msector_t buildData
end

Expand Down Expand Up @@ -404,6 +410,7 @@ struct sidedef
PTR linedef_s* line
PTR sector_s* sector
SHORT short flags
- origin_t origin
- msidedef_t buildData

# The following is used with FakeRadio.
Expand Down
9 changes: 8 additions & 1 deletion doomsday/engine/portable/include/p_maptypes.h
Expand Up @@ -5,6 +5,11 @@

#include "p_mapdata.h"

// Each Sector and SideDef has an origin in the world (used for distance based delta queuing)
typedef struct origin_s {
float pos[2];
} origin_t;

#define LO_prev link[0]
#define LO_next link[1]

Expand Down Expand Up @@ -303,6 +308,7 @@ typedef struct sector_s {
unsigned int changedBlockCount; // Number of blocks to mark changed.
unsigned short* blocks; // Light grid block indices.
float reverb[NUM_REVERB_DATA];
origin_t origin;
msector_t buildData;
} sector_t;

Expand Down Expand Up @@ -369,7 +375,7 @@ typedef enum sidedefsection_e {
typedef struct msidedef_s {
// Sidedef index. Always valid after loading & pruning.
int index;
int refCount;
int refCount;
} msidedef_t;

typedef struct sidedef_s {
Expand All @@ -380,6 +386,7 @@ typedef struct sidedef_s {
struct linedef_s* line;
struct sector_s* sector;
short flags;
origin_t origin;
msidedef_t buildData;
int fakeRadioUpdateCount; // frame number of last update
shadowcorner_t topCorners[2];
Expand Down
8 changes: 8 additions & 0 deletions doomsday/engine/portable/include/p_polyob.h
Expand Up @@ -98,6 +98,14 @@ void Polyobj_UpdateAABox(polyobj_t* polyobj);
*/
void Polyobj_UpdateSurfaceTangents(polyobj_t* polyobj);

/**
* Update the Polyobj's SideDef's map space origins according to the points
* defined by the center of the associated LineDef's vertices.
*
* @param polyobj Polyobj instance.
*/
void Polyobj_UpdateSideDefOrigins(polyobj_t* polyobj);

/**
* Iterate over the lines of the Polyobj making a callback for each.
* Iteration ends when all lines have been visited or @a callback
Expand Down
14 changes: 13 additions & 1 deletion doomsday/engine/portable/include/p_sector.h
Expand Up @@ -32,13 +32,25 @@
#include "r_data.h"
#include "p_dmu.h"

/**
* Update the origin of the sector according to the point defined by the center of
* the sector's axis-aligned bounding box (which must be initialized before calling).
*
* @param sec Sector instance.
*/
void Sector_UpdateOrigin(sector_t* sec);

/**
* Get the value of a sector property, selected by DMU_* name.
*
* @param sec Sector instance.
*/
int Sector_GetProperty(const sector_t* sector, setargs_t* args);

/**
* Update the sector, property is selected by DMU_* name.
* Update the sector property, selected by DMU_* name.
*
* @param sec Sector instance.
*/
int Sector_SetProperty(sector_t* sector, const setargs_t* args);

Expand Down
8 changes: 8 additions & 0 deletions doomsday/engine/portable/include/p_sidedef.h
Expand Up @@ -32,6 +32,14 @@
#include "r_data.h"
#include "p_dmu.h"

/**
* Update the SideDef's map space origin according to the point defined by
* the center of the owning LineDef's vertices.
*
* @param sideDef SideDef instance.
*/
void SideDef_UpdateOrigin(sidedef_t* side);

/**
* Update the SideDef's map space surface tangents according to the points
* defined by the associated LineDef's vertices. If no LineDef is presently
Expand Down
16 changes: 10 additions & 6 deletions doomsday/engine/portable/src/edit_map.c
Expand Up @@ -1302,15 +1302,15 @@ static void hardenLinedefs(GameMap *dest, editmap_t *src)

static void hardenSidedefs(GameMap* dest, editmap_t* src)
{
uint i;
uint i;

dest->numSideDefs = src->numSideDefs;
dest->sideDefs = Z_Malloc(dest->numSideDefs * sizeof(sidedef_t), PU_MAPSTATIC, 0);

for(i = 0; i < dest->numSideDefs; ++i)
{
sidedef_t *destS = &dest->sideDefs[i];
sidedef_t *srcS = src->sideDefs[i];
sidedef_t* destS = &dest->sideDefs[i];
sidedef_t* srcS = src->sideDefs[i];

memcpy(destS, srcS, sizeof(*destS));
destS->sector = &dest->sectors[srcS->sector->buildData.index - 1];
Expand All @@ -1323,24 +1323,28 @@ static void hardenSidedefs(GameMap* dest, editmap_t* src)
destS->SW_middlesurface.visOffset[1] = destS->SW_middlesurface.offset[1];
destS->SW_topsurface.visOffset[0] = destS->SW_topsurface.offset[0];
destS->SW_topsurface.visOffset[1] = destS->SW_topsurface.offset[1];

SideDef_UpdateOrigin(destS);
}
}

static void hardenSectors(GameMap* dest, editmap_t* src)
{
uint i;
uint i;

dest->numSectors = src->numSectors;
dest->sectors = Z_Malloc(dest->numSectors * sizeof(sector_t), PU_MAPSTATIC, 0);

for(i = 0; i < dest->numSectors; ++i)
{
sector_t *destS = &dest->sectors[i];
sector_t *srcS = src->sectors[i];
sector_t* destS = &dest->sectors[i];
sector_t* srcS = src->sectors[i];

memcpy(destS, srcS, sizeof(*destS));
destS->planeCount = 0;
destS->planes = NULL;

Sector_UpdateOrigin(destS);
}
}

Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/src/gamemap.c
Expand Up @@ -337,6 +337,7 @@ static void initPolyobj(polyobj_t* po)
}

Polyobj_UpdateAABox(po);
Polyobj_UpdateSideDefOrigins(po);
Polyobj_UpdateSurfaceTangents(po);

P_PolyobjUnlink(po);
Expand Down
20 changes: 20 additions & 0 deletions doomsday/engine/portable/src/p_polyob.c
Expand Up @@ -105,6 +105,23 @@ void Polyobj_UpdateSurfaceTangents(polyobj_t* po)
}
}

void Polyobj_UpdateSideDefOrigins(polyobj_t* po)
{
linedef_t** lineIter;
assert(po);

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

SideDef_UpdateOrigin(line->L_frontside);
if(line->L_backside)
{
SideDef_UpdateOrigin(line->L_backside);
}
}
}

static boolean mobjIsBlockingPolyobj(polyobj_t* po)
{
linedef_t** lineIter;
Expand Down Expand Up @@ -214,6 +231,8 @@ boolean P_PolyobjMove(polyobj_t* po, float delta[2])
return false;
}

Polyobj_UpdateSideDefOrigins(po);

// Various parties may be interested in this change; signal it.
P_PolyobjChanged(po);

Expand Down Expand Up @@ -323,6 +342,7 @@ boolean P_PolyobjRotate(polyobj_t* po, angle_t angle)
return false;
}

Polyobj_UpdateSideDefOrigins(po);
Polyobj_UpdateSurfaceTangents(po);

// Various parties may be interested in this change; signal it.
Expand Down
8 changes: 8 additions & 0 deletions doomsday/engine/portable/src/p_sector.c
Expand Up @@ -27,6 +27,14 @@
#include "de_refresh.h"
#include "de_play.h"

void Sector_UpdateOrigin(sector_t* sec)
{
assert(sec);

sec->origin.pos[VX] = (sec->bBox[BOXRIGHT] + sec->bBox[BOXLEFT]) / 2;
sec->origin.pos[VY] = (sec->bBox[BOXBOTTOM] + sec->bBox[BOXTOP]) / 2;
}

int Sector_SetProperty(sector_t* sec, const setargs_t* args)
{
switch(args->prop)
Expand Down
11 changes: 11 additions & 0 deletions doomsday/engine/portable/src/p_sidedef.c
Expand Up @@ -27,6 +27,17 @@
#include "de_refresh.h"
#include "de_play.h"

void SideDef_UpdateOrigin(sidedef_t* side)
{
assert(side);

// The side must be owned by a line.
if(!side->line) return;

side->origin.pos[VX] = side->line->L_v1pos[VX] + side->line->dX / 2;
side->origin.pos[VY] = side->line->L_v1pos[VY] + side->line->dY / 2;
}

void SideDef_UpdateSurfaceTangents(sidedef_t* side)
{
surface_t* surface = &side->SW_topsurface;
Expand Down
57 changes: 8 additions & 49 deletions doomsday/engine/portable/src/sv_pool.c
Expand Up @@ -89,13 +89,6 @@ typedef struct cregister_s {
dt_poly_t* polyObjs;
} cregister_t;

/**
* Each entity (mobj, sector, side, etc.) has an origin the world.
*/
typedef struct origin_s {
float pos[2];
} origin_t;

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

// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
Expand Down Expand Up @@ -130,9 +123,6 @@ static float deltaBaseScores[NUM_DELTA_TYPES];
// the mobj being compared.
static dt_mobj_t dummyZeroMobj;

// Origins of stuff. Calculated at the beginning of a map.
static origin_t* sectorOrigins, *sideOrigins;

// Pointer to the owner line for each side.
static linedef_t** sideOwners;

Expand All @@ -145,12 +135,10 @@ static linedef_t** sideOwners;
void Sv_InitPools(void)
{
uint i;
sector_t* sec;
uint startTime;

// Clients don't register anything.
if(isClient)
return;
if(isClient) return;

startTime = Sys_GetRealTime();

Expand Down Expand Up @@ -196,35 +184,6 @@ void Sv_InitPools(void)
sideOwners[i] = R_GetLineForSide(i);
}

// Origins of sectors.
sectorOrigins = Z_Malloc(sizeof(origin_t) * NUM_SECTORS, PU_MAP, 0);
for(i = 0; i < NUM_SECTORS; ++i)
{
sec = SECTOR_PTR(i);

sectorOrigins[i].pos[VX] =
(sec->bBox[BOXRIGHT] + sec->bBox[BOXLEFT]) / 2;
sectorOrigins[i].pos[VY] =
(sec->bBox[BOXBOTTOM] + sec->bBox[BOXTOP]) / 2;
}

// Origins of sides.
sideOrigins = Z_Malloc(sizeof(origin_t) * NUM_SIDEDEFS, PU_MAP, 0);
for(i = 0; i < NUM_SIDEDEFS; ++i)
{
vertex_t* vtx;

// The side must be owned by a line.
if(sideOwners[i] == NULL)
continue;

vtx = sideOwners[i]->L_v1;
sideOrigins[i].pos[VX] =
vtx->V_pos[VX] + sideOwners[i]->dX / 2;
sideOrigins[i].pos[VY] =
vtx->V_pos[VY] + sideOwners[i]->dY / 2;
}

// Store the current state of the world into both the registers.
Sv_RegisterWorld(&worldRegister, false);
Sv_RegisterWorld(&initialRegister, true);
Expand Down Expand Up @@ -1575,10 +1534,10 @@ float Sv_MobjDistance(const mobj_t* mo, const ownerinfo_t* info, boolean isReal)
*/
float Sv_SectorDistance(int index, const ownerinfo_t* info)
{
sector_t* sector = SECTOR_PTR(index);
sector_t* sector = SECTOR_PTR(index);

return P_ApproxDistance3(info->pos[VX] - sectorOrigins[index].pos[VX],
info->pos[VY] - sectorOrigins[index].pos[VY],
return P_ApproxDistance3(info->pos[VX] - sector->origin.pos[VX],
info->pos[VY] - sector->origin.pos[VY],
info->pos[VZ] -
((sector->planes[PLN_CEILING]->height +
sector->planes[PLN_FLOOR]->height) / 2));
Expand Down Expand Up @@ -1622,14 +1581,14 @@ float Sv_DeltaDistance(const void* deltaPtr, const ownerinfo_t* info)

if(delta->type == DT_SIDE)
{
return P_ApproxDistance(info->pos[VX] - sideOrigins[delta->id].pos[VX],
info->pos[VY] - sideOrigins[delta->id].pos[VY]);
sidedef_t* sideDef = &sideDefs[delta->id];
return P_ApproxDistance(info->pos[VX] - sideDef->origin.pos[VX],
info->pos[VY] - sideDef->origin.pos[VY]);
}

if(delta->type == DT_POLY)
{
polyobj_t* po = polyObjs[delta->id];

polyobj_t* po = polyObjs[delta->id];
return P_ApproxDistance(info->pos[VX] - po->pos[VX],
info->pos[VY] - po->pos[VY]);
}
Expand Down

0 comments on commit 929ef00

Please sign in to comment.