From bb6c65f9342198e04ede50a6e92e17ba7ea4001d Mon Sep 17 00:00:00 2001 From: Pavel V Date: Mon, 12 Jun 2023 17:58:43 +0300 Subject: [PATCH] cloudtest --- .github/workflows/cmake.yml | 2 +- CMakeLists.txt | 16 +++++- artfactory.cpp | 7 +++ artfactory.h | 1 + imgui_elements.cpp | 15 ++++- imgui_elements.h | 4 +- main.cpp | 2 +- test.cpp | 107 ++++++++++++++++++++++++++++++++++++ 8 files changed, 144 insertions(+), 10 deletions(-) create mode 100644 test.cpp diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 5a4f022..680a99c 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -36,5 +36,5 @@ jobs: working-directory: ${{github.workspace}}/build # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest -C ${{env.BUILD_TYPE}} + run: ctest -V -C ${{env.BUILD_TYPE}} diff --git a/CMakeLists.txt b/CMakeLists.txt index d97a2f9..80c7109 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,9 +43,7 @@ find_package(glfw3) add_subdirectory(colormap) -add_executable(cloudlife) -target_sources(cloudlife PUBLIC - main.cpp +add_library(clouds OBJECT artfactory.cpp settings.cpp imgui_elements.cpp @@ -57,5 +55,17 @@ target_sources(cloudlife PUBLIC vermiculate.cpp discrete.cpp thornbird.cpp) + +target_link_libraries(clouds IMGUI glfw GL colormap) + +add_executable(cloudlife main.cpp $) +add_executable(cloudtest test.cpp $) target_link_libraries(cloudlife IMGUI glfw GL colormap) +target_link_libraries(cloudtest IMGUI glfw GL colormap) set_target_properties(cloudlife PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +set_target_properties(cloudtest PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) + +include(CTest) + +add_test(NAME CloudTest1 COMMAND cloudtest) +add_test(NAME CloudTest2 COMMAND cloudtest -f 32 -i 8) diff --git a/artfactory.cpp b/artfactory.cpp index df25000..9ee2bbf 100644 --- a/artfactory.cpp +++ b/artfactory.cpp @@ -24,6 +24,13 @@ std::unique_ptr ArtFactory::get_art() { return std::unique_ptr(create(vc.get_value())); } +void ArtFactory::cycle_art() { + int i = vc.get_index() + 1; + if (i >= art_items.size()) + i = 0; + vc.set_index(i); +} + bool ArtFactory::render_gui() { return vc.RenderGui(); } diff --git a/artfactory.h b/artfactory.h index 2e56a5f..e7f7081 100644 --- a/artfactory.h +++ b/artfactory.h @@ -43,6 +43,7 @@ class ArtFactory : public Factory { public: ArtFactory(); std::unique_ptr get_art(); + void cycle_art(); bool render_gui(); private: VectorCombo::combo_container_t art_items; diff --git a/imgui_elements.cpp b/imgui_elements.cpp index 3b85421..ac5f990 100644 --- a/imgui_elements.cpp +++ b/imgui_elements.cpp @@ -145,7 +145,7 @@ bool ScrollableSliderUInt(const char* label, unsigned* v, unsigned v_min, unsign #include #include "timer.h" -void cpu_load_text() +char * cpu_load_text() { static int c = 0; static double up = 0, sp = 0; @@ -153,6 +153,7 @@ void cpu_load_text() static struct rusage old_usage; static double outt = 0, ostt = 0; static double ru_maxrss = 0; + static char text[1024*4]; if (c % 120 == 0) { common::Timer t; @@ -177,6 +178,14 @@ void cpu_load_text() } c++; - ImGui::Text("Usr + Sys = %.2f + %.2f = %.2f", up, sp, up+sp); - ImGui::Text("maxrss %.2f MB", ru_maxrss); + snprintf(text, sizeof(text), + "Usr + Sys = %.2f + %.2f = %.2f. maxrss %.2f MB", + up, sp, up+sp, ru_maxrss); + + return text; +} + +void cpu_load_gui() +{ + ImGui::Text(cpu_load_text()); } diff --git a/imgui_elements.h b/imgui_elements.h index 8bf9e2d..cc592b0 100644 --- a/imgui_elements.h +++ b/imgui_elements.h @@ -4,5 +4,5 @@ bool ScrollableSliderFloat(const char* label, float* v, float v_min, float v_max bool ScrollableSliderInt(const char* label, int* v, int v_min, int v_max, const char* format, float scrollFactor); bool ScrollableSliderUInt(const char* label, unsigned* v, unsigned v_min, unsigned v_max, const char* format, float scrollFactor); -void cpu_load_text(); - +char *cpu_load_text(); +void cpu_load_gui(); diff --git a/main.cpp b/main.cpp index 8f2efb4..fc1b74a 100644 --- a/main.cpp +++ b/main.cpp @@ -194,7 +194,7 @@ int main(int argc, char *argv[]) 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); - cpu_load_text(); + cpu_load_gui(); ImGui::End(); diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..eb4166e --- /dev/null +++ b/test.cpp @@ -0,0 +1,107 @@ +#include +#include + +#include // getopt +#include + +#include "imgui.h" +#include "imgui_elements.h" + +#include + +#include "timer.h" + +#include "artfactory.h" + +std::unique_ptr art; + +static int sw = 1024, sh = 1024; + +typedef uint32_t pixel_t; +pixel_t *image_data = NULL; +std::vector image_data_vector; +#define texture_size (art->tex_w * art->tex_h * sizeof(pixel_t)) + +void make_pbos() { + image_data_vector.resize(texture_size); + image_data = image_data_vector.data(); +} + + +int main(int argc, char *argv[]) +{ + int opt; + int frames = 128, iterations = 2, reporting = 1; + + while ((opt = getopt(argc, argv, "f:i:r:")) != -1) { + switch (opt) { + case 'f': + frames = atoi(optarg); + break; + case 'i': + iterations = atoi(optarg); + break; + case 'r': + reporting = atoi(optarg); + break; + default: /* '?' */ + fprintf(stderr, "Usage: %s [-f frames=128] [-i iterations=2] [-r reporting=1]\n", + argv[0]); + exit(EXIT_FAILURE); + } + } + + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + + ImGui::StyleColorsDark(); + + ArtFactory af; + art = af.get_art(); + + std::string first_art(art->name()); + + do { + sw = sh = 1024; + for (int i=0; iname(), sw, sh); + art->resized(sw, sh); + art->frame_number = 0; + make_pbos(); + + float fps = 0; + common::Timer old_t; + + while (art->frame_number < frames) + { + art->draw(image_data); + + ++art->frame_number; + if (art->clear_every != 0 && art->frame_number % art->clear_every == 0) + art->clear(); + + if (art->frame_number % reporting == 0) { + common::Timer t; + double dt = (t - old_t).seconds(); + double fps = art->frame_number / dt; + + printf("%s frame:%d fps:%.2f \r", + cpu_load_text(), art->frame_number, fps); + fflush(stdout); + } + } + sw += 321; + sh += 123; + printf("\n"); + } + + af.cycle_art(); + art = af.get_art(); + } while (first_art != art->name()); + + ImGui::DestroyContext(); + + return 0; +}