Skip to content

Commit

Permalink
Redid the most of the file loading/saving. Now uses $HOME/.avp/ and
Browse files Browse the repository at this point in the history
$AVP_DIR to look for files.
  • Loading branch information
Steven Fuller committed Dec 18, 2001
1 parent fdec628 commit 6a01356
Show file tree
Hide file tree
Showing 40 changed files with 1,399 additions and 1,578 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -20,7 +20,7 @@ LDLIBS = -L/usr/X11R6/lib -lX11 -lXext -lGL `sdl-config --libs` -lopenal

AFLAGS = -g -w+macro-params -w+orphan-labels -w+number-overflow

ROOT = main.c mathline.c math.asm opengl.c net.c menus.c openal.c cdplayer.c winapi.c stubs.c frustum.c kshape.c map.c maths.c md5.c mem3dc.c mem3dcpp.cpp module.c morph.c object.c shpanim.c sphere.c tables.c vdb.c version.c
ROOT = main.c files.c winapi.c stubs.c version.c mathline.c math.asm opengl.c openal.c cdplayer.c menus.c net.c frustum.c kshape.c map.c maths.c md5.c mem3dc.c mem3dcpp.cpp module.c morph.c object.c shpanim.c sphere.c tables.c vdb.c
AVP = ai_sight.c avpview.c bh_agun.c bh_ais.c bh_alien.c bh_binsw.c bh_cable.c bh_corpse.c bh_deathvol.c bh_debri.c bh_dummy.c bh_fan.c bh_far.c bh_fhug.c bh_gener.c bh_ldoor.c bh_lift.c bh_light.c bh_lnksw.c bh_ltfx.c bh_marin.c bh_mission.c bh_near.c bh_pargen.c bh_plachier.c bh_plift.c bh_pred.c bh_queen.c bh_rubberduck.c bh_selfdest.c bh_snds.c bh_spcl.c bh_swdor.c bh_track.c bh_types.c bh_videoscreen.c bh_waypt.c bh_weap.c bh_xeno.c bonusabilities.c cconvars.cpp cdtrackselection.cpp cheatmodes.c comp_map.c comp_shp.c consolelog.cpp davehook.cpp deaths.c decal.c detaillevels.c dynamics.c dynblock.c equipmnt.c equiputl.cpp extents.c game.c game_statistics.c gamecmds.cpp gamevars.cpp hmodel.c hud.c inventry.c language.c lighting.c load_shp.c los.c maps.c mempool.c messagehistory.c missions.cpp movement.c paintball.c particle.c pfarlocs.c pheromon.c player.c pmove.c psnd.c psndproj.c pvisible.c savegame.c scream.cpp secstats.c sfx.c stratdef.c targeting.c track.c triggers.c weapons.c
SHAPES = cube.c
SUPPORT = consbind.cpp consbtch.cpp coordstr.cpp daemon.cpp indexfnt.cpp r2base.cpp r2pos666.cpp reflist.cpp refobj.cpp rentrntq.cpp scstring.cpp strtab.cpp strutil.c trig666.cpp wrapstr.cpp
Expand Down
41 changes: 27 additions & 14 deletions README
Expand Up @@ -11,8 +11,7 @@ end users." Hopefully this status will change in the not-so-distant future.





(Please see note below regarding installation/running.)


