Moved platform specific code to src/plat

This commit is contained in:
Steve 2015-11-24 22:46:52 +00:00
parent e76cbaedda
commit 5aa3daf342
9 changed files with 134 additions and 49 deletions

View File

@ -1,4 +1,7 @@
CC=gcc
EXEEXT=
CC = gcc
EXEEXT =
SEARCHPATH += src/plat/unix
OBJS += unixInit.o
include common.mk

View File

@ -1,4 +1,7 @@
EXEEXT=.exe
CC=x86_64-w64-mingw32-gcc
EXEEXT = .exe
CC = x86_64-w64-mingw32-gcc
SEARCHPATH += src/plat/win32
OBJS += win32Init.o
include common.mk

View File

@ -1,6 +1,6 @@
PROG = tbftss
TARGET=$(PROG)$(EXEEXT)
TARGET = $(PROG)$(EXEEXT)
VERSION = 0.4
REVISION = $(shell date +"%y%m%d")

46
src/plat/unix/unixInit.c Normal file
View File

@ -0,0 +1,46 @@
/*
Copyright (C) 2015 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "unixInit.h"
void createSaveFolder(void)
{
char *userHome;
char dir[MAX_FILENAME_LENGTH];
userHome = getenv("HOME");
if (!userHome)
{
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Unable to determine user save folder. Will save to current dir.");
return;
}
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome);
sprintf(dir, "%s/.local/share/tbftss", userHome);
if (mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0 && errno != EEXIST)
{
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to create save dir '%s'. Will save to current dir.", dir);
return;
}
STRNCPY(app.saveDir, dir, MAX_FILENAME_LENGTH);
}

31
src/plat/unix/unixInit.h Normal file
View File

@ -0,0 +1,31 @@
/*
Copyright (C) 2015 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <sys/stat.h>
#include <pwd.h>
#include <unistd.h>
#include <errno.h>
#include "SDL2/SDL.h"
#include "../../defs.h"
#include "../../structs.h"
extern App app;

View File

@ -0,0 +1,25 @@
/*
Copyright (C) 2015 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "win32Init.h"
void createSaveFolder(void)
{
}

View File

@ -0,0 +1,19 @@
/*
Copyright (C) 2015 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

View File

@ -20,14 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "init.h"
#ifndef _WIN32
#define UNIX 1
#endif
#if UNIX
static void createSaveFolder(void);
#endif
static void loadConfig(void);
void saveConfig(void);
static void initColor(SDL_Color *c, int r, int g, int b);
@ -39,9 +31,8 @@ void initSDL(void)
/* do this here, so we don't destroy the save dir stored in app */
memset(&app, 0, sizeof(App));
#if UNIX
/* done in src/plat/ */
createSaveFolder();
#endif
rendererFlags = SDL_RENDERER_ACCELERATED;
windowFlags = 0;
@ -101,33 +92,6 @@ void initSDL(void)
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Game scale factor: %.2f,%.2f\n", app.scaleX, app.scaleY);
}
#ifdef UNIX
static void createSaveFolder(void)
{
char *userHome;
char dir[MAX_FILENAME_LENGTH];
userHome = getenv("HOME");
if (!userHome)
{
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Unable to determine user save folder. Will save to current dir.");
return;
}
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome);
sprintf(dir, "%s/.local/share/tbftss", userHome);
if (mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0 && errno != EEXIST)
{
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to create save dir '%s'. Will save to current dir.", dir);
return;
}
STRNCPY(app.saveDir, dir, MAX_FILENAME_LENGTH);
}
#endif
void initGameSystem(void)
{
initColor(&colors.red, 255, 0, 0);

View File

@ -27,13 +27,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../structs.h"
#include "../json/cJSON.h"
#if UNIX
#include <sys/stat.h>
#include <pwd.h>
#include <unistd.h>
#include <errno.h>
#endif
extern int fileExists(char *filename);
extern char *readFile(char *filename);
extern int writeFile(char *filename, char *data);
@ -62,6 +55,7 @@ extern void destroyGalacticMap(void);
extern void destroyWidgets(void);
extern void expireTexts(void);
extern void initInput(void);
extern void createSaveFolder(void);
extern App app;
extern Colors colors;