Skip to content

Commit

Permalink
Improved performance for content type filter.
Browse files Browse the repository at this point in the history
Signed-off-by: Kristian Duske <[email protected]>
  • Loading branch information
kduske committed Aug 28, 2013
1 parent 7e0c6e4 commit 2428ceb
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Mac/TrenchBroom/TrenchBroom-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2585</string>
<string>2590</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
Expand Down
25 changes: 24 additions & 1 deletion Source/Model/Face.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ namespace TrenchBroom {
m_selected = false;
m_texAxesValid = false;
m_vertexCacheValid = false;
m_contentType = CTDefault;
}

void Face::texAxesAndIndices(const Vec3f& faceNormal, Vec3f& xAxis, Vec3f& yAxis, unsigned int& planeNormIndex, unsigned int& faceNormIndex) const {
Expand Down Expand Up @@ -330,6 +331,25 @@ namespace TrenchBroom {
m_yOffset = Math<float>::correct(m_yOffset);
}

void Face::updateContentType() {
if (!m_textureName.empty()) {
if (m_textureName[0] == '*')
m_contentType = CTLiquid;
else if (Utility::containsString(m_textureName, "clip", false))
m_contentType = CTClip;
else if (Utility::containsString(m_textureName, "skip", false))
m_contentType = CTSkip;
else if (Utility::containsString(m_textureName, "hint", false))
m_contentType = CTHint;
else if (Utility::containsString(m_textureName, "trigger", false))
m_contentType = CTTrigger;
else
m_contentType = CTDefault;
} else {
m_contentType = CTDefault;
}
}

Face::Face(const BBoxf& worldBounds, bool forceIntegerFacePoints, const Vec3f& point1, const Vec3f& point2, const Vec3f& point3, const String& textureName) : m_worldBounds(worldBounds), m_textureName(textureName) {
init();
m_worldBounds = worldBounds;
Expand Down Expand Up @@ -365,7 +385,8 @@ namespace TrenchBroom {
m_texAxesValid(false),
m_vertexCacheValid(false),
m_filePosition(face.filePosition()),
m_selected(false) {
m_selected(false),
m_contentType(face.contentType()) {
face.getPoints(m_points[0], m_points[1], m_points[2]);
updatePointsFromBoundary();
}
Expand Down Expand Up @@ -411,6 +432,7 @@ namespace TrenchBroom {
m_texAxesValid = false;
m_vertexCacheValid = false;
m_selected = faceTemplate.selected();
m_contentType = faceTemplate.contentType();
}

void Face::setBrush(Brush* brush) {
Expand Down Expand Up @@ -502,6 +524,7 @@ namespace TrenchBroom {
if (m_texture != NULL)
m_texture->incUsageCount();
m_vertexCacheValid = false;
updateContentType();
}

void Face::moveTexture(const Vec3f& up, const Vec3f& right, Direction direction, float distance) {
Expand Down
17 changes: 17 additions & 0 deletions Source/Model/Face.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ namespace TrenchBroom {

class Face : public Utility::Allocator<Face> {
public:
enum ContentType {
CTLiquid,
CTClip,
CTSkip,
CTHint,
CTTrigger,
CTDefault
};

class WeightOrder {
private:
const Planef::WeightOrder& m_planeOrder;
Expand Down Expand Up @@ -127,6 +136,8 @@ namespace TrenchBroom {

size_t m_filePosition;
bool m_selected;

ContentType m_contentType;

inline void rotateTexAxes(Vec3f& xAxis, Vec3f& yAxis, const float angle, const unsigned int planeNormIndex) const {
// for some reason, when the texture plane normal is the Y axis, we must rotation clockwise
Expand All @@ -142,6 +153,7 @@ namespace TrenchBroom {

void projectOntoTexturePlane(Vec3f& xAxis, Vec3f& yAxis);
void compensateTransformation(const Mat4f& transformation);
void updateContentType();
public:
Face(const BBoxf& worldBounds, bool forceIntegerFacePoints, const Vec3f& point1, const Vec3f& point2, const Vec3f& point3, const String& textureName);
Face(const BBoxf& worldBounds, bool forceIntegerFacePoints, const Face& faceTemplate);
Expand Down Expand Up @@ -215,12 +227,17 @@ namespace TrenchBroom {
return centerOfVertices(m_side->vertices);
}

inline ContentType contentType() const {
return m_contentType;
}

inline const String& textureName() const {
return m_textureName;
}

inline void setTextureName(const String& textureName) {
m_textureName = textureName;
updateContentType();
}

inline Texture* texture() const {
Expand Down
33 changes: 20 additions & 13 deletions Source/Model/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,26 @@ namespace TrenchBroom {
unsigned int triggerCount = 0;
bool matches = pattern.empty();
for (unsigned int i = 0; i < faces.size(); i++) {
const String& textureName = faces[i]->textureName();
if (!m_viewOptions.showClipBrushes() && Utility::containsString(textureName, "clip", false))
clipCount++;
else if (!m_viewOptions.showSkipBrushes() && Utility::containsString(textureName, "skip", false))
skipCount++;
else if (!m_viewOptions.showHintBrushes() && Utility::containsString(textureName, "hint", false))
hintCount++;
else if (!m_viewOptions.showLiquidBrushes() && textureName[0] == '*')
liquidCount++;
else if (!m_viewOptions.showTriggerBrushes() && Utility::containsString(textureName, "trigger", false))
triggerCount++;
else if (!matches)
matches = Utility::containsString(textureName, pattern, false);
switch (faces[i]->contentType()) {
case Face::CTLiquid:
liquidCount++;
break;
case Face::CTClip:
clipCount++;
break;
case Face::CTSkip:
skipCount++;
break;
case Face::CTHint:
hintCount++;
case Face::CTTrigger:
triggerCount++;
break;
default:
if (!matches)
matches = Utility::containsString(faces[i]->textureName(), pattern, false);
break;
}
}

if (!m_viewOptions.showClipBrushes() && clipCount == faces.size())
Expand Down
2 changes: 1 addition & 1 deletion Windows/TrenchBroom/BuildNo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
337
338

0 comments on commit 2428ceb

Please sign in to comment.