remove: code artefact

This commit is contained in:
Loic Rio 2024-12-14 19:25:06 +01:00
parent 5a09672698
commit 212a30dd74
10 changed files with 35 additions and 49 deletions

View file

@ -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

View file

@ -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;
}

18
srcs/effects/debug.cpp Normal file
View file

@ -0,0 +1,18 @@
#include <cmath>
#include <cstdint>
#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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;

View file

@ -5,7 +5,7 @@
#include <X11/Xlib.h>
#include <csignal>
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);
}