From 7f6507d30cf92bd3143db01a5191fc69a7498b8b Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Tue, 19 Dec 2017 19:42:05 +0100 Subject: [PATCH] Fixed for windows --- .gitignore | 2 ++ CMakeLists.txt | 5 ++++- src/defines.h | 2 ++ src/hashtable.c | 10 +++++----- src/player.c | 33 ++++++++++++++++----------------- src/roommatrix.c | 3 +++ src/screenresolution.c | 8 ++++++++ src/stats.h | 2 +- src/texture.c | 2 ++ src/util.c | 7 +++++-- 10 files changed, 48 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index a7b383e..5efd782 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /build/ /tags +/.vs/ *.swp +*~ diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ba97e6..57eb9b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,10 @@ include(cmake/FindSDL2.cmake) include(cmake/FindSDL2_image.cmake) include(cmake/FindSDL2_mixer.cmake) include(cmake/FindSDL2_ttf.cmake) -include(cmake/FindCheck.cmake) + +if (NOT WIN32) + include(cmake/FindCheck.cmake) +endif (NOT WIN32) include_directories( ${LUA_INCLUDE_DIR} diff --git a/src/defines.h b/src/defines.h index c9f975f..a9c760a 100644 --- a/src/defines.h +++ b/src/defines.h @@ -1,6 +1,8 @@ #ifndef DEFINES_H_ #define DEFINES_H_ +#define WINDOWS 0 + /* Room/Map dimensions */ #define MAP_ROOM_WIDTH 16 #define MAP_ROOM_HEIGHT 12 diff --git a/src/hashtable.c b/src/hashtable.c index b8f49b8..1ca7524 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -57,7 +57,7 @@ entry_create(const char *key, void *value) Entry *entry; entry = ec_malloc(sizeof(Entry)); - entry->key = strdup(key); + entry->key = _strdup(key); entry->value = value; entry->next = NULL; @@ -68,9 +68,9 @@ void ht_set(Hashtable *table, const char *key, void *val) { int hashkey = 0; - Entry *newEntry; - Entry *next; - Entry *last; + Entry *newEntry = NULL; + Entry *next = NULL; + Entry *last = NULL; hashkey = hash(table, key); @@ -93,7 +93,7 @@ ht_set(Hashtable *table, const char *key, void *val) /* New entry */ newEntry = entry_create(key, val); - if (next == table->entries[hashkey]) { + if (next == table->entries[hashkey] && last == NULL) { table->entries[hashkey] = newEntry; newEntry->next = next; } else if(next == NULL) { diff --git a/src/player.c b/src/player.c index ccf42a7..8a337bb 100644 --- a/src/player.c +++ b/src/player.c @@ -1,14 +1,13 @@ #include +#include #include "player.h" #include "monster.h" -static Stats classStats[] = { - (Stats) { 11, 5, 7, 2, 1, 1 }, /* ENGINEER */ - (Stats) { 11, 5, 7, 2, 1, 1 }, /* MAGE */ - (Stats) { 11, 5, 7, 2, 1, 1 }, /* PALADIN */ - (Stats) { 11, 5, 7, 2, 2, 1 }, /* ROGUE */ - (Stats) { 11, 5, 7, 2, 1, 1 }, /* WARRIOR */ -}; +#define ENGINEER_STATS { 11, 5, 7, 2, 1, 1 } +#define MAGE_STATS { 11, 5, 7, 2, 1, 1 } +#define PALADIN_STATS { 11, 5, 7, 2, 1, 1 } +#define ROGUE_STATS { 11, 5, 7, 2, 2, 1 } +#define WARRIOR_STATS { 11, 5, 7, 2, 1, 1 } static bool has_collided(Player *player, RoomMatrix *matrix) @@ -153,24 +152,24 @@ player_create(class_t class, SDL_Renderer *renderer) char asset[100]; switch (class) { case ENGINEER: - strcpy(asset, "assets/Commissions/Engineer.png"); - player->stats = classStats[ENGINEER]; + strcpy_s(asset, 100, "assets/Commissions/Engineer.png"); + player->stats = (Stats) ENGINEER_STATS; break; case MAGE: - strcpy(asset, "assets/Commissions/Mage.png"); - player->stats = classStats[MAGE]; + strcpy_s(asset, 100, "assets/Commissions/Mage.png"); + player->stats = (Stats) MAGE_STATS; break; case PALADIN: - strcpy(asset, "assets/Commissions/Paladin.png"); - player->stats = classStats[PALADIN]; + strcpy_s(asset, 100, "assets/Commissions/Paladin.png"); + player->stats = (Stats) PALADIN_STATS; break; case ROGUE: - strcpy(asset, "assets/Commissions/Rogue.png"); - player->stats = classStats[ROGUE]; + strcpy_s(asset, 100, "assets/Commissions/Rogue.png"); + player->stats = (Stats) ROGUE_STATS; break; case WARRIOR: - strcpy(asset, "assets/Commissions/Warrior.png"); - player->stats = classStats[WARRIOR]; + strcpy_s(asset, 100, "assets/Commissions/Warrior.png"); + player->stats = (Stats) WARRIOR_STATS; break; } diff --git a/src/roommatrix.c b/src/roommatrix.c index 157c606..3a19e2e 100644 --- a/src/roommatrix.c +++ b/src/roommatrix.c @@ -1,4 +1,5 @@ #include +#include "defines.h" #include "roommatrix.h" #include "util.h" #include "map.h" @@ -61,6 +62,7 @@ void roommatrix_populate_from_map(RoomMatrix *rm, Map *m) } } +#ifndef WINDOWS static int min(int a, int b) { @@ -72,6 +74,7 @@ max(int a, int b) { return a > b ? a : b; } +#endif void roommatrix_update_with_player(RoomMatrix *rm, Player *p) diff --git a/src/screenresolution.c b/src/screenresolution.c index a30e0db..1f222b3 100644 --- a/src/screenresolution.c +++ b/src/screenresolution.c @@ -1,16 +1,24 @@ +#include "defines.h" + +#ifndef WINDOWS #include +#endif #include #include "screenresolution.h" Dimension getScreenDimensions() { +#ifndef WINDOWS Display *d = XOpenDisplay(NULL); Screen *s = DefaultScreenOfDisplay(d); Dimension dim = (Dimension) { s->width, s->height }; free(d); free(s); +#else + Dimension dim = (Dimension) { 1920, 1080 }; +#endif return dim; } diff --git a/src/stats.h b/src/stats.h index d846721..35d89ba 100644 --- a/src/stats.h +++ b/src/stats.h @@ -1,7 +1,7 @@ #ifndef STATS_H_ #define STATS_H_ -typedef struct { +typedef struct Stats_t { int hp; /* Hit points */ int dmg; /* Damage modifier */ int atk; /* Attack rating */ diff --git a/src/texture.c b/src/texture.c index 14e1dee..51ca2fa 100644 --- a/src/texture.c +++ b/src/texture.c @@ -1,4 +1,6 @@ #include +#include +#include #include "texture.h" #include "util.h" diff --git a/src/util.c b/src/util.c index ddb6ba6..4d186b2 100644 --- a/src/util.c +++ b/src/util.c @@ -1,6 +1,9 @@ +#include "defines.h" #include #include +#ifndef WINDOWS #include +#endif #include #include "util.h" @@ -9,8 +12,8 @@ void fatal(char *message) { char error_message[100]; - strcpy(error_message, "[!!] Fatal Error "); - strncat(error_message, message, 83); + strcpy_s(error_message, 100, "[!!] Fatal Error "); + strncat_s(error_message, 100, message, 83); perror(error_message); exit(-1); }