From b487caeae35e4e6916ed0d3b3c3f6031e231a6b7 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Tue, 23 Mar 2021 23:23:43 +0100 Subject: [PATCH] Fork and separation of tile picker and level editor. --- CMakeLists.txt | 6 ++-- include/conf.h | 4 +-- include/{ => editing_area}/draw.h | 0 include/{ => editing_area}/level.h | 0 include/editing_area/main.h | 5 +++ include/tile_picker/main.h | 5 +++ src/{ => editing_area}/draw.c | 2 +- src/{ => editing_area}/level.c | 2 +- src/editing_area/main.c | 54 ++++++++++++++++++++++++++++ src/main.c | 58 +++++++++--------------------- src/tile_picker/main.c | 12 +++++++ 11 files changed, 100 insertions(+), 48 deletions(-) rename include/{ => editing_area}/draw.h (100%) rename include/{ => editing_area}/level.h (100%) create mode 100644 include/editing_area/main.h create mode 100644 include/tile_picker/main.h rename src/{ => editing_area}/draw.c (95%) rename src/{ => editing_area}/level.c (99%) create mode 100644 src/editing_area/main.c create mode 100644 src/tile_picker/main.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7720b22..1b0ef96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,10 @@ include_directories(include) set(SOURCES src/main.c - src/level.c - src/draw.c + src/editing_area/main.c + src/editing_area/level.c + src/editing_area/draw.c + src/tile_picker/main.c ) set(FLAGS diff --git a/include/conf.h b/include/conf.h index e8631fb..b5e9970 100644 --- a/include/conf.h +++ b/include/conf.h @@ -2,8 +2,8 @@ /* Copyright (C) 2021 KikooDX */ #pragma once -static const int window_width = 396; -static const int window_height = 224; +static const int game_window_width = 396; +static const int game_window_height = 224; static const int draw_offset_x = -2; static const int draw_offset_y = -8; static const int tile_width = 16; diff --git a/include/draw.h b/include/editing_area/draw.h similarity index 100% rename from include/draw.h rename to include/editing_area/draw.h diff --git a/include/level.h b/include/editing_area/level.h similarity index 100% rename from include/level.h rename to include/editing_area/level.h diff --git a/include/editing_area/main.h b/include/editing_area/main.h new file mode 100644 index 0000000..c1d85eb --- /dev/null +++ b/include/editing_area/main.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* Copyright (C) 2021 KikooDX */ +#pragma once + +int editing_area_main(int argc, char **argv); diff --git a/include/tile_picker/main.h b/include/tile_picker/main.h new file mode 100644 index 0000000..eb5623d --- /dev/null +++ b/include/tile_picker/main.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* Copyright (C) 2021 KikooDX */ +#pragma once + +int tile_picker_main(int argc, char **argv); diff --git a/src/draw.c b/src/editing_area/draw.c similarity index 95% rename from src/draw.c rename to src/editing_area/draw.c index e818fe3..1c9f5bd 100644 --- a/src/draw.c +++ b/src/editing_area/draw.c @@ -2,7 +2,7 @@ /* Copyright (C) 2021 KikooDX */ #include "conf.h" -#include "level.h" +#include "editing_area/level.h" #include #include diff --git a/src/level.c b/src/editing_area/level.c similarity index 99% rename from src/level.c rename to src/editing_area/level.c index 98c6c6b..8c4bb75 100644 --- a/src/level.c +++ b/src/editing_area/level.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ /* Copyright (C) 2021 KikooDX */ -#include "level.h" +#include "editing_area/level.h" #include #include #include diff --git a/src/editing_area/main.c b/src/editing_area/main.c new file mode 100644 index 0000000..97f054e --- /dev/null +++ b/src/editing_area/main.c @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* Copyright (C) 2021 KikooDX */ + +#include "conf.h" +#include "editing_area/draw.h" +#include "editing_area/level.h" +#include +#include +#include +#include + +int editing_area_main(int argc, char **argv) +{ + struct Level level; + level.data = NULL; + + /* check for argument count */ + if (argc != 3) { + fprintf(stderr, "ERROR: expected 2 arguments, got %d\n", + argc - 1); + return EXIT_FAILURE; + }; + + /* initialize raylib */ + InitWindow(game_window_width, game_window_height, + "SLE main window"); + SetTargetFPS(target_fps); + /* load textures */ + const Texture2D tileset = LoadTexture(argv[1]); + assert(tileset.width > 0); + + /* load level */ + level_read(&level, argv[2]); + + while (!WindowShouldClose()) { + /* draw */ + BeginDrawing(); + + ClearBackground(BLACK); + level_draw(level, tileset); + + EndDrawing(); + } + + /* save level */ + level_write(level, argv[2]); + + /* deinit */ + level_free(&level); + + CloseWindow(); + + return EXIT_SUCCESS; +} diff --git a/src/main.c b/src/main.c index e89a4e3..55c5c58 100644 --- a/src/main.c +++ b/src/main.c @@ -1,53 +1,27 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ /* Copyright (C) 2021 KikooDX */ -#include "conf.h" -#include "draw.h" -#include "level.h" -#include -#include +#include "editing_area/main.h" +#include "tile_picker/main.h" #include #include +#include +#include +/* The editor fork to create two windows. One will be the level editor + * and the other the tile selection. This is done to allow the user to + * organize these panels in the way they want to. */ int main(int argc, char **argv) { - struct Level level; - level.data = NULL; + pid_t child_process = fork(); - /* check for argument count */ - if (argc != 3) { - fprintf(stderr, "ERROR: expected 2 arguments, got %d\n", - argc - 1); + if (child_process < 0) { + fprintf(stderr, "ERROR: process couldn't fork"); return EXIT_FAILURE; - }; - - /* initialize raylib */ - InitWindow(window_width, window_height, "SLE"); - SetTargetFPS(target_fps); - /* load textures */ - const Texture2D tileset = LoadTexture(argv[1]); - assert(tileset.width > 0); - - /* load level */ - level_read(&level, argv[2]); - - while (!WindowShouldClose()) { - /* draw */ - BeginDrawing(); - - ClearBackground(BLACK); - level_draw(level, tileset); - - EndDrawing(); - } - - /* save level */ - level_write(level, argv[2]); - - /* deinit */ - level_free(&level); - - CloseWindow(); - - return EXIT_SUCCESS; + } else if (child_process == 0) + /* child process, start the tile picker */ + return tile_picker_main(argc, argv); + else + /* main process, start the editing area */ + return editing_area_main(argc, argv); } diff --git a/src/tile_picker/main.c b/src/tile_picker/main.c new file mode 100644 index 0000000..2ec875d --- /dev/null +++ b/src/tile_picker/main.c @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* Copyright (C) 2021 KikooDX */ + +#include "editing_area/main.h" +#include +#include + +int tile_picker_main(int argc, char **argv) +{ + printf("hello you :)\n"); + return EXIT_SUCCESS; +}