diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..b7f7315e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,69 @@ +name: Compilation + +on: + push: + pull_request: + +jobs: + build: + strategy: + matrix: + include: + - os: ubuntu-22.04 + cc: clang + cxx: clang++ + container_image: ghcr.io/alliedmodders/build-containers/debian11-clang22:latest + - os: windows-2022 + cc: msvc + fail-fast: false + + name: ${{ matrix.os }} - ${{ matrix.cc }} + runs-on: ${{ matrix.os }} + container: + image: ${{ matrix.container_image }} + + steps: + - uses: actions/checkout@v4 + name: Repository checkout + with: + fetch-depth: 0 + submodules: recursive + path: repository + + - uses: actions/checkout@v4 + name: AMBuild checkout + if: startsWith(runner.os, 'Windows') + with: + repository: alliedmodders/ambuild + ref: fe8c99ccd24fa926bf6ac6b9935a5fc03df06a72 + fetch-depth: 0 + submodules: recursive + path: ambuild + + - name: Setup AMBuild + shell: bash + run: | + python3 -m pip install ./ambuild + + - name: Select clang compiler + if: startsWith(runner.os, 'Linux') + run: | + echo "CC=${{ matrix.cc }}" >> $GITHUB_ENV + echo "CXX=${{ matrix.cxx }}" >> $GITHUB_ENV + ${{ matrix.cc }} --version + ${{ matrix.cxx }} --version + + - name: Build + shell: bash + working-directory: repository + run: | + mkdir build + cd build + python3 ../configure.py + ambuild + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: libs_${{ runner.os }} + path: repository/build/lib \ No newline at end of file diff --git a/AMBuildScript b/AMBuildScript new file mode 100644 index 00000000..afe8ac1a --- /dev/null +++ b/AMBuildScript @@ -0,0 +1,179 @@ +# vim: set ts=2 sw=2 tw=99 noet ft=python: +import os +from ambuild2 import util + +def ResolveEnvPath(env, folder=None): + if env in os.environ: + path = os.environ[env] + if os.path.isdir(path): + return path + return None + + if folder: + head = os.getcwd() + oldhead = None + while head != None and head != oldhead: + path = os.path.join(head, folder) + if os.path.isdir(path): + return path + oldhead = head + head, tail = os.path.split(head) + + return None + +def Normalize(path): + return os.path.abspath(os.path.normpath(path)) + +class SDKConfig(object): + def __init__(self): + self.libs = [] + self.targets = [] + self.target_archs = set() + + if builder.options.targets: + target_archs = builder.options.targets.split(',') + else: + target_archs = ['x86'] + + for arch in target_archs: + try: + cxx = builder.DetectCxx(target_arch = arch) + self.target_archs.add(cxx.target.arch) + except Exception as e: + if builder.options.targets: + raise + print('Skipping target {}: {}'.format(arch, e)) + continue + self.targets.append(cxx) + + if not self.targets: + raise Exception('No suitable C/C++ compiler was found.') + + @property + def tag(self): + if builder.options.debug == '1': + return 'Debug' + return 'Release' + + def configure_cxx(self, cxx): + if cxx.like('gcc'): + self.configure_gcc(cxx) + elif cxx.family == 'msvc': + self.configure_msvc(cxx) + + # Optimization + if builder.options.opt == '1': + cxx.defines += ['NDEBUG'] + + # Debugging + if builder.options.debug == '1': + cxx.defines += ['DEBUG', '_DEBUG'] + + if cxx.target.arch == 'x86_64': + cxx.defines += ['X64BITS', 'PLATFORM_64BITS'] + cxx.defines += ['RAD_TELEMETRY_DISABLED'] + + # Platform-specifics + if cxx.target.platform == 'linux': + self.configure_linux(cxx) + elif cxx.target.platform == 'windows': + self.configure_windows(cxx) + + def configure_gcc(self, cxx): + cxx.cflags += [ + '-Wall', + '-Werror', + '-Wno-overloaded-virtual', + '-Wno-unused-function', + '-Wno-unknown-pragmas', + '-Wno-dangling-else', + '-Wno-unused-variable', + '-Wno-unused-private-field', + '-Wno-inconsistent-missing-override', + '-Wno-tautological-overlap-compare', + '-Wno-tautological-constant-out-of-range-compare', + '-Wno-undefined-bool-conversion', + '-Wno-nontrivial-memcall', + '-Wno-sync-alignment', + '-msse', + '-fPIC' + ] + + cxx.defines += [ + 'COMPILER_GCC' + ] + + cxx.cxxflags += [ + '-std=c++17' + ] + + if builder.options.opt == '1': + cxx.cflags += ['-O3'] + return + + def configure_msvc(self, cxx): + cxx.defines += ['COMPILER_MSVC'] + if cxx.target.arch == 'x86': + cxx.defines += ['COMPILER_MSVC32'] + elif cxx.target.arch == 'x86_64': + cxx.defines += ['COMPILER_MSVC64'] + + cxx.cxxflags += [ + '/std:c++17', + '/WX' + ] + + if builder.options.opt == '1': + cxx.cflags += ['/Ox', '/Zo'] + cxx.linkflags += ['/OPT:ICF', '/OPT:REF'] + + return + + def configure_linux(self, cxx): + cxx.defines += ['_LINUX', 'LINUX', 'POSIX', 'GNUC'] + + if cxx.target.arch == 'x86': + cxx.cflags += ["-march=pentium4", "-march=core2", "-msse2", "-mfpmath=sse"] + else: + cxx.cflags += ["-march=nocona", "-march=core2"] + + # Set of defines required by the HL2SDK + cxx.defines += [ + '_finite=finite', + 'strnicmp=strncasecmp', + '_vsnprintf=vsnprintf', + 'stricmp=strcasecmp', + '_alloca=alloca', + 'NO_MALLOC_OVERRIDE' + ] + return + + def configure_windows(self, cxx): + cxx.defines += ['_WINDOWS', 'WINDOWS', 'COMPILER_MSVC'] + if cxx.target.arch == 'x86': + cxx.defines += ['WIN32'] + elif cxx.target.arch == 'x86_64': + cxx.defines += ['WIN32', 'WIN64'] + return + + def configure(self): + for cxx in self.targets: + self.configure_cxx(cxx) + + def ConfigureLibrary(self, project, compiler, context, prefix = ''): + name = prefix + project.name + if compiler.target.platform == 'linux' and compiler.target.arch == 'x86': + name += '_i486' + binary = project.Configure(compiler, name, '{0} - {1}'.format(self.tag, compiler.target.arch)) + binary.compiler.cxxincludes += [ + os.path.join(context.currentSourcePath) + ] + return binary + +HL2SDK = SDKConfig() +HL2SDK.configure() + +BuildScripts = ['mathlib/AMBuilder', 'tier1/AMBuilder', 'PackageScript'] +# Turn off the 'lib' prefix for all platform, we will add it if we need to +util.StaticLibPrefix = '' +builder.Build(BuildScripts, { 'HL2SDK': HL2SDK }) \ No newline at end of file diff --git a/PackageScript b/PackageScript new file mode 100644 index 00000000..d514157e --- /dev/null +++ b/PackageScript @@ -0,0 +1,50 @@ +# vim: set ts=8 sts=2 sw=2 tw=99 et ft=python: +import os + +# This is where the files will be output to +# package is the default +builder.SetBuildFolder('lib') + + +folder_list = [] + +for task in HL2SDK.libs: + if task.target.platform == 'windows': + folder_list += ['public'] + break + +for task in HL2SDK.libs: + if task.target.platform == 'linux': + folder_list += ['linux'] + break + +# Create the distribution folder hierarchy. +folder_map = {} +for folder in folder_list: + norm_folder = os.path.normpath(folder) + folder_map[folder] = builder.AddFolder(norm_folder) + +# Do all straight-up file copies from the source tree. +def CopyFiles(src, dest, files): + if not dest: + dest = src + dest_entry = folder_map[dest] + for source_file in files: + source_path = os.path.join(builder.sourcePath, src, source_file) + builder.AddCopy(source_path, dest_entry) +def CopyFile(src, dest): + dest_entry = folder_map[dest] + source_path = os.path.join(builder.sourcePath, src) + builder.AddCopy(source_path, dest_entry) +def CopyDirContent(src, dest): + dest_entry = folder_map[dest] + for item in os.scandir(os.path.join(builder.sourcePath, src)): + if item.is_file(): + builder.AddCopy(item.path, dest_entry) + +# Copy binaries. +for task in HL2SDK.libs: + if task.target.platform == 'linux': + builder.AddCopy(task.binary, folder_map['linux']) + elif task.target.platform == 'windows': + builder.AddCopy(task.binary, folder_map['public']) \ No newline at end of file diff --git a/configure.py b/configure.py new file mode 100644 index 00000000..ad589bc4 --- /dev/null +++ b/configure.py @@ -0,0 +1,11 @@ +import sys +from ambuild2 import run + +parser = run.BuildParser(sourcePath = sys.path[0], api='2.2') +parser.options.add_argument('--enable-debug', action='store_const', const='1', dest='debug', + help='Enable debugging symbols') +parser.options.add_argument('--enable-optimize', action='store_const', const='1', dest='opt', + help='Enable optimization') +parser.options.add_argument('--targets', type=str, dest='targets', default=None, + help="Override the target architecture (use commas to separate multiple targets).") +parser.Configure() \ No newline at end of file diff --git a/lib/linux/mathlib_i486.a b/lib/linux/mathlib_i486.a index 963b347a..aff1d81d 100644 Binary files a/lib/linux/mathlib_i486.a and b/lib/linux/mathlib_i486.a differ diff --git a/lib/linux/tier1_i486.a b/lib/linux/tier1_i486.a index 8a596e82..160a74ff 100644 Binary files a/lib/linux/tier1_i486.a and b/lib/linux/tier1_i486.a differ diff --git a/lib/public/mathlib.lib b/lib/public/mathlib.lib index 453b4aff..2ba77036 100644 Binary files a/lib/public/mathlib.lib and b/lib/public/mathlib.lib differ diff --git a/lib/public/tier1.lib b/lib/public/tier1.lib index 388ca1f0..90db1463 100644 Binary files a/lib/public/tier1.lib and b/lib/public/tier1.lib differ diff --git a/mathlib/AMBuilder b/mathlib/AMBuilder new file mode 100644 index 00000000..4054140b --- /dev/null +++ b/mathlib/AMBuilder @@ -0,0 +1,45 @@ +# vim: set ts=2 sw=2 tw=99 noet ft=python: +import os, sys + +def AddSourceFilesFromDir(path, files): + list = [] + for file in files: + list.append(os.path.join(path, file)) + return list + +builder.SetBuildFolder('/') + +project = builder.StaticLibraryProject('mathlib') +project.sources = [ + 'anorms.cpp', + 'bumpvects.cpp', + 'color_conversion.cpp', + 'halton.cpp', + 'IceKey.cpp', + 'imagequant.cpp', + 'lightdesc.cpp', + 'mathlib_base.cpp', + 'polyhedron.cpp', + 'powsse.cpp', + 'quantize.cpp', + 'randsse.cpp', + 'simdvectormatrix.cpp', + 'sparse_convolution_noise.cpp', + 'sse.cpp', + 'sseconst.cpp', + 'ssenoise.cpp', + 'vector.cpp', + 'vmatrix.cpp', +] + +for cxx in HL2SDK.targets: + binary = HL2SDK.ConfigureLibrary(project, cxx, builder) + compiler = binary.compiler + + compiler.cxxincludes += [ + os.path.join(builder.currentSourcePath, '..', 'public'), + os.path.join(builder.currentSourcePath, '..', 'public', 'tier0'), + os.path.join(builder.currentSourcePath, '..', 'public', 'mathlib') + ] + +HL2SDK.libs += builder.Add(project) \ No newline at end of file diff --git a/mathlib/IceKey.cpp b/mathlib/IceKey.cpp index 3d1566a8..30765498 100644 --- a/mathlib/IceKey.cpp +++ b/mathlib/IceKey.cpp @@ -61,11 +61,11 @@ static const int ice_keyrot[16] = { static unsigned int gf_mult ( - register unsigned int a, - register unsigned int b, - register unsigned int m + unsigned int a, + unsigned int b, + unsigned int m ) { - register unsigned int res = 0; + unsigned int res = 0; while (b) { if (b & 1) @@ -89,10 +89,10 @@ gf_mult ( static unsigned long gf_exp7 ( - register unsigned int b, + unsigned int b, unsigned int m ) { - register unsigned int x; + unsigned int x; if (b == 0) return (0); @@ -110,10 +110,10 @@ gf_exp7 ( static unsigned long ice_perm32 ( - register unsigned long x + unsigned long x ) { - register unsigned long res = 0; - register const unsigned long *pbox = ice_pbox; + unsigned long res = 0; + const unsigned long *pbox = ice_pbox; while (x) { if (x & 1) @@ -134,7 +134,7 @@ ice_perm32 ( static void ice_sboxes_init (void) { - register int i; + int i; for (i=0; i<1024; i++) { int col = (i >> 1) & 0xff; @@ -203,7 +203,7 @@ IceKey::~IceKey () static unsigned long ice_f ( - register unsigned long p, + unsigned long p, const IceSubkey *sk ) { unsigned long tl, tr; /* Expanded 40-bit values */ @@ -241,8 +241,8 @@ IceKey::encrypt ( unsigned char *ctext ) const { - register int i; - register unsigned long l, r; + int i; + unsigned long l, r; l = (((unsigned long) ptext[0]) << 24) | (((unsigned long) ptext[1]) << 16) @@ -276,8 +276,8 @@ IceKey::decrypt ( unsigned char *ptext ) const { - register int i; - register unsigned long l, r; + int i; + unsigned long l, r; l = (((unsigned long) ctext[0]) << 24) | (((unsigned long) ctext[1]) << 16) @@ -314,20 +314,20 @@ IceKey::scheduleBuild ( int i; for (i=0; i<8; i++) { - register int j; - register int kr = keyrot[i]; + int j; + int kr = keyrot[i]; IceSubkey *isk = &_keysched[n + i]; for (j=0; j<3; j++) isk->val[j] = 0; for (j=0; j<15; j++) { - register int k; + int k; unsigned long *curr_sk = &isk->val[j % 3]; for (k=0; k<4; k++) { unsigned short *curr_kb = &kb[(kr + k) & 3]; - register int bit = *curr_kb & 1; + int bit = *curr_kb & 1; *curr_sk = (*curr_sk << 1) | bit; *curr_kb = (*curr_kb >> 1) | ((bit ^ 1) << 15); diff --git a/mathlib/mathlib_base.cpp b/mathlib/mathlib_base.cpp index 4e42448b..bdd76e6c 100644 --- a/mathlib/mathlib_base.cpp +++ b/mathlib/mathlib_base.cpp @@ -3027,7 +3027,7 @@ void CalcClosestPointOnLineSegment( const Vector &P, const Vector &vLineA, const { Vector vDir; float t = CalcClosestPointToLineT( P, vLineA, vLineB, vDir ); - t = clamp( t, 0, 1 ); + t = clamp( t, 0.f, 1.f ); if ( outT ) { *outT = t; @@ -3099,7 +3099,7 @@ void CalcClosestPointOnLineSegment2D( const Vector2D &P, const Vector2D &vLineA, { Vector2D vDir; float t = CalcClosestPointToLineT2D( P, vLineA, vLineB, vDir ); - t = clamp( t, 0, 1 ); + t = clamp( t, 0.f, 1.f ); if ( outT ) { *outT = t; diff --git a/mathlib/sse.cpp b/mathlib/sse.cpp index 49035db8..c1305644 100644 --- a/mathlib/sse.cpp +++ b/mathlib/sse.cpp @@ -59,10 +59,10 @@ _PS_EXTERN_CONST(am_pi_o_2, (float)(M_PI / 2.0)); _PS_EXTERN_CONST(am_2_o_pi, (float)(2.0 / M_PI)); _PS_EXTERN_CONST(am_pi_o_4, (float)(M_PI / 4.0)); _PS_EXTERN_CONST(am_4_o_pi, (float)(4.0 / M_PI)); -_PS_EXTERN_CONST_TYPE(am_sign_mask, int32, 0x80000000); -_PS_EXTERN_CONST_TYPE(am_inv_sign_mask, int32, ~0x80000000); -_PS_EXTERN_CONST_TYPE(am_min_norm_pos,int32, 0x00800000); -_PS_EXTERN_CONST_TYPE(am_mant_mask, int32, 0x7f800000); +_PS_EXTERN_CONST_TYPE(am_sign_mask, uint32, 0x80000000); +_PS_EXTERN_CONST_TYPE(am_inv_sign_mask, uint32, ~0x80000000); +_PS_EXTERN_CONST_TYPE(am_min_norm_pos,uint32, 0x00800000); +_PS_EXTERN_CONST_TYPE(am_mant_mask, uint32, 0x7f800000); _PS_EXTERN_CONST_TYPE(am_inv_mant_mask, int32, ~0x7f800000); _EPI32_CONST(1, 1); diff --git a/mathlib/sseconst.cpp b/mathlib/sseconst.cpp index 3e7cfab3..19f0da49 100644 --- a/mathlib/sseconst.cpp +++ b/mathlib/sseconst.cpp @@ -38,19 +38,19 @@ const fltx4 g_QuatMultRowSign[4] = { -1.0f, -1.0f, -1.0f, 1.0f } }; -const int32 ALIGN16 g_SIMD_clear_signmask[4]= {0x7fffffff,0x7fffffff,0x7fffffff,0x7fffffff}; -const int32 ALIGN16 g_SIMD_signmask[4]= { 0x80000000, 0x80000000, 0x80000000, 0x80000000 }; -const int32 ALIGN16 g_SIMD_lsbmask[4]= { 0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe }; -const int32 ALIGN16 g_SIMD_clear_wmask[4]= { 0xffffffff, 0xffffffff, 0xffffffff, 0 }; -const int32 ALIGN16 g_SIMD_AllOnesMask[4]= { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; // ~0,~0,~0,~0 -const int32 ALIGN16 g_SIMD_Low16BitsMask[4]= { 0xffff, 0xffff, 0xffff, 0xffff }; // 0xffff x 4 +const uint32 ALIGN16 g_SIMD_clear_signmask[4]= {0x7fffffff,0x7fffffff,0x7fffffff,0x7fffffff}; +const uint32 ALIGN16 g_SIMD_signmask[4]= { 0x80000000, 0x80000000, 0x80000000, 0x80000000 }; +const uint32 ALIGN16 g_SIMD_lsbmask[4]= { 0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe }; +const uint32 ALIGN16 g_SIMD_clear_wmask[4]= { 0xffffffff, 0xffffffff, 0xffffffff, 0 }; +const uint32 ALIGN16 g_SIMD_AllOnesMask[4]= { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; // ~0,~0,~0,~0 +const uint32 ALIGN16 g_SIMD_Low16BitsMask[4]= { 0xffff, 0xffff, 0xffff, 0xffff }; // 0xffff x 4 -const int32 ALIGN16 g_SIMD_ComponentMask[4][4] = +const uint32 ALIGN16 g_SIMD_ComponentMask[4][4] = { { 0xFFFFFFFF, 0, 0, 0 }, { 0, 0xFFFFFFFF, 0, 0 }, { 0, 0, 0xFFFFFFFF, 0 }, { 0, 0, 0, 0xFFFFFFFF } }; -const int32 ALIGN16 g_SIMD_SkipTailMask[4][4] = +const uint32 ALIGN16 g_SIMD_SkipTailMask[4][4] = { { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }, { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 }, diff --git a/public/mathlib/mathlib.h b/public/mathlib/mathlib.h index cbc15424..96bb3a30 100644 --- a/public/mathlib/mathlib.h +++ b/public/mathlib/mathlib.h @@ -328,7 +328,7 @@ void inline SinCos( float radians, float *sine, float *cosine ) fstp DWORD PTR [eax] } #elif defined ( _LINUX ) || defined ( __APPLE__ ) - register double __cosr, __sinr; + double __cosr, __sinr; __asm __volatile__ ("fsincos" : "=t" (__cosr), "=u" (__sinr) : "0" (radians)); @@ -1548,7 +1548,7 @@ float Hermite_Spline( float t ); -void Hermite_SplineBasis( float t, float basis[] ); +void Hermite_SplineBasis( float t, float basis[4] ); void Hermite_Spline( const Quaternion &q0, diff --git a/public/mathlib/ssemath.h b/public/mathlib/ssemath.h index 98889df5..a767e356 100644 --- a/public/mathlib/ssemath.h +++ b/public/mathlib/ssemath.h @@ -170,17 +170,17 @@ extern const fltx4 Four_Negative_FLT_MAX; // -FLT_MAX, -FLT_MAX, -FLT_MAX, extern const fltx4 g_SIMD_0123; // 0 1 2 3 as float // external aligned integer constants -extern const ALIGN16 int32 g_SIMD_clear_signmask[]; // 0x7fffffff x 4 -extern const ALIGN16 int32 g_SIMD_signmask[]; // 0x80000000 x 4 -extern const ALIGN16 int32 g_SIMD_lsbmask[]; // 0xfffffffe x 4 -extern const ALIGN16 int32 g_SIMD_clear_wmask[]; // -1 -1 -1 0 -extern const ALIGN16 int32 g_SIMD_ComponentMask[4][4]; // [0xFFFFFFFF 0 0 0], [0 0xFFFFFFFF 0 0], [0 0 0xFFFFFFFF 0], [0 0 0 0xFFFFFFFF] -extern const ALIGN16 int32 g_SIMD_AllOnesMask[]; // ~0,~0,~0,~0 -extern const ALIGN16 int32 g_SIMD_Low16BitsMask[]; // 0xffff x 4 +extern const ALIGN16 uint32 g_SIMD_clear_signmask[]; // 0x7fffffff x 4 +extern const ALIGN16 uint32 g_SIMD_signmask[]; // 0x80000000 x 4 +extern const ALIGN16 uint32 g_SIMD_lsbmask[]; // 0xfffffffe x 4 +extern const ALIGN16 uint32 g_SIMD_clear_wmask[]; // -1 -1 -1 0 +extern const ALIGN16 uint32 g_SIMD_ComponentMask[4][4]; // [0xFFFFFFFF 0 0 0], [0 0xFFFFFFFF 0 0], [0 0 0xFFFFFFFF 0], [0 0 0 0xFFFFFFFF] +extern const ALIGN16 uint32 g_SIMD_AllOnesMask[]; // ~0,~0,~0,~0 +extern const ALIGN16 uint32 g_SIMD_Low16BitsMask[]; // 0xffff x 4 // this mask is used for skipping the tail of things. If you have N elements in an array, and wish // to mask out the tail, g_SIMD_SkipTailMask[N & 3] what you want to use for the last iteration. -extern const int32 ALIGN16 g_SIMD_SkipTailMask[4][4]; +extern const uint32 ALIGN16 g_SIMD_SkipTailMask[4][4]; // Define prefetch macros. // The characteristics of cache and prefetch are completely diff --git a/public/mathlib/vector.h b/public/mathlib/vector.h index af9471f0..81d7feb1 100644 --- a/public/mathlib/vector.h +++ b/public/mathlib/vector.h @@ -518,9 +518,9 @@ inline void Vector::Init( vec_t ix, vec_t iy, vec_t iz ) inline void Vector::Random( vec_t minVal, vec_t maxVal ) { - x = minVal + ((float)rand() / RAND_MAX) * (maxVal - minVal); - y = minVal + ((float)rand() / RAND_MAX) * (maxVal - minVal); - z = minVal + ((float)rand() / RAND_MAX) * (maxVal - minVal); + x = minVal + ((float)rand() / VALVE_RAND_MAX) * (maxVal - minVal); + y = minVal + ((float)rand() / VALVE_RAND_MAX) * (maxVal - minVal); + z = minVal + ((float)rand() / VALVE_RAND_MAX) * (maxVal - minVal); CHECK_VALID(*this); } @@ -1854,9 +1854,9 @@ inline void QAngle::Init( vec_t ix, vec_t iy, vec_t iz ) inline void QAngle::Random( vec_t minVal, vec_t maxVal ) { - x = minVal + ((float)rand() / RAND_MAX) * (maxVal - minVal); - y = minVal + ((float)rand() / RAND_MAX) * (maxVal - minVal); - z = minVal + ((float)rand() / RAND_MAX) * (maxVal - minVal); + x = minVal + ((float)rand() / VALVE_RAND_MAX) * (maxVal - minVal); + y = minVal + ((float)rand() / VALVE_RAND_MAX) * (maxVal - minVal); + z = minVal + ((float)rand() / VALVE_RAND_MAX) * (maxVal - minVal); CHECK_VALID(*this); } diff --git a/public/mathlib/vector2d.h b/public/mathlib/vector2d.h index cf37edf7..4de33424 100644 --- a/public/mathlib/vector2d.h +++ b/public/mathlib/vector2d.h @@ -239,8 +239,8 @@ inline void Vector2D::Init( vec_t ix, vec_t iy ) inline void Vector2D::Random( float minVal, float maxVal ) { - x = minVal + ((float)rand() / RAND_MAX) * (maxVal - minVal); - y = minVal + ((float)rand() / RAND_MAX) * (maxVal - minVal); + x = minVal + ((float)rand() / VALVE_RAND_MAX) * (maxVal - minVal); + y = minVal + ((float)rand() / VALVE_RAND_MAX) * (maxVal - minVal); } inline void Vector2DClear( Vector2D& a ) diff --git a/public/mathlib/vector4d.h b/public/mathlib/vector4d.h index b9b3aa44..85fb6da1 100644 --- a/public/mathlib/vector4d.h +++ b/public/mathlib/vector4d.h @@ -249,10 +249,10 @@ inline void Vector4D::Init( vec_t ix, vec_t iy, vec_t iz, vec_t iw ) inline void Vector4D::Random( vec_t minVal, vec_t maxVal ) { - x = minVal + ((vec_t)rand() / RAND_MAX) * (maxVal - minVal); - y = minVal + ((vec_t)rand() / RAND_MAX) * (maxVal - minVal); - z = minVal + ((vec_t)rand() / RAND_MAX) * (maxVal - minVal); - w = minVal + ((vec_t)rand() / RAND_MAX) * (maxVal - minVal); + x = minVal + ((vec_t)rand() / VALVE_RAND_MAX) * (maxVal - minVal); + y = minVal + ((vec_t)rand() / VALVE_RAND_MAX) * (maxVal - minVal); + z = minVal + ((vec_t)rand() / VALVE_RAND_MAX) * (maxVal - minVal); + w = minVal + ((vec_t)rand() / VALVE_RAND_MAX) * (maxVal - minVal); } inline void Vector4DClear( Vector4D& a ) diff --git a/public/tier0/platform.h b/public/tier0/platform.h index 95778f50..0722708d 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -204,6 +204,12 @@ typedef unsigned int uint; #define abstract_class class NO_VTABLE #endif + +// MSVC CRT uses 0x7fff while gcc uses MAX_INT, leading to mismatches between platforms +// As a result, we pick the least common denominator here. This should be used anywhere +// you might typically want to use RAND_MAX +#define VALVE_RAND_MAX 0x7fff + /* FIXME: Enable this when we no longer fear change =) @@ -472,6 +478,42 @@ typedef void * HINSTANCE; #endif +#ifdef POSIX +#define _stricmp stricmp +#define strcmpi stricmp +#define stricmp strcasecmp +#define _vsnprintf vsnprintf +#define _alloca alloca +#ifdef _snprintf +#undef _snprintf +#endif +#define _snprintf snprintf +#define GetProcAddress dlsym +#define _chdir chdir +#define _strnicmp strnicmp +#define strnicmp strncasecmp +#define _getcwd getcwd +#define _snwprintf swprintf +#define swprintf_s swprintf +#define wcsicmp _wcsicmp +#define _wcsicmp wcscmp +#define _finite finite +#define _tempnam tempnam +#define _unlink unlink +#define _access access +#define _mkdir(dir) mkdir( dir, S_IRWXU | S_IRWXG | S_IRWXO ) +#define _wtoi(arg) wcstol(arg, NULL, 10) +#define _wtoi64(arg) wcstoll(arg, NULL, 10) + +#define _O_RDONLY O_RDONLY + +#define _stat stat +#define _open open +#define _lseek lseek +#define _read read +#define _close close +#endif + //----------------------------------------------------------------------------- // fsel //----------------------------------------------------------------------------- diff --git a/tier1/AMBuilder b/tier1/AMBuilder new file mode 100644 index 00000000..45ba79d3 --- /dev/null +++ b/tier1/AMBuilder @@ -0,0 +1,54 @@ +# vim: set ts=2 sw=2 tw=99 noet ft=python: +import os, sys + +builder.SetBuildFolder('/') + +project = builder.StaticLibraryProject('tier1') + +project.sources = [ + 'bitbuf.cpp', + 'byteswap.cpp', + 'characterset.cpp', + 'checksum_crc.cpp', + 'checksum_md5.cpp', + 'commandbuffer.cpp', + 'convar.cpp', + 'datamanager.cpp', + 'diff.cpp', + 'generichash.cpp', + 'interface.cpp', + 'KeyValues.cpp', + 'mempool.cpp', + 'memstack.cpp', + 'NetAdr.cpp', + 'newbitbuf.cpp', + 'rangecheckedvar.cpp', + 'stringpool.cpp', + 'strtools.cpp', + 'tier1.cpp', + 'tokenreader.cpp', + 'undiff.cpp', + 'uniqueid.cpp', + 'utlbuffer.cpp', + 'utlbufferutil.cpp', + 'utlstring.cpp', + 'utlsymbol.cpp' +] + +for cxx in HL2SDK.targets: + binary = HL2SDK.ConfigureLibrary(project, cxx, builder) + compiler = binary.compiler + + if compiler.target.platform == 'linux': + binary.sources += ['processor_detect_linux.cpp'] + else: + binary.sources += ['processor_detect.cpp'] + + compiler.cxxincludes += [ + os.path.join(builder.currentSourcePath, '..', 'common'), + os.path.join(builder.currentSourcePath, '..', 'public'), + os.path.join(builder.currentSourcePath, '..', 'public', 'tier0'), + os.path.join(builder.currentSourcePath, '..', 'public', 'tier1') + ] + +HL2SDK.libs += builder.Add(project) \ No newline at end of file diff --git a/tier1/checksum_md5.cpp b/tier1/checksum_md5.cpp index fc0961af..303d92b0 100644 --- a/tier1/checksum_md5.cpp +++ b/tier1/checksum_md5.cpp @@ -36,7 +36,7 @@ //----------------------------------------------------------------------------- static void MD5Transform(unsigned int buf[4], unsigned int const in[16]) { - register unsigned int a, b, c, d; + unsigned int a, b, c, d; a = buf[0]; b = buf[1]; diff --git a/tier1/generichash.cpp b/tier1/generichash.cpp index 2bc242c2..43667d42 100644 --- a/tier1/generichash.cpp +++ b/tier1/generichash.cpp @@ -137,7 +137,7 @@ unsigned FASTCALL HashStringCaselessConventional( const char *pszKey ) //----------------------------------------------------------------------------- unsigned FASTCALL HashInt( const int n ) { - register unsigned even, odd; + unsigned even, odd; even = g_nRandomValues[n & 0xff]; odd = g_nRandomValues[((n >> 8) & 0xff)]; @@ -154,10 +154,10 @@ unsigned FASTCALL HashInt( const int n ) //----------------------------------------------------------------------------- unsigned FASTCALL Hash4( const void *pKey ) { - register const uint32 * p = (const uint32 *) pKey; - register unsigned even, - odd, - n; + const uint32 * p = (const uint32 *) pKey; + unsigned even, + odd, + n; n = *p; even = g_nRandomValues[n & 0xff]; odd = g_nRandomValues[((n >> 8) & 0xff)]; @@ -176,10 +176,10 @@ unsigned FASTCALL Hash4( const void *pKey ) //----------------------------------------------------------------------------- unsigned FASTCALL Hash8( const void *pKey ) { - register const uint32 * p = (const uint32 *) pKey; - register unsigned even, - odd, - n; + const uint32 * p = (const uint32 *) pKey; + unsigned even, + odd, + n; n = *p; even = g_nRandomValues[n & 0xff]; odd = g_nRandomValues[((n >> 8) & 0xff)]; @@ -204,10 +204,10 @@ unsigned FASTCALL Hash8( const void *pKey ) //----------------------------------------------------------------------------- unsigned FASTCALL Hash12( const void *pKey ) { - register const uint32 * p = (const uint32 *) pKey; - register unsigned even, - odd, - n; + const uint32 * p = (const uint32 *) pKey; + unsigned even, + odd, + n; n = *p; even = g_nRandomValues[n & 0xff]; odd = g_nRandomValues[((n >> 8) & 0xff)]; @@ -238,10 +238,10 @@ unsigned FASTCALL Hash12( const void *pKey ) //----------------------------------------------------------------------------- unsigned FASTCALL Hash16( const void *pKey ) { - register const uint32 * p = (const uint32 *) pKey; - register unsigned even, - odd, - n; + const uint32 * p = (const uint32 *) pKey; + unsigned even, + odd, + n; n = *p; even = g_nRandomValues[n & 0xff]; odd = g_nRandomValues[((n >> 8) & 0xff)]; diff --git a/tier1/utlsymbol.cpp b/tier1/utlsymbol.cpp index 129d7765..bdb951cf 100644 --- a/tier1/utlsymbol.cpp +++ b/tier1/utlsymbol.cpp @@ -130,10 +130,16 @@ bool CUtlSymbolTable::CLess::operator()( const CStringPoolIndex &i1, const CStri const char* str2 = (i2 == INVALID_STRING_INDEX) ? pTable->m_pUserSearchString : pTable->StringFromIndex( i2 ); + if ( !str1 && str2 ) + return false; + if ( !str2 && str1 ) + return true; + if ( !str1 && !str2 ) + return false; if ( !pTable->m_bInsensitive ) - return strcmp( str1, str2 ) < 0; + return V_strcmp( str1, str2 ) < 0; else - return strcmpi( str1, str2 ) < 0; + return V_stricmp( str1, str2 ) < 0; }