replace cmake with meson & use C99 instead of C89

This commit also takes care of all the warnings that didn't appear
with CMake. I decided to switch to C99 cause my code clearly wasn't
C89 compliant.
This commit is contained in:
KikooDX 2021-05-04 19:52:23 +02:00
parent 5727f19fb9
commit 53132075b8
9 changed files with 68 additions and 52 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
build/
builddir/
# KBLE (Zig) files
backup_*.kble

View File

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

15
README
View File

@ -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
===
$ <SLE binary path> -tileset <tileset> -level <KBLE level to open>
Example:
$ build/sle -tileset assets/tileset.png -level sample.kble
$ sle -tileset assets/tileset.png -level sample.kble
SYNOPSIS
========

44
meson.build Normal file
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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