Commit c4cf9c14 authored by David Llewellyn-Jones's avatar David Llewellyn-Jones

Add global source files

These should have been added in the previous commit. They're
needed for storing the configured data directory, since
it's needed in multiple places throughout the application
(whenever anything is loaded from the data directory).
parent 6ff786b1
///////////////////////////////////////////////////////////////////
// Enzyme
// 3D Functy/Dandelion/programming game
//
// David Llewellyn-Jones
//
// October 2016
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
// Includes
#include "utils.h"
#include "global.h"
///////////////////////////////////////////////////////////////////
// Defines
///////////////////////////////////////////////////////////////////
// Structures and enumerations
struct _GlobalPersist {
GString * psDataDir;
};
///////////////////////////////////////////////////////////////////
// Global variables
///////////////////////////////////////////////////////////////////
// Function prototypes
///////////////////////////////////////////////////////////////////
// Function definitions
GlobalPersist * NewGlobalPersist () {
GlobalPersist * psGlobalData;
// Allocate some memory for the new structures
psGlobalData = g_new0 (GlobalPersist, 1);
psGlobalData->psDataDir = g_string_new (FUNCTYDIR);
return psGlobalData;
}
void DeleteGlobalPersist (GlobalPersist * psGlobalData) {
if (psGlobalData->psDataDir) {
g_string_free(psGlobalData->psDataDir, TRUE);
}
// Free up the structures
g_free (psGlobalData);
}
void SetDataDir (char const * szDir, GlobalPersist * psGlobalData) {
psGlobalData->psDataDir = g_string_assign (psGlobalData->psDataDir, szDir);
}
void GenerateDataPath (GString * szLeaf, GlobalPersist const * psGlobalData) {
if (szLeaf) {
g_string_prepend (szLeaf, psGlobalData->psDataDir->str);
}
}
///////////////////////////////////////////////////////////////////
// Enzyme
// 3D Functy/Dandelion/programming game
//
// David Llewellyn-Jones
//
// October 2016
///////////////////////////////////////////////////////////////////
#ifndef GLOBAL_H
#define GLOBAL_H
///////////////////////////////////////////////////////////////////
// Includes
///////////////////////////////////////////////////////////////////
// Defines
///////////////////////////////////////////////////////////////////
// Structures and enumerations
typedef struct _GlobalPersist GlobalPersist;
///////////////////////////////////////////////////////////////////
// Global variables
///////////////////////////////////////////////////////////////////
// Function prototypes
GlobalPersist * NewGlobalPersist ();
void DeleteGlobalPersist (GlobalPersist * psGlobalData);
void SetDataDir (char const * szDir, GlobalPersist * psGlobalData);
void GenerateDataPath (GString * szLeaf, GlobalPersist const * psGlobalData);
///////////////////////////////////////////////////////////////////
// Function definitions
#endif /* GLOBAL_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment