From 22475d6d94e96056d1550dca00b32d00e3821649 Mon Sep 17 00:00:00 2001 From: Steven Fuller Date: Thu, 25 Dec 2014 12:00:00 +0100 Subject: Import icculus.org release (2014-12-25) --- src/avp/avpview.c | 19 +- src/avp/bh_waypt.c | 2 +- src/avp/davehook.cpp | 2 +- src/avp/game.c | 1 + src/avp/hud.c | 4 +- src/avp/mempool.c | 21 +- src/avp/psndproj.c | 2 +- src/avp/savegame.c | 1 + src/avp/shapes/cube.c | 1 + src/avp/support/consbind.cpp | 2 +- src/avp/win95/avpchunk.cpp | 10 +- src/avp/win95/ffread.cpp | 27 +- src/avp/win95/frontend/avp_intro.cpp | 2 +- src/avp/win95/frontend/avp_intro.h | 1 + src/avp/win95/frontend/avp_menus.c | 16 +- src/avp/win95/frontend/avp_userprofile.h | 5 +- src/avp/win95/gadgets/teletype.cpp | 4 + src/avp/win95/pathchnk.cpp | 4 +- src/avp/win95/strachnk.cpp | 8 +- src/avp/win95/system.c | 1 + src/cdplayer.c | 62 +- src/fixer.h | 1 + src/fmv.c | 3 +- src/fmv.h | 2 + src/include/shape.h | 2 +- src/kshape.c | 9 +- src/main.c | 24 +- src/main2.c | 1561 ++++++++++++++++++++++++++++++ src/maths.c | 22 +- src/md5.c | 2 +- src/menus.c | 4 +- src/module.c | 2 +- src/oglfunc.c | 23 +- src/oglfunc.h | 11 +- src/openal.c | 15 +- src/opengl.c | 76 +- src/sdl12/SDLMain.h | 16 + src/sdl12/SDLMain.m | 381 ++++++++ src/vdb.c | 39 +- src/win95/animchnk.cpp | 2 +- src/win95/animobs.cpp | 4 +- src/win95/animobs.hpp | 4 +- src/win95/chnkload.cpp | 10 +- src/win95/fragchnk.cpp | 6 +- src/win95/hash_tem.hpp | 2 +- src/win95/hierchnk.cpp | 6 +- src/win95/hierchnk.hpp | 4 +- src/win95/mishchnk.cpp | 2 +- src/win95/obchunk.cpp | 4 +- src/win95/shpchunk.cpp | 9 +- src/winfiles.c | 12 +- 51 files changed, 2263 insertions(+), 190 deletions(-) create mode 100644 src/main2.c create mode 100644 src/sdl12/SDLMain.h create mode 100644 src/sdl12/SDLMain.m (limited to 'src') diff --git a/src/avp/avpview.c b/src/avp/avpview.c index e982476..fd4fe21 100644 --- a/src/avp/avpview.c +++ b/src/avp/avpview.c @@ -16,6 +16,7 @@ #include "lighting.h" #include "weapons.h" #include "sfx.h" +#include "fmv.h" /* character extents data so you know where the player's eyes are */ #include "extents.h" #include "avp_userprofile.h" @@ -100,7 +101,7 @@ extern int GetSingleColourForPrimary(int Colour); extern void ColourFillBackBuffer(int FillColour); static void ModifyHeadOrientation(void); -int AVPViewVolumePlaneTest(CLIPPLANEBLOCK *cpb, DISPLAYBLOCK *dblockptr, int or); +int AVPViewVolumePlaneTest(CLIPPLANEBLOCK *cpb, DISPLAYBLOCK *dblockptr, int obr); @@ -875,16 +876,16 @@ void InitialiseRenderer(void) int AVPViewVolumeTest(VIEWDESCRIPTORBLOCK *VDB_Ptr, DISPLAYBLOCK *dblockptr) { - int or = dblockptr->ObRadius; + int obr = dblockptr->ObRadius; /* Perform the view volume plane tests */ if( - AVPViewVolumePlaneTest(&VDB_Ptr->VDB_ClipZPlane, dblockptr, or) && - AVPViewVolumePlaneTest(&VDB_Ptr->VDB_ClipLeftPlane, dblockptr, or) && - AVPViewVolumePlaneTest(&VDB_Ptr->VDB_ClipRightPlane, dblockptr, or) && - AVPViewVolumePlaneTest(&VDB_Ptr->VDB_ClipUpPlane, dblockptr, or) && - AVPViewVolumePlaneTest(&VDB_Ptr->VDB_ClipDownPlane, dblockptr, or)) + AVPViewVolumePlaneTest(&VDB_Ptr->VDB_ClipZPlane, dblockptr, obr) && + AVPViewVolumePlaneTest(&VDB_Ptr->VDB_ClipLeftPlane, dblockptr, obr) && + AVPViewVolumePlaneTest(&VDB_Ptr->VDB_ClipRightPlane, dblockptr, obr) && + AVPViewVolumePlaneTest(&VDB_Ptr->VDB_ClipUpPlane, dblockptr, obr) && + AVPViewVolumePlaneTest(&VDB_Ptr->VDB_ClipDownPlane, dblockptr, obr)) return Yes; else @@ -900,13 +901,13 @@ int AVPViewVolumeTest(VIEWDESCRIPTORBLOCK *VDB_Ptr, DISPLAYBLOCK *dblockptr) */ -int AVPViewVolumePlaneTest(CLIPPLANEBLOCK *cpb, DISPLAYBLOCK *dblockptr, int or) +int AVPViewVolumePlaneTest(CLIPPLANEBLOCK *cpb, DISPLAYBLOCK *dblockptr, int obr) { VECTORCH POPRelObView; MakeVector(&dblockptr->ObView, &cpb->CPB_POP, &POPRelObView); - if(DotProduct(&POPRelObView, &cpb->CPB_Normal) < or) return Yes; + if(DotProduct(&POPRelObView, &cpb->CPB_Normal) < obr) return Yes; else return No; } diff --git a/src/avp/bh_waypt.c b/src/avp/bh_waypt.c index 899c33a..b1408f4 100644 --- a/src/avp/bh_waypt.c +++ b/src/avp/bh_waypt.c @@ -131,7 +131,7 @@ int NPCGetWaypointDirection(WAYPOINT_HEADER *waypoints, STRATEGYBLOCK *sbPtr, VE //Base shift value on strategy block so that the aliens don't keep changing their minds //about which route to take - GlobalLinkShift=(((int)sbPtr)&0xffff)>>4; + GlobalLinkShift=(((intptr_t)sbPtr)&0xffff)>>4; if (FindBestRoute(¤t_route,waypoints)==0) { /* Yuck! */ textprint("Waypoint dropout: no continuous route!\n"); diff --git a/src/avp/davehook.cpp b/src/avp/davehook.cpp index daa7c59..0571148 100644 --- a/src/avp/davehook.cpp +++ b/src/avp/davehook.cpp @@ -54,7 +54,7 @@ #define UseLocalAssert Yes #include "ourasert.h" -#include "frontend/avp_menus.h" +#include "avp_menus.h" /* Version settings ************************************************/ /* Constants *******************************************************/ diff --git a/src/avp/game.c b/src/avp/game.c index c7b8e02..c818a21 100644 --- a/src/avp/game.c +++ b/src/avp/game.c @@ -24,6 +24,7 @@ #include "psndplat.h" #include "particle.h" #include "sfx.h" +#include "fmv.h" #include "version.h" #include "bh_rubberduck.h" #include "bh_marin.h" diff --git a/src/avp/hud.c b/src/avp/hud.c index ee27bf9..bc945a1 100644 --- a/src/avp/hud.c +++ b/src/avp/hud.c @@ -101,7 +101,7 @@ int predHUDSoundHandle=SOUND_NOACTIVEINDEX; static int HUD_PrimaryRounds; static int HUD_SecondaryRounds; /* numerics buffer - the marine has more digits on his HUD than the other species */ -char ValueOfHUDDigit[MAX_NO_OF_COMMON_HUD_DIGITS]; +char ValueOfHUDDigit[MAX_NO_OF_MARINE_HUD_DIGITS]; #define PREDATOR_LOCK_ON_TIME (ONE_FIXED*5/3) @@ -237,7 +237,7 @@ void InitMarineHUD(void) { int i; - for (i=0; i MEMORY_BLOCK_SIZE) + { + // fatal error + return NULL; + } + // align up + amount = (amount + 7) & ~7; + if(amount>MemoryLeft) { CurrentMemoryBlock++; GLOBALASSERT(CurrentMemoryBlock= MAX_NUM_MEMORY_BLOCK) + { + // fatal error + return NULL; + } MemoryBlocks[CurrentMemoryBlock]=AllocateMem(MEMORY_BLOCK_SIZE); - GLOBALASSERT(MemoryBlocks[CurrentMemoryBlock]); - + GLOBALASSERT(MemoryBlocks[CurrentMemoryBlock]!=NULL); + if (MemoryBlocks[CurrentMemoryBlock] == NULL) + { + // fatal error + return NULL; + } MemoryLeft=MEMORY_BLOCK_SIZE; MemoryPoolPtr=MemoryBlocks[CurrentMemoryBlock]; diff --git a/src/avp/psndproj.c b/src/avp/psndproj.c index 4f8e959..59aad05 100644 --- a/src/avp/psndproj.c +++ b/src/avp/psndproj.c @@ -856,7 +856,7 @@ int FindAndLoadWavFile(int soundNum,char* wavFileName) #if LOAD_SOUND_FROM_FAST_FILE //first look in fast file { - unsigned nLen; + size_t nLen; if(ffreadbuf(sound_name,&nLen)) { return LoadWavFromFastFile(soundNum,sound_name); diff --git a/src/avp/savegame.c b/src/avp/savegame.c index 0047c99..5125995 100644 --- a/src/avp/savegame.c +++ b/src/avp/savegame.c @@ -30,6 +30,7 @@ #include "game_statistics.h" #include "avp_userprofile.h" #include "huddefs.h" +#include "fmv.h" #include "savegame.h" #include "huffman.hpp" diff --git a/src/avp/shapes/cube.c b/src/avp/shapes/cube.c index 291ae99..72c03b8 100644 --- a/src/avp/shapes/cube.c +++ b/src/avp/shapes/cube.c @@ -1,4 +1,5 @@ #include +#include #include "system.h" #include "shape.h" diff --git a/src/avp/support/consbind.cpp b/src/avp/support/consbind.cpp index 6477673..527210a 100644 --- a/src/avp/support/consbind.cpp +++ b/src/avp/support/consbind.cpp @@ -29,7 +29,7 @@ #define UseLocalAssert Yes #include "ourasert.h" -#include "frontend/avp_menus.h" +#include "avp_menus.h" /* Version settings ************************************************/ diff --git a/src/avp/win95/avpchunk.cpp b/src/avp/win95/avpchunk.cpp index 5731d47..b247797 100644 --- a/src/avp/win95/avpchunk.cpp +++ b/src/avp/win95/avpchunk.cpp @@ -242,7 +242,7 @@ AVP_Generator_Extra_Name_Chunk::AVP_Generator_Extra_Name_Chunk(Chunk_With_Childr AVP_Generator_Extra_Name_Chunk::~AVP_Generator_Extra_Name_Chunk() { - delete name; + delete [] name; } void AVP_Generator_Extra_Name_Chunk::fill_data_block(char* data_start) @@ -292,7 +292,7 @@ AVP_Generator_Extended_Settings_Chunk::AVP_Generator_Extended_Settings_Chunk(Chu AVP_Generator_Extended_Settings_Chunk::AVP_Generator_Extended_Settings_Chunk(Chunk_With_Children* parent) :Chunk(parent,"GENEXSET") { - weights=new AVP_Generator_Weighting; + weights=(AVP_Generator_Weighting *)new unsigned char[sizeof(AVP_Generator_Weighting)]; memset(weights,0,sizeof(AVP_Generator_Weighting)); weights->data_size=sizeof(AVP_Generator_Weighting); GenLimit=pad1=pad2=pad3=0; @@ -303,7 +303,7 @@ AVP_Generator_Extended_Settings_Chunk::AVP_Generator_Extended_Settings_Chunk(Chu AVP_Generator_Extended_Settings_Chunk::~AVP_Generator_Extended_Settings_Chunk() { - delete weights; + delete [] weights; } void AVP_Generator_Extended_Settings_Chunk::fill_data_block (char * data) @@ -580,7 +580,7 @@ AVP_Environment_Settings_Chunk::AVP_Environment_Settings_Chunk(Chunk_With_Childr AVP_Environment_Settings_Chunk::AVP_Environment_Settings_Chunk(Chunk_With_Children* parent) :Chunk(parent,"AVPENVIR") { - settings=new AVP_Environment_Settings; + settings=(AVP_Environment_Settings*)new unsigned char[sizeof(AVP_Environment_Settings)]; settings->data_size=sizeof(AVP_Environment_Settings); settings->sky_colour_red=200; settings->sky_colour_green=200; @@ -601,7 +601,7 @@ AVP_Environment_Settings_Chunk::AVP_Environment_Settings_Chunk(Chunk_With_Childr AVP_Environment_Settings_Chunk::~AVP_Environment_Settings_Chunk() { - delete settings; + delete [] settings; } void AVP_Environment_Settings_Chunk::fill_data_block (char * data_start) diff --git a/src/avp/win95/ffread.cpp b/src/avp/win95/ffread.cpp index e5ba27e..cc6aa1d 100644 --- a/src/avp/win95/ffread.cpp +++ b/src/avp/win95/ffread.cpp @@ -114,7 +114,7 @@ FFDataI::FFDataI(char const *_filename, void *_data, size_t _length) FFDataI::FFDataI(FFDataI const & ffd, ptrdiff_t offset) : filename(0) -, data((void *)((size_t)ffd.data + offset)) +, data((void *)((intptr_t)ffd.data + offset)) , length(ffd.length) { if (ffd.filename) @@ -212,7 +212,7 @@ FFHeaderI::FFHeaderI(FFHeaderI const & ffh) data = malloc(length); memcpy(data,ffh.data,length); } - ptrdiff_t offset = (size_t)data - (size_t)ffh.data; + ptrdiff_t offset = (intptr_t)data - (intptr_t)ffh.data; for (int i=0; i i_file(&ffh.files[i]); !i_file.done(); i_file.next()) @@ -243,7 +243,7 @@ FFHeaderI & FFHeaderI::operator = (FFHeaderI const & ffh) data = malloc(length); memcpy(data,ffh.data,length); } - ptrdiff_t offset = (size_t)data - (size_t)ffh.data; + ptrdiff_t offset = (intptr_t)data - (intptr_t)ffh.data; for (int i=0; i i_file(&ffh.files[i]); !i_file.done(); i_file.next()) @@ -300,9 +300,10 @@ FFError FFHeaderI::Read(char const *_filename) Clear(); char magic[4]; - unsigned long rffl_version; - size_t num_files; - size_t total_headsize; + uint32_t rffl_version; + uint32_t num_files; + uint32_t total_headsize; + uint32_t data_length; DWORD bytes_read; @@ -310,8 +311,10 @@ FFError FFHeaderI::Read(char const *_filename) READ_FILE(filename,(void)0,fclose(h),h,&rffl_version,4,bytes_read,0) READ_FILE(filename,(void)0,fclose(h),h,&num_files,4,bytes_read,0) READ_FILE(filename,(void)0,fclose(h),h,&total_headsize,4,bytes_read,0) - READ_FILE(filename,(void)0,fclose(h),h,&length,4,bytes_read,0) - + READ_FILE(filename,(void)0,fclose(h),h,&data_length,4,bytes_read,0) + + length = data_length; + if (strncmp(magic,"RFFL",4)) { ReportError(filename,"Incorrect file type"); @@ -341,14 +344,14 @@ FFError FFHeaderI::Read(char const *_filename) for (unsigned int i=0; i #include + +int SelectDirectDrawObject(void *pGUID); extern void StartMenuBackgroundBink(void); extern int PlayMenuBackgroundBink(void); @@ -45,10 +48,15 @@ extern void EndMenuBackgroundBink(void); extern int IDemandSelect(void); extern char *GetVideoModeDescription(void); +extern char *GetVideoModeDescription2(void); +extern char *GetVideoModeDescription3(void); extern void PreviousVideoMode(void); +extern void PreviousVideoMode2(void); extern void NextVideoMode(void); +extern void NextVideoMode2(void); extern void SaveVideoModeSettings(void); - +extern void LoadDeviceAndVideoModePreferences(void); +extern void SaveDeviceAndVideoModePreferences(void); extern void MakeSelectSessionMenu(void); @@ -665,11 +673,12 @@ extern void AvP_UpdateMenus(void) { int i; AVP_USER_PROFILE *profilePtr = GetFirstUserProfile(); + time_t FileTime = profilePtr->FileTime; for (i=0; iName,MENU_CENTREX,MENU_CENTREY-100,ONE_FIXED,AVPMENUFORMAT_CENTREJUSTIFIED); - RenderSmallMenuText(ctime(&profilePtr->FileTime),MENU_CENTREX,MENU_CENTREY-70,ONE_FIXED,AVPMENUFORMAT_CENTREJUSTIFIED); + RenderSmallMenuText(ctime(&FileTime),MENU_CENTREX,MENU_CENTREY-70,ONE_FIXED,AVPMENUFORMAT_CENTREJUSTIFIED); RenderMenu(); RenderHelpString(); @@ -1727,6 +1736,7 @@ static void RenderUserProfileSelectMenu(void) if (y>=-150 && y<=150) { char *textPtr = profilePtr->Name; + time_t FileTime = profilePtr->FileTime; int b; int targetBrightness; @@ -1758,7 +1768,7 @@ static void RenderUserProfileSelectMenu(void) b=Brightness[i]; RenderMenuText_Clipped(textPtr,MENU_CENTREX,MENU_CENTREY+y-60,b,AVPMENUFORMAT_CENTREJUSTIFIED,MENU_CENTREY-60-100,MENU_CENTREY-30+150); if (i > 0) - RenderSmallMenuText(ctime(&profilePtr->FileTime),MENU_CENTREX,MENU_CENTREY+y-30,b,AVPMENUFORMAT_CENTREJUSTIFIED); + RenderSmallMenuText(ctime(&FileTime),MENU_CENTREX,MENU_CENTREY+y-30,b,AVPMENUFORMAT_CENTREJUSTIFIED); } } diff --git a/src/avp/win95/frontend/avp_userprofile.h b/src/avp/win95/frontend/avp_userprofile.h index a630373..5d26a69 100644 --- a/src/avp/win95/frontend/avp_userprofile.h +++ b/src/avp/win95/frontend/avp_userprofile.h @@ -69,9 +69,10 @@ typedef struct { char Name[MAX_SIZE_OF_USERS_NAME+1]; - time_t FileTime; + // SBF: 32-bit time_t + uint32_t FileTime; - // used to be an incomplete SYSTEMTIME struct, TimeLastUpdated + // SBF: used to be an incomplete SYSTEMTIME struct, TimeLastUpdated int unused[6]; /* KJL 15:14:12 10/12/98 - array to hold level completion data diff --git a/src/avp/win95/gadgets/teletype.cpp b/src/avp/win95/gadgets/teletype.cpp index e7d4a7c..ad9cce8 100644 --- a/src/avp/win95/gadgets/teletype.cpp +++ b/src/avp/win95/gadgets/teletype.cpp @@ -292,6 +292,10 @@ TeletypeDaemon :: TeletypeDaemon { GLOBALASSERT( pTeletypeGadg ); + #if SupportTeletypeSound + SoundHandle = SOUND_NOACTIVEINDEX; + #endif + pTeletypeGadg_Val = pTeletypeGadg; fFinished_Val = No; diff --git a/src/avp/win95/pathchnk.cpp b/src/avp/win95/pathchnk.cpp index d37897e..044251a 100644 --- a/src/avp/win95/pathchnk.cpp +++ b/src/avp/win95/pathchnk.cpp @@ -45,8 +45,8 @@ AVP_Path_Chunk::AVP_Path_Chunk(Chunk_With_Children* parent,const char* data,size AVP_Path_Chunk::~AVP_Path_Chunk() { - if(PathName) delete PathName; - if(Path) delete Path; + if(PathName) delete [] PathName; + if(Path) delete [] Path; } void AVP_Path_Chunk::fill_data_block(char* data_start) diff --git a/src/avp/win95/strachnk.cpp b/src/avp/win95/strachnk.cpp index 6a3cf93..2ecde1d 100644 --- a/src/avp/win95/strachnk.cpp +++ b/src/avp/win95/strachnk.cpp @@ -360,7 +360,7 @@ Virtual_Object_Properties_Chunk::Virtual_Object_Properties_Chunk(Chunk_With_Chil Virtual_Object_Properties_Chunk::~Virtual_Object_Properties_Chunk() { - if(name)delete name; + if(name)delete [] name; } size_t Virtual_Object_Properties_Chunk::size_chunk() @@ -1046,8 +1046,8 @@ MultiSwitchStrategy::MultiSwitchStrategy(const char* data_start,size_t /*size*/) MultiSwitchStrategy::~MultiSwitchStrategy() { - if(Targets)delete Targets; - if(LinkedSwitches)delete LinkedSwitches; + if(Targets)delete [] Targets; + if(LinkedSwitches)delete [] LinkedSwitches; } @@ -1523,7 +1523,7 @@ TrackStrategy::~TrackStrategy() delete point_effects[i]; } if(point_effects) - delete point_effects; + delete [] point_effects; } size_t TrackStrategy::GetStrategySize() diff --git a/src/avp/win95/system.c b/src/avp/win95/system.c index e2c9345..6fc1279 100644 --- a/src/avp/win95/system.c +++ b/src/avp/win95/system.c @@ -21,6 +21,7 @@ #include "huddefs.h" #include "hud.h" //#include "hudgfx.h" +#include "fmv.h" #include "font.h" #include "bh_gener.h" #include "pvisible.h" diff --git a/src/cdplayer.c b/src/cdplayer.c index b8bf9ec..1d8dfe3 100644 --- a/src/cdplayer.c +++ b/src/cdplayer.c @@ -8,14 +8,15 @@ #include "win95/cd_player.h" #include "cdplayer.h" +/* cd_player.cpp */ +int CDPlayerVolume; + +#if SDL_MAJOR_VERSION < 2 static int HaveCDROM = 0; static SDL_CD *cdrom = NULL; /* ** */ -/* cd_player.cpp */ -int CDPlayerVolume; - void CheckCDVolume() { /* @@ -155,3 +156,58 @@ void CDDA_SwitchOn() fprintf(stderr, "CDDA_SwitchOn()\n"); */ } + +#else + +// What's a CD? + +void CheckCDVolume() +{ +} + +/* ** */ + +void CDDA_Start() +{ +} + +void CDDA_End() +{ +} + +void CDDA_ChangeVolume(int volume) +{ +} + +int CDDA_CheckNumberOfTracks() +{ + return 0; +} + +int CDDA_IsOn() +{ + return 0; +} + +int CDDA_IsPlaying() +{ + return 0; +} + +void CDDA_Play(int CDDATrack) +{ +} + +void CDDA_PlayLoop(int CDDATrack) +{ +} + +void CDDA_Stop() +{ +} + +void CDDA_SwitchOn() +{ +} + +#endif diff --git a/src/fixer.h b/src/fixer.h index 2479780..3d39012 100644 --- a/src/fixer.h +++ b/src/fixer.h @@ -9,6 +9,7 @@ #include #include #include +#include #define Yes 1 // sigh #define No 0 // sigh diff --git a/src/fmv.c b/src/fmv.c index 8edbd65..eea329b 100644 --- a/src/fmv.c +++ b/src/fmv.c @@ -11,7 +11,7 @@ #include "fmv.h" #include "avp_menus.h" #include "avp_userprofile.h" -#include "oglfunc.h" +#include "oglfunc.h" // move this into opengl.c #define UseLocalAssert 1 #include "ourasert.h" @@ -332,6 +332,7 @@ void UpdateFMVTexture(FMVTEXTURE *ftPtr) dstPtr += 3; } while(--pixels); +//#warning move this into opengl.c // update the opengl texture pglBindTexture(GL_TEXTURE_2D, ftPtr->ImagePtr->D3DTexture->id); diff --git a/src/fmv.h b/src/fmv.h index 4d7b5db..364d963 100644 --- a/src/fmv.h +++ b/src/fmv.h @@ -39,4 +39,6 @@ void UpdateAllFMVTextures(void); void ScanImagesForFMVs(void); void ReleaseAllFMVTextures(void); +void PlayBinkedFMV(char *filenamePtr); + #endif diff --git a/src/include/shape.h b/src/include/shape.h index cc5e986..6fe2edf 100644 --- a/src/include/shape.h +++ b/src/include/shape.h @@ -890,7 +890,7 @@ typedef struct txanimframe { int txf_orienty; int txf_numuvs; int *txf_uvdata; - int txf_image; + intptr_t txf_image; // SBF: 64HACK - needed to match TXANIMFRAME_MVS } TXANIMFRAME; diff --git a/src/kshape.c b/src/kshape.c index 7107c0b..a17d305 100644 --- a/src/kshape.c +++ b/src/kshape.c @@ -3015,8 +3015,11 @@ void CreateTxAnimUVArray(int *txa_data, int *uv_array, int *shapeitemptr) /* The sequence # will have been copied across by the control block */ - sequence = *txa_data++; - + sequence = *txa_data; + + // SBF: 64HACK - skip over the rest of the int* + txa_data = (int *)((intptr_t) txa_data + sizeof(int *)); + #if 0 textprint("sequence = %d\n", sequence); #endif @@ -4027,7 +4030,7 @@ void AddShape(DISPLAYBLOCK *dptr, VIEWDESCRIPTORBLOCK *VDB_Ptr) { if (dptr->ObStrategyBlock->I_SBtype==I_BehaviourInanimateObject) { - INANIMATEOBJECT_STATUSBLOCK* objStatPtr = dptr->ObStrategyBlock->SBdataptr; + INANIMATEOBJECT_STATUSBLOCK* objStatPtr = (INANIMATEOBJECT_STATUSBLOCK*) dptr->ObStrategyBlock->SBdataptr; if(objStatPtr->typeId==IOT_FieldCharge) { diff --git a/src/main.c b/src/main.c index eff537f..20b8e97 100644 --- a/src/main.c +++ b/src/main.c @@ -246,12 +246,17 @@ typedef struct VideoModeStruct VideoModeStruct VideoModeList[] = { { 512, 384, 0 }, { 640, 480, 0 }, +{ 720, 480, 0 }, { 800, 600, 0 }, { 1024, 768, 0 }, { 1152, 864, 0 }, -{ 1280, 960, 0, }, +{ 1280, 720, 0 }, +{ 1280, 768, 0 }, +{ 1280, 960, 0 }, { 1280, 1024, 0 }, -{ 1600, 1200, 0 } +{ 1600, 1200, 0 }, +{ 1920, 1080, 0 }, +{ 1920, 1200, 0 } }; int CurrentVideoMode; @@ -361,7 +366,8 @@ int InitSDL() atexit(SDL_Quit); - SDL_AvailableVideoModes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_OPENGL); + // needs to be cleaned up; SDL_VideoModeOK and SDL_ListModes aren't compatible + SDL_AvailableVideoModes = (SDL_Rect **)-1; //SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_OPENGL); if (SDL_AvailableVideoModes == NULL) return -1; @@ -544,7 +550,6 @@ int SetOGLVideoMode(int Width, int Height) { SDL_GrabMode isgrab; int flags; - char *ext; ScanDrawMode = ScanDrawD3DHardwareRGB; GotMouse = 1; @@ -580,7 +585,12 @@ int SetOGLVideoMode(int Width, int Height) SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - + + // These should be configurable video options. + //SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); + //SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); + SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); + if ((surface = SDL_SetVideoMode(Width, Height, 0, flags)) == NULL) { fprintf(stderr, "(OpenGL) SDL SetVideoMode failed: %s\n", SDL_GetError()); exit(EXIT_FAILURE); @@ -624,8 +634,6 @@ int SetOGLVideoMode(int Width, int Height) pglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - pglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - ScreenDescriptorBlock.SDB_Width = Width; ScreenDescriptorBlock.SDB_Height = Height; ScreenDescriptorBlock.SDB_CentreX = Width/2; @@ -637,8 +645,6 @@ int SetOGLVideoMode(int Width, int Height) ScreenDescriptorBlock.SDB_ClipUp = 0; ScreenDescriptorBlock.SDB_ClipDown = Height; - ext = (char *) pglGetString(GL_EXTENSIONS); - load_ogl_functions(1); InitOpenGL(); diff --git a/src/main2.c b/src/main2.c new file mode 100644 index 0000000..cdc353c --- /dev/null +++ b/src/main2.c @@ -0,0 +1,1561 @@ +#include +#include +#include +#include + +#include "SDL.h" +#include "oglfunc.h" + +#if !defined(_MSC_VER) +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include +#endif + +#include "fixer.h" + +#include "3dc.h" +#include "platform.h" +#include "inline.h" +#include "gamedef.h" +#include "gameplat.h" +#include "ffstdio.h" +#include "vision.h" +#include "comp_shp.h" +#include "avp_envinfo.h" +#include "stratdef.h" +#include "bh_types.h" +#include "avp_userprofile.h" +#include "pldnet.h" +#include "cdtrackselection.h" +#include "gammacontrol.h" +#include "opengl.h" +#include "avp_menus.h" +#include "avp_mp_config.h" +#include "npcsetup.h" +#include "cdplayer.h" +#include "hud.h" +#include "player.h" +#include "mempool.h" +#include "avpview.h" +#include "consbind.hpp" +#include "progress_bar.h" +#include "scrshot.hpp" +#include "version.h" +#include "fmv.h" + +void RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_CHAR(char Ch); +void RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(int wParam); + +char LevelName[] = {"predbit6\0QuiteALongNameActually"}; /* the real way to load levels */ + +int DebouncedGotAnyKey; +unsigned char DebouncedKeyboardInput[MAX_NUMBER_OF_INPUT_KEYS]; +int GotJoystick; +int GotMouse; +int JoystickEnabled; +int MouseVelX; +int MouseVelY; + +extern int ScanDrawMode; +extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock; +extern unsigned char KeyboardInput[MAX_NUMBER_OF_INPUT_KEYS]; +extern unsigned char GotAnyKey; +extern int NormalFrameTime; + +SDL_Window *window; +SDL_GLContext context; +SDL_Surface *surface; + +SDL_Joystick *joy; +JOYINFOEX JoystickData; +JOYCAPS JoystickCaps; + +/* defaults */ +static int WantFullscreen = 0; +static int WantMouseGrab = 0; +int WantSound = 1; +static int WantCDRom = 0; +static int WantJoystick = 0; + +static int ViewportWidth; +static int ViewportHeight; + +/* originally was "/usr/lib/libGL.so.1:/usr/lib/tls/libGL.so.1:/usr/X11R6/lib/libGL.so" */ +static const char * opengl_library = NULL; + +/* ** */ + +static void IngameKeyboardInput_ClearBuffer(void) +{ + // clear the keyboard state + memset((void*) KeyboardInput, 0, MAX_NUMBER_OF_INPUT_KEYS); + GotAnyKey = 0; +} + +void DirectReadKeyboard() +{ +} + +void DirectReadMouse() +{ +} + +void ReadJoysticks() +{ + int axes, balls, hats; + Uint8 hat; + + JoystickData.dwXpos = 0; + JoystickData.dwYpos = 0; + JoystickData.dwRpos = 0; + JoystickData.dwUpos = 0; + JoystickData.dwVpos = 0; + JoystickData.dwPOV = (DWORD) -1; + + if (joy == NULL || !GotJoystick) { + return; + } + + SDL_JoystickUpdate(); + + axes = SDL_JoystickNumAxes(joy); + balls = SDL_JoystickNumBalls(joy); + hats = SDL_JoystickNumHats(joy); + + if (axes > 0) { + JoystickData.dwXpos = SDL_JoystickGetAxis(joy, 0) + 32768; + } + if (axes > 1) { + JoystickData.dwYpos = SDL_JoystickGetAxis(joy, 1) + 32768; + } + + if (hats > 0) { + hat = SDL_JoystickGetHat(joy, 0); + + switch (hat) { + default: + case SDL_HAT_CENTERED: + JoystickData.dwPOV = (DWORD) -1; + break; + case SDL_HAT_UP: + JoystickData.dwPOV = 0; + break; + case SDL_HAT_RIGHT: + JoystickData.dwPOV = 9000; + break; + case SDL_HAT_DOWN: + JoystickData.dwPOV = 18000; + break; + case SDL_HAT_LEFT: + JoystickData.dwPOV = 27000; + break; + case SDL_HAT_RIGHTUP: + JoystickData.dwPOV = 4500; + break; + case SDL_HAT_RIGHTDOWN: + JoystickData.dwPOV = 13500; + break; + case SDL_HAT_LEFTUP: + JoystickData.dwPOV = 31500; + break; + case SDL_HAT_LEFTDOWN: + JoystickData.dwPOV = 22500; + break; + } + } +} + +/* ** */ + +unsigned char *GetScreenShot24(int *width, int *height) +{ +#if 0//REVIEW + unsigned char *buf; +// Uint16 redtable[256], greentable[256], bluetable[256]; + + if (surface == NULL) { + return NULL; + } + + buf = (unsigned char *)malloc(surface->w * surface->h * 3); + + if (surface->flags & SDL_WINDOW_OPENGL) { + pglPixelStorei(GL_PACK_ALIGNMENT, 1); + pglPixelStorei(GL_UNPACK_ALIGNMENT, 1); + pglReadPixels(0, 0, surface->w, surface->h, GL_RGB, GL_UNSIGNED_BYTE, buf); + } else { + unsigned char *ptrd; + unsigned short int *ptrs; + int x, y; + + if (SDL_MUSTLOCK(surface)) { + if (SDL_LockSurface(surface) < 0) { + free(buf); + return NULL; /* ... */ + } + } + + ptrd = buf; + for (y = 0; y < surface->h; y++) { + ptrs = (unsigned short *)(((unsigned char *)surface->pixels) + (surface->h-y-1)*surface->pitch); + for (x = 0; x < surface->w; x++) { + unsigned int c; + + c = *ptrs; + ptrd[0] = (c & 0xF800)>>8; + ptrd[1] = (c & 0x07E0)>>3; + ptrd[2] = (c & 0x001F)<<3; + + ptrs++; + ptrd += 3; + } + } + + if (SDL_MUSTLOCK(surface)) { + SDL_UnlockSurface(surface); + } + } + + *width = surface->w; + *height = surface->h; + +#if 0 + if (SDL_GetGammaRamp(redtable, greentable, bluetable) != -1) { + unsigned char *ptr; + int i; + + ptr = buf; + for (i = 0; i < surface->w*surface->h; i++) { + ptr[i*3+0] = redtable[ptr[i*3+0]]>>8; + ptr[i*3+1] = greentable[ptr[i*3+1]]>>8; + ptr[i*3+2] = bluetable[ptr[i*3+2]]>>8; + ptr += 3; + } + } +#endif + return buf; +#endif + return NULL; +} + +/* ** */ + +PROCESSORTYPES ReadProcessorType() +{ + return PType_PentiumMMX; +} + +/* ** */ + +typedef struct VideoModeStruct +{ + int w; + int h; + int available; +} VideoModeStruct; +VideoModeStruct VideoModeList[] = { + { 512, 384, 0 }, + { 640, 480, 0 }, + { 800, 600, 0 }, + { 1024, 768, 0 }, + { 1152, 864, 0 }, + { 1280, 720, 0 }, + { 1280, 960, 0 }, + { 1280, 1024, 0 }, + { 1600, 1200, 0 }, + { 1920, 1080, 0 } +}; + +int CurrentVideoMode; +const int TotalVideoModes = sizeof(VideoModeList) / sizeof(VideoModeList[0]); + +void LoadDeviceAndVideoModePreferences() +{ + FILE *fp; + int mode; + + fp = OpenGameFile("AvP_TempVideo.cfg", FILEMODE_READONLY, FILETYPE_CONFIG); + + if (fp != NULL) { + if (fscanf(fp, "%d", &mode) == 1) { + fclose(fp); + + if (mode >= 0 && mode < TotalVideoModes && VideoModeList[mode].available) { + CurrentVideoMode = mode; + return; + } + } else { + fclose(fp); + } + } + + /* No, or invalid, mode found */ + + /* Try 640x480 first */ + if (VideoModeList[1].available) { + CurrentVideoMode = 1; + } else { + int i; + + for (i = 0; i < TotalVideoModes; i++) { + if (VideoModeList[i].available) { + CurrentVideoMode = i; + break; + } + } + } +} + +void SaveDeviceAndVideoModePreferences() +{ + FILE *fp; + + fp = OpenGameFile("AvP_TempVideo.cfg", FILEMODE_WRITEONLY, FILETYPE_CONFIG); + if (fp != NULL) { + fprintf(fp, "%d\n", CurrentVideoMode); + fclose(fp); + } +} + +void PreviousVideoMode2() +{ + int cur = CurrentVideoMode; + + do { + if (cur == 0) + cur = TotalVideoModes; + cur--; + if (cur == CurrentVideoMode) + return; + } while(!VideoModeList[cur].available); + + CurrentVideoMode = cur; +} + +void NextVideoMode2() +{ + int cur = CurrentVideoMode; + + do { + cur++; + if (cur == TotalVideoModes) + cur = 0; + + if (cur == CurrentVideoMode) + return; + } while(!VideoModeList[cur].available); + + CurrentVideoMode = cur; +} + +char *GetVideoModeDescription2() +{ + return "SDL2"; +} + +char *GetVideoModeDescription3() +{ + static char buf[64]; + + _snprintf(buf, 64, "%dx%d", VideoModeList[CurrentVideoMode].w, VideoModeList[CurrentVideoMode].h); + + return buf; +} + +int InitSDL() +{ + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + fprintf(stderr, "SDL Init failed: %s\n", SDL_GetError()); + exit(EXIT_FAILURE); + } + + atexit(SDL_Quit); + +#if 0 + SDL_Rect **SDL_AvailableVideoModes; + SDL_AvailableVideoModes = SDL_ListModes(NULL, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL); + if (SDL_AvailableVideoModes == NULL) + return -1; + + if (SDL_AvailableVideoModes != (SDL_Rect **)-1) { + int i, j, foundit; + + foundit = 0; + for (i = 0; i < TotalVideoModes; i++) { + SDL_Rect **modes = SDL_AvailableVideoModes; + + for (j = 0; modes[j]; j++) { + if (modes[j]->w >= VideoModeList[i].w && + modes[j]->h >= VideoModeList[i].h) { + if (SDL_VideoModeOK(VideoModeList[i].w, VideoModeList[i].h, 16, SDL_FULLSCREEN | SDL_OPENGL)) { + /* assume SDL isn't lying to us */ + VideoModeList[i].available = 1; + + foundit = 1; + } + break; + } + } + } + if (foundit == 0) + return -1; + } else { + int i, foundit; + + foundit = 0; + for (i = 0; i < TotalVideoModes; i++) { + if (SDL_VideoModeOK(VideoModeList[i].w, VideoModeList[i].h, 16, SDL_FULLSCREEN | SDL_OPENGL)) { + /* assume SDL isn't lying to us */ + VideoModeList[i].available = 1; + + foundit = 1; + } + } + + if (foundit == 0) + return -1; + } +#endif + +{ + int i; + + for (i = 0; i < TotalVideoModes; i++) { + //if (SDL_VideoModeOK(VideoModeList[i].w, VideoModeList[i].h, 16, SDL_FULLSCREEN | SDL_OPENGL)) { + /* assume SDL isn't lying to us */ + VideoModeList[i].available = 1; + + //foundit = 1; + //} + } +} + + LoadDeviceAndVideoModePreferences(); + + if (WantJoystick) { + SDL_InitSubSystem(SDL_INIT_JOYSTICK); + + if (SDL_NumJoysticks() > 0) { + /* TODO: make joystick number a configuration parameter */ + + joy = SDL_JoystickOpen(0); + if (joy) { + GotJoystick = 1; + } + + JoystickCaps.wCaps = 0; /* no rudder... ? */ + + JoystickData.dwXpos = 0; + JoystickData.dwYpos = 0; + JoystickData.dwRpos = 0; + JoystickData.dwUpos = 0; + JoystickData.dwVpos = 0; + JoystickData.dwPOV = (DWORD) -1; + } + } + + Uint32 rmask, gmask, bmask, amask; + + // pre-create the software surface in OpenGL RGBA order + // menus.c assumes RGB565; possible to support both? +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x0000f800; + gmask = 0x000007e0; + bmask = 0x0000001f; + amask = 0x00000000; +#endif + + surface = SDL_CreateRGBSurface(0, 640, 480, 16, rmask, gmask, bmask, amask); + if (surface == NULL) { + return -1; + } + + return 0; +} + +/* ** */ +static void load_opengl_library(const char *lib) +{ +#if 0//REVIEW + char tmppath[PATH_MAX]; + size_t len, copylen; + + if (lib == NULL) { + if (SDL_GL_LoadLibrary(NULL) == 0) { + /* success */ + return; + } + + fprintf( stderr, "ERROR: no opengl libraries given\n" ); + exit( EXIT_FAILURE ); + } + + while (lib != NULL && *lib) { + len = strcspn(lib, ":"); + + copylen = min(len, PATH_MAX-1); + + strncpy(tmppath, lib, copylen); + tmppath[copylen] = 0; + + if (SDL_GL_LoadLibrary(tmppath) == 0) { + /* success */ + return; + } + + lib += len; + lib += strspn(lib, ":"); + } + + fprintf(stderr, "ERROR: unable to initialize opengl library: %s\n", SDL_GetError()); + exit(EXIT_FAILURE); +#endif +} + +int SetSoftVideoMode(int Width, int Height, int Depth) +{ + //TODO: clear surface + + ScanDrawMode = ScanDrawD3DHardwareRGB; + GotMouse = 1; + + // reset input + IngameKeyboardInput_ClearBuffer(); + + ScreenDescriptorBlock.SDB_Width = Width; + ScreenDescriptorBlock.SDB_Height = Height; + ScreenDescriptorBlock.SDB_CentreX = Width/2; + ScreenDescriptorBlock.SDB_CentreY = Height/2; + ScreenDescriptorBlock.SDB_ProjX = Width/2; + ScreenDescriptorBlock.SDB_ProjY = Height/2; + ScreenDescriptorBlock.SDB_ClipLeft = 0; + ScreenDescriptorBlock.SDB_ClipRight = Width; + ScreenDescriptorBlock.SDB_ClipUp = 0; + ScreenDescriptorBlock.SDB_ClipDown = Height; + + return 0; +} + +static int SDLCALL SDLEventFilter(void* userData, SDL_Event* event) { + (void) userData; + + //printf("SDLEventFilter: %d\n", event->type); + + switch (event->type) { + case SDL_APP_TERMINATING: + AvP.MainLoopRunning = 0; /* TODO */ + break; + } + + return 1; +} + +int SetOGLVideoMode(int Width, int Height) +{ + int oldflags; + int flags; + + ScanDrawMode = ScanDrawD3DHardwareRGB; + GotMouse = 1; + + if (window == NULL) { + load_ogl_functions(0); + + /* + if (window != NULL) { + oldflags = SDL_GetWindowFlags(window); + + SDL_DestroyWindow(window); + } + + */ + flags = SDL_WINDOW_OPENGL; + if (WantFullscreen) { + flags |= SDL_WINDOW_FULLSCREEN; + } + + // reset input + IngameKeyboardInput_ClearBuffer(); + + // force restart the video system + SDL_QuitSubSystem(SDL_INIT_VIDEO); + SDL_InitSubSystem(SDL_INIT_VIDEO); + + load_opengl_library(opengl_library); + + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + + // These should be configurable video options. + //SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); + //SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); + SDL_GL_SetSwapInterval(1); + + window = SDL_CreateWindow("Aliens vs Predator", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + Width, + Height, + flags); + if (window == NULL) { + fprintf(stderr, "(OpenGL) SDL SDL_CreateWindow failed: %s\n", SDL_GetError()); + exit(EXIT_FAILURE); + } + + context = SDL_GL_CreateContext(window); + if (context == NULL) { + fprintf(stderr, "(OpenGL) SDL SDL_GL_CreateContext failed: %s\n", SDL_GetError()); + exit(EXIT_FAILURE); + } + SDL_GL_MakeCurrent(window, context); + + SDL_AddEventWatch(SDLEventFilter, NULL); //TODO move this to startup? + + load_ogl_functions(1); + + ///* this is for supporting keyboard input processing with little hassle */ + //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + + //SDL_SetRelativeMouseMode(isgrab); + } + + ViewportWidth = Width; + ViewportHeight = Height; + + SDL_SetWindowSize(window, Width, Height); + + pglViewport(0, 0, Width, Height); + + pglMatrixMode(GL_PROJECTION); + pglLoadIdentity(); + pglMatrixMode(GL_MODELVIEW); + pglLoadIdentity(); + + pglEnable(GL_BLEND); + pglBlendFunc(GL_SRC_ALPHA, GL_ONE); + + pglEnable(GL_DEPTH_TEST); + pglDepthFunc(GL_LEQUAL); + pglDepthMask(GL_TRUE); + pglDepthRange(0.0, 1.0); + + pglEnable(GL_TEXTURE_2D); + + pglPolygonMode(GL_FRONT, GL_FILL); + pglPolygonMode(GL_BACK, GL_FILL); + pglDisable(GL_CULL_FACE); + + pglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + ScreenDescriptorBlock.SDB_Width = Width; + ScreenDescriptorBlock.SDB_Height = Height; + ScreenDescriptorBlock.SDB_CentreX = Width/2; + ScreenDescriptorBlock.SDB_CentreY = Height/2; + ScreenDescriptorBlock.SDB_ProjX = Width/2; + ScreenDescriptorBlock.SDB_ProjY = Height/2; + ScreenDescriptorBlock.SDB_ClipLeft = 0; + ScreenDescriptorBlock.SDB_ClipRight = Width; + ScreenDescriptorBlock.SDB_ClipUp = 0; + ScreenDescriptorBlock.SDB_ClipDown = Height; + + InitOpenGL(); + + return 0; +} + +int InitialiseWindowsSystem(HANDLE hInstance, int nCmdShow, int WinInitMode) +{ + return 0; +} + +int ExitWindowsSystem() +{ + if (joy != NULL) { + SDL_JoystickClose(joy); + } + + load_ogl_functions(0); + + if (surface != NULL) { + SDL_FreeSurface(surface); + } + surface = NULL; + + if (context != NULL) { + SDL_GL_DeleteContext(context); + } + context = NULL; + + if (window != NULL) { + SDL_DestroyWindow(window); + } + window = NULL; + + return 0; +} + +static int GotPrintScn, HavePrintScn; + +static int KeySymToKey(int keysym) +{ + switch(keysym) { + case SDLK_ESCAPE: + return KEY_ESCAPE; + + case SDLK_0: + return KEY_0; + case SDLK_1: + return KEY_1; + case SDLK_2: + return KEY_2; + case SDLK_3: + return KEY_3; + case SDLK_4: + return KEY_4; + case SDLK_5: + return KEY_5; + case SDLK_6: + return KEY_6; + case SDLK_7: + return KEY_7; + case SDLK_8: + return KEY_8; + case SDLK_9: + return KEY_9; + + case SDLK_a: + return KEY_A; + case SDLK_b: + return KEY_B; + case SDLK_c: + return KEY_C; + case SDLK_d: + return KEY_D; + case SDLK_e: + return KEY_E; + case SDLK_f: + return KEY_F; + case SDLK_g: + return KEY_G; + case SDLK_h: + return KEY_H; + case SDLK_i: + return KEY_I; + case SDLK_j: + return KEY_J; + case SDLK_k: + return KEY_K; + case SDLK_l: + return KEY_L; + case SDLK_m: + return KEY_M; + case SDLK_n: + return KEY_N; + case SDLK_o: + return KEY_O; + case SDLK_p: + return KEY_P; + case SDLK_q: + return KEY_Q; + case SDLK_r: + return KEY_R; + case SDLK_s: + return KEY_S; + case SDLK_t: + return KEY_T; + case SDLK_u: + return KEY_U; + case SDLK_v: + return KEY_V; + case SDLK_w: + return KEY_W; + case SDLK_x: + return KEY_X; + case SDLK_y: + return KEY_Y; + case SDLK_z: + return KEY_Z; + + case SDLK_LEFT: + return KEY_LEFT; + case SDLK_RIGHT: + return KEY_RIGHT; + case SDLK_UP: + return KEY_UP; + case SDLK_DOWN: + return KEY_DOWN; + case SDLK_RETURN: + return KEY_CR; + case SDLK_TAB: + return KEY_TAB; + case SDLK_INSERT: + return KEY_INS; + case SDLK_DELETE: + return KEY_DEL; + case SDLK_END: + return KEY_END; + case SDLK_HOME: + return KEY_HOME; + case SDLK_PAGEUP: + return KEY_PAGEUP; + case SDLK_PAGEDOWN: + return KEY_PAGEDOWN; + case SDLK_BACKSPACE: + return KEY_BACKSPACE; + case SDLK_COMMA: + return KEY_COMMA; + case SDLK_PERIOD: + return KEY_FSTOP; + case SDLK_SPACE: + return KEY_SPACE; + + case SDLK_LSHIFT: + return KEY_LEFTSHIFT; + case SDLK_RSHIFT: + return KEY_RIGHTSHIFT; + case SDLK_LALT: + return KEY_LEFTALT; + case SDLK_RALT: + return KEY_RIGHTALT; + case SDLK_LCTRL: + return KEY_LEFTCTRL; + case SDLK_RCTRL: + return KEY_RIGHTCTRL; + + case SDLK_CAPSLOCK: + return KEY_CAPS; + case SDLK_NUMLOCKCLEAR: + return KEY_NUMLOCK; + case SDLK_SCROLLLOCK: + return KEY_SCROLLOK; + + case SDLK_KP_0: + return KEY_NUMPAD0; + case SDLK_KP_1: + return KEY_NUMPAD1; + case SDLK_KP_2: + return KEY_NUMPAD2; + case SDLK_KP_3: + return KEY_NUMPAD3; + case SDLK_KP_4: + return KEY_NUMPAD4; + case SDLK_KP_5: + return KEY_NUMPAD5; + case SDLK_KP_6: + return KEY_NUMPAD6; + case SDLK_KP_7: + return KEY_NUMPAD7; + case SDLK_KP_8: + return KEY_NUMPAD8; + case SDLK_KP_9: + return KEY_NUMPAD9; + case SDLK_KP_MINUS: + return KEY_NUMPADSUB; + case SDLK_KP_PLUS: + return KEY_NUMPADADD; + case SDLK_KP_PERIOD: + return KEY_NUMPADDEL; + case SDLK_KP_ENTER: + return KEY_NUMPADENTER; + case SDLK_KP_DIVIDE: + return KEY_NUMPADDIVIDE; + case SDLK_KP_MULTIPLY: + return KEY_NUMPADMULTIPLY; + + case SDLK_LEFTBRACKET: + return KEY_LBRACKET; + case SDLK_RIGHTBRACKET: + return KEY_RBRACKET; + case SDLK_SEMICOLON: + return KEY_SEMICOLON; + case SDLK_QUOTE: + return KEY_APOSTROPHE; + case SDLK_BACKQUOTE: + return KEY_GRAVE; + case SDLK_BACKSLASH: + return KEY_BACKSLASH; + case SDLK_SLASH: + return KEY_SLASH; +/* case SDLK_ + return KEY_CAPITAL; */ + case SDLK_MINUS: + return KEY_MINUS; + case SDLK_EQUALS: + return KEY_EQUALS; + case SDLK_LGUI: + return KEY_LWIN; + case SDLK_RGUI: + return KEY_RWIN; +/* case SDLK_ + return KEY_APPS; */ + + case SDLK_F1: + return KEY_F1; + case SDLK_F2: + return KEY_F2; + case SDLK_F3: + return KEY_F3; + case SDLK_F4: + return KEY_F4; + case SDLK_F5: + return KEY_F5; + case SDLK_F6: + return KEY_F6; + case SDLK_F7: + return KEY_F7; + case SDLK_F8: + return KEY_F8; + case SDLK_F9: + return KEY_F9; + case SDLK_F10: + return KEY_F10; + case SDLK_F11: + return KEY_F11; + case SDLK_F12: + return KEY_F12; + +/* finish foreign keys */ + + default: + return -1; + } +} + +static void handle_keypress(int key, int unicode, int press) +{ + if (key == -1) + return; + + if (press) { + switch(key) { + case KEY_BACKSPACE: + RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_BACK); + break; + case KEY_END: + RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_END); + break; + case KEY_HOME: + RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_HOME); + break; + case KEY_LEFT: + RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_LEFT); + break; + case KEY_UP: + RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_UP); + break; + case KEY_RIGHT: + RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_RIGHT); + break; + case KEY_DOWN: + RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_DOWN); + break; + case KEY_INS: + RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_INSERT); + break; + case KEY_DEL: + RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_DELETE); + break; + case KEY_TAB: + RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_TAB); + break; + default: + break; + } + } + + if (press && !KeyboardInput[key]) { + DebouncedKeyboardInput[key] = 1; + DebouncedGotAnyKey = 1; + } + + if (press) + GotAnyKey = 1; + KeyboardInput[key] = press; +} + +static void handle_buttonpress(int button, int press) +{ + int key; + + switch(button) { + case 4: /* mouse wheel up */ + key = KEY_MOUSEWHEELUP; + break; + case 5: /* mouse wheel down */ + key = KEY_MOUSEWHEELDOWN; + break; + default: /* other buttons are handled elsewhere */ + return; + } + + /* since this currently only handles wheel up/down */ + if (press == 0) + return; + + if (press && !KeyboardInput[key]) { + DebouncedKeyboardInput[key] = 1; + } + + GotAnyKey = 1; + KeyboardInput[key] = press; +} + +void CheckForWindowsMessages() +{ + SDL_Event event; + int x, y, buttons, wantmouse; + + GotAnyKey = 0; + DebouncedGotAnyKey = 0; + memset(DebouncedKeyboardInput, 0, sizeof(DebouncedKeyboardInput)); + + wantmouse = 0; //(surface->flags & SDL_FULLSCREEN) || + //(SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON); + + KeyboardInput[KEY_MOUSEWHEELUP] = 0; + KeyboardInput[KEY_MOUSEWHEELDOWN] = 0; + + if (SDL_PollEvent(&event)) { + do { + switch(event.type) { + case SDL_MOUSEBUTTONDOWN: + if (wantmouse) + handle_buttonpress(event.button.button, 1); + break; + case SDL_MOUSEBUTTONUP: + break; + case SDL_TEXTINPUT: { + int unicode = event.text.text[0]; //TODO convert to utf-32 + if (unicode && !(unicode & 0xFF80)) { + RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_CHAR(unicode); + KeyboardEntryQueue_Add(unicode); + } + } + break; + case SDL_KEYDOWN: + if (event.key.keysym.sym == SDLK_PRINTSCREEN) { + if (HavePrintScn == 0) + GotPrintScn = 1; + HavePrintScn = 1; + } else { + handle_keypress(KeySymToKey(event.key.keysym.sym), 0, 1); + } + break; + case SDL_KEYUP: + if (event.key.keysym.sym == SDLK_PRINTSCREEN) { + GotPrintScn = 0; + HavePrintScn = 0; + } else { + handle_keypress(KeySymToKey(event.key.keysym.sym), 0, 0); + } + break; + case SDL_QUIT: + AvP.MainLoopRunning = 0; /* TODO */ + exit(0); //TODO + break; + } + } while (SDL_PollEvent(&event)); + } + + buttons = SDL_GetRelativeMouseState(&x, &y); + + if (wantmouse) { + if (buttons & SDL_BUTTON(1)) + handle_keypress(KEY_LMOUSE, 0, 1); + else + handle_keypress(KEY_LMOUSE, 0, 0); + if (buttons & SDL_BUTTON(2)) + handle_keypress(KEY_MMOUSE, 0, 1); + else + handle_keypress(KEY_MMOUSE, 0, 0); + if (buttons & SDL_BUTTON(3)) + handle_keypress(KEY_RMOUSE, 0, 1); + else + handle_keypress(KEY_RMOUSE, 0, 0); + + MouseVelX = DIV_FIXED(x, NormalFrameTime); + MouseVelY = DIV_FIXED(y, NormalFrameTime); + } else { + KeyboardInput[KEY_LMOUSE] = 0; + KeyboardInput[KEY_MMOUSE] = 0; + KeyboardInput[KEY_RMOUSE] = 0; + MouseVelX = 0; + MouseVelY = 0; + } + + if (GotJoystick) { + int numbuttons; + + SDL_JoystickUpdate(); + + numbuttons = SDL_JoystickNumButtons(joy); + if (numbuttons > 16) numbuttons = 16; + + for (x = 0; x < numbuttons; x++) { + if (SDL_JoystickGetButton(joy, x)) { + GotAnyKey = 1; + if (!KeyboardInput[KEY_JOYSTICK_BUTTON_1+x]) { + KeyboardInput[KEY_JOYSTICK_BUTTON_1+x] = 1; + DebouncedKeyboardInput[KEY_JOYSTICK_BUTTON_1+x] = 1; + } + } else { + KeyboardInput[KEY_JOYSTICK_BUTTON_1+x] = 0; + } + } + } + + if ((KeyboardInput[KEY_LEFTALT]||KeyboardInput[KEY_RIGHTALT]) && DebouncedKeyboardInput[KEY_CR]) { + //SDL_GrabMode gm; + // + //SDL_WM_ToggleFullScreen(surface); + // + //gm = SDL_WM_GrabInput(SDL_GRAB_QUERY); + //if (gm == SDL_GRAB_OFF && !(surface->flags & SDL_FULLSCREEN)) + // SDL_ShowCursor(1); + //else + // SDL_ShowCursor(0); + } + + if (KeyboardInput[KEY_LEFTCTRL] && DebouncedKeyboardInput[KEY_G]) { + //SDL_GrabMode gm; + // + //gm = SDL_WM_GrabInput(SDL_GRAB_QUERY); + //SDL_WM_GrabInput((gm == SDL_GRAB_ON) ? SDL_GRAB_OFF : SDL_GRAB_ON); + // + //gm = SDL_WM_GrabInput(SDL_GRAB_QUERY); + //if (gm == SDL_GRAB_OFF && !(surface->flags & SDL_FULLSCREEN)) + // SDL_ShowCursor(1); + //else + // SDL_ShowCursor(0); + } + + if (GotPrintScn) { + GotPrintScn = 0; + + ScreenShot(); + } +} + +void InGameFlipBuffers() +{ + if (window != NULL) { + SDL_GL_SwapWindow(window); + } +} + +void FlipBuffers() +{ + // TODO: move this to init + static GLuint t; + + if (t == 0) { + pglGenTextures(1, &t); + + pglBindTexture(GL_TEXTURE_2D, t); + + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + + pglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 640, 480, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL); + } + + pglDisableClientState(GL_VERTEX_ARRAY); + pglDisableClientState(GL_TEXTURE_COORD_ARRAY); + pglDisableClientState(GL_COLOR_ARRAY); + + pglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + pglMatrixMode(GL_PROJECTION); + pglLoadIdentity(); + pglMatrixMode(GL_MODELVIEW); + pglLoadIdentity(); + + pglDisable(GL_ALPHA_TEST); + pglDisable(GL_BLEND); + pglDisable(GL_DEPTH_TEST); + + pglBindTexture(GL_TEXTURE_2D, t); + pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 640, 480, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, surface->pixels); + + GLfloat x0; + GLfloat x1; + GLfloat y0; + GLfloat y1; + + // figure out the best way to fit the 640x480 virtual window + GLfloat a = ViewportHeight * 640.0f / 480.0f; + GLfloat b = ViewportWidth * 480.0f / 640.0f; + + if (a <= ViewportWidth) { + // a x ViewportHeight window + y0 = -1.0f; + y1 = 1.0f; + + x1 = 1.0 - (ViewportWidth - a) / ViewportWidth; + x0 = -x1; + } else { + // ViewportWidth x b window + x0 = -1.0f; + x1 = 1.0f; + + y1 = 1.0 - (ViewportHeight - b) / ViewportHeight; + y0 = -y1; + } + + pglBegin(GL_QUADS); + + pglTexCoord2f(0.0, 1.0); + pglVertex3f(x0, y0, -1.0); + + pglTexCoord2f(1.0, 1.0); + pglVertex3f(x1, y0, -1.0); + + pglTexCoord2f(1.0, 0.0); + pglVertex3f(x1, y1, -1.0); + + pglTexCoord2f(0.0, 0.0); + pglVertex3f(x0, y1, -1.0); + + pglEnd(); + + pglBindTexture(GL_TEXTURE_2D, 0); + + SDL_GL_SwapWindow(window); +} + +char *AvpCDPath = 0; + +#if !defined(_MSC_VER) +static const struct option getopt_long_options[] = { +{ "help", 0, NULL, 'h' }, +{ "version", 0, NULL, 'v' }, +{ "fullscreen", 0, NULL, 'f' }, +{ "windowed", 0, NULL, 'w' }, +{ "nosound", 0, NULL, 's' }, +{ "nocdrom", 0, NULL, 'c' }, +{ "nojoy", 0, NULL, 'j' }, +{ "debug", 0, NULL, 'd' }, +{ "withgl", 1, NULL, 'g' }, +/* +{ "loadrifs", 1, NULL, 'l' }, +{ "server", 0, someval, 1 }, +{ "client", 1, someval, 2 }, +*/ +{ NULL, 0, NULL, 0 }, +}; +#endif + +static const char *usage_string = +"Aliens vs Predator Linux - http://www.icculus.org/avp/\n" +"Based on Rebellion Developments AvP Gold source\n" +" [-h | --help] Display this help message\n" +" [-v | --version] Display the game version\n" +" [-f | --fullscreen] Run the game fullscreen\n" +" [-w | --windowed] Run the game in a window\n" +" [-s | --nosound] Do not access the soundcard\n" +" [-c | --nocdrom] Do not access the CD-ROM\n" +" [-j | --nojoy] Do not access the joystick\n" +" [-g | --withgl] [x] Use [x] instead of /usr/lib/libGL.so.1 for OpenGL\n" +; + +int main(int argc, char *argv[]) +{ +#if !defined(_MSC_VER) + int c; + + opterr = 0; + while ((c = getopt_long(argc, argv, "hvfwscdg:", getopt_long_options, NULL)) != -1) { + switch(c) { + case 'h': + printf("%s", usage_string); + exit(EXIT_SUCCESS); + case 'v': + printf("%s", AvPVersionString); + exit(EXIT_SUCCESS); + case 'f': + WantFullscreen = 1; + break; + case 'w': + WantFullscreen = 0; + break; + case 's': + WantSound = 0; + break; + case 'c': + WantCDRom = 0; + break; + case 'j': + WantJoystick = 0; + break; + case 'd': { + extern int DebuggingCommandsActive; + DebuggingCommandsActive = 1; + } + break; + case 'g': + opengl_library = optarg; + break; + default: + printf("%s", usage_string); + exit(EXIT_FAILURE); + } + } +#endif + + InitGameDirectories(argv[0]); + + if (InitSDL() == -1) { + fprintf(stderr, "Could not find a sutable resolution!\n"); + fprintf(stderr, "At least 512x384 is needed. Does OpenGL work?\n"); + exit(EXIT_FAILURE); + } + + LoadCDTrackList(); + + SetFastRandom(); + +#if MARINE_DEMO + ffInit("fastfile/mffinfo.txt","fastfile/"); +#elif ALIEN_DEMO + ffInit("alienfastfile/ffinfo.txt","alienfastfile/"); +#else + ffInit("fastfile/ffinfo.txt","fastfile/"); +#endif + InitGame(); + + //NEW + SetOGLVideoMode(VideoModeList[1].w, VideoModeList[1].h); + //NEW + + SetSoftVideoMode(640, 480, 16); + + InitialVideoMode(); + + /* Env_List can probably be removed */ + Env_List[0]->main = LevelName; + + InitialiseSystem(); + InitialiseRenderer(); + + LoadKeyConfiguration(); + + SoundSys_Start(); + if (WantCDRom) CDDA_Start(); + + InitTextStrings(); + + BuildMultiplayerLevelNameArray(); + + ChangeDirectDrawObject(); + AvP.LevelCompleted = 0; + LoadSounds("PLAYER"); + + /* is this still neccessary? */ + AvP.CurrentEnv = AvP.StartingEnv = 0; + +#if ALIEN_DEMO + AvP.PlayerType = I_Alien; + SetLevelToLoad(AVP_ENVIRONMENT_INVASION_A); +#elif PREDATOR_DEMO + AvP.PlayerType = I_Predator; + SetLevelToLoad(AVP_ENVIRONMENT_INVASION_P); +#elif MARINE_DEMO + AvP.PlayerType = I_Marine; + SetLevelToLoad(AVP_ENVIRONMENT_INVASION); +#endif + +#if !(ALIEN_DEMO|PREDATOR_DEMO|MARINE_DEMO) +while (AvP_MainMenus()) +#else +if (AvP_MainMenus()) +#endif +{ + int menusActive = 0; + int thisLevelHasBeenCompleted = 0; + + /* turn off any special effects */ + d3d_light_ctrl.ctrl = LCCM_NORMAL; + + //NEW + //TODO + // need to watch for CurrentVideoMode to change in all cases + // the menu will always render in a 640x480 virtual window + // game will render in a user-specified virtual window + // real window will be which ever size is available + //TODO + //NEW + SetOGLVideoMode(VideoModeList[CurrentVideoMode].w, VideoModeList[CurrentVideoMode].h); + + InitialiseGammaSettings(RequestedGammaSetting); + + start_of_loaded_shapes = load_precompiled_shapes(); + + InitCharacter(); + + LoadRifFile(); /* sets up a map */ + + AssignAllSBNames(); + + StartGame(); + + ffcloseall(); + + AvP.MainLoopRunning = 1; + + ScanImagesForFMVs(); + + ResetFrameCounter(); + + Game_Has_Loaded(); + + ResetFrameCounter(); + + if(AvP.Network!=I_No_Network) + { + /*Need to choose a starting position for the player , but first we must look + through the network messages to find out which generator spots are currently clear*/ + netGameData.myGameState = NGS_Playing; + MinimalNetCollectMessages(); + TeleportNetPlayerToAStartingPosition(Player->ObStrategyBlock,1); + } + + IngameKeyboardInput_ClearBuffer(); + + while(AvP.MainLoopRunning) { + CheckForWindowsMessages(); + + switch(AvP.GameMode) { + case I_GM_Playing: + if ((!menusActive || (AvP.Network!=I_No_Network && !netGameData.skirmishMode)) && !AvP.LevelCompleted) { + /* TODO: print some debugging stuff */ + + DoAllShapeAnimations(); + + UpdateGame(); + + AvpShowViews(); + + MaintainHUD(); + + CheckCDAndChooseTrackIfNeeded(); + + if(InGameMenusAreRunning() && ( (AvP.Network!=I_No_Network && netGameData.skirmishMode) || (AvP.Network==I_No_Network)) ) { + SoundSys_StopAll(); + } + } else { + ReadUserInput(); + + SoundSys_Management(); + + FlushD3DZBuffer(); + + ThisFramesRenderingHasBegun(); + } + + menusActive = AvP_InGameMenus(); + if (AvP.RestartLevel) menusActive=0; + + if (AvP.LevelCompleted) { + SoundSys_FadeOutFast(); + DoCompletedLevelStatisticsScreen(); + thisLevelHasBeenCompleted = 1; + } + + ThisFramesRenderingHasFinished(); + + InGameFlipBuffers(); + + FrameCounterHandler(); + { + PLAYER_STATUS *playerStatusPtr = (PLAYER_STATUS *) (Player->ObStrategyBlock->SBdataptr); + + if (!menusActive && playerStatusPtr->IsAlive && !AvP.LevelCompleted) { + DealWithElapsedTime(); + } + } + break; + + case I_GM_Menus: + AvP.GameMode = I_GM_Playing; + break; + default: + fprintf(stderr, "AvP.MainLoopRunning: gamemode = %d\n", AvP.GameMode); + exit(EXIT_FAILURE); + } + + if (AvP.RestartLevel) { + AvP.RestartLevel = 0; + AvP.LevelCompleted = 0; + + FixCheatModesInUserProfile(UserProfilePtr); + + RestartLevel(); + } + } + + AvP.LevelCompleted = thisLevelHasBeenCompleted; + + FixCheatModesInUserProfile(UserProfilePtr); + + ReleaseAllFMVTextures(); + + CONSBIND_WriteKeyBindingsToConfigFile(); + + DeInitialisePlayer(); + + DeallocatePlayersMirrorImage(); + + KillHUD(); + + Destroy_CurrentEnvironment(); + + DeallocateAllImages(); + + EndNPCs(); + + ExitGame(); + + SoundSys_StopAll(); + + SoundSys_ResetFadeLevel(); + + CDDA_Stop(); + + if (AvP.Network != I_No_Network) { + EndAVPNetGame(); + } + + ClearMemoryPool(); + +/* go back to menu mode */ +#if !(ALIEN_DEMO|PREDATOR_DEMO|MARINE_DEMO) + SetSoftVideoMode(640, 480, 16); +#endif +} + + SoundSys_StopAll(); + SoundSys_RemoveAll(); + + ExitSystem(); + + CDDA_End(); + ClearMemoryPool(); + + return 0; +} diff --git a/src/maths.c b/src/maths.c index 71a1389..ea5ad8a 100644 --- a/src/maths.c +++ b/src/maths.c @@ -2311,7 +2311,7 @@ dx = 0; /* TODO: uninitialized?? */ #define DEG_3 31 #define SEP_3 3 -static long table [DEG_3] = +static int32_t table [DEG_3] = { -851904987, -43806228, -2029755270, 1390239686, -1912102820, -485608943, 1969813258, -1590463333, -1944053249, 455935928, @@ -2324,8 +2324,8 @@ static long table [DEG_3] = #define TABLE_END (table + sizeof (table) / sizeof (table [0])) -static long * front_ptr = table + SEP_3; -static long * rear_ptr = table; +static int32_t * front_ptr = table + SEP_3; +static int32_t * rear_ptr = table; void SetSeededFastRandom(int seed); @@ -2359,7 +2359,7 @@ int FastRandom(void) { - long i; + int32_t i; /* @@ -2370,7 +2370,7 @@ int FastRandom(void) */ *front_ptr += *rear_ptr; - i = (long) ((unsigned long) *front_ptr >> 1); + i = (int32_t) ((uint32_t) *front_ptr >> 1); /* `front_ptr' and `rear_ptr' can't wrap at the same time. */ @@ -2402,12 +2402,12 @@ int FastRandom(void) #define SEEDED_DEG_3 13 #define SEEDED_SEP_3 3 -static long seeded_table [SEEDED_DEG_3]; +static int32_t seeded_table [SEEDED_DEG_3]; #define SEEDED_TABLE_END (seeded_table + sizeof (seeded_table) / sizeof (seeded_table [0])) -static long * seeded_front_ptr = seeded_table + SEEDED_SEP_3; -static long * seeded_rear_ptr = seeded_table; +static int32_t * seeded_front_ptr = seeded_table + SEEDED_SEP_3; +static int32_t * seeded_rear_ptr = seeded_table; @@ -2415,7 +2415,7 @@ int SeededFastRandom(void) { - long i; + int32_t i; /* @@ -2426,7 +2426,7 @@ int SeededFastRandom(void) */ *seeded_front_ptr += *seeded_rear_ptr; - i = (long) ((unsigned long) *seeded_front_ptr >> 1); + i = (int32_t) ((uint32_t) *seeded_front_ptr >> 1); /* `front_ptr' and `rear_ptr' can't wrap at the same time. */ @@ -2458,7 +2458,7 @@ void SetSeededFastRandom(int seed) { int i; - long number = seed; + int32_t number = seed; for(i = 0; i < SEEDED_DEG_3; ++i) { diff --git a/src/md5.c b/src/md5.c index 611f151..247d21c 100644 --- a/src/md5.c +++ b/src/md5.c @@ -142,7 +142,7 @@ MD5Final(md5byte digest[16], struct MD5Context *ctx) byteSwap(ctx->buf, 4); memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ + memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ } #ifndef ASM_MD5 diff --git a/src/menus.c b/src/menus.c index 5415dc3..25e98ae 100644 --- a/src/menus.c +++ b/src/menus.c @@ -290,7 +290,7 @@ static void LoadMenuFont() { AVPMENUGFX *gfxPtr; char buffer[100]; - unsigned int fastFileLength; + size_t fastFileLength; void const *pFastFileData; IntroFont_Light.height = 33; @@ -1050,7 +1050,7 @@ void LoadAvPMenuGfx(enum AVPMENUGFX_ID menuGfxID) { AVPMENUGFX *gfxPtr; char buffer[100]; - unsigned int fastFileLength; + size_t fastFileLength; void const *pFastFileData; GLOBALASSERT(menuGfxID < MAX_NO_OF_AVPMENUGFXS); diff --git a/src/module.c b/src/module.c index 8efcece..393f19a 100644 --- a/src/module.c +++ b/src/module.c @@ -643,7 +643,7 @@ int GetModuleVisArrays(void) ModuleArraySize = index + 1; - ModuleCurrVisArray = AllocateMem(ModuleArraySize); + ModuleCurrVisArray = (char*) AllocateMem(ModuleArraySize); if(ModuleCurrVisArray) { diff --git a/src/oglfunc.c b/src/oglfunc.c index 0df0bf7..c5ec48e 100644 --- a/src/oglfunc.c +++ b/src/oglfunc.c @@ -42,6 +42,7 @@ PFNGLGETERRORPROC pglGetError; PFNGLGETFLOATVPROC pglGetFloatv; PFNGLGETINTEGERVPROC pglGetIntegerv; PFNGLGETSTRINGPROC pglGetString; +PFNGLGETTEXPARAMETERFVPROC pglGetTexParameterfv; PFNGLHINTPROC pglHint; PFNGLLOADIDENTITYPROC pglLoadIdentity; PFNGLLOADMATRIXFPROC pglLoadMatrixf; @@ -100,11 +101,15 @@ PFNGLSECONDARYCOLOR3UBEXTPROC pglSecondaryColor3ubEXT; PFNGLSECONDARYCOLOR3UBVEXTPROC pglSecondaryColor3ubvEXT; PFNGLSECONDARYCOLORPOINTEREXTPROC pglSecondaryColorPointerEXT; +int ogl_have_multisample_filter_hint; int ogl_have_paletted_texture; int ogl_have_secondary_color; +int ogl_have_texture_filter_anisotropic; +int ogl_use_multisample_filter_hint; int ogl_use_paletted_texture; int ogl_use_secondary_color; +int ogl_use_texture_filter_anisotropic; static void dummyfunc() { @@ -183,6 +188,7 @@ void load_ogl_functions(int mode) LoadOGLProc(PFNGLGETFLOATVPROC, glGetFloatv); LoadOGLProc(PFNGLGETINTEGERVPROC, glGetIntegerv); LoadOGLProc(PFNGLGETSTRINGPROC, glGetString); + LoadOGLProc(PFNGLGETTEXPARAMETERFVPROC, glGetTexParameterfv); LoadOGLProc(PFNGLHINTPROC, glHint); LoadOGLProc(PFNGLLOADIDENTITYPROC, glLoadIdentity); LoadOGLProc(PFNGLLOADMATRIXFPROC, glLoadMatrixf); @@ -247,8 +253,10 @@ void load_ogl_functions(int mode) ext = (const char *) pglGetString(GL_EXTENSIONS); + ogl_have_multisample_filter_hint = check_token(ext, "GL_NV_multisample_filter_hint"); ogl_have_paletted_texture = check_token(ext, "GL_EXT_paletted_texture"); ogl_have_secondary_color = check_token(ext, "GL_EXT_secondary_color"); + ogl_have_texture_filter_anisotropic = check_token(ext, "GL_EXT_texture_filter_anisotropic"); #ifndef GL_COLOR_TABLE_WIDTH_EXT #define GL_COLOR_TABLE_WIDTH_EXT GL_COLOR_TABLE_WIDTH @@ -287,11 +295,20 @@ void load_ogl_functions(int mode) ogl_have_secondary_color = 0; } } - + + ogl_use_multisample_filter_hint = ogl_have_multisample_filter_hint; ogl_use_paletted_texture = ogl_have_paletted_texture; ogl_use_secondary_color = ogl_have_secondary_color; - - // fprintf(stderr, "RENDER DEBUG: pal:%d sec:%d\n", ogl_use_paletted_texture, ogl_use_secondary_color); + ogl_use_texture_filter_anisotropic = ogl_have_texture_filter_anisotropic; + +#if 0 + fprintf(stderr, "RENDER DEBUG: pal:%d sec:%d mfh:%d tfa:%d\n", + ogl_use_paletted_texture, + ogl_use_secondary_color, + ogl_use_multisample_filter_hint, + ogl_use_texture_filter_anisotropic + ); +#endif } int check_for_errors(const char *file, int line) diff --git a/src/oglfunc.h b/src/oglfunc.h index ffb108a..a55fc1f 100644 --- a/src/oglfunc.h +++ b/src/oglfunc.h @@ -5,7 +5,8 @@ #include #endif -#include +#include "SDL_opengl.h" +//#include //#include typedef void (APIENTRY *PFNGLALPHAFUNCPROC)(GLenum, GLclampf); @@ -45,6 +46,7 @@ typedef GLenum (APIENTRY *PFNGLGETERRORPROC)(void); typedef void (APIENTRY *PFNGLGETFLOATVPROC)(GLenum, GLfloat *); typedef void (APIENTRY *PFNGLGETINTEGERVPROC)(GLenum, GLint *); typedef const GLubyte* (APIENTRY *PFNGLGETSTRINGPROC)(GLenum); +typedef void (APIENTRY *PFNGLGETTEXPARAMETERFVPROC)(GLenum, GLenum, GLfloat*); typedef void (APIENTRY *PFNGLHINTPROC)(GLenum, GLenum); typedef void (APIENTRY *PFNGLLOADIDENTITYPROC)(void); typedef void (APIENTRY *PFNGLLOADMATRIXFPROC)(const GLfloat *); @@ -119,6 +121,8 @@ typedef void (APIENTRY * PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort *v); typedef void (APIENTRY * PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); #endif +typedef void (APIENTRY *PFNGLXSWAPINTERVALSGIPROC)(int interval); + extern PFNGLALPHAFUNCPROC pglAlphaFunc; extern PFNGLARRAYELEMENTPROC pglArrayElement; extern PFNGLBEGINPROC pglBegin; @@ -156,6 +160,7 @@ extern PFNGLGETERRORPROC pglGetError; extern PFNGLGETFLOATVPROC pglGetFloatv; extern PFNGLGETINTEGERVPROC pglGetIntegerv; extern PFNGLGETSTRINGPROC pglGetString; +extern PFNGLGETTEXPARAMETERFVPROC pglGetTexParameterfv; extern PFNGLHINTPROC pglHint; extern PFNGLLOADIDENTITYPROC pglLoadIdentity; extern PFNGLLOADMATRIXFPROC pglLoadMatrixf; @@ -214,11 +219,15 @@ extern PFNGLSECONDARYCOLOR3UBEXTPROC pglSecondaryColor3ubEXT; extern PFNGLSECONDARYCOLOR3UBVEXTPROC pglSecondaryColor3ubvEXT; extern PFNGLSECONDARYCOLORPOINTEREXTPROC pglSecondaryColorPointerEXT; +extern int ogl_have_multisample_filter_hint; extern int ogl_have_paletted_texture; extern int ogl_have_secondary_color; +extern int ogl_have_texture_filter_anisotropic; +extern int ogl_use_multisample_filter_hint; extern int ogl_use_paletted_texture; extern int ogl_use_secondary_color; +extern int ogl_use_texture_filter_anisotropic; extern void load_ogl_functions(int mode); extern int check_for_errors(const char *file, int line); diff --git a/src/openal.c b/src/openal.c index 70418c8..7018255 100644 --- a/src/openal.c +++ b/src/openal.c @@ -3,8 +3,8 @@ #include #include -#include -#include +#include "al.h" +#include "alc.h" #include "fixer.h" @@ -23,6 +23,10 @@ #include #endif +#if 0 +#define OPENAL_DEBUG +#endif + ACTIVESOUNDSAMPLE ActiveSounds[SOUND_MAXACTIVE]; ACTIVESOUNDSAMPLE BlankActiveSound = {SID_NOSOUND,ASP_Minimum,0,0,NULL,0,0,0,0,0, { {0,0,0},{0,0,0},0,0 }, 0, 0, { 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, NULL, NULL, NULL}; SOUNDSAMPLEDATA BlankGameSound = {0,0,0,0,0,NULL,0,0,NULL,0}; @@ -563,6 +567,7 @@ int PlatPlaySound(int activeIndex) if (ActiveSounds[activeIndex].threedee) { alSourcei(ActiveSounds[activeIndex].ds3DBufferP, AL_SOURCE_RELATIVE, AL_FALSE); + alSourcef(ActiveSounds[activeIndex].ds3DBufferP, AL_REFERENCE_DISTANCE, ActiveSounds[activeIndex].threedeedata.inner_range); // TODO: min distance ActiveSounds[activeIndex].threedeedata.inner_range? // TODO: max distance DS3D_DEFAULTMAXDISTANCE? @@ -865,7 +870,9 @@ void PlatUpdatePlayer() or[5] = -(float) ((Global_VDB_Ptr->VDB_Mat.mat32) / 65536.0F); } - if ((AvP.PlayerType == I_Alien && DopplerShiftIsOn && NormalFrameTime)) { +#warning VELOCITY AND/OR OPENAL SETUP IS IN WRONG UNITS + static int useVel = 0; + if (useVel!=0&&(AvP.PlayerType == I_Alien && DopplerShiftIsOn && NormalFrameTime)) { DYNAMICSBLOCK *dynPtr = Player->ObStrategyBlock->DynPtr; float invFrameTime = 100000.0f/(float)NormalFrameTime; @@ -883,7 +890,7 @@ void PlatUpdatePlayer() pos[2] = Global_VDB_Ptr->VDB_World.vz; // 10000.0; #ifdef OPENAL_DEBUG - fprintf(stderr, "OPENAL: Player: (%f, %f, %f) (%f, %f, %f %f, %f, %f)\n", pos[0], pos[1], pos[2], or[0], or[1], or[2], or[3], or[4], or[5]); + fprintf(stderr, "OPENAL: Player: (%f, %f, %f) (%f, %f, %f %f, %f, %f) (%f, %f, %f)\n", pos[0], pos[1], pos[2], or[0], or[1], or[2], or[3], or[4], or[5], vel[0], vel[1], vel[2]); #endif pos[0] = 0.0f; diff --git a/src/opengl.c b/src/opengl.c index f4f041b..15195cd 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -54,10 +54,6 @@ static D3DTexture *CurrentlyBoundTexture = NULL; #define TA_MAXVERTICES 2048 #define TA_MAXTRIANGLES 2048 -#if GL_EXT_secondary_color -extern PFNGLSECONDARYCOLORPOINTEREXTPROC pglSecondaryColorPointerEXT; -#endif - typedef struct VertexArray { GLfloat v[4]; @@ -69,9 +65,9 @@ typedef struct VertexArray typedef struct TriangleArray { - int a; - int b; - int c; + unsigned short a; + unsigned short b; + unsigned short c; } TriangleArray; static VertexArray varr[TA_MAXVERTICES*2]; @@ -132,6 +128,14 @@ A few things: void InitOpenGL() { + pglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); + pglHint( GL_GENERATE_MIPMAP_HINT, GL_NICEST ); + + if ( ogl_use_multisample_filter_hint ) + { + pglHint( GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST ); + } + CurrentTranslucencyMode = TRANSLUCENCY_OFF; pglBlendFunc(GL_ONE, GL_ZERO); @@ -155,12 +159,12 @@ void InitOpenGL() #if 0 #if GL_EXT_secondary_color - if (useseparate) { - pglEnableClientState(GL_SEPARATE_COLOR_ARRAY_EXT); - pglSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, sizeof(svarr[0]), svarr[0].c); - } else { - pglDisableClientState(GL_SEPARATE_COLOR_ARRAY_EXT); - } + if (ogl_use_secondary_color) { + pglEnableClientState(GL_SEPARATE_COLOR_ARRAY_EXT); + pglSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, sizeof(svarr[0]), svarr[0].c); + } else { + pglDisableClientState(GL_SEPARATE_COLOR_ARRAY_EXT); + } #endif #endif @@ -179,20 +183,8 @@ void InitOpenGL() static void FlushTriangleBuffers(int backup) { - int i; - if (tarrc) { -#if 1 - pglBegin(GL_TRIANGLES); - for (i = 0; i < tarrc; i++) { - pglArrayElement(tarr[i].a); - pglArrayElement(tarr[i].b); - pglArrayElement(tarr[i].c); - } - pglEnd(); -#else - pglDrawElements(GL_TRIANGLES, tarrc*3, GL_UNSIGNED_INT, tarr); -#endif + pglDrawElements(GL_TRIANGLES, tarrc*3, GL_UNSIGNED_SHORT, tarr); tarrc = 0; tarrp = tarr; @@ -217,17 +209,7 @@ static void FlushTriangleBuffers(int backup) pglDisableClientState(GL_TEXTURE_COORD_ARRAY); -#if 1 - pglBegin(GL_TRIANGLES); - for (i = 0; i < starrc; i++) { - pglArrayElement(starr[i].a); - pglArrayElement(starr[i].b); - pglArrayElement(starr[i].c); - } - pglEnd(); -#else - pglDrawElements(GL_TRIANGLES, starrc*3, GL_UNSIGNED_INT, starr); -#endif + pglDrawElements(GL_TRIANGLES, starrc*3, GL_UNSIGNED_SHORT, starr); pglEnableClientState(GL_TEXTURE_COORD_ARRAY); @@ -339,7 +321,7 @@ static void CheckTriangleBuffer(int rver, int sver, int rtri, int stri, D3DTextu FlushTriangleBuffers(0); } - if ((int)tex != -1) + if ((intptr_t)tex != -1) CheckBoundTextureIsCorrect(tex); if (mode != -1) CheckTranslucencyModeIsCorrect(mode); @@ -450,17 +432,20 @@ static void SelectPolygonBeginType(int points) GLuint CreateOGLTexture(D3DTexture *tex, unsigned char *buf) { GLuint h; + GLfloat max_anisotropy; FlushTriangleBuffers(1); pglGenTextures(1, &h); pglBindTexture(GL_TEXTURE_2D, h); + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); pglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->w, tex->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); @@ -469,8 +454,17 @@ GLuint CreateOGLTexture(D3DTexture *tex, unsigned char *buf) tex->id = h; tex->filter = FILTERING_BILINEAR_ON; - if (CurrentlyBoundTexture) - pglBindTexture(GL_TEXTURE_2D, CurrentlyBoundTexture->id); /* restore current */ + if ( ogl_use_texture_filter_anisotropic ) + { + pglGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy); + pglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy); + } + + if ( CurrentlyBoundTexture != NULL ) + { + /* restore the previously-bound texture */ + pglBindTexture(GL_TEXTURE_2D, CurrentlyBoundTexture->id); + } return h; } diff --git a/src/sdl12/SDLMain.h b/src/sdl12/SDLMain.h new file mode 100644 index 0000000..c56d90c --- /dev/null +++ b/src/sdl12/SDLMain.h @@ -0,0 +1,16 @@ +/* SDLMain.m - main entry point for our Cocoa-ized SDL app + Initial Version: Darrell Walisser + Non-NIB-Code & other changes: Max Horn + + Feel free to customize this file to suit your needs +*/ + +#ifndef _SDLMain_h_ +#define _SDLMain_h_ + +#import + +@interface SDLMain : NSObject +@end + +#endif /* _SDLMain_h_ */ diff --git a/src/sdl12/SDLMain.m b/src/sdl12/SDLMain.m new file mode 100644 index 0000000..2434f81 --- /dev/null +++ b/src/sdl12/SDLMain.m @@ -0,0 +1,381 @@ +/* SDLMain.m - main entry point for our Cocoa-ized SDL app + Initial Version: Darrell Walisser + Non-NIB-Code & other changes: Max Horn + + Feel free to customize this file to suit your needs +*/ + +#include "SDL.h" +#include "SDLMain.h" +#include /* for MAXPATHLEN */ +#include + +/* For some reaon, Apple removed setAppleMenu from the headers in 10.4, + but the method still is there and works. To avoid warnings, we declare + it ourselves here. */ +@interface NSApplication(SDL_Missing_Methods) +- (void)setAppleMenu:(NSMenu *)menu; +@end + +/* Use this flag to determine whether we use SDLMain.nib or not */ +#define SDL_USE_NIB_FILE 0 + +/* Use this flag to determine whether we use CPS (docking) or not */ +#define SDL_USE_CPS 1 +#ifdef SDL_USE_CPS +/* Portions of CPS.h */ +typedef struct CPSProcessSerNum +{ + UInt32 lo; + UInt32 hi; +} CPSProcessSerNum; + +extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn); +extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); +extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn); + +#endif /* SDL_USE_CPS */ + +static int gArgc; +static char **gArgv; +static BOOL gFinderLaunch; +static BOOL gCalledAppMainline = FALSE; + +static NSString *getApplicationName(void) +{ + const NSDictionary *dict; + NSString *appName = 0; + + /* Determine the application name */ + dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); + if (dict) + appName = [dict objectForKey: @"CFBundleName"]; + + if (![appName length]) + appName = [[NSProcessInfo processInfo] processName]; + + return appName; +} + +#if SDL_USE_NIB_FILE +/* A helper category for NSString */ +@interface NSString (ReplaceSubString) +- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; +@end +#endif + +@interface NSApplication (SDLApplication) +@end + +@implementation NSApplication (SDLApplication) +/* Invoked from the Quit menu item */ +- (void)terminate:(id)sender +{ + /* Post a SDL_QUIT event */ + SDL_Event event; + event.type = SDL_QUIT; + SDL_PushEvent(&event); +} +@end + +/* The main class of the application, the application's delegate */ +@implementation SDLMain + +/* Set the working directory to the .app's parent directory */ +- (void) setupWorkingDirectory:(BOOL)shouldChdir +{ + if (shouldChdir) + { + char parentdir[MAXPATHLEN]; + CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); + if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) { + chdir(parentdir); /* chdir to the binary app's parent */ + } + CFRelease(url); + CFRelease(url2); + } +} + +#if SDL_USE_NIB_FILE + +/* Fix menu to contain the real app name instead of "SDL App" */ +- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName +{ + NSRange aRange; + NSEnumerator *enumerator; + NSMenuItem *menuItem; + + aRange = [[aMenu title] rangeOfString:@"SDL App"]; + if (aRange.length != 0) + [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]]; + + enumerator = [[aMenu itemArray] objectEnumerator]; + while ((menuItem = [enumerator nextObject])) + { + aRange = [[menuItem title] rangeOfString:@"SDL App"]; + if (aRange.length != 0) + [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]]; + if ([menuItem hasSubmenu]) + [self fixMenu:[menuItem submenu] withAppName:appName]; + } +} + +#else + +static void setApplicationMenu(void) +{ + /* warning: this code is very odd */ + NSMenu *appleMenu; + NSMenuItem *menuItem; + NSString *title; + NSString *appName; + + appName = getApplicationName(); + appleMenu = [[NSMenu alloc] initWithTitle:@""]; + + /* Add menu items */ + title = [@"About " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; + + [appleMenu addItem:[NSMenuItem separatorItem]]; + + title = [@"Hide " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; + + menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; + [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; + + [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; + + [appleMenu addItem:[NSMenuItem separatorItem]]; + + title = [@"Quit " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; + + + /* Put menu into the menubar */ + menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; + [menuItem setSubmenu:appleMenu]; + [[NSApp mainMenu] addItem:menuItem]; + + /* Tell the application object that this is now the application menu */ + [NSApp setAppleMenu:appleMenu]; + + /* Finally give up our references to the objects */ + [appleMenu release]; + [menuItem release]; +} + +/* Create a window menu */ +static void setupWindowMenu(void) +{ + NSMenu *windowMenu; + NSMenuItem *windowMenuItem; + NSMenuItem *menuItem; + + windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; + + /* "Minimize" item */ + menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; + [windowMenu addItem:menuItem]; + [menuItem release]; + + /* Put menu into the menubar */ + windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; + [windowMenuItem setSubmenu:windowMenu]; + [[NSApp mainMenu] addItem:windowMenuItem]; + + /* Tell the application object that this is now the window menu */ + [NSApp setWindowsMenu:windowMenu]; + + /* Finally give up our references to the objects */ + [windowMenu release]; + [windowMenuItem release]; +} + +/* Replacement for NSApplicationMain */ +static void CustomApplicationMain (int argc, char **argv) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + SDLMain *sdlMain; + + /* Ensure the application object is initialised */ + [NSApplication sharedApplication]; + +#ifdef SDL_USE_CPS + { + CPSProcessSerNum PSN; + /* Tell the dock about us */ + if (!CPSGetCurrentProcess(&PSN)) + if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103)) + if (!CPSSetFrontProcess(&PSN)) + [NSApplication sharedApplication]; + } +#endif /* SDL_USE_CPS */ + + /* Set up the menubar */ + [NSApp setMainMenu:[[NSMenu alloc] init]]; + setApplicationMenu(); + setupWindowMenu(); + + /* Create SDLMain and make it the app delegate */ + sdlMain = [[SDLMain alloc] init]; + [NSApp setDelegate:sdlMain]; + + /* Start the main event loop */ + [NSApp run]; + + [sdlMain release]; + [pool release]; +} + +#endif + + +/* + * Catch document open requests...this lets us notice files when the app + * was launched by double-clicking a document, or when a document was + * dragged/dropped on the app's icon. You need to have a + * CFBundleDocumentsType section in your Info.plist to get this message, + * apparently. + * + * Files are added to gArgv, so to the app, they'll look like command line + * arguments. Previously, apps launched from the finder had nothing but + * an argv[0]. + * + * This message may be received multiple times to open several docs on launch. + * + * This message is ignored once the app's mainline has been called. + */ +- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename +{ + const char *temparg; + size_t arglen; + char *arg; + char **newargv; + + if (!gFinderLaunch) /* MacOS is passing command line args. */ + return FALSE; + + if (gCalledAppMainline) /* app has started, ignore this document. */ + return FALSE; + + temparg = [filename UTF8String]; + arglen = SDL_strlen(temparg) + 1; + arg = (char *) SDL_malloc(arglen); + if (arg == NULL) + return FALSE; + + newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2)); + if (newargv == NULL) + { + SDL_free(arg); + return FALSE; + } + gArgv = newargv; + + SDL_strlcpy(arg, temparg, arglen); + gArgv[gArgc++] = arg; + gArgv[gArgc] = NULL; + return TRUE; +} + + +/* Called when the internal event loop has just started running */ +- (void) applicationDidFinishLaunching: (NSNotification *) note +{ + int status; + + /* Set the working directory to the .app's parent directory */ + [self setupWorkingDirectory:gFinderLaunch]; + +#if SDL_USE_NIB_FILE + /* Set the main menu to contain the real app name instead of "SDL App" */ + [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()]; +#endif + + /* Hand off to main application code */ + gCalledAppMainline = TRUE; + status = SDL_main (gArgc, gArgv); + + /* We're done, thank you for playing */ + exit(status); +} +@end + + +@implementation NSString (ReplaceSubString) + +- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString +{ + unsigned int bufferSize; + unsigned int selfLen = [self length]; + unsigned int aStringLen = [aString length]; + unichar *buffer; + NSRange localRange; + NSString *result; + + bufferSize = selfLen + aStringLen - aRange.length; + buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar)); + + /* Get first part into buffer */ + localRange.location = 0; + localRange.length = aRange.location; + [self getCharacters:buffer range:localRange]; + + /* Get middle part into buffer */ + localRange.location = 0; + localRange.length = aStringLen; + [aString getCharacters:(buffer+aRange.location) range:localRange]; + + /* Get last part into buffer */ + localRange.location = aRange.location + aRange.length; + localRange.length = selfLen - localRange.location; + [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange]; + + /* Build output string */ + result = [NSString stringWithCharacters:buffer length:bufferSize]; + + NSDeallocateMemoryPages(buffer, bufferSize); + + return result; +} + +@end + + + +#ifdef main +# undef main +#endif + + +/* Main entry point to executable - should *not* be SDL_main! */ +int main (int argc, char **argv) +{ + /* Copy the arguments into a global variable */ + /* This is passed if we are launched by double-clicking */ + if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + gArgv = (char **) SDL_malloc(sizeof (char *) * 2); + gArgv[0] = argv[0]; + gArgv[1] = NULL; + gArgc = 1; + gFinderLaunch = YES; + } else { + int i; + gArgc = argc; + gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1)); + for (i = 0; i <= argc; i++) + gArgv[i] = argv[i]; + gFinderLaunch = NO; + } + +#if SDL_USE_NIB_FILE + NSApplicationMain (argc, argv); +#else + CustomApplicationMain (argc, argv); +#endif + return 0; +} + diff --git a/src/vdb.c b/src/vdb.c index 848497c..dc69000 100644 --- a/src/vdb.c +++ b/src/vdb.c @@ -19,7 +19,7 @@ extern int ScanDrawMode; */ -SCENE Global_Scene = 0; +SCENE Global_Scene/* = 0*/; @@ -386,37 +386,11 @@ static void CreateProjectorArray(VIEWDESCRIPTORBLOCK *vdb) SetVDB requires a VIEWDESCRIPTORBLOCK - See the actual function code for what each parameter is - */ -void SetVDB(vdb, fl, ty, d, cx,cy, prx,pry, mxp, cl,cr,cu,cd, h1,h2,hc, amb) - - VIEWDESCRIPTORBLOCK *vdb; - - int fl; - int ty; - - int d; - - int cx; - int cy; - - int prx; - int pry; - int mxp; - - int cl; - int cr; - int cu; - int cd; - - int h1; - int h2; - int hc; - - int amb; - +void SetVDB(VIEWDESCRIPTORBLOCK *vdb, int fl, int ty, int d, int cx, int cy, + int prx, int pry, int mxp, int cl, int cr, int cu, int cd, + int h1, int h2, int hc, int amb) { @@ -729,10 +703,7 @@ VIEWDESCRIPTORBLOCK* CreateActiveVDB(void) */ -int DestroyActiveVDB(dblockptr) - - VIEWDESCRIPTORBLOCK *dblockptr; - +int DestroyActiveVDB(VIEWDESCRIPTORBLOCK *dblockptr) { int j = -1; diff --git a/src/win95/animchnk.cpp b/src/win95/animchnk.cpp index f6802cb..adaecaa 100644 --- a/src/win95/animchnk.cpp +++ b/src/win95/animchnk.cpp @@ -218,7 +218,7 @@ FrameList::FrameList(TEXANIM* p,FrameList* fl,int* conv) FrameList::~FrameList() { delete [] Textures; - delete UVCoords; + delete [] UVCoords; } TEXANIM::TEXANIM() diff --git a/src/win95/animobs.cpp b/src/win95/animobs.cpp index 56539f5..f1c00ee 100644 --- a/src/win95/animobs.cpp +++ b/src/win95/animobs.cpp @@ -153,9 +153,9 @@ void Object_Animation_Sequence_Header_Chunk::fill_data_block (char *data_start) Object_Animation_Sequence_Header_Chunk::~Object_Animation_Sequence_Header_Chunk() { if (sequence_name) - delete sequence_name; + delete[] sequence_name; if(extra_data) - delete extra_data; + delete[] extra_data; } Object_Animation_Sequence_Header_Chunk::Object_Animation_Sequence_Header_Chunk (Chunk_With_Children * parent,const char * data_start, size_t) diff --git a/src/win95/animobs.hpp b/src/win95/animobs.hpp index 727df47..ee93efb 100644 --- a/src/win95/animobs.hpp +++ b/src/win95/animobs.hpp @@ -246,7 +246,9 @@ struct Object_Animation_Frame { ChunkQuat orientation; ChunkVectorInt transform; - signed long at_frame_no; //frame start time (0-65535) + + // SBF: 64HACK - changed long to int32_t as this structure isn't serialized correctly + int32_t at_frame_no; //frame start time (0-65535) int flags; int get_sound_index(){return ((flags & HierarchyFrame_SoundIndexMask )>>24);} diff --git a/src/win95/chnkload.cpp b/src/win95/chnkload.cpp index 1d450c2..99bc0a5 100644 --- a/src/win95/chnkload.cpp +++ b/src/win95/chnkload.cpp @@ -91,7 +91,7 @@ Shape_Fragment_Type::~Shape_Fragment_Type() #endif } - if(name) delete name; + if(name) delete[] name; } void Shape_Fragment_Type::AddShape(SHAPEHEADER* shp) @@ -2403,7 +2403,7 @@ BOOL copy_to_shapeheader ( uv_imnums[item_list[i*9+3]>>16]=local_tex_index_nos[texno]; item_list[i*9 + 3] += local_tex_index_nos[texno]; - shphd->sh_textures[UVIndex] = (int *) PoolAllocateMem (sizeof(int) * cshp_ptr->uv_list[UVIndex].num_verts * 2); + shphd->sh_textures[UVIndex] = (int *) PoolAllocateMem (sizeof(int *) * cshp_ptr->uv_list[UVIndex].num_verts * 2); for (j=0; juv_list[UVIndex].num_verts; j++) { (shphd->sh_textures[UVIndex])[(j*2)] = ProcessUVCoord(h,UVC_POLY_U,(int)cshp_ptr->uv_list[UVIndex].vert[j].u,uv_imnums[UVIndex]); (shphd->sh_textures[UVIndex])[(j*2)+1] = ProcessUVCoord(h,UVC_POLY_V,(int)cshp_ptr->uv_list[UVIndex].vert[j].v,uv_imnums[UVIndex]); @@ -3444,7 +3444,7 @@ BOOL copy_to_mainshpl (Shape_Chunk * shp, int list_pos) if (cshp.num_uvs) { for (i=0; ish_textures[i] = (int *) AllocateMem (sizeof(int) * cshp.uv_list[i].num_verts * 2); + shphd->sh_textures[i] = (int *) AllocateMem (sizeof(int *) * cshp.uv_list[i].num_verts * 2); for (j=0; jsh_textures[i])[(j*2)] = (int)cshp.uv_list[i].vert[j].u; (shphd->sh_textures[i])[(j*2)+1] = (int)cshp.uv_list[i].vert[j].v; @@ -3738,7 +3738,7 @@ BOOL copy_to_mainshpl (Shape_Sub_Shape_Chunk * shp, int list_pos) if (cshp.num_uvs) { for (i=0; ish_textures[i] = (int *) AllocateMem (sizeof(int) * cshp.uv_list[i].num_verts * 2); + shphd->sh_textures[i] = (int *) AllocateMem (sizeof(int *) * cshp.uv_list[i].num_verts * 2); for (j=0; jsh_textures[i])[(j*2)] = (int)cshp.uv_list[i].vert[j].u; (shphd->sh_textures[i])[(j*2)+1] = (int)cshp.uv_list[i].vert[j].v; @@ -3957,7 +3957,7 @@ BOOL copy_to_mainshpl (Shape_Sub_Shape_Chunk * shp, int list_pos) if (cshp.num_uvs) { for (i=0; ish_textures[i] = (int *) AllocateMem (sizeof(int) * cshp.uv_list[i].num_verts * 2); + shphd->sh_textures[i] = (int *) AllocateMem (sizeof(int *) * cshp.uv_list[i].num_verts * 2); for (j=0; jsh_textures[i])[(j*2)] = (int)cshp.uv_list[i].vert[j].u; (shphd->sh_textures[i])[(j*2)+1] = (int)cshp.uv_list[i].vert[j].v; diff --git a/src/win95/fragchnk.cpp b/src/win95/fragchnk.cpp index 1affcc7..50af938 100644 --- a/src/win95/fragchnk.cpp +++ b/src/win95/fragchnk.cpp @@ -56,7 +56,7 @@ Fragment_Type_Data_Chunk::Fragment_Type_Data_Chunk(Chunk_With_Children* const pa Fragment_Type_Data_Chunk::~Fragment_Type_Data_Chunk() { - if(frag_type_name) delete frag_type_name; + if(frag_type_name) delete [] frag_type_name; } void Fragment_Type_Data_Chunk::fill_data_block(char* data_start) @@ -124,7 +124,7 @@ Fragment_Type_Shape_Chunk::Fragment_Type_Shape_Chunk(Chunk_With_Children* const Fragment_Type_Shape_Chunk::~Fragment_Type_Shape_Chunk() { - if(name) delete name; + if(name) delete [] name; } void Fragment_Type_Shape_Chunk::fill_data_block(char* data_start) @@ -195,7 +195,7 @@ Fragment_Type_Sound_Chunk::Fragment_Type_Sound_Chunk(Chunk_With_Children* const Fragment_Type_Sound_Chunk::~Fragment_Type_Sound_Chunk() { - if(wav_name) delete wav_name; + if(wav_name) delete [] wav_name; } void Fragment_Type_Sound_Chunk::fill_data_block(char* data_start) diff --git a/src/win95/hash_tem.hpp b/src/win95/hash_tem.hpp index bc25f53..8edda53 100644 --- a/src/win95/hash_tem.hpp +++ b/src/win95/hash_tem.hpp @@ -242,7 +242,7 @@ inline unsigned HashFunction(void const * const _vP) { // treat as integer - return HashFunction(reinterpret_cast(_vP)); + return HashFunction(reinterpret_cast(_vP)); } // a hash function for strings diff --git a/src/win95/hierchnk.cpp b/src/win95/hierchnk.cpp index 56d4437..1ebe41e 100644 --- a/src/win95/hierchnk.cpp +++ b/src/win95/hierchnk.cpp @@ -323,7 +323,7 @@ Object_Hierarchy_Alternate_Shape_Set_Chunk::Object_Hierarchy_Alternate_Shape_Set Object_Hierarchy_Alternate_Shape_Set_Chunk::~Object_Hierarchy_Alternate_Shape_Set_Chunk() { - if(Shape_Set_Name) delete Shape_Set_Name; + if(Shape_Set_Name) delete[] Shape_Set_Name; while(Replaced_Shape_List.size()) { @@ -428,7 +428,7 @@ Hierarchy_Shape_Set_Collection_Chunk::Hierarchy_Shape_Set_Collection_Chunk(Chunk Hierarchy_Shape_Set_Collection_Chunk::~Hierarchy_Shape_Set_Collection_Chunk() { - if(Set_Collection_Name) delete Set_Collection_Name; + if(Set_Collection_Name) delete[] Set_Collection_Name; } void Hierarchy_Shape_Set_Collection_Chunk::fill_data_block(char* data_start) @@ -521,7 +521,7 @@ Hierarchy_Degradation_Distance_Chunk::Hierarchy_Degradation_Distance_Chunk(Chunk Hierarchy_Degradation_Distance_Chunk::~Hierarchy_Degradation_Distance_Chunk() { - if(distance_array)delete distance_array; + if(distance_array)delete[] distance_array; } void Hierarchy_Degradation_Distance_Chunk::fill_data_block(char* data_start) diff --git a/src/win95/hierchnk.hpp b/src/win95/hierchnk.hpp index 4772196..46dd333 100644 --- a/src/win95/hierchnk.hpp +++ b/src/win95/hierchnk.hpp @@ -101,8 +101,8 @@ struct Replaced_Shape_Details { ~Replaced_Shape_Details() { - if(old_object_name) delete old_object_name; - if(new_object_name) delete new_object_name; + if(old_object_name) delete[] old_object_name; + if(new_object_name) delete[] new_object_name; } //object name of shape to be replaced diff --git a/src/win95/mishchnk.cpp b/src/win95/mishchnk.cpp index a0e3795..c170364 100644 --- a/src/win95/mishchnk.cpp +++ b/src/win95/mishchnk.cpp @@ -639,7 +639,7 @@ void File_Chunk::post_input_processing() ol()->assoc_with_shape(shape_array[ol()->get_header()->shape_id_no]); } - delete shape_array; + delete [] shape_array; Chunk_With_Children::post_input_processing(); diff --git a/src/win95/obchunk.cpp b/src/win95/obchunk.cpp index b062570..2222370 100644 --- a/src/win95/obchunk.cpp +++ b/src/win95/obchunk.cpp @@ -1012,7 +1012,7 @@ Object_Track_Chunk2::Object_Track_Chunk2(Object_Chunk * parent) Object_Track_Chunk2::~Object_Track_Chunk2() { - if(sections) delete sections; + if(sections) delete [] sections; } void Object_Track_Chunk2::fill_data_block (char *data_start) @@ -1132,7 +1132,7 @@ Object_Track_Sound_Chunk::Object_Track_Sound_Chunk(Chunk_With_Children* const pa Object_Track_Sound_Chunk::~Object_Track_Sound_Chunk() { - if(wav_name) delete wav_name; + if(wav_name) delete [] wav_name; } void Object_Track_Sound_Chunk::fill_data_block(char* data_start) diff --git a/src/win95/shpchunk.cpp b/src/win95/shpchunk.cpp index 332ff39..779045b 100644 --- a/src/win95/shpchunk.cpp +++ b/src/win95/shpchunk.cpp @@ -1523,7 +1523,7 @@ Shape_Merge_Data_Chunk::Shape_Merge_Data_Chunk (Shape_Sub_Shape_Chunk * parent, Shape_Merge_Data_Chunk::~Shape_Merge_Data_Chunk() { - if (num_polys) delete merge_data; + if (num_polys) delete [] merge_data; } void Shape_Merge_Data_Chunk::fill_data_block(char * data_start) @@ -2575,7 +2575,7 @@ Shape_Fragment_Type_Chunk::Shape_Fragment_Type_Chunk(Chunk_With_Children* const Shape_Fragment_Type_Chunk::~Shape_Fragment_Type_Chunk() { - if(frag_type_name) delete frag_type_name; + if(frag_type_name) delete [] frag_type_name; } void Shape_Fragment_Type_Chunk::fill_data_block(char* data_start) @@ -3337,6 +3337,9 @@ void* Shape_Preprocessed_Data_Chunk::GetMemoryBlock() { void* retval=memory_block; +// 64HACK +#pragma message ("64HACK") +#if 0 unsigned int* current=(unsigned int*)&first_pointer; unsigned int* next; while((*current>>16)!=0xffff) @@ -3346,7 +3349,7 @@ void* Shape_Preprocessed_Data_Chunk::GetMemoryBlock() current=next; } *current=(unsigned int)&memory_block[(*current)&0xffff]; - +#endif memory_block=0; block_size=0; return retval; diff --git a/src/winfiles.c b/src/winfiles.c index 8cc87b6..798210d 100644 --- a/src/winfiles.c +++ b/src/winfiles.c @@ -678,7 +678,7 @@ static char* GetLocalDirectory(void) if( homepath != NULL ) { - homedir = (unsigned char*)malloc(strlen(homedrive)+strlen(homepath)+1); + homedir = (char*)malloc(strlen(homedrive)+strlen(homepath)+1); strcpy(homedir, homedrive); strcat(homedir, homepath); @@ -704,7 +704,7 @@ static char* GetLocalDirectory(void) homedir = _strdup("."); } - localdir = (unsigned char*)malloc(strlen(homedir) + 10); + localdir = (char*)malloc(strlen(homedir) + 10); strcpy(localdir, homedir); strcat(localdir, "\\AvPLinux"); // temp name, maybe @@ -762,11 +762,13 @@ static const char* GetGlobalDirectory(const char* argv0) /* Game-specific initialization */ +extern "C" { + extern char const *SecondTex_Directory; + extern char const *SecondSoundDir; +} + void InitGameDirectories(char *argv0) { - extern char *SecondTex_Directory; - extern char *SecondSoundDir; - const char* localdir; const char* globaldir; -- cgit v1.3