From 4bbe82a70561eaef94e5873f35b61dbbc9ec3e43 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Tue, 19 Dec 2017 22:51:00 +0100 Subject: [PATCH] More windows stuff --- CMakeLists.txt | 4 +++- src/actiontext.h | 1 + src/hashtable.c | 2 +- src/linkedlist.c | 2 +- src/map.c | 2 +- src/map_lua.c | 28 ++++++++++++++-------------- src/player.c | 10 +++++----- src/random.c | 2 +- src/roommatrix.c | 4 ++-- src/screenresolution.c | 10 +++++----- src/sprite.c | 3 ++- src/stats.c | 1 + src/util.c | 10 +++++----- src/util.h | 7 ++----- 14 files changed, 44 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93b43a8..748e52b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,9 @@ if (NOT WIN32) ) endif (NOT WIN32) -add_definitions("-std=gnu11 -pedantic -Wall -Wextra -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes") +if (NOT WIN32) + add_definitions("-std=gnu11 -pedantic -Wall -Wextra -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes") +endif (NOT WIN32) # PROGRAMS: add_executable(breakhack diff --git a/src/actiontext.h b/src/actiontext.h index 2bfc9f6..eb94f8d 100644 --- a/src/actiontext.h +++ b/src/actiontext.h @@ -2,6 +2,7 @@ #define ACTIONTEXT_H_ #include +#include #include "position.h" #include "texture.h" diff --git a/src/hashtable.c b/src/hashtable.c index 9171dd0..0a11e60 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -94,7 +94,7 @@ ht_set(Hashtable *table, const char *key, void *val) /* New entry */ newEntry = entry_create(key, val); - if (next == table->entries[hashkey] && last == NULL) { + if (next == table->entries[hashkey]) { table->entries[hashkey] = newEntry; newEntry->next = next; } else if(next == NULL) { diff --git a/src/linkedlist.c b/src/linkedlist.c index 4084ba2..fec32f3 100644 --- a/src/linkedlist.c +++ b/src/linkedlist.c @@ -23,7 +23,7 @@ LinkedList* linkedlist_node_create(void) return newList; } -LinkedList* linkedlist_create() +LinkedList* linkedlist_create(void) { return NULL; } diff --git a/src/map.c b/src/map.c index 4c8ba4b..0cffd4e 100644 --- a/src/map.c +++ b/src/map.c @@ -199,7 +199,7 @@ void map_render(Map *map, Camera *cam) } monsterItem = map->monsters; - while (monsterItem) { + while (monsterItem != NULL) { Monster *monster = monsterItem->data; monsterItem = monsterItem->next; monster_render(monster, cam); diff --git a/src/map_lua.c b/src/map_lua.c index d24d6e0..13d5262 100644 --- a/src/map_lua.c +++ b/src/map_lua.c @@ -62,8 +62,8 @@ int l_map_set_current_room(lua_State *L) unsigned int room_x, room_y; map = luaL_checkmap(L, 1); - room_x = luaL_checkinteger(L, 2); - room_y = luaL_checkinteger(L, 3); + room_x = (int) luaL_checkinteger(L, 2); + room_y = (int) luaL_checkinteger(L, 3); map->currentRoom = (Position) { room_x, room_y }; @@ -96,8 +96,8 @@ extract_tile_data(lua_State *L, bool collider, lightsource; map = luaL_checkmap(L, 1); - tile_x = luaL_checkinteger(L, 2); - tile_y = luaL_checkinteger(L, 3); + tile_x = (int) luaL_checkinteger(L, 2); + tile_y = (int) luaL_checkinteger(L, 3); // Read the table lua_settop(L, 4); @@ -111,10 +111,10 @@ extract_tile_data(lua_State *L, lua_getfield(L, 4, "isCollider"); lua_getfield(L, 4, "isLightSource"); - t_index0 = luaL_checkinteger(L, -6); - t_index1 = luaL_checkinteger(L, -5); - tile_clip_x = luaL_checkinteger(L, -4); - tile_clip_y = luaL_checkinteger(L, -3); + t_index0 = (int) luaL_checkinteger(L, -6); + t_index1 = (int) luaL_checkinteger(L, -5); + tile_clip_x = (int) luaL_checkinteger(L, -4); + tile_clip_y = (int) luaL_checkinteger(L, -3); collider = lua_toboolean(L, -2); lightsource = lua_toboolean(L, -1); @@ -156,8 +156,8 @@ l_add_monster(lua_State *L) renderer = luaL_checksdlrenderer(L); map = luaL_checkmap(L, 1); - x = luaL_checkinteger(L, 2); - y = luaL_checkinteger(L, 3); + x = (int) luaL_checkinteger(L, 2); + y = (int) luaL_checkinteger(L, 3); // Read the table lua_settop(L, 4); @@ -172,10 +172,10 @@ l_add_monster(lua_State *L) texture_path_1 = luaL_checkstring(L, -6); texture_path_2 = luaL_checkstring(L, -5); - clip_x = luaL_checkinteger(L, -4); - clip_y = luaL_checkinteger(L, -3); - nstate = luaL_checkinteger(L, -2); - cstate = luaL_checkinteger(L, -1); + clip_x = (int) luaL_checkinteger(L, -4); + clip_y = (int) luaL_checkinteger(L, -3); + nstate = (int) luaL_checkinteger(L, -2); + cstate = (int) luaL_checkinteger(L, -1); texture1 = map_add_monster_texture(map, texture_path_1, renderer); texture2 = map_add_monster_texture(map, texture_path_2, renderer); diff --git a/src/player.c b/src/player.c index 4426596..29a25ec 100644 --- a/src/player.c +++ b/src/player.c @@ -155,23 +155,23 @@ player_create(class_t class, SDL_Renderer *renderer) char asset[100]; switch (class) { case ENGINEER: - _strcpy(asset, 100, "assets/Commissions/Engineer.png"); + m_strcpy(asset, 100, "assets/Commissions/Engineer.png"); player->stats = (Stats) ENGINEER_STATS; break; case MAGE: - _strcpy(asset, 100, "assets/Commissions/Mage.png"); + m_strcpy(asset, 100, "assets/Commissions/Mage.png"); player->stats = (Stats) MAGE_STATS; break; case PALADIN: - _strcpy(asset, 100, "assets/Commissions/Paladin.png"); + m_strcpy(asset, 100, "assets/Commissions/Paladin.png"); player->stats = (Stats) PALADIN_STATS; break; case ROGUE: - _strcpy(asset, 100, "assets/Commissions/Rogue.png"); + m_strcpy(asset, 100, "assets/Commissions/Rogue.png"); player->stats = (Stats) ROGUE_STATS; break; case WARRIOR: - _strcpy(asset, 100, "assets/Commissions/Warrior.png"); + m_strcpy(asset, 100, "assets/Commissions/Warrior.png"); player->stats = (Stats) WARRIOR_STATS; break; } diff --git a/src/random.c b/src/random.c index af0bff9..234a4bc 100644 --- a/src/random.c +++ b/src/random.c @@ -8,7 +8,7 @@ get_random(unsigned int max) { static bool seeded = false; if (!seeded) { - srand(time(NULL)); + srand((unsigned int) time(NULL)); seeded = true; } diff --git a/src/roommatrix.c b/src/roommatrix.c index 3a19e2e..301884d 100644 --- a/src/roommatrix.c +++ b/src/roommatrix.c @@ -62,7 +62,7 @@ void roommatrix_populate_from_map(RoomMatrix *rm, Map *m) } } -#ifndef WINDOWS +#ifndef _WIN32 static int min(int a, int b) { @@ -74,7 +74,7 @@ max(int a, int b) { return a > b ? a : b; } -#endif +#endif // _WIN32 void roommatrix_update_with_player(RoomMatrix *rm, Player *p) diff --git a/src/screenresolution.c b/src/screenresolution.c index 84af914..1071308 100644 --- a/src/screenresolution.c +++ b/src/screenresolution.c @@ -1,24 +1,24 @@ #include "defines.h" -#ifndef WINDOWS +#ifndef _WIN32 #include -#endif +#endif // _WIN32 #include #include "screenresolution.h" Dimension getScreenDimensions(void) { -#ifndef WINDOWS +#ifndef _WIN32 Display *d = XOpenDisplay(NULL); Screen *s = DefaultScreenOfDisplay(d); Dimension dim = (Dimension) { s->width, s->height }; free(d); free(s); -#else +#else // _WIN32 Dimension dim = (Dimension) { 1920, 1080 }; -#endif +#endif // _WIN32 return dim; } diff --git a/src/sprite.c b/src/sprite.c index be6bf93..840fff1 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -10,7 +10,8 @@ Sprite* sprite_create_default(void) *s = (Sprite) { { NULL, NULL }, (SDL_Rect) { 0, 0, 16, 16 }, - false, pos, + false, + pos, NULL, 0 }; diff --git a/src/stats.c b/src/stats.c index 66d40c7..07678c0 100644 --- a/src/stats.c +++ b/src/stats.c @@ -1,4 +1,5 @@ #include +#include #include #include diff --git a/src/util.c b/src/util.c index ac77f77..79f403e 100644 --- a/src/util.c +++ b/src/util.c @@ -9,7 +9,7 @@ #include "util.h" void -_strcpy(char *restrict dest, size_t destsz, char *restrict src) +m_strcpy(char *dest, size_t destsz, char *src) { #ifndef _WIN32 UNUSED(destsz); @@ -20,9 +20,9 @@ _strcpy(char *restrict dest, size_t destsz, char *restrict src) } void -_strncat(char *restrict dest, +m_strncat(char *dest, size_t destsz, - char *restrict src, + char *src, size_t srcsz) { #ifndef _WIN32 @@ -38,8 +38,8 @@ void fatal(char *message) { char error_message[100]; - _strcpy(error_message, 100, "[!!] Fatal Error "); - _strncat(error_message, 100, message, 83); + m_strcpy(error_message, 100, "[!!] Fatal Error "); + m_strncat(error_message, 100, message, 83); perror(error_message); exit(-1); } diff --git a/src/util.h b/src/util.h index 1c7ba30..dbb8982 100644 --- a/src/util.h +++ b/src/util.h @@ -5,12 +5,9 @@ void fatal(char *message); void *ec_malloc(unsigned int size); -void _strcpy(char *restrict dest, size_t destsz, char *restrict src); +void m_strcpy(char *dest, size_t destsz, char *src); void -_strncat(char *restrict dest, - size_t destsz, - char *restrict src, - size_t srcsz); +m_strncat(char *dest, size_t destsz, char *src, size_t srcsz); #endif // UTIL_H_