Skip to content

Commit

Permalink
Fixed strange code in vis.cpp. Preparing to adding limits configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Karaulov committed Nov 23, 2022
1 parent f2ec7ff commit a199cb0
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 33 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set(SOURCE_FILES
src/bsp/forcecrc32.h src/bsp/forcecrc32.cpp
src/bsp/BspMerger.h src/bsp/BspMerger.cpp
src/bsp/Bsp.h src/bsp/Bsp.cpp
src/bsp/bsplimits.h
src/bsp/bsplimits.h src/bsp/bsplimits.cpp
src/bsp/bsptypes.h src/bsp/bsptypes.cpp
src/bsp/Entity.h src/bsp/Entity.cpp
src/bsp/Keyvalue.h src/bsp/Keyvalue.cpp
Expand Down Expand Up @@ -121,6 +121,7 @@ if(MSVC)
source_group("Source Files\\bsp" FILES src/bsp/forcecrc32.cpp
src/bsp/BspMerger.cpp
src/bsp/Bsp.cpp
src/bsp/bsplimits.cpp
src/bsp/bsptypes.cpp
src/bsp/Entity.cpp
src/bsp/Keyvalue.cpp
Expand Down
49 changes: 49 additions & 0 deletions src/bsp/bsplimits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "bsplimits.h"


unsigned int MAX_MAP_COORD=32767; // stuff breaks past this point

float FLT_MAX_COORD=32767.f;
float FLT_MIN_COORD=-32767.f;

unsigned int MAX_MAP_MODELS=4096;
unsigned int MAX_MAP_NODES=32768;
unsigned int MAX_MAP_CLIPNODES=32767;
unsigned int MAX_MAP_LEAVES=65536;
unsigned int MAX_MAP_TEXDATA=0;
unsigned int MAX_MAP_VISDATA=64 * ( 1024 * 1024 ); // 64 MB
unsigned int MAX_MAP_ENTS=8192;
unsigned int MAX_MAP_SURFEDGES=512000;
unsigned int MAX_MAP_EDGES=256000;
unsigned int MAX_MAP_TEXTURES=4096;
unsigned int MAX_MAP_LIGHTDATA=64 * ( 1024 * 1024 ); // 64 MB
unsigned int MAX_TEXTURE_DIMENSION=1024;
unsigned int MAX_TEXTURE_SIZE=((MAX_TEXTURE_DIMENSION * MAX_TEXTURE_DIMENSION * 2 * 3) / 2);

unsigned int MAX_KEY_LEN=256; // not sure if this includes the null char
unsigned int MAX_VAL_LEN=4096; // not sure if this includes the null char

void ResetBspLimits()
{
MAX_MAP_COORD=32767; // stuff breaks past this point (leafs signed short mins/maxs breaks)

FLT_MAX_COORD=32767.f;
FLT_MIN_COORD=-32767.f;

MAX_MAP_MODELS=4096;
MAX_MAP_NODES=32768;
MAX_MAP_CLIPNODES=32767;
MAX_MAP_LEAVES=65536;
MAX_MAP_TEXDATA=0;
MAX_MAP_VISDATA=64 * ( 1024 * 1024 ); // 64 MB
MAX_MAP_ENTS=8192;
MAX_MAP_SURFEDGES=512000;
MAX_MAP_EDGES=256000;
MAX_MAP_TEXTURES=4096;
MAX_MAP_LIGHTDATA=64 * ( 1024 * 1024 ); // 64 MB
MAX_TEXTURE_DIMENSION=1024;
MAX_TEXTURE_SIZE=((MAX_TEXTURE_DIMENSION * MAX_TEXTURE_DIMENSION * 2 * 3) / 2);

MAX_KEY_LEN=256;
MAX_VAL_LEN=4096;
}
57 changes: 30 additions & 27 deletions src/bsp/bsplimits.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
#define MAX_MAP_HULLS 4
#define MAX_MAP_COORD 32767 // stuff breaks past this point
#pragma once
#include <stdint.h>

#define FLT_MAX_COORD 32767.f
#define FLT_MIN_COORD -32767.f

#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_MAP_HULLS 4
#define MAX_MAP_PLANES 65535
#define MAX_MAP_TEXINFOS 32767 // Can be 65535 if unsigned short?
#define MAX_MAP_MARKSURFS 65535
#define MAX_MAP_VERTS 65535
#define MAX_MAP_FACES 65535 // (unsgined short) This ought to be 32768, otherwise faces(in world) can become invisible. --vluzacn
#define MAX_KEYS_PER_ENT 128
#define MAXLIGHTMAPS 4

extern unsigned int MAX_MAP_COORD; // stuff breaks past this point

#define MAX_KEYS_PER_ENT 64 // just guessing
#define MAX_KEY_LEN 256 // not sure if this includes the null char
#define MAX_VAL_LEN 4096 // not sure if this includes the null char
extern float FLT_MAX_COORD;
extern float FLT_MIN_COORD;

#define MAXLIGHTMAPS 4
extern unsigned int MAX_MAP_MODELS;
extern unsigned int MAX_MAP_NODES;
extern unsigned int MAX_MAP_CLIPNODES;
extern unsigned int MAX_MAP_LEAVES;
extern unsigned int MAX_MAP_TEXDATA;
extern unsigned int MAX_MAP_VISDATA; // 64 MB
extern unsigned int MAX_MAP_ENTS;
extern unsigned int MAX_MAP_SURFEDGES;
extern unsigned int MAX_MAP_EDGES;
extern unsigned int MAX_MAP_TEXTURES;
extern unsigned int MAX_MAP_LIGHTDATA; // 64 MB
extern unsigned int MAX_TEXTURE_DIMENSION;
extern unsigned int MAX_TEXTURE_SIZE;

extern unsigned int MAX_KEY_LEN; // not sure if this includes the null char
extern unsigned int MAX_VAL_LEN; // not sure if this includes the null char

extern void ResetBspLimits(); // reset all limits to default values
11 changes: 9 additions & 2 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3109,12 +3109,13 @@ void Gui::drawSettings()
if (ImGui::Begin("Settings", &showSettingsWidget))
{
ImGuiContext& g = *GImGui;
const int settings_tabs = 6;
const int settings_tabs = 7;
static const char* tab_titles[settings_tabs] = {
"General",
"FGDs",
"Asset Paths",
"Optimizing",
"Limits",
"Rendering",
"Controls"
};
Expand Down Expand Up @@ -3220,6 +3221,7 @@ void Gui::drawSettings()
{
g_settings.reset();
}

if (ImGui::IsItemHovered() && g.HoveredIdTimer > g_tooltip_delay)
{
ImGui::BeginTooltip();
Expand Down Expand Up @@ -3424,6 +3426,11 @@ void Gui::drawSettings()
}
}
else if (settingsTab == 4)
{
ImGui::DragFloat("Movement speed", &app->moveSpeed, 0.1f, 0.1f, 1000, "%.1f");
ImGui::DragFloat("Rotation speed", &app->rotationSpeed, 0.01f, 0.1f, 100, "%.1f");
}
else if (settingsTab == 5)
{
ImGui::Text("Viewport:");
if (ImGui::Checkbox("VSync", &vsync))
Expand Down Expand Up @@ -3531,7 +3538,7 @@ void Gui::drawSettings()

ImGui::Columns(1);
}
else if (settingsTab == 5)
else if (settingsTab == 6)
{
ImGui::DragFloat("Movement speed", &app->moveSpeed, 0.1f, 0.1f, 1000, "%.1f");
ImGui::DragFloat("Rotation speed", &app->rotationSpeed, 0.01f, 0.1f, 100, "%.1f");
Expand Down
2 changes: 2 additions & 0 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ void AppSettings::loadDefault()
passableEnts.clear();
playerOnlyTriggers.clear();
monsterOnlyTriggers.clear();

ResetBspLimits();
}

void AppSettings::reset()
Expand Down
12 changes: 9 additions & 3 deletions src/qtools/vis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,19 @@ bool shiftVis(unsigned char* vis, int len, int offsetLeaf, int shift)
if (byteShifts > 0)
{
// TODO: detect overflows here too
static unsigned char temp[MAX_MAP_LEAVES / 8];

if (shift > 0)
{
int startByte = (offsetLeaf + bitShifts) / 8;
int moveSize = len - (startByte + byteShifts);
unsigned char* temp = new unsigned char[moveSize];

memcpy(temp, (unsigned char*)vis + startByte, moveSize);

memset((unsigned char*)vis + startByte, 0, byteShifts);

memcpy((unsigned char*)vis + startByte + byteShifts, temp, moveSize);

delete[] temp;
}
else
{
Expand Down Expand Up @@ -315,7 +318,6 @@ int64_t CompressAll(BSPLEAF* leafs, unsigned char* uncompressed, unsigned char*
int64_t x = 0;
unsigned char* dest;
unsigned char* src;
unsigned char compressed[MAX_MAP_LEAVES / 8];
unsigned int g_bitbytes = ((numLeaves + 63) & ~63) >> 3;

unsigned char* vismap_p = output;
Expand Down Expand Up @@ -350,6 +352,8 @@ int64_t CompressAll(BSPLEAF* leafs, unsigned char* uncompressed, unsigned char*
continue;
}

unsigned char * compressed = new unsigned char[MAX_MAP_LEAVES / 8];

memset(&compressed, 0, sizeof(compressed));

src = uncompressed + i * g_bitbytes;
Expand All @@ -368,6 +372,8 @@ int64_t CompressAll(BSPLEAF* leafs, unsigned char* uncompressed, unsigned char*
leafs[i + 1].nVisOffset = (int)(dest - output); // leaf 0 is a common solid

memcpy(dest, compressed, x);

delete[] compressed;
}

delete[] sharedRows;
Expand Down
1 change: 1 addition & 0 deletions vs-project/bspguy.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
<ClInclude Include=".\..\src\bsp\Bsp.h" />
<ClCompile Include=".\..\src\bsp\Bsp.cpp" />
<ClInclude Include=".\..\src\bsp\bsplimits.h" />
<ClCompile Include=".\..\src\bsp\bsplimits.cpp" />
<ClInclude Include=".\..\src\bsp\bsptypes.h" />
<ClCompile Include=".\..\src\bsp\bsptypes.cpp" />
<ClInclude Include=".\..\src\bsp\Entity.h" />
Expand Down
3 changes: 3 additions & 0 deletions vs-project/bspguy.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<ClCompile Include=".\..\src\bsp\Bsp.cpp">
<Filter>Source Files\bsp</Filter>
</ClCompile>
<ClCompile Include=".\..\src\bsp\bsplimits.cpp">
<Filter>Source Files\bsp</Filter>
</ClCompile>
<ClCompile Include=".\..\src\bsp\bsptypes.cpp">
<Filter>Source Files\bsp</Filter>
</ClCompile>
Expand Down

0 comments on commit a199cb0

Please sign in to comment.