- [polyobj branch] cleaned up polyobject code for upcoming rework:

* no longer uses segs to create polyobjects
  * use TArrays instead of doing multiple passes over the data.
  * started with node list to allow linking a polyobject into multiple subsectors.


SVN r2375 (polyobjects)
This commit is contained in:
Christoph Oelckers 2010-06-14 21:30:38 +00:00
parent 1436f0a4fa
commit 0913fb16a4
13 changed files with 474 additions and 489 deletions

View file

@ -173,7 +173,6 @@ void FNodeBuilder::CreateSubsectorsForReal ()
subsector_t sub; subsector_t sub;
unsigned int i; unsigned int i;
sub.poly = NULL;
sub.validcount = 0; sub.validcount = 0;
sub.CenterX = 0; // Code in p_setup.cpp will set these for us later. sub.CenterX = 0; // Code in p_setup.cpp will set these for us later.
sub.CenterY = 0; sub.CenterY = 0;

View file

@ -95,7 +95,6 @@ void FNodeBuilder::Extract (node_t *&outNodes, int &nodeCount,
DWORD numsegs = CloseSubsector (segs, i, outVerts); DWORD numsegs = CloseSubsector (segs, i, outVerts);
outSubs[i].numlines = numsegs; outSubs[i].numlines = numsegs;
outSubs[i].firstline = segs.Size() - numsegs; outSubs[i].firstline = segs.Size() - numsegs;
outSubs[i].poly = NULL;
} }
segCount = segs.Size (); segCount = segs.Size ();

View file

@ -539,7 +539,7 @@ bool PO_MovePolyobj (int num, int x, int y, bool force=false);
bool PO_RotatePolyobj (int num, angle_t angle); bool PO_RotatePolyobj (int num, angle_t angle);
void PO_Init (); void PO_Init ();
bool PO_Busy (int polyobj); bool PO_Busy (int polyobj);
void PO_ClosestPoint(const FPolyObj *poly, fixed_t ox, fixed_t oy, fixed_t &x, fixed_t &y, seg_t **seg); void PO_ClosestPoint(const FPolyObj *poly, fixed_t ox, fixed_t oy, fixed_t &x, fixed_t &y, side_t **seg);
struct FPolyObj *PO_GetPolyobj(int polyNum); struct FPolyObj *PO_GetPolyobj(int polyNum);
// //

View file

@ -687,9 +687,9 @@ line_t *FBlockLinesIterator::Next()
polyLink->polyobj->validcount = validcount; polyLink->polyobj->validcount = validcount;
} }
line_t *ld = polyLink->polyobj->lines[polyIndex]; line_t *ld = polyLink->polyobj->Linedefs[polyIndex];
if (++polyIndex >= polyLink->polyobj->numlines) if (++polyIndex >= (int)polyLink->polyobj->Linedefs.Size())
{ {
polyLink = polyLink->next; polyLink = polyLink->next;
polyIndex = 0; polyIndex = 0;

View file

@ -496,8 +496,8 @@ void P_SerializePolyobjs (FArchive &arc)
arc << seg << po_NumPolyobjs; arc << seg << po_NumPolyobjs;
for(i = 0, po = polyobjs; i < po_NumPolyobjs; i++, po++) for(i = 0, po = polyobjs; i < po_NumPolyobjs; i++, po++)
{ {
arc << po->tag << po->angle << po->startSpot[0] << arc << po->tag << po->angle << po->StartSpot.x <<
po->startSpot[1] << po->interpolation; po->StartSpot.y << po->interpolation;
} }
} }
else else
@ -525,8 +525,8 @@ void P_SerializePolyobjs (FArchive &arc)
arc << angle; arc << angle;
PO_RotatePolyobj (po->tag, angle); PO_RotatePolyobj (po->tag, angle);
arc << deltaX << deltaY << po->interpolation; arc << deltaX << deltaY << po->interpolation;
deltaX -= po->startSpot[0]; deltaX -= po->StartSpot.x;
deltaY -= po->startSpot[1]; deltaY -= po->StartSpot.y;
PO_MovePolyobj (po->tag, deltaX, deltaY, true); PO_MovePolyobj (po->tag, deltaX, deltaY, true);
} }
} }

View file

@ -3301,6 +3301,7 @@ void P_FreeLevelData ()
} }
extern msecnode_t *headsecnode; extern msecnode_t *headsecnode;
extern FPolyNode *headpolynode;
void P_FreeExtraLevelData() void P_FreeExtraLevelData()
{ {
@ -3327,6 +3328,17 @@ void P_FreeExtraLevelData()
} }
headsecnode = NULL; headsecnode = NULL;
} }
{
FPolyNode *node = headpolynode;
while (node != NULL)
{
FPolyNode *next = node->pnext;
delete node;
node = next;
}
headpolynode = NULL;
}
} }
// //

View file

