Skip to content

Commit

Permalink
Fix "screenshot" cmd. Fix 'goto first entity' opt.
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Dec 9, 2024
1 parent fc63c57 commit 91a3229
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 116 deletions.
125 changes: 51 additions & 74 deletions src/editor/BspRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,93 +65,66 @@ BspRenderer::BspRenderer(Bsp* _map)
{
print_log(get_localized_string(LANG_0267));
Entity* foundEnt = NULL;
bool foundCam = false;

for (auto ent : map->ents)
{
if (ent->hasKey("classname") && ent->keyvalues["classname"] == "info_player_start")
if (ent->hasKey("classname") && ent->keyvalues["classname"] == "trigger_camera")
{
foundCam = true;
foundEnt = ent;
break;
}
}

if (!foundEnt)
{
for (auto ent : map->ents)
{
if (ent->hasKey("classname") && ent->keyvalues["classname"] == "info_player_deathmatch")
if (ent->hasKey("classname") && ent->keyvalues["classname"] == "info_player_start")
{
foundEnt = ent;
break;
}
}
}

if (!foundEnt)
{
for (auto ent : map->ents)
{
if (ent->hasKey("classname") && ent->keyvalues["classname"] == "trigger_camera")
if (ent->hasKey("classname") && ent->keyvalues["classname"] == "info_player_deathmatch")
{
foundEnt = ent;
break;
}
}
}


if (foundEnt)
if (!foundEnt)
{
renderCameraOrigin = foundEnt->origin;
renderCameraOrigin.z += 32;
for (unsigned int i = 0; i < foundEnt->keyOrder.size(); i++)
for (auto ent : map->ents)
{
if (foundEnt->keyOrder[i] == "angles")
{
renderCameraAngles = parseVector(foundEnt->keyvalues["angles"]);
}
if (foundEnt->keyOrder[i] == "angle")
{
float y = str_to_float(foundEnt->keyvalues["angle"]);

if (y >= 0.0f)
{
renderCameraAngles.y = y;
}
else if (y == -1.0f)
{
renderCameraAngles.x = -90.0f;
renderCameraAngles.y = 0.0f;
renderCameraAngles.z = 0.0f;
}
else if (y <= -2.0f)
{
renderCameraAngles.x = 90.0f;
renderCameraAngles.y = 0.0f;
renderCameraAngles.z = 0.0f;
}
}
foundEnt = ent;
break;
}

renderCameraAngles = renderCameraAngles.flip();
renderCameraAngles.z = renderCameraAngles.z + 90.0f;
renderCameraAngles = renderCameraAngles.normalize_angles();
renderCameraAngles.y = 0.0f;
}


/*for (auto ent : map->ents)
if (foundEnt)
{
if (ent->hasKey("classname") && ent->keyvalues["classname"] == "info_player_start")
renderCameraOrigin = foundEnt->origin;
if (!foundCam)
{
renderCameraOrigin = ent->origin;
/*for (unsigned int i = 0; i < ent->keyOrder.size(); i++)
renderCameraOrigin.z += 32;
for (unsigned int i = 0; i < foundEnt->keyOrder.size(); i++)
{
if (ent->keyOrder[i] == "angles")
if (foundEnt->keyOrder[i] == "angles")
{
renderCameraAngles = parseVector(ent->keyvalues["angles"]);
renderCameraAngles = parseVector(foundEnt->keyvalues["angles"]);
}
if (ent->keyOrder[i] == "angle")
if (foundEnt->keyOrder[i] == "angle")
{
float y = str_to_float(ent->keyvalues["angle"]);
float y = str_to_float(foundEnt->keyvalues["angle"]);

if (y >= 0.0f)
{
Expand All @@ -171,39 +144,43 @@ BspRenderer::BspRenderer(Bsp* _map)
}
}
}
break;
}
*/


//if (ent->hasKey("classname") && ent->keyvalues["classname"] == "trigger_camera")
//{
// this->renderCameraOrigin = ent->origin;
/*
auto targets = ent->getTargets();
bool found = false;
for (auto ent2 : map->ents)
{
if (found)
break;
if (ent2->hasKey("targetname"))
{
for (auto target : targets)
else
{
if (ent2->keyvalues["targetname"] == target)
auto targets = foundEnt->getTargets();
Entity* targetEnt = NULL;
for (auto ent2 : map->ents)
{
found = true;
break;
if (targetEnt)
break;
if (ent2->hasKey("targetname"))
{
for (auto target : targets)
{
if (ent2->keyvalues["targetname"] == target)
{
targetEnt = ent2;
break;
}
}
}
}

if (targetEnt)
{
vec3 newAngle = targetEnt->origin - foundEnt->origin;
VectorAngles(newAngle, newAngle);
newAngle[0] = -newAngle[0];
renderCameraAngles = newAngle;
}
}

renderCameraAngles = renderCameraAngles.flip();
renderCameraAngles.z = renderCameraAngles.z + 90.0f;
renderCameraAngles = renderCameraAngles.normalize_angles();
renderCameraAngles.y = 0.0f;
}
}
*/
/* break;
}
}*/
}


if (g_settings.save_cam)
Expand Down
142 changes: 102 additions & 40 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,25 +552,25 @@ void Renderer::renderLoop()
GLuint fbo = NULL, texture, rbo;


if (ortho_overview)
{
if (ortho_save_tga || ortho_save_bmp)
{
setupFakeOrthoView(ortho_tga_w, ortho_tga_h, ortho_mins, ortho_maxs);
}
else
{
setupFakeOrthoView(0, 0, ortho_mins, ortho_maxs);
}
}
else
if (ortho_save_tga || ortho_save_bmp || (make_screenshot && !isLoading))
{
setupView();
}
glEnable(GL_MULTISAMPLE);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable(GL_POLYGON_SMOOTH);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glEnable(GL_POINT_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);

glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT, GL_NICEST);


//for (auto& tex : g_all_Textures)
//{
// tex->upload(tex->type);
//}


if (ortho_save_tga || ortho_save_bmp || (make_screenshot && !isLoading))
{
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);

Expand Down Expand Up @@ -598,16 +598,20 @@ void Renderer::renderLoop()
Bsp* map = SelectedMap;
if (map)
{
int tries = make_screenshot_target;
int tries = make_screenshot_target + 1;
BspRenderer* rend = SelectedMap->getBspRender();
Entity* foundEnt = NULL;

bool foundCam = false;

for (auto ent : map->ents)
{
if (ent->hasKey("classname") && ent->keyvalues["classname"] == "trigger_camera")
{
tries--;
if (tries <= 0)
{
foundCam = true;
foundEnt = ent;
break;
}
Expand Down Expand Up @@ -662,34 +666,66 @@ void Renderer::renderLoop()
if (foundEnt)
{
rend->renderCameraOrigin = foundEnt->origin;
rend->renderCameraOrigin.z += 32;
for (unsigned int i = 0; i < foundEnt->keyOrder.size(); i++)
if (!foundCam)
{
if (foundEnt->keyOrder[i] == "angles")
{
rend->renderCameraAngles = parseVector(foundEnt->keyvalues["angles"]);
}
if (foundEnt->keyOrder[i] == "angle")
rend->renderCameraOrigin.z += 32;
for (unsigned int i = 0; i < foundEnt->keyOrder.size(); i++)
{
float y = str_to_float(foundEnt->keyvalues["angle"]);

if (y >= 0.0f)
if (foundEnt->keyOrder[i] == "angles")
{
rend->renderCameraAngles.y = y;
rend->renderCameraAngles = parseVector(foundEnt->keyvalues["angles"]);
}
else if (y == -1.0f)
if (foundEnt->keyOrder[i] == "angle")
{
rend->renderCameraAngles.x = -90.0f;
rend->renderCameraAngles.y = 0.0f;
rend->renderCameraAngles.z = 0.0f;
float y = str_to_float(foundEnt->keyvalues["angle"]);

if (y >= 0.0f)
{
rend->renderCameraAngles.y = y;
}
else if (y == -1.0f)
{
rend->renderCameraAngles.x = -90.0f;
rend->renderCameraAngles.y = 0.0f;
rend->renderCameraAngles.z = 0.0f;
}
else if (y <= -2.0f)
{
rend->renderCameraAngles.x = 90.0f;
rend->renderCameraAngles.y = 0.0f;
rend->renderCameraAngles.z = 0.0f;
}
}
else if (y <= -2.0f)
}
}
else
{
auto targets = foundEnt->getTargets();
Entity* targetEnt = NULL;
for (auto ent2 : map->ents)
{
if (targetEnt)
break;
if (ent2->hasKey("targetname"))
{
rend->renderCameraAngles.x = 90.0f;
rend->renderCameraAngles.y = 0.0f;
rend->renderCameraAngles.z = 0.0f;
for (auto target : targets)
{
if (ent2->keyvalues["targetname"] == target)
{
targetEnt = ent2;
break;
}
}
}
}

if (targetEnt)
{
vec3 newAngle = targetEnt->origin - foundEnt->origin;
VectorAngles(newAngle, newAngle);
newAngle[0] = -newAngle[0];
rend->renderCameraAngles = newAngle;
}
}

rend->renderCameraAngles = rend->renderCameraAngles.flip();
Expand All @@ -705,6 +741,32 @@ void Renderer::renderLoop()
}
}



if (ortho_overview)
{
if (ortho_save_tga || ortho_save_bmp)
{
setupFakeOrthoView(ortho_tga_w, ortho_tga_h, ortho_mins, ortho_maxs);
}
else
{
setupFakeOrthoView(0, 0, ortho_mins, ortho_maxs);
}
}
else
{
if (make_screenshot)
{
setupView(ortho_tga_w, ortho_tga_h);
}
else
{
setupView();
}
}


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//Update keyboard / mouse state
Expand Down Expand Up @@ -1291,12 +1353,8 @@ void Renderer::renderLoop()

if (ortho_save_tga || (make_screenshot && !isLoading))
{
make_screenshot--;
make_screenshot_target++;

if (make_screenshot)
{

std::string screenPath = g_working_dir;


Expand All @@ -1317,6 +1375,10 @@ void Renderer::renderLoop()
print_log("Saved to {} file!\n", (g_working_dir + "overview.tga"));
}

make_screenshot--;
make_screenshot_target++;


if (make_screenshot <= 0)
{
is_closing = true;
Expand Down
Loading

0 comments on commit 91a3229

Please sign in to comment.