Commit ac637334 authored by Kiste's avatar Kiste
Browse files

Implement install stuff

parent 804e7a88
project('libbulletml', 'c', 'cpp')
libbulletmldep = dependency('libbulletml')
sdlmixerdep = dependency('SDL2_mixer')
executable('noiz2sa',
'src/attractmanager.c',
'src/background.c',
'src/barragemanager.cc',
'src/bonus.c',
'src/clrtbl.c',
'src/degutil.c',
'src/foe.cc',
'src/foecommand.cc',
'src/frag.c',
'src/letterrender.c',
'src/noiz2sa.c',
'src/rand.c',
'src/screen.c',
'src/ship.c',
'src/shot.c',
'src/soundmanager.c',
'src/vector.c',
dependencies : [sdlmixerdep, libbulletmldep]
)
subdir('src')
install_data('noiz2sa.desktop', install_dir : join_paths(get_option('datadir'), 'applications'))
install_data('noiz2sa.png', install_dir : join_paths(get_option('datadir'), 'pixmaps'))
install_subdir('boss', install_dir : join_paths(get_option('datadir'), 'noiz2sa'))
install_subdir('images', install_dir : join_paths(get_option('datadir'), 'noiz2sa'))
install_subdir('middle', install_dir : join_paths(get_option('datadir'), 'noiz2sa'))
install_subdir('sounds', install_dir : join_paths(get_option('datadir'), 'noiz2sa'))
install_subdir('zako', install_dir : join_paths(get_option('datadir'), 'noiz2sa'))
option('localdata', type : 'boolean', value : false, description : 'Load data files from current folder')
[Desktop Entry]
Version=1.0
Type=Application
Name=Noiz2sa
Comment=Abstract shootem up game
Exec=noiz2sa
Icon=noiz2sa
Terminal=false
StartupNotify=false
Categories=Game;Shooter;
noiz2sa.png

245 Bytes

......@@ -49,12 +49,35 @@ static void initHiScore() {
hiScore.stage = 0;
}
static char *getPrefPath() {
static char name[256];
char *tmpname = NULL;
tmpname = getenv("XDG_CONFIG_HOME");
if ( tmpname ) {
strcpy(name, tmpname);
strcat(name, "/");
strcat(name, PREF_FILE);
return name;
}
tmpname = getenv("HOME");
if ( tmpname ) {
strcpy(name, tmpname);
strcat(name, "/");
strcat(name, PREF_FILE);
return name;
}
return PREF_FILE;
}
// Load preference.
void loadPreference() {
FILE *fp;
int i, j;
int version;
if ( NULL == (fp = fopen(PREF_FILE,"rb")) ) {
printf("Loading from %s\n", getPrefPath());
if ( NULL == (fp = fopen(getPrefPath(),"rb")) ) {
initHiScore();
return;
}
......@@ -80,7 +103,7 @@ void loadPreference() {
void savePreference() {
FILE *fp;
int i, j;
if ( NULL == (fp = fopen(PREF_FILE,"wb")) ) return;
if ( NULL == (fp = fopen(getPrefPath(),"wb")) ) return;
putw(VERSION_NUM, fp);
for ( i=0 ; i<STAGE_NUM ; i++ ) {
putw(hiScore.stageScore[i], fp);
......
......@@ -43,13 +43,25 @@ static int readBulletMLFiles(const char *dirPath, Barrage brg[]) {
struct dirent *dir;
int i = 0;
char fileName[256];
#ifndef DATAPATH
if ( (dp = opendir(dirPath)) == NULL ) {
#else
char fullDirPath[256];
strcpy(fullDirPath, DATAPATH);
strcat(fullDirPath, "/");
strcat(fullDirPath, dirPath);
if ( (dp = opendir(fullDirPath)) == NULL ) {
#endif
fprintf(stderr, "Can't open directory: %s\n", dirPath);
exit(EXIT_FAILURE);
}
while ((dir = readdir(dp)) != NULL) {
if ( strcmp(strrchr(dir->d_name, '.'), ".xml") != 0 ) continue; // Read .xml files.
#ifndef DATAPATH
strcpy(fileName, dirPath);
#else
strcpy(fileName, fullDirPath);
#endif
strcat(fileName, "/");
strcat(fileName, dir->d_name);
brg[i].bulletml = new BulletMLParserTinyXML(fileName);
......
......@@ -25,14 +25,14 @@ void drawLetterBuf(int idx, int lx, int ly, int ltSize, int d, LayerBit color1,
size *= 1.3f; length *= 1.1f;
switch ( d ) {
case 0:
x = -x; y = y;
x = -x;
break;
case 1:
t = x; x = -y; y = -t;
deg += 90;
break;
case 2:
x = x; y = -y;
y = -y;
deg += 180;
break;
case 3:
......
libbulletmldep = dependency('libbulletml')
sdldep = dependency('sdl2')
sdlmixerdep = dependency('SDL2_mixer')
if not get_option('localdata')
add_project_arguments(''.join(['-DDATAPATH="', join_paths(get_option('prefix'), get_option('datadir'), 'noiz2sa'), '/"']), language : ['c', 'cpp'])
endif
executable('noiz2sa',
'attractmanager.c',
'background.c',
'barragemanager.cc',
'bonus.c',
'clrtbl.c',
'degutil.c',
'foe.cc',
'foecommand.cc',
'frag.c',
'letterrender.c',
'noiz2sa.c',
'rand.c',
'screen.c',
'ship.c',
'shot.c',
'soundmanager.c',
'vector.c',
dependencies : [sdldep, sdlmixerdep, libbulletmldep],
install : true
)
......@@ -55,11 +55,20 @@ SDL_Joystick *stick = NULL;
static void loadSprites() {
SDL_Surface *img;
int i;
#ifndef DATAPATH
char name[32];
#else
char name[256];
#endif
color[0].r = 100; color[0].g = 0; color[0].b = 0;
SDL_SetPaletteColors(video->format->palette, color, 0, 1);
for ( i=0 ; i<SPRITE_NUM ; i++ ) {
#ifndef DATAPATH
strcpy(name, "images/");
#else
strcpy(name, DATAPATH);
strcat(name, "images/");
#endif
strcat(name, spriteFile[i]);
img = SDL_LoadBMP(name);
if ( img == NULL ) {
......@@ -126,11 +135,15 @@ void initSDL(int window, int scaling) {
Uint32 windowFlags;
SDL_PixelFormat *pfrm;
if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 ) {
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
atexit(closeSDL);
if ( SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0 ) {
fprintf(stderr, "Unable to initialize SDL_JOYSTICK: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
windowFlags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_INPUT_FOCUS;
if ( !window ) windowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
......
......@@ -15,7 +15,7 @@
#include <signal.h>
#include <string.h>
#include "SDL_mixer.h"
#include <SDL_mixer.h>
#include "soundmanager.h"
static int useAudio = 0;
......@@ -59,10 +59,19 @@ void closeSound() {
static void loadSounds() {
int i;
#ifndef DATAPATH
char name[32];
#else
char name[256];
#endif
for ( i=0 ; i<MUSIC_NUM ; i++ ) {
#ifndef DATAPATH
strcpy(name, "sounds/");
#else
strcpy(name, DATAPATH);
strcat(name, "sounds/");
#endif
strcat(name, musicFileName[i]);
if ( NULL == (music[i] = Mix_LoadMUS(name)) ) {
fprintf(stderr, "Couldn't load: %s\n", name);
......@@ -71,7 +80,12 @@ static void loadSounds() {
}
}
for ( i=0 ; i<CHUNK_NUM ; i++ ) {
#ifndef DATAPATH
strcpy(name, "sounds/");
#else
strcpy(name, DATAPATH);
strcat(name, "sounds/");
#endif
strcat(name, chunkFileName[i]);
if ( NULL == (chunk[i] = Mix_LoadWAV(name)) ) {
fprintf(stderr, "Couldn't load: %s\n", name);
......
Supports Markdown
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