From c4ea522c5e84753721362dd2c811d234d0caff53 Mon Sep 17 00:00:00 2001 From: Krispy Date: Thu, 5 Sep 2024 21:11:44 -0500 Subject: [PATCH] Merged idtech5 idlib sys/ --- neo/CMakeLists.txt | 1 + neo/MayaImport/maya_main.cpp | 3 +- neo/cm/CollisionModel_load.cpp | 4 +- neo/d3xp/script/Script_Compiler.cpp | 4 +- neo/d3xp/script/Script_Program.cpp | 6 +- neo/framework/Console.cpp | 2 - neo/framework/File.cpp | 2 - neo/game/script/Script_Compiler.cpp | 4 +- neo/game/script/Script_Program.cpp | 6 +- neo/idlib/Lib.cpp | 65 +-- neo/idlib/Lib.h | 124 ++++- neo/idlib/containers/List.h | 33 +- neo/idlib/containers/StaticList.h | 31 ++ neo/idlib/math/Math.cpp | 2 +- neo/idlib/precompiled.h | 38 +- neo/idlib/sys/sys_assert.cpp | 105 +++++ neo/idlib/sys/sys_assert.h | 146 ++++++ neo/idlib/sys/sys_builddefines.h | 35 ++ neo/idlib/sys/sys_defines.h | 426 ++++++++++++++++++ neo/idlib/sys/sys_includes.h | 102 +++++ neo/idlib/sys/sys_types.h | 289 ++++++++++++ neo/renderer/DeviceContext.cpp | 2 +- neo/renderer/GuiModel.cpp | 10 +- neo/renderer/GuiModel.h | 6 +- neo/renderer/Model.h | 25 +- neo/renderer/ModelDecal.h | 2 +- neo/renderer/ModelOverlay.cpp | 8 +- neo/renderer/ModelOverlay.h | 2 +- neo/renderer/Model_ma.cpp | 2 +- neo/renderer/Model_prt.cpp | 2 +- neo/renderer/RenderSystem.cpp | 4 +- neo/renderer/RenderSystem.h | 4 +- neo/renderer/tr_deform.cpp | 24 +- neo/renderer/tr_local.h | 18 +- neo/renderer/tr_orderIndexes.cpp | 10 +- neo/renderer/tr_stencilshadow.cpp | 2 +- neo/renderer/tr_trisurf.cpp | 10 +- neo/renderer/tr_turboshadow.cpp | 20 +- neo/sys/platform.h | 302 ------------- neo/tools/compilers/dmap/shadowopt3.cpp | 12 +- neo/tools/compilers/renderbump/renderbump.cpp | 2 +- neo/tools/guied/GEItemScriptsDlg.cpp | 2 +- neo/tools/guied/GEWorkspaceFile.cpp | 2 +- neo/tools/radiant/CamWnd.cpp | 2 +- neo/tools/radiant/RadiantEditor.cpp | 2 +- 45 files changed, 1397 insertions(+), 506 deletions(-) create mode 100644 neo/idlib/sys/sys_assert.cpp create mode 100644 neo/idlib/sys/sys_assert.h create mode 100644 neo/idlib/sys/sys_builddefines.h create mode 100644 neo/idlib/sys/sys_defines.h create mode 100644 neo/idlib/sys/sys_includes.h create mode 100644 neo/idlib/sys/sys_types.h diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index c7f237b6b..e0f5f7fe6 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -726,6 +726,7 @@ set(src_idlib idlib/math/Simd_SSE2.cpp idlib/math/Simd_SSE3.cpp idlib/math/Vector.cpp + idlib/sys/sys_assert.cpp idlib/BitMsg.cpp idlib/LangDict.cpp idlib/Lexer.cpp diff --git a/neo/MayaImport/maya_main.cpp b/neo/MayaImport/maya_main.cpp index 2dad4c9f0..fce5cf02a 100644 --- a/neo/MayaImport/maya_main.cpp +++ b/neo/MayaImport/maya_main.cpp @@ -110,7 +110,6 @@ void MayaError( const char *fmt, ... ) { FS_WriteFloatString ================= */ -#define MAX_PRINT_MSG 4096 static int WriteFloatString( FILE *file, const char *fmt, ... ) { long i; unsigned long u; @@ -3133,7 +3132,7 @@ ID_MAYA_IMPORT_API const char *Maya_ConvertModel( const char *ospath, const char } catch( idException &exception ) { - errorMessage = exception.error; + errorMessage = exception.GetError(); } return errorMessage; diff --git a/neo/cm/CollisionModel_load.cpp b/neo/cm/CollisionModel_load.cpp index 2720f5dbb..71ed518f9 100644 --- a/neo/cm/CollisionModel_load.cpp +++ b/neo/cm/CollisionModel_load.cpp @@ -105,7 +105,7 @@ void idCollisionModelManagerLocal::ParseProcNodes( idLexer *src ) { struct basicSurf_t { idDrawVert *verts; int numVerts; - glIndex_t *indices; + triIndex_t *indices; int numIndices; const idMaterial *mat; }; @@ -182,7 +182,7 @@ void idCollisionModelManagerLocal::CheckProcModelSurfClip( idLexer *src ) { model->maxEdges += numIndices; idDrawVert *verts = (idDrawVert *)Mem_Alloc(numVerts * sizeof(idDrawVert)); - glIndex_t *indices = (glIndex_t *)Mem_Alloc(numIndices * sizeof(glIndex_t)); + triIndex_t *indices = (triIndex_t *)Mem_Alloc(numIndices * sizeof(triIndex_t)); //parse the actual verts and tris for ( j = 0; j < numVerts; j++ ) { diff --git a/neo/d3xp/script/Script_Compiler.cpp b/neo/d3xp/script/Script_Compiler.cpp index 7b3b0f4c6..65fd641b7 100644 --- a/neo/d3xp/script/Script_Compiler.cpp +++ b/neo/d3xp/script/Script_Compiler.cpp @@ -2672,9 +2672,9 @@ void idCompiler::CompileFile( const char *text, const char *filename, bool toCon if ( console ) { // don't print line number of an error if were calling script from the console using the "script" command - sprintf( error, "Error: %s\n", err.error ); + sprintf( error, "Error: %s\n", err.GetError() ); } else { - sprintf( error, "Error: file %s, line %d: %s\n", gameLocal.program.GetFilename( currentFileNumber ), currentLineNumber, err.error ); + sprintf( error, "Error: file %s, line %d: %s\n", gameLocal.program.GetFilename( currentFileNumber ), currentLineNumber, err.GetError() ); } parser.FreeSource(); diff --git a/neo/d3xp/script/Script_Program.cpp b/neo/d3xp/script/Script_Program.cpp index ef9bacf10..dd232aa26 100644 --- a/neo/d3xp/script/Script_Program.cpp +++ b/neo/d3xp/script/Script_Program.cpp @@ -1667,7 +1667,7 @@ void idProgram::BeginCompilation( void ) { } catch( idCompileError &err ) { - gameLocal.Error( "%s", err.error ); + gameLocal.Error( "%s", err.GetError() ); } } @@ -1843,10 +1843,10 @@ bool idProgram::CompileText( const char *source, const char *text, bool console catch( idCompileError &err ) { if ( console ) { - gameLocal.Printf( "%s\n", err.error ); + gameLocal.Printf( "%s\n", err.GetError() ); return false; } else { - gameLocal.Error( "%s\n", err.error ); + gameLocal.Error( "%s\n", err.GetError() ); } }; diff --git a/neo/framework/Console.cpp b/neo/framework/Console.cpp index 9d810a556..2bcd3bc9a 100644 --- a/neo/framework/Console.cpp +++ b/neo/framework/Console.cpp @@ -31,8 +31,6 @@ If you have questions concerning this license or the applicable additional terms #include "ConsoleHistory.h" -#define MAX_PRINT_MSG 4096 - #define CON_TEXTSIZE 0x30000 #define NUM_CON_TIMES 4 #define CONSOLE_FIRSTREPEAT 200 diff --git a/neo/framework/File.cpp b/neo/framework/File.cpp index e67627e1f..4902d8197 100644 --- a/neo/framework/File.cpp +++ b/neo/framework/File.cpp @@ -31,8 +31,6 @@ If you have questions concerning this license or the applicable additional terms #include "Unzip.h" -#define MAX_PRINT_MSG 4096 - /* ================= FS_WriteFloatString diff --git a/neo/game/script/Script_Compiler.cpp b/neo/game/script/Script_Compiler.cpp index 7b3b0f4c6..65fd641b7 100644 --- a/neo/game/script/Script_Compiler.cpp +++ b/neo/game/script/Script_Compiler.cpp @@ -2672,9 +2672,9 @@ void idCompiler::CompileFile( const char *text, const char *filename, bool toCon if ( console ) { // don't print line number of an error if were calling script from the console using the "script" command - sprintf( error, "Error: %s\n", err.error ); + sprintf( error, "Error: %s\n", err.GetError() ); } else { - sprintf( error, "Error: file %s, line %d: %s\n", gameLocal.program.GetFilename( currentFileNumber ), currentLineNumber, err.error ); + sprintf( error, "Error: file %s, line %d: %s\n", gameLocal.program.GetFilename( currentFileNumber ), currentLineNumber, err.GetError() ); } parser.FreeSource(); diff --git a/neo/game/script/Script_Program.cpp b/neo/game/script/Script_Program.cpp index ef9bacf10..dd232aa26 100644 --- a/neo/game/script/Script_Program.cpp +++ b/neo/game/script/Script_Program.cpp @@ -1667,7 +1667,7 @@ void idProgram::BeginCompilation( void ) { } catch( idCompileError &err ) { - gameLocal.Error( "%s", err.error ); + gameLocal.Error( "%s", err.GetError() ); } } @@ -1843,10 +1843,10 @@ bool idProgram::CompileText( const char *source, const char *text, bool console catch( idCompileError &err ) { if ( console ) { - gameLocal.Printf( "%s\n", err.error ); + gameLocal.Printf( "%s\n", err.GetError() ); return false; } else { - gameLocal.Error( "%s\n", err.error ); + gameLocal.Error( "%s\n", err.GetError() ); } }; diff --git a/neo/idlib/Lib.cpp b/neo/idlib/Lib.cpp index a0615b15b..534485faa 100644 --- a/neo/idlib/Lib.cpp +++ b/neo/idlib/Lib.cpp @@ -52,6 +52,8 @@ idCVarSystem * idLib::cvarSystem = NULL; idFileSystem * idLib::fileSystem = NULL; int idLib::frameNumber = 0; +char idException::error[2048]; + /* ================ idLib::Init @@ -81,7 +83,9 @@ void idLib::Init( void ) { //idMatX::Test(); // test idPolynomial +#ifdef _DEBUG idPolynomial::Test(); +#endif // initialize the dictionary string pools idDict::Init(); @@ -135,29 +139,16 @@ idVec4 colorLtGrey = idVec4( 0.75f, 0.75f, 0.75f, 1.00f ); idVec4 colorMdGrey = idVec4( 0.50f, 0.50f, 0.50f, 1.00f ); idVec4 colorDkGrey = idVec4( 0.25f, 0.25f, 0.25f, 1.00f ); -static dword colorMask[2] = { 255, 0 }; - -/* -================ -ColorFloatToByte -================ -*/ -ID_INLINE static byte ColorFloatToByte( float c ) { - return (byte) ( ( (dword) ( c * 255.0f ) ) & colorMask[FLOATSIGNBITSET(c)] ); -} - /* ================ PackColor ================ */ dword PackColor( const idVec4 &color ) { - dword dw, dx, dy, dz; - - dx = ColorFloatToByte( color.x ); - dy = ColorFloatToByte( color.y ); - dz = ColorFloatToByte( color.z ); - dw = ColorFloatToByte( color.w ); + byte dx = idMath::Ftob( color.x * 255.0f ); + byte dy = idMath::Ftob( color.y * 255.0f ); + byte dz = idMath::Ftob( color.z * 255.0f ); + byte dw = idMath::Ftob( color.w * 255.0f ); #if SDL_BYTEORDER == SDL_LIL_ENDIAN return ( dx << 0 ) | ( dy << 8 ) | ( dz << 16 ) | ( dw << 24 ); @@ -191,11 +182,9 @@ PackColor ================ */ dword PackColor( const idVec3 &color ) { - dword dx, dy, dz; - - dx = ColorFloatToByte( color.x ); - dy = ColorFloatToByte( color.y ); - dz = ColorFloatToByte( color.z ); + byte dx = idMath::Ftob( color.x * 255.0f ); + byte dy = idMath::Ftob( color.y * 255.0f ); + byte dz = idMath::Ftob( color.z * 255.0f ); #if SDL_BYTEORDER == SDL_LIL_ENDIAN return ( dx << 0 ) | ( dy << 8 ) | ( dz << 16 ); @@ -416,7 +405,7 @@ ID_INLINE static void RevBitFieldSwap( void *bp, int elsize) { while ( elsize-- ) { v = *p; t = 0; - for (i = 7; i; i--) { + for (i = 7; i>=0; i--) { t <<= 1; v >>= 1; t |= v & 1; @@ -569,25 +558,19 @@ int IntForSixtets( byte *in ) { } /* -=============================================================================== - - Assertion +======================== +BreakOnListGrowth -=============================================================================== +debug tool to find uses of idlist that are dynamically growing +======================== */ +void BreakOnListGrowth() { +} -void AssertFailed( const char *file, int line, const char *expression ) { - idLib::sys->DebugPrintf( "\n\nASSERTION FAILED!\n%s(%d): '%s'\n", file, line, expression ); -#ifdef _MSC_VER - __debugbreak(); - _exit(1); -#elif defined(__unix__) - // __builtin_trap() causes an illegal instruction which is kinda ugly. - // especially if you'd like to be able to continue after the assertion during debugging - raise(SIGTRAP); // this will break into the debugger. -#elif defined( __GNUC__ ) - __builtin_trap(); - _exit(1); -#endif - +/* +======================== +BreakOnListDefault +======================== +*/ +void BreakOnListDefault() { } diff --git a/neo/idlib/Lib.h b/neo/idlib/Lib.h index 08cc8b3e0..ec66e6a48 100644 --- a/neo/idlib/Lib.h +++ b/neo/idlib/Lib.h @@ -75,10 +75,44 @@ class idLib { =============================================================================== */ +typedef int qhandle_t; + class idFile; class idVec3; class idVec4; +#ifndef NULL +#define NULL ((void *)0) +#endif + +#ifndef BIT +#define BIT( num ) ( 1ULL << ( num ) ) +#endif + +#define MAX_STRING_CHARS 1024 // max length of a string +#define MAX_PRINT_MSG 16384 // buffer size for our various printf routines + +// maximum world size +#define MAX_WORLD_COORD ( 128 * 1024 ) +#define MIN_WORLD_COORD ( -128 * 1024 ) +#define MAX_WORLD_SIZE ( MAX_WORLD_COORD - MIN_WORLD_COORD ) + +#define SIZE_KB( x ) ( ( (x) + 1023 ) / 1024 ) +#define SIZE_MB( x ) ( ( ( SIZE_KB( x ) ) + 1023 ) / 1024 ) +#define SIZE_GB( x ) ( ( ( SIZE_MB( x ) ) + 1023 ) / 1024 ) + +#ifndef BIT +#define BIT( num ) BITT< num >::VALUE +#endif + +template< unsigned int B > +class BITT { +public: + typedef enum bitValue_e { + VALUE = 1 << B, + } bitValue_t; +}; + // basic colors extern idVec4 colorBlack; extern idVec4 colorWhite; @@ -120,33 +154,75 @@ bool Swap_IsBigEndian( void ); void SixtetsForInt( byte *out, int src); int IntForSixtets( byte *in ); -#define MAX_TYPE( x ) ( ( ( ( 1 << ( ( sizeof( x ) - 1 ) * 8 - 1 ) ) - 1 ) << 8 ) | 255 ) -#define MIN_TYPE( x ) ( - MAX_TYPE( x ) - 1 ) -#define MAX_UNSIGNED_TYPE( x ) ( ( ( ( 1U << ( ( sizeof( x ) - 1 ) * 8 ) ) - 1 ) << 8 ) | 255U ) -#define MIN_UNSIGNED_TYPE( x ) 0 - -template< typename _type_ > -bool IsSignedType( const _type_ t ) { - return _type_( -1 ) < 0; -} - -#ifdef _DEBUG -void AssertFailed( const char *file, int line, const char *expression ); -#undef assert -// DG: change assert to use ?: so I can use it in _alloca()/_alloca16() (MSVC didn't like if() in there) -#define assert( X ) (X) ? 1 : (AssertFailed( __FILE__, __LINE__, #X ), 0) -#endif - +/* +================================================ +idException +================================================ +*/ class idException { public: - char error[MAX_STRING_CHARS]; + static const int MAX_ERROR_LEN = 2048; + + idException( const char *text = "" ) { + strncpy( error, text, MAX_ERROR_LEN ); + } + + // this really, really should be a const function, but it's referenced too many places to change right now + const char * GetError() { + return error; + } + +protected: + // if GetError() were correctly const this would be named GetError(), too + char * GetErrorBuffer() { + return error; + } + int GetErrorBufferSize() { + return MAX_ERROR_LEN; + } + +private: + friend class idFatalException; + static char error[MAX_ERROR_LEN]; +}; - idException( const char *text = "" ) { strcpy( error, text ); } +/* +================================================ +idFatalException +================================================ +*/ +class idFatalException { +public: + static const int MAX_ERROR_LEN = 2048; + + idFatalException( const char *text = "" ) { + strncpy( idException::error, text, MAX_ERROR_LEN ); + } + + // this really, really should be a const function, but it's referenced too many places to change right now + const char * GetError() { + return idException::error; + } + +protected: + // if GetError() were correctly const this would be named GetError(), too + char * GetErrorBuffer() { + return idException::error; + } + int GetErrorBufferSize() { + return MAX_ERROR_LEN; + } }; -// move from Math.h to keep gcc happy -template ID_INLINE T Max( T x, T y ) { return ( x > y ) ? x : y; } -template ID_INLINE T Min( T x, T y ) { return ( x < y ) ? x : y; } +/* +================================================ +idNetworkLoadException +================================================ +*/ +class idNetworkLoadException : public idException { +public: + idNetworkLoadException( const char * text = "" ) : idException( text ) { } +}; /* =============================================================================== @@ -156,6 +232,10 @@ template ID_INLINE T Min( T x, T y ) { return ( x < y ) ? x : y; } =============================================================================== */ +// System +#include "sys/sys_assert.h" +//#include "sys/sys_threading.h" + // memory management and arrays #include "Heap.h" #include "containers/Sort.h" diff --git a/neo/idlib/containers/List.h b/neo/idlib/containers/List.h index 7c2d16da0..721475ee9 100644 --- a/neo/idlib/containers/List.h +++ b/neo/idlib/containers/List.h @@ -124,7 +124,8 @@ class idList { type * Find( type const & obj ) const; // find pointer to the given element int FindNull( void ) const; // find the index for the first NULL pointer in the list int IndexOf( const type *obj ) const; // returns the index for the pointer to an element in the list - bool RemoveIndex( int index ); // remove the element at the given index + bool RemoveIndex( int index ); // remove the element at the given index + bool RemoveIndexFast( int index ); // removes the element at the given index and places the last element into its spot - DOES NOT PRESERVE LIST ORDER bool Remove( const type & obj ); // remove the element void Sort( cmp_t *compare = ( cmp_t * )&idListSortCompare ); void SortSubSection( int startIndex, int endIndex, cmp_t *compare = ( cmp_t * )&idListSortCompare ); @@ -895,6 +896,36 @@ ID_INLINE bool idList::RemoveIndex( int index ) { return true; } +/* +======================== +idList<_type_,_tag_>::RemoveIndexFast + +Removes the element at the specified index and moves the last element into its spot, rather +than moving the whole array down by one. Of course, this doesn't maintain the order of +elements! The number of elements in the list is reduced by one. + +return: bool - false if the data is not found in the list. + +NOTE: The element is not destroyed, so any memory used by it may not be freed until the + destruction of the list. +======================== +*/ +template< class type > +ID_INLINE bool idList::RemoveIndexFast( int index ) { + if ( ( index < 0 ) || ( index >= num ) ) { + return false; + } + + num--; + + if ( index != num ) { + list[ index ] = list[ num ]; + } + + return true; +} + + /* ================ idList::Remove diff --git a/neo/idlib/containers/StaticList.h b/neo/idlib/containers/StaticList.h index 4ae72f725..4fa2f2cbd 100644 --- a/neo/idlib/containers/StaticList.h +++ b/neo/idlib/containers/StaticList.h @@ -70,6 +70,7 @@ class idStaticList { int FindNull( void ) const; // find the index for the first NULL pointer in the list int IndexOf( const type *obj ) const; // returns the index for the pointer to an element in the list bool RemoveIndex( int index ); // remove the element at the given index + bool RemoveIndexFast( int index ); // remove the element at the given index bool Remove( const type & obj ); // remove the element void Swap( idStaticList &other ); // swap the contents of the lists void DeleteContents( bool clear ); // delete the contents of the list @@ -510,6 +511,36 @@ ID_INLINE bool idStaticList::RemoveIndex( int index ) { return true; } +/* +======================== +idStaticList::RemoveIndexFast + +Removes the element at the specified index and moves the last element into its spot, rather +than moving the whole array down by one. Of course, this doesn't maintain the order of +elements! The number of elements in the list is reduced by one. + +return: bool - false if the data is not found in the list. + +NOTE: The element is not destroyed, so any memory used by it may not be freed until the + destruction of the list. +======================== +*/ +template +ID_INLINE bool idStaticList::RemoveIndexFast( int index ) { + if ( ( index < 0 ) || ( index >= num ) ) { + return false; + } + + num--; + + if ( index != num ) { + list[ index ] = list[ num ]; + } + + return true; +} + + /* ================ idStaticList::Remove diff --git a/neo/idlib/math/Math.cpp b/neo/idlib/math/Math.cpp index e89045638..3d9c389cf 100644 --- a/neo/idlib/math/Math.cpp +++ b/neo/idlib/math/Math.cpp @@ -136,7 +136,7 @@ idMath::Ftob ======================== */ byte idMath::Ftob( float f ) { -#ifdef ID_WIN_X86_SSE_INTRIN +#if 0 // If a converted result is negative the value (0) is returned and if the // converted result is larger than the maximum byte the value (255) is returned. __m128 x = _mm_load_ss( &f ); diff --git a/neo/idlib/precompiled.h b/neo/idlib/precompiled.h index 1195e94ef..9179ae648 100644 --- a/neo/idlib/precompiled.h +++ b/neo/idlib/precompiled.h @@ -29,38 +29,22 @@ If you have questions concerning this license or the applicable additional terms #ifndef __PRECOMPILED_H__ #define __PRECOMPILED_H__ -#ifdef _WIN32 - -#if defined(ID_ALLOW_TOOLS) && !defined(_D3SDK) && !defined(GAME_DLL) -// (hopefully) suppress "warning C4996: 'MBCS_Support_Deprecated_In_MFC': -// MBCS support in MFC is deprecated and may be removed in a future version of MFC." -#define NO_WARN_MBCS_MFC_DEPRECATION - -#include - -#include "tools/comafx/framework.h" -#include "tools/comafx/pch.h" - +#include "sys/sys_includes.h" +#include "sys/sys_defines.h" +#include "sys/sys_builddefines.h" +#include "sys/sys_assert.h" +#include "sys/sys_types.h" +//#include "sys/sys_intrinsics.h" +//#include "sys/sys_threading.h" + +#if defined(_WIN32) && defined(ID_ALLOW_TOOLS) && !defined(_D3SDK) && !defined(GAME_DLL) // scaling factor based on DPI (dpi/96.0f, so 1.0 by default); implemented in win_main.cpp float Win_GetWindowScalingFactor(HWND window); -#endif - -#include -#include -#include - -#include // no malloc.h on mac or unix - -#endif /* _WIN32 */ +#endif /* _WIN32 && !ID_ALLOW_TOOLS && !_D3SDK && !GAME_DLL */ //----------------------------------------------------- -#if !defined( _DEBUG ) && !defined( NDEBUG ) - // don't generate asserts - #define NDEBUG -#endif - -//----------------------------------------------------- +#define ID_TIME_T time_t // Signed because -1 means "File not found" and we don't want that to compare > than any other time // configuration #include "config.h" diff --git a/neo/idlib/sys/sys_assert.cpp b/neo/idlib/sys/sys_assert.cpp new file mode 100644 index 000000000..60a4049ad --- /dev/null +++ b/neo/idlib/sys/sys_assert.cpp @@ -0,0 +1,105 @@ +/* +=========================================================================== + +Doom 3 BFG Edition GPL Source Code +Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. + +This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). + +Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Doom 3 BFG Edition Source Code. If not, see . + +In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +#include "precompiled.h" +#pragma hdrstop + +/* +================================================================================================ +Contains the AssertMacro implementation. +================================================================================================ +*/ + +idCVar com_assertOutOfDebugger( "com_assertOutOfDebugger", "0", CVAR_BOOL, "by default, do not assert while not running under the debugger" ); + +struct skippedAssertion_t { + skippedAssertion_t() : + file( NULL ), + line( -1 ) { + } + const char * file; + int line; +}; +static idStaticList< skippedAssertion_t,20 > skippedAssertions; + +/* +======================== +AssertFailed +======================== +*/ +bool AssertFailed( const char * file, int line, const char * expression ) { + // Set this to true to skip ALL assertions, including ones YOU CAUSE! + static volatile bool skipAllAssertions = false; + if ( skipAllAssertions ) { + return false; + } + + // Set this to true to skip ONLY this assertion + static volatile bool skipThisAssertion = false; + skipThisAssertion = false; + + for ( int i = 0; i < skippedAssertions.Num(); i++ ) { + if ( skippedAssertions[i].file == file && skippedAssertions[i].line == line ) { + skipThisAssertion = true; + // Set breakpoint here to re-enable + if ( !skipThisAssertion ) { + skippedAssertions.RemoveIndexFast( i ); + } + return false; + } + } + + idLib::Warning( "ASSERTION FAILED! %s(%d): '%s'", file, line, expression ); + +#ifdef _WIN32 + if( IsDebuggerPresent() || com_assertOutOfDebugger.GetBool() ) { +#else + if( com_assertOutOfDebugger.GetBool() ) { +#endif +#ifdef _WIN32 +#ifdef _MSC_VER + __debugbreak(); +#else + // DG: mingw support + DebugBreak(); +#endif +#else // not _WIN32 + // DG: POSIX support + raise( SIGTRAP ); +#endif // _WIN32 + } + + if ( skipThisAssertion ) { + skippedAssertion_t * skipped = skippedAssertions.Alloc(); + skipped->file = file; + skipped->line = line; + } + + return true; +} + diff --git a/neo/idlib/sys/sys_assert.h b/neo/idlib/sys/sys_assert.h new file mode 100644 index 000000000..ee7ded61f --- /dev/null +++ b/neo/idlib/sys/sys_assert.h @@ -0,0 +1,146 @@ +/* +=========================================================================== + +Doom 3 BFG Edition GPL Source Code +Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. + +This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). + +Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Doom 3 BFG Edition Source Code. If not, see . + +In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ +#ifndef __SYS_ASSERT_H__ +#define __SYS_ASSERT_H__ + +/* +================================================================================================ + +Getting assert() to work as we want on all platforms and code analysis tools can be tricky. + +================================================================================================ +*/ + +bool AssertFailed( const char *file, int line, const char *expression ); + +// tell PC-Lint that assert failed won't return, which means it can assume the conditions +// are true for subsequent analysis. +//lint -function( exit, AssertFailed ) + +//====================== assert in debug mode ======================= +#if defined( _DEBUG ) || defined( _lint ) + + +#undef assert + +// idassert is useful for cases where some external library (think MFC, etc.) +// decides it's a good idea to redefine assert on us +#define idassert( x ) (void)( ( !!( x ) ) || ( AssertFailed( __FILE__, __LINE__, #x ) ) ) + +// We have the code analysis tools on the 360 compiler, +// so let it know what our asserts are. +// The VS ultimate editions also get it on win32, but not x86 +#define assert( x ) __analysis_assume( x ) ; idassert( x ) + +#define verify( x ) ( ( x ) ? true : ( AssertFailed( __FILE__, __LINE__, #x ), false ) ) + + +#else // _DEBUG + +//====================== assert in release mode ======================= + +#define idassert( x ) { (( void )0); } + +#undef assert + +#define assert( x ) idassert( x ) + +#define verify( x ) ( ( x ) ? true : false ) + +#endif // _DEBUG + +//===================================================================== + +#define idreleaseassert( x ) (void)( ( !!( x ) ) || ( AssertFailed( __FILE__, __LINE__, #x ) ) ); + +#define release_assert( x ) idreleaseassert( x ) + +#define assert_2_byte_aligned( ptr ) assert( ( ((UINT_PTR)(ptr)) & 1 ) == 0 ) +#define assert_4_byte_aligned( ptr ) assert( ( ((UINT_PTR)(ptr)) & 3 ) == 0 ) +#define assert_8_byte_aligned( ptr ) assert( ( ((UINT_PTR)(ptr)) & 7 ) == 0 ) +#define assert_16_byte_aligned( ptr ) assert( ( ((UINT_PTR)(ptr)) & 15 ) == 0 ) +#define assert_32_byte_aligned( ptr ) assert( ( ((UINT_PTR)(ptr)) & 31 ) == 0 ) +#define assert_64_byte_aligned( ptr ) assert( ( ((UINT_PTR)(ptr)) & 63 ) == 0 ) +#define assert_128_byte_aligned( ptr ) assert( ( ((UINT_PTR)(ptr)) & 127 ) == 0 ) +#define assert_aligned_to_type_size( ptr ) assert( ( ((UINT_PTR)(ptr)) & ( sizeof( (ptr)[0] ) - 1 ) ) == 0 ) + +#if !defined( __TYPEINFOGEN__ ) && !defined( _lint ) // pcLint has problems with assert_offsetof() + +#if __cplusplus >= 201703L + +#define compile_time_assert( x ) static_assert( x ); + +#else + +template struct compile_time_assert_failed; +template<> struct compile_time_assert_failed {}; +template struct compile_time_assert_test {}; +#define compile_time_assert_join2( a, b ) a##b +#define compile_time_assert_join( a, b ) compile_time_assert_join2(a,b) +#define compile_time_assert( x ) typedef compile_time_assert_test)> compile_time_assert_join(compile_time_assert_typedef_, __LINE__) + +#endif + +#define assert_sizeof( type, size ) compile_time_assert( sizeof( type ) == size ) +#define assert_sizeof_8_byte_multiple( type ) compile_time_assert( ( sizeof( type ) & 7 ) == 0 ) +#define assert_sizeof_16_byte_multiple( type ) compile_time_assert( ( sizeof( type ) & 15 ) == 0 ) +#define assert_offsetof( type, field, offset ) compile_time_assert( offsetof( type, field ) == offset ) +#define assert_offsetof_8_byte_multiple( type, field ) compile_time_assert( ( offsetof( type, field ) & 7 ) == 0 ) +#define assert_offsetof_16_byte_multiple( type, field ) compile_time_assert( ( offsetof( type, field ) & 15 ) == 0 ) + +#else + +#define compile_time_assert( x ) +#define assert_sizeof( type, size ) +#define assert_sizeof_8_byte_multiple( type ) +#define assert_sizeof_16_byte_multiple( type ) +#define assert_offsetof( type, field, offset ) +#define assert_offsetof_8_byte_multiple( type, field ) +#define assert_offsetof_16_byte_multiple( type, field ) + +#endif + +// useful for verifying that an array of items has the same number of elements in it as an enum type +#define verify_array_size( _array_name_, _max_enum_ ) \ + compile_time_assert( sizeof( _array_name_ ) == ( _max_enum_ ) * sizeof( _array_name_[ 0 ] ) ) + + +// ai debugging macros (designed to limit ai interruptions to non-ai programmers) +#ifdef _DEBUG +//#define DEBUGAI // NOTE: uncomment for full ai debugging +#endif + +#ifdef DEBUGAI +#define ASSERTAI( x ) assert( x ) +#define VERIFYAI( x ) verify( x ) +#else // DEBUGAI +#define ASSERTAI( x ) +#define VERIFYAI( x ) ( ( x ) ? true : false ) +#endif // DEBUGAI + +#endif // !__SYS_ASSERT_H__ diff --git a/neo/idlib/sys/sys_builddefines.h b/neo/idlib/sys/sys_builddefines.h new file mode 100644 index 000000000..02f8d4515 --- /dev/null +++ b/neo/idlib/sys/sys_builddefines.h @@ -0,0 +1,35 @@ +/* +=========================================================================== + +Doom 3 BFG Edition GPL Source Code +Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. + +This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). + +Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Doom 3 BFG Edition Source Code. If not, see . + +In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +/* +=============================================================================== + + Preprocessor settings for compiling different versions. + +=============================================================================== +*/ diff --git a/neo/idlib/sys/sys_defines.h b/neo/idlib/sys/sys_defines.h new file mode 100644 index 000000000..e85a69c2e --- /dev/null +++ b/neo/idlib/sys/sys_defines.h @@ -0,0 +1,426 @@ +/* +=========================================================================== + +Doom 3 BFG Edition GPL Source Code +Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. + +This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). + +Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Doom 3 BFG Edition Source Code. If not, see . + +In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ +#ifndef SYS_DEFINES_H +#define SYS_DEFINES_H + +// NOTE: By default Win32 uses a 1MB stack. Doom3 1.3.1 uses 4MB (probably set after compiling with EDITBIN /STACK +// dhewm3 now uses a 8MB stack, set with a linker flag in CMakeLists.txt (/STACK:8388608 for MSVC, -Wl,--stack,8388608 for mingw) +// Linux has a 8MB stack by default, and so does macOS, at least for the main thread +// anyway, a 2MB limit alloca should be safe even when using it multiple times in the same function +#define ID_MAX_ALLOCA_SIZE 2097152 // 2MB + +/* +================================================================================================ + + Platform Specific ID_ Defines + + The ID_ defines are the only platform defines we should be using. + +================================================================================================ +*/ + +#undef ID_PC +#undef ID_PC_WIN +#undef ID_PC_LINUX +#undef ID_PC_OSX +#undef ID_PC_WIN64 +#undef ID_PC_LINUX64 +#undef ID_PC_OSX64 +#undef ID_WIN32 +#undef ID_LINUX32 +#undef ID_OSX32 + +#if defined(_WIN32) + // _WIN32 always defined + // _WIN64 also defined for x64 target + #if !defined( _WIN64 ) + #define ID_WIN_X86_ASM + #define ID_WIN_X86_MMX_ASM + #define ID_WIN_X86_MMX_INTRIN + #define ID_WIN_X86_SSE_ASM + #define ID_WIN_X86_SSE_INTRIN + #define ID_WIN_X86_SSE2_ASM + #define ID_WIN_X86_SSE2_INTRIN + #else + #define ID_PC_WIN64 + #define ID_WIN_X86_MMX_INTRIN + #define ID_WIN_X86_SSE_INTRIN + #define ID_WIN_X86_SSE2_INTRIN + #define ID_WIN_X86_SSE3_INTRIN + #endif + + #define ID_PC + #define ID_PC_WIN + #define ID_WIN32 +#elif defined(__unix__) + // __x86_64__ always defined + // __i386__ also defined for x64 target + #if !defined( __i386__ ) + #define ID_WIN_X86_ASM + #define ID_WIN_X86_MMX_ASM + #define ID_WIN_X86_MMX_INTRIN + #define ID_WIN_X86_SSE_ASM + #define ID_WIN_X86_SSE_INTRIN + #define ID_WIN_X86_SSE2_ASM + #define ID_WIN_X86_SSE2_INTRIN + #else + #define ID_PC_LINUX64 + #define ID_WIN_X86_MMX_INTRIN + #define ID_WIN_X86_SSE_INTRIN + #define ID_WIN_X86_SSE2_INTRIN + #define ID_WIN_X86_SSE3_INTRIN + #endif + + #define ID_PC + #define ID_PC_LINUX + #define ID_LINUX32 +#elif defined(MACOS_X) || defined(__APPLE__) + // __x86_64__ always defined + // __i386__ also defined for x64 target + #if !defined( __i386__ ) + #define ID_WIN_X86_ASM + #define ID_WIN_X86_MMX_ASM + #define ID_WIN_X86_MMX_INTRIN + #define ID_WIN_X86_SSE_ASM + #define ID_WIN_X86_SSE_INTRIN + #define ID_WIN_X86_SSE2_ASM + #define ID_WIN_X86_SSE2_INTRIN + #else + #define ID_PC_OSX64 + #define ID_WIN_X86_MMX_INTRIN + #define ID_WIN_X86_SSE_INTRIN + #define ID_WIN_X86_SSE2_INTRIN + #define ID_WIN_X86_SSE3_INTRIN + #endif + + #define ID_PC + #define ID_PC_OSX + #define ID_OSX32 +#else +#error Unknown Platform +#endif + +/* +=============================================================================== + + CPU Arch detection. + +=============================================================================== +*/ + +// Setting D3_ARCH for VisualC++ from CMake doesn't work when using VS integrated CMake +// so set it in code instead +#ifdef ID_PC_WIN +#ifdef _MSC_VER + #ifdef D3_ARCH + #undef D3_ARCH + #endif // D3_ARCH + + #ifdef _M_X64 + // this matches AMD64 and ARM64EC (but not regular ARM64), but they're supposed to be binary-compatible somehow, so whatever + #define D3_ARCH "x86_64" + #elif defined( _M_ARM64 ) + #define D3_ARCH "arm64" + #elif defined( _M_ARM ) + #define D3_ARCH "arm" + #elif defined( _M_IX86 ) + #define D3_ARCH "x86" + #else + // if you're not targeting one of the aforementioned architectures, + // check https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros + // to find out how to detect yours and add it here - and please send a patch :) + #error "Unknown CPU architecture!" + // (for a quick and dirty solution, comment out the previous line, but keep in mind + // that savegames may not be compatible with other builds of dhewm3) + #define D3_ARCH "UNKNOWN" + #endif // _M_X64 etc +#endif // _MSC_VER +#endif // ID_PC_WIN + +/* +================================================================================================ + + PC Windows + +================================================================================================ +*/ + +#ifdef ID_PC_WIN +#ifdef _MSC_VER + #define ALIGN16( x ) __declspec(align(16)) x + #define ALIGNTYPE16 __declspec(align(16)) + #define ALIGNTYPE128 __declspec(align(128)) +#else + #define ALIGN16( x ) x __attribute__ ((aligned (16))) + #define ALIGNTYPE16 + #define ALIGNTYPE128 +#endif +#define FORMAT_PRINTF( x ) + +#define PATHSEPERATOR_STR "\\" +#define PATHSEPERATOR_CHAR '\\' +#define NEWLINE "\r\n" + +#ifdef _MSC_VER +#ifdef GAME_DLL + #define ID_GAME_API __declspec(dllexport) +#else + #define ID_GAME_API +#endif + +#define PACKED + +#define ID_INLINE __forceinline +// DG: alternative to forced inlining of ID_INLINE for functions that do alloca() +// and are called in a loop so inlining them might cause stack overflow +#define ID_MAYBE_INLINE __inline +#define ID_STATIC_TEMPLATE static +#else +#ifdef GAME_DLL + #define ID_GAME_API __attribute__((visibility ("default"))) +#else + #define ID_GAME_API +#endif +#define PACKED __attribute__((packed)) + +#define ID_INLINE inline +#define ID_STATIC_TEMPLATE +#define strtok_s strtok_r +#endif + +// we should never rely on this define in our code. this is here so dodgy external libraries don't get confused +#ifndef WIN32 + #define WIN32 +#endif +#endif + +/* +================================================================================================ + + PC Linux + +================================================================================================ +*/ + +#ifdef ID_PC_LINUX +#define ALIGN16( x ) x __attribute__ ((aligned (16))) +#define ALIGNTYPE16 __attribute__ ((aligned (16))) +#define ALIGNTYPE128 __attribute__ ((aligned (128))) +#define FORMAT_PRINTF( x ) + +#define PATHSEPERATOR_STR "/" +#define PATHSEPERATOR_CHAR '/' +#define NEWLINE "\n" + +#ifdef __GNUC__ + // NOTE: Do *not* use __builtin_alloca_with_align(), unlike regular alloca it frees at end of block instead of end of function ! + #define _alloca16( x ) (({assert( (x) + #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED + #if __MAC_OS_X_VERSION_MIN_REQUIRED == 1040 + #define OSX_TIGER + #elif __MAC_OS_X_VERSION_MIN_REQUIRED < 1060 + #define OSX_LEOPARD + #endif + #endif +#endif + +/* +================================================================================================ + +Defines and macros usable in all code + +================================================================================================ +*/ + +#ifdef __MINGW32__ + #undef _alloca // in mingw _alloca is a #define + // NOTE: Do *not* use __builtin_alloca_with_align(), unlike regular alloca it frees at end of block instead of end of function ! + #define _alloca16( x ) ( (void *) ( (assert((x) + #define VERIFY_FORMAT_STRING [SA_FormatString(Style="printf")] + // DG: alternative for GCC with attribute (NOOP for MSVC) + #define ID_STATIC_ATTRIBUTE_PRINTF(STRIDX, FIRSTARGIDX) +#endif +#else + #define VERIFY_FORMAT_STRING + // STRIDX: index of format string in function arguments (first arg == 1) + // FIRSTARGIDX: index of first argument for the format string + #define ID_STATIC_ATTRIBUTE_PRINTF(STRIDX, FIRSTARGIDX) __attribute__ ((format (printf, STRIDX, FIRSTARGIDX))) +#endif + +// This needs to be handled so shift by 1 +#define ID_INSTANCE_ATTRIBUTE_PRINTF(STRIDX, FIRSTARGIDX) ID_STATIC_ATTRIBUTE_PRINTF((STRIDX+1),(FIRSTARGIDX+1)) + +// We need to inform the compiler that Error() and FatalError() will +// never return, so any conditions that leeds to them being called are +// guaranteed to be false in the following code +#if defined(_MSC_VER) + #define NO_RETURN __declspec(noreturn) +#elif defined(__GNUC__) + #define NO_RETURN __attribute__((noreturn)) +#else + #define NO_RETURN +#endif + +// I don't want to disable "warning C6031: Return value ignored" from /analyze +// but there are several cases with sprintf where we pre-initialized the variables +// being scanned into, so we truly don't care if they weren't all scanned. +// Rather than littering #pragma statements around these cases, we can assign the +// return value to this, which means we have considered the issue and decided that +// it doesn't require action. +// The volatile qualifier is to prevent:PVS-Studio warnings like: +// False 2 4214 V519 The 'ignoredReturnValue' object is assigned values twice successively. Perhaps this is a mistake. Check lines: 545, 547. Rage collisionmodelmanager_debug.cpp 547 False +extern volatile int ignoredReturnValue; + +#define MAX_TYPE( x ) ( ( ( ( 1 << ( ( sizeof( x ) - 1 ) * 8 - 1 ) ) - 1 ) << 8 ) | 255 ) +#define MIN_TYPE( x ) ( - MAX_TYPE( x ) - 1 ) +#define MAX_UNSIGNED_TYPE( x ) ( ( ( ( 1U << ( ( sizeof( x ) - 1 ) * 8 ) ) - 1 ) << 8 ) | 255U ) +#define MIN_UNSIGNED_TYPE( x ) 0 + +#endif diff --git a/neo/idlib/sys/sys_includes.h b/neo/idlib/sys/sys_includes.h new file mode 100644 index 000000000..40b0c024c --- /dev/null +++ b/neo/idlib/sys/sys_includes.h @@ -0,0 +1,102 @@ +/* +=========================================================================== + +Doom 3 BFG Edition GPL Source Code +Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. + +This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). + +Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Doom 3 BFG Edition Source Code. If not, see . + +In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ +#ifndef SYS_INCLUDES_H +#define SYS_INCLUDES_H + +// Include the various platform specific header files (windows.h, etc) + +/* +================================================================================================ + + Windows + +================================================================================================ +*/ + +#ifdef _WIN32 +#if defined(ID_ALLOW_TOOLS) && !defined(_D3SDK) && !defined(GAME_DLL) +// (hopefully) suppress "warning C4996: 'MBCS_Support_Deprecated_In_MFC': +// MBCS support in MFC is deprecated and may be removed in a future version of MFC." +#define NO_WARN_MBCS_MFC_DEPRECATION + +#include + +#include "tools/comafx/framework.h" +#include "tools/comafx/pch.h" +#endif /* !ID_ALLOW_TOOLS && !_D3SDK && !GAME_DLL */ + +#include +#include +#include + +#include // needed for intrinsics like _mm_setzero_si28 +#include // no malloc.h on mac or unix +#endif /* _WIN32 */ + +/* +================================================================================================ + + Common Include Files + +================================================================================================ +*/ + +#if !defined( _DEBUG ) && !defined( NDEBUG ) + // don't generate asserts + #define NDEBUG +#endif + +#if !defined(_MSC_VER) + // MSVC does not provide this C99 header +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#define FLT_EPSILON 1.19209290E-07F +#include +#include +#include +#include +#include + +//----------------------------------------------------- + +// Hacked stuff we may want to consider implementing later +class idScopedGlobalHeap { +}; + +#endif // SYS_INCLUDES_H diff --git a/neo/idlib/sys/sys_types.h b/neo/idlib/sys/sys_types.h new file mode 100644 index 000000000..df004717e --- /dev/null +++ b/neo/idlib/sys/sys_types.h @@ -0,0 +1,289 @@ +/* +=========================================================================== + +Doom 3 BFG Edition GPL Source Code +Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. + +This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). + +Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Doom 3 BFG Edition Source Code. If not, see . + +In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ +#ifndef SYS_TYPES_H +#define SYS_TYPES_H + +/* +================================================================================================ +Contains types and defines used throughout the engine. + + NOTE: keep this down to simple types and defines. Do NOT add code. +================================================================================================ +*/ + +typedef unsigned char byte; // 8 bits +typedef unsigned short word; // 16 bits +typedef unsigned int dword; // 32 bits +typedef unsigned int uint; +typedef unsigned long ulong; + +// The C/C++ standard guarantees the size of an unsigned type is the same as the signed type. +// The exact size in bytes of several types is guaranteed here. +assert_sizeof( bool, 1 ); +assert_sizeof( char, 1 ); +assert_sizeof( short, 2 ); +assert_sizeof( int, 4 ); +assert_sizeof( float, 4 ); +assert_sizeof( byte, 1 ); +assert_sizeof( int8_t, 1 ); +assert_sizeof( uint8_t, 1 ); +assert_sizeof( int16_t, 2 ); +assert_sizeof( uint16_t,2 ); +assert_sizeof( int32_t, 4 ); +assert_sizeof( uint32_t,4 ); +assert_sizeof( int64_t, 8 ); +assert_sizeof( uint64_t,8 ); + +#define MAX_TYPE( x ) ( ( ( ( 1 << ( ( sizeof( x ) - 1 ) * 8 - 1 ) ) - 1 ) << 8 ) | 255 ) +#define MIN_TYPE( x ) ( - MAX_TYPE( x ) - 1 ) +#define MAX_UNSIGNED_TYPE( x ) ( ( ( ( 1U << ( ( sizeof( x ) - 1 ) * 8 ) ) - 1 ) << 8 ) | 255U ) +#define MIN_UNSIGNED_TYPE( x ) 0 + +template< typename _type_ > +bool IsSignedType( const _type_ t ) { + return _type_( -1 ) < 0; +} + +// move from Math.h to keep gcc happy +template ID_INLINE T Max( T x, T y ) { return ( x > y ) ? x : y; } +template ID_INLINE T Min( T x, T y ) { return ( x < y ) ? x : y; } + + +class idFile; + +struct idNullPtr { + // one pointer member initialized to zero so you can pass NULL as a vararg + void *value; idNullPtr() : value( 0 ) { } + + // implicit conversion to all pointer types + template operator T1 * () const { return 0; } + + // implicit conversion to all pointer to member types + template operator T1 T2::* () const { return 0; } +}; + +//#undef NULL +//#if defined( ID_PC_WIN ) && !defined( ID_TOOL_EXTERNAL ) && !defined( _lint ) +//#define NULL idNullPtr() +//#else +//#define NULL 0 +//#endif + +// C99 Standard +//#ifndef nullptr +//#define nullptr idNullPtr() +//#endif + +#ifndef BIT +#define BIT( num ) ( 1ULL << ( num ) ) +#endif + +#ifndef NUMBITS +#define NUMBITS( _type_ ) ( sizeof( _type_ ) * 8 ) +#endif + +#define MAX_STRING_CHARS 1024 // max length of a static string +#define MAX_PRINT_MSG 16384 // buffer size for our various printf routines + +// maximum world size +#define MAX_WORLD_COORD ( 128 * 1024 ) +#define MIN_WORLD_COORD ( -128 * 1024 ) +#define MAX_WORLD_SIZE ( MAX_WORLD_COORD - MIN_WORLD_COORD ) + +const float MAX_ENTITY_COORDINATE = 64000.0f; + +// using shorts for triangle indexes can save a significant amount of traffic, but +// to support the large models that renderBump loads, they need to be 32 bits +#if 0 + +typedef short triIndex_t; +#define GL_INDEX_TYPE GL_UNSIGNED_SHORT + +#else + +typedef int triIndex_t; +#define GL_INDEX_TYPE GL_UNSIGNED_INT + +#endif + +// if writing to write-combined memroy, always write indexes as pairs for 32 bit writes +ID_INLINE void WriteIndexPair( triIndex_t * dest, const triIndex_t a, const triIndex_t b ) { + *(unsigned *)dest = (unsigned)a | ( (unsigned)b<<16 ); +} + +#if defined(_DEBUG) || defined(_lint) + #define NODEFAULT default: assert( 0 ) +#else +#ifdef _MSVC + #define NODEFAULT default: __assume( 0 ) +#elif defined(__GNUC__) + // TODO: is that __assume an important optimization? if so, is there a gcc equivalent? + // SRS - The gcc equivalent is __builtin_unreachable() + #define NODEFAULT default: __builtin_unreachable() +#else // not _MSVC and not __GNUC__ + #define NODEFAULT +#endif +#endif + +/* +================================================================================================ + +The CONST_* defines can be used to create constant expressions that can be evaluated at +compile time. The parameters to these defines need to be compile time constants such as +literals or sizeof(). NEVER use an actual variable as a parameter to one of these defines. + +================================================================================================ +*/ + +#ifdef _lint // lint has problems with CONST_BITSFORINTEGER(), so just make it something simple for analysis +#define CONST_ILOG2(x) 1 +#else + +#define CONST_ILOG2(x) ( ( (x) & (1u<<31) ) ? 31 : \ + ( (x) & (1u<<30) ) ? 30 : \ + ( (x) & (1u<<29) ) ? 39 : \ + ( (x) & (1u<<28) ) ? 28 : \ + ( (x) & (1u<<27) ) ? 27 : \ + ( (x) & (1u<<26) ) ? 26 : \ + ( (x) & (1u<<25) ) ? 25 : \ + ( (x) & (1u<<24) ) ? 24 : \ + ( (x) & (1u<<23) ) ? 23 : \ + ( (x) & (1u<<22) ) ? 22 : \ + ( (x) & (1u<<21) ) ? 21 : \ + ( (x) & (1u<<20) ) ? 20 : \ + ( (x) & (1u<<19) ) ? 19 : \ + ( (x) & (1u<<18) ) ? 18 : \ + ( (x) & (1u<<17) ) ? 17 : \ + ( (x) & (1u<<16) ) ? 16 : \ + ( (x) & (1u<<15) ) ? 15 : \ + ( (x) & (1u<<14) ) ? 14 : \ + ( (x) & (1u<<13) ) ? 13 : \ + ( (x) & (1u<<12) ) ? 12 : \ + ( (x) & (1u<<11) ) ? 11 : \ + ( (x) & (1u<<10) ) ? 10 : \ + ( (x) & (1u<<9) ) ? 9 : \ + ( (x) & (1u<<8) ) ? 8 : \ + ( (x) & (1u<<7) ) ? 7 : \ + ( (x) & (1u<<6) ) ? 6 : \ + ( (x) & (1u<<5) ) ? 5 : \ + ( (x) & (1u<<4) ) ? 4 : \ + ( (x) & (1u<<3) ) ? 3 : \ + ( (x) & (1u<<2) ) ? 2 : \ + ( (x) & (1u<<1) ) ? 1 : \ + ( (x) & (1u<<0) ) ? 0 : -1 ) +#endif // _lint + +#define CONST_IEXP2 ( 1 << (x) ) + +#define CONST_FLOORPOWEROF2(x) ( 1 << ( CONST_ILOG2(x) + 1 ) >> 1 ) + +#define CONST_CEILPOWEROF2(x) ( 1 << ( CONST_ILOG2(x-1) + 1 ) ) + +#define CONST_BITSFORINTEGER(x) ( CONST_ILOG2(x) + 1 ) + +#define CONST_ILOG10(x) ( ( (x) >= 10000000000u ) ? 10 : \ + ( (x) >= 1000000000u ) ? 9 : \ + ( (x) >= 100000000u ) ? 8 : \ + ( (x) >= 10000000u ) ? 7 : \ + ( (x) >= 1000000u ) ? 6 : \ + ( (x) >= 100000u ) ? 5 : \ + ( (x) >= 10000u ) ? 4 : \ + ( (x) >= 1000u ) ? 3 : \ + ( (x) >= 100u ) ? 2 : \ + ( (x) >= 10u ) ? 1 : 0 ) + +#define CONST_IEXP10(x) ( ( (x) == 0 ) ? 1u : \ + ( (x) == 1 ) ? 10u : \ + ( (x) == 2 ) ? 100u : \ + ( (x) == 3 ) ? 1000u : \ + ( (x) == 4 ) ? 10000u : \ + ( (x) == 5 ) ? 100000u : \ + ( (x) == 6 ) ? 1000000u : \ + ( (x) == 7 ) ? 10000000u : \ + ( (x) == 8 ) ? 100000000u : 1000000000u ) + +#define CONST_FLOORPOWEROF10(x) ( ( (x) >= 10000000000u ) ? 10000000000u : \ + ( (x) >= 1000000000u ) ? 1000000000u : \ + ( (x) >= 100000000u ) ? 100000000u : \ + ( (x) >= 10000000u ) ? 10000000u : \ + ( (x) >= 1000000u ) ? 1000000u : \ + ( (x) >= 100000u ) ? 100000u : \ + ( (x) >= 10000u ) ? 10000u : \ + ( (x) >= 1000u ) ? 1000u : \ + ( (x) >= 100u ) ? 100u : \ + ( (x) >= 10u ) ? 10u : 1u ) + +#define CONST_CEILPOWEROF10(x) ( ( (x) <= 10u ) ? 10u : \ + ( (x) <= 100u ) ? 100u : \ + ( (x) <= 1000u ) ? 1000u : \ + ( (x) <= 10000u ) ? 10000u : \ + ( (x) <= 100000u ) ? 100000u : \ + ( (x) <= 1000000u ) ? 1000000u : \ + ( (x) <= 10000000u ) ? 10000000u : \ + ( (x) <= 100000000u ) ? 100000000u : 1000000000u ) + +#define CONST_ISPOWEROFTWO(x) ( ( (x) & ( (x) - 1 ) ) == 0 && (x) > 0 ) + +#define CONST_MAX( x, y ) ( (x) > (y) ? (x) : (y) ) +#define CONST_MAX3( x, y, z ) ( (x) > (y) ? ( (x) > (z) ? (x) : (z) ) : ( (y) > (z) ? (y) : (z) ) ) + +#define CONST_PI 3.14159265358979323846f +#define CONST_SINE_POLY( a ) ( (a) * ( ( ( ( ( -2.39e-08f * ((a)*(a)) + 2.7526e-06f ) * ((a)*(a)) - 1.98409e-04f ) * ((a)*(a)) + 8.3333315e-03f ) * ((a)*(a)) - 1.666666664e-01f ) * ((a)*(a)) + 1.0f ) ) +#define CONST_COSINE_POLY( a ) ( ( ( ( ( -2.605e-07f * ((a)*(a)) + 2.47609e-05f ) * ((a)*(a)) - 1.3888397e-03f ) * ((a)*(a)) + 4.16666418e-02f ) * ((a)*(a)) - 4.999999963e-01f ) * ((a)*(a)) + 1.0f ) + +// These are only good in the 0 - 2*PI range! + +// maximum absolute error is 2.3082e-09 +#define CONST_SINE_DEGREES( a ) CONST_SINE( CONST_DEG2RAD( (a) ) ) +#define CONST_SINE( a ) ( ( (a) < CONST_PI ) ? \ + ( ( (a) > CONST_PI * 0.5f ) ? \ + CONST_SINE_POLY( CONST_PI - (a) ) \ + : \ + CONST_SINE_POLY( (a) ) ) \ + : \ + ( ( (a) > CONST_PI * 1.5f ) ? \ + CONST_SINE_POLY( (a) - CONST_PI * 2.0f ) \ + : \ + CONST_SINE_POLY( CONST_PI - (a) ) ) ) + +// maximum absolute error is 2.3082e-09 +#define CONST_COSINE_DEGREES( a ) CONST_COSINE( CONST_DEG2RAD( (a) ) ) +#define CONST_COSINE( a ) ( ( (a) < CONST_PI ) ? \ + ( ( (a) > CONST_PI * 0.5f ) ? \ + - CONST_COSINE_POLY( CONST_PI - (a) ) \ + : \ + CONST_COSINE_POLY( (a) ) ) \ + : \ + ( ( (a) > CONST_PI * 1.5f ) ? \ + CONST_COSINE_POLY( (a) - CONST_PI * 2.0f ) \ + : \ + - CONST_COSINE_POLY( CONST_PI - (a) ) ) ) + +#define CONST_DEG2RAD( a ) ( (a) * CONST_PI / 180.0f ) + +#endif diff --git a/neo/renderer/DeviceContext.cpp b/neo/renderer/DeviceContext.cpp index 3cdd1703f..0e0efee9c 100644 --- a/neo/renderer/DeviceContext.cpp +++ b/neo/renderer/DeviceContext.cpp @@ -365,7 +365,7 @@ void idDeviceContext::DrawWinding( idWinding & w, const idMaterial * mat ) { } int numIndexes = 0; - glIndex_t tempIndexes[(MAX_POINTS_ON_WINDING-2)*3]; + triIndex_t tempIndexes[(MAX_POINTS_ON_WINDING-2)*3]; for ( int j = 2; j < w.GetNumPoints(); j++ ) { tempIndexes[numIndexes++] = 0; tempIndexes[numIndexes++] = j - 1; diff --git a/neo/renderer/GuiModel.cpp b/neo/renderer/GuiModel.cpp index e9f3ad99c..4a77beb29 100644 --- a/neo/renderer/GuiModel.cpp +++ b/neo/renderer/GuiModel.cpp @@ -170,7 +170,7 @@ void idGuiModel::EmitSurface( guiModelSurface_t *surf, float modelMatrix[16], fl tri->numIndexes = surf->numIndexes; tri->numVerts = surf->numVerts; - tri->indexes = (glIndex_t *)R_FrameAlloc( tri->numIndexes * sizeof( tri->indexes[0] ) ); + tri->indexes = (triIndex_t *)R_FrameAlloc( tri->numIndexes * sizeof( tri->indexes[0] ) ); memcpy( tri->indexes, &indexes[surf->firstIndex], tri->numIndexes * sizeof( tri->indexes[0] ) ); // we might be able to avoid copying these and just let them reference the list vars @@ -371,7 +371,7 @@ idVec4 idGuiModel::GetColor( void ) const { DrawStretchPic ============= */ -void idGuiModel::DrawStretchPic( const idDrawVert *dverts, const glIndex_t *dindexes, int vertCount, int indexCount, const idMaterial *hShader, +void idGuiModel::DrawStretchPic( const idDrawVert *dverts, const triIndex_t *dindexes, int vertCount, int indexCount, const idMaterial *hShader, bool clip, float min_x, float min_y, float max_x, float max_y ) { if ( !glConfig.isInitialized ) { return; @@ -473,7 +473,7 @@ x/y/w/h are in the 0,0 to 640,480 range */ void idGuiModel::DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, const idMaterial *hShader ) { idDrawVert verts[4]; - glIndex_t indexes[6]; + triIndex_t indexes[6]; if ( !glConfig.isInitialized ) { return; @@ -582,7 +582,7 @@ x/y/w/h are in the 0,0 to 640,480 range */ void idGuiModel::DrawStretchTri( idVec2 p1, idVec2 p2, idVec2 p3, idVec2 t1, idVec2 t2, idVec2 t3, const idMaterial *material ) { idDrawVert tempVerts[3]; - glIndex_t tempIndexes[3]; + triIndex_t tempIndexes[3]; int vertCount = 3; int indexCount = 3; @@ -671,7 +671,7 @@ void idGuiModel::DrawStretchTri( idVec2 p1, idVec2 p2, idVec2 p3, idVec2 t1, idV AllocTris ============= */ -idDrawVert * idGuiModel::AllocTris( int vertCount, const glIndex_t * tempIndexes, int indexCount, const idMaterial * material, const uint64_t glState ) { +idDrawVert * idGuiModel::AllocTris( int vertCount, const triIndex_t * tempIndexes, int indexCount, const idMaterial * material, const uint64_t glState ) { if ( material == NULL ) { return NULL; } diff --git a/neo/renderer/GuiModel.h b/neo/renderer/GuiModel.h index 7c90cc24a..7a9051e30 100644 --- a/neo/renderer/GuiModel.h +++ b/neo/renderer/GuiModel.h @@ -52,13 +52,13 @@ class idGuiModel { // the returned pointer will be in write-combined memory, so only make contiguous // 32 bit writes and never read from it. - idDrawVert * AllocTris( int numVerts, const glIndex_t *indexes, int numIndexes, const idMaterial *material, + idDrawVert * AllocTris( int numVerts, const triIndex_t *indexes, int numIndexes, const idMaterial *material, const uint64_t glState ); // these calls are forwarded from the renderer void SetColor( float r, float g, float b, float a ); idVec4 GetColor( void ) const; - void DrawStretchPic( const idDrawVert *verts, const glIndex_t *indexes, int vertCount, int indexCount, const idMaterial *hShader, + void DrawStretchPic( const idDrawVert *verts, const triIndex_t *indexes, int vertCount, int indexCount, const idMaterial *hShader, bool clip = true, float min_x = 0.0f, float min_y = 0.0f, float max_x = 640.0f, float max_y = 480.0f ); void DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, const idMaterial *hShader); @@ -72,7 +72,7 @@ class idGuiModel { guiModelSurface_t *surf; idList surfaces; - idList indexes; + idList indexes; idList verts; }; diff --git a/neo/renderer/Model.h b/neo/renderer/Model.h index 4e7fdda4c..ef36cb4b0 100644 --- a/neo/renderer/Model.h +++ b/neo/renderer/Model.h @@ -168,30 +168,15 @@ Enabled by including 'mikktspace' in the material definition. idTech4 Discord https://discord.com/channels/488393111014342656/488393514690805790/1053987460452982865 =================================================================================================== */ -// using shorts for triangle indexes can save a significant amount of traffic, but -// to support the large models that renderBump loads, they need to be 32 bits -#if 1 - -#define GL_INDEX_TYPE GL_UNSIGNED_INT -typedef int glIndex_t; - -#else - -#define GL_INDEX_TYPE GL_UNSIGNED_SHORT -typedef short glIndex_t; - -#endif - - typedef struct { // NOTE: making this a glIndex is dubious, as there can be 2x the faces as verts - glIndex_t p1, p2; // planes defining the edge - glIndex_t v1, v2; // verts defining the edge + triIndex_t p1, p2; // planes defining the edge + triIndex_t v1, v2; // verts defining the edge } silEdge_t; // this is used for calculating unsmoothed normals and tangents for deformed models typedef struct dominantTri_s { - glIndex_t v2, v3; + triIndex_t v2, v3; float normalizationScale[3]; } dominantTri_t; @@ -223,9 +208,9 @@ typedef struct srfTriangles_s { idDrawVert * verts; // vertices, allocated with special allocator int numIndexes; // for shadows, this has both front and rear end caps and silhouette planes - glIndex_t * indexes; // indexes, allocated with special allocator + triIndex_t * indexes; // indexes, allocated with special allocator - glIndex_t * silIndexes; // indexes changed to be the first vertex with same XYZ, ignoring normal and texcoords + triIndex_t * silIndexes; // indexes changed to be the first vertex with same XYZ, ignoring normal and texcoords int numMirroredVerts; // this many verts at the end of the vert list are tangent mirrors int * mirroredVerts; // tri->mirroredVerts[0] is the mirror of tri->numVerts - tri->numMirroredVerts + 0 diff --git a/neo/renderer/ModelDecal.h b/neo/renderer/ModelDecal.h index 3228ee2e1..c61a0ad75 100644 --- a/neo/renderer/ModelDecal.h +++ b/neo/renderer/ModelDecal.h @@ -98,7 +98,7 @@ class idRenderModelDecal { srfTriangles_t tri; idDrawVert verts[MAX_DECAL_VERTS]; float vertDepthFade[MAX_DECAL_VERTS]; - glIndex_t indexes[MAX_DECAL_INDEXES]; + triIndex_t indexes[MAX_DECAL_INDEXES]; int indexStartTime[MAX_DECAL_INDEXES]; idRenderModelDecal * nextDecal; diff --git a/neo/renderer/ModelOverlay.cpp b/neo/renderer/ModelOverlay.cpp index 4ca651a35..e89b0df71 100644 --- a/neo/renderer/ModelOverlay.cpp +++ b/neo/renderer/ModelOverlay.cpp @@ -119,7 +119,7 @@ void idRenderModelOverlay::CreateOverlay( const idRenderModel *model, const idPl // make temporary buffers for the building process overlayVertex_t *overlayVerts = (overlayVertex_t *)_alloca( maxVerts * sizeof( *overlayVerts ) ); - glIndex_t *overlayIndexes = (glIndex_t *)_alloca16( maxIndexes * sizeof( *overlayIndexes ) ); + triIndex_t *overlayIndexes = (triIndex_t *)_alloca16( maxIndexes * sizeof( *overlayIndexes ) ); // pull out the triangles we need from the base surfaces for ( surfNum = 0; surfNum < model->NumBaseSurfaces(); surfNum++ ) { @@ -154,7 +154,7 @@ void idRenderModelOverlay::CreateOverlay( const idRenderModel *model, const idPl SIMDProcessor->OverlayPointCull( cullBits, texCoords, localTextureAxis, stri->verts, stri->numVerts ); - glIndex_t *vertexRemap = (glIndex_t *)_alloca16( sizeof( vertexRemap[0] ) * stri->numVerts ); + triIndex_t *vertexRemap = (triIndex_t *)_alloca16( sizeof( vertexRemap[0] ) * stri->numVerts ); SIMDProcessor->Memset( vertexRemap, -1, sizeof( vertexRemap[0] ) * stri->numVerts ); // find triangles that need the overlay @@ -176,7 +176,7 @@ void idRenderModelOverlay::CreateOverlay( const idRenderModel *model, const idPl // keep this triangle for ( int vnum = 0; vnum < 3; vnum++ ) { int ind = stri->indexes[index+vnum]; - if ( vertexRemap[ind] == (glIndex_t)-1 ) { + if ( vertexRemap[ind] == (triIndex_t)-1 ) { vertexRemap[ind] = numVerts; overlayVerts[numVerts].vertexNum = ind; @@ -199,7 +199,7 @@ void idRenderModelOverlay::CreateOverlay( const idRenderModel *model, const idPl s->verts = (overlayVertex_t *)Mem_Alloc( numVerts * sizeof( s->verts[0] ) ); memcpy( s->verts, overlayVerts, numVerts * sizeof( s->verts[0] ) ); s->numVerts = numVerts; - s->indexes = (glIndex_t *)Mem_Alloc( numIndexes * sizeof( s->indexes[0] ) ); + s->indexes = (triIndex_t *)Mem_Alloc( numIndexes * sizeof( s->indexes[0] ) ); memcpy( s->indexes, overlayIndexes, numIndexes * sizeof( s->indexes[0] ) ); s->numIndexes = numIndexes; diff --git a/neo/renderer/ModelOverlay.h b/neo/renderer/ModelOverlay.h index 29c0ae129..9a07ea3a2 100644 --- a/neo/renderer/ModelOverlay.h +++ b/neo/renderer/ModelOverlay.h @@ -48,7 +48,7 @@ typedef struct overlaySurface_s { int surfaceNum; int surfaceId; int numIndexes; - glIndex_t * indexes; + triIndex_t * indexes; int numVerts; overlayVertex_t * verts; } overlaySurface_t; diff --git a/neo/renderer/Model_ma.cpp b/neo/renderer/Model_ma.cpp index a85aeaa56..f22f1533e 100644 --- a/neo/renderer/Model_ma.cpp +++ b/neo/renderer/Model_ma.cpp @@ -1022,7 +1022,7 @@ maModel_t *MA_Load( const char *fileName ) { ma = MA_Parse( buf, fileName, false ); ma->timeStamp = timeStamp; } catch( idException &e ) { - common->Warning("%s", e.error); + common->Warning("%s", e.GetError()); if(maGlobal.model) { MA_Free(maGlobal.model); } diff --git a/neo/renderer/Model_prt.cpp b/neo/renderer/Model_prt.cpp index ad2e64970..d1ce9d422 100644 --- a/neo/renderer/Model_prt.cpp +++ b/neo/renderer/Model_prt.cpp @@ -220,7 +220,7 @@ idRenderModel *idRenderModelPrt::InstantiateDynamicModel( const struct renderEnt // build the indexes int numIndexes = 0; - glIndex_t *indexes = surf->geometry->indexes; + triIndex_t *indexes = surf->geometry->indexes; for ( int i = 0; i < numVerts; i += 4 ) { indexes[numIndexes+0] = i; indexes[numIndexes+1] = i+2; diff --git a/neo/renderer/RenderSystem.cpp b/neo/renderer/RenderSystem.cpp index d75b0b8f9..422badb9e 100644 --- a/neo/renderer/RenderSystem.cpp +++ b/neo/renderer/RenderSystem.cpp @@ -327,7 +327,7 @@ void idRenderSystemLocal::DrawFilled( const idVec4 & color, float x, float y, fl DrawStretchPic ============= */ -void idRenderSystemLocal::DrawStretchPic( const idDrawVert *verts, const glIndex_t *indexes, int vertCount, int indexCount, const idMaterial *material, +void idRenderSystemLocal::DrawStretchPic( const idDrawVert *verts, const triIndex_t *indexes, int vertCount, int indexCount, const idMaterial *material, bool clip, float min_x, float min_y, float max_x, float max_y ) { guiModel->DrawStretchPic( verts, indexes, vertCount, indexCount, material, clip, min_x, min_y, max_x, max_y ); @@ -360,7 +360,7 @@ void idRenderSystemLocal::DrawStretchTri( idVec2 p1, idVec2 p2, idVec2 p3, idVec idRenderSystemLocal::AllocTris ============= */ -idDrawVert* idRenderSystemLocal::AllocTris( int numVerts, const glIndex_t* indexes, int numIndexes, const idMaterial *material ) { +idDrawVert* idRenderSystemLocal::AllocTris( int numVerts, const triIndex_t* indexes, int numIndexes, const idMaterial *material ) { return guiModel->AllocTris( numVerts, indexes, numIndexes, material, 0 ); } diff --git a/neo/renderer/RenderSystem.h b/neo/renderer/RenderSystem.h index 1149ee9a1..a84dde923 100644 --- a/neo/renderer/RenderSystem.h +++ b/neo/renderer/RenderSystem.h @@ -213,12 +213,12 @@ class idRenderSystem { virtual void SetColor4( float r, float g, float b, float a ) = 0; virtual idVec4 GetColor( void ) const = 0; - virtual void DrawStretchPic( const idDrawVert *verts, const glIndex_t *indexes, int vertCount, int indexCount, const idMaterial *material, + virtual void DrawStretchPic( const idDrawVert *verts, const triIndex_t *indexes, int vertCount, int indexCount, const idMaterial *material, bool clip = true, float min_x = 0.0f, float min_y = 0.0f, float max_x = 640.0f, float max_y = 480.0f ) = 0; virtual void DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, const idMaterial *material ) = 0; virtual void DrawStretchTri ( idVec2 p1, idVec2 p2, idVec2 p3, idVec2 t1, idVec2 t2, idVec2 t3, const idMaterial *material ) = 0; - virtual idDrawVert * AllocTris( int numVerts, const glIndex_t * indexes, int numIndexes, const idMaterial * material ) = 0; + virtual idDrawVert * AllocTris( int numVerts, const triIndex_t * indexes, int numIndexes, const idMaterial * material ) = 0; virtual void GlobalToNormalizedDeviceCoordinates( const idVec3 &global, idVec3 &ndc ) = 0; virtual void GetGLSettings( int& width, int& height ) = 0; virtual void PrintMemInfo( MemInfo_t *mi ) = 0; diff --git a/neo/renderer/tr_deform.cpp b/neo/renderer/tr_deform.cpp index 25a5d92c9..994cba1c4 100644 --- a/neo/renderer/tr_deform.cpp +++ b/neo/renderer/tr_deform.cpp @@ -105,7 +105,7 @@ static void R_AutospriteDeform( drawSurf_t *surf ) { newTri = (srfTriangles_t *)R_ClearedFrameAlloc( sizeof( *newTri ) ); newTri->numVerts = tri->numVerts; newTri->numIndexes = tri->numIndexes; - newTri->indexes = (glIndex_t *)R_FrameAlloc( newTri->numIndexes * sizeof( newTri->indexes[0] ) ); + newTri->indexes = (triIndex_t *)R_FrameAlloc( newTri->numIndexes * sizeof( newTri->indexes[0] ) ); idDrawVert *ac = (idDrawVert *)_alloca16( newTri->numVerts * sizeof( idDrawVert ) ); @@ -192,7 +192,7 @@ static int edgeVerts[6][2] = { srfTriangles_t *newTri = (srfTriangles_t *)R_ClearedFrameAlloc( sizeof( *newTri ) ); newTri->numVerts = tri->numVerts; newTri->numIndexes = tri->numIndexes; - newTri->indexes = (glIndex_t *)R_FrameAlloc( newTri->numIndexes * sizeof( newTri->indexes[0] ) ); + newTri->indexes = (triIndex_t *)R_FrameAlloc( newTri->numIndexes * sizeof( newTri->indexes[0] ) ); memcpy( newTri->indexes, tri->indexes, newTri->numIndexes * sizeof( newTri->indexes[0] ) ); idDrawVert *ac = (idDrawVert *)_alloca16( newTri->numVerts * sizeof( idDrawVert ) ); @@ -283,7 +283,7 @@ R_WindingFromTriangles ===================== */ #define MAX_TRI_WINDING_INDEXES 16 -int R_WindingFromTriangles( const srfTriangles_t *tri, glIndex_t indexes[MAX_TRI_WINDING_INDEXES] ) { +int R_WindingFromTriangles( const srfTriangles_t *tri, triIndex_t indexes[MAX_TRI_WINDING_INDEXES] ) { int i, j, k, l; indexes[0] = tri->indexes[0]; @@ -389,7 +389,7 @@ static void R_FlareDeform( drawSurf_t *surf ) { newTri = (srfTriangles_t *)R_ClearedFrameAlloc( sizeof( *newTri ) ); newTri->numVerts = 4; newTri->numIndexes = 2*3; - newTri->indexes = (glIndex_t *)R_FrameAlloc( newTri->numIndexes * sizeof( newTri->indexes[0] ) ); + newTri->indexes = (triIndex_t *)R_FrameAlloc( newTri->numIndexes * sizeof( newTri->indexes[0] ) ); idDrawVert *ac = (idDrawVert *)_alloca16( newTri->numVerts * sizeof( idDrawVert ) ); @@ -431,7 +431,7 @@ static void R_FlareDeform( drawSurf_t *surf ) { float spread = surf->shaderRegisters[ surf->material->GetDeformRegister(0) ] * r_flareSize.GetFloat(); idVec3 edgeDir[4][3]; - glIndex_t indexes[MAX_TRI_WINDING_INDEXES]; + triIndex_t indexes[MAX_TRI_WINDING_INDEXES]; int numIndexes = R_WindingFromTriangles( tri, indexes ); surf->material = declManager->FindMaterial( "textures/smf/anamorphicFlare" ); @@ -496,7 +496,7 @@ static void R_FlareDeform( drawSurf_t *surf ) { } // setup indexes - static glIndex_t triIndexes[2*3] = { + static triIndex_t triIndexes[2*3] = { 0,1,2, 0,2,3 }; @@ -527,7 +527,7 @@ static void R_FlareDeform( drawSurf_t *surf ) { newTri = (srfTriangles_t *)R_ClearedFrameAlloc( sizeof( *newTri ) ); newTri->numVerts = 16; newTri->numIndexes = 18*3; - newTri->indexes = (glIndex_t *)R_FrameAlloc( newTri->numIndexes * sizeof( newTri->indexes[0] ) ); + newTri->indexes = (triIndex_t *)R_FrameAlloc( newTri->numIndexes * sizeof( newTri->indexes[0] ) ); idDrawVert *ac = (idDrawVert *)_alloca16( newTri->numVerts * sizeof( idDrawVert ) ); @@ -572,7 +572,7 @@ static void R_FlareDeform( drawSurf_t *surf ) { float spread = surf->shaderRegisters[ surf->material->GetDeformRegister(0) ] * r_flareSize.GetFloat(); idVec3 edgeDir[4][3]; - glIndex_t indexes[MAX_TRI_WINDING_INDEXES]; + triIndex_t indexes[MAX_TRI_WINDING_INDEXES]; int numIndexes = R_WindingFromTriangles( tri, indexes ); @@ -675,14 +675,14 @@ static void R_FlareDeform( drawSurf_t *surf ) { } #if 1 - static glIndex_t triIndexes[18*3] = { + static triIndex_t triIndexes[18*3] = { 0,4,5, 0,5,6, 0,6,7, 0,7,1, 1,7,8, 1,8,9, 15,4,0, 15,0,3, 3,0,1, 3,1,2, 2,1,9, 2,9,10, 14,15,3, 14,3,13, 13,3,2, 13,2,12, 12,2,11, 11,2,10 }; #else newTri->numIndexes = 12; - static glIndex_t triIndexes[4*3] = { + static triIndex_t triIndexes[4*3] = { 0,1,2, 0,2,3, 0,4,5,0,5,6 }; #endif @@ -916,7 +916,7 @@ static void R_EyeballDeform( drawSurf_t *surf ) { memset( newTri, 0, sizeof( *newTri ) ); newTri->numVerts = tri->numVerts; newTri->numIndexes = tri->numIndexes; - newTri->indexes = (glIndex_t *)R_FrameAlloc( tri->numIndexes * sizeof( newTri->indexes[0] ) ); + newTri->indexes = (triIndex_t *)R_FrameAlloc( tri->numIndexes * sizeof( newTri->indexes[0] ) ); idDrawVert *ac = (idDrawVert *)_alloca16( tri->numVerts * sizeof( idDrawVert ) ); newTri->numIndexes = 0; @@ -1092,7 +1092,7 @@ static void R_ParticleDeform( drawSurf_t *surf, bool useArea ) { tri->numVerts = 4 * count; tri->numIndexes = 6 * count; tri->verts = (idDrawVert *)R_FrameAlloc( tri->numVerts * sizeof( tri->verts[0] ) ); - tri->indexes = (glIndex_t *)R_FrameAlloc( tri->numIndexes * sizeof( tri->indexes[0] ) ); + tri->indexes = (triIndex_t *)R_FrameAlloc( tri->numIndexes * sizeof( tri->indexes[0] ) ); // just always draw the particles tri->bounds = stage->bounds; diff --git a/neo/renderer/tr_local.h b/neo/renderer/tr_local.h index a843ec903..12feeae4b 100644 --- a/neo/renderer/tr_local.h +++ b/neo/renderer/tr_local.h @@ -710,12 +710,12 @@ class idRenderSystemLocal : public idRenderSystem { virtual void SetColor( const idVec4 &rgba ); virtual void SetColor4( float r, float g, float b, float a ); virtual idVec4 GetColor( void ) const; - virtual void DrawStretchPic ( const idDrawVert *verts, const glIndex_t *indexes, int vertCount, int indexCount, const idMaterial *material, + virtual void DrawStretchPic ( const idDrawVert *verts, const triIndex_t *indexes, int vertCount, int indexCount, const idMaterial *material, bool clip = true, float x = 0.0f, float y = 0.0f, float w = 640.0f, float h = 0.0f ); virtual void DrawStretchPic ( float x, float y, float w, float h, float s1, float t1, float s2, float t2, const idMaterial *material ); virtual void DrawStretchTri ( idVec2 p1, idVec2 p2, idVec2 p3, idVec2 t1, idVec2 t2, idVec2 t3, const idMaterial *material ); - virtual idDrawVert * AllocTris( int numVerts, const glIndex_t * indexes, int numIndexes, const idMaterial *material ); + virtual idDrawVert * AllocTris( int numVerts, const triIndex_t * indexes, int numIndexes, const idMaterial *material ); virtual void GlobalToNormalizedDeviceCoordinates( const idVec3 &global, idVec3 &ndc ); virtual void GetGLSettings( int& width, int& height ); virtual void PrintMemInfo( MemInfo_t *mi ); @@ -1460,7 +1460,7 @@ dmap time optimization of shadow volumes, called from R_CreateShadowVolume typedef struct { idVec3 *verts; // includes both front and back projections, caller should free int numVerts; - glIndex_t *indexes; // caller should free + triIndex_t *indexes; // caller should free // indexes must be sorted frontCap, rearCap, silPlanes so the caps can be removed // when the viewer is in a position that they don't need to see them @@ -1470,7 +1470,7 @@ typedef struct { int totalIndexes; } optimizedShadow_t; -optimizedShadow_t SuperOptimizeOccluders( idVec4 *verts, glIndex_t *indexes, int numIndexes, +optimizedShadow_t SuperOptimizeOccluders( idVec4 *verts, triIndex_t *indexes, int numIndexes, idPlane projectionPlane, idVec3 projectionOrigin ); void CleanupOptimizedShadowTris( srfTriangles_t *tri ); @@ -1540,8 +1540,8 @@ typedef struct deformInfo_s { // NB: Better pointer alignment, adds; numDominant int numMirroredVerts; int numDominantTris; int numHiddenTris; // HINTS - glIndex_t* indexes; - glIndex_t* silIndexes; + triIndex_t* indexes; + triIndex_t* silIndexes; silEdge_t* silEdges; int* dupVerts; int* mirroredVerts; @@ -1560,9 +1560,9 @@ typedef struct deformInfo_s { int * mirroredVerts; int numIndexes; - glIndex_t * indexes; + triIndex_t * indexes; - glIndex_t * silIndexes; + triIndex_t * silIndexes; int numDupVerts; int * dupVerts; @@ -1683,7 +1683,7 @@ TR_ORDERINDEXES ============================================================= */ -void R_OrderIndexes( int numIndexes, glIndex_t *indexes ); +void R_OrderIndexes( int numIndexes, triIndex_t *indexes ); /* ============================================================= diff --git a/neo/renderer/tr_orderIndexes.cpp b/neo/renderer/tr_orderIndexes.cpp index 0055e3d54..3ab98d12f 100644 --- a/neo/renderer/tr_orderIndexes.cpp +++ b/neo/renderer/tr_orderIndexes.cpp @@ -39,7 +39,7 @@ R_MeshCost #if 0 #define CACHE_SIZE 24 #define STALL_SIZE 8 -int R_MeshCost( int numIndexes, glIndex_t *indexes ) { +int R_MeshCost( int numIndexes, triIndex_t *indexes ) { int inCache[CACHE_SIZE]; int i, j, v; int c_stalls; @@ -88,11 +88,11 @@ Reorganizes the indexes so they will take best advantage of the internal GPU vertex caches ==================== */ -void R_OrderIndexes( int numIndexes, glIndex_t *indexes ) { +void R_OrderIndexes( int numIndexes, triIndex_t *indexes ) { bool *triangleUsed; int numTris; - glIndex_t *oldIndexes; - glIndex_t *base; + triIndex_t *oldIndexes; + triIndex_t *base; int numOldIndexes; int tri; int i; @@ -107,7 +107,7 @@ void R_OrderIndexes( int numIndexes, glIndex_t *indexes ) { } // save off the original indexes - oldIndexes = (glIndex_t *)_alloca( numIndexes * sizeof( *oldIndexes ) ); + oldIndexes = (triIndex_t *)_alloca( numIndexes * sizeof( *oldIndexes ) ); memcpy( oldIndexes, indexes, numIndexes * sizeof( *oldIndexes ) ); numOldIndexes = numIndexes; diff --git a/neo/renderer/tr_stencilshadow.cpp b/neo/renderer/tr_stencilshadow.cpp index 2eb428cdd..2da073af8 100644 --- a/neo/renderer/tr_stencilshadow.cpp +++ b/neo/renderer/tr_stencilshadow.cpp @@ -143,7 +143,7 @@ static int *remap; #define MAX_SHADOW_INDEXES 0x18000 #define MAX_SHADOW_VERTS 0x18000 static int numShadowIndexes; -static glIndex_t shadowIndexes[MAX_SHADOW_INDEXES]; +static triIndex_t shadowIndexes[MAX_SHADOW_INDEXES]; static int numShadowVerts; static idVec4 shadowVerts[MAX_SHADOW_VERTS]; static bool overflowed; diff --git a/neo/renderer/tr_trisurf.cpp b/neo/renderer/tr_trisurf.cpp index 29c0a7012..a247fa76f 100644 --- a/neo/renderer/tr_trisurf.cpp +++ b/neo/renderer/tr_trisurf.cpp @@ -129,20 +129,20 @@ static idBlockAlloc srfTrianglesAllocator; #ifdef USE_TRI_DATA_ALLOCATOR static idDynamicBlockAlloc triVertexAllocator; -static idDynamicBlockAlloc triIndexAllocator; +static idDynamicBlockAlloc triIndexAllocator; static idDynamicBlockAlloc triShadowVertexAllocator; static idDynamicBlockAlloc triPlaneAllocator; -static idDynamicBlockAlloc triSilIndexAllocator; +static idDynamicBlockAlloc triSilIndexAllocator; static idDynamicBlockAlloc triSilEdgeAllocator; static idDynamicBlockAlloc triDominantTrisAllocator; static idDynamicBlockAlloc triMirroredVertAllocator; static idDynamicBlockAlloc triDupVertAllocator; #else static idDynamicAlloc triVertexAllocator; -static idDynamicAlloc triIndexAllocator; +static idDynamicAlloc triIndexAllocator; static idDynamicAlloc triShadowVertexAllocator; static idDynamicAlloc triPlaneAllocator; -static idDynamicAlloc triSilIndexAllocator; +static idDynamicAlloc triSilIndexAllocator; static idDynamicAlloc triSilEdgeAllocator; static idDynamicAlloc triDominantTrisAllocator; static idDynamicAlloc triMirroredVertAllocator; @@ -2172,7 +2172,7 @@ void R_ReverseTriangles( srfTriangles_t *tri ) { // flip the index order to make them back sided for ( i = 0 ; i < tri->numIndexes ; i+= 3 ) { - glIndex_t temp; + triIndex_t temp; temp = tri->indexes[ i + 0 ]; tri->indexes[ i + 0 ] = tri->indexes[ i + 1 ]; diff --git a/neo/renderer/tr_turboshadow.cpp b/neo/renderer/tr_turboshadow.cpp index f73bfbd26..79aef4372 100644 --- a/neo/renderer/tr_turboshadow.cpp +++ b/neo/renderer/tr_turboshadow.cpp @@ -83,7 +83,7 @@ srfTriangles_t *R_CreateVertexProgramTurboShadowVolume( const idRenderEntityLoca int i, j; srfTriangles_t *newTri; silEdge_t *sil; - const glIndex_t *indexes; + const triIndex_t *indexes; const byte *facing; R_CalcInteractionFacing( ent, tri, light, cullInfo ); @@ -137,11 +137,11 @@ srfTriangles_t *R_CreateVertexProgramTurboShadowVolume( const idRenderEntityLoca // alloc the max possible size #ifdef USE_TRI_DATA_ALLOCATOR R_AllocStaticTriSurfIndexes( newTri, ( numShadowingFaces + tri->numSilEdges ) * 6 ); - glIndex_t *tempIndexes = newTri->indexes; - glIndex_t *shadowIndexes = newTri->indexes; + triIndex_t *tempIndexes = newTri->indexes; + triIndex_t *shadowIndexes = newTri->indexes; #else - glIndex_t *tempIndexes = (glIndex_t *)_alloca16( tri->numSilEdges * 6 * sizeof( tempIndexes[0] ) ); - glIndex_t *shadowIndexes = tempIndexes; + triIndex_t *tempIndexes = (triIndex_t *)_alloca16( tri->numSilEdges * 6 * sizeof( tempIndexes[0] ) ); + triIndex_t *shadowIndexes = tempIndexes; #endif // create new triangles along sil planes @@ -226,7 +226,7 @@ srfTriangles_t *R_CreateTurboShadowVolume( const idRenderEntityLocal *ent, idVec3 localLightOrigin; srfTriangles_t *newTri; silEdge_t *sil; - const glIndex_t *indexes; + const triIndex_t *indexes; const byte *facing; R_CalcInteractionFacing( ent, tri, light, cullInfo ); @@ -313,11 +313,11 @@ srfTriangles_t *R_CreateTurboShadowVolume( const idRenderEntityLocal *ent, // alloc the max possible size #ifdef USE_TRI_DATA_ALLOCATOR R_AllocStaticTriSurfIndexes( newTri, ( numShadowingFaces + tri->numSilEdges ) * 6 ); - glIndex_t *tempIndexes = newTri->indexes; - glIndex_t *shadowIndexes = newTri->indexes; + triIndex_t *tempIndexes = newTri->indexes; + triIndex_t *shadowIndexes = newTri->indexes; #else - glIndex_t *tempIndexes = (glIndex_t *)_alloca16( tri->numSilEdges * 6 * sizeof( tempIndexes[0] ) ); - glIndex_t *shadowIndexes = tempIndexes; + triIndex_t *tempIndexes = (triIndex_t *)_alloca16( tri->numSilEdges * 6 * sizeof( tempIndexes[0] ) ); + triIndex_t *shadowIndexes = tempIndexes; #endif // create new triangles along sil planes diff --git a/neo/sys/platform.h b/neo/sys/platform.h index c0bd6d9e4..daafc9d54 100644 --- a/neo/sys/platform.h +++ b/neo/sys/platform.h @@ -29,308 +29,6 @@ If you have questions concerning this license or the applicable additional terms #ifndef __PLATFORM__ #define __PLATFORM__ -// NOTE: By default Win32 uses a 1MB stack. Doom3 1.3.1 uses 4MB (probably set after compiling with EDITBIN /STACK -// dhewm3 now uses a 8MB stack, set with a linker flag in CMakeLists.txt (/STACK:8388608 for MSVC, -Wl,--stack,8388608 for mingw) -// Linux has a 8MB stack by default, and so does macOS, at least for the main thread -// anyway, a 2MB limit alloca should be safe even when using it multiple times in the same function -#define ID_MAX_ALLOCA_SIZE 2097152 // 2MB - -/* -=============================================================================== - - CPU Arch detection. - -=============================================================================== -*/ - -// Setting D3_ARCH for VisualC++ from CMake doesn't work when using VS integrated CMake -// so set it in code instead -#ifdef _MSC_VER - #ifdef D3_ARCH - #undef D3_ARCH - #endif // D3_ARCH - - #ifdef _M_X64 - // this matches AMD64 and ARM64EC (but not regular ARM64), but they're supposed to be binary-compatible somehow, so whatever - #define D3_ARCH "x86_64" - #elif defined( _M_ARM64 ) - #define D3_ARCH "arm64" - #elif defined( _M_ARM ) - #define D3_ARCH "arm" - #elif defined( _M_IX86 ) - #define D3_ARCH "x86" - #else - // if you're not targeting one of the aforementioned architectures, - // check https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros - // to find out how to detect yours and add it here - and please send a patch :) - #error "Unknown CPU architecture!" - // (for a quick and dirty solution, comment out the previous line, but keep in mind - // that savegames may not be compatible with other builds of dhewm3) - #define D3_ARCH "UNKNOWN" - #endif // _M_X64 etc -#endif // _MSC_VER - -/* -=============================================================================== - - Non-portable system services. - -=============================================================================== -*/ - -// Win32 -#if defined( WIN32 ) || defined( _WIN32 ) - #ifdef __MINGW32__ - #undef _alloca // in mingw _alloca is a #define - // NOTE: Do *not* use __builtin_alloca_with_align(), unlike regular alloca it frees at end of block instead of end of function ! - #define _alloca16( x ) ( (void *) ( (assert((x) - #define VERIFY_FORMAT_STRING [SA_FormatString(Style="printf")] - // DG: alternative for GCC with attribute (NOOP for MSVC) - #define ID_STATIC_ATTRIBUTE_PRINTF(STRIDX, FIRSTARGIDX) - #endif - -#else - #define VERIFY_FORMAT_STRING - // STRIDX: index of format string in function arguments (first arg == 1) - // FIRSTARGIDX: index of first argument for the format string - #define ID_STATIC_ATTRIBUTE_PRINTF(STRIDX, FIRSTARGIDX) __attribute__ ((format (printf, STRIDX, FIRSTARGIDX))) - // DG end -#endif // _MSC_VER - -// This needs to be handled so shift by 1 -#define ID_INSTANCE_ATTRIBUTE_PRINTF(STRIDX, FIRSTARGIDX) ID_STATIC_ATTRIBUTE_PRINTF((STRIDX+1),(FIRSTARGIDX+1)) - - -// We need to inform the compiler that Error() and FatalError() will -// never return, so any conditions that leeds to them being called are -// guaranteed to be false in the following code - -#if defined( _MSC_VER ) - #define NO_RETURN __declspec(noreturn) -#elif defined( __GNUC__ ) - #define NO_RETURN __attribute__((noreturn)) -#else - #define NO_RETURN -#endif - -#if !defined(_MSC_VER) - // MSVC does not provide this C99 header - #include -#endif -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -//#define FLT_EPSILON 1.19209290E-07F -#include -#include -#include -#include -#include - -#ifdef _WIN32 - #define WIN32_LEAN_AND_MEAN - #include - #undef FindText // stupid namespace poluting Microsoft monkeys -#endif - -// Apple legacy -#ifdef __APPLE__ - #include - #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED - #if __MAC_OS_X_VERSION_MIN_REQUIRED == 1040 - #define OSX_TIGER - #elif __MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - #define OSX_LEOPARD - #endif - #endif -#endif - -#define ID_TIME_T time_t - -typedef unsigned char byte; // 8 bits -typedef unsigned short word; // 16 bits -typedef unsigned int dword; // 32 bits -typedef unsigned int uint; -typedef unsigned long ulong; - -typedef int qhandle_t; - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#ifndef BIT -#define BIT( num ) ( 1 << ( num ) ) -#endif - -#define MAX_STRING_CHARS 1024 // max length of a string - -// maximum world size -#define MAX_WORLD_COORD ( 128 * 1024 ) -#define MIN_WORLD_COORD ( -128 * 1024 ) -#define MAX_WORLD_SIZE ( MAX_WORLD_COORD - MIN_WORLD_COORD ) - -#ifndef BIT -#define BIT( num ) BITT< num >::VALUE -#endif - -template< unsigned int B > -class BITT { -public: - typedef enum bitValue_e { - VALUE = 1 << B, - } bitValue_t; -}; #endif diff --git a/neo/tools/compilers/dmap/shadowopt3.cpp b/neo/tools/compilers/dmap/shadowopt3.cpp index 453819051..eb72cea23 100644 --- a/neo/tools/compilers/dmap/shadowopt3.cpp +++ b/neo/tools/compilers/dmap/shadowopt3.cpp @@ -98,7 +98,7 @@ for each triangle typedef struct { idVec3 v[3]; idVec3 edge[3]; // positive side is inside the triangle - glIndex_t index[3]; + triIndex_t index[3]; idPlane plane; // positive side is forward for the triangle, which is away from the light int planeNum; // from original triangle, not calculated from the clipped verts } shadowTri_t; @@ -109,7 +109,7 @@ static shadowTri_t outputTris[MAX_SHADOW_TRIS]; static int numOutputTris; typedef struct shadowOptEdge_s { - glIndex_t index[2]; + triIndex_t index[2]; struct shadowOptEdge_s *nextEdge; } shadowOptEdge_t; @@ -309,7 +309,7 @@ Generates outputTris by clipping all the triangles against each other, retaining only those closest to the projectionOrigin ==================== */ -static void ClipOccluders( idVec4 *verts, glIndex_t *indexes, int numIndexes, +static void ClipOccluders( idVec4 *verts, triIndex_t *indexes, int numIndexes, idVec3 projectionOrigin ) { int numTris = numIndexes / 3; int i; @@ -1006,7 +1006,7 @@ verts have been culled against individual frustums of point lights ==================== */ -optimizedShadow_t SuperOptimizeOccluders( idVec4 *verts, glIndex_t *indexes, int numIndexes, +optimizedShadow_t SuperOptimizeOccluders( idVec4 *verts, triIndex_t *indexes, int numIndexes, idPlane projectionPlane, idVec3 projectionOrigin ) { memset( &ret, 0, sizeof( ret ) ); @@ -1048,7 +1048,7 @@ optimizedShadow_t SuperOptimizeOccluders( idVec4 *verts, glIndex_t *indexes, int maxRetIndexes = ret.numFrontCapIndexes + ret.numRearCapIndexes + ret.numSilPlaneIndexes; - ret.indexes = (glIndex_t *)Mem_Alloc( maxRetIndexes * sizeof( ret.indexes[0] ) ); + ret.indexes = (triIndex_t *)Mem_Alloc( maxRetIndexes * sizeof( ret.indexes[0] ) ); for ( int i = 0 ; i < numOutputTris ; i++ ) { // flip the indexes so the surface triangle faces outside the shadow volume ret.indexes[i*3+0] = outputTris[i].index[2]; @@ -1142,7 +1142,7 @@ void CleanupOptimizedShadowTris( srfTriangles_t *tri ) { uniqued = (idVec3 *)_alloca( sizeof( *uniqued ) * maxUniqued ); numUniqued = 0; - glIndex_t *remap = (glIndex_t *)_alloca( sizeof( *remap ) * tri->numVerts ); + triIndex_t *remap = (triIndex_t *)_alloca( sizeof( *remap ) * tri->numVerts ); for ( i = 0 ; i < tri->numIndexes ; i++ ) { if ( tri->indexes[i] > tri->numVerts || tri->indexes[i] < 0 ) { diff --git a/neo/tools/compilers/renderbump/renderbump.cpp b/neo/tools/compilers/renderbump/renderbump.cpp index 5b810ecec..96d001358 100644 --- a/neo/tools/compilers/renderbump/renderbump.cpp +++ b/neo/tools/compilers/renderbump/renderbump.cpp @@ -883,7 +883,7 @@ static idRenderModel *CombineModelSurfaces( idRenderModel *model ) { newTri->bounds.Clear(); idDrawVert *verts = newTri->verts; - glIndex_t *indexes = newTri->indexes; + triIndex_t *indexes = newTri->indexes; numIndexes = 0; numVerts = 0; for ( i = 0 ; i < model->NumSurfaces() ; i++ ) { diff --git a/neo/tools/guied/GEItemScriptsDlg.cpp b/neo/tools/guied/GEItemScriptsDlg.cpp index 03a133dc5..ab2a23cc6 100644 --- a/neo/tools/guied/GEItemScriptsDlg.cpp +++ b/neo/tools/guied/GEItemScriptsDlg.cpp @@ -295,7 +295,7 @@ bool GEItescriptsDlg_Apply ( HWND hwnd ) } catch ( idException &e ) { - MessageBox ( hwnd, e.error, "Script Error", MB_OK|MB_ICONERROR); + MessageBox ( hwnd, e.GetError(), "Script Error", MB_OK|MB_ICONERROR); return false; } diff --git a/neo/tools/guied/GEWorkspaceFile.cpp b/neo/tools/guied/GEWorkspaceFile.cpp index 6aa0f569f..af2b7cee4 100644 --- a/neo/tools/guied/GEWorkspaceFile.cpp +++ b/neo/tools/guied/GEWorkspaceFile.cpp @@ -339,7 +339,7 @@ bool rvGEWorkspace::LoadFile ( const char* filename, idStr* error ) result = false; if ( error ) { - *error = e.error; + *error = e.GetError(); } return false; } diff --git a/neo/tools/radiant/CamWnd.cpp b/neo/tools/radiant/CamWnd.cpp index 43201e3b5..e5e22beb8 100644 --- a/neo/tools/radiant/CamWnd.cpp +++ b/neo/tools/radiant/CamWnd.cpp @@ -1570,7 +1570,7 @@ int idEditorBrushoTris(idEditorBrush *brush, idTriList *tris, idMatList *mats, b R_ResizeStaticTriSurfIndexes( existingTri, newNumIndexes ); idDrawVert* newVerts = existingTri->verts; - glIndex_t* newIndexes = existingTri->indexes; + triIndex_t* newIndexes = existingTri->indexes; // Copy new vertices for ( int k = 0; k < tri->numVerts; k++ ) { diff --git a/neo/tools/radiant/RadiantEditor.cpp b/neo/tools/radiant/RadiantEditor.cpp index 8a88f0c26..2f16ed1b1 100644 --- a/neo/tools/radiant/RadiantEditor.cpp +++ b/neo/tools/radiant/RadiantEditor.cpp @@ -389,7 +389,7 @@ void RadiantRun( void ) { } } catch( idException &ex ) { - ::MessageBox( NULL, ex.error, "Exception error", MB_OK ); + ::MessageBox( NULL, ex.GetError(), "Exception error", MB_OK ); RadiantShutdown(); } }