From 71c054f0925f837d0d09b6c6bc4be11a38a735f7 Mon Sep 17 00:00:00 2001 From: jonny_jr9 Date: Fri, 10 Nov 2023 14:38:14 +0100 Subject: [PATCH] Add common.h with LOG macro, Add '#pragma once' - add conditional logging macro in common.h - add '#pragma once' to every header file - fix typo in food.h --- include/common.h | 24 ++++++++++++++++++++++++ include/config.h | 3 +++ include/food.h | 3 ++- include/game.h | 1 + include/input.h | 2 ++ include/menu.h | 2 ++ include/render.h | 3 +++ include/snake.h | 2 +- src/food.c | 2 +- src/map.c | 2 ++ 10 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 include/common.h diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..93a5590 --- /dev/null +++ b/include/common.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include "config.h" + +//=========================== +//========= LOGGING ========= +//=========================== +//conditional logging when DEBUG_OUTPUT_ENABLED is defined in config.h +//example: LOGD("game: %d", count) +#ifdef DEBUG_OUTPUT_ENABLED +#define LOGD(format, ...) printf(format, ##__VA_ARGS__) +#else +#define LOGD(format, ...) do {} while (0) +#endif + +//conditional logging when INFO_OUTPUT_ENABLED is defined in config.h +//example: LOGD("game: %d", count) +#ifdef INFO_OUTPUT_ENABLED +#define LOGI(format, ...) printf(format, ##__VA_ARGS__) +#else +#define LOGI(format, ...) do {} while (0) +#endif diff --git a/include/config.h b/include/config.h index 8c16e19..2fd58b0 100644 --- a/include/config.h +++ b/include/config.h @@ -3,6 +3,9 @@ // global configuration macros #define MAX_MAP_SIZE 10 #define MAX_MAP_FIELDS (MAX_MAP_SIZE*MAX_MAP_SIZE) +// logging settings +#define DEBUG_OUTPUT_ENABLED +#define INFO_OUTPUT_ENABLED // struct for storing game configuration typedef struct config_t diff --git a/include/food.h b/include/food.h index 7a0c56e..e3aed75 100644 --- a/include/food.h +++ b/include/food.h @@ -1,9 +1,10 @@ +#pragma once #include void placeFood(); // platziert zufällig (mit bestimmtem Algorithmus) Fressen auf dem Spielfeld // darf nicht auf der Schlange oder auf Wänden sein -bool ckeckEaten(); +bool checkEaten(); // Überprüft, ob Snake gefressen hat -> true wenn gefressen // Vergleich mit gameData_t foodX, foodY \ No newline at end of file diff --git a/include/game.h b/include/game.h index 2aaa19a..304c4b0 100644 --- a/include/game.h +++ b/include/game.h @@ -1,3 +1,4 @@ +#pragma once #include #include "snake.h" diff --git a/include/input.h b/include/input.h index 1fef448..0cb0eba 100644 --- a/include/input.h +++ b/include/input.h @@ -1,3 +1,5 @@ +#pragma once + void processInputEvent(); //wird von SDL aufgerufen, wenn Taste gedrückt wurde //bekommt Info darüber, welche Taste gedrückt wurde diff --git a/include/menu.h b/include/menu.h index 9f3f203..5514834 100644 --- a/include/menu.h +++ b/include/menu.h @@ -1,3 +1,5 @@ +#pragma once + void showStartScreen(); //zum Starten Enter drücken //optional: "E" eingeben für Settings diff --git a/include/render.h b/include/render.h index d75fefa..dfd0ba3 100644 --- a/include/render.h +++ b/include/render.h @@ -1,4 +1,7 @@ +#pragma once + #include "game.h" #include "snake.h" + void renderGame(); //erstellt aus Spielfeldstruktur die graphische Anzeige mit SDL-Framework \ No newline at end of file diff --git a/include/snake.h b/include/snake.h index b159b58..6f62e86 100644 --- a/include/snake.h +++ b/include/snake.h @@ -1,5 +1,5 @@ - #pragma once + #include #include "config.h" diff --git a/src/food.c b/src/food.c index b135693..3804d90 100644 --- a/src/food.c +++ b/src/food.c @@ -8,7 +8,7 @@ void placeFood(int count) } // Überprüft, ob Snake gefressen hat -bool ckeckEaten() +bool checkEaten() { return 0; } diff --git a/src/map.c b/src/map.c index cc4daac..52c5cce 100644 --- a/src/map.c +++ b/src/map.c @@ -1,5 +1,6 @@ #include "map.h" #include "game.h" +#include "common.h" // generate random map based on difficulty level map_t generateMap(int difficulty) @@ -12,6 +13,7 @@ map_t generateMap(int difficulty) // search and load map by name (if not found loads default map) void loadMapByName(char *name) { + LOGI("map: loading map %s", name); return; // TODO add map presets }