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<miptex_t> miptex;
|
||||||
std::vector<mtexinfo_t> mtexinfos;
|
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 */
|
/* map from plane hash code to list of indicies in `planes` vector */
|
||||||
std::unordered_map<int, std::vector<int>> planehash;
|
std::unordered_map<int, std::vector<int>> planehash;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,29 @@ typedef struct mtexinfo_s {
|
||||||
float vecs[2][4]; /* [s/t][xyz offset] */
|
float vecs[2][4]; /* [s/t][xyz offset] */
|
||||||
int32_t miptex;
|
int32_t miptex;
|
||||||
uint64_t flags;
|
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;
|
} mtexinfo_t;
|
||||||
|
|
||||||
typedef struct visfacet_s {
|
typedef struct visfacet_s {
|
||||||
|
|
|
||||||
48
qbsp/map.cc
48
qbsp/map.cc
|
|
@ -23,6 +23,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -236,38 +237,31 @@ Returns a global texinfo number
|
||||||
int
|
int
|
||||||
FindTexinfo(mtexinfo_t *texinfo, uint64_t flags)
|
FindTexinfo(mtexinfo_t *texinfo, uint64_t flags)
|
||||||
{
|
{
|
||||||
const size_t num_texinfo = map.mtexinfos.size();
|
|
||||||
|
|
||||||
/* Set the texture flags */
|
/* Set the texture flags */
|
||||||
texinfo->flags = flags;
|
texinfo->flags = flags;
|
||||||
|
|
||||||
for (size_t index = 0; index < num_texinfo; index++) {
|
/* Don't worry about texture alignment on skip or hint surfaces */
|
||||||
const mtexinfo_t *target = &map.mtexinfos.at(index);
|
if (texinfo->flags & (TEX_SKIP | TEX_HINT)) {
|
||||||
if (texinfo->miptex != target->miptex)
|
for (int i=0; i<2; i++)
|
||||||
continue;
|
for (int j=0; j<4; j++)
|
||||||
if (texinfo->flags != target->flags)
|
texinfo->vecs[i][j] = 0.0f;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 */
|
/* 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);
|
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 */
|
/* detect colors with components in 0-1 and scale them to 0-255 */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue