Updated Signals, now using a structure

main
Brett 2022-11-16 17:49:02 -05:00
parent 7aea5ee8c4
commit 538edecc88
16 changed files with 50 additions and 42 deletions

View File

@ -32,3 +32,21 @@
2024 2092 1668636254845829121 Step_3 9d5d6ad8db7a0552
1 2159 1668636510057295808 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
2159 2281 1668636510177299347 Step_3 9d5d6ad8db7a0552
7 1557 1668638729558081224 CMakeFiles/Step_3.dir/src/graphics/debug_gui.cpp.o 9493619f74acd06a
7 1574 1668638729574081674 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
6 1747 1668638729746086503 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511
7 1869 1668638729870089983 CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o d86a254d2bce8f74
8 1915 1668638729914091218 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
6 2036 1668638730038094702 CMakeFiles/Step_3.dir/src/engine/math/bvh.cpp.o 7d05e3e63b85d471
7 2214 1668638730214099644 CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o 1007c86c207ac940
7 2355 1668638730354103574 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
7 2359 1668638730358103688 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
6 2756 1668638730758114918 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
1747 2768 1668638730770115257 CMakeFiles/Step_3.dir/src/graphics/input.cpp.o 510001b0955ab019
1558 3089 1668638731090124243 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 2553d57dba16057b
6 8726 1668638736726282542 CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o 1c68ba16e6b4d09b
1 1000 1668638793499880427 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511
1 1393 1668638820428640327 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
1 1823 1668638855401629000 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
1 1938 1668638882162386794 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
1938 2015 1668638882238388948 Step_3 9d5d6ad8db7a0552

Binary file not shown.

View File

@ -1,3 +1,3 @@
Start testing: Nov 16 17:11 EST
Start testing: Nov 16 17:48 EST
----------------------------------------------------------
End testing: Nov 16 17:11 EST
End testing: Nov 16 17:48 EST

View File

