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/
/tags
/.vs/
*.swp
*~

View File

@ -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}

View File

@ -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

View File

@ -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) {

View File

@ -1,14 +1,13 @@
#include <string.h>
#include <stdio.h>
#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;
}

View File

@ -1,4 +1,5 @@
#include <stdlib.h>
#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)

View File

@ -1,16 +1,24 @@
#include "defines.h"
#ifndef WINDOWS
#include <X11/Xlib.h>
#endif
#include <stdlib.h>
#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;
}

View File

@ -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 */

View File

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

View File

@ -1,6 +1,9 @@
#include "defines.h"
#include <stdio.h>
#include <stdlib.h>
#ifndef WINDOWS
#include <unistd.h>
#endif
#include <string.h>
#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);
}