Obviously this README is totally incomplete, and will probably remain so for
Expand Down Expand Up @@ -42,12 +41,29 @@ If you are wanting to run the Alien demo (the installer is an .exe but you
can just use unzip to extract the files from the .exe), add -DALIEN_DEMO to
the CFLAGS line (the one that's uncommented) in the Makefile. Rename all game
files lowercase. Be sure to install SDL 1.2 (http://www.libsdl.org) with
OpenGL support, nasm 0.98, PhysicsFS 0.1.4 (http://icculus.org/physfs/),
and the latest OpenAL CVS (http://www.openal.org). AvP requires a 3D card
with OpenGL support.

Create the MPConfig and User_Profiles directories if they do not exist.
(Note: Windows profiles probably do not work in Linux and vice versa)
OpenGL support, nasm 0.98, and the latest OpenAL CVS (http://www.openal.org).
AvP requires a 3D card with OpenGL support.

***
IMPORTANT:
AvP now uses $HOME/.avp/ to load/store configs, logs, etc.
NOTE: Windows profiles probably do not work in Linux and vice versa.

AvP will no longer use the current working directory to look for files. You
must either copy or symlink the AvP binary to the game data directory and run
that, or set AVP_DATA to the data directory.

Currently:
If you want to install the mappacks from
http://www.avpnews.com/files/avpfiles.html, install them with the rest of
the game data, not in ~/.avp/. Make sure everything is lowercase (although,
the maps in avp_rifs/Custom do not have to be totally lowercase, just the .rif
extension). Maybe in the future users will be able to install the files in
~/.avp/ also.

Hopefully all the necessary file loading changes were made. Please let me
know if something goes wrong.
***

If you have the regular edition, add -DREGULAR_EDITION to CFLAGS.

Expand All @@ -64,14 +80,11 @@ have to uncomment a LDLIBS line in the Makefile.


relnev:~/avp/AvP Demo 3 - Alien$ ls
aenglish.txt alienavp_huds/ alienfastfile/ avp_rifs/ MPConfig/
User_Profiles/
aenglish.txt alienavp_huds/ alienfastfile/ avp_rifs/
relnev:~/avp/Gold Edition$ ls
avp_huds/ avp_rifs/ cd tracks.txt default.cfg fastfile/ language.txt
MPConfig/ User_Profiles/
avp_huds/ avp_rifs/ cd tracks.txt fastfile/ language.txt

Support for the demo is not quite complete (some sounds are missing and some
text is incorrect/missing).
Support for the demo is not quite complete (some sounds are missing).


Linux Port-specific commands:
Expand Down
15 changes: 9 additions & 6 deletions src/avp/cdtrackselection.cpp
Expand Up @@ -112,22 +112,25 @@ void LoadCDTrackList()
//clear out the old list first
EmptyCDTrackList();

HANDLE file=CreateFile(CDTrackFileName,GENERIC_READ, 0, 0, OPEN_EXISTING,FILE_FLAG_RANDOM_ACCESS, 0);
if(file==INVALID_HANDLE_VALUE)
FILE *file = OpenGameFile(CDTrackFileName, FILEMODE_READONLY, FILETYPE_OPTIONAL);

if(file==NULL)
{
LOGDXFMT(("Failed to open %s",CDTrackFileName));
return;
}

char* buffer;
int file_size;
unsigned long bytes_read;

fseek(file, 0, SEEK_END);
file_size = ftell(file);
rewind(file);

//copy the file contents into a buffer
file_size= GetFileSize(file,0);
buffer=new char[file_size+1];
ReadFile(file,buffer,file_size,&bytes_read,0);
CloseHandle(file);
fread(buffer, 1, file_size, file);
fclose(file);

char* bufferptr=buffer;

Expand Down
23 changes: 15 additions & 8 deletions src/avp/psnd.c
Expand Up @@ -511,10 +511,10 @@ void Sound_Play(SOUNDINDEX soundNumber, char *format, ...)
if(loop) ActiveSounds[newIndex].loop = 1;
else ActiveSounds[newIndex].loop = 0;

/*
printf("Play: new = %d. num = %d, p = %d, v = %d, pi = %d, l = %d, mi = %d, rev = %d\n", newIndex, soundNumber, priority, volume, pitch, loop, marine_ignore, reverb_off);
printf("Play: %d %d %s l:%d\n", newIndex, soundNumber, GameSounds[soundNumber].wavName, loop);
*/
#if 0
fprintf(stderr, "PSND: Play: new = %d. num = %d, p = %d, v = %d, pi = %d, l = %d, mi = %d, rev = %d\n", newIndex, soundNumber, priority, volume, pitch, loop, marine_ignore, reverb_off);
fprintf(stderr, "PSND: Play: %d %d %s l:%d\n", newIndex, soundNumber, GameSounds[soundNumber].wavName, loop);
#endif

if(worldPosn)
{
Expand Down Expand Up @@ -562,8 +562,10 @@ printf("Play: %d %d %s l:%d\n", newIndex, soundNumber, GameSounds[soundNumber].w
// //sound starts part of the way in
// IDirectSoundBuffer_SetCurrentPosition(ActiveSounds[newIndex].dsBufferP,soundStartPosition);
// }
#if 0 /* TODO */
if (soundStartPosition)
fprintf(stderr, "Sound_Play: sound starts part of the way in (%d)\n", soundStartPosition);
#endif
}

void Sound_Stop(int activeSoundNumber)
Expand All @@ -590,9 +592,11 @@ void Sound_Stop(int activeSoundNumber)
/* stop the sound: it may have already stopped, of course, but never mind */

PlatStopSound(activeSoundNumber);
/*
printf("Stop: %d %d %s\n", activeSoundNumber, soundNo, GameSounds[soundNo].wavName);
*/

#if 0
fprintf(stderr, "PSND: Stop: %d %d %s\n", activeSoundNumber, soundNo, GameSounds[soundNo].wavName);
#endif

/* release the active sound slot */
buf = ActiveSounds[activeSoundNumber].ds3DBufferP;
ActiveSounds[activeSoundNumber] = BlankActiveSound;
Expand Down Expand Up @@ -853,8 +857,9 @@ void Save_SoundState(int* soundHandle)
// IDirectSoundBuffer_GetCurrentPosition(sound->dsBufferP,(LPDWORD)&block->position,NULL);
// else
block->position = 0;
#if 0 /* TODO */
fprintf(stderr, "Save_SoundState: GetCurrentPosition!\n");

#endif
strcpy((char*)(block+1),name);

}
Expand Down Expand Up @@ -944,7 +949,9 @@ void Save_SoundsWithNoReference()
// IDirectSoundBuffer_GetCurrentPosition(sound->dsBufferP,(LPDWORD)&block->position,NULL);
// else
block->position = 0;
#if 0 /* TODO */
fprintf(stderr, "Save_SoundsWithNoReference: GetCurrentPosition!\n");
#endif

strcpy((char*)(block+1),name);
}
Expand Down
12 changes: 5 additions & 7 deletions src/avp/psndproj.c
Expand Up @@ -867,16 +867,14 @@ int FindAndLoadWavFile(int soundNum,char* wavFileName)

{
//check to see if file exists locally first
FILE* wavFile=fopen(sound_name,"rb");

FILE* wavFile = OpenGameFile(sound_name, FILEMODE_READONLY, FILETYPE_PERM);
if(!wavFile && SecondSoundDir)
{
//look for sound over network
sprintf (sound_name, "%s%s", SecondSoundDir,wavFileName);

wavFile=fopen(sound_name,"rb");
if(!wavFile)
{

wavFile = OpenGameFile(sound_name, FILEMODE_READONLY, FILETYPE_PERM);
if(!wavFile) {
LOGDXFMT(("Failed to find %s\n",wavFileName));
return 0;
}
Expand Down Expand Up @@ -905,7 +903,7 @@ void *LoadRebSndFile(char *filename)
void *bufferPtr;
long int save_pos, size_of_file;
FILE *fp;
fp = fopen(filename,"rb");
fp = OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_PERM);

if (!fp) goto error;

Expand Down
52 changes: 18 additions & 34 deletions src/avp/savegame.c
Expand Up @@ -397,8 +397,7 @@ static BOOL SaveGameAllowed()
void SaveGame()
{
char filename[100];
HANDLE file;
DWORD bytes_written;
FILE *file;
int headerLength;
HuffmanPackage *packagePtr;

Expand Down Expand Up @@ -456,34 +455,27 @@ void SaveGame()
SaveGameRequest = SAVELOAD_REQUEST_NONE;

//write the file
file = CreateFile(filename,GENERIC_WRITE, 0, 0, CREATE_ALWAYS,FILE_FLAG_RANDOM_ACCESS, 0);
file = OpenGameFile(filename, FILEMODE_WRITEONLY, FILETYPE_CONFIG);

if (file == INVALID_HANDLE_VALUE)
if (file == NULL)
{
GLOBALASSERT("Error saving file"==0);
return;
}

WriteFile(file,SaveInfo.BufferStart,headerLength,&bytes_written,0);
fwrite(SaveInfo.BufferStart, headerLength, 1, file);

packagePtr = HuffmanCompression(SaveInfo.BufferStart+headerLength,SaveInfo.BufferSpaceUsed-headerLength);

WriteFile(file,packagePtr,packagePtr->CompressedDataSize+sizeof(HuffmanPackage),&bytes_written,0);

CloseHandle(file);

fwrite(packagePtr, packagePtr->CompressedDataSize+sizeof(HuffmanPackage), 1, file);

fclose(file);

NewOnScreenMessage(GetTextString(TEXTSTRING_SAVEGAME_GAMESAVED));
DisplaySavesLeft();

}








static void EndLoadGame()
{
Expand All @@ -495,7 +487,6 @@ static void EndLoadGame()
LoadInfo.BufferPos = NULL;
LoadInfo.BufferSize = 0;
LoadInfo.BufferSpaceLeft = 0;

}

extern SAVE_SLOT_HEADER SaveGameSlot[];
Expand Down Expand Up @@ -535,9 +526,8 @@ void LoadSavedGame()
{
SAVE_SLOT_HEADER* save_slot;
char filename[100];
HANDLE file;
FILE *file;
BOOL terminal_error = FALSE;
unsigned int bytes_read;

if(LoadGameRequest == SAVELOAD_REQUEST_NONE) return;

Expand Down Expand Up @@ -576,31 +566,32 @@ void LoadSavedGame()
LoadGameRequest = SAVELOAD_REQUEST_NONE;

//load the file
file = CreateFile(filename,GENERIC_READ, 0, 0, OPEN_EXISTING,FILE_FLAG_RANDOM_ACCESS, 0);
file = OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_CONFIG);


if(file==INVALID_HANDLE_VALUE)
if(file==NULL)
{
//failed to load
EndLoadGame();
return;
}

LoadInfo.BufferSize = GetFileSize(file,0);
fseek(file, 0, SEEK_END);
LoadInfo.BufferSize = ftell(file);
rewind(file);

if(!LoadInfo.BufferSize)
{
CloseHandle(file);
fclose(file);
EndLoadGame();
return;
}

//allocate buffer , and read file into memory
LoadInfo.BufferStart = (char*) AllocateMem(LoadInfo.BufferSize);
ReadFile(file,LoadInfo.BufferStart,LoadInfo.BufferSize,(LPDWORD)&bytes_read,0);
CloseHandle(file);
fread(LoadInfo.BufferStart, LoadInfo.BufferSize, 1, file);
fclose(file);



LoadInfo.BufferPos = LoadInfo.BufferStart;
LoadInfo.BufferSpaceLeft = LoadInfo.BufferSize;

Expand Down Expand Up @@ -1340,10 +1331,6 @@ static void SaveMiscGlobalStuff()
GetFMVInformation(&block->FMV_MessageNumber,&block->FMV_FrameNumber);
}





extern void DisplaySavesLeft()
{
char text [100];
Expand All @@ -1353,9 +1340,6 @@ extern void DisplaySavesLeft()
NewOnScreenMessage(text);
}




extern void ResetNumberOfSaves()
{
switch(AvP.Difficulty)
Expand All @@ -1370,7 +1354,7 @@ extern void ResetNumberOfSaves()
case I_Impossible :
NumberOfSavesLeft = NUM_SAVES_FOR_HARD_MODE;
break;

default:
break;
}
}

0 comments on commit 6a01356

Please sign in to comment.