diff options
-rw-r--r-- | libdimension/png.c | 2 | ||||
-rw-r--r-- | tests/glxx.cpp | 6 | ||||
-rw-r--r-- | tests/testsxx.cpp | 49 | ||||
-rw-r--r-- | tests/testsxx.hpp | 3 |
4 files changed, 58 insertions, 2 deletions
diff --git a/libdimension/png.c b/libdimension/png.c index ae380f9..8a23214 100644 --- a/libdimension/png.c +++ b/libdimension/png.c @@ -616,4 +616,4 @@ dmnsn_png_read_row_callback(png_structp png_ptr, png_uint_32 row, int pass) if (progress) { dmnsn_increment_progress(progress); } -}
\ No newline at end of file +} diff --git a/tests/glxx.cpp b/tests/glxx.cpp index b22111f..e44510b 100644 --- a/tests/glxx.cpp +++ b/tests/glxx.cpp @@ -42,12 +42,18 @@ main() { // Render the scene Progress progress = raytracer.render_async(); + std::cout << "Raytracing scene: "; + Progress barprogress = Tests::progressbar_async(std::cout, progress); + // Display the scene as it's rendered while (progress.progress() < 1.0) { writer.write(); display.flush(); } + barprogress.finish(); + std::cout << std::endl; + // Make sure we show the completed rendering progress.finish(); writer.write(); diff --git a/tests/testsxx.cpp b/tests/testsxx.cpp index e8dc910..908d0f8 100644 --- a/tests/testsxx.cpp +++ b/tests/testsxx.cpp @@ -76,6 +76,53 @@ namespace Dimension { dmnsn_display_flush(m_display); } + + namespace + { + struct Progressbar_Payload + { + public: + std::ostream* ostr; + const Progress* progress; + }; + + void * + progressbar_thread(void *ptr) + { + Progressbar_Payload* payload + = reinterpret_cast<Progressbar_Payload*>(ptr); + + *payload->ostr << *payload->progress; + + int* ret = static_cast<int*>(std::malloc(sizeof(int))); + if (ret) { + *ret = 0; + } + return ret; + } + } + + Progress progressbar_async(std::ostream& ostr, + const Dimension::Progress& progress) + { + dmnsn_progress* barprogress = dmnsn_new_progress(); + if (!barprogress) { + throw Dimension_Error("Couldn't allocate progress object."); + } + + Progressbar_Payload* payload = new Progressbar_Payload; + payload->ostr = &ostr; + payload->progress = &progress; + + /* Create the worker thread */ + if (pthread_create(&barprogress->thread, NULL, &progressbar_thread, + reinterpret_cast<void*>(payload)) + != 0) { + throw Dimension_Error("Couldn't create background thread."); + } + + return Progress(barprogress); + } } // Print a progress bar of the progress of `progress' @@ -91,4 +138,4 @@ namespace Dimension } return ostr << "|" << std::flush; } -}
\ No newline at end of file +} diff --git a/tests/testsxx.hpp b/tests/testsxx.hpp index c2c1771..e2b654f 100644 --- a/tests/testsxx.hpp +++ b/tests/testsxx.hpp @@ -43,6 +43,9 @@ namespace Dimension private: dmnsn_display* m_display; }; + + Progress progressbar_async(std::ostream& ostr, + const Dimension::Progress& progress); } // Print a progress bar of the progress of `progress' |