Skip to content

Commit e018ece

Browse files
committed
misc fixes
- fix downscale not working with some non-POT dimensions - fix disabled Solid Entities render flag still rendering ent clipnodes - fix downscale crash - don't select all faces when worldspawn is selected before switching to face picking mode (laggy) - fix debug widget crash
1 parent c7c5faf commit e018ece

File tree

4 files changed

+47
-28
lines changed

4 files changed

+47
-28
lines changed

src/bsp/Bsp.cpp

+26-15
Original file line numberDiff line numberDiff line change
@@ -2743,7 +2743,8 @@ bool Bsp::downscale_texture(int textureId, int newWidth, int newHeight) {
27432743
}
27442744
byte* newPalette = (byte*)(textures + texOffset + newOffset[3] + newWidths[3] * newHeights[3]);
27452745

2746-
float srcScale = (float)oldWidth / tex.nWidth;
2746+
float srcScaleX = (float)oldWidth / tex.nWidth;
2747+
float srcScaleY = (float)oldHeight / tex.nHeight;
27472748

27482749
for (int i = 0; i < 4; i++) {
27492750
byte* srcData = (byte*)(textures + texOffset + tex.nOffsets[i]);
@@ -2752,10 +2753,10 @@ bool Bsp::downscale_texture(int textureId, int newWidth, int newHeight) {
27522753
int dstWidth = newWidths[i];
27532754

27542755
for (int y = 0; y < newHeights[i]; y++) {
2755-
int srcY = (int)(srcScale * y + 0.5f);
2756+
int srcY = (int)(srcScaleY * y + 0.5f);
27562757

27572758
for (int x = 0; x < newWidths[i]; x++) {
2758-
int srcX = (int)(srcScale * x + 0.5f);
2759+
int srcX = (int)(srcScaleX * x + 0.5f);
27592760

27602761
dstData[y * dstWidth + x] = srcData[srcY * srcWidth + srcX];
27612762
}
@@ -2769,7 +2770,8 @@ bool Bsp::downscale_texture(int textureId, int newWidth, int newHeight) {
27692770
}
27702771

27712772
// scale up face texture coordinates
2772-
float scale = tex.nWidth / (float)oldWidth;
2773+
float scaleX = tex.nWidth / (float)oldWidth;
2774+
float scaleY = tex.nHeight / (float)oldHeight;
27732775

27742776
for (int i = 0; i < faceCount; i++) {
27752777
BSPFACE& face = faces[i];
@@ -2792,8 +2794,8 @@ bool Bsp::downscale_texture(int textureId, int newWidth, int newHeight) {
27922794

27932795
vec3 oldvs = info->vS;
27942796
vec3 oldvt = info->vT;
2795-
info->vS *= scale;
2796-
info->vT *= scale;
2797+
info->vS *= scaleX;
2798+
info->vT *= scaleY;
27972799

27982800
// get before/after uv coordinates
27992801
float oldu = (dotProduct(oldvs, vert) + info->shiftS) * (1.0f / (float)oldWidth);
@@ -2840,18 +2842,27 @@ bool Bsp::downscale_texture(int textureId, int maxDim) {
28402842
int newWidth = tex.nWidth;
28412843
int newHeight = tex.nHeight;
28422844

2843-
float ratio = oldHeight / (float)oldWidth;
2844-
2845-
while (newWidth > 0 && (newWidth > maxDim || newHeight > maxDim || (newHeight % 16) != 0)) {
2846-
newWidth -= 16;
2847-
newHeight = newWidth * ratio;
2845+
if (tex.nWidth > maxDim && tex.nWidth > tex.nHeight) {
2846+
float ratio = oldHeight / (float)oldWidth;
2847+
newWidth = maxDim;
2848+
newHeight = (int)(((newWidth * ratio) + 8) / 16) * 16;
2849+
if (newHeight > oldHeight) {
2850+
newHeight = (int)((newWidth * ratio) / 16) * 16;
2851+
}
28482852
}
2849-
2850-
if (oldWidth == newWidth) {
2851-
return false;
2853+
else if (tex.nHeight > maxDim) {
2854+
float ratio = oldWidth / (float)oldHeight;
2855+
newHeight = maxDim;
2856+
newWidth = (int)(((newHeight * ratio) + 8) / 16) * 16;
2857+
if (newWidth > oldWidth) {
2858+
newWidth = (int)((newHeight * ratio) / 16) * 16;
2859+
}
2860+
}
2861+
else {
2862+
return false; // no need to downscale
28522863
}
28532864

2854-
if (tex.nWidth == 0) {
2865+
if (oldWidth == newWidth && oldHeight == newHeight) {
28552866
logf("Failed to downscale texture %s %dx%d to max dim %d\n", tex.szName, oldWidth, oldHeight, maxDim);
28562867
return false;
28572868
}

src/editor/BspRenderer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ void BspRenderer::render(int highlightEnt, bool highlightAlwaysOnTop, int clipno
15021502
drawModelClipnodes(0, false, clipnodeHull);
15031503
}
15041504

1505-
if (g_render_flags & RENDER_ENT_CLIPNODES) {
1505+
if ((g_render_flags & RENDER_ENTS) && (g_render_flags & RENDER_ENT_CLIPNODES)) {
15061506
for (int i = 0, sz = map->ents.size(); i < sz; i++) {
15071507
if (renderEnts[i].modelIdx >= 0 && renderEnts[i].modelIdx < map->modelCount) {
15081508
if (clipnodeHull == -1 && renderModels[renderEnts[i].modelIdx].groupCount > 0) {

src/editor/Gui.cpp

+19-11
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ void Gui::draw3dContextMenus() {
522522
set<int> downscaled;
523523

524524
for (int i = 0; i < app->selectedFaces.size(); i++) {
525-
BSPFACE& face = map->faces[app->pickInfo.faceIdx];
525+
BSPFACE& face = map->faces[app->selectedFaces[i]];
526526
BSPTEXTUREINFO& info = map->texinfos[face.iTextureInfo];
527527

528528
if (downscaled.count(info.iMiptex))
@@ -541,8 +541,8 @@ void Gui::draw3dContextMenus() {
541541
else if (maxDim > 32) { nextBestDim = 32; }
542542
else if (maxDim > 32) { nextBestDim = 32; }
543543

544-
map->downscale_texture(info.iMiptex, nextBestDim);
545544
downscaled.insert(info.iMiptex);
545+
map->downscale_texture(info.iMiptex, nextBestDim);
546546
}
547547

548548
app->deselectFaces();
@@ -958,8 +958,12 @@ void Gui::drawMenuBar() {
958958
tooltip(g, "Render point-sized entities which either have no model or reference MDL/SPR files.");
959959

960960
if (ImGui::MenuItem("Solid Entities", 0, g_render_flags & RENDER_ENTS)) {
961-
g_render_flags ^= RENDER_ENTS;
962-
g_render_flags |= RENDER_SPECIAL_ENTS;
961+
if (g_render_flags & RENDER_ENTS) {
962+
g_render_flags &= ~(RENDER_ENTS | RENDER_SPECIAL_ENTS);
963+
}
964+
else {
965+
g_render_flags |= RENDER_ENTS | RENDER_SPECIAL_ENTS;
966+
}
963967
}
964968
tooltip(g, "Render entities that reference BSP models.");
965969

@@ -1312,7 +1316,7 @@ void Gui::drawMenuBar() {
13121316
}
13131317
tooltip(g, "Subdivides faces until they have valid extents. The drawback to this method is reduced in-game performace from higher poly counts.");
13141318

1315-
ImGui::MenuItem("", "WIP");
1319+
ImGui::MenuItem("##", "WIP");
13161320
tooltip(g, "Anything you choose here will break lightmaps. "
13171321
"Run the map through a RAD compiler to fix, and pray that the mapper didn't "
13181322
"customize compile settings much.");
@@ -1496,11 +1500,15 @@ void Gui::drawToolbar() {
14961500
if (app->pickInfo.valid && app->pickInfo.modelIdx >= 0) {
14971501
Bsp* map = app->pickInfo.map;
14981502
BspRenderer* mapRenderer = app->mapRenderers[app->pickInfo.mapIdx];
1499-
BSPMODEL& model = map->models[app->pickInfo.modelIdx];
1500-
for (int i = 0; i < model.nFaces; i++) {
1501-
int faceIdx = model.iFirstFace + i;
1502-
mapRenderer->highlightFace(faceIdx, true);
1503-
app->selectedFaces.push_back(faceIdx);
1503+
1504+
// don't select all worldspawn faces because it lags the program
1505+
if (app->pickInfo.modelIdx != 0) {
1506+
BSPMODEL& model = map->models[app->pickInfo.modelIdx];
1507+
for (int i = 0; i < model.nFaces; i++) {
1508+
int faceIdx = model.iFirstFace + i;
1509+
mapRenderer->highlightFace(faceIdx, true);
1510+
app->selectedFaces.push_back(faceIdx);
1511+
}
15041512
}
15051513
}
15061514
app->selectMapIdx = app->pickInfo.mapIdx;
@@ -1688,7 +1696,7 @@ void Gui::drawDebugWidget() {
16881696

16891697
}
16901698

1691-
if (app->pickInfo.valid) {
1699+
if (app->pickInfo.valid && app->pickInfo.map) {
16921700
Bsp* map = app->pickInfo.map;
16931701

16941702
if (ImGui::CollapsingHeader("Map", ImGuiTreeNodeFlags_DefaultOpen))

src/editor/Renderer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ void Renderer::drawPlane(BSPPLANE& plane, COLOR4 color) {
16821682
vec3 right = crossProduct(plane.vNormal, crossDir);
16831683
vec3 up = crossProduct(right, plane.vNormal);
16841684

1685-
float s = 100.0f;
1685+
float s = 32768.0f;
16861686

16871687
vec3 topLeft = vec3(ori + right * -s + up * s).flip();
16881688
vec3 topRight = vec3(ori + right * s + up * s).flip();

0 commit comments

Comments
 (0)