From 555ee4fe15ae38e6a7bbe9e49c4533799652696c Mon Sep 17 00:00:00 2001 From: onpon4 Date: Thu, 26 Feb 2015 11:09:28 -0500 Subject: [PATCH] Removed support for PAK files. These are really unnecessary, and their support makes converting the music from MOD to Ogg Vorbis more complicated than it needs to be. --- Makefile | 18 +---- src/Starfighter.cpp | 11 +-- src/Starfighter.h | 1 - src/aliens.cpp | 8 --- src/audio.cpp | 16 ----- src/comms.cpp | 6 -- src/graphics.cpp | 5 -- src/intermission.cpp | 6 -- src/resources.cpp | 18 ----- src/script.cpp | 14 ---- src/title.cpp | 12 ---- src/unpack.cpp | 156 ------------------------------------------- src/unpack.h | 22 ------ 13 files changed, 2 insertions(+), 291 deletions(-) delete mode 100644 src/unpack.cpp delete mode 100644 src/unpack.h diff --git a/Makefile b/Makefile index 7faa831..5e24a61 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,10 @@ OBJS = ai.o aliens.o audio.o bullets.o cargo.o collectable.o comms.o debris.o ev VERSION = 1.2-SDL2 PROG = starfighter -PACK = starfighter.pak DOCS = docs/* DATA = data gfx sound DATAFILES = data/* gfx/* sound/* -USEPACK ?= 0 - PREFIX ?= /usr BINDIR ?= $(PREFIX)/games/ DATADIR ?= $(PREFIX)/share/games/parallelrealities/ @@ -19,15 +16,12 @@ DOCDIR ?= $(PREFIX)/share/doc/$(PROG)/ # top-level rule to create the program. ALL = $(PROG) -ifeq ($(USEPACK), 1) - ALL += $(PACK) -endif all: $(ALL) # compiling other source files. %.o: src/%.cpp src/*.h - $(CXX) $(CXXFLAGS) -c -DVERSION=\"$(VERSION)\" -DPACKLOCATION=\"$(DATADIR)$(PACK)\" -DUSEPACK=$(USEPACK) $< + $(CXX) $(CXXFLAGS) -c -DVERSION=\"$(VERSION)\" -DDATADIR=\"$(DATADIR)\" $< # linking the program. $(PROG): $(OBJS) @@ -44,19 +38,9 @@ install: $(ALL) mkdir -p $(DESTDIR)$(DOCDIR) install -m 755 $(PROG) $(DESTDIR)$(BINDIR)$(PROG) -ifeq ($(USEPACK), 1) - install -m 644 $(PACK) $(DESTDIR)$(DATADIR)$(PACK) -else cp -pr $(DATA) $(DESTDIR)$(DATADIR) -endif cp -p $(DOCS) $(DESTDIR)$(DOCDIR) -$(PACK): pack.py $(DATAFILES) - ./pack.py $(PACK) $(DATAFILES) - -unpack: unpack.py - ./unpack.py $(PACK) - optimise: advpng -z gfx/*.png jpegoptim --strip-all gfx/*.jpg diff --git a/src/Starfighter.cpp b/src/Starfighter.cpp index 26494fa..f3893a5 100644 --- a/src/Starfighter.cpp +++ b/src/Starfighter.cpp @@ -24,13 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int main(int argc, char *argv[]) { -#if !USEPACK - char datadir[] = PACKLOCATION; - char *slash = strrchr(datadir, '/'); - if(slash) - *slash = 0; - chdir(datadir); -#endif + chdir(DATADIR); defineGlobals(); // Must do this first! @@ -54,13 +48,10 @@ int main(int argc, char *argv[]) for (int i = 1 ; i < argc ; i++) { - #if USEPACK - #else if (strcmp(argv[i], "-nomove") == 0) {printf("Enemy movement disabled\n"); dev.moveAliens = 0;} if (strcmp(argv[i], "-nofire") == 0) {printf("Enemy firing disabled\n"); dev.fireAliens = 0;} - #endif if (strcmp(argv[i], "-cheat") == 0) cheatAttempt = true; if (strcmp(argv[i], "-noaudio") == 0) diff --git a/src/Starfighter.h b/src/Starfighter.h index e3ee76d..68793d8 100644 --- a/src/Starfighter.h +++ b/src/Starfighter.h @@ -61,7 +61,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "script.h" #include "shop.h" #include "title.h" -#include "unpack.h" #include "version.h" #include "weapons.h" diff --git a/src/aliens.cpp b/src/aliens.cpp index 4063566..06e2f49 100644 --- a/src/aliens.cpp +++ b/src/aliens.cpp @@ -293,17 +293,9 @@ static void getPreDefinedAliens() int barrierSpeed = 1; sprintf(string, "data/aliens%d.dat", currentGame.area); - #if USEPACK - int dataLocation = locateDataInPak(string, 0); - if (dataLocation == -1) - return; - fp = fopen(PACKLOCATION, "rb"); - fseek(fp, dataLocation, SEEK_SET); - #else fp = fopen(string, "rb"); if (fp == NULL) return; - #endif fscanf(fp, "%d ", &index); diff --git a/src/audio.cpp b/src/audio.cpp index 821f464..7b2e95e 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -83,12 +83,7 @@ Mix_Chunk *loadSound(const char *filename) { Mix_Chunk *chunk; - #if USEPACK - unpack(filename, PAK_WAV); - chunk = Mix_LoadWAV_RW(engine.sdlrw, 1); - #else chunk = Mix_LoadWAV(filename); - #endif return chunk; } @@ -101,18 +96,7 @@ void loadMusic(const char *filename) if (engine.music != NULL) Mix_FreeMusic(engine.music); - #if USEPACK - if(!unpack(filename, PAK_MOD)) - return; - - char musicFilename[PATH_MAX]; - strcpy(musicFilename, ""); - sprintf(musicFilename, "%smusic.mod", engine.userHomeDirectory); - - engine.music = Mix_LoadMUS(musicFilename); - #else engine.music = Mix_LoadMUS(filename); - #endif } void playRandomTrack() diff --git a/src/comms.cpp b/src/comms.cpp index d11545f..2f283b9 100644 --- a/src/comms.cpp +++ b/src/comms.cpp @@ -87,13 +87,7 @@ static void createMissionDetailSurface(SDL_Surface *comms, int missionSlot) sprintf(string, "data/brief%d.txt", mission); - #if USEPACK - int dataLocation = locateDataInPak(string, 1); - fp = fopen(PACKLOCATION, "rb"); - fseek(fp, dataLocation, SEEK_SET); - #else fp = fopen(string, "rb"); - #endif fscanf(fp, "%[^\n]%*c", name); sprintf(string, "+++ Communication with %s +++", name); diff --git a/src/graphics.cpp b/src/graphics.cpp index a5983b9..5e4e4b9 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -669,12 +669,7 @@ SDL_Surface *loadImage(const char *filename) { SDL_Surface *image, *newImage; - #if USEPACK - unpack(filename, PAK_IMG); - image = IMG_Load_RW(engine.sdlrw, 1); - #else image = IMG_Load(filename); - #endif if (image == NULL) { printf("Couldn't load %s: %s\n", filename, SDL_GetError()); diff --git a/src/intermission.cpp b/src/intermission.cpp index 066b344..0b7d588 100644 --- a/src/intermission.cpp +++ b/src/intermission.cpp @@ -197,13 +197,7 @@ static void setSystemPlanets() break; } - #if USEPACK - int dataLocation = locateDataInPak(string, 1); - fp = fopen(PACKLOCATION, "rb"); - fseek(fp, dataLocation, SEEK_SET); - #else fp = fopen(string, "rb"); - #endif int distance; char name[50]; diff --git a/src/resources.cpp b/src/resources.cpp index 50ef05b..de0894a 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -59,14 +59,7 @@ void loadGameGraphics() FILE *fp; - #if USEPACK - int dataLocation = locateDataInPak(string, 1); - fp = fopen(PACKLOCATION, "rb"); - if(fp) - fseek(fp, dataLocation, SEEK_SET); - #else fp = fopen(string, "rb"); - #endif if (fp == NULL) exit(1); @@ -121,13 +114,7 @@ void loadGameGraphics() strcpy(string, "data/resources_all.dat"); - #if USEPACK - dataLocation = locateDataInPak(string, 1); - fp = fopen(PACKLOCATION, "rb"); - fseek(fp, dataLocation, SEEK_SET); - #else fp = fopen(string, "rb"); - #endif fscanf(fp, "%d %s", &index, string); while (index != -1) @@ -188,12 +175,7 @@ void loadFont() for (int i = 0 ; i < MAX_FONTSHAPES ; i++) { - #if USEPACK - unpack("gfx/smallFont.png", PAK_FONT); - image = IMG_Load_RW(engine.sdlrw, 1); - #else image = IMG_Load("gfx/smallFont.png"); - #endif if (image == NULL) { printf("Couldn't load game font! (%s) Exitting.\n", SDL_GetError()); diff --git a/src/script.cpp b/src/script.cpp index 883a36a..2cfda7b 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -61,17 +61,9 @@ void loadScriptEvents() int time, entity, flags; char face[255], message[255]; - #if USEPACK - int dataLocation = locateDataInPak(filename, 0); - if (dataLocation == -1) - return; - fp = fopen(PACKLOCATION, "rb"); - fseek(fp, dataLocation, SEEK_SET); - #else fp = fopen(filename, "rb"); if (fp == NULL) return; - #endif fscanf(fp, "%d ", &time); @@ -144,13 +136,7 @@ static void setScene(int scene) sprintf(string, "data/cutscene%d.dat", scene); - #if USEPACK - int dataLocation = locateDataInPak(string, 1); - fp = fopen(PACKLOCATION, "rb"); - fseek(fp, dataLocation, SEEK_SET); - #else fp = fopen(string, "rb"); - #endif // Load in the specified background fscanf(fp, "%s", string); diff --git a/src/title.cpp b/src/title.cpp index f33d787..8e70a53 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -535,13 +535,7 @@ void showStory() FILE *fp; - #if USEPACK - int dataLocation = locateDataInPak("data/intro.txt", 1); - fp = fopen(PACKLOCATION, "rb"); - fseek(fp, dataLocation, SEEK_SET); - #else fp = fopen("data/intro.txt", "rb"); - #endif int i = 0; int nextPos = -1; @@ -683,13 +677,7 @@ void doCredits() drawBackGround(); - #if USEPACK - int dataLocation = locateDataInPak("data/credits.txt", 1); - fp = fopen(PACKLOCATION, "rb"); - fseek(fp, dataLocation, SEEK_SET); - #else fp = fopen("data/credits.txt", "rb"); - #endif for (int i = 0 ; i < 6 ; i++) { diff --git a/src/unpack.cpp b/src/unpack.cpp deleted file mode 100644 index 397f5a8..0000000 --- a/src/unpack.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* -Copyright (C) 2003 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 "Starfighter.h" - -/* -Searches the pak file for the required data. When -it is found, the data is read into a character buffer. -*/ -bool unpack(const char *file, signed char fileType) -{ - unsigned char *packBuffer; - char packFilename[60]; - int packFSize; - - FILE *pak; - FILE *fp = NULL; // music has to be read-written-read! - char musicFilename[PATH_MAX]; - - strcpy(packFilename, ""); - - pak = fopen(PACKLOCATION, "rb"); - if (pak == NULL) - { - printf("Couldn't access the Project: Starfighter data file!\n"); - exit(1); - } - fseek(pak, 4, SEEK_SET); - - while (true) - { - if (!fread(packFilename, 1, 56, pak)) - { - fclose(pak); - - if (fileType == PAK_MOD || fileType == PAK_S3M) - return false; - - if (fileType != PAK_FONT) - { - showErrorAndExit(0, file); - } - exit(1); - break; - } - - fread(&packFSize, 4, 1, pak); - packFSize = SDL_SwapLE32(packFSize); - - if (strcmp(packFilename, file) == 0) - { - if ((fileType == PAK_MOD) || (fileType == PAK_S3M)) - { - if (fileType == PAK_MOD) - { - sprintf(musicFilename, "%smusic.mod", engine.userHomeDirectory); - fp = fopen(musicFilename, "wb"); - } - else - { - sprintf(musicFilename, "%smusic.s3m", engine.userHomeDirectory); - fp = fopen(musicFilename, "wb"); - } - - if (fp == NULL) - showErrorAndExit(1, ""); - } - packBuffer = (unsigned char*) malloc(packFSize); - fread(packBuffer, 1, packFSize, pak); - if ((fileType == PAK_MOD) || (fileType == PAK_S3M)) - { - fwrite(packBuffer, 1, packFSize, fp); - fclose(fp); - } - break; - } - else - { - fseek(pak, packFSize, SEEK_CUR); - } - } - - if ((fileType != PAK_MOD) && (fileType != PAK_S3M)) - engine.sdlrw = SDL_RWFromMem(packBuffer, packFSize); - - fclose(pak); - return true; -} - -/* -Search the data package for the required file. -When it is found, return the location. -*/ -int locateDataInPak(const char *file, bool required) -{ - char packFilename[60] = ""; - int packFSize; - int location = 0; - - FILE *pak; - - pak = fopen(PACKLOCATION, "rb"); - if (pak == NULL) - { - printf("Couldn't access the Project: Starfighter data file!\n"); - exit(1); - } - fseek(pak, 4, SEEK_SET); - - while (true) - { - if (!fread(packFilename, 1, 56, pak)) - { - fclose(pak); - if (required) - { - showErrorAndExit(0, file); - exit(1); - } - break; - } - fread(&packFSize, 4, 1, pak); - packFSize = SDL_SwapLE32(packFSize); - - if (strcmp(packFilename, file) == 0) - { - location = ftell(pak); - fclose(pak); - - return location; - } - else - { - fseek(pak, packFSize, SEEK_CUR); - } - } - - return -1; // we only get this if it isn't required -} diff --git a/src/unpack.h b/src/unpack.h deleted file mode 100644 index ae8d01b..0000000 --- a/src/unpack.h +++ /dev/null @@ -1,22 +0,0 @@ -/* -Copyright (C) 2003 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. - -*/ - -extern bool unpack(const char *file, signed char fileType); -extern int locateDataInPak(const char *file, bool required);