@ -305,7 +305,7 @@ bool SightCheck::P_SightBlockLinesIterator (int x, int y)
int *list; int *list;
polyblock_t *polyLink; polyblock_t *polyLink;
int i; unsigned int i;
extern polyblock_t **PolyBlockMap; extern polyblock_t **PolyBlockMap;
offset = y*bmapwidth+x; offset = y*bmapwidth+x;
@ -318,9 +318,9 @@ bool SightCheck::P_SightBlockLinesIterator (int x, int y)
if (polyLink->polyobj->validcount != validcount) if (polyLink->polyobj->validcount != validcount)
{ {
polyLink->polyobj->validcount = validcount; polyLink->polyobj->validcount = validcount;
for (i = 0; i < polyLink->polyobj->numlines; i++) for (i = 0; i < polyLink->polyobj->Linedefs.Size(); i++)
{ {
if (!P_SightCheckLine (polyLink->polyobj->lines[i])) if (!P_SightCheckLine (polyLink->polyobj->Linedefs[i]))
return false; return false;
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -1098,6 +1098,7 @@ void R_Subsector (subsector_t *sub)
R_ProjectParticle (Particles + i, subsectors[sub-subsectors].sector, shade, FakeSide); R_ProjectParticle (Particles + i, subsectors[sub-subsectors].sector, shade, FakeSide);
} }
#if 0
if (sub->poly) if (sub->poly)
{ // Render the polyobj in the subsector first { // Render the polyobj in the subsector first
int polyCount = sub->poly->numsegs; int polyCount = sub->poly->numsegs;
@ -1107,6 +1108,9 @@ void R_Subsector (subsector_t *sub)
R_AddLine (*polySeg++); R_AddLine (*polySeg++);
} }
} }
#else
#pragma warning("Deactivated polyobj code!")
#endif
while (count--) while (count--)
{ {

View file

@ -854,6 +854,9 @@ struct side_t
DInterpolation *SetInterpolation(int position); DInterpolation *SetInterpolation(int position);
void StopInterpolation(int position); void StopInterpolation(int position);
vertex_t *V1() const;
vertex_t *V2() const;
}; };
FArchive &operator<< (FArchive &arc, side_t::part &p); FArchive &operator<< (FArchive &arc, side_t::part &p);
@ -916,19 +919,20 @@ struct msecnode_t
bool visited; // killough 4/4/98, 4/7/98: used in search algorithms bool visited; // killough 4/4/98, 4/7/98: used in search algorithms
}; };
struct FPolyNode;
// //
// A SubSector. // A SubSector.
// References a Sector. // References a Sector.
// Basically, this is a list of LineSegs indicating the visible walls that // Basically, this is a list of LineSegs indicating the visible walls that
// define (all or some) sides of a convex BSP leaf. // define (all or some) sides of a convex BSP leaf.
// //
struct FPolyObj;
struct subsector_t struct subsector_t
{ {
sector_t *sector; sector_t *sector;
DWORD numlines; DWORD numlines;
DWORD firstline; DWORD firstline;
FPolyObj *poly; FPolyNode *polys;
int validcount; int validcount;
fixed_t CenterX, CenterY; fixed_t CenterX, CenterY;
}; };
@ -954,9 +958,52 @@ struct seg_t
BITFIELD bPolySeg:1; BITFIELD bPolySeg:1;
}; };
//
// Linked lists of polyobjects
//
struct FPolyObj;
struct FPolyNode
{
FPolyObj *poly; // owning polyobject
FPolyNode *pnext; // next polyobj in list
FPolyNode **pprev; // previous polyobj
subsector_t *subsector; // containimg subsector
FPolyNode *snext; // next subsector
FPolyNode **sprev; // previous subsector
TArray<seg_t> segs; // segs for this node
};
struct FPolyVertex
{
fixed_t x, y;
};
// ===== Polyobj data ===== // ===== Polyobj data =====
struct FPolyObj struct FPolyObj
{ {
TArray<side_t *> Sidedefs;
TArray<line_t *> Linedefs;
TArray<vertex_t *> Vertices;
TArray<FPolyVertex> OriginalPts;
TArray<FPolyVertex> PrevPts;
FPolyVertex StartSpot;
angle_t angle;
int tag; // reference tag assigned in HereticEd
int bbox[4];
int validcount;
int crush; // should the polyobj attempt to crush mobjs?
bool bHurtOnTouch; // should the polyobj hurt anything it touches?
int seqType;
fixed_t size; // polyobj size (area of POLY_AREAUNIT == size of FRACUNIT)
FPolyNode *subsectorlinks;
DThinker *specialdata; // pointer to a thinker, if the poly is moving
TObjPtr<DInterpolation> interpolation;
/*
int numsegs; int numsegs;
seg_t **segs; seg_t **segs;
int numlines; int numlines;
@ -966,16 +1013,22 @@ struct FPolyObj
fixed_t startSpot[2]; fixed_t startSpot[2];
vertex_t *originalPts; // used as the base for the rotations vertex_t *originalPts; // used as the base for the rotations
vertex_t *prevPts; // use to restore the old point values vertex_t *prevPts; // use to restore the old point values
angle_t angle; */
int tag; // reference tag assigned in HereticEd
int bbox[4]; FPolyObj()
int validcount; {
int crush; // should the polyobj attempt to crush mobjs? StartSpot.x = StartSpot.y = 0;
bool bHurtOnTouch; // should the polyobj hurt anything it touches? angle = 0;
int seqType; tag = 0;
fixed_t size; // polyobj size (area of POLY_AREAUNIT == size of FRACUNIT) memset(bbox, 0, sizeof(bbox));
DThinker *specialdata; // pointer to a thinker, if the poly is moving validcount = 0;
TObjPtr<DInterpolation> interpolation; crush = 0;
bHurtOnTouch = false;
seqType = 0;
size = 0;
subsectorlinks = NULL;
specialdata = NULL;
}
~FPolyObj(); ~FPolyObj();
DInterpolation *SetInterpolation(); DInterpolation *SetInterpolation();

View file

@ -728,8 +728,8 @@ void DWallScrollInterpolation::Serialize(FArchive &arc)
DPolyobjInterpolation::DPolyobjInterpolation(FPolyObj *po) DPolyobjInterpolation::DPolyobjInterpolation(FPolyObj *po)
{ {
poly = po; poly = po;
oldverts.Resize(po->numvertices<<1); oldverts.Resize(po->Vertices.Size() << 1);
bakverts.Resize(po->numvertices<<1); bakverts.Resize(po->Vertices.Size() << 1);
UpdateInterpolation (); UpdateInterpolation ();
interpolator.AddInterpolation(this); interpolator.AddInterpolation(this);
} }
@ -755,10 +755,10 @@ void DPolyobjInterpolation::Destroy()
void DPolyobjInterpolation::UpdateInterpolation() void DPolyobjInterpolation::UpdateInterpolation()
{ {
for(int i = 0; i < poly->numvertices; i++) for(unsigned int i = 0; i < poly->Vertices.Size(); i++)
{ {
oldverts[i*2 ] = poly->vertices[i]->x; oldverts[i*2 ] = poly->Vertices[i]->x;
oldverts[i*2+1] = poly->vertices[i]->y; oldverts[i*2+1] = poly->Vertices[i]->y;
} }
} }
@ -770,10 +770,10 @@ void DPolyobjInterpolation::UpdateInterpolation()
void DPolyobjInterpolation::Restore() void DPolyobjInterpolation::Restore()
{ {
for(int i = 0; i < poly->numvertices; i++) for(unsigned int i = 0; i < poly->Vertices.Size(); i++)
{ {
poly->vertices[i]->x = bakverts[i*2 ]; poly->Vertices[i]->x = bakverts[i*2 ];
poly->vertices[i]->y = bakverts[i*2+1]; poly->Vertices[i]->y = bakverts[i*2+1];
} }
//poly->Moved(); //poly->Moved();
} }
@ -786,10 +786,10 @@ void DPolyobjInterpolation::Restore()
void DPolyobjInterpolation::Interpolate(fixed_t smoothratio) void DPolyobjInterpolation::Interpolate(fixed_t smoothratio)
{ {
for(int i = 0; i < poly->numvertices; i++) for(unsigned int i = 0; i < poly->Vertices.Size(); i++)
{ {
fixed_t *px = &poly->vertices[i]->x; fixed_t *px = &poly->Vertices[i]->x;
fixed_t *py = &poly->vertices[i]->y; fixed_t *py = &poly->Vertices[i]->y;
bakverts[i*2 ] = *px; bakverts[i*2 ] = *px;
bakverts[i*2+1] = *py; bakverts[i*2+1] = *py;

View file

@ -1471,6 +1471,7 @@ void RP_Subsector (subsector_t *sub)
// R_ProjectParticle (Particles + i, subsectors[sub-subsectors].sector, shade, FakeSide); // R_ProjectParticle (Particles + i, subsectors[sub-subsectors].sector, shade, FakeSide);
// } // }
#if 0
if (sub->poly) if (sub->poly)
{ // Render the polyobj in the subsector first { // Render the polyobj in the subsector first
int polyCount = sub->poly->numsegs; int polyCount = sub->poly->numsegs;
@ -1480,6 +1481,7 @@ void RP_Subsector (subsector_t *sub)
RP_AddLine (*polySeg++); RP_AddLine (*polySeg++);
} }
} }
#endif
while (count--) while (count--)
{ {

View file

@ -795,11 +795,11 @@ static void CalcSectorSoundOrg(const sector_t *sec, int channum, fixed_t *x, fix
static void CalcPolyobjSoundOrg(const FPolyObj *poly, fixed_t *x, fixed_t *y, fixed_t *z) static void CalcPolyobjSoundOrg(const FPolyObj *poly, fixed_t *x, fixed_t *y, fixed_t *z)
{ {
seg_t *seg; side_t *side;
sector_t *sec; sector_t *sec;
PO_ClosestPoint(poly, *x, *y, *x, *y, &seg); PO_ClosestPoint(poly, *x, *y, *x, *y, &side);
sec = seg->frontsector; sec = side->sector;
*z = clamp(*z, sec->floorplane.ZatPoint(*x, *y), sec->ceilingplane.ZatPoint(*x, *y)); *z = clamp(*z, sec->floorplane.ZatPoint(*x, *y), sec->ceilingplane.ZatPoint(*x, *y));
} }