Skip to content

Commit

Permalink
SPEED UP FPS x2
Browse files Browse the repository at this point in the history
Optimizations
  • Loading branch information
UnrealKaraulov committed Dec 9, 2023
1 parent d71e649 commit c60352c
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 46 deletions.
1 change: 1 addition & 0 deletions cfg/language.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1179,5 +1179,6 @@ LANG_1177 = Clipnodes
LANG_1178 = ent_context
LANG_1179 = (WIP)
LANG_1180 = No entity selected
LANG_FGD_BAD_OFFSET = ERROR: Expected 3 components in offset() property (line {}) in FGD {}\n
LANG_DUMP_TEX = Dump Textures
LANG_DUMP_TEX_DESC = Dump all loaded textures to .png files.
19 changes: 8 additions & 11 deletions src/bsp/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@
#include "util.h"
#include <algorithm>

Entity::Entity(const std::string& classname)
{
cachedModelIdx = -2;
targetsCached = false;
rendermode = kRenderNormal;
renderamt = 0;
renderfx = kRenderFxNone;
rendercolor = vec3(1.0f, 1.0f, 1.0f);
setOrAddKeyvalue("classname", classname);
}

void Entity::addKeyvalue(const std::string key, const std::string value, bool multisupport)
{
if (!strlen(key))
return;

if (key == "origin")
originInited = false;

int dup = 1;
if (keyvalues.find(key) == keyvalues.end())
{
Expand Down Expand Up @@ -200,7 +193,11 @@ bool Entity::isWorldSpawn()

vec3 Entity::getOrigin()
{
return hasKey("origin") ? parseVector(keyvalues["origin"]) : vec3();
if (originInited)
return origin;
originInited = true;
origin = hasKey("origin") ? parseVector(keyvalues["origin"]) : vec3();
return origin;
}

// TODO: maybe store this in a text file or something
Expand Down
20 changes: 15 additions & 5 deletions src/bsp/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,27 @@ class Entity
renderamt = 0;
renderfx = kRenderFxNone;
rendercolor = vec3(1.0f, 1.0f, 1.0f);
origin = vec3(0.0f, 0.0f, 0.0f);
originInited = false;
}
Entity(const std::string& classname);
~Entity(void)

Entity(const std::string& classname)
{
cachedTargets.clear();
keyOrder.clear();
keyvalues.clear();
cachedModelIdx = -2;
targetsCached = false;
rendermode = kRenderNormal;
renderamt = 0;
renderfx = kRenderFxNone;
rendercolor = vec3(1.0f, 1.0f, 1.0f);
originInited = false;
setOrAddKeyvalue("classname", classname);
}

~Entity(void)
{
cachedTargets.clear();
keyOrder.clear();
keyvalues.clear();
}

void addKeyvalue(const std::string key, const std::string value, bool multisupport = false);
Expand Down Expand Up @@ -67,6 +75,8 @@ class Entity

size_t getMemoryUsage(); // aproximate

bool originInited = false;
vec3 origin = vec3(0.0f, 0.0f, 0.0f);
int rendermode = kRenderNormal;
int renderamt = 0;
int renderfx = kRenderFxNone;
Expand Down
17 changes: 15 additions & 2 deletions src/editor/Fgd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,27 @@ void Fgd::parseClassHeader(FgdClass& fgdClass)

if (nums.size() == 3)
{
fgdClass.color = {(unsigned char)atoi(nums[0].c_str()), (unsigned char)atoi(nums[1].c_str()), (unsigned char)atoi(nums[2].c_str())};
fgdClass.color = { (unsigned char)atoi(nums[0].c_str()), (unsigned char)atoi(nums[1].c_str()), (unsigned char)atoi(nums[2].c_str()) };
}
else
{
logf(get_localized_string(LANG_0306),lineNum,name);
logf(get_localized_string(LANG_0306), lineNum, name);
}
fgdClass.colorSet = true;
}
else if (lpart.starts_with("offset("))
{
std::vector<std::string> nums = splitString(getValueInParens(typeParts[i]), " ");

if (nums.size() == 3)
{
fgdClass.offset = { (float)atof(nums[0].c_str()), (float)atof(nums[1].c_str()),(float)atof(nums[2].c_str()) };
}
else
{
logf(get_localized_string("LANG_FGD_BAD_OFFSET"), lineNum, name);
}
}
else if (lpart.starts_with("studio("))
{
std::string mdlpath = getValueInParens(typeParts[i]);
Expand Down
2 changes: 2 additions & 0 deletions src/editor/Fgd.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct FgdClass
vec3 mins;
vec3 maxs;
COLOR3 color;
vec3 offset;
hashmap otherTypes; // unrecognized types

// if false, then need to get props from the base class
Expand All @@ -87,6 +88,7 @@ struct FgdClass
mins = vec3(-8, -8, -8);
maxs = vec3(8, 8, 8);
color = {220, 0, 220};
offset = vec3(0, 0, 0);
modelSkin = modelBody = modelSequence = 0;
}

Expand Down
29 changes: 15 additions & 14 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ Renderer::Renderer()
logf(get_localized_string(LANG_0902));
return;
}
showDragAxes = true;

g_settings.loadDefault();
g_settings.load();
Expand Down Expand Up @@ -225,6 +224,8 @@ Renderer::Renderer()

oldLeftMouse = curLeftMouse = oldRightMouse = curRightMouse = 0;

blockMoving = false;
showDragAxes = true;

gui->init();

Expand Down Expand Up @@ -349,21 +350,21 @@ void Renderer::renderLoop()
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);

{//Update keyboard / mouse state
oldLeftMouse = curLeftMouse;
curLeftMouse = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT);
oldRightMouse = curRightMouse;
curRightMouse = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT);
//Update keyboard / mouse state
oldLeftMouse = curLeftMouse;
curLeftMouse = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT);
oldRightMouse = curRightMouse;
curRightMouse = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT);

DebugKeyPressed = pressed[GLFW_KEY_F1];
DebugKeyPressed = pressed[GLFW_KEY_F1];

anyCtrlPressed = pressed[GLFW_KEY_LEFT_CONTROL] || pressed[GLFW_KEY_RIGHT_CONTROL];
anyAltPressed = pressed[GLFW_KEY_LEFT_ALT] || pressed[GLFW_KEY_RIGHT_ALT];
anyShiftPressed = pressed[GLFW_KEY_LEFT_SHIFT] || pressed[GLFW_KEY_RIGHT_SHIFT];
anyCtrlPressed = pressed[GLFW_KEY_LEFT_CONTROL] || pressed[GLFW_KEY_RIGHT_CONTROL];
anyAltPressed = pressed[GLFW_KEY_LEFT_ALT] || pressed[GLFW_KEY_RIGHT_ALT];
anyShiftPressed = pressed[GLFW_KEY_LEFT_SHIFT] || pressed[GLFW_KEY_RIGHT_SHIFT];

oldControl = canControl;
canControl = /*!gui->imgui_io->WantCaptureKeyboard && */ !gui->imgui_io->WantTextInput && !gui->imgui_io->WantCaptureMouseUnlessPopupClose;

oldControl = canControl;
canControl = /*!gui->imgui_io->WantCaptureKeyboard && */ !gui->imgui_io->WantTextInput && !gui->imgui_io->WantCaptureMouseUnlessPopupClose;
}

if (curTime - lastTitleTime > 0.5)
{
Expand Down Expand Up @@ -1005,7 +1006,6 @@ void Renderer::drawEntConnections()

void Renderer::controls()
{
static bool blockMoving = false;

if (blockMoving)
{
Expand Down Expand Up @@ -1797,6 +1797,7 @@ bool Renderer::transformAxisControls()
axisDragStart = rounded;

tmpEnt->setOrAddKeyvalue("origin", (rounded - getEntOffset(map, tmpEnt)).toKeyvalueString());

map->getBspRender()->refreshEnt(tmpEntIdx);

updateEntConnectionPositions();
Expand Down
1 change: 1 addition & 0 deletions src/editor/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class Renderer
int transformMode = TRANSFORM_MODE_MOVE;
int transformTarget = TRANSFORM_OBJECT;
int pickMode = PICK_OBJECT;
bool blockMoving = false;
bool showDragAxes = true;
bool pickClickHeld = true; // true if the mouse button is still held after picking an object
vec3 axisDragStart;
Expand Down
26 changes: 13 additions & 13 deletions src/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,21 +244,21 @@ std::string toLowerCase(const std::string& s)
return ret;
}

std::string trimSpaces(std::string s)
std::string trimSpaces(const std::string & str)
{
// Remove white space indents
size_t lineStart = s.find_first_not_of(" \t\n\r");
if (lineStart == std::string::npos)
return "";

// Remove spaces after the last character
size_t lineEnd = s.find_last_not_of(" \t\n\r");
if (lineEnd != std::string::npos && lineEnd < s.length() - 1)
s = s.substr(lineStart, (lineEnd + 1) - lineStart);
else
s = s.substr(lineStart);
if (str.empty())
{
return str;
}

return s;
std::string result = str;
while (!result.empty() && std::isspace(result.front())) {
result.erase(result.begin());
}
while (!result.empty() && std::isspace(result.back())) {
result.pop_back();
}
return result;
}

int getTextureSizeInBytes(BSPMIPTEX* bspTexture, bool palette)
Expand Down
2 changes: 1 addition & 1 deletion src/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void removeDir(const std::string& dirName);

std::string toLowerCase(const std::string& s);

std::string trimSpaces(std::string s);
std::string trimSpaces(const std::string& str);

int getTextureSizeInBytes(BSPMIPTEX* bspTexture, bool palette = false);

Expand Down

0 comments on commit c60352c

Please sign in to comment.