From 298393b653d8a60e20291cbd4c9ae1a699644c24 Mon Sep 17 00:00:00 2001 From: mittorn Date: Wed, 5 Dec 2018 23:57:05 +0700 Subject: [PATCH] Initial amd64 port --- engine/client/cl_demo.c | 8 +- engine/client/cl_gameui.c | 2 +- engine/client/cl_remap.c | 12 +- engine/client/cl_video.c | 4 +- engine/client/client.h | 6 +- engine/client/gl_studio.c | 3 +- engine/client/mod_dbghulls.c | 6 +- engine/client/s_stream.c | 4 +- engine/client/s_vox.c | 4 +- engine/client/titles.c | 8 +- engine/common/common.c | 22 +-- engine/common/common.h | 37 +++-- engine/common/custom.c | 2 +- engine/common/filesystem.c | 68 ++++---- engine/common/host.c | 2 +- engine/common/imagelib/img_bmp.c | 24 +-- engine/common/imagelib/img_main.c | 5 +- engine/common/imagelib/img_wad.c | 19 ++- engine/common/mathlib.h | 6 +- engine/common/mod_bmodel.c | 2 +- engine/common/mod_studio.c | 4 +- engine/common/net_buffer.c | 22 +-- engine/common/net_buffer.h | 6 +- engine/common/net_ws.c | 2 +- engine/common/protocol.h | 10 +- engine/common/soundlib/snd_main.c | 10 +- engine/common/soundlib/snd_mp3.c | 18 +- engine/common/soundlib/snd_wav.c | 8 +- engine/common/soundlib/soundlib.h | 28 ++-- engine/eiface.h | 2 +- engine/server/server.h | 6 +- engine/server/sv_client.c | 2 +- engine/server/sv_game.c | 264 +++++++++++++++++++++++++++--- engine/server/sv_init.c | 5 +- engine/server/sv_save.c | 2 +- 35 files changed, 440 insertions(+), 193 deletions(-) diff --git a/engine/client/cl_demo.c b/engine/client/cl_demo.c index 962e99c2..5c069fef 100644 --- a/engine/client/cl_demo.c +++ b/engine/client/cl_demo.c @@ -349,9 +349,9 @@ Write demo header */ void CL_WriteDemoHeader( const char *name ) { - long copysize; - long savepos; - long curpos; + int copysize; + int savepos; + int curpos; Con_Printf( "recording to %s.\n", name ); cls.demofile = FS_Open( name, "wb", false ); @@ -489,7 +489,7 @@ void CL_DrawDemoRecording( void ) { char string[64]; rgba_t color = { 255, 255, 255, 255 }; - long pos; + int pos; int len; if(!( host_developer.value && cls.demorecording )) diff --git a/engine/client/cl_gameui.c b/engine/client/cl_gameui.c index 5887c341..eaf9a890 100644 --- a/engine/client/cl_gameui.c +++ b/engine/client/cl_gameui.c @@ -376,7 +376,7 @@ pfnPIC_Load ========= */ -static HIMAGE pfnPIC_Load( const char *szPicName, const byte *image_buf, long image_size, long flags ) +static HIMAGE pfnPIC_Load( const char *szPicName, const byte *image_buf, int image_size, int flags ) { HIMAGE tx; diff --git a/engine/client/cl_remap.c b/engine/client/cl_remap.c index dfa7af55..637dc4ed 100644 --- a/engine/client/cl_remap.c +++ b/engine/client/cl_remap.c @@ -78,7 +78,9 @@ byte *CL_CreateRawTextureFromPixels( texture_t *tx, size_t *size, int topcolor, // fill header if( !pin.name[0] ) Q_strncpy( pin.name, "#raw_remap_image.mdl", sizeof( pin.name )); pin.flags = STUDIO_NF_COLORMAP; // just in case :-) - pin.index = (int)(tx + 1); // pointer to pixels + //pin.index = (int)(tx + 1); // pointer to pixels + // no more pointer-to-int-to-pointer casts + Image_SetMDLPointer( (byte*)((texture_t *)tx + 1) ); pin.width = tx->width; pin.height = tx->height; @@ -102,7 +104,8 @@ void CL_DuplicateTexture( mstudiotexture_t *ptexture, int topcolor, int bottomco gl_texture_t *glt; texture_t *tx = NULL; char texname[128]; - int i, size, index; + int i, index; + size_t size; byte paletteBackup[768]; byte *raw, *pal; @@ -145,7 +148,8 @@ void CL_UpdateStudioTexture( mstudiotexture_t *ptexture, int topcolor, int botto rgbdata_t *pic; texture_t *tx = NULL; char texname[128], name[128], mdlname[128]; - int i, size, index; + int i, index; + size_t size; byte paletteBackup[768]; byte *raw, *pal; @@ -430,4 +434,4 @@ void CL_ClearAllRemaps( void ) Mem_Free( clgame.remap_info ); } clgame.remap_info = NULL; -} \ No newline at end of file +} diff --git a/engine/client/cl_video.c b/engine/client/cl_video.c index 58de74b2..d386ac20 100644 --- a/engine/client/cl_video.c +++ b/engine/client/cl_video.c @@ -242,7 +242,7 @@ qboolean SCR_PlayCinematic( const char *arg ) return true; } -long SCR_GetAudioChunk( char *rawdata, long length ) +int SCR_GetAudioChunk( char *rawdata, int length ) { int r; @@ -307,4 +307,4 @@ void SCR_FreeCinematic( void ) AVI_CloseVideo( cin_state ); AVI_Shutdown(); -} \ No newline at end of file +} diff --git a/engine/client/client.h b/engine/client/client.h index 91ad215c..18fcd300 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -548,8 +548,8 @@ typedef struct ui_globalvars_t *globals; qboolean drawLogo; // set to TRUE if logo.avi missed or corrupted - long logo_xres; - long logo_yres; + int logo_xres; + int logo_yres; float logo_length; qboolean use_text_api; @@ -1058,7 +1058,7 @@ void Con_LoadHistory( void ); // void S_StreamRawSamples( int samples, int rate, int width, int channels, const byte *data ); void S_StreamAviSamples( void *Avi, int entnum, float fvol, float attn, float synctime ); -void S_StartBackgroundTrack( const char *intro, const char *loop, long position, qboolean fullpath ); +void S_StartBackgroundTrack( const char *intro, const char *loop, int position, qboolean fullpath ); void S_StopBackgroundTrack( void ); void S_StreamSetPause( int pause ); void S_StartStreaming( void ); diff --git a/engine/client/gl_studio.c b/engine/client/gl_studio.c index 40ec0926..ed0ceff4 100644 --- a/engine/client/gl_studio.c +++ b/engine/client/gl_studio.c @@ -3560,7 +3560,8 @@ static void R_StudioLoadTexture( model_t *mod, studiohdr_t *phdr, mstudiotexture SetBits( flags, TF_NOMIPMAP ); // NOTE: replace index with pointer to start of imagebuffer, ImageLib expected it - ptexture->index = (int)((byte *)phdr) + ptexture->index; + //ptexture->index = (int)((byte *)phdr) + ptexture->index; + Image_SetMDLPointer((byte *)phdr + ptexture->index); size = sizeof( mstudiotexture_t ) + ptexture->width * ptexture->height + 768; if( FBitSet( host.features, ENGINE_LOAD_DELUXEDATA ) && FBitSet( ptexture->flags, STUDIO_NF_MASKED )) diff --git a/engine/client/mod_dbghulls.c b/engine/client/mod_dbghulls.c index d2226d0f..edf27a31 100644 --- a/engine/client/mod_dbghulls.c +++ b/engine/client/mod_dbghulls.c @@ -733,7 +733,7 @@ void R_DrawWorldHull( void ) list_for_each_entry( poly, &hull->polys, chain ) { - srand((unsigned long)poly); + srand((unsigned int)poly); pglColor3f( rand() % 256 / 255.0, rand() % 256 / 255.0, rand() % 256 / 255.0 ); pglBegin( GL_POLYGON ); for( i = 0; i < poly->numpoints; i++ ) @@ -766,7 +766,7 @@ void R_DrawModelHull( void ) pglDisable( GL_TEXTURE_2D ); list_for_each_entry( poly, &hull->polys, chain ) { - srand((unsigned long)poly); + srand((unsigned int)poly); pglColor3f( rand() % 256 / 255.0, rand() % 256 / 255.0, rand() % 256 / 255.0 ); pglBegin( GL_POLYGON ); for( i = 0; i < poly->numpoints; i++ ) @@ -775,4 +775,4 @@ void R_DrawModelHull( void ) } pglEnable( GL_TEXTURE_2D ); pglDisable( GL_POLYGON_OFFSET_FILL ); -} \ No newline at end of file +} diff --git a/engine/client/s_stream.c b/engine/client/s_stream.c index bc7a8acc..c912548a 100644 --- a/engine/client/s_stream.c +++ b/engine/client/s_stream.c @@ -71,7 +71,7 @@ float S_GetMusicVolume( void ) S_StartBackgroundTrack ================= */ -void S_StartBackgroundTrack( const char *introTrack, const char *mainTrack, long position, qboolean fullpath ) +void S_StartBackgroundTrack( const char *introTrack, const char *mainTrack, int position, qboolean fullpath ) { S_StopBackgroundTrack(); @@ -341,4 +341,4 @@ void S_StreamSoundTrack( void ) } else break; // no more samples for this frame } -} \ No newline at end of file +} diff --git a/engine/client/s_vox.c b/engine/client/s_vox.c index bee8ae90..39b0e1d7 100644 --- a/engine/client/s_vox.c +++ b/engine/client/s_vox.c @@ -606,7 +606,7 @@ void VOX_ReadSentenceFile( const char *psentenceFileName ) { char c, *pch, *pFileData; char *pchlast, *pSentenceData; - int fileSize; + size_t fileSize; // load file pFileData = (char *)FS_LoadFile( psentenceFileName, &fileSize, false ); @@ -684,4 +684,4 @@ void VOX_Init( void ) void VOX_Shutdown( void ) { g_numSentences = 0; -} \ No newline at end of file +} diff --git a/engine/client/titles.c b/engine/client/titles.c index 23b55fcb..a2b4ccbc 100644 --- a/engine/client/titles.c +++ b/engine/client/titles.c @@ -325,16 +325,18 @@ void CL_TextMessageParse( byte *pMemFile, int fileSize ) // copy Name heap pNameHeap = ((char *)clgame.titles) + messageSize; memcpy( pNameHeap, nameHeap, nameHeapSize ); - nameOffset = pNameHeap - clgame.titles[0].pName; + //nameOffset = pNameHeap - clgame.titles[0].pName; //undefined on amd64 + // copy text & fixup pointers pCurrentText = pNameHeap + nameHeapSize; for( i = 0; i < messageCount; i++ ) { - clgame.titles[i].pName += nameOffset; // adjust name pointer (parallel buffer) + clgame.titles[i].pName = pNameHeap; // adjust name pointer (parallel buffer) Q_strcpy( pCurrentText, clgame.titles[i].pMessage ); // copy text over clgame.titles[i].pMessage = pCurrentText; + pNameHeap += Q_strlen( pNameHeap ) + 1; pCurrentText += Q_strlen( pCurrentText ) + 1; } @@ -342,4 +344,4 @@ void CL_TextMessageParse( byte *pMemFile, int fileSize ) Con_DPrintf( S_ERROR "TextMessage: overflow text message buffer!\n" ); clgame.numTitles = messageCount; -} \ No newline at end of file +} diff --git a/engine/common/common.c b/engine/common/common.c index b5f06d40..286bccb0 100644 --- a/engine/common/common.c +++ b/engine/common/common.c @@ -45,7 +45,7 @@ void DBG_AssertFunction( qboolean fExpr, const char* szExpr, const char* szFile, } #endif // DEBUG -static long idum = 0; +static int idum = 0; #define MAX_RANDOM_RANGE 0x7FFFFFFFUL #define IA 16807 @@ -58,12 +58,12 @@ static long idum = 0; #define AM (1.0 / IM) #define RNMX (1.0 - EPS) -static long lran1( void ) +static int lran1( void ) { - static long iy = 0; - static long iv[NTAB]; + static int iy = 0; + static int iv[NTAB]; int j; - long k; + int k; if( idum <= 0 || !iy ) { @@ -100,7 +100,7 @@ static float fran1( void ) return temp; } -void COM_SetRandomSeed( long lSeed ) +void COM_SetRandomSeed( int lSeed ) { if( lSeed ) idum = lSeed; else idum = -time( NULL ); @@ -1009,7 +1009,7 @@ byte* COM_LoadFileForMe( const char *filename, int *pLength ) { string name; byte *file, *pfile; - long iLength; + size_t iLength; if( !COM_CheckString( filename )) { @@ -1052,11 +1052,11 @@ byte *COM_LoadFile( const char *filename, int usehunk, int *pLength ) /* ============= -COM_LoadFile +COM_SaveFile ============= */ -int COM_SaveFile( const char *filename, const void *data, long len ) +int COM_SaveFile( const char *filename, const void *data, int len ) { // check for empty filename if( !COM_CheckString( filename )) @@ -1222,8 +1222,8 @@ int COM_CompareFileTime( const char *filename1, const char *filename2, int *iCom if( filename1 && filename2 ) { - long ft1 = FS_FileTime( filename1, false ); - long ft2 = FS_FileTime( filename2, false ); + int ft1 = FS_FileTime( filename1, false ); + int ft2 = FS_FileTime( filename2, false ); // one of files is missing if( ft1 == -1 || ft2 == -1 ) diff --git a/engine/common/common.h b/engine/common/common.h index 32042092..1fcf8737 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -545,9 +545,9 @@ const char *FS_GetDiskPath( const char *name, qboolean gamedironly ); const char *COM_FileWithoutPath( const char *in ); byte *W_LoadLump( wfile_t *wad, const char *lumpname, size_t *lumpsizeptr, const char type ); void W_Close( wfile_t *wad ); -byte *FS_LoadFile( const char *path, long *filesizeptr, qboolean gamedironly ); -byte *FS_LoadDirectFile( const char *path, long *filesizeptr ); -qboolean FS_WriteFile( const char *filename, const void *data, long len ); +byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly ); +byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr ); +qboolean FS_WriteFile( const char *filename, const void *data, fs_offset_t len ); qboolean COM_ParseVector( char **pfile, float *v, size_t size ); void COM_NormalizeAngles( vec3_t angles ); int COM_FileSize( const char *filename ); @@ -557,14 +557,14 @@ int COM_CheckString( const char *string ); int COM_CompareFileTime( const char *filename1, const char *filename2, int *iCompare ); search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly ); file_t *FS_Open( const char *filepath, const char *mode, qboolean gamedironly ); -long FS_Write( file_t *file, const void *data, size_t datasize ); -long FS_Read( file_t *file, void *buffer, size_t buffersize ); +fs_offset_t FS_Write( file_t *file, const void *data, size_t datasize ); +fs_offset_t FS_Read( file_t *file, void *buffer, size_t buffersize ); int FS_VPrintf( file_t *file, const char *format, va_list ap ); -int FS_Seek( file_t *file, long offset, int whence ); +int FS_Seek( file_t *file, fs_offset_t offset, int whence ); int FS_Gets( file_t *file, byte *string, size_t bufsize ); int FS_Printf( file_t *file, const char *format, ... ) _format( 2 ); -long FS_FileSize( const char *filename, qboolean gamedironly ); -long FS_FileTime( const char *filename, qboolean gamedironly ); +fs_offset_t FS_FileSize( const char *filename, qboolean gamedironly ); +int FS_FileTime( const char *filename, qboolean gamedironly ); int FS_Print( file_t *file, const char *msg ); qboolean FS_Rename( const char *oldname, const char *newname ); int FS_FileExists( const char *filename, int gamedironly ); @@ -573,11 +573,11 @@ qboolean FS_FileCopy( file_t *pOutput, file_t *pInput, int fileSize ); qboolean FS_Delete( const char *path ); int FS_UnGetc( file_t *file, byte c ); void COM_StripExtension( char *path ); -long FS_Tell( file_t *file ); +fs_offset_t FS_Tell( file_t *file ); qboolean FS_Eof( file_t *file ); int FS_Close( file_t *file ); int FS_Getc( file_t *file ); -long FS_FileLength( file_t *f ); +fs_offset_t FS_FileLength( file_t *f ); /* ======================================================================== @@ -704,6 +704,7 @@ void Image_PaletteTranslate( byte *palSrc, int top, int bottom, int pal_size ); void Image_SetForceFlags( uint flags ); // set image force flags on loading size_t Image_DXTGetLinearSize( int type, int width, int height, int depth ); void Image_ClearForceFlags( void ); +void Image_SetMDLPointer( byte *p ); /* ======================================================================== @@ -763,9 +764,9 @@ wavdata_t *FS_LoadSound( const char *filename, const byte *buffer, size_t size ) void FS_FreeSound( wavdata_t *pack ); stream_t *FS_OpenStream( const char *filename ); wavdata_t *FS_StreamInfo( stream_t *stream ); -long FS_ReadStream( stream_t *stream, int bytes, void *buffer ); -long FS_SetStreamPos( stream_t *stream, long newpos ); -long FS_GetStreamPos( stream_t *stream ); +int FS_ReadStream( stream_t *stream, int bytes, void *buffer ); +int FS_SetStreamPos( stream_t *stream, int newpos ); +int FS_GetStreamPos( stream_t *stream ); void FS_FreeStream( stream_t *stream ); qboolean Sound_Process( wavdata_t **wav, int rate, int width, uint flags ); uint Sound_GetApproxWavePlayLen( const char *filepath ); @@ -784,7 +785,7 @@ const char *Q_buildcommit( void ); // qboolean Host_IsQuakeCompatible( void ); void EXPORT Host_Shutdown( void ); -int Host_CompareFileTime( long ft1, long ft2 ); +int Host_CompareFileTime( int ft1, int ft2 ); void Host_NewInstance( const char *name, const char *finalmsg ); void Host_EndGame( qboolean abort, const char *message, ... ) _format( 2 ); void Host_AbortCurrentFrame( void ); @@ -842,7 +843,7 @@ cvar_t *pfnCvar_RegisterClientVariable( const char *szName, const char *szValue, cvar_t *pfnCvar_RegisterGameUIVariable( const char *szName, const char *szValue, int flags ); char *COM_MemFgets( byte *pMemFile, int fileSize, int *filePos, char *pBuffer, int bufferSize ); void COM_HexConvert( const char *pszInput, int nInputLength, byte *pOutput ); -int COM_SaveFile( const char *filename, const void *data, long len ); +int COM_SaveFile( const char *filename, const void *data, int len ); byte* COM_LoadFileForMe( const char *filename, int *pLength ); qboolean COM_IsSafeFileToDownload( const char *filename ); cvar_t *pfnCVarGetPointer( const char *szVarName ); @@ -986,7 +987,7 @@ struct cmdalias_s *Cmd_AliasGetList( void ); char *Cmd_GetName( struct cmd_s *cmd ); struct pmtrace_s *PM_TraceLine( float *start, float *end, int flags, int usehull, int ignore_pe ); void SV_StartSound( edict_t *ent, int chan, const char *sample, float vol, float attn, int flags, int pitch ); -void SV_StartMusic( const char *curtrack, const char *looptrack, long position ); +void SV_StartMusic( const char *curtrack, const char *looptrack, int position ); void SV_CreateDecal( sizebuf_t *msg, const float *origin, int decalIndex, int entityIndex, int modelIndex, int flags, float scale ); void Log_Printf( const char *fmt, ... ) _format( 1 ); struct sizebuf_s *SV_GetReliableDatagram( void ); @@ -1043,7 +1044,7 @@ void SCR_Init( void ); void SCR_UpdateScreen( void ); void SCR_BeginLoadingPlaque( qboolean is_background ); void SCR_CheckStartupVids( void ); -long SCR_GetAudioChunk( char *rawdata, long length ); +int SCR_GetAudioChunk( char *rawdata, int length ); wavdata_t *SCR_GetMovieInfo( void ); void SCR_Shutdown( void ); void Con_Print( const char *txt ); @@ -1061,7 +1062,7 @@ void Info_WriteVars( file_t *f ); void Info_Print( const char *s ); void Cmd_WriteVariables( file_t *f ); int Cmd_CheckMapsList( int fRefresh ); -void COM_SetRandomSeed( long lSeed ); +void COM_SetRandomSeed( int lSeed ); int COM_RandomLong( int lMin, int lMax ); float COM_RandomFloat( float fMin, float fMax ); qboolean LZSS_IsCompressed( const byte *source ); diff --git a/engine/common/custom.c b/engine/common/custom.c index f624b0c6..a379b38b 100644 --- a/engine/common/custom.c +++ b/engine/common/custom.c @@ -63,7 +63,7 @@ void COM_ClearCustomizationList( customization_t *pHead, qboolean bCleanDecals ) qboolean COM_CreateCustomization( customization_t *pListHead, resource_t *pResource, int playernumber, int flags, customization_t **pOut, int *nLumps ) { qboolean bError = false; - long checksize = 0; + size_t checksize = 0; customization_t *pCust; if( pOut ) *pOut = NULL; diff --git a/engine/common/filesystem.c b/engine/common/filesystem.c index 7cb184dc..a3b7e772 100644 --- a/engine/common/filesystem.c +++ b/engine/common/filesystem.c @@ -68,13 +68,13 @@ typedef struct wadtype_s typedef struct file_s { int handle; // file descriptor - long real_length; // uncompressed file size (for files opened in "read" mode) - long position; // current position in the file - long offset; // offset into the package (0 if external file) + fs_offset_t real_length; // uncompressed file size (for files opened in "read" mode) + fs_offset_t position; // current position in the file + fs_offset_t offset; // offset into the package (0 if external file) int ungetc; // single stored character from ungetc, cleared to EOF when read time_t filetime; // pak, wad or real filetime // contents buffer - long buff_ind, buff_len; // buffer current index and length + fs_offset_t buff_ind, buff_len; // buffer current index and length byte buff[FILE_BUFF_SIZE]; // intermediate buffer } file_t; @@ -123,11 +123,11 @@ qboolean fs_caseinsensitive = true; // try to search missing files static void FS_InitMemory( void ); static searchpath_t *FS_FindFile( const char *name, int *index, qboolean gamedironly ); static dlumpinfo_t *W_FindLump( wfile_t *wad, const char *name, const char matchtype ); -static dpackfile_t *FS_AddFileToPack( const char* name, pack_t *pack, long offset, long size ); -static byte *W_LoadFile( const char *path, long *filesizeptr, qboolean gamedironly ); +static dpackfile_t *FS_AddFileToPack( const char* name, pack_t *pack, fs_offset_t offset, fs_offset_t size ); +static byte *W_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly ); static wfile_t *W_Open( const char *filename, int *errorcode ); static qboolean FS_SysFolderExists( const char *path ); -static long FS_SysFileTime( const char *filename ); +static int FS_SysFileTime( const char *filename ); static char W_TypeFromExt( const char *lumpname ); static const char *W_ExtFromType( char lumptype ); static void FS_Purge( file_t* file ); @@ -389,7 +389,7 @@ FS_AddFileToPack Add a file to the list of files contained into a package ==================== */ -static dpackfile_t *FS_AddFileToPack( const char *name, pack_t *pack, long offset, long size ) +static dpackfile_t *FS_AddFileToPack( const char *name, pack_t *pack, fs_offset_t offset, fs_offset_t size ) { int left, right, middle; dpackfile_t *pfile; @@ -1705,7 +1705,7 @@ FS_SysFileTime Internal function used to determine filetime ==================== */ -static long FS_SysFileTime( const char *filename ) +static int FS_SysFileTime( const char *filename ) { struct stat buf; @@ -2154,9 +2154,9 @@ FS_Write Write "datasize" bytes into a file ==================== */ -long FS_Write( file_t *file, const void *data, size_t datasize ) +fs_offset_t FS_Write( file_t *file, const void *data, size_t datasize ) { - long result; + fs_offset_t result; if( !file ) return 0; @@ -2168,7 +2168,7 @@ long FS_Write( file_t *file, const void *data, size_t datasize ) FS_Purge( file ); // write the buffer and update the position - result = write( file->handle, data, (long)datasize ); + result = write( file->handle, data, (fs_offset_t)datasize ); file->position = lseek( file->handle, 0, SEEK_CUR ); if( file->real_length < file->position ) @@ -2186,10 +2186,10 @@ FS_Read Read up to "buffersize" bytes from a file ==================== */ -long FS_Read( file_t *file, void *buffer, size_t buffersize ) +fs_offset_t FS_Read( file_t *file, void *buffer, size_t buffersize ) { - long count, done; - long nb; + fs_offset_t count, done; + fs_offset_t nb; // nothing to copy if( buffersize == 0 ) return 1; @@ -2209,7 +2209,7 @@ long FS_Read( file_t *file, void *buffer, size_t buffersize ) { count = file->buff_len - file->buff_ind; - done += ((long)buffersize > count ) ? count : (long)buffersize; + done += ((fs_offset_t)buffersize > count ) ? count : (fs_offset_t)buffersize; memcpy( buffer, &file->buff[file->buff_ind], done ); file->buff_ind += done; @@ -2226,8 +2226,8 @@ long FS_Read( file_t *file, void *buffer, size_t buffersize ) // if we have a lot of data to get, put them directly into "buffer" if( buffersize > sizeof( file->buff ) / 2 ) { - if( count > (long)buffersize ) - count = (long)buffersize; + if( count > (fs_offset_t)buffersize ) + count = (fs_offset_t)buffersize; lseek( file->handle, file->offset + file->position, SEEK_SET ); nb = read (file->handle, &((byte *)buffer)[done], count ); @@ -2241,8 +2241,8 @@ long FS_Read( file_t *file, void *buffer, size_t buffersize ) } else { - if( count > (long)sizeof( file->buff )) - count = (long)sizeof( file->buff ); + if( count > (fs_offset_t)sizeof( file->buff )) + count = (fs_offset_t)sizeof( file->buff ); lseek( file->handle, file->offset + file->position, SEEK_SET ); nb = read( file->handle, file->buff, count ); @@ -2252,7 +2252,7 @@ long FS_Read( file_t *file, void *buffer, size_t buffersize ) file->position += nb; // copy the requested data in "buffer" (as much as we can) - count = (long)buffersize > file->buff_len ? file->buff_len : (long)buffersize; + count = (fs_offset_t)buffersize > file->buff_len ? file->buff_len : (fs_offset_t)buffersize; memcpy( &((byte *)buffer)[done], file->buff, count ); file->buff_ind = count; done += count; @@ -2303,7 +2303,7 @@ Print a string into a file int FS_VPrintf( file_t *file, const char *format, va_list ap ) { int len; - long buff_size = MAX_SYSPATH; + fs_offset_t buff_size = MAX_SYSPATH; char *tempbuff; if( !file ) return 0; @@ -2402,7 +2402,7 @@ FS_Seek Move the position index in a file ==================== */ -int FS_Seek( file_t *file, long offset, int whence ) +int FS_Seek( file_t *file, fs_offset_t offset, int whence ) { // compute the file offset switch( whence ) @@ -2446,7 +2446,7 @@ FS_Tell Give the current position in a file ==================== */ -long FS_Tell( file_t *file ) +fs_offset_t FS_Tell( file_t *file ) { if( !file ) return 0; return file->position - file->buff_len + file->buff_ind; @@ -2487,11 +2487,11 @@ Filename are relative to the xash directory. Always appends a 0 byte. ============ */ -byte *FS_LoadFile( const char *path, long *filesizeptr, qboolean gamedironly ) +byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly ) { file_t *file; byte *buf = NULL; - long filesize = 0; + fs_offset_t filesize = 0; file = FS_Open( path, "rb", gamedironly ); @@ -2522,11 +2522,11 @@ Filename are relative to the xash directory. Always appends a 0 byte. ============ */ -byte *FS_LoadDirectFile( const char *path, long *filesizeptr ) +byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr ) { file_t *file; byte *buf = NULL; - long filesize = 0; + fs_offset_t filesize = 0; file = FS_SysOpen( path, "rb" ); @@ -2556,7 +2556,7 @@ FS_WriteFile The filename will be prefixed by the current game directory ============ */ -qboolean FS_WriteFile( const char *filename, const void *data, long len ) +qboolean FS_WriteFile( const char *filename, const void *data, fs_offset_t len ) { file_t *file; @@ -2724,7 +2724,7 @@ FS_FileSize return size of file in bytes ================== */ -long FS_FileSize( const char *filename, qboolean gamedironly ) +fs_offset_t FS_FileSize( const char *filename, qboolean gamedironly ) { int length = -1; // in case file was missed file_t *fp; @@ -2749,7 +2749,7 @@ FS_FileLength return size of file in bytes ================== */ -long FS_FileLength( file_t *f ) +fs_offset_t FS_FileLength( file_t *f ) { if( !f ) return 0; return f->real_length; @@ -2762,7 +2762,7 @@ FS_FileTime return time of creation file in seconds ================== */ -long FS_FileTime( const char *filename, qboolean gamedironly ) +int FS_FileTime( const char *filename, qboolean gamedironly ) { searchpath_t *search; int pack_ind; @@ -3253,7 +3253,7 @@ W_ReadLump reading lump into temp buffer =========== */ -byte *W_ReadLump( wfile_t *wad, dlumpinfo_t *lump, long *lumpsizeptr ) +byte *W_ReadLump( wfile_t *wad, dlumpinfo_t *lump, fs_offset_t *lumpsizeptr ) { size_t oldpos, size = 0; byte *buf; @@ -3454,7 +3454,7 @@ W_LoadFile loading lump into the tmp buffer =========== */ -static byte *W_LoadFile( const char *path, long *lumpsizeptr, qboolean gamedironly ) +static byte *W_LoadFile( const char *path, fs_offset_t *lumpsizeptr, qboolean gamedironly ) { searchpath_t *search; int index; diff --git a/engine/common/host.c b/engine/common/host.c index 92e1c539..0fd6dec7 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -57,7 +57,7 @@ convar_t *host_framerate; convar_t *con_gamemaps; convar_t *build, *ver; -int Host_CompareFileTime( long ft1, long ft2 ) +int Host_CompareFileTime( int ft1, int ft2 ) { if( ft1 < ft2 ) { diff --git a/engine/common/imagelib/img_bmp.c b/engine/common/imagelib/img_bmp.c index 498e215d..12415cf5 100644 --- a/engine/common/imagelib/img_bmp.c +++ b/engine/common/imagelib/img_bmp.c @@ -48,20 +48,20 @@ qboolean Image_LoadBMP( const char *name, const byte *buffer, size_t filesize ) buf_p = (byte *)buffer; bhdr.id[0] = *buf_p++; bhdr.id[1] = *buf_p++; // move pointer - bhdr.fileSize = *(long *)buf_p; buf_p += 4; - bhdr.reserved0 = *(long *)buf_p; buf_p += 4; - bhdr.bitmapDataOffset = *(long *)buf_p; buf_p += 4; - bhdr.bitmapHeaderSize = *(long *)buf_p; buf_p += 4; - bhdr.width = *(long *)buf_p; buf_p += 4; - bhdr.height = *(long *)buf_p; buf_p += 4; + bhdr.fileSize = *(int *)buf_p; buf_p += 4; + bhdr.reserved0 = *(int *)buf_p; buf_p += 4; + bhdr.bitmapDataOffset = *(int *)buf_p; buf_p += 4; + bhdr.bitmapHeaderSize = *(int *)buf_p; buf_p += 4; + bhdr.width = *(int *)buf_p; buf_p += 4; + bhdr.height = *(int *)buf_p; buf_p += 4; bhdr.planes = *(short *)buf_p; buf_p += 2; bhdr.bitsPerPixel = *(short *)buf_p; buf_p += 2; - bhdr.compression = *(long *)buf_p; buf_p += 4; - bhdr.bitmapDataSize = *(long *)buf_p; buf_p += 4; - bhdr.hRes = *(long *)buf_p; buf_p += 4; - bhdr.vRes = *(long *)buf_p; buf_p += 4; - bhdr.colors = *(long *)buf_p; buf_p += 4; - bhdr.importantColors = *(long *)buf_p; buf_p += 4; + bhdr.compression = *(int *)buf_p; buf_p += 4; + bhdr.bitmapDataSize = *(int *)buf_p; buf_p += 4; + bhdr.hRes = *(int *)buf_p; buf_p += 4; + bhdr.vRes = *(int *)buf_p; buf_p += 4; + bhdr.colors = *(int *)buf_p; buf_p += 4; + bhdr.importantColors = *(int *)buf_p; buf_p += 4; // bogus file header check if( bhdr.reserved0 != 0 ) return false; diff --git a/engine/common/imagelib/img_main.c b/engine/common/imagelib/img_main.c index 57cf79d4..e9f3f6e9 100644 --- a/engine/common/imagelib/img_main.c +++ b/engine/common/imagelib/img_main.c @@ -213,7 +213,8 @@ rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size ) const char *ext = COM_FileExtension( filename ); string path, loadname, sidename; qboolean anyformat = true; - int i, filesize = 0; + int i; + size_t filesize = 0; const loadpixformat_t *format; const cubepack_t *cmap; byte *f; @@ -488,4 +489,4 @@ rgbdata_t *FS_CopyImage( rgbdata_t *in ) } return out; -} \ No newline at end of file +} diff --git a/engine/common/imagelib/img_wad.c b/engine/common/imagelib/img_wad.c index 954e3c8c..f5e4eecb 100644 --- a/engine/common/imagelib/img_wad.c +++ b/engine/common/imagelib/img_wad.c @@ -129,6 +129,19 @@ qboolean Image_LoadFNT( const char *name, const byte *buffer, size_t filesize ) return Image_AddIndexedImageToPack( fin, image.width, image.height ); } +/* +====================== +Image_SetMDLPointer + +Transfer buffer pointer before Image_LoadMDL +====================== +*/ +static void *g_mdltexdata; +void Image_SetMDLPointer(byte *p) +{ + g_mdltexdata = p; +} + /* ============ Image_LoadMDL @@ -147,7 +160,9 @@ qboolean Image_LoadMDL( const char *name, const byte *buffer, size_t filesize ) image.width = pin->width; image.height = pin->height; pixels = image.width * image.height; - fin = (byte *)pin->index; // setup buffer + fin = (byte *)g_mdltexdata; + ASSERT(fin); + g_mdltexdata = NULL; if( !Image_ValidSize( name )) return false; @@ -496,4 +511,4 @@ qboolean Image_LoadMIP( const char *name, const byte *buffer, size_t filesize ) image.depth = 1; return Image_AddIndexedImageToPack( fin, image.width, image.height ); -} \ No newline at end of file +} diff --git a/engine/common/mathlib.h b/engine/common/mathlib.h index 2b898780..f939dc10 100644 --- a/engine/common/mathlib.h +++ b/engine/common/mathlib.h @@ -67,8 +67,8 @@ GNU General Public License for more details. #define Q_min( a, b ) (((a) < (b)) ? (a) : (b)) #define Q_max( a, b ) (((a) > (b)) ? (a) : (b)) #define Q_recip( a ) ((float)(1.0f / (float)(a))) -#define Q_floor( a ) ((float)(long)(a)) -#define Q_ceil( a ) ((float)(long)((a) + 1)) +#define Q_floor( a ) ((float)(int)(a)) +#define Q_ceil( a ) ((float)(int)((a) + 1)) #define Q_round( x, y ) (floor( x / y + 0.5 ) * y ) #define Q_rint(x) ((x) < 0 ? ((int)((x)-0.5f)) : ((int)((x)+0.5f))) #define IS_NAN(x) (((*(int *)&x) & (255<<23)) == (255<<23)) @@ -199,4 +199,4 @@ extern const matrix3x4 matrix3x4_identity; extern const matrix4x4 matrix4x4_identity; extern const float m_bytenormals[NUMVERTEXNORMALS][3]; -#endif//MATHLIB_H \ No newline at end of file +#endif//MATHLIB_H diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index 6548ab5f..0a4a219c 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -1528,7 +1528,7 @@ static void Mod_LoadEntities( dbspmodel_t *bmod ) if( bmod->isworld ) { char entfilename[MAX_QPATH]; - long entpatchsize; + int entpatchsize; size_t ft1, ft2; // world is check for entfile too diff --git a/engine/common/mod_studio.c b/engine/common/mod_studio.c index d209a443..fc6d1da9 100644 --- a/engine/common/mod_studio.c +++ b/engine/common/mod_studio.c @@ -602,7 +602,7 @@ void *R_StudioGetAnim( studiohdr_t *m_pStudioHeader, model_t *m_pSubModel, mstud pseqgroup = (mstudioseqgroup_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqgroupindex) + pseqdesc->seqgroup; if( pseqdesc->seqgroup == 0 ) - return ((byte *)m_pStudioHeader + pseqgroup->data + pseqdesc->animindex); + return ((byte *)m_pStudioHeader + pseqdesc->animindex); paSequences = (cache_user_t *)m_pSubModel->submodels; @@ -914,7 +914,7 @@ void Mod_StudioComputeBounds( void *buffer, vec3_t mins, vec3_t maxs, qboolean i pseqgroup = (mstudioseqgroup_t *)((byte *)pstudiohdr + pstudiohdr->seqgroupindex) + pseqdesc->seqgroup; if( pseqdesc->seqgroup == 0 ) - panim = (mstudioanim_t *)((byte *)pstudiohdr + pseqgroup->data + pseqdesc->animindex); + panim = (mstudioanim_t *)((byte *)pstudiohdr + pseqdesc->animindex); else continue; for( j = 0; j < pstudiohdr->numbones; j++ ) diff --git a/engine/common/net_buffer.c b/engine/common/net_buffer.c index 9488a2c3..b6355403 100644 --- a/engine/common/net_buffer.c +++ b/engine/common/net_buffer.c @@ -165,7 +165,7 @@ void MSG_WriteUBitLong( sizebuf_t *sb, uint curData, int numbits ) dword iCurBitMasked; int nBitsWritten; - Assert(( iDWord * 4 + sizeof( long )) <= (uint)MSG_GetMaxBytes( sb )); + Assert(( iDWord * 4 + sizeof( int )) <= (uint)MSG_GetMaxBytes( sb )); iCurBitMasked = iCurBit & 31; ((dword *)sb->pData)[iDWord] &= BitWriteMasks[iCurBitMasked][nBitsLeft]; @@ -304,12 +304,12 @@ void MSG_WriteVec3Angles( sizebuf_t *sb, const float *fa ) void MSG_WriteBitFloat( sizebuf_t *sb, float val ) { - long intVal; + int intVal; - Assert( sizeof( long ) == sizeof( float )); + Assert( sizeof( int ) == sizeof( float )); Assert( sizeof( float ) == 4 ); - intVal = *((long *)&val ); + intVal = *((int *)&val ); MSG_WriteUBitLong( sb, intVal, 32 ); } @@ -360,9 +360,9 @@ void MSG_WriteWord( sizebuf_t *sb, int val ) MSG_WriteUBitLong( sb, val, sizeof( word ) << 3 ); } -void MSG_WriteLong( sizebuf_t *sb, long val ) +void MSG_WriteLong( sizebuf_t *sb, int val ) { - MSG_WriteSBitLong( sb, val, sizeof( long ) << 3 ); + MSG_WriteSBitLong( sb, val, sizeof( int ) << 3 ); } void MSG_WriteDword( sizebuf_t *sb, dword val ) @@ -456,10 +456,10 @@ uint MSG_ReadUBitLong( sizebuf_t *sb, int numbits ) float MSG_ReadBitFloat( sizebuf_t *sb ) { - long val; + int val; int bit, byte; - Assert( sizeof( float ) == sizeof( long )); + Assert( sizeof( float ) == sizeof( int )); Assert( sizeof( float ) == 4 ); if( MSG_Overflow( sb, 32 )) @@ -617,9 +617,9 @@ void MSG_ReadVec3Angles( sizebuf_t *sb, vec3_t fa ) } -long MSG_ReadLong( sizebuf_t *sb ) +int MSG_ReadLong( sizebuf_t *sb ) { - return MSG_ReadSBitLong( sb, sizeof( long ) << 3 ); + return MSG_ReadSBitLong( sb, sizeof( int ) << 3 ); } dword MSG_ReadDword( sizebuf_t *sb ) @@ -685,4 +685,4 @@ void MSG_ExciseBits( sizebuf_t *sb, int startbit, int bitstoremove ) MSG_SeekToBit( sb, startbit, SEEK_SET ); sb->nDataBits -= bitstoremove; -} \ No newline at end of file +} diff --git a/engine/common/net_buffer.h b/engine/common/net_buffer.h index 62a5f284..4a631898 100644 --- a/engine/common/net_buffer.h +++ b/engine/common/net_buffer.h @@ -86,7 +86,7 @@ void MSG_WriteChar( sizebuf_t *sb, int val ); void MSG_WriteByte( sizebuf_t *sb, int val ); void MSG_WriteShort( sizebuf_t *sb, int val ); void MSG_WriteWord( sizebuf_t *sb, int val ); -void MSG_WriteLong( sizebuf_t *sb, long val ); +void MSG_WriteLong( sizebuf_t *sb, int val ); void MSG_WriteDword( sizebuf_t *sb, dword val ); void MSG_WriteCoord( sizebuf_t *sb, float val ); void MSG_WriteFloat( sizebuf_t *sb, float val ); @@ -123,7 +123,7 @@ int MSG_ReadChar( sizebuf_t *sb ); int MSG_ReadByte( sizebuf_t *sb ); int MSG_ReadShort( sizebuf_t *sb ); int MSG_ReadWord( sizebuf_t *sb ); -long MSG_ReadLong( sizebuf_t *sb ); +int MSG_ReadLong( sizebuf_t *sb ); dword MSG_ReadDword( sizebuf_t *sb ); float MSG_ReadCoord( sizebuf_t *sb ); float MSG_ReadFloat( sizebuf_t *sb ); @@ -132,4 +132,4 @@ void MSG_ReadVec3Angles( sizebuf_t *sb, vec3_t fa ); qboolean MSG_ReadBytes( sizebuf_t *sb, void *pOut, int nBytes ); char *MSG_ReadStringExt( sizebuf_t *sb, qboolean bLine ); -#endif//NET_BUFFER_H \ No newline at end of file +#endif//NET_BUFFER_H diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c index 6c25019e..beeaa59e 100644 --- a/engine/common/net_ws.c +++ b/engine/common/net_ws.c @@ -258,7 +258,7 @@ typedef struct float fakelag; // cached fakelag value LONGPACKET split; int split_flags[NET_MAX_FRAGMENTS]; - long sequence_number; + int sequence_number; int ip_sockets[NS_COUNT]; qboolean initialized; qboolean threads_initialized; diff --git a/engine/common/protocol.h b/engine/common/protocol.h index 742d065e..1bff7a55 100644 --- a/engine/common/protocol.h +++ b/engine/common/protocol.h @@ -30,7 +30,7 @@ GNU General Public License for more details. #define svc_print 8 // [byte] id [string] null terminated string #define svc_stufftext 9 // [string] stuffed into client's console buffer #define svc_setangle 10 // [angle angle angle] set the view angle to this absolute value -#define svc_serverdata 11 // [long] protocol ... +#define svc_serverdata 11 // [int] protocol ... #define svc_lightstyle 12 // [index][pattern][float] #define svc_updateuserinfo 13 // [byte] playernum, [string] userinfo #define svc_deltatable 14 // [table header][...] @@ -77,7 +77,7 @@ GNU General Public License for more details. // reserved #define svc_resourcelocation 56 // [string] #define svc_querycvarvalue 57 // [string] -#define svc_querycvarvalue2 58 // [string][long] (context) +#define svc_querycvarvalue2 58 // [string][int] (context) #define svc_lastmsg 58 // start user messages at this point // client to server @@ -183,8 +183,8 @@ GNU General Public License for more details. #define PROTOCOL_VERSION_QUAKE 15 // listed only unmatched ops -#define svc_updatestat 3 // [byte] [long] (svc_event) -#define svc_version 4 // [long] server version (svc_changing) +#define svc_updatestat 3 // [byte] [int] (svc_event) +#define svc_version 4 // [int] server version (svc_changing) #define svc_updatename 13 // [byte] [string] (svc_updateuserinfo) #define svc_updatefrags 14 // [byte] [short] (svc_deltatable) #define svc_stopsound 16 // (svc_resource) @@ -243,4 +243,4 @@ GNU General Public License for more details. extern const char *svc_strings[svc_lastmsg+1]; extern const char *clc_strings[clc_lastmsg+1]; -#endif//NET_PROTOCOL_H \ No newline at end of file +#endif//NET_PROTOCOL_H diff --git a/engine/common/soundlib/snd_main.c b/engine/common/soundlib/snd_main.c index ca3bac13..66ba9568 100644 --- a/engine/common/soundlib/snd_main.c +++ b/engine/common/soundlib/snd_main.c @@ -59,7 +59,7 @@ wavdata_t *FS_LoadSound( const char *filename, const byte *buffer, size_t size ) const char *ext = COM_FileExtension( filename ); string path, loadname; qboolean anyformat = true; - int filesize = 0; + size_t filesize = 0; const loadwavfmt_t *format; byte *f; @@ -223,7 +223,7 @@ FS_ReadStream extract stream as wav-data and put into buffer, move file pointer ================ */ -long FS_ReadStream( stream_t *stream, int bytes, void *buffer ) +int FS_ReadStream( stream_t *stream, int bytes, void *buffer ) { if( !stream || !stream->format || !stream->format->readfunc ) return 0; @@ -241,7 +241,7 @@ FS_GetStreamPos get stream position (in bytes) ================ */ -long FS_GetStreamPos( stream_t *stream ) +int FS_GetStreamPos( stream_t *stream ) { if( !stream || !stream->format || !stream->format->getposfunc ) return -1; @@ -256,7 +256,7 @@ FS_SetStreamPos set stream position (in bytes) ================ */ -long FS_SetStreamPos( stream_t *stream, long newpos ) +int FS_SetStreamPos( stream_t *stream, int newpos ) { if( !stream || !stream->format || !stream->format->setposfunc ) return -1; @@ -277,4 +277,4 @@ void FS_FreeStream( stream_t *stream ) return; stream->format->freefunc( stream ); -} \ No newline at end of file +} diff --git a/engine/common/soundlib/snd_mp3.c b/engine/common/soundlib/snd_mp3.c index b98454df..d04819db 100644 --- a/engine/common/soundlib/snd_mp3.c +++ b/engine/common/soundlib/snd_mp3.c @@ -32,12 +32,12 @@ typedef struct } wavinfo_t; // custom stdio -typedef long (*pfread)( void *handle, void *buf, size_t count ); -typedef long (*pfseek)( void *handle, long offset, int whence ); +typedef int (*pfread)( void *handle, void *buf, size_t count ); +typedef int (*pfseek)( void *handle, int offset, int whence ); extern void *create_decoder( int *error ); -extern int feed_mpeg_header( void *mpg, const char *data, long bufsize, long streamsize, wavinfo_t *sc ); -extern int feed_mpeg_stream( void *mpg, const char *data, long bufsize, char *outbuf, size_t *outsize ); +extern int feed_mpeg_header( void *mpg, const char *data, int bufsize, int streamsize, wavinfo_t *sc ); +extern int feed_mpeg_stream( void *mpg, const char *data, int bufsize, char *outbuf, size_t *outsize ); extern int open_mpeg_stream( void *mpg, void *file, pfread f_read, pfseek f_seek, wavinfo_t *sc ); extern int read_mpeg_stream( void *mpg, char *outbuf, size_t *outsize ); extern int get_stream_pos( void *mpg ); @@ -205,7 +205,7 @@ Stream_ReadMPG assume stream is valid ================= */ -long Stream_ReadMPG( stream_t *stream, long needBytes, void *buffer ) +int Stream_ReadMPG( stream_t *stream, int needBytes, void *buffer ) { // buffer handling int bytesWritten = 0; @@ -216,7 +216,7 @@ long Stream_ReadMPG( stream_t *stream, long needBytes, void *buffer ) while( 1 ) { byte *data; - long outsize; + int outsize; if( !stream->buffsize ) { @@ -253,7 +253,7 @@ Stream_SetPosMPG assume stream is valid ================= */ -long Stream_SetPosMPG( stream_t *stream, long newpos ) +int Stream_SetPosMPG( stream_t *stream, int newpos ) { if( set_stream_pos( stream->ptr, newpos ) != -1 ) { @@ -273,7 +273,7 @@ Stream_GetPosMPG assume stream is valid ================= */ -long Stream_GetPosMPG( stream_t *stream ) +int Stream_GetPosMPG( stream_t *stream ) { return get_stream_pos( stream->ptr ); } @@ -300,4 +300,4 @@ void Stream_FreeMPG( stream_t *stream ) } Mem_Free( stream ); -} \ No newline at end of file +} diff --git a/engine/common/soundlib/snd_wav.c b/engine/common/soundlib/snd_wav.c index 80ca54b1..68484393 100644 --- a/engine/common/soundlib/snd_wav.c +++ b/engine/common/soundlib/snd_wav.c @@ -403,7 +403,7 @@ Stream_ReadWAV assume stream is valid ================= */ -long Stream_ReadWAV( stream_t *stream, long bytes, void *buffer ) +int Stream_ReadWAV( stream_t *stream, int bytes, void *buffer ) { int remaining; @@ -426,7 +426,7 @@ Stream_SetPosWAV assume stream is valid ================= */ -long Stream_SetPosWAV( stream_t *stream, long newpos ) +int Stream_SetPosWAV( stream_t *stream, int newpos ) { // NOTE: stream->pos it's real file position without header size if( FS_Seek( stream->file, stream->buffsize + newpos, SEEK_SET ) != -1 ) @@ -445,7 +445,7 @@ Stream_GetPosWAV assume stream is valid ================= */ -long Stream_GetPosWAV( stream_t *stream ) +int Stream_GetPosWAV( stream_t *stream ) { return stream->pos; } @@ -462,4 +462,4 @@ void Stream_FreeWAV( stream_t *stream ) if( stream->file ) FS_Close( stream->file ); Mem_Free( stream ); -} \ No newline at end of file +} diff --git a/engine/common/soundlib/soundlib.h b/engine/common/soundlib/soundlib.h index df384d22..f9577b66 100644 --- a/engine/common/soundlib/soundlib.h +++ b/engine/common/soundlib/soundlib.h @@ -34,9 +34,9 @@ typedef struct streamfmt_s const char *ext; stream_t *(*openfunc)( const char *filename ); - long (*readfunc)( stream_t *stream, long bytes, void *buffer ); - long (*setposfunc)( stream_t *stream, long newpos ); - long (*getposfunc)( stream_t *stream ); + int (*readfunc)( stream_t *stream, int bytes, void *buffer ); + int (*setposfunc)( stream_t *stream, int newpos ); + int (*getposfunc)( stream_t *stream ); void (*freefunc)( stream_t *stream ); } streamfmt_t; @@ -95,14 +95,14 @@ typedef struct stream_s typedef struct { int riff_id; // 'RIFF' - long rLen; + int rLen; int wave_id; // 'WAVE' int fmt_id; // 'fmt ' - long pcm_header_len; // varies... + int pcm_header_len; // varies... short wFormatTag; short nChannels; // 1,2 for stereo data is (l,r) pairs - long nSamplesPerSec; - long nAvgBytesPerSec; + int nSamplesPerSec; + int nAvgBytesPerSec; short nBlockAlign; short nBitsPerSample; } wavehdr_t; @@ -110,7 +110,7 @@ typedef struct typedef struct { int data_id; // 'data' or 'fact' - long dLen; + int dLen; } chunkhdr_t; extern sndlib_t sound; @@ -124,14 +124,14 @@ qboolean Sound_LoadMPG( const char *name, const byte *buffer, size_t filesize ); // stream operate // stream_t *Stream_OpenWAV( const char *filename ); -long Stream_ReadWAV( stream_t *stream, long bytes, void *buffer ); -long Stream_SetPosWAV( stream_t *stream, long newpos ); -long Stream_GetPosWAV( stream_t *stream ); +int Stream_ReadWAV( stream_t *stream, int bytes, void *buffer ); +int Stream_SetPosWAV( stream_t *stream, int newpos ); +int Stream_GetPosWAV( stream_t *stream ); void Stream_FreeWAV( stream_t *stream ); stream_t *Stream_OpenMPG( const char *filename ); -long Stream_ReadMPG( stream_t *stream, long bytes, void *buffer ); -long Stream_SetPosMPG( stream_t *stream, long newpos ); -long Stream_GetPosMPG( stream_t *stream ); +int Stream_ReadMPG( stream_t *stream, int bytes, void *buffer ); +int Stream_SetPosMPG( stream_t *stream, int newpos ); +int Stream_GetPosMPG( stream_t *stream ); void Stream_FreeMPG( stream_t *stream ); #endif//SOUNDLIB_H diff --git a/engine/eiface.h b/engine/eiface.h index c25093b6..39d9e946 100644 --- a/engine/eiface.h +++ b/engine/eiface.h @@ -287,7 +287,7 @@ typedef struct KeyValueData_s char *szClassName; // in: entity classname char *szKeyName; // in: name of key char *szValue; // in: value of key - long fHandled; // out: DLL sets to true if key-value pair was understood + int fHandled; // out: DLL sets to true if key-value pair was understood } KeyValueData; diff --git a/engine/server/server.h b/engine/server/server.h index b0553602..96d09cf1 100644 --- a/engine/server/server.h +++ b/engine/server/server.h @@ -592,6 +592,11 @@ edict_t* SV_CreateNamedEntity( edict_t *ent, string_t className ); string_t SV_AllocString( const char *szValue ); string_t SV_MakeString( const char *szValue ); const char *SV_GetString( string_t iString ); +void SV_SetStringArrayMode( qboolean dynamic ); +void SV_EmptyStringPool( void ); +#ifdef XASH_64BIT +void SV_PrintStr64Stats_f( void ); +#endif sv_client_t *SV_ClientFromEdict( const edict_t *pEdict, qboolean spawned_only ); int SV_MapIsValid( const char *filename, const char *spawn_entity, const char *landmark_name ); void SV_StartSound( edict_t *ent, int chan, const char *sample, float vol, float attn, int flags, int pitch ); @@ -613,7 +618,6 @@ void SV_RestartStaticEnts( void ); int pfnGetCurrentPlayer( void ); edict_t *SV_EdictNum( int n ); char *SV_Localinfo( void ); - // // sv_log.c // diff --git a/engine/server/sv_client.c b/engine/server/sv_client.c index 83cf1fd9..5b4f4cd8 100644 --- a/engine/server/sv_client.c +++ b/engine/server/sv_client.c @@ -2049,7 +2049,7 @@ void SV_TSourceEngineQuery( netadr_t from ) MSG_WriteString( &buf, GI->game_url ); MSG_WriteString( &buf, GI->update_url ); MSG_WriteByte( &buf, 0 ); - MSG_WriteLong( &buf, (long)GI->version ); + MSG_WriteLong( &buf, (int)GI->version ); MSG_WriteLong( &buf, GI->size ); if( GI->gamemode == 2 ) diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index 6d71bc7b..179cb121 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -571,7 +571,7 @@ void SV_RestartAmbientSounds( void ) soundlist_t soundInfo[256]; string curtrack, looptrack; int i, nSounds; - long position; + int position; if( !SV_Active( )) return; @@ -2152,7 +2152,7 @@ SV_StartMusic ================= */ -void SV_StartMusic( const char *curtrack, const char *looptrack, long position ) +void SV_StartMusic( const char *curtrack, const char *looptrack, int position ) { MSG_BeginServerCmd( &sv.multicast, svc_stufftext ); MSG_WriteString( &sv.multicast, va( "music \"%s\" \"%s\" %li\n", curtrack, looptrack, position )); @@ -2964,41 +2964,248 @@ void *pfnPvEntPrivateData( edict_t *pEdict ) return NULL; } + +#ifdef XASH_64BIT +static struct str64_s +{ + size_t maxstringarray; + qboolean allowdup; + char *staticstringarray; + char *pstringarray; + char *pstringarraystatic; + char *pstringbase; + char *poldstringbase; + char *plast; + qboolean dynamic; + size_t maxalloc; + size_t numdups; + size_t numoverflows; + size_t totalalloc; +} str64; +#endif + +/* +================== +SV_EmptyStringPool + +Free strings on server stop. Reset string pointer on 64 bits +================== +*/ +void SV_EmptyStringPool( void ) +{ +#ifdef XASH_64BIT + if( str64.dynamic ) // switch only after array fill (more space for multiplayer games) + str64.pstringbase = str64.pstringarray; + else + { + str64.pstringbase = str64.poldstringbase = str64.pstringarraystatic; + str64.plast = str64.pstringbase + 1; + } +#else + Mem_EmptyPool( svgame.stringspool ); +#endif +} + +/* +=============== +SV_SetStringArrayMode + +use different arrays on 64 bit platforms +set dynamic after complete server spawn +this helps not to lose strings that belongs to static game part +=============== +*/ +void SV_SetStringArrayMode( qboolean dynamic ) +{ +#ifdef XASH_64BIT + Con_Reportf( "SV_SetStringArrayMode(%d) %d\n", dynamic, str64.dynamic ); + + if( dynamic == str64.dynamic ) + return; + + str64.dynamic = dynamic; + + SV_EmptyStringPool(); +#endif +} + +#ifdef XASH_64BIT +#ifndef _WIN32 +#define USE_MMAP +#include +#endif +#endif + +/* +================== +SV_AllocStringPool + +alloc string pool on 32bit platforms +alloc string array near the server library on 64bit platforms if possible +alloc string array somewhere if not (MAKE_STRING will not work. Always call ALLOC_STRING instead, or crash) +this case need patched game dll with MAKE_STRING checking ptrdiff size +================== +*/ +void SV_AllocStringPool( void ) +{ +#ifdef XASH_64BIT + void *ptr = NULL; + string lenstr; + + Con_Reportf( "SV_AllocStringPool()\n" ); + if( Sys_GetParmFromCmdLine( "-str64alloc", lenstr ) ) + { + str64.maxstringarray = Q_atoi( lenstr ); + if( str64.maxstringarray < 1024 || str64.maxstringarray >= INT_MAX ) + str64.maxstringarray = 65536; + } + else str64.maxstringarray = 65536; + if( Sys_CheckParm( "-str64dup" ) ) + str64.allowdup = true; + +#ifdef USE_MMAP + { + size_t pagesize = sysconf( _SC_PAGESIZE ); + int arrlen = (str64.maxstringarray * 2) & ~(pagesize - 1); + void *base = svgame.dllFuncs.pfnGameInit; + void *start = svgame.hInstance - arrlen; + + while( start - base > INT_MIN ) + { + void *mapptr = mmap((void*)((unsigned long)start & ~(pagesize - 1)), arrlen, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0 ); + if( mapptr && mapptr != (void*)-1 && mapptr - base > INT_MIN && mapptr - base < INT_MAX ) + { + ptr = mapptr; + break; + } + if( mapptr ) munmap( mapptr, arrlen ); + start -= arrlen; + } + + if( !ptr ) + { + start = base; + while( start - base < INT_MAX ) + { + void *mapptr = mmap((void*)((unsigned long)start & ~(pagesize - 1)), arrlen, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0 ); + if( mapptr && mapptr != (void*)-1 && mapptr - base > INT_MIN && mapptr - base < INT_MAX ) + { + ptr = mapptr; + break; + } + if( mapptr ) munmap( mapptr, arrlen ); + start += arrlen; + } + } + + + if( ptr ) + { + Con_Reportf( "SV_AllocStringPool: Allocated string array near the server library: %p %p\n", base, ptr ); + + } + else + { + Con_Reportf( "SV_AllocStringPool: Failed to allocate string array near the server library!\n" ); + ptr = str64.staticstringarray = Mem_Calloc(host.mempool, str64.maxstringarray * 2); + } + } +#else + ptr = str64.staticstringarray = Mem_Calloc(host.mempool, str64.maxstringarray * 2); +#endif + + str64.pstringarray = ptr; + str64.pstringarraystatic = ptr + str64.maxstringarray; + str64.pstringbase = str64.poldstringbase = ptr; + str64.plast = ptr + 1; + svgame.globals->pStringBase = ptr; +#else + svgame.stringspool = Mem_AllocPool( "Server Strings" ); + svgame.globals->pStringBase = ""; +#endif +} + +void SV_FreeStringPool( void ) +{ +#ifdef XASH_64BIT + Con_Reportf( "SV_FreeStringPool()\n" ); + + if( str64.pstringarray != str64.staticstringarray ) + munmap( str64.pstringarray, (str64.maxstringarray * 2) & ~(sysconf( _SC_PAGESIZE ) - 1) ); + else + Mem_Free( str64.staticstringarray ); +#else + Mem_FreePool( &svgame.stringspool ); +#endif +} + /* ============= SV_AllocString allocate new engine string +on 64bit platforms find in array string if deduplication enabled (default) +if not found, add to array +use -str64dup to disable deduplication, -str64alloc to set array size ============= */ -string_t SV_AllocString( const char *szString ) +string_t GAME_EXPORT SV_AllocString( const char *szValue ) { - char *out, *out_p; - int i, l; + const char *newString = NULL; if( svgame.physFuncs.pfnAllocString != NULL ) - return svgame.physFuncs.pfnAllocString( szString ); - - if( !COM_CheckString( szString )) - return 0; + return svgame.physFuncs.pfnAllocString( szValue ); +#ifdef XASH_64BIT + int cmp = 1; - l = Q_strlen( szString ) + 1; + if( !str64.allowdup ) + for( newString = str64.poldstringbase + 1; newString < str64.plast && ( cmp = Q_strcmp( newString, szValue ) ); newString += Q_strlen( newString ) + 1 ); - out = out_p = Mem_Calloc( svgame.stringspool, l ); - for( i = 0; i < l; i++ ) + if( cmp ) { - if( szString[i] == '\\' && i < l - 1 ) + uint len = Q_strlen( szValue ); + + if( str64.plast - str64.poldstringbase + len + 2 > str64.maxstringarray ) { - i++; - if( szString[i] == 'n') - *out_p++ = '\n'; - else *out_p++ = '\\'; + str64.plast = str64.pstringbase + 1; + str64.poldstringbase = str64.pstringbase; + str64.numoverflows++; } - else *out_p++ = szString[i]; + + //MsgDev( D_NOTE, "SV_AllocString: %ld %s\n", str64.plast - svgame.globals->pStringBase, szValue ); + memcpy( str64.plast, szValue, len + 1 ); + str64.totalalloc += len + 1; + + newString = str64.plast; + str64.plast += len + 1; } + else + str64.numdups++; + //MsgDev( D_NOTE, "SV_AllocString: dup %ld %s\n", newString - svgame.globals->pStringBase, szValue ); + + if( newString - str64.pstringarray > str64.maxalloc ) + str64.maxalloc = newString - str64.pstringarray; + + return newString - svgame.globals->pStringBase; +#else + newString = _copystring( svgame.stringspool, szValue, __FILE__, __LINE__ ); + return newString - svgame.globals->pStringBase; +#endif +} - return out - svgame.globals->pStringBase; -} +#ifdef XASH_64BIT +void SV_PrintStr64Stats_f( void ) +{ + Msg( "====================\n" ); + Msg( "64 bit string pool statistics\n" ); + Msg( "====================\n" ); + Msg( "string array size: %lu\n", str64.maxstringarray ); + Msg( "total alloc %lu\n", str64.totalalloc ); + Msg( "maximum array usage: %lu\n", str64.maxalloc ); + Msg( "overflow counter: %lu\n", str64.numoverflows ); + Msg( "dup string counter: %lu\n", str64.numdups ); +} +#endif /* ============= @@ -3011,9 +3218,18 @@ string_t SV_MakeString( const char *szValue ) { if( svgame.physFuncs.pfnMakeString != NULL ) return svgame.physFuncs.pfnMakeString( szValue ); +#ifdef XASH_64BIT + { + long long ptrdiff = szValue - svgame.globals->pStringBase; + if( ptrdiff > INT_MAX || ptrdiff < INT_MIN ) + return SV_AllocString(szValue); + else + return (int)ptrdiff; + } +#else return szValue - svgame.globals->pStringBase; -} - +#endif +} /* ============= @@ -4745,7 +4961,7 @@ void SV_UnloadProgs( void ) Delta_Shutdown (); Mod_ClearUserData (); - Mem_FreePool( &svgame.stringspool ); + SV_FreeStringPool(); if( svgame.dllFuncs2.pfnGameShutdown != NULL ) svgame.dllFuncs2.pfnGameShutdown (); @@ -4892,7 +5108,7 @@ qboolean SV_LoadProgs( const char *name ) e->free = true; // mark all edicts as freed Cvar_FullSet( "host_gameloaded", "1", FCVAR_READ_ONLY ); - svgame.stringspool = Mem_AllocPool( "Server Strings" ); + SV_AllocStringPool(); // fire once Con_Printf( "Dll loaded for game ^2\"%s\"\n", svgame.dllFuncs.pfnGetGameDescription( )); diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index a294e8ce..affe4bff 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -514,6 +514,8 @@ void SV_ActivateServer( int runPhysics ) svgame.globals->time = sv.time; svgame.dllFuncs.pfnServerActivate( svgame.edicts, svgame.numEntities, svs.maxclients ); + SV_SetStringArrayMode( true ); + // parse user-specified resources SV_CreateGenericResources(); @@ -616,7 +618,7 @@ void SV_DeactivateServer( void ) SV_ClearPhysEnts (); - Mem_EmptyPool( svgame.stringspool ); + SV_EmptyStringPool(); for( i = 0; i < svs.maxclients; i++ ) { @@ -914,6 +916,7 @@ State machine exec new map */ void SV_ExecLoadLevel( void ) { + SV_SetStringArrayMode( false ); if( SV_SpawnServer( GameState->levelName, NULL, GameState->backgroundMap )) { SV_SpawnEntities( GameState->levelName ); diff --git a/engine/server/sv_save.c b/engine/server/sv_save.c index 86a7528d..5fb9e478 100644 --- a/engine/server/sv_save.c +++ b/engine/server/sv_save.c @@ -2133,7 +2133,7 @@ used for reload game after player death const char *SV_GetLatestSave( void ) { static char savename[MAX_QPATH]; - long newest = 0, ft; + int newest = 0, ft; int i, found = 0; search_t *t;