~kikoodx/kble-c

c559481af99c181d3f5565bf6b13d897104278e3 — KikooDX 3 years ago 933ee23
Build with raylib of ncurses. Not sure about this.

This seems like a big overhead. I think I will focus on one target and
keep the possibility to work on another later.
6 files changed, 74 insertions(+), 5 deletions(-)

M CMakeLists.txt
A include/conf.h
A include/renderer/init.h
M src/main.c
A src/ncurses/init.c
A src/raylib/init.c
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();
}