- create an intermediate structure between sectors and subsectors.
A section is a continuous part of a sector or in some case of several nearby continuous parts. For sectors with far away parts multiple sections will be created, especially when they lie in disjoint parts of the map. This is mainly supposed to cut down on time for linking dynamic lights. Since they need to traverse subsectors to find all touching sidedefs a more coarse data structure that only contains the info needed for this is more suitable. In particular, this does not contain any intra-sector lines, i.e. those with both sides in the same sector.
This commit is contained in:
parent
b1d35eb0b3
commit
49bfdbef9f
11 changed files with 1282 additions and 904 deletions
141
src/tarray.h
141
src/tarray.h
|
|
@ -250,6 +250,12 @@ public:
|
|||
return Array[Count-1];
|
||||
}
|
||||
|
||||
// returns address of first element
|
||||
T *Data() const
|
||||
{
|
||||
return &Array[0];
|
||||
}
|
||||
|
||||
unsigned int Find(const T& item) const
|
||||
{
|
||||
unsigned int i;
|
||||
|
|
@ -267,6 +273,7 @@ public:
|
|||
::new((void*)&Array[Count]) T(item);
|
||||
return Count++;
|
||||
}
|
||||
|
||||
void Append(const TArray<T> &item)
|
||||
{
|
||||
unsigned start = Reserve(item.Size());
|
||||
|
|
@ -350,6 +357,18 @@ public:
|
|||
::new ((void *)&Array[index]) T(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Reserves a range of entries in the middle of the array, shifting elements as needed
|
||||
void ReserveAt(unsigned int index, unsigned int amount)
|
||||
{
|
||||
Grow(amount);
|
||||
memmove(&Array[index + amount], &Array[index], sizeof(T)*(Count - index - amount));
|
||||
for (unsigned i = 0; i < amount; i++)
|
||||
{
|
||||
::new ((void *)&Array[index + i]) T();
|
||||
}
|
||||
}
|
||||
|
||||
void ShrinkToFit ()
|
||||
{
|
||||
if (Most > Count)
|
||||
|
|
@ -1332,3 +1351,125 @@ public:
|
|||
memset(&bytes[0], 0, bytes.Size());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// A wrapper to externally stored data.
|
||||
// I would have expected something for this in the stl, but std::span is only in C++20.
|
||||
template <class T>
|
||||
class TArrayView
|
||||
{
|
||||
public:
|
||||
|
||||
typedef TIterator<T> iterator;
|
||||
typedef TIterator<const T> const_iterator;
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return &Array[0];
|
||||
}
|
||||
const_iterator begin() const
|
||||
{
|
||||
return &Array[0];
|
||||
}
|
||||
const_iterator cbegin() const
|
||||
{
|
||||
return &Array[0];
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return &Array[Count];
|
||||
}
|
||||
const_iterator end() const
|
||||
{
|
||||
return &Array[Count];
|
||||
}
|
||||
const_iterator cend() const
|
||||
{
|
||||
return &Array[Count];
|
||||
}
|
||||
|
||||
|
||||
////////
|
||||
TArrayView() = default; // intended to keep this type trivial.
|
||||
TArrayView(T *data, unsigned count = 0)
|
||||
{
|
||||
Count = count;
|
||||
Array = data;
|
||||
}
|
||||
TArrayView(const TArrayView<T> &other)
|
||||
{
|
||||
Count = other.Count;
|
||||
Array = other.Array;
|
||||
}
|
||||
TArrayView<T> &operator= (const TArrayView<T> &other)
|
||||
{
|
||||
Count = other.Count;
|
||||
Array = other.Array;
|
||||
return *this;
|
||||
}
|
||||
// Check equality of two arrays
|
||||
bool operator==(const TArrayView<T> &other) const
|
||||
{
|
||||
if (Count != other.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (unsigned int i = 0; i < Count; ++i)
|
||||
{
|
||||
if (Array[i] != other.Array[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Return a reference to an element
|
||||
T &operator[] (size_t index) const
|
||||
{
|
||||
return Array[index];
|
||||
}
|
||||
// Returns a reference to the last element
|
||||
T &Last() const
|
||||
{
|
||||
return Array[Count - 1];
|
||||
}
|
||||
|
||||
// returns address of first element
|
||||
T *Data() const
|
||||
{
|
||||
return &Array[0];
|
||||
}
|
||||
|
||||
unsigned Size() const
|
||||
{
|
||||
return Count;
|
||||
}
|
||||
|
||||
unsigned int Find(const T& item) const
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < Count; ++i)
|
||||
{
|
||||
if (Array[i] == item)
|
||||
break;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void Set(T *data, unsigned count)
|
||||
{
|
||||
Array = data;
|
||||
Count = count;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Count = 0;
|
||||
Array = nullptr;
|
||||
}
|
||||
private:
|
||||
T *Array;
|
||||
unsigned int Count;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue