diff --git a/.gitignore b/.gitignore index f70a192..4077cd4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -build/ +builddir/ # KBLE (Zig) files backup_*.kble diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 709e154..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -cmake_minimum_required(VERSION 3.18) - -project(sle C) - -include_directories(include) - -set(SOURCES - src/main.c - src/options.c - src/mouse.c - src/scale.c - src/strtoint.c - src/strtocolor.c - src/editing_area/main.c - src/editing_area/level.c - src/editing_area/draw.c - src/tile_picker/main.c - src/tile_picker/draw.c -) - -set(FLAGS - -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum - -Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes - -Wold-style-definition -Werror-implicit-function-declaration - -Wformat-pedantic - -Werror -pedantic -std=c90 - -Os) - -add_executable(${PROJECT_NAME} ${SOURCES} ${SOURCES_RAYLIB}) - -add_compile_options(PRIVATE ${FLAGS}) - -target_link_libraries(${PROJECT_NAME} raylib) diff --git a/README b/README index 29a6643..7038573 100644 --- a/README +++ b/README @@ -8,18 +8,21 @@ KBLE format specifications: COMPILATION =========== -Dependencies: raylib +Runtime dependencies: raylib +Build dependencies: meson, raylib -$ git clone https://git.sr.ht/~kikoodx/sle -$ mkdir sle/build && cd sle/build -$ cmake .. -$ make +$ git clone https://git.sr.ht/~kikoodx/sle && cd sle +$ meson setup builddir && cd builddir +$ meson compile + +The following will install the resulting `sle` binary on your system. +# meson install RUN === $ -tileset -level Example: -$ build/sle -tileset assets/tileset.png -level sample.kble +$ sle -tileset assets/tileset.png -level sample.kble SYNOPSIS ======== diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..9b27f80 --- /dev/null +++ b/meson.build @@ -0,0 +1,44 @@ +project('sle', 'c', + version : '0.4.0', + license : 'GPL-3.0-or-later') +raylibdep = dependency('raylib', version: '>=3.5.0') + +inc = include_directories('include') + +sources = [ + 'src/main.c', + 'src/main.c', + 'src/mouse.c', + 'src/options.c', + 'src/scale.c', + 'src/strtocolor.c', + 'src/strtoint.c', + 'src/editing_area/draw.c', + 'src/editing_area/level.c', + 'src/editing_area/main.c', + 'src/tile_picker/draw.c', + 'src/tile_picker/main.c', +] + +c_flags = [ + '-std=c99', + '-Os', + '-Wall', + '-Wextra', + '-pedantic', + '-Wshadow', + '-Wswitch-default', + '-Wswitch-enum', + '-Wunreachable-code', + '-Wstrict-prototypes', + '-Wmissing-prototypes', + '-Wold-style-definition', + '-Werror-implicit-function-declaration', +] + +executable('sle', + sources, + include_directories : inc, + dependencies : raylibdep, + install : true, + c_args : c_flags) diff --git a/src/editing_area/draw.c b/src/editing_area/draw.c index 019c8ac..cbb28d8 100644 --- a/src/editing_area/draw.c +++ b/src/editing_area/draw.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ /* Copyright (C) 2021 KikooDX */ +#include "editing_area/draw.h" #include "conf.h" #include "editing_area/level.h" #include "options.h" @@ -21,9 +22,8 @@ void level_draw(struct Level level, struct Options options, const Tile tile = level.data[tile_index] - options.tile_first; /* if tile is not in tileset, skip */ - if (tile < 0 || - (!tile && !options.tile_first) || - tile >= options.tileset_width * + if ((!tile && !options.tile_first) || + tile >= (Tile)options.tileset_width * options.tileset_height) continue; diff --git a/src/editing_area/level.c b/src/editing_area/level.c index f02f30d..3f1276f 100644 --- a/src/editing_area/level.c +++ b/src/editing_area/level.c @@ -18,6 +18,7 @@ static int write_byte_group(FILE *file, Tile value, int size); int level_read(struct Level *level, char *path) { FILE *file = NULL; + int byte_hold = 0; unsigned char byte = 0; unsigned int tile_size = 0; int level_size = 0; @@ -43,9 +44,10 @@ int level_read(struct Level *level, char *path) } /* get tile size (in bytes) */ - tile_size = read_byte(file); - if (tile_size < 0) + byte_hold = read_byte(file); + if (byte_hold < 0) return -1; + tile_size = (unsigned int)byte_hold; /* check than tile size is in boundaries */ if (tile_size > sizeof(Tile) / sizeof(char)) { fprintf(stderr, @@ -56,11 +58,11 @@ int level_read(struct Level *level, char *path) } /* get width */ level->width = read_byte_group(file, 2); - if (level->width == (Tile)-1) + if ((Tile)level->width == (Tile)-1) return -1; /* get height */ level->height = read_byte_group(file, 2); - if (level->height == (Tile)-1) + if ((Tile)level->height == (Tile)-1) return -1; /* allocate memory for data */ @@ -96,11 +98,11 @@ int level_create(struct Level *level, struct Options options) /* set width */ level->width = options.new_level_width; - if (level->width == (Tile)-1) + if ((Tile)level->width == (Tile)-1) return -1; /* set height */ level->height = options.new_level_height; - if (level->height == (Tile)-1) + if ((Tile)level->height == (Tile)-1) return -1; /* allocate memory for data */ diff --git a/src/editing_area/main.c b/src/editing_area/main.c index c58e20f..8988af3 100644 --- a/src/editing_area/main.c +++ b/src/editing_area/main.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ /* Copyright (C) 2021 KikooDX */ +#include "editing_area/main.h" #include "conf.h" #include "editing_area/draw.h" #include "editing_area/level.h" @@ -24,7 +25,6 @@ int editing_area_main(struct Options options, { int mouse_x; int mouse_y; - int error; struct Level level; level.data = NULL; Texture2D tileset; diff --git a/src/main.c b/src/main.c index 72577a7..d23aaa7 100644 --- a/src/main.c +++ b/src/main.c @@ -32,7 +32,6 @@ static void set_tileset_dimensions(struct Options *options); * organize these panels in the way they want to. */ int main(int argc, char **argv) { - int error; pid_t child_process; struct SharedData *shared_data; struct Options options = options_defaults(); diff --git a/src/tile_picker/main.c b/src/tile_picker/main.c index 6fb3199..4ca5f5f 100644 --- a/src/tile_picker/main.c +++ b/src/tile_picker/main.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ /* Copyright (C) 2021 KikooDX */ +#include "tile_picker/main.h" #include "conf.h" #include "mouse.h" #include "options.h" @@ -97,7 +98,7 @@ static void update_mouse(int *mouse_x, int *mouse_y, struct SharedData *shared_data) { const bool left_click = IsMouseButtonDown(0); - const bool right_click = IsMouseButtonDown(1); + /* const bool right_click = IsMouseButtonDown(1); */ update_mouse_position( mouse_x, mouse_y,