Skip to content

Commit

Permalink
new features and gui cleanup
Browse files Browse the repository at this point in the history
- option to subdivide a face until surface extents are valid
- option to toggle between half-life and sven co-op map limits
- option to toggle rendering of the map boundaries
- bad surface extents shown in validate output
- disable nav mesh debug code
- cleanup porting tools menu
- select worldspawn when program first starts
  • Loading branch information
wootguy committed Apr 23, 2024
1 parent 1478803 commit c3927b0
Show file tree
Hide file tree
Showing 15 changed files with 649 additions and 370 deletions.
454 changes: 266 additions & 188 deletions src/bsp/Bsp.cpp

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion src/bsp/Bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,33 @@ class Bsp
// showing between faces with different texture scales
// scaleNotSubdivide:true = scale face textures to lower extents
// scaleNotSubdivide:false = subdivide face textures to lower extents
// downscaleOnly:true = don't scale or subdivide anything, just downscale the textures
// maxTextureDim = downscale textures first if they are larger than this (0 = disable)
void fix_bad_surface_extents(bool scaleNotSubdivide, int maxTextureDim);
void fix_bad_surface_extents(bool scaleNotSubdivide, bool downscaleOnly, int maxTextureDim);

// subdivide a face until it has valid surface extents
void fix_bad_surface_extents_with_subdivide(int faceIdx);

// reduces size of textures that exceed game limits and adjusts face scales accordingly
void downscale_invalid_textures();

void downscale_textures(int maxDim);

// downscales a texture to the maximum specified width/height
// true if was downscaled
bool downscale_texture(int textureId, int maxDim);

bool downscale_texture(int textureId, int newWidth, int newHeight);

vec3 get_face_center(int faceIdx);

// scales up texture sizes on models that aren't used by visible entities
void allocblock_reduction();

// gets estimated number of allocblocks filled
// actual amount will vary because there is some wasted space when the engine generates lightmap atlases
float calc_allocblock_usage();

// subdivides along the axis with the most texture pixels (for biggest surface extent reduction)
bool subdivide_face(int faceIdx);

