M CMakeLists.txt => CMakeLists.txt +22 -5
@@ 1,5 1,6 @@
cmake_minimum_required(VERSION 3.18)
-project(kblec C)
+# Add render targets here.
+project(kble C)
include_directories(include)
@@ 8,10 9,26 @@ set(SOURCES
src/level.c
)
-add_executable(${PROJECT_NAME} ${SOURCES})
-target_compile_options(${PROJECT_NAME} PRIVATE
+set(SOURCES_NCURSES
+ src/ncurses/init.c
+)
+
+set(SOURCES_RAYLIB
+ src/raylib/init.c
+)
+
+set(FLAGS
-Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum
-Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes
-Wold-style-definition -Werror-implicit-function-declaration
- -ansi -pedantic-errors -g -Os)
-#target_link_libraries(${PROJECT_NAME} raylib)
+ -g -Os
+)
+
+add_executable(kble-ncurses ${SOURCES} ${SOURCES_NCURSES})
+add_executable(kble-raylib ${SOURCES} ${SOURCES_RAYLIB})
+
+target_compile_options(kble-ncurses PRIVATE ${FLAGS} -DNCURSES)
+target_compile_options(kble-raylib PRIVATE ${FLAGS} -DRAYLIB)
+
+target_link_libraries(kble-ncurses ncurses)
+target_link_libraries(kble-raylib raylib)
A include/conf.h => include/conf.h +7 -0
@@ 0,0 1,7 @@
+#pragma once
+
+#if defined(RAYLIB)
+# define WINDOW_WIDTH 640
+# define WINDOW_HEIGHT 480
+# define TARGET_FPS 60
+#endif
A include/renderer/init.h => include/renderer/init.h +6 -0
@@ 0,0 1,6 @@
+#pragma once
+
+/* Initialize renderer. */
+void renderer_init(void);
+/* Deinitialize renderer. */
+void renderer_deinit(void);
M src/main.c => src/main.c +4 -0
@@ 5,6 5,7 @@
#include <stdlib.h>
#include "level.h"
+#include "renderer/init.h"
int main(int argc, char **argv) {
struct Level level;
@@ 16,8 17,11 @@ int main(int argc, char **argv) {
}
level_read(&level, argv[1]);
+ renderer_init();
+
level_write(level, argv[2]);
level_free(&level);
+ renderer_deinit();
return EXIT_SUCCESS;
}
A src/ncurses/init.c => src/ncurses/init.c +21 -0
@@ 0,0 1,21 @@
+#include <locale.h>
+#include <ncurses.h>
+#include <unistd.h>
+
+#include "renderer/init.h"
+
+void renderer_init(void) {
+ setlocale(LC_ALL, "");
+
+ initscr();
+ cbreak();
+ noecho();
+ nonl();
+ intrflush(stdscr, FALSE);
+ keypad(stdscr, TRUE);
+ curs_set(TRUE);
+}
+
+void renderer_deinit(void) {
+ endwin();
+}
A src/raylib/init.c => src/raylib/init.c +14 -0
@@ 0,0 1,14 @@
+#include <raylib.h>
+
+#include "conf.h"
+
+#include "renderer/init.h"
+
+void renderer_init(void) {
+ InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "KBLE");
+ SetTargetFPS(TARGET_FPS);
+}
+
+void renderer_deinit(void) {
+ CloseWindow();
+}