Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
yekm committed Apr 3, 2023
1 parent 1540ffd commit f810958
Show file tree
Hide file tree
Showing 8 changed files with 439 additions and 777 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ find_package(glfw3)
add_subdirectory(colormap)

add_executable(cloudlife)
target_sources(cloudlife PUBLIC main.cpp imgui_elements.cpp random.c)
target_sources(cloudlife PUBLIC
main.cpp
settings.cpp
imgui_elements.cpp
random.c
cloudlife.cpp)
target_link_libraries(cloudlife IMGUI glfw GL colormap)
set_target_properties(cloudlife PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
45 changes: 45 additions & 0 deletions art.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <cstdint>
#include <string>
#include <vector>

class Art {
public:
Art(std::string _name)
: name(_name) {}
virtual bool render_gui() = 0;
virtual void resize(int _w, int _h) = 0;
virtual void render(uint32_t *p) = 0;
virtual void load(std::string json) {};
virtual std::string save() { return ""; };

void drawdot(int x, int y, double o, uint32_t c) {
if (x+1 > w || y+1 > h) return;
uint32_t *p = data();
p[ y*w + x ] = c | ((unsigned)(0xff*o)<<24);
}

void drawdot(int x, int y, uint32_t c) {
if (x+1 > w || y+1 > h) return;
uint32_t *p = data();
p[ y*w + x ] = c;
}

virtual void reinit() { resize(w, h); }

protected:
void default_resize(int _w, int _h) {
w = _w;
h = _h;
//data = (uint8_t *)xrealloc(data, w*h*sizeof(uint32_t));
pixels.resize(w*h);
clear();
}
void clear() {
std::fill(pixels.begin(), pixels.end(), 0);
}
int w, h;
//uint8_t *data() { return reinterpret_cast<uint8_t*>(pixels.data()); }
uint32_t *data() { return pixels.data(); }
std::vector<uint32_t> pixels;
std::string name;
};
Loading

0 comments on commit f810958

Please sign in to comment.