Fixed for windows

This commit is contained in:
Linus Probert 2017-12-19 19:42:05 +01:00
parent b269abd0f7
commit 7f6507d30c
10 changed files with 48 additions and 26 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
/build/ /build/
/tags /tags
/.vs/
*.swp *.swp
*~

View File

@ -10,7 +10,10 @@ include(cmake/FindSDL2.cmake)
include(cmake/FindSDL2_image.cmake) include(cmake/FindSDL2_image.cmake)
include(cmake/FindSDL2_mixer.cmake) include(cmake/FindSDL2_mixer.cmake)
include(cmake/FindSDL2_ttf.cmake) include(cmake/FindSDL2_ttf.cmake)
include(cmake/FindCheck.cmake)
if (NOT WIN32)
include(cmake/FindCheck.cmake)
endif (NOT WIN32)
include_directories( include_directories(
${LUA_INCLUDE_DIR} ${LUA_INCLUDE_DIR}

View File

@ -1,6 +1,8 @@
#ifndef DEFINES_H_ #ifndef DEFINES_H_
#define DEFINES_H_ #define DEFINES_H_
#define WINDOWS 0
/* Room/Map dimensions */ /* Room/Map dimensions */
#define MAP_ROOM_WIDTH 16 #define MAP_ROOM_WIDTH 16
#define MAP_ROOM_HEIGHT 12 #define MAP_ROOM_HEIGHT 12

View File

@ -57,7 +57,7 @@ entry_create(const char *key, void *value)
Entry *entry; Entry *entry;
entry = ec_malloc(sizeof(Entry)); entry = ec_malloc(sizeof(Entry));
entry->key = strdup(key); entry->key = _strdup(key);
entry->value = value; entry->value = value;
entry->next = NULL; entry->next = NULL;
@ -68,9 +68,9 @@ void
ht_set(Hashtable *table, const char *key, void *val) ht_set(Hashtable *table, const char *key, void *val)
{ {
int hashkey = 0; int hashkey = 0;
Entry *newEntry; Entry *newEntry = NULL;
Entry *next; Entry *next = NULL;
Entry *last; Entry *last = NULL;
hashkey = hash(table, key); hashkey = hash(table, key);
@ -93,7 +93,7 @@ ht_set(Hashtable *table, const char *key, void *val)
/* New entry */ /* New entry */
newEntry = entry_create(key, val); newEntry = entry_create(key, val);
if (next == table->entries[hashkey]) { if (next == table->entries[hashkey] && last == NULL) {
table->entries[hashkey] = newEntry; table->entries[hashkey] = newEntry;
newEntry->next = next; newEntry->next = next;
} else if(next == NULL) { } else if(next == NULL) {

View File

@ -1,14 +1,13 @@
#include <string.h> #include <string.h>
#include <stdio.h>
#include "player.h" #include "player.h"
#include "monster.h" #include "monster.h"
static Stats classStats[] = { #define ENGINEER_STATS { 11, 5, 7, 2, 1, 1 }
(Stats) { 11, 5, 7, 2, 1, 1 }, /* ENGINEER */ #define MAGE_STATS { 11, 5, 7, 2, 1, 1 }
(Stats) { 11, 5, 7, 2, 1, 1 }, /* MAGE */ #define PALADIN_STATS { 11, 5, 7, 2, 1, 1 }
(Stats) { 11, 5, 7, 2, 1, 1 }, /* PALADIN */ #define ROGUE_STATS { 11, 5, 7, 2, 2, 1 }
(Stats) { 11, 5, 7, 2, 2, 1 }, /* ROGUE */ #define WARRIOR_STATS { 11, 5, 7, 2, 1, 1 }
(Stats) { 11, 5, 7, 2, 1, 1 }, /* WARRIOR */
};
static bool static bool
has_collided(Player *player, RoomMatrix *matrix) has_collided(Player *player, RoomMatrix *matrix)
@ -153,24 +152,24 @@ player_create(class_t class, SDL_Renderer *renderer)
char asset[100]; char asset[100];
switch (class) { switch (class) {
case ENGINEER: case ENGINEER:
strcpy(asset, "assets/Commissions/Engineer.png"); strcpy_s(asset, 100, "assets/Commissions/Engineer.png");
player->stats = classStats[ENGINEER]; player->stats = (Stats) ENGINEER_STATS;
break; break;
case MAGE: case MAGE:
strcpy(asset, "assets/Commissions/Mage.png"); strcpy_s(asset, 100, "assets/Commissions/Mage.png");
player->stats = classStats[MAGE]; player->stats = (Stats) MAGE_STATS;
break; break;
case PALADIN: case PALADIN:
strcpy(asset, "assets/Commissions/Paladin.png"); strcpy_s(asset, 100, "assets/Commissions/Paladin.png");
player->stats = classStats[PALADIN]; player->stats = (Stats) PALADIN_STATS;
break; break;
case ROGUE: case ROGUE:
strcpy(asset, "assets/Commissions/Rogue.png"); strcpy_s(asset, 100, "assets/Commissions/Rogue.png");
player->stats = classStats[ROGUE]; player->stats = (Stats) ROGUE_STATS;
break; break;
case WARRIOR: case WARRIOR:
strcpy(asset, "assets/Commissions/Warrior.png"); strcpy_s(asset, 100, "assets/Commissions/Warrior.png");
player->stats = classStats[WARRIOR]; player->stats = (Stats) WARRIOR_STATS;
break; break;
} }

View File

@ -1,4 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include "defines.h"
#include "roommatrix.h" #include "roommatrix.h"
#include "util.h" #include "util.h"
#include "map.h" #include "map.h"
@ -61,6 +62,7 @@ void roommatrix_populate_from_map(RoomMatrix *rm, Map *m)
} }
} }
#ifndef WINDOWS
static int static int
min(int a, int b) min(int a, int b)
{ {
@ -72,6 +74,7 @@ max(int a, int b)
{ {
return a > b ? a : b; return a > b ? a : b;
} }
#endif
void void
roommatrix_update_with_player(RoomMatrix *rm, Player *p) roommatrix_update_with_player(RoomMatrix *rm, Player *p)

View File

@ -1,16 +1,24 @@
#include "defines.h"
#ifndef WINDOWS
#include <X11/Xlib.h> #include <X11/Xlib.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include "screenresolution.h" #include "screenresolution.h"
Dimension getScreenDimensions() Dimension getScreenDimensions()
{ {
#ifndef WINDOWS
Display *d = XOpenDisplay(NULL); Display *d = XOpenDisplay(NULL);
Screen *s = DefaultScreenOfDisplay(d); Screen *s = DefaultScreenOfDisplay(d);
Dimension dim = (Dimension) { s->width, s->height }; Dimension dim = (Dimension) { s->width, s->height };
free(d); free(d);
free(s); free(s);
#else
Dimension dim = (Dimension) { 1920, 1080 };
#endif
return dim; return dim;
} }

View File

@ -1,7 +1,7 @@
#ifndef STATS_H_ #ifndef STATS_H_
#define STATS_H_ #define STATS_H_
typedef struct { typedef struct Stats_t {
int hp; /* Hit points */ int hp; /* Hit points */
int dmg; /* Damage modifier */ int dmg; /* Damage modifier */
int atk; /* Attack rating */ int atk; /* Attack rating */

View File

@ -1,4 +1,6 @@
#include <SDL2/SDL_image.h> #include <SDL2/SDL_image.h>
#include <stdio.h>
#include <stdlib.h>
#include "texture.h" #include "texture.h"
#include "util.h" #include "util.h"

View File

@ -1,6 +1,9 @@
#include "defines.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef WINDOWS
#include <unistd.h> #include <unistd.h>
#endif
#include <string.h> #include <string.h>
#include "util.h" #include "util.h"
@ -9,8 +12,8 @@ void fatal(char *message)
{ {
char error_message[100]; char error_message[100];
strcpy(error_message, "[!!] Fatal Error "); strcpy_s(error_message, 100, "[!!] Fatal Error ");
strncat(error_message, message, 83); strncat_s(error_message, 100, message, 83);
perror(error_message); perror(error_message);
exit(-1); exit(-1);
} }