mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-29 07:22:07 +00:00
- made the MapSectionGenerator a class to remove a global array.
This commit is contained in:
parent
4357f0dc40
commit
202d209eb8
1 changed files with 133 additions and 119 deletions
|
@ -51,13 +51,35 @@
|
|||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
// Map section generation
|
||||
// Map sections are physically separated parts of the map.
|
||||
// If the player is in section A, any map part in other sections can
|
||||
// often be quickly discarded to improve performance.
|
||||
//
|
||||
//==========================================================================
|
||||
static TArray<subsector_t *> MapSectionCollector;
|
||||
|
||||
static void DoSetMapSection(subsector_t *sub, int num)
|
||||
struct MapSectionGenerator
|
||||
{
|
||||
struct cvertex_t
|
||||
{
|
||||
double X, Y;
|
||||
|
||||
operator int() const { return xs_FloorToInt(X) + 65536 * xs_FloorToInt(Y); }
|
||||
bool operator!= (const cvertex_t &other) const { return fabs(X - other.X) >= EQUAL_EPSILON || fabs(Y - other.Y) >= EQUAL_EPSILON; }
|
||||
cvertex_t& operator =(const vertex_t *v) { X = v->fX(); Y = v->fY(); return *this; }
|
||||
};
|
||||
|
||||
typedef TMap<cvertex_t, int> FSectionVertexMap;
|
||||
TArray<subsector_t *> MapSectionCollector;
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void DoSetMapSection(subsector_t *sub, int num)
|
||||
{
|
||||
MapSectionCollector.Resize(1);
|
||||
MapSectionCollector[0] = sub;
|
||||
sub->mapsection = num;
|
||||
|
@ -82,30 +104,20 @@ static void DoSetMapSection(subsector_t *sub, int num)
|
|||
}
|
||||
}
|
||||
MapSectionCollector.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Merge sections. This is needed in case the map contains errors
|
||||
// like overlapping lines resulting in abnormal subsectors.
|
||||
//
|
||||
// This function ensures that any vertex position can only be in one section.
|
||||
//
|
||||
//==========================================================================
|
||||
//==========================================================================
|
||||
//
|
||||
// Merge sections. This is needed in case the map contains errors
|
||||
// like overlapping lines resulting in abnormal subsectors.
|
||||
//
|
||||
// This function ensures that any vertex position can only be in one section.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
struct cvertex_t
|
||||
{
|
||||
double X, Y;
|
||||
|
||||
operator int() const { return xs_FloorToInt(X) + 65536 * xs_FloorToInt(Y); }
|
||||
bool operator!= (const cvertex_t &other) const { return fabs(X - other.X) >= EQUAL_EPSILON || fabs(Y - other.Y) >= EQUAL_EPSILON; }
|
||||
cvertex_t& operator =(const vertex_t *v) { X = v->fX(); Y = v->fY(); return *this; }
|
||||
};
|
||||
|
||||
typedef TMap<cvertex_t, int> FSectionVertexMap;
|
||||
|
||||
static int MergeMapSections(int num)
|
||||
{
|
||||
int MergeMapSections(int num)
|
||||
{
|
||||
FSectionVertexMap vmap;
|
||||
FSectionVertexMap::Pair *pair;
|
||||
TArray<int> sectmap;
|
||||
|
@ -168,16 +180,16 @@ static int MergeMapSections(int num)
|
|||
assert(sub.mapsection != -1);
|
||||
}
|
||||
return mergecount - 1;
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void SetMapSections()
|
||||
{
|
||||
void SetMapSections()
|
||||
{
|
||||
bool set;
|
||||
int num = 0;
|
||||
do
|
||||
|
@ -197,10 +209,11 @@ static void SetMapSections()
|
|||
while (set);
|
||||
num = MergeMapSections(num);
|
||||
currentmapsection.Resize(1 + num/8);
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
Printf("%d map sections found\n", num);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
|
@ -283,7 +296,8 @@ static void PrepareSectorData()
|
|||
}
|
||||
}
|
||||
}
|
||||
SetMapSections();
|
||||
MapSectionGenerator msg;
|
||||
msg.SetMapSections();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
Loading…
Reference in a new issue