diff --git a/art.hpp b/art.hpp index fd438b7..b39663e 100644 --- a/art.hpp +++ b/art.hpp @@ -7,6 +7,7 @@ #include "pixelbuffer.h" +#include "imgui.h" #include "imgui_elements.h" @@ -27,14 +28,25 @@ class Art { bool gui() { if (pb) ScrollableSliderUInt("Max pixels", &pixel_buffer_maximum, 1, pixel_buffer_maximum_max, "%d", pixel_buffer_maximum/16); - return render_gui(); + bool up = render_gui(); + + ImGui::Text("pixels drawn %d, discarded %d", + pixels_drawn, pixels_discarded); + + if (pb) + ImGui::Text("pixel_buffer_size %d", + pb->buffer.size()); + + return up; } void draw(uint32_t *p) { + bool direct = render(p); if (pb) { pb->trunc(pixel_buffer_maximum); render_pixel_buffer(p); + } else if (!direct) { + std::copy(pixels.begin(), pixels.end(), p); } - render(p); } virtual void load(std::string json) {}; virtual std::string save() { return ""; }; @@ -62,10 +74,8 @@ class Art { virtual ~Art() = default; - unsigned pixels_drawn = 0; - unsigned pixels_discarded = 0; unsigned frame_number = 0, clear_every = 0; - unsigned pixel_buffer_maximum = 1024*10, pixel_buffer_maximum_max = 1024*64; + unsigned pixel_buffer_maximum = 1024*10, pixel_buffer_maximum_max = 1024*1024; void clear() { fill0(pixels); @@ -75,15 +85,26 @@ class Art { private: virtual void resize(int _w, int _h) {default_resize(_w, _h);}; virtual bool render_gui() = 0; - virtual void render(uint32_t *p) = 0; + virtual bool render(uint32_t *p) = 0; void render_pixel_buffer(uint32_t *screen) { + std::fill_n(screen, w*h, 0); +#if 1 + auto b = pb->buffer.begin(); + auto pbm = pb->buffer.size() > pixel_buffer_maximum ? pixel_buffer_maximum : pb->buffer.size(); + auto end = pb->buffer.begin() + pbm; + for (; b != end; ++b) + drawdot(screen, b->x, b->y, b->color); +#else for (auto &p : pb->buffer) drawdot(screen, p.x, p.y, p.color); +#endif } protected: + unsigned pixels_drawn = 0; + unsigned pixels_discarded = 0; void default_resize(int _w, int _h) { w = _w; h = _h; diff --git a/cloudlife.cpp b/cloudlife.cpp index 125702b..9915544 100644 --- a/cloudlife.cpp +++ b/cloudlife.cpp @@ -23,7 +23,7 @@ * documentation. No representations are made about the suitability of this * software for any purpose. It is provided "as is" without express or * implied warranty. - + * Dear ImGui port by Pavel Vasilyev , Jan 2023 */ @@ -243,7 +243,7 @@ unsigned int Cloudlife::do_tick() return count; } -void Cloudlife::render(uint32_t *p) { +bool Cloudlife::render(uint32_t *p) { unsigned int count = 0; for (int i=0; iticks_per_frame; ++i) @@ -270,8 +270,7 @@ void Cloudlife::render(uint32_t *p) { draw_field(); cycles++; - std::copy(pixels.begin(), pixels.end(), p); - + return false; } diff --git a/cloudlife.hpp b/cloudlife.hpp index f207ea6..33c9c77 100644 --- a/cloudlife.hpp +++ b/cloudlife.hpp @@ -25,7 +25,7 @@ class Cloudlife : public Art { private: virtual bool render_gui() override; virtual void resize(int _w, int _h) override; - virtual void render(uint32_t *p) override; + virtual bool render(uint32_t *p) override; std::unique_ptr f; unsigned ncolors=512; diff --git a/discrete.cpp b/discrete.cpp index 227fdea..b7f0e69 100644 --- a/discrete.cpp +++ b/discrete.cpp @@ -53,6 +53,7 @@ static enum ftypes bias[BIASES] = void Discrete::init_discrete() { + pb.reset(); discrete = discretestruct{}; double range; discretestruct *hp = &discrete; @@ -172,7 +173,8 @@ void Discrete::init_discrete() break; } case THORNBIRD: - hp->b = 0.1; + pb = std::make_unique(); + hp->b = 0.1; hp->i = hp->j = 0.1; /* select frequencies for parameter variation */ @@ -323,21 +325,22 @@ void Discrete::draw_discrete_1() break; } if (hp->op == THORNBIRD) { - x = (short) (hp->maxx / 2 * (1 - + sint*hp->j + cost*cosp*hp->i - cost*sinp*hp->b)); - y = (short) (hp->maxy / 2 * (1 - - cost*hp->j + sint*cosp*hp->i - sint*sinp*hp->b)); + x = (short) (hp->maxx / 2 * (1 + + sint*hp->j + cost*cosp*hp->i - cost*sinp*hp->b)); + y = (short) (hp->maxy / 2 * (1 + - cost*hp->j + sint*cosp*hp->i - sint*sinp*hp->b)); + pb->append({x, y, pal.get_color(count - k)}); } else { x = hp->maxx / 2 + (int) ((hp->i - hp->ic) * hp->is); y = hp->maxy / 2 - (int) ((hp->j - hp->jc) * hp->js); + drawdot(x, y, pal.get_color(count - k)); } - drawdot(x, y, pal.get_color(k)); } } -void Discrete::render(uint32_t *p) +bool Discrete::render(uint32_t *p) { discretestruct *hp = &discrete; int i; @@ -347,13 +350,14 @@ void Discrete::render(uint32_t *p) hp->count++; } - std::copy(pixels.begin(), pixels.end(), p); //if (hp->op == THORNBIRD) // clear(); if (hp->count > cycles) { resize(w, h); } + + return false; } diff --git a/ifs.cpp b/ifs.cpp index a6a046f..d0bdeab 100644 --- a/ifs.cpp +++ b/ifs.cpp @@ -241,7 +241,7 @@ IFS::iterate(int count, int p) /* Come on and iterate, iterate, iterate and sing... * * Yeah, this function just calls iterate, mutate, * * and then draws everything. */ -void IFS::render(uint32_t *p) +bool IFS::render(uint32_t *p) { int i; int partcolor, x, y; @@ -285,7 +285,7 @@ void IFS::render(uint32_t *p) mutate(&lenses[i]); } - std::copy(pixels.begin(), pixels.end(), p); + return false; } diff --git a/ifs.h b/ifs.h index 9696507..9200421 100644 --- a/ifs.h +++ b/ifs.h @@ -22,7 +22,7 @@ class IFS : public Art { private: virtual bool render_gui() override; virtual void resize(int _w, int _h) override; - virtual void render(uint32_t *p) override; + virtual bool render(uint32_t *p) override; int ncolours = 1024; int ccolour; diff --git a/main.cpp b/main.cpp index 90e1648..ded3200 100644 --- a/main.cpp +++ b/main.cpp @@ -201,9 +201,6 @@ int main(int argc, char *argv[]) bool reinit = art->gui(); - ImGui::Text("pixels drawn %d, discarded %d", - art->pixels_drawn, art->pixels_discarded); - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); diff --git a/mtron.cpp b/mtron.cpp index 86df42b..d93ecd9 100644 --- a/mtron.cpp +++ b/mtron.cpp @@ -38,7 +38,7 @@ void Minskytron::dt(uint32_t *p, int x, int y, double o, uint32_t c) { p[ y*W + x ] = c | ((unsigned)(0xff*o)<<24); } -void Minskytron::render(uint32_t *p) { +bool Minskytron::render(uint32_t *p) { //clear(); //std::fill(p, p+TEXTURE_SIZE, 0); memset(p, 0, TEXTURE_SIZE); @@ -74,7 +74,7 @@ void Minskytron::render(uint32_t *p) { ++i; } - //std::copy(pixels.begin(), pixels.end(), p); + return true; } bool Minskytron::render_gui() { diff --git a/mtron.hpp b/mtron.hpp index 44e1a01..4bba2a7 100644 --- a/mtron.hpp +++ b/mtron.hpp @@ -21,7 +21,7 @@ class Minskytron : public Art { private: virtual bool render_gui() override; //virtual void resize(int _w, int _h) override; - virtual void render(uint32_t *p) override; + virtual bool render(uint32_t *p) override; void reinit(); void dt(uint32_t *p, int x, int y, double o, uint32_t c); diff --git a/vermiculate.cpp b/vermiculate.cpp index a0d7dd0..27f1551 100644 --- a/vermiculate.cpp +++ b/vermiculate.cpp @@ -641,7 +641,7 @@ bool Vermiculate::move (unsigned char thr) return (!LP->dead); } -void Vermiculate::render (uint32_t *p) +bool Vermiculate::render (uint32_t *p) { int had_instring = (instring != 0); int tick = 0; @@ -695,7 +695,7 @@ void Vermiculate::render (uint32_t *p) if (loop++ < cycles) goto AGAIN; - std::copy(pixels.begin(), pixels.end(), p); + return false; } bool Vermiculate::render_gui () diff --git a/vermiculate.h b/vermiculate.h index eed6cb0..532b414 100644 --- a/vermiculate.h +++ b/vermiculate.h @@ -37,7 +37,7 @@ class Vermiculate : public Art { private: virtual bool render_gui() override; virtual void resize(int _w, int _h) override; - virtual void render(uint32_t *p) override; + virtual bool render(uint32_t *p) override; int speed = 1; bool erasing, cleared, autopal;