Expand Down
4 changes: 2 additions & 2 deletions src/bsp/BspMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ void BspMerger::merge_lighting(Bsp& mapA, Bsp& mapB) {

// create a single full-bright lightmap to use for all faces, if one map has lighting but the other doesn't
if (thisColorCount == 0 && otherColorCount != 0) {
thisColorCount = MAX_SURFACE_EXTENT * MAX_SURFACE_EXTENT;
thisColorCount = g_limits.max_surface_extents * g_limits.max_surface_extents;
totalColorCount += thisColorCount;
int sz = thisColorCount * sizeof(COLOR3);
mapA.lumps[LUMP_LIGHTING] = new byte[sz];
Expand All @@ -1667,7 +1667,7 @@ void BspMerger::merge_lighting(Bsp& mapA, Bsp& mapB) {
}
}
else if (thisColorCount != 0 && otherColorCount == 0) {
otherColorCount = MAX_SURFACE_EXTENT * MAX_SURFACE_EXTENT;
otherColorCount = g_limits.max_surface_extents * g_limits.max_surface_extents;
totalColorCount += otherColorCount;
otherRad = new COLOR3[otherColorCount];
freemem = true;
Expand Down
17 changes: 0 additions & 17 deletions src/bsp/bsplimits.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
#define MAX_MAP_HULLS 4
#define MAX_MAP_COORD 131072 // stuff breaks past this point

#define MAX_MAP_MODELS 4096
#define MAX_MAP_PLANES 65535
#define MAX_MAP_VERTS 65535
#define MAX_MAP_NODES 32768
#define MAX_MAP_TEXINFOS 32767
#define MAX_MAP_FACES 65535 // This ought to be 32768, otherwise faces(in world) can become invisible. --vluzacn
#define MAX_MAP_CLIPNODES 32767
#define MAX_MAP_LEAVES 65536
#define MAX_MAP_MARKSURFS 65536
#define MAX_MAP_TEXDATA 0
#define MAX_MAP_VISDATA (64 * ( 1024 * 1024 )) // 64 MB
#define MAX_MAP_ENTS 8192
#define MAX_MAP_SURFEDGES 512000
#define MAX_MAP_EDGES 256000
#define MAX_MAP_TEXTURES 4096
#define MAX_MAP_LIGHTDATA (64 * ( 1024 * 1024 )) // 64 MB
#define MAX_TEXTURE_DIMENSION 1024
#define MAXTEXTURENAME 16
#define MIPLEVELS 4
#define MAX_TEXTURE_SIZE ((MAX_TEXTURE_DIMENSION * MAX_TEXTURE_DIMENSION * sizeof(short) * 3) / 2)

#define MAX_KEYS_PER_ENT 64 // just guessing
#define MAX_KEY_LEN 256 // not sure if this includes the null char
Expand Down
50 changes: 50 additions & 0 deletions src/editor/AppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,51 @@ void AppSettings::loadDefault()
entreport_open = false;
show_transform_axes = false;
settings_tab = 0;
engine = ENGINE_HALF_LIFE;

g_engine_limits[ENGINE_HALF_LIFE].max_surface_extents = 16;
g_engine_limits[ENGINE_HALF_LIFE].max_models = 512;
g_engine_limits[ENGINE_HALF_LIFE].max_planes = 32768;
g_engine_limits[ENGINE_HALF_LIFE].max_vertexes = 65535;
g_engine_limits[ENGINE_HALF_LIFE].max_nodes = 32767;
g_engine_limits[ENGINE_HALF_LIFE].max_faces = 65535;
g_engine_limits[ENGINE_HALF_LIFE].max_clipnodes = 32767;
g_engine_limits[ENGINE_HALF_LIFE].max_leaves = 32760;
g_engine_limits[ENGINE_HALF_LIFE].max_marksurfaces = 65535;
g_engine_limits[ENGINE_HALF_LIFE].max_surfedges = 512000;
g_engine_limits[ENGINE_HALF_LIFE].max_edges = 256000;
g_engine_limits[ENGINE_HALF_LIFE].max_textures = 512;
g_engine_limits[ENGINE_HALF_LIFE].max_lightdata = 48*1024*1024;
g_engine_limits[ENGINE_HALF_LIFE].max_visdata = 8*1024*1024;
g_engine_limits[ENGINE_HALF_LIFE].max_entdata = 2*1024*1024;
g_engine_limits[ENGINE_HALF_LIFE].max_entities = 8192;
g_engine_limits[ENGINE_HALF_LIFE].max_texinfos = 32767;
g_engine_limits[ENGINE_HALF_LIFE].max_allocblocks = 64;
g_engine_limits[ENGINE_HALF_LIFE].max_texturepixels = 262144;
g_engine_limits[ENGINE_HALF_LIFE].max_mapboundary = 4096;

g_engine_limits[ENGINE_SVEN_COOP].max_surface_extents = 64;
g_engine_limits[ENGINE_SVEN_COOP].max_models = 4096;
g_engine_limits[ENGINE_SVEN_COOP].max_planes = 65535;
g_engine_limits[ENGINE_SVEN_COOP].max_vertexes = 65535;
g_engine_limits[ENGINE_SVEN_COOP].max_nodes = 32768;
g_engine_limits[ENGINE_SVEN_COOP].max_faces = 65535;
g_engine_limits[ENGINE_SVEN_COOP].max_clipnodes = 32768;
g_engine_limits[ENGINE_SVEN_COOP].max_leaves = 65536;
g_engine_limits[ENGINE_SVEN_COOP].max_marksurfaces = 65535;
g_engine_limits[ENGINE_SVEN_COOP].max_surfedges = 512000;
g_engine_limits[ENGINE_SVEN_COOP].max_edges = 256000;
g_engine_limits[ENGINE_SVEN_COOP].max_textures = 4096;
g_engine_limits[ENGINE_SVEN_COOP].max_lightdata = 64 * 1024 * 1024;
g_engine_limits[ENGINE_SVEN_COOP].max_visdata = 64 * 1024 * 1024;
g_engine_limits[ENGINE_SVEN_COOP].max_entdata = 2 * 1024 * 1024;
g_engine_limits[ENGINE_SVEN_COOP].max_entities = 8192;
g_engine_limits[ENGINE_SVEN_COOP].max_texinfos = 32767;
g_engine_limits[ENGINE_SVEN_COOP].max_allocblocks = 1024;
g_engine_limits[ENGINE_SVEN_COOP].max_texturepixels = 1048576;
g_engine_limits[ENGINE_SVEN_COOP].max_mapboundary = 32768;

g_limits = g_engine_limits[ENGINE_HALF_LIFE];

render_flags = g_render_flags = RENDER_TEXTURES | RENDER_LIGHTMAPS | RENDER_SPECIAL
| RENDER_ENTS | RENDER_SPECIAL_ENTS | RENDER_POINT_ENTS | RENDER_WIREFRAME | RENDER_ENT_CONNECTIONS
Expand Down Expand Up @@ -94,6 +139,10 @@ void AppSettings::load() {
else if (key == "fgd") { fgdPaths.push_back(val); }
else if (key == "res") { resPaths.push_back(val); }
else if (key == "savebackup") { g_settings.backUpMap = atoi(val.c_str()) != 0; }
else if (key == "engine") {
g_settings.engine = clamp(atoi(val.c_str()), 0, 1);
g_limits = g_engine_limits[g_settings.engine];
}
}

g_settings.valid = true;
Expand Down Expand Up @@ -184,4 +233,5 @@ void AppSettings::save() {
file << "font_size=" << g_settings.fontSize << endl;
file << "undo_levels=" << g_settings.undoLevels << endl;
file << "savebackup=" << g_settings.backUpMap << endl;
file << "engine=" << g_settings.engine << endl;
}
1 change: 1 addition & 0 deletions src/editor/AppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct AppSettings {
int windowY;
int maximized;
int fontSize;
int engine;
std::string gamedir;
std::string workingdir;
bool valid;
Expand Down
3 changes: 3 additions & 0 deletions src/editor/BspRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,8 @@ bool BspRenderer::pickModelPoly(vec3 start, vec3 dir, vec3 offset, int modelIdx,
hullIdx = getBestClipnodeHull(modelIdx);
}

// Nav mesh WIP code
/*
if (clipnodesLoaded && (selectWorldClips || selectEntClips) && hullIdx != -1) {
for (int i = 0; i < renderClipnodes[modelIdx].faceMaths[hullIdx].size(); i++) {
FaceMath& faceMath = renderClipnodes[modelIdx].faceMaths[hullIdx][i];
Expand Down Expand Up @@ -1831,6 +1833,7 @@ bool BspRenderer::pickModelPoly(vec3 start, vec3 dir, vec3 offset, int modelIdx,
}
}
}
*/

return foundBetterPick;
}
Expand Down
3 changes: 2 additions & 1 deletion src/editor/BspRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ enum RenderFlags {
RENDER_ORIGIN = 128,
RENDER_WORLD_CLIPNODES = 256,
RENDER_ENT_CLIPNODES = 512,
RENDER_ENT_CONNECTIONS = 1024
RENDER_ENT_CONNECTIONS = 1024,
RENDER_MAP_BOUNDARY = 2048
};

struct LightmapInfo {
Expand Down
Loading

0 comments on commit c3927b0

Please sign in to comment.