Skip to content

Commit

Permalink
Merged idtech5 idlib sys/
Browse files Browse the repository at this point in the history
  • Loading branch information
FriskTheFallenHuman committed Sep 6, 2024
1 parent 15c3de4 commit c4ea522
Show file tree
Hide file tree
Showing 45 changed files with 1,397 additions and 506 deletions.
1 change: 1 addition & 0 deletions neo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions neo/MayaImport/maya_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions neo/cm/CollisionModel_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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++ ) {
Expand Down
4 changes: 2 additions & 2 deletions neo/d3xp/script/Script_Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions neo/d3xp/script/Script_Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ void idProgram::BeginCompilation( void ) {
}

catch( idCompileError &err ) {
gameLocal.Error( "%s", err.error );
gameLocal.Error( "%s", err.GetError() );
}
}

Expand Down Expand Up @@ -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() );
}
};

Expand Down
2 changes: 0 additions & 2 deletions neo/framework/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions neo/framework/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions neo/game/script/Script_Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions neo/game/script/Script_Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ void idProgram::BeginCompilation( void ) {
}

catch( idCompileError &err ) {
gameLocal.Error( "%s", err.error );
gameLocal.Error( "%s", err.GetError() );
}
}

Expand Down Expand Up @@ -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() );
}
};

Expand Down
65 changes: 24 additions & 41 deletions neo/idlib/Lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ idCVarSystem * idLib::cvarSystem = NULL;
idFileSystem * idLib::fileSystem = NULL;
int idLib::frameNumber = 0;

char idException::error[2048];

/*
================
idLib::Init
Expand Down Expand Up @@ -81,7 +83,9 @@ void idLib::Init( void ) {
//idMatX::Test();

// test idPolynomial
#ifdef _DEBUG
idPolynomial::Test();
#endif

// initialize the dictionary string pools
idDict::Init();
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
}
124 changes: 102 additions & 22 deletions neo/idlib/Lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<class T> ID_INLINE T Max( T x, T y ) { return ( x > y ) ? x : y; }
template<class T> 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 ) { }
};

/*
===============================================================================
Expand All @@ -156,6 +232,10 @@ template<class T> 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"
Expand Down
Loading

0 comments on commit c4ea522

Please sign in to comment.