From bde42f320f947b527ebe1c38c9438f177a3c2ce6 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 13 Jul 2021 18:29:35 +0200 Subject: [PATCH] Move to cmake --- .gitignore | 2 + .idea/.gitignore | 8 + .idea/atomorph.iml | 2 + .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + CMakeLists.txt | 46 +++ Makefile | 39 -- demo/allegro5/AtoMorph-GUI.cbp | 48 --- demo/allegro5/Makefile | 44 --- demo/allegro5/README | 15 - demo/allegro5/data/fixed_font.tga | Bin 25839 -> 0 bytes demo/allegro5/main.cpp | 561 --------------------------- demo/allegro5/main.h | 50 --- demo/allegro5/obj/.gitignore | 4 - atomorph.cpp => src/atomorph.cpp | 0 atomorph.h => src/atomorph.h | 1 + color.cpp => src/color.cpp | 0 color.h => src/color.h | 4 +- fluidmodel.cpp => src/fluidmodel.cpp | 2 +- fluidmodel.h => src/fluidmodel.h | 0 morph.cpp => src/morph.cpp | 0 morph.h => src/morph.h | 0 perlin.cpp => src/perlin.cpp | 0 perlin.h => src/perlin.h | 0 spline.cpp => src/spline.cpp | 0 spline.h => src/spline.h | 0 thread.cpp => src/thread.cpp | 0 thread.h => src/thread.h | 3 +- vec3d.h => src/vec3d.h | 0 30 files changed, 83 insertions(+), 764 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/atomorph.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 CMakeLists.txt delete mode 100644 Makefile delete mode 100644 demo/allegro5/AtoMorph-GUI.cbp delete mode 100644 demo/allegro5/Makefile delete mode 100644 demo/allegro5/README delete mode 100755 demo/allegro5/data/fixed_font.tga delete mode 100644 demo/allegro5/main.cpp delete mode 100644 demo/allegro5/main.h delete mode 100644 demo/allegro5/obj/.gitignore rename atomorph.cpp => src/atomorph.cpp (100%) rename atomorph.h => src/atomorph.h (99%) rename color.cpp => src/color.cpp (100%) rename color.h => src/color.h (97%) rename fluidmodel.cpp => src/fluidmodel.cpp (99%) rename fluidmodel.h => src/fluidmodel.h (100%) rename morph.cpp => src/morph.cpp (100%) rename morph.h => src/morph.h (100%) rename perlin.cpp => src/perlin.cpp (100%) rename perlin.h => src/perlin.h (100%) rename spline.cpp => src/spline.cpp (100%) rename spline.h => src/spline.h (100%) rename thread.cpp => src/thread.cpp (100%) rename thread.h => src/thread.h (99%) rename vec3d.h => src/vec3d.h (100%) diff --git a/.gitignore b/.gitignore index 9141573..e86b816 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ demo/allegro5/atomorph-gui demo/atomorph libatomorph.a +cmake-build-* +.idea \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/atomorph.iml b/.idea/atomorph.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/atomorph.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..323310f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..38a3db3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.16) +project("atomorph") + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_compile_options(-Wall -Wextra -Werror) + +option(WINDOWS "Whether the build target is Windows or not." OFF) +option(SHARED "Whether we should build a shared library, instead of a static one." OFF) + +if (NOT WINDOWS) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +else() + set(CMAKE_POSITION_INDEPENDENT_CODE OFF) +endif() + +set(LIBTYPE STATIC) +if (SHARED) + set(LIBTYPE SHARED) +endif (SHARED) + +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_link_options(-fuse-ld=lld) +endif () + +file(GLOB_RECURSE SRC_FILES "src/*.cpp") +add_library(atomorph ${LIBTYPE} ${SRC_FILES}) + +if (WINDOWS) + MESSAGE(WARNING, "Using Windows Build.") + # Add a definition for the compiler, so we can use it in C++ as well. + ADD_DEFINITIONS(-D WINDOWS=1) + # -m64: Build a 64 bit library + add_compile_options(-m64) + if (SHARED) + set_target_properties(atomorph PROPERTIES SUFFIX ".dll") + endif() +endif (WINDOWS) + +if (STATICC) + message("Linking dependencies statically.") + set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed") + set(LINKS -static-libgcc -static-libstdc++ -Wl,-Bstatic -lm -lstdc++ -lpthread -Wl,-Bdynamic ${LINKS}) +endif(STATICC) +target_link_libraries(atomorph ${LINKS}) diff --git a/Makefile b/Makefile deleted file mode 100644 index 027b735..0000000 --- a/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -NAME = atomorph -CC = gcc -PROF = -O2 -C_FLAGS = -std=c++11 -Wall -pedantic $(PROF) -OBJ_DIR = obj - -SRC_FILES := $(wildcard *.cpp) -O_FILES := $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(SRC_FILES)) - -OUT = ./lib$(NAME).a - -all: - @printf "\033[0mHINT: On errors, try \033[1;33m-std=gnu++11 -stdlib=libc++\033[0m compiler flags.\033[0m\n" - @printf "\033[0mHINT: Use \033[1;33mmake opencv\033[0m for OpenCV optimizations (experimental).\033[0m\n" - @printf "\033[0mHINT: Use \033[1;33mmake deprecated\033[0m to compile the old version.\033[0m\n" - @$(MAKE) $(OUT) -s - -opencv: DEFINES = -D ATOMORPH_OPENCV -opencv: $(O_FILES) - @ar rcs $(OUT) $(O_FILES) - @printf "\033[1;32mOpenCV dependent lib$(NAME).a DONE!\033[0m\n" - -deprecated: DEFINES = -D ATOMORPH_DEPRECATED -deprecated: $(O_FILES) - @ar rcs $(OUT) $(O_FILES) - @printf "\033[1;32mDeprecated lib$(NAME).a DONE!\033[0m\n" - -$(OUT): $(O_FILES) - @ar rcs $(OUT) $(O_FILES) - @printf "\033[1;32mlib$(NAME).a DONE!\033[0m\n" - -$(OBJ_DIR)/%.o: %.cpp - @printf "\033[1m\033[31mCompiling \033[37m....\033[34m %-20s\t\033[33m%6s\033[31m lines\033[0m \n" $*.cpp "`wc -l $*.cpp | cut -f1 -d' '`" - @$(CC) $(INCLUDE) $< $(DEFINES) $(C_FLAGS) -c -o $@ - -clean: - @printf "\033[1;36mCleaning \033[37m ...." - @rm -f $(O_FILES) $(OUT) *~ *.bak *.orig *.rej - @printf "\033[1;37m lib$(NAME).a cleaned!\033[0m\n" diff --git a/demo/allegro5/AtoMorph-GUI.cbp b/demo/allegro5/AtoMorph-GUI.cbp deleted file mode 100644 index 3a2dbf6..0000000 --- a/demo/allegro5/AtoMorph-GUI.cbp +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - diff --git a/demo/allegro5/Makefile b/demo/allegro5/Makefile deleted file mode 100644 index 1da2c57..0000000 --- a/demo/allegro5/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -NAME = atomorph-gui -CC = gcc -PROF = -O2 -C_FLAGS = -std=c++11 -Wall $(PROF) -L_FLAGS = ../../libatomorph.a -lm -lstdc++ $(PROF) -OBJ_DIR = obj -DEFINES = -D ATOMORPH_DEPRECATED - -#Change the LIB_DIR to the path where the MODULES are located: -LIB_DIR = /usr/lib/ -MODULES = allegro.so allegro_image.so allegro_font.so allegro_primitives.so - -SRC_FILES := $(wildcard *.cpp) -LIB_FILES := $(patsubst %,$(LIB_DIR)/lib%,$(MODULES)) -O_FILES := $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(SRC_FILES)) - -OUT = ./$(NAME) - -all: - @printf "\033[0mHINT: libatomorph.a has to be compiled using the \033[1;33mmake deprecated\033[0m command.\033[0m\n" - @printf "\033[0mHINT: Use \033[1;33mmake static\033[0m to link statically.\033[0m\n" - @$(MAKE) dynamically_linked -s - -static: - @$(MAKE) statically_linked -s - -statically_linked: $(O_FILES) - @printf "\033[1;33mMaking \033[37m ...." - $(CC) -static -o ./$(NAME) $(O_FILES) $(LIB_FILES) $(L_FLAGS) - @printf "\033[1;32m Statically linked %s DONE!\033[0m\n" $(NAME) - -dynamically_linked: $(O_FILES) - @printf "\033[1;33mMaking \033[37m ...." - $(CC) -o ./$(NAME) $(O_FILES) $(LIB_FILES) $(L_FLAGS) - @printf "\033[1;32m Dynamically linked %s DONE!\033[0m\n" $(NAME) - -$(OBJ_DIR)/%.o: %.cpp - @printf "\033[1m\033[31mCompiling \033[37m....\033[34m %-20s\t\033[33m%6s\033[31m lines\033[0m \n" $*.cpp "`wc -l $*.cpp | cut -f1 -d' '`" - @$(CC) $< $(DEFINES) $(C_FLAGS) -c -o $@ - -clean: - @printf "\033[1;36mCleaning \033[37m ...." - @rm -f $(O_FILES) $(OUT) *~ *.bak *.orig *.rej - @printf "\033[1;37m $(NAME) cleaned!\033[0m\n" diff --git a/demo/allegro5/README b/demo/allegro5/README deleted file mode 100644 index ff7ad76..0000000 --- a/demo/allegro5/README +++ /dev/null @@ -1,15 +0,0 @@ -This AtoMorph-GUI implementation is deprecated because it uses -an older version of the AtoMorph Library. The latter has to be -compiled using the `deprecated` build target. - -AtoMorph-GUI requires Allegro5.1 installed on your system. - -Build instructions: - Run make in this folder. - Edit the Makefile if needed. - -Alternative build instructions: - Use CodeBlocks and open AtoMorph-GUI.cbp. - -If you like this software, please consider making a donation -by sending Bitcoins to 1Erich1YUdkUAp9ynf4Rfw2ug8nBtuUmMu. diff --git a/demo/allegro5/data/fixed_font.tga b/demo/allegro5/data/fixed_font.tga deleted file mode 100755 index bc751239a6cb1a4df06e90213c242732d14bf0e0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25839 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 -#include - -#include "main.h" - -const float FPS = 60.0; // Maximum FPS. -const int SCREEN_W = 800; -const int SCREEN_H = 600; -const int MORPH_W = 128; // Width of the morph. Should be at most the width of the input image. -const int MORPH_H = 128; // Height of the morph. Should be at most the height of the input image. -const int ATOMS = 10000; // Number of atoms used in one thread. -const size_t THREAD_N = 5; // Number of threads to use to find a perfect morph. -const size_t SLOWNESS = 50; // How many frames to render per animation cycle. - -size_t morph_time = 0; -int view_frame = 0; -bool pressed_keys[ALLEGRO_KEY_MAX]; - -size_t active_thread = 0; // When render is ON, morph only one thread at a time. -int color_fade = AM_NONE; // Color interpolation method. -int trajectory = AM_NONE; // Atom trajectory interpolation method. -bool median_combining = false; // Noise reduction method. FALSE for averaging. -bool stop_morphing = false; // To halt the morph time temporarily. -bool no_render = false; // When TRUE no blending is done, just atom morphing. - -ALLEGRO_DISPLAY *display = NULL; -ALLEGRO_EVENT_QUEUE *event_queue = NULL; -ALLEGRO_TIMER *timer = NULL; -ALLEGRO_FONT *font = NULL; -ALLEGRO_BITMAP *morph_bmp = NULL; // Holds the final morph as a bitmap. -ALLEGRO_BITMAP *thread_bmp[THREAD_N]; // Holds the results of the morphing threads. - -// Helper function to initially populate the AM_SCENE object according to the provided -// image file. -bool fill_scene(AM_SCENE *scene, size_t frame, const char *png_file) { - std::random_device rd; - std::default_random_engine re(rd()); - std::uniform_real_distribution uniform_dist(0.0, 1.0); - - ALLEGRO_BITMAP * bmp = al_load_bitmap(png_file); - int bmp_w = al_get_bitmap_width(bmp); - int bmp_h = al_get_bitmap_height(bmp); - - al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY); - - for (int j=0; jpush_atom(frame, am_create_atom(px,py,r,g,b,a)); - } - } - - al_unlock_bitmap(bmp); - al_destroy_bitmap(bmp); - return true; -} - -int main(int argc, char **argv) { - if (!init(argc, argv)) { - fprintf(stderr, "Failed to initialize!\n"); - return -1; - } - - std::random_device rd; - std::default_random_engine seed_engine(rd()); - std::uniform_int_distribution uniform_dist(1, std::numeric_limits::max()); - - morph_bmp = al_create_bitmap(MORPH_W, MORPH_H); - al_set_target_bitmap(morph_bmp); - al_clear_to_color(al_map_rgba(0,0,0,0)); - - AM_BLENDER blender; // Used to combine the thread results into the final morph. - blender.set_resolution(MORPH_W, MORPH_H); - blender.set_median_combining(median_combining); - blender.start(); - - AM_THREAD scene_thread[THREAD_N]; // Each of these will morph its own version of the animation. - AM_SCENE scene_buf [THREAD_N]; // Temporarily holds the last results of the morphing threads. - AM_IMAGE image_buf [THREAD_N]; // Used to render the final image of the provided scene. - - { - AM_SCENE scene; // Needed temporarily to store the raw input data. - - scene.init(ATOMS, 6); // Reserve 6 frames for this scene. - fill_scene(&scene, 0, "../tests/data/battlelord_1.png"); - fill_scene(&scene, 1, "../tests/data/battlelord_2.png"); - fill_scene(&scene, 2, "../tests/data/battlelord_3.png"); - fill_scene(&scene, 3, "../tests/data/battlelord_4.png"); - fill_scene(&scene, 4, "../tests/data/battlelord_5.png"); - fill_scene(&scene, 5, "../tests/data/battlelord_6.png"); - - for (size_t i=0; ipixel_count(); - for (size_t i=0; iget_xy(i, &x, &y); - img->get_rgba(i, &r, &g, &b, &a); - - al_put_pixel(x, y, al_map_rgba(r,g,b,a)); - } - - // Finally unlock the bitmap: - if (lock) al_unlock_bitmap(to); -} - -void blend_morphs(AM_BLENDER *blender, ALLEGRO_BITMAP *to) { - // Clear old bitmap: - al_set_target_bitmap(to); - al_set_blender(ALLEGRO_DEST_MINUS_SRC, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); - al_draw_filled_rectangle(0.0, 0.0, MORPH_W, MORPH_H, al_map_rgba(0,0,0,255)); - - // Prepare to render: - al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); - ALLEGRO_LOCKED_REGION * lock = al_lock_bitmap(to,ALLEGRO_PIXEL_FORMAT_ANY,ALLEGRO_LOCK_READWRITE); - if (lock == NULL) return; - - // Put the pixels: - size_t pixels = blender->pixel_count(); - for (size_t i=0; iget_xy(i, &x, &y); - blender->get_rgba(i, &r, &g, &b, &a); - - al_put_pixel(x, y, al_map_rgba(r,g,b,a)); - } - - // Finally unlock the bitmap: - if (lock) al_unlock_bitmap(to); -} - -bool init(int argc, char **argv) { - if (true == (am_get_warning()&AM_WARN_POINTER_SIZE)) { - fprintf(stderr, "Pointer size is insufficiently small.\n"); - } - if (true == (am_get_warning()&AM_WARN_ATOM_SIZE)) { - fprintf(stderr, "Atom size (%lu) is larger than optimal (%lu).\n", - sizeof(AM_ATOM), - sizeof(void *) - ); - } - - if(!al_init()) { - fprintf(stderr, "failed to initialize allegro!\n"); - return false; - } - - if(!al_install_keyboard()) { - fprintf(stderr, "failed to initialize the keyboard!\n"); - return false; - } - - al_install_mouse(); - al_init_image_addon(); - al_init_font_addon(); - al_init_primitives_addon(); - - timer = al_create_timer(1.0 / FPS); - if(!timer) { - fprintf(stderr, "failed to create timer!\n"); - return false; - } - - display = al_create_display(SCREEN_W, SCREEN_H); - if(!display) { - fprintf(stderr, "failed to create display!\n"); - al_destroy_timer(timer); - return false; - } - - al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR|ALLEGRO_MIN_LINEAR); - - font = al_load_font("data/fixed_font.tga", 0, 0); - if (font==NULL) { - fprintf(stderr, "failed to load font!\n"); - al_destroy_display(display); - al_destroy_timer(timer); - return false; - } - - al_set_target_bitmap(al_get_backbuffer(display)); - - event_queue = al_create_event_queue(); - if(!event_queue) { - fprintf(stderr, "failed to create event_queue!\n"); - al_destroy_display(display); - al_destroy_timer(timer); - al_destroy_font(font); - return false; - } - - al_register_event_source(event_queue, al_get_display_event_source(display)); - al_register_event_source(event_queue, al_get_timer_event_source(timer)); - al_register_event_source(event_queue, al_get_keyboard_event_source()); - al_register_event_source(event_queue, al_get_mouse_event_source()); - - al_clear_to_color(al_map_rgb(0,0,0)); - al_draw_textf(font, al_map_rgb(0,255,0), SCREEN_W/2, SCREEN_H/2, - ALLEGRO_ALIGN_CENTRE, - "LOADING..."); - - al_flip_display(); - - al_start_timer(timer); - calculate_fps(); - - return true; -} - -int round_int( double r ) { - return (r > 0.0) ? (r + 0.5) : (r - 0.5); -} - -int calculate_fps() { - static int times = 0; - static double old_time = 0.0; - static double delta_sum = 0.0; - static int old_fps = -1; - - static bool first = true; - if (first) { - first = false; - old_time = al_get_time(); - return -1; - } - - int rec_times = 0; - int max_times = round_int(FPS); - double new_time = al_get_time(); - double delta = new_time - old_time; - delta_sum += delta; - old_time = new_time; - double p = delta_sum * max_times; - rec_times = round_int(p); - - if (times > rec_times) { - return -1; - } - times++; - - int fps = 0; - if (delta_sum >= 1.0 || times>=max_times) { - fps = times; - old_fps = fps; - times=0; - delta_sum=0.0; - } - else { - if (old_fps == -1) fps = times; - else fps = old_fps; - } - - return fps; -} diff --git a/demo/allegro5/main.h b/demo/allegro5/main.h deleted file mode 100644 index 3836b3a..0000000 --- a/demo/allegro5/main.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * AtoMorph Demo - Simple Demo showing what AtoMorph is capable of doing. - * See Copyright Notice at the end of this file. - */ - -#include "../../atomorph.h" - -#include -#include -#include -#include -#include - -extern const float FPS; -extern const int SCREEN_W; -extern const int SCREEN_H; - -extern ALLEGRO_DISPLAY *display ; -extern ALLEGRO_EVENT_QUEUE *event_queue ; -extern ALLEGRO_TIMER *timer ; -extern ALLEGRO_FONT *font ; - -bool init(int argc, char **argv); -int calculate_fps(); -void draw(AM_SCENE *scene, ALLEGRO_BITMAP *to, double t, double weight); -void render_morph(AM_IMAGE *img, ALLEGRO_BITMAP *to); -void blend_morphs(AM_BLENDER *b, ALLEGRO_BITMAP *to); -/* -The MIT License (MIT) - -Copyright (c) 2013-2014 Erich Erstu - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ diff --git a/demo/allegro5/obj/.gitignore b/demo/allegro5/obj/.gitignore deleted file mode 100644 index 5e7d273..0000000 --- a/demo/allegro5/obj/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/atomorph.cpp b/src/atomorph.cpp similarity index 100% rename from atomorph.cpp rename to src/atomorph.cpp diff --git a/atomorph.h b/src/atomorph.h similarity index 99% rename from atomorph.h rename to src/atomorph.h index e7cbe05..89905aa 100644 --- a/atomorph.h +++ b/src/atomorph.h @@ -15,6 +15,7 @@ #include #include #include +#include #ifdef ATOMORPH_OPENCV #include diff --git a/color.cpp b/src/color.cpp similarity index 100% rename from color.cpp rename to src/color.cpp diff --git a/color.h b/src/color.h similarity index 97% rename from color.h rename to src/color.h index f235e12..d1b3ddd 100644 --- a/color.h +++ b/src/color.h @@ -1,7 +1,9 @@ /* * See Copyright Notice in atomorph.h */ - + +#include + namespace am { typedef struct color { diff --git a/fluidmodel.cpp b/src/fluidmodel.cpp similarity index 99% rename from fluidmodel.cpp rename to src/fluidmodel.cpp index 4c5a8a0..b6e5b7e 100644 --- a/fluidmodel.cpp +++ b/src/fluidmodel.cpp @@ -162,7 +162,7 @@ FluidModel::~FluidModel() { } -void FluidModel::step(size_t steps_left, double freedom_radius, double morph_time) { +void FluidModel::step(size_t steps_left, double freedom_radius, [[maybe_unused]]double morph_time) { bool drag = false; double mdx = 0.0, mdy = 0.0; diff --git a/fluidmodel.h b/src/fluidmodel.h similarity index 100% rename from fluidmodel.h rename to src/fluidmodel.h diff --git a/morph.cpp b/src/morph.cpp similarity index 100% rename from morph.cpp rename to src/morph.cpp diff --git a/morph.h b/src/morph.h similarity index 100% rename from morph.h rename to src/morph.h diff --git a/perlin.cpp b/src/perlin.cpp similarity index 100% rename from perlin.cpp rename to src/perlin.cpp diff --git a/perlin.h b/src/perlin.h similarity index 100% rename from perlin.h rename to src/perlin.h diff --git a/spline.cpp b/src/spline.cpp similarity index 100% rename from spline.cpp rename to src/spline.cpp diff --git a/spline.h b/src/spline.h similarity index 100% rename from spline.h rename to src/spline.h diff --git a/thread.cpp b/src/thread.cpp similarity index 100% rename from thread.cpp rename to src/thread.cpp diff --git a/thread.h b/src/thread.h similarity index 99% rename from thread.h rename to src/thread.h index a4d48c5..78862f0 100644 --- a/thread.h +++ b/src/thread.h @@ -1,7 +1,8 @@ /* * See Copyright Notice in atomorph.h - */ + */ +#include #include "atomorph.h" namespace am { diff --git a/vec3d.h b/src/vec3d.h similarity index 100% rename from vec3d.h rename to src/vec3d.h