[Add] Linux specific stuff for saving.
This commit is contained in:
parent
a741250073
commit
c51612d764
@ -246,8 +246,8 @@ static void input_key(int keynum, double value, int abs) {
|
||||
else if(KEY("pause") && NOHYP()) {
|
||||
if(value == KEY_PRESS) {
|
||||
if(!toolkit) {
|
||||
if(paused) unpause();
|
||||
} else pause();
|
||||
if(paused) unpause_game();
|
||||
} else pause_game();
|
||||
}
|
||||
}
|
||||
// Opens a menu.
|
||||
@ -336,8 +336,8 @@ void input_handle(SDL_Event* event) {
|
||||
if(event->type == SDL_ACTIVEEVENT) {
|
||||
if(event->active.state != SDL_APPMOUSEFOCUS) {
|
||||
// We don't need mouse focus.
|
||||
if((event->active.gain == 0) && !paused) pause();
|
||||
else if((event->active.gain == 1) && pause) unpause();
|
||||
if((event->active.gain == 0) && !paused) pause_game();
|
||||
else if((event->active.gain == 1) && paused) unpause_game();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,13 @@
|
||||
#include <SDL.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef LINUX
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "lephisto.h"
|
||||
#include "conf.h"
|
||||
#include "log.h"
|
||||
@ -75,6 +82,8 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine,
|
||||
int main(int argc, char** argv) {
|
||||
#endif
|
||||
|
||||
char* home, dir[PATH_MAX];
|
||||
|
||||
// Print the version.
|
||||
snprintf(version, VERSION_LEN, "%d.%d.%d", VMAJOR, VMINOR, VREV);
|
||||
LOG(" "APPNAME" v%s", version);
|
||||
@ -85,6 +94,21 @@ int main(int argc, char** argv) {
|
||||
// Input must be initialized for config to work.
|
||||
input_init();
|
||||
|
||||
// Create the home directory if needed.
|
||||
#ifdef LINUX
|
||||
struct stat buf;
|
||||
|
||||
home = getenv("HOME");
|
||||
snprintf(dir, PATH_MAX, "%s/.lephisto", home);
|
||||
stat(dir, &buf);
|
||||
if(!S_ISDIR(buf.st_mode)) {
|
||||
if(mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) < 0)
|
||||
WARN("Unable to create lephisto directory '%s'", dir);
|
||||
else
|
||||
DEBUG("Created lephisto directory '%s'", dir);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Set the configuration.
|
||||
conf_setDefaults(); // Default config values.
|
||||
conf_loadConfig(CONF_FILE); // Have Lua parse config.
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "toolkit.h"
|
||||
#include "log.h"
|
||||
#include "lephisto.h"
|
||||
#include "pause.h"
|
||||
#include "pilot.h"
|
||||
#include "space.h"
|
||||
#include "player.h"
|
||||
@ -104,7 +103,7 @@ static void menu_main_load(char* str) {
|
||||
(void)str;
|
||||
|
||||
menu_main_close();
|
||||
load_game("text.xml");
|
||||
load_game("test.xml");
|
||||
}
|
||||
|
||||
static void menu_main_new(char* str) {
|
||||
@ -121,7 +120,6 @@ void menu_small(void) {
|
||||
menu_isOpen(MENU_SMALL) ||
|
||||
menu_isOpen(MENU_DEATH))
|
||||
return; // It's already open..
|
||||
pause();
|
||||
|
||||
unsigned int wid;
|
||||
|
||||
@ -145,7 +143,6 @@ static void menu_small_close(char* str) {
|
||||
if(strcmp(str, "btnResume")==0)
|
||||
window_destroy(window_get("Menu"));
|
||||
|
||||
unpause();
|
||||
menu_Close(MENU_SMALL);
|
||||
}
|
||||
|
||||
@ -164,7 +161,6 @@ static void exit_game(void) {
|
||||
// Info menu.
|
||||
void menu_info(void) {
|
||||
if(menu_isOpen(MENU_INFO)) return;
|
||||
pause();
|
||||
|
||||
char str[128];
|
||||
char* lt;
|
||||
@ -222,7 +218,6 @@ static void menu_info_close(char* str) {
|
||||
window_destroy(window_get("Info"));
|
||||
|
||||
menu_Close(MENU_INFO);
|
||||
unpause();
|
||||
}
|
||||
|
||||
static void info_outfits_menu(char* str) {
|
||||
|
@ -21,7 +21,7 @@ static void pilots_unpause(void);
|
||||
static void pilots_delay(unsigned int delay);
|
||||
|
||||
// Pause the game.
|
||||
void pause(void) {
|
||||
void pause_game(void) {
|
||||
if(paused) return; // Well well.. We are paused already.
|
||||
|
||||
pilots_pause();
|
||||
@ -32,7 +32,7 @@ void pause(void) {
|
||||
paused = 1; // We should unpause it.
|
||||
}
|
||||
|
||||
void unpause(void) {
|
||||
void unpause_game(void) {
|
||||
if(!paused) return; // We are unpaused already.
|
||||
|
||||
pilots_unpause();
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
extern int paused;
|
||||
|
||||
void pause(void);
|
||||
void unpause(void);
|
||||
void pause_game(void);
|
||||
void unpause_game(void);
|
||||
|
||||
void pause_delay(unsigned int delay);
|
||||
|
||||
|
@ -872,7 +872,7 @@ Pilot* pilot_createEmpty(Ship* ship, char* name,
|
||||
int faction, AI_Profile* ai, const int flags) {
|
||||
|
||||
Pilot* dyn;
|
||||
dyn = MALLOC_L(Pilot*);
|
||||
dyn = MALLOC_L(Pilot);
|
||||
pilot_init(dyn, ship, name, faction, ai, 0., NULL, NULL, flags | PILOT_EMPTY);
|
||||
return dyn;
|
||||
}
|
||||
|
14
src/player.c
14
src/player.c
@ -320,14 +320,14 @@ void player_cleanup(void) {
|
||||
int i;
|
||||
|
||||
// Cleanup name.
|
||||
if(player_name) free(player_name);
|
||||
if(player_name != NULL) free(player_name);
|
||||
|
||||
// Cleanup messages.
|
||||
for(i = 0; i < msg_max; i++)
|
||||
memset(msg_stack[i].str, '\0', MSG_SIZE_MAX);
|
||||
|
||||
// Clean up the stack.
|
||||
if(player_stack) {
|
||||
if(player_stack != NULL) {
|
||||
for(i = 0; i < player_nstack; i++) {
|
||||
pilot_free(player_stack[i]);
|
||||
free(player_lstack[i]);
|
||||
@ -339,7 +339,7 @@ void player_cleanup(void) {
|
||||
// Nothing left.
|
||||
player_nstack = 0;
|
||||
}
|
||||
if(missions_done) {
|
||||
if(missions_done != NULL) {
|
||||
free(missions_done);
|
||||
missions_done = NULL;
|
||||
missions_ndone = 0;
|
||||
@ -1595,7 +1595,7 @@ static int player_parseShip(xmlNodePtr parent, int is_player) {
|
||||
xmlr_attr(parent, "model", model);
|
||||
|
||||
// Player is currently on this ship.
|
||||
if(is_player) {
|
||||
if(is_player != 0) {
|
||||
pilot_create(ship_get(model), name, faction_get("Player"), NULL, 0., NULL,
|
||||
NULL, PILOT_PLAYER | PILOT_NO_OUTFITS);
|
||||
ship = player;
|
||||
@ -1609,7 +1609,7 @@ static int player_parseShip(xmlNodePtr parent, int is_player) {
|
||||
node = parent->xmlChildrenNode;
|
||||
|
||||
do {
|
||||
if(!is_player) xmlr_str(node, "location", loc);
|
||||
if(!is_player == 0) xmlr_str(node, "location", loc);
|
||||
|
||||
if(xml_isNode(node, "outfits")) {
|
||||
cur = node->xmlChildrenNode;
|
||||
@ -1645,9 +1645,9 @@ static int player_parseShip(xmlNodePtr parent, int is_player) {
|
||||
} while(xml_nextNode(node));
|
||||
|
||||
// Add it to the stack if it's not what the player is in.
|
||||
if(!is_player) {
|
||||
if(is_player == 0) {
|
||||
player_stack = realloc(player_stack, sizeof(Pilot*)*(player_nstack+1));
|
||||
player_stack[player_nstack] = pilot_copy(player);
|
||||
player_stack[player_nstack] = ship;
|
||||
player_lstack = realloc(player_lstack, sizeof(char*)*(player_nstack+1));
|
||||
player_lstack[player_nstack] = strdup(loc);
|
||||
player_nstack++;
|
||||
|
27
src/save.c
27
src/save.c
@ -1,6 +1,15 @@
|
||||
#include <stdlib.h>
|
||||
#ifdef LINUX
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "lephisto.h"
|
||||
#include "log.h"
|
||||
#include "xml.h"
|
||||
#include "player.h"
|
||||
#include "save.h"
|
||||
|
||||
// Externs.
|
||||
@ -22,7 +31,7 @@ static int save_data(xmlTextWriterPtr writer) {
|
||||
|
||||
// Save the current game.
|
||||
int save_all(void) {
|
||||
char* file;
|
||||
char file[PATH_MAX], *home;
|
||||
xmlDocPtr doc;
|
||||
xmlTextWriterPtr writer;
|
||||
|
||||
@ -45,7 +54,21 @@ int save_all(void) {
|
||||
xmlw_endElem(writer); // lephisto_save.
|
||||
xmlw_done(writer);
|
||||
|
||||
file = "test.xml";
|
||||
#ifdef LINUX
|
||||
struct stat buf;
|
||||
home = getenv("HOME");
|
||||
snprintf(file, PATH_MAX, "%s/.lephisto/saves", home);
|
||||
stat(file, &buf);
|
||||
if(!S_ISDIR(buf.st_mode))
|
||||
if(mkdir(file, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
|
||||
WARN("Unable to create '%s' for saving: %s", file, strerror(errno));
|
||||
WARN("Aborting save...");
|
||||
xmlFreeTextWriter(writer);
|
||||
xmlFreeDoc(doc);
|
||||
return -1;
|
||||
}
|
||||
snprintf(file, PATH_MAX, "%s/.lephisto/saves/%s.ls", home, player_name);
|
||||
#endif
|
||||
|
||||
xmlFreeTextWriter(writer);
|
||||
xmlSaveFileEnc(file, doc, "UTF-8");
|
||||
|
@ -495,6 +495,7 @@ unsigned int window_create(char* name, const int x, const int y,
|
||||
// Toolkit is enabled.
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
toolkit = 1; // Enable it.
|
||||
pause_game();
|
||||
}
|
||||
|
||||
return wid;
|
||||
@ -558,7 +559,7 @@ void window_destroy(const unsigned int wid) {
|
||||
// No windows left.
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
toolkit = 0; // Disable the toolkit.
|
||||
if(paused) unpause();
|
||||
if(paused) unpause_game();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user