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.
This commit is contained in:
onpon4 2015-02-26 11:09:28 -05:00
parent ed621bf3a4
commit 555ee4fe15
13 changed files with 2 additions and 291 deletions

View File

@ -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

View File

@ -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)

View File

@ -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"

View File

@ -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);

View File

@ -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()

View File

@ -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);

View File

@ -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());

View File

@ -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];

View File

@ -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());

View File

@ -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);

View File

@ -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++)
{

View File

@ -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
}

View File

@ -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);