Skip to content

Commit

Permalink
Fix bspmodel crash. Update movespeed code. Bugixes
Browse files Browse the repository at this point in the history
Fix crash with twicely reload async textures. Replaced some old code. Bugfixes
  • Loading branch information
Karaulov committed Dec 11, 2022
1 parent 2d6c990 commit 888de54
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 46 deletions.
5 changes: 1 addition & 4 deletions src/editor/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ void CreateBspModelCommand::execute()
if (aaatriggerIdx == -1)
{
aaatriggerIdx = addDefaultTexture();
renderer->reloadTextures();
}

vec3 mins = vec3(-mdl_size, -mdl_size, -mdl_size);
Expand Down Expand Up @@ -475,10 +474,8 @@ int CreateBspModelCommand::addDefaultTexture()

lodepng_decode24(&tex_dat, &w, &h, aaatrigger_dat, sizeof(aaatrigger_dat));

int aaatriggerIdx = map->add_texture("aaatrigger", NULL, w, h);
//renderer->reloadTextures();
int aaatriggerIdx = map->add_texture("aaatrigger", tex_dat, w, h);

//lodepng_encode24_file("test.png", (unsigned char*)tex_dat, w, h);
delete[] tex_dat;

return aaatriggerIdx;
Expand Down
8 changes: 4 additions & 4 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ void Gui::drawMenuBar()

Entity* newEnt = new Entity();
newEnt->addKeyvalue("origin", origin.toKeyvalueString());
newEnt->addKeyvalue("classname", "func_illusionary");
newEnt->addKeyvalue("classname", "trigger_once");

float snapSize = pow(2.0f, app->gridSnapLevel * 1.0f);
if (snapSize < 16)
Expand Down Expand Up @@ -4357,8 +4357,8 @@ void Gui::drawSettings()
}
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");
ImGui::DragFloat("Movement speed", &app->moveSpeed, 1.0f, 100.0f, 1000.0f, "%.1f");
ImGui::DragFloat("Rotation speed", &app->rotationSpeed, 0.1f, 0.1f, 100.0f, "%.1f");
}

ImGui::EndChild();
Expand Down Expand Up @@ -6080,7 +6080,7 @@ void Gui::drawLightMapTool()
continue;
}

if (ImGui::ImageButton((std::to_string(i) + "_lightmap").c_str(), (ImTextureID)currentlightMap[i]->id, imgSize, ImVec2(0, 0), ImVec2(1, 1)))
if (ImGui::ImageButton((std::to_string(i) + "_lightmap").c_str(), (ImTextureID)(long long)currentlightMap[i]->id, imgSize, ImVec2(0, 0), ImVec2(1, 1)))
{
float itemwidth = ImGui::GetItemRectMax().x - ImGui::GetItemRectMin().x;
float itemheight = ImGui::GetItemRectMax().y - ImGui::GetItemRectMin().y;
Expand Down
54 changes: 24 additions & 30 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ void window_maximize_callback(GLFWwindow* window, int maximized)
g_settings.maximized = maximized == GLFW_TRUE;
}

void window_minimize_callback(GLFWwindow* window, int iconified)
{
g_app->isSleeping = iconified == GLFW_TRUE;
}

void window_close_callback(GLFWwindow* window)
{
g_settings.save();
Expand Down Expand Up @@ -115,7 +120,7 @@ void AppSettings::loadDefault()
autoImportEnt = false;
sameDirForEnt = false;

moveSpeed = 4.0f;
moveSpeed = 500.0f;
fov = 75.0f;
zfar = 262144.0f;
rotSpeed = 5.0f;
Expand Down Expand Up @@ -302,6 +307,11 @@ void AppSettings::load()
else if (key == "move_speed")
{
g_settings.moveSpeed = (float)atof(val.c_str());
if (g_settings.moveSpeed < 100)
{
logf("Move speed can be 100 - 1000. Replaced to default value.\n");
g_settings.moveSpeed = 500;
}
}
else if (key == "rot_speed")
{
Expand Down Expand Up @@ -717,6 +727,7 @@ Renderer::Renderer()
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetWindowPosCallback(window, window_pos_callback);
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetWindowIconifyCallback(window, window_minimize_callback);
glfwSetWindowMaximizeCallback(window, window_maximize_callback);

glewInit();
Expand Down Expand Up @@ -828,20 +839,21 @@ void Renderer::renderLoop()

updateDragAxes();

g_time = glfwGetTime();

double lastFrameTime = g_time;
double lastTitleTime = g_time;

oldTime = glfwGetTime();
curTime = oldTime;
double lastTitleTime = curTime;

while (!glfwWindowShouldClose(window))
{
oldTime = curTime;
curTime = glfwGetTime();
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
mousePos = vec2((float)xpos, (float)ypos);

glfwPollEvents();


{//Update keyboard / mouse state
oldLeftMouse = curLeftMouse;
curLeftMouse = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT);
Expand Down Expand Up @@ -871,9 +883,9 @@ void Renderer::renderLoop()
}

Bsp* map = SelectedMap;
if (g_time - lastTitleTime > 0.5)
if (curTime - lastTitleTime > 0.5)
{
lastTitleTime = g_time;
lastTitleTime = curTime;
if (map)
{
glfwSetWindowTitle(window, std::string(std::string("bspguy - ") + map->bsp_path).c_str());
Expand All @@ -894,24 +906,9 @@ void Renderer::renderLoop()
bool isTransformingValid = (!modelUsesSharedStructures || (transformMode == TRANSFORM_MOVE && transformTarget != TRANSFORM_VERTEX)) && (isTransformableSolid || isScalingObject);
bool isTransformingWorld = pickInfo.IsSelectedEnt(0) && transformTarget != TRANSFORM_OBJECT;


g_time = glfwGetTime();
g_frame_counter++;

double frameDelta = g_time - lastFrameTime;
frameTimeScale = 0.05 / frameDelta;
double fps = 1.0 / frameDelta;

//FIXME : frameTimeScale = 0.05f / frameDelta ???
frameTimeScale = 100.0 / fps;

lastFrameTime = g_time;

double spin = g_time * 2;

matmodel.loadIdentity();
matmodel.rotateZ((float)spin);
matmodel.rotateX((float)spin);
matmodel.rotateZ((float)oldTime);
matmodel.rotateX((float)curTime);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

Expand Down Expand Up @@ -1428,8 +1425,7 @@ void Renderer::controls()
}
}


cameraOrigin += getMoveDir() * (float)frameTimeScale;
cameraOrigin += getMoveDir() * (curTime - oldTime) * moveSpeed;

moveGrabbedEnt();

Expand Down Expand Up @@ -2344,8 +2340,6 @@ vec3 Renderer::getMoveDir()
wishdir -= forward;
}

wishdir *= moveSpeed;

if (anyShiftPressed)
wishdir *= 4.0f;
if (anyCtrlPressed)
Expand Down Expand Up @@ -3988,7 +3982,7 @@ void Renderer::deselectObject()
updateEntConnections();
}

void Renderer::selectFace(Bsp * map, int face, bool add)
void Renderer::selectFace(Bsp* map, int face, bool add)
{
if (!map)
return;
Expand Down
6 changes: 4 additions & 2 deletions src/editor/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class Renderer
void saveSettings();
void loadSettings();

bool isSleeping = false;
bool reloading = false;
bool isLoading = false;
bool reloadingGameDir = false;
Expand Down Expand Up @@ -203,12 +204,13 @@ class Renderer

Fgd* fgd = NULL;

double oldTime = 0.0;
double curTime = 0.0;
vec3 cameraForward;
vec3 cameraUp;
vec3 cameraRight;
bool cameraIsRotating;
double frameTimeScale = 0.0;
float moveSpeed = 4.0f;
float moveSpeed = 200.0f;
float fov = 75.0f;
float zNear = 1.0f;
float zFar = 262144.0f;
Expand Down
3 changes: 0 additions & 3 deletions src/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#include <set>

bool DebugKeyPressed = false;
unsigned int g_frame_counter = 0;
double g_time = 0.0;

ProgressMeter g_progress;
int g_render_flags;
std::vector<std::string> g_log_buffer;
Expand Down
3 changes: 0 additions & 3 deletions src/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ static const vec3 s_baseaxis[18] = {
{0, -1, 0}, {1, 0, 0}, {0, 0, -1}, // north wall
};


extern unsigned int g_frame_counter;
extern double g_time;
extern bool DebugKeyPressed;
extern bool g_verbose;
extern ProgressMeter g_progress;
Expand Down

0 comments on commit 888de54

Please sign in to comment.