@ -56,6 +56,11 @@ static inline double degreeeToRadian(double deg) {
}
namespace Raytracing {
struct Signals {
bool haltExecution {false};
bool pauseRaytracing {false};
bool haltRaytracing {false};
};
class AlignedAllocator {
private:
public:

View File

@ -4,19 +4,16 @@
*/
// Yes, globals are bad.
#include "engine/util/debug.h"
#include <engine/util/std.h>
#include <config.h>
#ifdef COMPILE_GUI
#include <graphics/gl/gl.h>
#endif
bool* haltExecution;
bool* pauseRaytracing;
bool* haltRaytracing;
namespace Raytracing {
std::unordered_map<std::string, std::shared_ptr<profiler>> profiles;
Signals* RTSignal = new Signals {};
#ifdef COMPILE_GUI
std::shared_ptr<VAO> aabbVAO = nullptr;
int count = 0;

View File

@ -24,11 +24,11 @@
*
*/
using namespace Raytracing;
namespace Raytracing{
extern Signals* RTSignal;
}
extern bool* haltExecution;
extern bool* pauseRaytracing;
extern bool* haltRaytracing;
using namespace Raytracing;
int main(int argc, char** args) {
// since this is linux only we can easily set our process priority to be high with a syscall
@ -77,20 +77,13 @@ int main(int argc, char** args) {
if (parser.parse(args, argc))
return 0;
// yes this is a very stupid and bad way of doing this.
haltExecution = new bool;
pauseRaytracing = new bool;
haltRaytracing = new bool;
*haltExecution = false;
*pauseRaytracing = false;
*haltRaytracing = false;
if (signal(SIGTERM, [] (int sig) -> void {
ilog<<"Computations complete.\nHalting now...\n";
*haltExecution = true;
RTSignal->haltExecution = true;
})==SIG_ERR) { elog<<"Unable to change signal handler.\n"; return 1; }
if (signal(SIGINT, [] (int sig) -> void {
ilog<<"Computations complete.\nHalting now...\n";
*haltExecution = true;
RTSignal->haltExecution = true;
})==SIG_ERR) { elog<<"Unable to change signal handler.\n"; return 1; }
tlog << "Parsing complete! Starting raytracer with options:" << std::endl;
@ -160,7 +153,7 @@ int main(int argc, char** args) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
window.endUpdate();
}
*haltExecution = true;
RTSignal->haltExecution= true;
raycaster.join();
delete(spiderVAO);
delete(houseVAO);
@ -201,9 +194,7 @@ int main(int argc, char** args) {
ilog << "Writing Image!\n";
imageOutput.write(parser.getOptionValue("--output") + timeString.str(), parser.getOptionValue("--format"));
delete(haltExecution);
delete(haltRaytracing);
delete(pauseRaytracing);
delete(RTSignal);
#ifdef COMPILE_GUI
deleteQuad();
#endif

View File

@ -8,12 +8,10 @@
#include <utility>
#include <engine/util/debug.h>
extern bool* haltExecution;
extern bool* pauseRaytracing;
extern bool* haltRaytracing;
namespace Raytracing {
extern Signals* RTSignal;
Ray Camera::projectRay(PRECISION_TYPE x, PRECISION_TYPE y) {
// transform the x and y to points from image coords to be inside the camera's viewport.
double transformedX = (x / (image.getWidth() - 1));
@ -93,9 +91,9 @@ namespace Raytracing {
Ray localRay = ray;
Vec4 color {1.0, 1.0, 1.0};
for (int CURRENT_BOUNCE = 0; CURRENT_BOUNCE < maxBounceDepth; CURRENT_BOUNCE++){
if (*haltExecution || *haltRaytracing)
if (RTSignal->haltExecution || RTSignal->haltRaytracing)
return color;
while (*pauseRaytracing) // sleep for 1/60th of a second, or about 1 frame.
while (RTSignal->pauseRaytracing) // sleep for 1/60th of a second, or about 1 frame.
std::this_thread::sleep_for(std::chrono::milliseconds(16));
auto hit = world.checkIfHit(localRay, 0.001, infinity);
if (hit.first.hit) {
@ -153,9 +151,9 @@ namespace Raytracing {
PRECISION_TYPE sf = 1.0 / raysPerPixel;
// apply pixel color with gamma correction
image.setPixelColor(i, j, {std::sqrt(sf * color.r()), std::sqrt(sf * color.g()), std::sqrt(sf * color.b())});
if (*haltExecution || *haltRaytracing)
if (RTSignal->haltExecution || RTSignal->haltRaytracing)
return;
while (*pauseRaytracing) // sleep for 1/60th of a second, or about 1 frame.
while (RTSignal->pauseRaytracing) // sleep for 1/60th of a second, or about 1 frame.
std::this_thread::sleep_for(std::chrono::milliseconds(16));
}
}
@ -227,9 +225,9 @@ namespace Raytracing {
PRECISION_TYPE sf = 1.0 / raysPerPixel;
// apply pixel color with gamma correction
image.setPixelColor(x, y, {std::sqrt(sf * color.r()), std::sqrt(sf * color.g()), std::sqrt(sf * color.b())});
if (*haltExecution || *haltRaytracing)
if (RTSignal->haltExecution || RTSignal->haltRaytracing)
return;
while (*pauseRaytracing) // sleep for 1/60th of a second, or about 1 frame.
while (RTSignal->pauseRaytracing) // sleep for 1/60th of a second, or about 1 frame.
std::this_thread::sleep_for(std::chrono::milliseconds(16));
} catch (std::exception& error) {
flog << "Possibly fatal error in the multithreaded raytracer!\n";

View File

@ -7,13 +7,12 @@
#include <graphics/gl/gl.h>
#include "engine/image/stb_image.h"
#include "graphics/debug_gui.h"
extern bool* haltExecution;
extern bool* pauseRaytracing;
extern bool* haltRaytracing;
#include <engine/util/std.h>
namespace Raytracing {
extern Signals* RTSignal;
const std::vector<float> vertices = {
1.0f, 1.0f, 0.0f, // top right
1.0f, -1.0f, 0.0f, // bottom right
@ -482,14 +481,14 @@ namespace Raytracing {
static float yaw = 0, pitch = 0;
void DisplayRenderer::draw() {
if (*haltExecution){m_window.closeWindow();}
if (RTSignal->haltExecution){m_window.closeWindow();}
if (Input::isKeyDown(GLFW_KEY_ESCAPE) && Input::isState(GLFW_KEY_ESCAPE))
m_window.setMouseGrabbed(!m_window.isMouseGrabbed());
DebugUI::render([this]() -> void {
if (ImGui::Button("Start") && !started){
started = true;
*haltRaytracing = false;
RTSignal->haltRaytracing = false;
ilog << "Running raycaster!\n";
if(m_parser.hasOption("--multi")) {
m_raycaster.runMulti(std::max(std::stoi(m_parser.getOptionValue("-t")), std::stoi(m_parser.getOptionValue("--threads"))));
@ -497,9 +496,9 @@ namespace Raytracing {
m_raycaster.runSingle();
}
}
if (ImGui::Checkbox("Pause", pauseRaytracing)){}
if (ImGui::Checkbox("Pause", &RTSignal->pauseRaytracing)){}
if (ImGui::Button("Stop") && started){
*haltRaytracing = true;
RTSignal->haltRaytracing = true;
started = false;
m_raycaster.deleteThreads();
}