qbsp: optimize FindTexinfo
This commit is contained in:
parent
fbaee78379
commit
1f7bd69385
|
|
@ -80,6 +80,9 @@ typedef struct mapdata_s {
|
|||
std::vector<miptex_t> miptex;
|
||||
std::vector<mtexinfo_t> mtexinfos;
|
||||
|
||||
/* quick lookup for texinfo */
|
||||
std::map<mtexinfo_t, int> mtexinfo_lookup;
|
||||
|
||||
/* map from plane hash code to list of indicies in `planes` vector */
|
||||
std::unordered_map<int, std::vector<int>> planehash;
|
||||
|
||||
|
|
|
|||
|
|
@ -200,6 +200,29 @@ typedef struct mtexinfo_s {
|
|||
float vecs[2][4]; /* [s/t][xyz offset] */
|
||||
int32_t miptex;
|
||||
uint64_t flags;
|
||||
|
||||
bool operator<(const mtexinfo_s &other) const {
|
||||
if (this->miptex < other.miptex)
|
||||
return true;
|
||||
if (this->miptex > other.miptex)
|
||||
return false;
|
||||
|
||||
if (this->flags < other.flags)
|
||||
return true;
|
||||
if (this->flags > other.flags)
|
||||
return false;
|
||||
|
||||
for (int i=0; i<2; i++) {
|
||||
for (int j=0; j<4; j++) {
|
||||
if (this->vecs[i][j] < other.vecs[i][j])
|
||||
return true;
|
||||
if (this->vecs[i][j] > other.vecs[i][j])
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} mtexinfo_t;
|
||||
|
||||
typedef struct visfacet_s {
|
||||
|
|
|
|||
48
qbsp/map.cc
48
qbsp/map.cc
|
|
@ -23,6 +23,7 @@
|
|||
#include <memory>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
|
@ -236,38 +237,31 @@ Returns a global texinfo number
|
|||
int
|
||||
FindTexinfo(mtexinfo_t *texinfo, uint64_t flags)
|
||||
{
|
||||
const size_t num_texinfo = map.mtexinfos.size();
|
||||
|
||||
/* Set the texture flags */
|
||||
texinfo->flags = flags;
|
||||
|
||||
for (size_t index = 0; index < num_texinfo; index++) {
|
||||
const mtexinfo_t *target = &map.mtexinfos.at(index);
|
||||
if (texinfo->miptex != target->miptex)
|
||||
continue;
|
||||
if (texinfo->flags != target->flags)
|
||||
continue;
|
||||
|
||||
/* Don't worry about texture alignment on skip or hint surfaces */
|
||||
if (texinfo->flags & (TEX_SKIP | TEX_HINT))
|
||||
return index;
|
||||
|
||||
int j;
|
||||
for (j = 0; j < 4; j++) {
|
||||
if (texinfo->vecs[0][j] != target->vecs[0][j])
|
||||
break;
|
||||
if (texinfo->vecs[1][j] != target->vecs[1][j])
|
||||
break;
|
||||
}
|
||||
if (j != 4)
|
||||
continue;
|
||||
|
||||
return static_cast<int>(index);
|
||||
|
||||
/* Don't worry about texture alignment on skip or hint surfaces */
|
||||
if (texinfo->flags & (TEX_SKIP | TEX_HINT)) {
|
||||
for (int i=0; i<2; i++)
|
||||
for (int j=0; j<4; j++)
|
||||
texinfo->vecs[i][j] = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
// check for an exact match in the reverse lookup
|
||||
const auto it = map.mtexinfo_lookup.find(*texinfo);
|
||||
if (it != map.mtexinfo_lookup.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
/* Allocate a new texinfo at the end of the array */
|
||||
const int num_texinfo = static_cast<int>(map.mtexinfos.size());
|
||||
map.mtexinfos.push_back(*texinfo);
|
||||
return static_cast<int>(num_texinfo);
|
||||
map.mtexinfo_lookup[*texinfo] = num_texinfo;
|
||||
|
||||
// catch broken < implementations in mtexinfo_t
|
||||
assert(map.mtexinfo_lookup.find(*texinfo) != map.mtexinfo_lookup.end());
|
||||
|
||||
return num_texinfo;
|
||||
}
|
||||
|
||||
/* detect colors with components in 0-1 and scale them to 0-255 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue