Initial commit

This commit is contained in:
Brian Harris
2012-11-26 12:58:24 -06:00
parent a5214f79ef
commit 5016f605b8
1115 changed files with 587266 additions and 0 deletions

View File

@@ -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 <http://www.gnu.org/licenses/>.
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.
===========================================================================
*/
MEM_TAG( UNSET ) // This should never be used
MEM_TAG( STATIC_EXE ) // The static exe, generally how much memory we are using before our main() function ever runs
MEM_TAG( DEBUG ) // Crap we don't care about, because it won't be in a retail build
MEM_TAG( NEW ) // Crap allocated with new which hasn't been given an explicit tag
MEM_TAG( BLOCKALLOC ) // Crap allocated with idBlockAlloc which hasn't been given an explicit tag
MEM_TAG( PHYSICAL )
MEM_TAG( TRI_VERTS )
MEM_TAG( TRI_INDEXES )
MEM_TAG( TRI_SHADOW )
MEM_TAG( TRI_PLANES )
MEM_TAG( TRI_SIL_INDEXES )
MEM_TAG( TRI_SIL_EDGE )
MEM_TAG( TRI_DOMINANT_TRIS )
MEM_TAG( TRI_MIR_VERT )
MEM_TAG( TRI_DUP_VERT )
MEM_TAG( SRFTRIS )
MEM_TAG( TEMP ) // Temp data which should be automatically freed at the end of the function
MEM_TAG( PAGE )
MEM_TAG( DEFRAG_BLOCK )
MEM_TAG( MATH )
MEM_TAG( MD5_WEIGHT )
MEM_TAG( MD5_BASE )
MEM_TAG( MD5_ANIM )
MEM_TAG( MD5_INDEX )
MEM_TAG( JOINTMAT )
MEM_TAG( DECAL )
MEM_TAG( CULLBITS )
MEM_TAG( TEXCOORDS )
MEM_TAG( VERTEXREMAP )
MEM_TAG( JOINTBUFFER )
MEM_TAG( IMAGE )
MEM_TAG( DXBUFFER )
MEM_TAG( AUDIO )
MEM_TAG( FUNC_CALLBACK )
MEM_TAG( SAVEGAMES )
MEM_TAG( IDFILE )
MEM_TAG( NETWORKING )
MEM_TAG( SWF )
MEM_TAG( STEAM )
MEM_TAG( IDLIB )
MEM_TAG( IDLIB_LIST )
MEM_TAG( IDLIB_LIST_IMAGE )
MEM_TAG( IDLIB_LIST_SURFACE )
MEM_TAG( IDLIB_LIST_PHYSICS )
MEM_TAG( IDLIB_LIST_DECL )
MEM_TAG( IDLIB_LIST_CMD )
MEM_TAG( IDLIB_LIST_TRIANGLES )
MEM_TAG( IDLIB_LIST_MATERIAL )
MEM_TAG( IDLIB_LIST_SOUND )
MEM_TAG( IDLIB_LIST_SNAPSHOT )
MEM_TAG( IDLIB_LIST_MENU )
MEM_TAG( IDLIB_LIST_MENUWIDGET )
MEM_TAG( IDLIB_LIST_PLAYER )
MEM_TAG( IDLIB_LIST_MAP )
MEM_TAG( IDLIB_HASH )
MEM_TAG( IDLIB_STRING )
MEM_TAG( IDLIB_SURFACE )
MEM_TAG( IDLIB_WINDING )
MEM_TAG( IDLIB_LEXER )
MEM_TAG( IDLIB_PARSER )
MEM_TAG( AF )
MEM_TAG( COLLISION )
MEM_TAG( COLLISION_QUERY )
MEM_TAG( DECLTEXT )
MEM_TAG( RSX )
MEM_TAG( CVAR )
MEM_TAG( CRAP ) // Crap allocated with new which hasn't been given an explicit tag
MEM_TAG( CINEMATIC )
MEM_TAG( FONT )
MEM_TAG( MATERIAL )
MEM_TAG( MODEL )
MEM_TAG( RENDER )
MEM_TAG( RENDER_TOOLS )
MEM_TAG( RENDER_WINDING )
MEM_TAG( RENDER_STATIC )
MEM_TAG( RENDER_ENTITY )
MEM_TAG( RENDER_LIGHT )
MEM_TAG( RENDER_INTERACTION )
MEM_TAG( SURFACE )
MEM_TAG( LIGHT )
MEM_TAG( AI )
MEM_TAG( SCRIPT )
MEM_TAG( EVENTS )
MEM_TAG( JPG )
MEM_TAG( AAS )
MEM_TAG( STRING )
MEM_TAG( THREAD )
MEM_TAG( DECL )
MEM_TAG( SYSTEM )
MEM_TAG( PSN )
MEM_TAG( OLD_UI )
MEM_TAG( ANIM )
MEM_TAG( ANIMWEB )
MEM_TAG( PHYSICS )
MEM_TAG( PARTICLE )
MEM_TAG( ENTITY )
MEM_TAG( GAME )
MEM_TAG( FX )
MEM_TAG( PVS )
MEM_TAG( IDCLASS )
MEM_TAG( ZIP )
MEM_TAG( JOBLIST )
MEM_TAG( AMPLITUDE )
MEM_TAG( RESOURCE )
MEM_TAG( ACHIEVEMENT )
MEM_TAG( TARGET )
MEM_TAG( BINK )
MEM_TAG( PROJECTILE )
MEM_TAG( MOVER )
MEM_TAG( ACTOR )
MEM_TAG( PHYSICS_CLIP )
MEM_TAG( PHYSICS_CLIP_MOVER )
MEM_TAG( PHYSICS_CLIP_AF )
MEM_TAG( PHYSICS_CLIP_BRITTLE )
MEM_TAG( PHYSICS_CLIP_ENTITY )
MEM_TAG( PHYSICS_BRITTLE )
MEM_TAG( PHYSICS_AF )
MEM_TAG( RENDERPROG )
#undef MEM_TAG

View File

@@ -0,0 +1,90 @@
/*
===========================================================================
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 <http://www.gnu.org/licenses/>.
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.
===========================================================================
*/
#pragma hdrstop
#include "../precompiled.h"
/*
================================================================================================
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 );
if ( IsDebuggerPresent() || com_assertOutOfDebugger.GetBool() ) {
__debugbreak();
}
if ( skipThisAssertion ) {
skippedAssertion_t * skipped = skippedAssertions.Alloc();
skipped->file = file;
skipped->line = line;
}
return true;
}

138
neo/idlib/sys/sys_assert.h Normal file
View File

@@ -0,0 +1,138 @@
/*
===========================================================================
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 <http://www.gnu.org/licenses/>.
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()
template<bool> struct compile_time_assert_failed;
template<> struct compile_time_assert_failed<true> {};
template<int x> 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<sizeof(compile_time_assert_failed<(bool)(x)>)> compile_time_assert_join(compile_time_assert_typedef_, __LINE__)
#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__

View File

@@ -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 <http://www.gnu.org/licenses/>.
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.
===============================================================================
*/

154
neo/idlib/sys/sys_defines.h Normal file
View File

@@ -0,0 +1,154 @@
/*
===========================================================================
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 <http://www.gnu.org/licenses/>.
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
/*
================================================================================================
PC Windows
================================================================================================
*/
#define CPUSTRING "x86"
#define BUILD_STRING "win-" CPUSTRING
#define BUILD_OS_ID 0
#define ALIGN16( x ) __declspec(align(16)) x
#define ALIGNTYPE16 __declspec(align(16))
#define ALIGNTYPE128 __declspec(align(128))
#define FORMAT_PRINTF( x )
#define PATHSEPARATOR_STR "\\"
#define PATHSEPARATOR_CHAR '\\'
#define NEWLINE "\r\n"
#define ID_INLINE inline
#define ID_FORCE_INLINE __forceinline
// lint complains that extern used with definition is a hazard, but it
// has the benefit (?) of making it illegal to take the address of the function
#ifdef _lint
#define ID_INLINE_EXTERN inline
#define ID_FORCE_INLINE_EXTERN __forceinline
#else
#define ID_INLINE_EXTERN extern inline
#define ID_FORCE_INLINE_EXTERN extern __forceinline
#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
/*
================================================================================================
Defines and macros usable in all code
================================================================================================
*/
#define ALIGN( x, a ) ( ( ( x ) + ((a)-1) ) & ~((a)-1) )
#define _alloca16( x ) ((void *)ALIGN( (UINT_PTR)_alloca( ALIGN( x, 16 ) + 16 ), 16 ) )
#define _alloca128( x ) ((void *)ALIGN( (UINT_PTR)_alloca( ALIGN( x, 128 ) + 128 ), 128 ) )
#define likely( x ) ( x )
#define unlikely( x ) ( x )
// A macro to disallow the copy constructor and operator= functions
// NOTE: The macro contains "private:" so all members defined after it will be private until
// public: or protected: is specified.
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
private: \
TypeName(const TypeName&); \
void operator=(const TypeName&);
/*
================================================================================================
Setup for /analyze code analysis, which we currently only have on the 360, but
we may get later for win32 if we buy the higher end vc++ licenses.
Even with VS2010 ultmate, /analyze only works for x86, not x64
Also note the __analysis_assume macro in sys_assert.h relates to code analysis.
This header should be included even by job code that doesn't reference the
bulk of the codebase, so it is the best place for analyze pragmas.
================================================================================================
*/
// disable some /analyze warnings here
#pragma warning( disable: 6255 ) // warning C6255: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead. (Note: _malloca requires _freea.)
#pragma warning( disable: 6262 ) // warning C6262: Function uses '36924' bytes of stack: exceeds /analyze:stacksize'32768'. Consider moving some data to heap
#pragma warning( disable: 6326 ) // warning C6326: Potential comparison of a constant with another constant
#pragma warning( disable: 6031 ) // warning C6031: Return value ignored
// this warning fires whenever you have two calls to new in a function, but we assume new never fails, so it is not relevant for us
#pragma warning( disable: 6211 ) // warning C6211: Leaking memory 'staticModel' due to an exception. Consider using a local catch block to clean up memory
// we want to fix all these at some point...
#pragma warning( disable: 6246 ) // warning C6246: Local declaration of 'es' hides declaration of the same name in outer scope. For additional information, see previous declaration at line '969' of 'w:\tech5\rage\game\ai\fsm\fsm_combat.cpp': Lines: 969
#pragma warning( disable: 6244 ) // warning C6244: Local declaration of 'viewList' hides previous declaration at line '67' of 'w:\tech5\engine\renderer\rendertools.cpp'
// win32 needs this, but 360 doesn't
#pragma warning( disable: 6540 ) // warning C6540: The use of attribute annotations on this function will invalidate all of its existing __declspec annotations [D:\tech5\engine\engine-10.vcxproj]
// checking format strings catches a LOT of errors
#include <CodeAnalysis\SourceAnnotations.h>
#define VERIFY_FORMAT_STRING [SA_FormatString(Style="printf")]
// 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
#define NO_RETURN __declspec(noreturn)
// 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

View File

@@ -0,0 +1,53 @@
/*
===========================================================================
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 <http://www.gnu.org/licenses/>.
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_FILESYSTEM_H
#define SYS_FILESYSTEM_H
void Sys_Mkdir( const char *path );
bool Sys_Rmdir( const char *path );
bool Sys_IsFileWritable( const char *path );
enum sysFolder_t {
FOLDER_ERROR = -1,
FOLDER_NO = 0,
FOLDER_YES = 1
};
// returns FOLDER_YES if the specified path is a folder
sysFolder_t Sys_IsFolder( const char *path );
// use fs_debug to verbose Sys_ListFiles
// returns -1 if directory was not found (the list is cleared)
int Sys_ListFiles( const char * directory, const char * extension, idList<class idStr> & list );
const char * Sys_EXEPath();
const char * Sys_CWD();
const char * Sys_LaunchPath();
#endif

View File

@@ -0,0 +1,106 @@
/*
===========================================================================
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 <http://www.gnu.org/licenses/>.
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
================================================================================================
*/
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // prevent auto literal to string conversion
#ifndef _D3SDK
#ifndef GAME_DLL
#define WINVER 0x501
#include <winsock2.h>
#include <mmsystem.h>
#include <mmreg.h>
#define DIRECTINPUT_VERSION 0x0800 // was 0x0700 with the old mssdk
#define DIRECTSOUND_VERSION 0x0800
#include <dsound.h>
#include <dinput.h>
#endif /* !GAME_DLL */
#endif /* !_D3SDK */
#include <intrin.h> // needed for intrinsics like _mm_setzero_si28
#pragma warning(disable : 4100) // unreferenced formal parameter
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4244) // conversion to smaller type, possible loss of data
#pragma warning(disable : 4714) // function marked as __forceinline not inlined
#pragma warning(disable : 4996) // unsafe string operations
#include <malloc.h> // no malloc.h on mac or unix
#include <windows.h> // for qgl.h
#undef FindText // fix namespace pollution
/*
================================================================================================
Common Include Files
================================================================================================
*/
#if !defined( _DEBUG ) && !defined( NDEBUG )
// don't generate asserts
#define NDEBUG
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <ctype.h>
#include <typeinfo>
#include <errno.h>
#include <math.h>
#include <limits.h>
#include <memory>
//-----------------------------------------------------
// Hacked stuff we may want to consider implementing later
class idScopedGlobalHeap {
};
#endif // SYS_INCLUDES_H

View File

@@ -0,0 +1,200 @@
/*
===========================================================================
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 <http://www.gnu.org/licenses/>.
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_INTRIINSICS_H__
#define __SYS_INTRIINSICS_H__
/*
================================================================================================
Scalar single precision floating-point intrinsics
================================================================================================
*/
ID_INLINE_EXTERN float __fmuls( float a, float b ) { return ( a * b ); }
ID_INLINE_EXTERN float __fmadds( float a, float b, float c ) { return ( a * b + c ); }
ID_INLINE_EXTERN float __fnmsubs( float a, float b, float c ) { return ( c - a * b ); }
ID_INLINE_EXTERN float __fsels( float a, float b, float c ) { return ( a >= 0.0f ) ? b : c; }
ID_INLINE_EXTERN float __frcps( float x ) { return ( 1.0f / x ); }
ID_INLINE_EXTERN float __fdivs( float x, float y ) { return ( x / y ); }
ID_INLINE_EXTERN float __frsqrts( float x ) { return ( 1.0f / sqrtf( x ) ); }
ID_INLINE_EXTERN float __frcps16( float x ) { return ( 1.0f / x ); }
ID_INLINE_EXTERN float __fdivs16( float x, float y ) { return ( x / y ); }
ID_INLINE_EXTERN float __frsqrts16( float x ) { return ( 1.0f / sqrtf( x ) ); }
ID_INLINE_EXTERN float __frndz( float x ) { return (float)( (int)( x ) ); }
/*
================================================================================================
Zero cache line and prefetch intrinsics
================================================================================================
*/
// The code below assumes that a cache line is 64 bytes.
// We specify the cache line size as 128 here to make the code consistent with the consoles.
#define CACHE_LINE_SIZE 128
ID_FORCE_INLINE void Prefetch( const void * ptr, int offset ) {
// const char * bytePtr = ( (const char *) ptr ) + offset;
// _mm_prefetch( bytePtr + 0, _MM_HINT_NTA );
// _mm_prefetch( bytePtr + 64, _MM_HINT_NTA );
}
ID_FORCE_INLINE void ZeroCacheLine( void * ptr, int offset ) {
assert_128_byte_aligned( ptr );
char * bytePtr = ( (char *) ptr ) + offset;
__m128i zero = _mm_setzero_si128();
_mm_store_si128( (__m128i *) ( bytePtr + 0*16 ), zero );
_mm_store_si128( (__m128i *) ( bytePtr + 1*16 ), zero );
_mm_store_si128( (__m128i *) ( bytePtr + 2*16 ), zero );
_mm_store_si128( (__m128i *) ( bytePtr + 3*16 ), zero );
_mm_store_si128( (__m128i *) ( bytePtr + 4*16 ), zero );
_mm_store_si128( (__m128i *) ( bytePtr + 5*16 ), zero );
_mm_store_si128( (__m128i *) ( bytePtr + 6*16 ), zero );
_mm_store_si128( (__m128i *) ( bytePtr + 7*16 ), zero );
}
ID_FORCE_INLINE void FlushCacheLine( const void * ptr, int offset ) {
const char * bytePtr = ( (const char *) ptr ) + offset;
_mm_clflush( bytePtr + 0 );
_mm_clflush( bytePtr + 64 );
}
/*
================================================
Block Clear Macros
================================================
*/
// number of additional elements that are potentially cleared when clearing whole cache lines at a time
ID_INLINE_EXTERN int CACHE_LINE_CLEAR_OVERFLOW_COUNT( int size ) {
if ( ( size & ( CACHE_LINE_SIZE - 1 ) ) == 0 ) {
return 0;
}
if ( size > CACHE_LINE_SIZE ) {
return 1;
}
return ( CACHE_LINE_SIZE / ( size & ( CACHE_LINE_SIZE - 1 ) ) );
}
// if the pointer is not on a cache line boundary this assumes the cache line the pointer starts in was already cleared
#define CACHE_LINE_CLEAR_BLOCK( ptr, size ) \
byte * startPtr = (byte *)( ( ( (UINT_PTR) ( ptr ) ) + CACHE_LINE_SIZE - 1 ) & ~( CACHE_LINE_SIZE - 1 ) ); \
byte * endPtr = (byte *)( ( (UINT_PTR) ( ptr ) + ( size ) - 1 ) & ~( CACHE_LINE_SIZE - 1 ) ); \
for ( ; startPtr <= endPtr; startPtr += CACHE_LINE_SIZE ) { \
ZeroCacheLine( startPtr, 0 ); \
}
#define CACHE_LINE_CLEAR_BLOCK_AND_FLUSH( ptr, size ) \
byte * startPtr = (byte *)( ( ( (UINT_PTR) ( ptr ) ) + CACHE_LINE_SIZE - 1 ) & ~( CACHE_LINE_SIZE - 1 ) ); \
byte * endPtr = (byte *)( ( (UINT_PTR) ( ptr ) + ( size ) - 1 ) & ~( CACHE_LINE_SIZE - 1 ) ); \
for ( ; startPtr <= endPtr; startPtr += CACHE_LINE_SIZE ) { \
ZeroCacheLine( startPtr, 0 ); \
FlushCacheLine( startPtr, 0 ); \
}
/*
================================================================================================
Vector Intrinsics
================================================================================================
*/
/*
================================================
PC Windows
================================================
*/
#if !defined( R_SHUFFLE_D )
#define R_SHUFFLE_D( x, y, z, w ) (( (w) & 3 ) << 6 | ( (z) & 3 ) << 4 | ( (y) & 3 ) << 2 | ( (x) & 3 ))
#endif
// make the intrinsics "type unsafe"
typedef union __declspec(intrin_type) _CRT_ALIGN(16) __m128c {
__m128c() {}
__m128c( __m128 f ) { m128 = f; }
__m128c( __m128i i ) { m128i = i; }
operator __m128() { return m128; }
operator __m128i() { return m128i; }
__m128 m128;
__m128i m128i;
} __m128c;
#define _mm_madd_ps( a, b, c ) _mm_add_ps( _mm_mul_ps( (a), (b) ), (c) )
#define _mm_nmsub_ps( a, b, c ) _mm_sub_ps( (c), _mm_mul_ps( (a), (b) ) )
#define _mm_splat_ps( x, i ) __m128c( _mm_shuffle_epi32( __m128c( x ), _MM_SHUFFLE( i, i, i, i ) ) )
#define _mm_perm_ps( x, perm ) __m128c( _mm_shuffle_epi32( __m128c( x ), perm ) )
#define _mm_sel_ps( a, b, c ) _mm_or_ps( _mm_andnot_ps( __m128c( c ), a ), _mm_and_ps( __m128c( c ), b ) )
#define _mm_sel_si128( a, b, c ) _mm_or_si128( _mm_andnot_si128( __m128c( c ), a ), _mm_and_si128( __m128c( c ), b ) )
#define _mm_sld_ps( x, y, imm ) __m128c( _mm_or_si128( _mm_srli_si128( __m128c( x ), imm ), _mm_slli_si128( __m128c( y ), 16 - imm ) ) )
#define _mm_sld_si128( x, y, imm ) _mm_or_si128( _mm_srli_si128( x, imm ), _mm_slli_si128( y, 16 - imm ) )
ID_FORCE_INLINE_EXTERN __m128 _mm_msum3_ps( __m128 a, __m128 b ) {
__m128 c = _mm_mul_ps( a, b );
return _mm_add_ps( _mm_splat_ps( c, 0 ), _mm_add_ps( _mm_splat_ps( c, 1 ), _mm_splat_ps( c, 2 ) ) );
}
ID_FORCE_INLINE_EXTERN __m128 _mm_msum4_ps( __m128 a, __m128 b ) {
__m128 c = _mm_mul_ps( a, b );
c = _mm_add_ps( c, _mm_perm_ps( c, _MM_SHUFFLE( 1, 0, 3, 2 ) ) );
c = _mm_add_ps( c, _mm_perm_ps( c, _MM_SHUFFLE( 2, 3, 0, 1 ) ) );
return c;
}
#define _mm_shufmix_epi32( x, y, perm ) __m128c( _mm_shuffle_ps( __m128c( x ), __m128c( y ), perm ) )
#define _mm_loadh_epi64( x, address ) __m128c( _mm_loadh_pi( __m128c( x ), (__m64 *)address ) )
#define _mm_storeh_epi64( address, x ) _mm_storeh_pi( (__m64 *)address, __m128c( x ) )
// floating-point reciprocal with close to full precision
ID_FORCE_INLINE_EXTERN __m128 _mm_rcp32_ps( __m128 x ) {
__m128 r = _mm_rcp_ps( x ); // _mm_rcp_ps() has 12 bits of precision
r = _mm_sub_ps( _mm_add_ps( r, r ), _mm_mul_ps( _mm_mul_ps( x, r ), r ) );
r = _mm_sub_ps( _mm_add_ps( r, r ), _mm_mul_ps( _mm_mul_ps( x, r ), r ) );
return r;
}
// floating-point reciprocal with at least 16 bits precision
ID_FORCE_INLINE_EXTERN __m128 _mm_rcp16_ps( __m128 x ) {
__m128 r = _mm_rcp_ps( x ); // _mm_rcp_ps() has 12 bits of precision
r = _mm_sub_ps( _mm_add_ps( r, r ), _mm_mul_ps( _mm_mul_ps( x, r ), r ) );
return r;
}
// floating-point divide with close to full precision
ID_FORCE_INLINE_EXTERN __m128 _mm_div32_ps( __m128 x, __m128 y ) {
return _mm_mul_ps( x, _mm_rcp32_ps( y ) );
}
// floating-point divide with at least 16 bits precision
ID_FORCE_INLINE_EXTERN __m128 _mm_div16_ps( __m128 x, __m128 y ) {
return _mm_mul_ps( x, _mm_rcp16_ps( y ) );
}
// load idBounds::GetMins()
#define _mm_loadu_bounds_0( bounds ) _mm_perm_ps( _mm_loadh_pi( _mm_load_ss( & bounds[0].x ), (__m64 *) & bounds[0].y ), _MM_SHUFFLE( 1, 3, 2, 0 ) )
// load idBounds::GetMaxs()
#define _mm_loadu_bounds_1( bounds ) _mm_perm_ps( _mm_loadh_pi( _mm_load_ss( & bounds[1].x ), (__m64 *) & bounds[1].y ), _MM_SHUFFLE( 1, 3, 2, 0 ) )
#endif // !__SYS_INTRIINSICS_H__

View File

@@ -0,0 +1,168 @@
/*
===========================================================================
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 <http://www.gnu.org/licenses/>.
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_THREADING_H__
#define __SYS_THREADING_H__
#ifndef __TYPEINFOGEN__
/*
================================================================================================
Platform specific mutex, signal, atomic integer and memory barrier.
================================================================================================
*/
typedef CRITICAL_SECTION mutexHandle_t;
typedef HANDLE signalHandle_t;
typedef LONG interlockedInt_t;
// _ReadWriteBarrier() does not translate to any instructions but keeps the compiler
// from reordering read and write instructions across the barrier.
// MemoryBarrier() inserts and CPU instruction that keeps the CPU from reordering reads and writes.
#pragma intrinsic(_ReadWriteBarrier)
#define SYS_MEMORYBARRIER _ReadWriteBarrier(); MemoryBarrier()
/*
================================================================================================
Platform specific thread local storage.
Can be used to store either a pointer or an integer.
================================================================================================
*/
class idSysThreadLocalStorage {
public:
idSysThreadLocalStorage() {
tlsIndex = TlsAlloc();
}
idSysThreadLocalStorage( const ptrdiff_t &val ) {
tlsIndex = TlsAlloc();
TlsSetValue( tlsIndex, (LPVOID)val );
}
~idSysThreadLocalStorage() {
TlsFree( tlsIndex );
}
operator ptrdiff_t() {
return (ptrdiff_t)TlsGetValue( tlsIndex );
}
const ptrdiff_t & operator = ( const ptrdiff_t &val ) {
TlsSetValue( tlsIndex, (LPVOID)val );
return val;
}
DWORD tlsIndex;
};
#define ID_TLS idSysThreadLocalStorage
#endif // __TYPEINFOGEN__
/*
================================================================================================
Platform independent threading functions.
================================================================================================
*/
enum core_t {
CORE_ANY = -1,
CORE_0A,
CORE_0B,
CORE_1A,
CORE_1B,
CORE_2A,
CORE_2B
};
typedef unsigned int (*xthread_t)( void * );
enum xthreadPriority {
THREAD_LOWEST,
THREAD_BELOW_NORMAL,
THREAD_NORMAL,
THREAD_ABOVE_NORMAL,
THREAD_HIGHEST
};
#define DEFAULT_THREAD_STACK_SIZE ( 256 * 1024 )
// on win32, the threadID is NOT the same as the threadHandle
uintptr_t Sys_GetCurrentThreadID();
// returns a threadHandle
uintptr_t Sys_CreateThread( xthread_t function, void *parms, xthreadPriority priority,
const char *name, core_t core, int stackSize = DEFAULT_THREAD_STACK_SIZE,
bool suspended = false );
void Sys_WaitForThread( uintptr_t threadHandle );
void Sys_DestroyThread( uintptr_t threadHandle );
void Sys_SetCurrentThreadName( const char *name );
void Sys_SignalCreate( signalHandle_t & handle, bool manualReset );
void Sys_SignalDestroy( signalHandle_t & handle );
void Sys_SignalRaise( signalHandle_t & handle );
void Sys_SignalClear( signalHandle_t & handle );
bool Sys_SignalWait( signalHandle_t & handle, int timeout );
void Sys_MutexCreate( mutexHandle_t & handle );
void Sys_MutexDestroy( mutexHandle_t & handle );
bool Sys_MutexLock( mutexHandle_t & handle, bool blocking );
void Sys_MutexUnlock( mutexHandle_t & handle );
interlockedInt_t Sys_InterlockedIncrement( interlockedInt_t & value );
interlockedInt_t Sys_InterlockedDecrement( interlockedInt_t & value );
interlockedInt_t Sys_InterlockedAdd( interlockedInt_t & value, interlockedInt_t i );
interlockedInt_t Sys_InterlockedSub( interlockedInt_t & value, interlockedInt_t i );
interlockedInt_t Sys_InterlockedExchange( interlockedInt_t & value, interlockedInt_t exchange );
interlockedInt_t Sys_InterlockedCompareExchange( interlockedInt_t & value, interlockedInt_t comparand, interlockedInt_t exchange );
void * Sys_InterlockedExchangePointer( void * & ptr, void * exchange );
void * Sys_InterlockedCompareExchangePointer( void * & ptr, void * comparand, void * exchange );
void Sys_Yield();
const int MAX_CRITICAL_SECTIONS = 4;
enum {
CRITICAL_SECTION_ZERO = 0,
CRITICAL_SECTION_ONE,
CRITICAL_SECTION_TWO,
CRITICAL_SECTION_THREE
};
#endif // !__SYS_THREADING_H__

287
neo/idlib/sys/sys_types.h Normal file
View File

@@ -0,0 +1,287 @@
/*
===========================================================================
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 <http://www.gnu.org/licenses/>.
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;
typedef signed char int8;
typedef unsigned char uint8;
typedef short int int16;
typedef unsigned short int uint16;
typedef int int32;
typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;
// 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, 1 );
assert_sizeof( uint8, 1 );
assert_sizeof( int16, 2 );
assert_sizeof( uint16, 2 );
assert_sizeof( int32, 4 );
assert_sizeof( uint32, 4 );
assert_sizeof( int64, 8 );
assert_sizeof( uint64, 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;
}
template<class T> T Max( T x, T y ) { return ( x > y ) ? x : y; }
template<class T> 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<typename T1> operator T1 * () const { return 0; }
// implicit conversion to all pointer to member types
template<typename T1, typename T2> 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;
#if 1
typedef unsigned short triIndex_t;
#define GL_INDEX_TYPE GL_UNSIGNED_SHORT
#else
typedef unsigned 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
#define NODEFAULT default: __assume( 0 )
#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

View File

@@ -0,0 +1,358 @@
/*
===========================================================================
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 <http://www.gnu.org/licenses/>.
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.
===========================================================================
*/
#pragma hdrstop
#include "../../precompiled.h"
/*
================================================================================================
================================================================================================
*/
#define MS_VC_EXCEPTION 0x406D1388
typedef struct tagTHREADNAME_INFO {
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
/*
========================
Sys_SetThreadName
========================
*/
void Sys_SetThreadName( DWORD threadID, const char * name ) {
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = name;
info.dwThreadID = threadID;
info.dwFlags = 0;
__try {
RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(DWORD), (const ULONG_PTR *)&info );
}
// this much is just to keep /analyze quiet
__except( GetExceptionCode() == MS_VC_EXCEPTION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH ) {
info.dwFlags = 0;
}
}
/*
========================
Sys_SetCurrentThreadName
========================
*/
void Sys_SetCurrentThreadName( const char * name ) {
Sys_SetThreadName( GetCurrentThreadId(), name );
}
/*
========================
Sys_Createthread
========================
*/
uintptr_t Sys_CreateThread( xthread_t function, void *parms, xthreadPriority priority, const char *name, core_t core, int stackSize, bool suspended ) {
DWORD flags = ( suspended ? CREATE_SUSPENDED : 0 );
// Without this flag the 'dwStackSize' parameter to CreateThread specifies the "Stack Commit Size"
// and the "Stack Reserve Size" is set to the value specified at link-time.
// With this flag the 'dwStackSize' parameter to CreateThread specifies the "Stack Reserve Size"
// and the “Stack Commit Size” is set to the value specified at link-time.
// For various reasons (some of which historic) we reserve a large amount of stack space in the
// project settings. By setting this flag and by specifying 64 kB for the "Stack Commit Size" in
// the project settings we can create new threads with a much smaller reserved (and committed)
// stack space. It is very important that the "Stack Commit Size" is set to a small value in
// the project settings. If it is set to a large value we may be both reserving and committing
// a lot of memory by setting the STACK_SIZE_PARAM_IS_A_RESERVATION flag. There are some
// 50 threads allocated for normal game play. If, for instance, the commit size is set to 16 MB
// then by adding this flag we would be reserving and committing 50 x 16 = 800 MB of memory.
// On the other hand, if this flag is not set and the "Stack Reserve Size" is set to 16 MB in the
// project settings, then we would still be reserving 50 x 16 = 800 MB of virtual address space.
flags |= STACK_SIZE_PARAM_IS_A_RESERVATION;
DWORD threadId;
HANDLE handle = CreateThread( NULL, // LPSECURITY_ATTRIBUTES lpsa, //-V513
stackSize,
(LPTHREAD_START_ROUTINE)function,
parms,
flags,
&threadId);
if ( handle == 0 ) {
idLib::common->FatalError( "CreateThread error: %i", GetLastError() );
return (uintptr_t)0;
}
Sys_SetThreadName( threadId, name );
if ( priority == THREAD_HIGHEST ) {
SetThreadPriority( (HANDLE)handle, THREAD_PRIORITY_HIGHEST ); // we better sleep enough to do this
} else if ( priority == THREAD_ABOVE_NORMAL ) {
SetThreadPriority( (HANDLE)handle, THREAD_PRIORITY_ABOVE_NORMAL );
} else if ( priority == THREAD_BELOW_NORMAL ) {
SetThreadPriority( (HANDLE)handle, THREAD_PRIORITY_BELOW_NORMAL );
} else if ( priority == THREAD_LOWEST ) {
SetThreadPriority( (HANDLE)handle, THREAD_PRIORITY_LOWEST );
}
// Under Windows, we don't set the thread affinity and let the OS deal with scheduling
return (uintptr_t)handle;
}
/*
========================
Sys_GetCurrentThreadID
========================
*/
uintptr_t Sys_GetCurrentThreadID() {
return GetCurrentThreadId();
}
/*
========================
Sys_WaitForThread
========================
*/
void Sys_WaitForThread( uintptr_t threadHandle ) {
WaitForSingleObject( (HANDLE)threadHandle, INFINITE );
}
/*
========================
Sys_DestroyThread
========================
*/
void Sys_DestroyThread( uintptr_t threadHandle ) {
if ( threadHandle == 0 ) {
return;
}
WaitForSingleObject( (HANDLE)threadHandle, INFINITE );
CloseHandle( (HANDLE)threadHandle );
}
/*
========================
Sys_Yield
========================
*/
void Sys_Yield() {
SwitchToThread();
}
/*
================================================================================================
Signal
================================================================================================
*/
/*
========================
Sys_SignalCreate
========================
*/
void Sys_SignalCreate( signalHandle_t & handle, bool manualReset ) {
handle = CreateEvent( NULL, manualReset, FALSE, NULL );
}
/*
========================
Sys_SignalDestroy
========================
*/
void Sys_SignalDestroy( signalHandle_t &handle ) {
CloseHandle( handle );
}
/*
========================
Sys_SignalRaise
========================
*/
void Sys_SignalRaise( signalHandle_t & handle ) {
SetEvent( handle );
}
/*
========================
Sys_SignalClear
========================
*/
void Sys_SignalClear( signalHandle_t & handle ) {
// events are created as auto-reset so this should never be needed
ResetEvent( handle );
}
/*
========================
Sys_SignalWait
========================
*/
bool Sys_SignalWait( signalHandle_t & handle, int timeout ) {
DWORD result = WaitForSingleObject( handle, timeout == idSysSignal::WAIT_INFINITE ? INFINITE : timeout );
assert( result == WAIT_OBJECT_0 || ( timeout != idSysSignal::WAIT_INFINITE && result == WAIT_TIMEOUT ) );
return ( result == WAIT_OBJECT_0 );
}
/*
================================================================================================
Mutex
================================================================================================
*/
/*
========================
Sys_MutexCreate
========================
*/
void Sys_MutexCreate( mutexHandle_t & handle ) {
InitializeCriticalSection( &handle );
}
/*
========================
Sys_MutexDestroy
========================
*/
void Sys_MutexDestroy( mutexHandle_t & handle ) {
DeleteCriticalSection( &handle );
}
/*
========================
Sys_MutexLock
========================
*/
bool Sys_MutexLock( mutexHandle_t & handle, bool blocking ) {
if ( TryEnterCriticalSection( &handle ) == 0 ) {
if ( !blocking ) {
return false;
}
EnterCriticalSection( &handle );
}
return true;
}
/*
========================
Sys_MutexUnlock
========================
*/
void Sys_MutexUnlock( mutexHandle_t & handle ) {
LeaveCriticalSection( & handle );
}
/*
================================================================================================
Interlocked Integer
================================================================================================
*/
/*
========================
Sys_InterlockedIncrement
========================
*/
interlockedInt_t Sys_InterlockedIncrement( interlockedInt_t & value ) {
return InterlockedIncrementAcquire( & value );
}
/*
========================
Sys_InterlockedDecrement
========================
*/
interlockedInt_t Sys_InterlockedDecrement( interlockedInt_t & value ) {
return InterlockedDecrementRelease( & value );
}
/*
========================
Sys_InterlockedAdd
========================
*/
interlockedInt_t Sys_InterlockedAdd( interlockedInt_t & value, interlockedInt_t i ) {
return InterlockedExchangeAdd( & value, i ) + i;
}
/*
========================
Sys_InterlockedSub
========================
*/
interlockedInt_t Sys_InterlockedSub( interlockedInt_t & value, interlockedInt_t i ) {
return InterlockedExchangeAdd( & value, - i ) - i;
}
/*
========================
Sys_InterlockedExchange
========================
*/
interlockedInt_t Sys_InterlockedExchange( interlockedInt_t & value, interlockedInt_t exchange ) {
return InterlockedExchange( & value, exchange );
}
/*
========================
Sys_InterlockedCompareExchange
========================
*/
interlockedInt_t Sys_InterlockedCompareExchange( interlockedInt_t & value, interlockedInt_t comparand, interlockedInt_t exchange ) {
return InterlockedCompareExchange( & value, exchange, comparand );
}
/*
================================================================================================
Interlocked Pointer
================================================================================================
*/
/*
========================
Sys_InterlockedExchangePointer
========================
*/
void *Sys_InterlockedExchangePointer( void *& ptr, void * exchange ) {
return InterlockedExchangePointer( & ptr, exchange );
}
/*
========================
Sys_InterlockedCompareExchangePointer
========================
*/
void * Sys_InterlockedCompareExchangePointer( void * & ptr, void * comparand, void * exchange ) {
return InterlockedCompareExchangePointer( & ptr, exchange, comparand );
}