diff --git a/src/Optional.h b/src/Optional.h index 3b3a7d4..0633df4 100644 --- a/src/Optional.h +++ b/src/Optional.h @@ -1,4 +1,5 @@ #ifndef OPTIONAL_H_ +#define OPTIONAL_H_ namespace utils { diff --git a/src/Progress.h b/src/Progress.h new file mode 100644 index 0000000..6417dfa --- /dev/null +++ b/src/Progress.h @@ -0,0 +1,29 @@ +#ifndef PROGRESS_H_ +#define PROGRESS_H_ + +#include + +namespace utils { + +#define BAR_WIDTH 70 + +class Progress { +public: + static void of(float p) { + std::cout << "["; + int pos = BAR_WIDTH * p; + for (int i = 0; i < BAR_WIDTH; ++i) { + if (i < pos) + std::cout << "="; + else if (i == pos) + std::cout << ">"; + else + std::cout << " "; + } + std::cout << "] " << int(p * 100.0) << " %\r"; + std::cout.flush(); + } +}; +} // namespace utils + +#endif // !PROGRESS_H_ diff --git a/src/RayTracer.cc b/src/RayTracer.cc index 69c55b1..479e6d4 100644 --- a/src/RayTracer.cc +++ b/src/RayTracer.cc @@ -2,6 +2,7 @@ #include "HitRecord.h" #include "Output.h" #include "Parser.h" +#include "Progress.h" #include "Ray.h" #include @@ -70,7 +71,8 @@ void RayTracer::render() { rpp = raysPerPixel.z(); } - for (int y = 0; y < height; ++y) + for (int y = 0; y < height; ++y) { + utils::Progress::of((y + 1.0f) / height); for (int x = 0; x < width; ++x) for (int j = 0; j < gridHeight; ++j) for (int i = 0; i < gridWidth; ++i) { @@ -88,6 +90,9 @@ void RayTracer::render() { calculateColor(hit, y * width + x); } } + } + + std::cout << std::endl; } void RayTracer::run() {