diff --git a/Makefile b/Makefile index 198f109..6967431 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ SRCS= \ $(SRC_DIR)effects/random.cpp \ $(SRC_DIR)effects/wood.cpp \ $(SRC_DIR)effects/mountain.cpp \ + $(SRC_DIR)effects/debug.cpp \ MAKEFLAGS += --no-print-directory diff --git a/srcs/effects/cloud.cpp b/srcs/effects/cloud.cpp index 26ecad1..f76924e 100644 --- a/srcs/effects/cloud.cpp +++ b/srcs/effects/cloud.cpp @@ -3,10 +3,7 @@ #include "window.hpp" #include "noise/perlin.hpp" -int cloud(uint32_t *img, bool &needUpdate) { - if (!needUpdate) - return 0; - needUpdate = false; +int cloud(uint32_t *img) { static PerlinNoise PerlinNoise; static float time = 0.0; for (int y = 0; y < HEIGHT; y++) { @@ -19,7 +16,6 @@ int cloud(uint32_t *img, bool &needUpdate) { } } time += 0.1; - needUpdate = true; return 0; } diff --git a/srcs/effects/debug.cpp b/srcs/effects/debug.cpp new file mode 100644 index 0000000..685eee2 --- /dev/null +++ b/srcs/effects/debug.cpp @@ -0,0 +1,18 @@ +#include +#include +#include "window.hpp" +#include "noise/perlin.hpp" + +int test(uint32_t *img) { + static bool a = true; + for (int y = 0; y < HEIGHT; y++) { + for (int x = 0; x < WIDTH; x++) { + if (a) + img[y * WIDTH + x] = 0x202020; + else + img[y * WIDTH + x] = 0x0; + } + } + a = !a; + return 0; +} \ No newline at end of file diff --git a/srcs/effects/graph.cpp b/srcs/effects/graph.cpp index 9a704a8..605f467 100644 --- a/srcs/effects/graph.cpp +++ b/srcs/effects/graph.cpp @@ -3,10 +3,7 @@ #include "window.hpp" #include "noise/perlin.hpp" -int graph(uint32_t *img, bool &needUpdate) { - if (!needUpdate) - return 0; - needUpdate = false; +int graph(uint32_t *img) { static PerlinNoise PerlinNoise; static float time = 0.0; for (int x = 0; x < WIDTH; x++) { @@ -21,14 +18,10 @@ int graph(uint32_t *img, bool &needUpdate) { } } time += 0.001; - needUpdate = true; return 0; } -int graph2(uint32_t *img, bool &needUpdate) { - if (!needUpdate) - return 0; - needUpdate = false; +int graph2(uint32_t *img) { static PerlinNoise PerlinNoise; static float time = 0.0; for (int x = 0; x < WIDTH; x++) { @@ -45,6 +38,5 @@ int graph2(uint32_t *img, bool &needUpdate) { } } time += 0.001; - needUpdate = true; return 0; } diff --git a/srcs/effects/marble.cpp b/srcs/effects/marble.cpp index 5f0bb90..5ebe23f 100644 --- a/srcs/effects/marble.cpp +++ b/srcs/effects/marble.cpp @@ -3,10 +3,7 @@ #include "window.hpp" #include "noise/perlin.hpp" -int marble(uint32_t *img, bool &needUpdate) { - if (!needUpdate) - return 0; - needUpdate = false; +int marble(uint32_t *img) { static PerlinNoise perlinNoise; static float time = 0.0; for (int y = 0; y < HEIGHT; y++) { @@ -18,7 +15,6 @@ int marble(uint32_t *img, bool &needUpdate) { } } time += 0.01; - needUpdate = true; return 0; } diff --git a/srcs/effects/mountain.cpp b/srcs/effects/mountain.cpp index 056d09b..10fc502 100644 --- a/srcs/effects/mountain.cpp +++ b/srcs/effects/mountain.cpp @@ -3,10 +3,7 @@ #include "window.hpp" #include "noise/perlin.hpp" -int mountain(uint32_t *img, bool &needUpdate) { - if (!needUpdate) - return 0; - needUpdate = false; +int mountain(uint32_t *img) { static PerlinNoise P(9); static PerlinNoise P2(1000); static PerlinNoise P3(500); @@ -34,9 +31,6 @@ int mountain(uint32_t *img, bool &needUpdate) { img[i * WIDTH + x] = 0x151515; } } - - time += 0.03; - needUpdate = true; return 0; } diff --git a/srcs/effects/random.cpp b/srcs/effects/random.cpp index 7700633..5bc2414 100644 --- a/srcs/effects/random.cpp +++ b/srcs/effects/random.cpp @@ -2,10 +2,7 @@ #include "window.hpp" #include "noise/perlin.hpp" -int random(uint32_t *img, bool &needUpdate) { - if (!needUpdate) - return 0; - needUpdate = false; +int random(uint32_t *img) { static PerlinNoise PerlinNoise; static float time = 0.0; for (int y = 0; y < HEIGHT; y++) { @@ -17,7 +14,6 @@ int random(uint32_t *img, bool &needUpdate) { } } time += 0.01; - needUpdate = true; return 0; } diff --git a/srcs/effects/wood.cpp b/srcs/effects/wood.cpp index 115bba0..1374113 100644 --- a/srcs/effects/wood.cpp +++ b/srcs/effects/wood.cpp @@ -3,10 +3,7 @@ #include "window.hpp" #include "noise/perlin.hpp" -int wood(uint32_t *img, bool &needUpdate) { - if (!needUpdate) - return 0; - needUpdate = false; +int wood(uint32_t *img) { static PerlinNoise perlinNoise; static float time = 0.0; for (int y = 0; y < HEIGHT; y++) { @@ -18,6 +15,5 @@ int wood(uint32_t *img, bool &needUpdate) { } } time += 0.01; - needUpdate = true; return 0; } diff --git a/srcs/main.cpp b/srcs/main.cpp index f3c59e5..4b649dc 100644 --- a/srcs/main.cpp +++ b/srcs/main.cpp @@ -4,14 +4,14 @@ int main() { - WindowManager window(WIDTH, HEIGHT, mountain); + WindowManager window(WIDTH, HEIGHT, test); window.load_render(graph); window.load_render(graph2); window.load_render(cloud); window.load_render(marble); window.load_render(random); window.load_render(wood); - + window.load_render(mountain); window.loop(); return 0; diff --git a/srcs/windowManager/WindowManager.cpp b/srcs/windowManager/WindowManager.cpp index 4fc08a2..22efc88 100644 --- a/srcs/windowManager/WindowManager.cpp +++ b/srcs/windowManager/WindowManager.cpp @@ -5,7 +5,7 @@ #include #include -WindowManager::WindowManager(int width, int height, int (*render)(u_int32_t *img, bool &needUpdate)) : +WindowManager::WindowManager(int width, int height, int (*render)(u_int32_t *img)) : render(render), ptrTabIndex(0), WindowX(0), WindowY(0), @@ -15,8 +15,7 @@ WindowManager::WindowManager(int width, int height, int (*render)(u_int32_t *img WindowClass(CopyFromParent), WindowVisual(CopyFromParent), AttributeValueMask(CWBackPixel | CWEventMask), - isDisplayReady(false), - needUpdate(true) + isDisplayReady(false) { img = new u_int32_t[width * height]; MainDisplay = XOpenDisplay(0); @@ -81,10 +80,8 @@ void WindowManager::loop() { handle_events(GeneralEvent); } if (isDisplayReady) { - if (this->needUpdate) { - update_image(this->render); - display_image(); - } + update_image(this->render); + display_image(); // XSync(this->MainDisplay, false); } } @@ -112,11 +109,11 @@ void WindowManager::display_image() { XFlush(MainDisplay); } -void WindowManager::update_image(int (*func)(u_int32_t *img, bool &needUpdate)) { - if (func(this->img, this->needUpdate)) +void WindowManager::update_image(int (*func)(u_int32_t *img)) { + if (func(this->img)) this->isWindowOpen = false; } -void WindowManager::load_render(int (*func)(u_int32_t *img, bool &needUpdate)) { +void WindowManager::load_render(int (*func)(u_int32_t *img)) { this->renderFunctions.push_back(func); } \ No newline at end of file