remove: code artefact
This commit is contained in:
parent
5a09672698
commit
212a30dd74
10 changed files with 35 additions and 49 deletions
1
Makefile
1
Makefile
|
|
@ -10,6 +10,7 @@ SRCS= \
|
||||||
$(SRC_DIR)effects/random.cpp \
|
$(SRC_DIR)effects/random.cpp \
|
||||||
$(SRC_DIR)effects/wood.cpp \
|
$(SRC_DIR)effects/wood.cpp \
|
||||||
$(SRC_DIR)effects/mountain.cpp \
|
$(SRC_DIR)effects/mountain.cpp \
|
||||||
|
$(SRC_DIR)effects/debug.cpp \
|
||||||
|
|
||||||
MAKEFLAGS += --no-print-directory
|
MAKEFLAGS += --no-print-directory
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,7 @@
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
#include "noise/perlin.hpp"
|
#include "noise/perlin.hpp"
|
||||||
|
|
||||||
int cloud(uint32_t *img, bool &needUpdate) {
|
int cloud(uint32_t *img) {
|
||||||
if (!needUpdate)
|
|
||||||
return 0;
|
|
||||||
needUpdate = false;
|
|
||||||
static PerlinNoise PerlinNoise;
|
static PerlinNoise PerlinNoise;
|
||||||
static float time = 0.0;
|
static float time = 0.0;
|
||||||
for (int y = 0; y < HEIGHT; y++) {
|
for (int y = 0; y < HEIGHT; y++) {
|
||||||
|
|
@ -19,7 +16,6 @@ int cloud(uint32_t *img, bool &needUpdate) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time += 0.1;
|
time += 0.1;
|
||||||
needUpdate = true;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
18
srcs/effects/debug.cpp
Normal file
18
srcs/effects/debug.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
|
@ -3,10 +3,7 @@
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
#include "noise/perlin.hpp"
|
#include "noise/perlin.hpp"
|
||||||
|
|
||||||
int graph(uint32_t *img, bool &needUpdate) {
|
int graph(uint32_t *img) {
|
||||||
if (!needUpdate)
|
|
||||||
return 0;
|
|
||||||
needUpdate = false;
|
|
||||||
static PerlinNoise PerlinNoise;
|
static PerlinNoise PerlinNoise;
|
||||||
static float time = 0.0;
|
static float time = 0.0;
|
||||||
for (int x = 0; x < WIDTH; x++) {
|
for (int x = 0; x < WIDTH; x++) {
|
||||||
|
|
@ -21,14 +18,10 @@ int graph(uint32_t *img, bool &needUpdate) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time += 0.001;
|
time += 0.001;
|
||||||
needUpdate = true;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int graph2(uint32_t *img, bool &needUpdate) {
|
int graph2(uint32_t *img) {
|
||||||
if (!needUpdate)
|
|
||||||
return 0;
|
|
||||||
needUpdate = false;
|
|
||||||
static PerlinNoise PerlinNoise;
|
static PerlinNoise PerlinNoise;
|
||||||
static float time = 0.0;
|
static float time = 0.0;
|
||||||
for (int x = 0; x < WIDTH; x++) {
|
for (int x = 0; x < WIDTH; x++) {
|
||||||
|
|
@ -45,6 +38,5 @@ int graph2(uint32_t *img, bool &needUpdate) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time += 0.001;
|
time += 0.001;
|
||||||
needUpdate = true;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,7 @@
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
#include "noise/perlin.hpp"
|
#include "noise/perlin.hpp"
|
||||||
|
|
||||||
int marble(uint32_t *img, bool &needUpdate) {
|
int marble(uint32_t *img) {
|
||||||
if (!needUpdate)
|
|
||||||
return 0;
|
|
||||||
needUpdate = false;
|
|
||||||
static PerlinNoise perlinNoise;
|
static PerlinNoise perlinNoise;
|
||||||
static float time = 0.0;
|
static float time = 0.0;
|
||||||
for (int y = 0; y < HEIGHT; y++) {
|
for (int y = 0; y < HEIGHT; y++) {
|
||||||
|
|
@ -18,7 +15,6 @@ int marble(uint32_t *img, bool &needUpdate) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time += 0.01;
|
time += 0.01;
|
||||||
needUpdate = true;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,7 @@
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
#include "noise/perlin.hpp"
|
#include "noise/perlin.hpp"
|
||||||
|
|
||||||
int mountain(uint32_t *img, bool &needUpdate) {
|
int mountain(uint32_t *img) {
|
||||||
if (!needUpdate)
|
|
||||||
return 0;
|
|
||||||
needUpdate = false;
|
|
||||||
static PerlinNoise P(9);
|
static PerlinNoise P(9);
|
||||||
static PerlinNoise P2(1000);
|
static PerlinNoise P2(1000);
|
||||||
static PerlinNoise P3(500);
|
static PerlinNoise P3(500);
|
||||||
|
|
@ -34,9 +31,6 @@ int mountain(uint32_t *img, bool &needUpdate) {
|
||||||
img[i * WIDTH + x] = 0x151515;
|
img[i * WIDTH + x] = 0x151515;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
time += 0.03;
|
time += 0.03;
|
||||||
needUpdate = true;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,7 @@
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
#include "noise/perlin.hpp"
|
#include "noise/perlin.hpp"
|
||||||
|
|
||||||
int random(uint32_t *img, bool &needUpdate) {
|
int random(uint32_t *img) {
|
||||||
if (!needUpdate)
|
|
||||||
return 0;
|
|
||||||
needUpdate = false;
|
|
||||||
static PerlinNoise PerlinNoise;
|
static PerlinNoise PerlinNoise;
|
||||||
static float time = 0.0;
|
static float time = 0.0;
|
||||||
for (int y = 0; y < HEIGHT; y++) {
|
for (int y = 0; y < HEIGHT; y++) {
|
||||||
|
|
@ -17,7 +14,6 @@ int random(uint32_t *img, bool &needUpdate) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time += 0.01;
|
time += 0.01;
|
||||||
needUpdate = true;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,7 @@
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
#include "noise/perlin.hpp"
|
#include "noise/perlin.hpp"
|
||||||
|
|
||||||
int wood(uint32_t *img, bool &needUpdate) {
|
int wood(uint32_t *img) {
|
||||||
if (!needUpdate)
|
|
||||||
return 0;
|
|
||||||
needUpdate = false;
|
|
||||||
static PerlinNoise perlinNoise;
|
static PerlinNoise perlinNoise;
|
||||||
static float time = 0.0;
|
static float time = 0.0;
|
||||||
for (int y = 0; y < HEIGHT; y++) {
|
for (int y = 0; y < HEIGHT; y++) {
|
||||||
|
|
@ -18,6 +15,5 @@ int wood(uint32_t *img, bool &needUpdate) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time += 0.01;
|
time += 0.01;
|
||||||
needUpdate = true;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
WindowManager window(WIDTH, HEIGHT, mountain);
|
WindowManager window(WIDTH, HEIGHT, test);
|
||||||
window.load_render(graph);
|
window.load_render(graph);
|
||||||
window.load_render(graph2);
|
window.load_render(graph2);
|
||||||
window.load_render(cloud);
|
window.load_render(cloud);
|
||||||
window.load_render(marble);
|
window.load_render(marble);
|
||||||
window.load_render(random);
|
window.load_render(random);
|
||||||
window.load_render(wood);
|
window.load_render(wood);
|
||||||
|
window.load_render(mountain);
|
||||||
|
|
||||||
window.loop();
|
window.loop();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <csignal>
|
#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),
|
render(render),
|
||||||
ptrTabIndex(0),
|
ptrTabIndex(0),
|
||||||
WindowX(0), WindowY(0),
|
WindowX(0), WindowY(0),
|
||||||
|
|
@ -15,8 +15,7 @@ WindowManager::WindowManager(int width, int height, int (*render)(u_int32_t *img
|
||||||
WindowClass(CopyFromParent),
|
WindowClass(CopyFromParent),
|
||||||
WindowVisual(CopyFromParent),
|
WindowVisual(CopyFromParent),
|
||||||
AttributeValueMask(CWBackPixel | CWEventMask),
|
AttributeValueMask(CWBackPixel | CWEventMask),
|
||||||
isDisplayReady(false),
|
isDisplayReady(false)
|
||||||
needUpdate(true)
|
|
||||||
{
|
{
|
||||||
img = new u_int32_t[width * height];
|
img = new u_int32_t[width * height];
|
||||||
MainDisplay = XOpenDisplay(0);
|
MainDisplay = XOpenDisplay(0);
|
||||||
|
|
@ -81,10 +80,8 @@ void WindowManager::loop() {
|
||||||
handle_events(GeneralEvent);
|
handle_events(GeneralEvent);
|
||||||
}
|
}
|
||||||
if (isDisplayReady) {
|
if (isDisplayReady) {
|
||||||
if (this->needUpdate) {
|
|
||||||
update_image(this->render);
|
update_image(this->render);
|
||||||
display_image();
|
display_image();
|
||||||
}
|
|
||||||
// XSync(this->MainDisplay, false);
|
// XSync(this->MainDisplay, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -112,11 +109,11 @@ void WindowManager::display_image() {
|
||||||
XFlush(MainDisplay);
|
XFlush(MainDisplay);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::update_image(int (*func)(u_int32_t *img, bool &needUpdate)) {
|
void WindowManager::update_image(int (*func)(u_int32_t *img)) {
|
||||||
if (func(this->img, this->needUpdate))
|
if (func(this->img))
|
||||||
this->isWindowOpen = false;
|
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);
|
this->renderFunctions.push_back(func);
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue