From b6de5bb71206cd2e6c64a87f7fc8c1f44200560c Mon Sep 17 00:00:00 2001 From: Caroline Joy Bell Date: Mon, 9 Jan 2023 08:57:09 -0800 Subject: [PATCH 01/29] Create tasks.json Enables Visual Studio code integration with Waf for configure and build. --- .vscode/tasks.json | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..5fa3b6e3 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Configure Waf for host OS: x86", + "type": "shell", + "problemMatcher": [], + "command": "./waf configure -T release --prefix=out/", + "windows": { + "command": "./waf.bat configure -T release --prefix=out/" + } + }, + { + "label": "Configure Waf for host OS: x86_64", + "type": "shell", + "problemMatcher": [], + "command": "./waf configure -T release --64bits --prefix=out/", + "windows": { + "command": "./waf.bat configure -T release --64bits --prefix=out/" + } + }, + { + "label": "Configure Waf for outdated Android", + "type": "shell", + "problemMatcher": [], + "command": "./waf configure -T release --android=armeabi-v7a-hard,4.9,21", + "windows": { + "command": "echo \"Not supported on Windows.\"" + } + }, + { + "label": "Build", + "type": "shell", + "problemMatcher": [], + "command": "./waf install", + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} From edb08661f26936dcac08eeca08e56910db181d26 Mon Sep 17 00:00:00 2001 From: Caroline Joy Bell Date: Thu, 12 Jan 2023 21:15:42 -0800 Subject: [PATCH 02/29] Update tasks.json Addresses some comments by @exstrim401. These changes were made through GitHub's editor, they have not been tested. --- .vscode/tasks.json | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 5fa3b6e3..d4f801a0 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,28 +2,28 @@ "version": "2.0.0", "tasks": [ { - "label": "Configure Waf for host OS: x86", + "label": "Configure Waf for Debug 32-bit", "type": "shell", + "command": "./waf configure -T debug --prefix=out/", "problemMatcher": [], - "command": "./waf configure -T release --prefix=out/", "windows": { - "command": "./waf.bat configure -T release --prefix=out/" + "command": "./waf.bat configure -T debug --prefix=out/" } }, { - "label": "Configure Waf for host OS: x86_64", + "label": "Configure Waf for Debug 64-bit", "type": "shell", + "command": "./waf configure -T debug --64bits --prefix=out/", "problemMatcher": [], - "command": "./waf configure -T release --64bits --prefix=out/", "windows": { - "command": "./waf.bat configure -T release --64bits --prefix=out/" + "command": "./waf.bat configure -T debug --64bits --prefix=out/" } }, { - "label": "Configure Waf for outdated Android", + "label": "Configure Waf for Debug on outdated Android", "type": "shell", - "problemMatcher": [], "command": "./waf configure -T release --android=armeabi-v7a-hard,4.9,21", + "problemMatcher": [], "windows": { "command": "echo \"Not supported on Windows.\"" } @@ -31,11 +31,21 @@ { "label": "Build", "type": "shell", - "problemMatcher": [], "command": "./waf install", + "problemMatcher": { + "base": "$gcc", + "fileLocation": ["relative", "${workspaceFolder}/build"] + }, "group": { "kind": "build", "isDefault": true + }, + "windows": { + "command": "./waf.bat install", + "problemMatcher": { + "base": "$msCompile", + "fileLocation": ["relative", "${workspaceFolder}/build"] + } } } ] From ef9f4b2965fee47234a033b0f9e8d453b558da41 Mon Sep 17 00:00:00 2001 From: Caroline Joy Bell Date: Thu, 12 Jan 2023 21:34:29 -0800 Subject: [PATCH 03/29] Update tasks.json Adds macOS-specific commands --- .vscode/tasks.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index d4f801a0..c045c688 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -8,6 +8,9 @@ "problemMatcher": [], "windows": { "command": "./waf.bat configure -T debug --prefix=out/" + }, + "osx": { + "command": "python3 waf configure -T debug --prefix=out/" } }, { @@ -17,6 +20,9 @@ "problemMatcher": [], "windows": { "command": "./waf.bat configure -T debug --64bits --prefix=out/" + }, + "osx": { + "command": "python3 waf configure -T debug --64bits --prefix=out/" } }, { @@ -46,6 +52,9 @@ "base": "$msCompile", "fileLocation": ["relative", "${workspaceFolder}/build"] } + }, + "osx": { + "command": "python3 waf install" } } ] From 02c60cf2c7bb44d9eb25affd960b331230305467 Mon Sep 17 00:00:00 2001 From: Caroline Joy Bell Date: Thu, 12 Jan 2023 21:38:45 -0800 Subject: [PATCH 04/29] Update tasks.json Adding commands for Android build on Windows and macOS just in case it's now supported. This will just result in an error if it's not supported anyway. --- .vscode/tasks.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c045c688..0e74f0cb 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -31,7 +31,10 @@ "command": "./waf configure -T release --android=armeabi-v7a-hard,4.9,21", "problemMatcher": [], "windows": { - "command": "echo \"Not supported on Windows.\"" + "command": "./waf.bat configure -T release --android=armeabi-v7a-hard,4.9,21" + }, + "osx": { + "command": "python3 waf configure -T release --android=armeabi-v7a-hard,4.9,21" } }, { From ecfe257da2b470c1d67ab7b357a27a6b661c562a Mon Sep 17 00:00:00 2001 From: Caroline Joy Bell Date: Fri, 13 Jan 2023 07:50:03 -0800 Subject: [PATCH 05/29] Update tasks.json --- .vscode/tasks.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0e74f0cb..5b236400 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -26,7 +26,7 @@ } }, { - "label": "Configure Waf for Debug on outdated Android", + "label": "Configure Waf for Debug on Android (NDK r10e)", "type": "shell", "command": "./waf configure -T release --android=armeabi-v7a-hard,4.9,21", "problemMatcher": [], From d7a2277804cb0d992b1a1c6dfd050064b16d4fec Mon Sep 17 00:00:00 2001 From: Caroline Joy Bell Date: Fri, 13 Jan 2023 08:00:04 -0800 Subject: [PATCH 06/29] Update tasks.json --- .vscode/tasks.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 5b236400..8dc70c0c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,22 +7,22 @@ "command": "./waf configure -T debug --prefix=out/", "problemMatcher": [], "windows": { - "command": "./waf.bat configure -T debug --prefix=out/" + "command": "./waf.bat configure -T debug --prefix=build/out/" }, "osx": { - "command": "python3 waf configure -T debug --prefix=out/" + "command": "python3 waf configure -T debug --prefix=build/out/" } }, { "label": "Configure Waf for Debug 64-bit", "type": "shell", - "command": "./waf configure -T debug --64bits --prefix=out/", + "command": "./waf configure -T debug --64bits --prefix=build/out/", "problemMatcher": [], "windows": { - "command": "./waf.bat configure -T debug --64bits --prefix=out/" + "command": "./waf.bat configure -T debug --64bits --prefix=build/out/" }, "osx": { - "command": "python3 waf configure -T debug --64bits --prefix=out/" + "command": "python3 waf configure -T debug --64bits --prefix=build/out/" } }, { From de32c758c15f12508241e276056a73f6ceb99731 Mon Sep 17 00:00:00 2001 From: Caroline Joy Bell Date: Fri, 13 Jan 2023 21:02:02 -0800 Subject: [PATCH 07/29] Update tasks.json Thought I already did this --- .vscode/tasks.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 8dc70c0c..c1047249 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -28,13 +28,13 @@ { "label": "Configure Waf for Debug on Android (NDK r10e)", "type": "shell", - "command": "./waf configure -T release --android=armeabi-v7a-hard,4.9,21", + "command": "./waf configure -T debug --android=armeabi-v7a-hard,4.9,21", "problemMatcher": [], "windows": { - "command": "./waf.bat configure -T release --android=armeabi-v7a-hard,4.9,21" + "command": "./waf.bat configure -T debug --android=armeabi-v7a-hard,4.9,21" }, "osx": { - "command": "python3 waf configure -T release --android=armeabi-v7a-hard,4.9,21" + "command": "python3 waf configure -T debug --android=armeabi-v7a-hard,4.9,21" } }, { From 88cf25ff80004f20fe36c05991ec97be1cf43c67 Mon Sep 17 00:00:00 2001 From: Caroline Joy Bell Date: Mon, 16 Jan 2023 07:54:17 -0800 Subject: [PATCH 08/29] Update tasks.json --- .vscode/tasks.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c1047249..3687eab4 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,7 +4,7 @@ { "label": "Configure Waf for Debug 32-bit", "type": "shell", - "command": "./waf configure -T debug --prefix=out/", + "command": "./waf configure -T debug --prefix=build/out/", "problemMatcher": [], "windows": { "command": "./waf.bat configure -T debug --prefix=build/out/" From 99cad5f7d11d3add2a6cd8dda506ad1f07ba6f2e Mon Sep 17 00:00:00 2001 From: nillerusr Date: Tue, 18 Apr 2023 21:53:37 +0000 Subject: [PATCH 09/29] update ivp submodule --- ivp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivp b/ivp index 960c7228..b5bc8099 160000 --- a/ivp +++ b/ivp @@ -1 +1 @@ -Subproject commit 960c7228f8e8d710625891991e88b1ec3aa92e45 +Subproject commit b5bc80990d4894a37a4985c0a134ebf878200247 From 89af23bdfb1e566555d6915c271ea45958cf1782 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Tue, 18 Apr 2023 23:48:15 +0000 Subject: [PATCH 10/29] finally fix fucking ragdolls --- ivp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivp b/ivp index b5bc8099..066d8ad9 160000 --- a/ivp +++ b/ivp @@ -1 +1 @@ -Subproject commit b5bc80990d4894a37a4985c0a134ebf878200247 +Subproject commit 066d8ad98425549bb9d107a2fa6f00db49818513 From 7d00b0404f50d8ad24ba297a84bda37503b4b785 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Fri, 21 Apr 2023 01:52:04 +0300 Subject: [PATCH 11/29] update ivp submodule --- ivp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivp b/ivp index 066d8ad9..bceb2c42 160000 --- a/ivp +++ b/ivp @@ -1 +1 @@ -Subproject commit 066d8ad98425549bb9d107a2fa6f00db49818513 +Subproject commit bceb2c427255f181a2538ca43369989aa0d983d7 From 1ccbe2bbb62cf9ef10bb113f0ff9d24672ed5721 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Sun, 23 Apr 2023 23:45:09 +0300 Subject: [PATCH 12/29] unitests: add mathlib test --- .../mathlibtest/mathlib_performance_test.cpp | 41 ++++++++++++++++++ unittests/mathlibtest/mathlib_test.cpp | 43 +++++++++++++++++++ unittests/mathlibtest/wscript | 39 +++++++++++++++++ wscript | 2 + 4 files changed, 125 insertions(+) create mode 100644 unittests/mathlibtest/mathlib_performance_test.cpp create mode 100644 unittests/mathlibtest/mathlib_test.cpp create mode 100755 unittests/mathlibtest/wscript diff --git a/unittests/mathlibtest/mathlib_performance_test.cpp b/unittests/mathlibtest/mathlib_performance_test.cpp new file mode 100644 index 00000000..6058ed25 --- /dev/null +++ b/unittests/mathlibtest/mathlib_performance_test.cpp @@ -0,0 +1,41 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Unit test program for CommandBuffer +// +// $NoKeywords: $ +//=============================================================================// + +#include "unitlib/unitlib.h" +#include "tier1/CommandBuffer.h" +#include "tier1/strtools.h" +#include "tier0/platform.h" +#include "tier0/fasttimer.h" + + +DEFINE_TESTSUITE( MathlibTestSuite ) + +DEFINE_TESTCASE( MathlibTestSSE, MathlibTestSuite ) +{ + CFastTimer timer; + timer.Start(); + + float sum = 0.f; + + for( float a = 0.f; a <= M_PI; a += 0.000001f ) + sum += sinf(a); + + timer.End(); + + Msg("cos Cycles: %llu\n", timer.GetDuration().GetLongCycles()); + Msg("cos sum - %f\n", sum); + + timer.Start(); + + for( float a = 0.f; a <= M_PI; a += 0.000001f ) + sum += FastCos(a); + + timer.End(); + + Msg("ssecos Cycles: %llu\n", timer.GetDuration().GetLongCycles()); + Msg("ssecos sum - %f\n", sum); +} diff --git a/unittests/mathlibtest/mathlib_test.cpp b/unittests/mathlibtest/mathlib_test.cpp new file mode 100644 index 00000000..36d01847 --- /dev/null +++ b/unittests/mathlibtest/mathlib_test.cpp @@ -0,0 +1,43 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Unit test program for testing of mathlib +// +// $NoKeywords: $ +//=============================================================================// + +#include "unitlib/unitlib.h" +#include "filesystem.h" +#include "tier2/tier2.h" +#include "mathlib/mathlib.h" + +//----------------------------------------------------------------------------- +// Used to connect/disconnect the DLL +//----------------------------------------------------------------------------- +class CTier2TestAppSystem : public CTier2AppSystem< IAppSystem > +{ + typedef CTier2AppSystem< IAppSystem > BaseClass; + +public: + virtual bool Connect( CreateInterfaceFn factory ) + { + if ( !BaseClass::Connect( factory ) ) + return false; + + if ( !g_pFullFileSystem ) + return false; + return true; + } + + virtual InitReturnVal_t Init() + { + MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f ); + + InitReturnVal_t nRetVal = BaseClass::Init(); + if ( nRetVal != INIT_OK ) + return nRetVal; + + return INIT_OK; + } +}; + +USE_UNITTEST_APPSYSTEM( CTier2TestAppSystem ) diff --git a/unittests/mathlibtest/wscript b/unittests/mathlibtest/wscript new file mode 100755 index 00000000..5015ee71 --- /dev/null +++ b/unittests/mathlibtest/wscript @@ -0,0 +1,39 @@ +#! /usr/bin/env python +# encoding: utf-8 + +from waflib import Utils +import os + +top = '.' +PROJECT_NAME = 'mathlibtest' + +def options(opt): + return + +def configure(conf): + conf.define('TIER2TEST_EXPORTS', 1) + +def build(bld): + source = ['mathlib_performance_test.cpp', 'mathlib_test.cpp'] + includes = ['../../public', '../../public/tier0'] + defines = [] + libs = ['tier0', 'tier1','tier2', 'mathlib', 'unitlib'] + + if bld.env.DEST_OS != 'win32': + libs += [ 'DL', 'LOG' ] + else: + libs += ['USER32', 'SHELL32'] + + install_path = bld.env.TESTDIR + bld.shlib( + source = source, + target = PROJECT_NAME, + name = PROJECT_NAME, + features = 'c cxx', + includes = includes, + defines = defines, + use = libs, + install_path = install_path, + subsystem = bld.env.MSVC_SUBSYSTEM, + idx = bld.get_taskgen_count() + ) diff --git a/wscript b/wscript index ef760ccc..7441473c 100644 --- a/wscript +++ b/wscript @@ -51,6 +51,7 @@ projects={ 'launcher', 'launcher_main', 'materialsystem', +# 'materialsystem/shaderapiempty', 'materialsystem/shaderapidx9', 'materialsystem/shaderlib', 'materialsystem/stdshaders', @@ -94,6 +95,7 @@ projects={ 'unittests/tier1test', 'unittests/tier2test', 'unittests/tier3test', + 'unittests/mathlibtest', 'utils/unittest' ], 'dedicated': [ From f2fa241ae67b312ed73883830e7f1eaafa8959b4 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Mon, 24 Apr 2023 16:06:58 +0000 Subject: [PATCH 13/29] add macos workflow, fix filesystem_async max thread count --- .github/workflows/build.yml | 18 +++++++++++++++ .github/workflows/tests.yml | 9 ++++++++ appframework/sdlmgr.cpp | 2 +- appframework/wscript | 9 ++++---- bitmap/ImageByteSwap.cpp | 14 +++--------- bitmap/imageformat.cpp | 2 -- filesystem/filesystem_async.cpp | 11 +++++---- scripts/build-macos-amd64.sh | 8 +++++++ scripts/tests-macos-amd64.sh | 7 ++++++ tier2/renderutils.cpp | 2 +- utils/unittest/unittest.cpp | 2 +- wscript | 40 ++++++++++++++++++--------------- 12 files changed, 79 insertions(+), 45 deletions(-) create mode 100755 scripts/build-macos-amd64.sh create mode 100755 scripts/tests-macos-amd64.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0c29e52e..39c8aadd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -91,3 +91,21 @@ jobs: - name: Build dedicated linux-amd64 run: | scripts/build-ubuntu-amd64.sh -d + + build-macos-amd64: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + - name: Build macos-amd64 + run: | + scripts/build-macos-amd64.sh + + build-dedicated-macos-amd64: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + - name: Build dedicated macos-amd64 + run: | + scripts/build-macos-amd64.sh -d diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c21d0a55..d8adc5ab 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,6 +21,15 @@ jobs: run: | scripts/tests-ubuntu-amd64.sh + tests-macos-amd64: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + - name: Run tests macos-amd64 + run: | + scripts/tests-macos-amd64.sh + tests-windows-i386: runs-on: windows-2019 diff --git a/appframework/sdlmgr.cpp b/appframework/sdlmgr.cpp index bad06f1b..dd5ee2c2 100644 --- a/appframework/sdlmgr.cpp +++ b/appframework/sdlmgr.cpp @@ -2224,7 +2224,7 @@ GLMDisplayDB *CSDLMgr::GetDisplayDB( void ) } #ifndef OSX -# include "glmdisplaydb_linuxwin.inl" +#include "glmdisplaydb_linuxwin.inl" #endif diff --git a/appframework/wscript b/appframework/wscript index 0fea261a..f8ded318 100755 --- a/appframework/wscript +++ b/appframework/wscript @@ -24,11 +24,10 @@ def build(bld): source += [ 'sdlmgr.cpp' ] - - if bld.env.DEST_OS == 'darwin': - source += [ - 'glmrendererinfo_osx.mm' - ] + + if bld.env.DEST_OS == 'darwin' and bld.env.GL: + source += ['glmrendererinfo_osx.mm'] + if bld.env.DEST_OS == 'win32': source += [ diff --git a/bitmap/ImageByteSwap.cpp b/bitmap/ImageByteSwap.cpp index 57217f15..44fc5fa6 100644 --- a/bitmap/ImageByteSwap.cpp +++ b/bitmap/ImageByteSwap.cpp @@ -88,14 +88,7 @@ namespace ImageLoader Assert( IsFormatValidForConversion( imageFormat ) ); -#if !defined( DX_TO_GL_ABSTRACTION ) && !defined( NO_X360_XDK ) - if ( IsPC() ) - { - // running as a win32 tool, data is in expected order - // for conversion code - return; - } - +#ifdef _X360 // running on 360 and converting, input data must be x86 order // swap to ensure conversion code gets valid data XGENDIANTYPE xEndian; @@ -137,7 +130,7 @@ namespace ImageLoader { Assert( IsFormatValidForConversion( imageFormat ) ); -#if !defined( DX_TO_GL_ABSTRACTION ) && !defined( NO_X360_XDK ) +#ifdef _X360 // It would have been nice to use the 360 D3DFORMAT bit encodings, but the codes // are different for win32, and this routine is used by a win32 library to // manipulate 360 data, so there can be no reliance on D3DFORMAT bits @@ -201,7 +194,7 @@ namespace ImageLoader { Assert( IsFormatValidForConversion( imageFormat ) ); -#if !defined( DX_TO_GL_ABSTRACTION ) && !defined( NO_X360_XDK ) +#ifdef _X360 XGENDIANTYPE xEndian; switch ( imageFormat ) { @@ -256,5 +249,4 @@ namespace ImageLoader } #endif } - } diff --git a/bitmap/imageformat.cpp b/bitmap/imageformat.cpp index c2222653..6e2c99c1 100644 --- a/bitmap/imageformat.cpp +++ b/bitmap/imageformat.cpp @@ -288,13 +288,11 @@ int GetNumMipMapLevels( int width, int height, int depth ) // Turn off warning about FOURCC formats below... #pragma warning (disable:4063) -#ifdef DX_TO_GL_ABSTRACTION #ifndef MAKEFOURCC #define MAKEFOURCC(ch0, ch1, ch2, ch3) \ ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \ ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 )) #endif //defined(MAKEFOURCC) -#endif //----------------------------------------------------------------------------- // convert back and forth from D3D format to ImageFormat, regardless of // whether it's supported or not diff --git a/filesystem/filesystem_async.cpp b/filesystem/filesystem_async.cpp index 769ed017..493b1b70 100644 --- a/filesystem/filesystem_async.cpp +++ b/filesystem/filesystem_async.cpp @@ -659,8 +659,9 @@ void CBaseFileSystem::InitAsync() Msg( "Async I/O disabled from command line\n" ); return; } - +#ifndef UNITTESTS if ( VCRGetMode() == VCR_Disabled ) +#endif { // create the i/o thread pool m_pThreadPool = CreateThreadPool(); @@ -668,7 +669,6 @@ void CBaseFileSystem::InitAsync() ThreadPoolStartParams_t params; params.iThreadPriority = 0; params.bIOThreads = true; - params.nThreadsMax = 4; // Limit count of IO threads to a maximum of 4. if ( IsX360() ) { // override defaults @@ -678,11 +678,10 @@ void CBaseFileSystem::InitAsync() params.bUseAffinityTable = true; params.iAffinityTable[0] = XBOX_PROCESSOR_3; } - else if( IsPC() ) + else { - // override defaults - // maximum # of async I/O thread on PC is 2 - params.nThreads = 1; + params.nThreadsMax = MIN(params.nThreads, 4); // Limit count of IO threads to a maximum of 4. + params.nStackSize = 256*1024; } if ( !m_pThreadPool->Start( params, "IOJob" ) ) diff --git a/scripts/build-macos-amd64.sh b/scripts/build-macos-amd64.sh new file mode 100755 index 00000000..de0e8cfd --- /dev/null +++ b/scripts/build-macos-amd64.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +git submodule init && git submodule update + +brew install sdl2 + +./waf configure -T debug --64bits --disable-warns $* && +./waf build diff --git a/scripts/tests-macos-amd64.sh b/scripts/tests-macos-amd64.sh new file mode 100755 index 00000000..ff4e46b2 --- /dev/null +++ b/scripts/tests-macos-amd64.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +git submodule init && git submodule update +./waf configure -T release --sanitize=address,undefined --disable-warns --tests -8 --prefix=out/ $* && +./waf install && +cd out && +DYLD_LIBRARY_PATH=bin/ ./unittest || exit 1 diff --git a/tier2/renderutils.cpp b/tier2/renderutils.cpp index 9b35e9fb..1c4870d8 100644 --- a/tier2/renderutils.cpp +++ b/tier2/renderutils.cpp @@ -12,7 +12,7 @@ #include "materialsystem/imaterial.h" #include "tier0/vprof.h" #include "tier0/basetypes.h" -#ifndef DEDICATED +#ifdef DX_TO_GL_ABSTRACTION #include "togl/rendermechanism.h" #endif diff --git a/utils/unittest/unittest.cpp b/utils/unittest/unittest.cpp index 9135c67c..898e86e7 100644 --- a/utils/unittest/unittest.cpp +++ b/utils/unittest/unittest.cpp @@ -128,7 +128,7 @@ bool CUnitTestApp::Create() while ((dir = readdir(d)) != NULL) { int len = strlen(dir->d_name); - if( len > 2 && strcmp(dir->d_name+len-3, ".so") == 0) + if( len > 2 && strcmp(dir->d_name+len-strlen(DLL_EXT_STRING), DLL_EXT_STRING) == 0) { static char path[2048]; snprintf(path, sizeof(path), "tests/%s", dir->d_name); diff --git a/wscript b/wscript index 7441473c..ada484c5 100644 --- a/wscript +++ b/wscript @@ -159,15 +159,17 @@ def define_platform(conf): conf.env.DEDICATED = conf.options.DEDICATED conf.env.TESTS = conf.options.TESTS conf.env.TOGLES = conf.options.TOGLES - conf.env.GL = conf.options.GL + conf.env.GL = conf.options.GL and not conf.options.TESTS and not conf.options.DEDICATED conf.env.OPUS = conf.options.OPUS if conf.options.DEDICATED: conf.options.SDL = False -# conf.options.GL = False conf.define('DEDICATED', 1) - if conf.options.GL and not conf.options.TESTS: + if conf.options.TESTS: + conf.define('UNITTESTS', 1) + + if conf.env.GL: conf.env.append_unique('DEFINES', [ 'DX_TO_GL_ABSTRACTION', 'GL_GLEXT_PROTOTYPES', @@ -177,6 +179,9 @@ def define_platform(conf): if conf.options.TOGLES: conf.env.append_unique('DEFINES', ['TOGLES']) + if conf.options.TESTS: + conf.define('UNITTESTS', 1) + if conf.options.SDL and not conf.options.TESTS: conf.env.SDL = 1 conf.define('USE_SDL', 1) @@ -323,6 +328,20 @@ def check_deps(conf): for i in a: conf.check_cc(lib = i) + if conf.env.DEST_OS == "darwin": + conf.check(lib='iconv', uselib_store='ICONV') + conf.env.FRAMEWORK_APPKIT = "AppKit" + conf.env.FRAMEWORK_IOKIT = "IOKit" + conf.env.FRAMEWORK_FOUNDATION = "Foundation" + conf.env.FRAMEWORK_COREFOUNDATION = "CoreFoundation" + conf.env.FRAMEWORK_COREGRAPHICS = "CoreGraphics" + conf.env.FRAMEWORK_OPENGL = "OpenGL" + conf.env.FRAMEWORK_CARBON = "Carbon" + conf.env.FRAMEWORK_APPLICATIONSERVICES = "ApplicationServices" + conf.env.FRAMEWORK_CORESERVICES = "CoreServices" + conf.env.FRAMEWORK_COREAUDIO = "CoreAudio" + conf.env.FRAMEWORK_AUDIOTOOLBOX = "AudioToolbox" + conf.env.FRAMEWORK_SYSTEMCONFIGURATION = "SystemConfiguration" if conf.options.TESTS: return @@ -361,21 +380,6 @@ def check_deps(conf): conf.check(lib='android_support', uselib_store='ANDROID_SUPPORT') conf.check(lib='opus', uselib_store='OPUS') - if conf.env.DEST_OS == "darwin": - conf.check(lib='iconv', uselib_store='ICONV') - conf.env.FRAMEWORK_APPKIT = "AppKit" - conf.env.FRAMEWORK_IOKIT = "IOKit" - conf.env.FRAMEWORK_FOUNDATION = "Foundation" - conf.env.FRAMEWORK_COREFOUNDATION = "CoreFoundation" - conf.env.FRAMEWORK_COREGRAPHICS = "CoreGraphics" - conf.env.FRAMEWORK_OPENGL = "OpenGL" - conf.env.FRAMEWORK_CARBON = "Carbon" - conf.env.FRAMEWORK_APPLICATIONSERVICES = "ApplicationServices" - conf.env.FRAMEWORK_CORESERVICES = "CoreServices" - conf.env.FRAMEWORK_COREAUDIO = "CoreAudio" - conf.env.FRAMEWORK_AUDIOTOOLBOX = "AudioToolbox" - conf.env.FRAMEWORK_SYSTEMCONFIGURATION = "SystemConfiguration" - if conf.env.DEST_OS == 'win32': conf.check(lib='libz', uselib_store='ZLIB', define_name='USE_ZLIB') # conf.check(lib='nvtc', uselib_store='NVTC') From ba695d2092d06002a28faa4c25b1bb56b88d6673 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Mon, 24 Apr 2023 22:04:29 +0000 Subject: [PATCH 14/29] fix steam dick font loading --- vgui2/vgui_surfacelib/linuxfont.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/vgui2/vgui_surfacelib/linuxfont.cpp b/vgui2/vgui_surfacelib/linuxfont.cpp index aada7b4a..04703718 100644 --- a/vgui2/vgui_surfacelib/linuxfont.cpp +++ b/vgui2/vgui_surfacelib/linuxfont.cpp @@ -20,7 +20,9 @@ #include #include #include +#if HAVE_FC #include +#endif #include #include "materialsystem/imaterialsystem.h" @@ -462,10 +464,14 @@ char *TryFindFont(const char *winFontName, bool bBold, int italic) return fontFile; #else - // "platform/resource/linux_fonts/"; + bool bRegularPostfix = false; + fontName = "dejavusans"; if( strcmp( winFontName, "Courier New") == 0 ) - fontName = "liberationmono"; + { + strncpy(fontFile, "platform/resource/linux_fonts/liberationmono-regular.ttf", sizeof(fontFile)); + return fontFile; + } if( bBold ) { @@ -477,9 +483,13 @@ char *TryFindFont(const char *winFontName, bool bBold, int italic) else if( italic ) fontNamePost = "oblique"; else - fontNamePost = "regular"; + fontNamePost = NULL; + + if( fontNamePost ) + snprintf(fontFile, sizeof fontFile, "platform/resource/linux_fonts/%s-%s.ttf", fontName, fontNamePost); + else + snprintf(fontFile, sizeof fontFile, "platform/resource/linux_fonts/%s.ttf", fontName ); - snprintf(fontFile, sizeof fontFile, "platform/resource/linux_fonts/%s-%s.ttf", fontName, fontNamePost); return fontFile; #endif } @@ -498,14 +508,14 @@ char *CLinuxFont::GetFontFileName( const char *windowsFontName, int flags ) else if ( !Q_stricmp( pchFontName, "Arial Black" ) || Q_stristr( pchFontName, "bold" ) ) bBold = true; - const int italic = ( flags & vgui::ISurface::FONTFLAG_ITALIC ) ? FC_SLANT_ITALIC : FC_SLANT_ROMAN; - #if !HAVE_FC - char *filename = TryFindFont( windowsFontName, bBold, italic ); - Msg("Found font: %s\n", filename); + char *filename = TryFindFont( windowsFontName, bBold, flags & vgui::ISurface::FONTFLAG_ITALIC ); if( !filename ) return NULL; + Msg("Found font: %s\n", filename); return strdup( filename ); #else + const int italic = ( flags & vgui::ISurface::FONTFLAG_ITALIC ) ? FC_SLANT_ITALIC : FC_SLANT_ROMAN; + const int nFcWeight = bBold ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL; FcPattern *match = FontMatch( FC_FAMILY, FcTypeString, pchFontName, FC_WEIGHT, FcTypeInteger, nFcWeight, From 699271f212d3d62ed6f519d0ab887de01c17ba5f Mon Sep 17 00:00:00 2001 From: nillerusr Date: Mon, 24 Apr 2023 22:19:49 +0000 Subject: [PATCH 15/29] WIP: musl port --- common/{ => android}/freetype/freetype.h | 0 common/{ => android}/freetype/ftbbox.h | 0 common/{ => android}/freetype/ftbdf.h | 0 common/{ => android}/freetype/ftbitmap.h | 0 common/{ => android}/freetype/ftcache.h | 0 common/{ => android}/freetype/ftchapters.h | 0 common/{ => android}/freetype/fterrdef.h | 0 common/{ => android}/freetype/fterrors.h | 0 common/{ => android}/freetype/ftgasp.h | 0 common/{ => android}/freetype/ftglyph.h | 0 common/{ => android}/freetype/ftgxval.h | 0 common/{ => android}/freetype/ftgzip.h | 0 common/{ => android}/freetype/ftimage.h | 0 common/{ => android}/freetype/ftincrem.h | 0 common/{ => android}/freetype/ftlcdfil.h | 0 common/{ => android}/freetype/ftlist.h | 0 common/{ => android}/freetype/ftlzw.h | 0 common/{ => android}/freetype/ftmac.h | 0 common/{ => android}/freetype/ftmm.h | 0 common/{ => android}/freetype/ftmodapi.h | 0 common/{ => android}/freetype/ftmoderr.h | 0 common/{ => android}/freetype/ftotval.h | 0 common/{ => android}/freetype/ftoutln.h | 0 common/{ => android}/freetype/ftpfr.h | 0 common/{ => android}/freetype/ftrender.h | 0 common/{ => android}/freetype/ftsizes.h | 0 common/{ => android}/freetype/ftsnames.h | 0 common/{ => android}/freetype/ftstroke.h | 0 common/{ => android}/freetype/ftsynth.h | 0 common/{ => android}/freetype/ftsystem.h | 0 common/{ => android}/freetype/fttrigon.h | 0 common/{ => android}/freetype/fttypes.h | 0 common/{ => android}/freetype/ftwinfnt.h | 0 common/{ => android}/freetype/ftxf86.h | 0 common/{ => android}/freetype/t1tables.h | 0 common/{ => android}/freetype/ttnameid.h | 0 common/{ => android}/freetype/tttables.h | 0 common/{ => android}/freetype/tttags.h | 0 common/{ => android}/freetype/ttunpat.h | 0 common/{ => android}/iconv.h | 0 common/freetype/config/ftconfig-32.h | 350 ---------- common/freetype/config/ftconfig-64.h | 350 ---------- common/freetype/config/ftconfig.h | 20 - common/freetype/config/ftheader.h | 729 --------------------- common/freetype/config/ftmodule.h | 22 - common/freetype/config/ftoption.h | 669 ------------------- common/freetype/config/ftstdlib.h | 180 ----- engine/sv_log.cpp | 2 + engine/sys_dll.cpp | 8 +- engine/sys_dll2.cpp | 6 +- ivp | 2 +- public/tier0/basetypes.h | 11 +- public/tier0/platform.h | 4 + tier0/assert_dialog.cpp | 6 +- tier0/stacktools.cpp | 4 +- tier0/threadtools.cpp | 5 - tier1/strtools.cpp | 2 +- 57 files changed, 24 insertions(+), 2346 deletions(-) rename common/{ => android}/freetype/freetype.h (100%) rename common/{ => android}/freetype/ftbbox.h (100%) rename common/{ => android}/freetype/ftbdf.h (100%) rename common/{ => android}/freetype/ftbitmap.h (100%) rename common/{ => android}/freetype/ftcache.h (100%) rename common/{ => android}/freetype/ftchapters.h (100%) rename common/{ => android}/freetype/fterrdef.h (100%) rename common/{ => android}/freetype/fterrors.h (100%) rename common/{ => android}/freetype/ftgasp.h (100%) rename common/{ => android}/freetype/ftglyph.h (100%) rename common/{ => android}/freetype/ftgxval.h (100%) rename common/{ => android}/freetype/ftgzip.h (100%) rename common/{ => android}/freetype/ftimage.h (100%) rename common/{ => android}/freetype/ftincrem.h (100%) rename common/{ => android}/freetype/ftlcdfil.h (100%) rename common/{ => android}/freetype/ftlist.h (100%) rename common/{ => android}/freetype/ftlzw.h (100%) rename common/{ => android}/freetype/ftmac.h (100%) rename common/{ => android}/freetype/ftmm.h (100%) rename common/{ => android}/freetype/ftmodapi.h (100%) rename common/{ => android}/freetype/ftmoderr.h (100%) rename common/{ => android}/freetype/ftotval.h (100%) rename common/{ => android}/freetype/ftoutln.h (100%) rename common/{ => android}/freetype/ftpfr.h (100%) rename common/{ => android}/freetype/ftrender.h (100%) rename common/{ => android}/freetype/ftsizes.h (100%) rename common/{ => android}/freetype/ftsnames.h (100%) rename common/{ => android}/freetype/ftstroke.h (100%) rename common/{ => android}/freetype/ftsynth.h (100%) rename common/{ => android}/freetype/ftsystem.h (100%) rename common/{ => android}/freetype/fttrigon.h (100%) rename common/{ => android}/freetype/fttypes.h (100%) rename common/{ => android}/freetype/ftwinfnt.h (100%) rename common/{ => android}/freetype/ftxf86.h (100%) rename common/{ => android}/freetype/t1tables.h (100%) rename common/{ => android}/freetype/ttnameid.h (100%) rename common/{ => android}/freetype/tttables.h (100%) rename common/{ => android}/freetype/tttags.h (100%) rename common/{ => android}/freetype/ttunpat.h (100%) rename common/{ => android}/iconv.h (100%) delete mode 100644 common/freetype/config/ftconfig-32.h delete mode 100644 common/freetype/config/ftconfig-64.h delete mode 100644 common/freetype/config/ftconfig.h delete mode 100644 common/freetype/config/ftheader.h delete mode 100644 common/freetype/config/ftmodule.h delete mode 100644 common/freetype/config/ftoption.h delete mode 100644 common/freetype/config/ftstdlib.h diff --git a/common/freetype/freetype.h b/common/android/freetype/freetype.h similarity index 100% rename from common/freetype/freetype.h rename to common/android/freetype/freetype.h diff --git a/common/freetype/ftbbox.h b/common/android/freetype/ftbbox.h similarity index 100% rename from common/freetype/ftbbox.h rename to common/android/freetype/ftbbox.h diff --git a/common/freetype/ftbdf.h b/common/android/freetype/ftbdf.h similarity index 100% rename from common/freetype/ftbdf.h rename to common/android/freetype/ftbdf.h diff --git a/common/freetype/ftbitmap.h b/common/android/freetype/ftbitmap.h similarity index 100% rename from common/freetype/ftbitmap.h rename to common/android/freetype/ftbitmap.h diff --git a/common/freetype/ftcache.h b/common/android/freetype/ftcache.h similarity index 100% rename from common/freetype/ftcache.h rename to common/android/freetype/ftcache.h diff --git a/common/freetype/ftchapters.h b/common/android/freetype/ftchapters.h similarity index 100% rename from common/freetype/ftchapters.h rename to common/android/freetype/ftchapters.h diff --git a/common/freetype/fterrdef.h b/common/android/freetype/fterrdef.h similarity index 100% rename from common/freetype/fterrdef.h rename to common/android/freetype/fterrdef.h diff --git a/common/freetype/fterrors.h b/common/android/freetype/fterrors.h similarity index 100% rename from common/freetype/fterrors.h rename to common/android/freetype/fterrors.h diff --git a/common/freetype/ftgasp.h b/common/android/freetype/ftgasp.h similarity index 100% rename from common/freetype/ftgasp.h rename to common/android/freetype/ftgasp.h diff --git a/common/freetype/ftglyph.h b/common/android/freetype/ftglyph.h similarity index 100% rename from common/freetype/ftglyph.h rename to common/android/freetype/ftglyph.h diff --git a/common/freetype/ftgxval.h b/common/android/freetype/ftgxval.h similarity index 100% rename from common/freetype/ftgxval.h rename to common/android/freetype/ftgxval.h diff --git a/common/freetype/ftgzip.h b/common/android/freetype/ftgzip.h similarity index 100% rename from common/freetype/ftgzip.h rename to common/android/freetype/ftgzip.h diff --git a/common/freetype/ftimage.h b/common/android/freetype/ftimage.h similarity index 100% rename from common/freetype/ftimage.h rename to common/android/freetype/ftimage.h diff --git a/common/freetype/ftincrem.h b/common/android/freetype/ftincrem.h similarity index 100% rename from common/freetype/ftincrem.h rename to common/android/freetype/ftincrem.h diff --git a/common/freetype/ftlcdfil.h b/common/android/freetype/ftlcdfil.h similarity index 100% rename from common/freetype/ftlcdfil.h rename to common/android/freetype/ftlcdfil.h diff --git a/common/freetype/ftlist.h b/common/android/freetype/ftlist.h similarity index 100% rename from common/freetype/ftlist.h rename to common/android/freetype/ftlist.h diff --git a/common/freetype/ftlzw.h b/common/android/freetype/ftlzw.h similarity index 100% rename from common/freetype/ftlzw.h rename to common/android/freetype/ftlzw.h diff --git a/common/freetype/ftmac.h b/common/android/freetype/ftmac.h similarity index 100% rename from common/freetype/ftmac.h rename to common/android/freetype/ftmac.h diff --git a/common/freetype/ftmm.h b/common/android/freetype/ftmm.h similarity index 100% rename from common/freetype/ftmm.h rename to common/android/freetype/ftmm.h diff --git a/common/freetype/ftmodapi.h b/common/android/freetype/ftmodapi.h similarity index 100% rename from common/freetype/ftmodapi.h rename to common/android/freetype/ftmodapi.h diff --git a/common/freetype/ftmoderr.h b/common/android/freetype/ftmoderr.h similarity index 100% rename from common/freetype/ftmoderr.h rename to common/android/freetype/ftmoderr.h diff --git a/common/freetype/ftotval.h b/common/android/freetype/ftotval.h similarity index 100% rename from common/freetype/ftotval.h rename to common/android/freetype/ftotval.h diff --git a/common/freetype/ftoutln.h b/common/android/freetype/ftoutln.h similarity index 100% rename from common/freetype/ftoutln.h rename to common/android/freetype/ftoutln.h diff --git a/common/freetype/ftpfr.h b/common/android/freetype/ftpfr.h similarity index 100% rename from common/freetype/ftpfr.h rename to common/android/freetype/ftpfr.h diff --git a/common/freetype/ftrender.h b/common/android/freetype/ftrender.h similarity index 100% rename from common/freetype/ftrender.h rename to common/android/freetype/ftrender.h diff --git a/common/freetype/ftsizes.h b/common/android/freetype/ftsizes.h similarity index 100% rename from common/freetype/ftsizes.h rename to common/android/freetype/ftsizes.h diff --git a/common/freetype/ftsnames.h b/common/android/freetype/ftsnames.h similarity index 100% rename from common/freetype/ftsnames.h rename to common/android/freetype/ftsnames.h diff --git a/common/freetype/ftstroke.h b/common/android/freetype/ftstroke.h similarity index 100% rename from common/freetype/ftstroke.h rename to common/android/freetype/ftstroke.h diff --git a/common/freetype/ftsynth.h b/common/android/freetype/ftsynth.h similarity index 100% rename from common/freetype/ftsynth.h rename to common/android/freetype/ftsynth.h diff --git a/common/freetype/ftsystem.h b/common/android/freetype/ftsystem.h similarity index 100% rename from common/freetype/ftsystem.h rename to common/android/freetype/ftsystem.h diff --git a/common/freetype/fttrigon.h b/common/android/freetype/fttrigon.h similarity index 100% rename from common/freetype/fttrigon.h rename to common/android/freetype/fttrigon.h diff --git a/common/freetype/fttypes.h b/common/android/freetype/fttypes.h similarity index 100% rename from common/freetype/fttypes.h rename to common/android/freetype/fttypes.h diff --git a/common/freetype/ftwinfnt.h b/common/android/freetype/ftwinfnt.h similarity index 100% rename from common/freetype/ftwinfnt.h rename to common/android/freetype/ftwinfnt.h diff --git a/common/freetype/ftxf86.h b/common/android/freetype/ftxf86.h similarity index 100% rename from common/freetype/ftxf86.h rename to common/android/freetype/ftxf86.h diff --git a/common/freetype/t1tables.h b/common/android/freetype/t1tables.h similarity index 100% rename from common/freetype/t1tables.h rename to common/android/freetype/t1tables.h diff --git a/common/freetype/ttnameid.h b/common/android/freetype/ttnameid.h similarity index 100% rename from common/freetype/ttnameid.h rename to common/android/freetype/ttnameid.h diff --git a/common/freetype/tttables.h b/common/android/freetype/tttables.h similarity index 100% rename from common/freetype/tttables.h rename to common/android/freetype/tttables.h diff --git a/common/freetype/tttags.h b/common/android/freetype/tttags.h similarity index 100% rename from common/freetype/tttags.h rename to common/android/freetype/tttags.h diff --git a/common/freetype/ttunpat.h b/common/android/freetype/ttunpat.h similarity index 100% rename from common/freetype/ttunpat.h rename to common/android/freetype/ttunpat.h diff --git a/common/iconv.h b/common/android/iconv.h similarity index 100% rename from common/iconv.h rename to common/android/iconv.h diff --git a/common/freetype/config/ftconfig-32.h b/common/freetype/config/ftconfig-32.h deleted file mode 100644 index 3b447508..00000000 --- a/common/freetype/config/ftconfig-32.h +++ /dev/null @@ -1,350 +0,0 @@ -/* ftconfig.h. Generated from ftconfig.in by configure. */ -/***************************************************************************/ -/* */ -/* ftconfig.in */ -/* */ -/* UNIX-specific configuration file (specification only). */ -/* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2006, 2007 by */ -/* David Turner, Robert Wilhelm, and Werner Lemberg. */ -/* */ -/* This file is part of the FreeType project, and may only be used, */ -/* modified, and distributed under the terms of the FreeType project */ -/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ -/* this file you indicate that you have read the license and */ -/* understand and accept it fully. */ -/* */ -/***************************************************************************/ - - - /*************************************************************************/ - /* */ - /* This header file contains a number of macro definitions that are used */ - /* by the rest of the engine. Most of the macros here are automatically */ - /* determined at compile time, and you should not need to change it to */ - /* port FreeType, except to compile the library with a non-ANSI */ - /* compiler. */ - /* */ - /* Note however that if some specific modifications are needed, we */ - /* advise you to place a modified copy in your build directory. */ - /* */ - /* The build directory is usually `freetype/builds/', and */ - /* contains system-specific files that are always included first when */ - /* building the library. */ - /* */ - /*************************************************************************/ - - -#ifndef __FTCONFIG_H__ -#define __FTCONFIG_H__ - -#include -#include FT_CONFIG_OPTIONS_H -#include FT_CONFIG_STANDARD_LIBRARY_H - - -FT_BEGIN_HEADER - - - /*************************************************************************/ - /* */ - /* PLATFORM-SPECIFIC CONFIGURATION MACROS */ - /* */ - /* These macros can be toggled to suit a specific system. The current */ - /* ones are defaults used to compile FreeType in an ANSI C environment */ - /* (16bit compilers are also supported). Copy this file to your own */ - /* `freetype/builds/' directory, and edit it to port the engine. */ - /* */ - /*************************************************************************/ - - -#define HAVE_UNISTD_H 1 -#define HAVE_FCNTL_H 1 - -#define SIZEOF_INT 4 -#define SIZEOF_LONG 4 - - -#define FT_SIZEOF_INT SIZEOF_INT -#define FT_SIZEOF_LONG SIZEOF_LONG - -#define FT_CHAR_BIT CHAR_BIT - - /* Preferred alignment of data */ -#define FT_ALIGNMENT 8 - - - /* FT_UNUSED is a macro used to indicate that a given parameter is not */ - /* used -- this is only used to get rid of unpleasant compiler warnings */ -#ifndef FT_UNUSED -#define FT_UNUSED( arg ) ( (arg) = (arg) ) -#endif - - - /*************************************************************************/ - /* */ - /* AUTOMATIC CONFIGURATION MACROS */ - /* */ - /* These macros are computed from the ones defined above. Don't touch */ - /* their definition, unless you know precisely what you are doing. No */ - /* porter should need to mess with them. */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* Mac support */ - /* */ - /* This is the only necessary change, so it is defined here instead */ - /* providing a new configuration file. */ - /* */ -#if ( defined( __APPLE__ ) && !defined( DARWIN_NO_CARBON ) ) || \ - ( defined( __MWERKS__ ) && defined( macintosh ) ) - /* no Carbon frameworks for 64bit 10.4.x */ -#include "AvailabilityMacros.h" -#if defined( __LP64__ ) && \ - ( MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 ) -#define DARWIN_NO_CARBON 1 -#else -#define FT_MACINTOSH 1 -#endif -#endif - - - /* Fix compiler warning with sgi compiler */ -#if defined( __sgi ) && !defined( __GNUC__ ) -#if defined( _COMPILER_VERSION ) && ( _COMPILER_VERSION >= 730 ) -#pragma set woff 3505 -#endif -#endif - - - /*************************************************************************/ - /* */ - /* IntN types */ - /* */ - /* Used to guarantee the size of some specific integers. */ - /* */ - typedef signed short FT_Int16; - typedef unsigned short FT_UInt16; - -#if FT_SIZEOF_INT == 4 - - typedef signed int FT_Int32; - typedef unsigned int FT_UInt32; - -#elif FT_SIZEOF_LONG == 4 - - typedef signed long FT_Int32; - typedef unsigned long FT_UInt32; - -#else -#error "no 32bit type found -- please check your configuration files" -#endif - - - /* look up an integer type that is at least 32 bits */ -#if FT_SIZEOF_INT >= 4 - - typedef int FT_Fast; - typedef unsigned int FT_UFast; - -#elif FT_SIZEOF_LONG >= 4 - - typedef long FT_Fast; - typedef unsigned long FT_UFast; - -#endif - - - /* determine whether we have a 64-bit int type for platforms without */ - /* Autoconf */ -#if FT_SIZEOF_LONG == 8 - - /* FT_LONG64 must be defined if a 64-bit type is available */ -#define FT_LONG64 -#define FT_INT64 long - -#elif defined( _MSC_VER ) && _MSC_VER >= 900 /* Visual C++ (and Intel C++) */ - - /* this compiler provides the __int64 type */ -#define FT_LONG64 -#define FT_INT64 __int64 - -#elif defined( __BORLANDC__ ) /* Borland C++ */ - - /* XXXX: We should probably check the value of __BORLANDC__ in order */ - /* to test the compiler version. */ - - /* this compiler provides the __int64 type */ -#define FT_LONG64 -#define FT_INT64 __int64 - -#elif defined( __WATCOMC__ ) /* Watcom C++ */ - - /* Watcom doesn't provide 64-bit data types */ - -#elif defined( __MWERKS__ ) /* Metrowerks CodeWarrior */ - -#define FT_LONG64 -#define FT_INT64 long long int - -#elif defined( __GNUC__ ) - - /* GCC provides the `long long' type */ -#define FT_LONG64 -#define FT_INT64 long long int - -#endif /* FT_SIZEOF_LONG == 8 */ - - -#define FT_BEGIN_STMNT do { -#define FT_END_STMNT } while ( 0 ) -#define FT_DUMMY_STMNT FT_BEGIN_STMNT FT_END_STMNT - - - /*************************************************************************/ - /* */ - /* A 64-bit data type will create compilation problems if you compile */ - /* in strict ANSI mode. To avoid them, we disable their use if */ - /* __STDC__ is defined. You can however ignore this rule by */ - /* defining the FT_CONFIG_OPTION_FORCE_INT64 configuration macro. */ - /* */ -#if defined( FT_LONG64 ) && !defined( FT_CONFIG_OPTION_FORCE_INT64 ) - -#ifdef __STDC__ - - /* Undefine the 64-bit macros in strict ANSI compilation mode. */ - /* Since `#undef' doesn't survive in configuration header files */ - /* we use the postprocessing facility of AC_CONFIG_HEADERS to */ - /* replace the leading `/' with `#'. */ -#undef FT_LONG64 -#undef FT_INT64 - -#endif /* __STDC__ */ - -#endif /* FT_LONG64 && !FT_CONFIG_OPTION_FORCE_INT64 */ - - -#ifdef FT_MAKE_OPTION_SINGLE_OBJECT - -#define FT_LOCAL( x ) static x -#define FT_LOCAL_DEF( x ) static x - -#else - -#ifdef __cplusplus -#define FT_LOCAL( x ) extern "C" x -#define FT_LOCAL_DEF( x ) extern "C" x -#else -#define FT_LOCAL( x ) extern x -#define FT_LOCAL_DEF( x ) x -#endif - -#endif /* FT_MAKE_OPTION_SINGLE_OBJECT */ - - -#ifndef FT_BASE - -#ifdef __cplusplus -#define FT_BASE( x ) extern "C" x -#else -#define FT_BASE( x ) extern x -#endif - -#endif /* !FT_BASE */ - - -#ifndef FT_BASE_DEF - -#ifdef __cplusplus -#define FT_BASE_DEF( x ) x -#else -#define FT_BASE_DEF( x ) x -#endif - -#endif /* !FT_BASE_DEF */ - - -#ifndef FT_EXPORT - -#ifdef __cplusplus -#define FT_EXPORT( x ) extern "C" x -#else -#define FT_EXPORT( x ) extern x -#endif - -#endif /* !FT_EXPORT */ - - -#ifndef FT_EXPORT_DEF - -#ifdef __cplusplus -#define FT_EXPORT_DEF( x ) extern "C" x -#else -#define FT_EXPORT_DEF( x ) extern x -#endif - -#endif /* !FT_EXPORT_DEF */ - - -#ifndef FT_EXPORT_VAR - -#ifdef __cplusplus -#define FT_EXPORT_VAR( x ) extern "C" x -#else -#define FT_EXPORT_VAR( x ) extern x -#endif - -#endif /* !FT_EXPORT_VAR */ - - /* The following macros are needed to compile the library with a */ - /* C++ compiler and with 16bit compilers. */ - /* */ - - /* This is special. Within C++, you must specify `extern "C"' for */ - /* functions which are used via function pointers, and you also */ - /* must do that for structures which contain function pointers to */ - /* assure C linkage -- it's not possible to have (local) anonymous */ - /* functions which are accessed by (global) function pointers. */ - /* */ - /* */ - /* FT_CALLBACK_DEF is used to _define_ a callback function. */ - /* */ - /* FT_CALLBACK_TABLE is used to _declare_ a constant variable that */ - /* contains pointers to callback functions. */ - /* */ - /* FT_CALLBACK_TABLE_DEF is used to _define_ a constant variable */ - /* that contains pointers to callback functions. */ - /* */ - /* */ - /* Some 16bit compilers have to redefine these macros to insert */ - /* the infamous `_cdecl' or `__fastcall' declarations. */ - /* */ -#ifndef FT_CALLBACK_DEF -#ifdef __cplusplus -#define FT_CALLBACK_DEF( x ) extern "C" x -#else -#define FT_CALLBACK_DEF( x ) static x -#endif -#endif /* FT_CALLBACK_DEF */ - -#ifndef FT_CALLBACK_TABLE -#ifdef __cplusplus -#define FT_CALLBACK_TABLE extern "C" -#define FT_CALLBACK_TABLE_DEF extern "C" -#else -#define FT_CALLBACK_TABLE extern -#define FT_CALLBACK_TABLE_DEF /* nothing */ -#endif -#endif /* FT_CALLBACK_TABLE */ - - -FT_END_HEADER - - -#endif /* __FTCONFIG_H__ */ - - -/* END */ diff --git a/common/freetype/config/ftconfig-64.h b/common/freetype/config/ftconfig-64.h deleted file mode 100644 index d0765b05..00000000 --- a/common/freetype/config/ftconfig-64.h +++ /dev/null @@ -1,350 +0,0 @@ -/* ftconfig.h. Generated from ftconfig.in by configure. */ -/***************************************************************************/ -/* */ -/* ftconfig.in */ -/* */ -/* UNIX-specific configuration file (specification only). */ -/* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2006, 2007 by */ -/* David Turner, Robert Wilhelm, and Werner Lemberg. */ -/* */ -/* This file is part of the FreeType project, and may only be used, */ -/* modified, and distributed under the terms of the FreeType project */ -/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ -/* this file you indicate that you have read the license and */ -/* understand and accept it fully. */ -/* */ -/***************************************************************************/ - - - /*************************************************************************/ - /* */ - /* This header file contains a number of macro definitions that are used */ - /* by the rest of the engine. Most of the macros here are automatically */ - /* determined at compile time, and you should not need to change it to */ - /* port FreeType, except to compile the library with a non-ANSI */ - /* compiler. */ - /* */ - /* Note however that if some specific modifications are needed, we */ - /* advise you to place a modified copy in your build directory. */ - /* */ - /* The build directory is usually `freetype/builds/', and */ - /* contains system-specific files that are always included first when */ - /* building the library. */ - /* */ - /*************************************************************************/ - - -#ifndef __FTCONFIG_H__ -#define __FTCONFIG_H__ - -#include -#include FT_CONFIG_OPTIONS_H -#include FT_CONFIG_STANDARD_LIBRARY_H - - -FT_BEGIN_HEADER - - - /*************************************************************************/ - /* */ - /* PLATFORM-SPECIFIC CONFIGURATION MACROS */ - /* */ - /* These macros can be toggled to suit a specific system. The current */ - /* ones are defaults used to compile FreeType in an ANSI C environment */ - /* (16bit compilers are also supported). Copy this file to your own */ - /* `freetype/builds/' directory, and edit it to port the engine. */ - /* */ - /*************************************************************************/ - - -#define HAVE_UNISTD_H 1 -#define HAVE_FCNTL_H 1 - -#define SIZEOF_INT 4 -#define SIZEOF_LONG 8 - - -#define FT_SIZEOF_INT SIZEOF_INT -#define FT_SIZEOF_LONG SIZEOF_LONG - -#define FT_CHAR_BIT CHAR_BIT - - /* Preferred alignment of data */ -#define FT_ALIGNMENT 8 - - - /* FT_UNUSED is a macro used to indicate that a given parameter is not */ - /* used -- this is only used to get rid of unpleasant compiler warnings */ -#ifndef FT_UNUSED -#define FT_UNUSED( arg ) ( (arg) = (arg) ) -#endif - - - /*************************************************************************/ - /* */ - /* AUTOMATIC CONFIGURATION MACROS */ - /* */ - /* These macros are computed from the ones defined above. Don't touch */ - /* their definition, unless you know precisely what you are doing. No */ - /* porter should need to mess with them. */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* Mac support */ - /* */ - /* This is the only necessary change, so it is defined here instead */ - /* providing a new configuration file. */ - /* */ -#if ( defined( __APPLE__ ) && !defined( DARWIN_NO_CARBON ) ) || \ - ( defined( __MWERKS__ ) && defined( macintosh ) ) - /* no Carbon frameworks for 64bit 10.4.x */ -#include "AvailabilityMacros.h" -#if defined( __LP64__ ) && \ - ( MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 ) -#define DARWIN_NO_CARBON 1 -#else -#define FT_MACINTOSH 1 -#endif -#endif - - - /* Fix compiler warning with sgi compiler */ -#if defined( __sgi ) && !defined( __GNUC__ ) -#if defined( _COMPILER_VERSION ) && ( _COMPILER_VERSION >= 730 ) -#pragma set woff 3505 -#endif -#endif - - - /*************************************************************************/ - /* */ - /* IntN types */ - /* */ - /* Used to guarantee the size of some specific integers. */ - /* */ - typedef signed short FT_Int16; - typedef unsigned short FT_UInt16; - -#if FT_SIZEOF_INT == 4 - - typedef signed int FT_Int32; - typedef unsigned int FT_UInt32; - -#elif FT_SIZEOF_LONG == 4 - - typedef signed long FT_Int32; - typedef unsigned long FT_UInt32; - -#else -#error "no 32bit type found -- please check your configuration files" -#endif - - - /* look up an integer type that is at least 32 bits */ -#if FT_SIZEOF_INT >= 4 - - typedef int FT_Fast; - typedef unsigned int FT_UFast; - -#elif FT_SIZEOF_LONG >= 4 - - typedef long FT_Fast; - typedef unsigned long FT_UFast; - -#endif - - - /* determine whether we have a 64-bit int type for platforms without */ - /* Autoconf */ -#if FT_SIZEOF_LONG == 8 - - /* FT_LONG64 must be defined if a 64-bit type is available */ -#define FT_LONG64 -#define FT_INT64 long - -#elif defined( _MSC_VER ) && _MSC_VER >= 900 /* Visual C++ (and Intel C++) */ - - /* this compiler provides the __int64 type */ -#define FT_LONG64 -#define FT_INT64 __int64 - -#elif defined( __BORLANDC__ ) /* Borland C++ */ - - /* XXXX: We should probably check the value of __BORLANDC__ in order */ - /* to test the compiler version. */ - - /* this compiler provides the __int64 type */ -#define FT_LONG64 -#define FT_INT64 __int64 - -#elif defined( __WATCOMC__ ) /* Watcom C++ */ - - /* Watcom doesn't provide 64-bit data types */ - -#elif defined( __MWERKS__ ) /* Metrowerks CodeWarrior */ - -#define FT_LONG64 -#define FT_INT64 long long int - -#elif defined( __GNUC__ ) - - /* GCC provides the `long long' type */ -#define FT_LONG64 -#define FT_INT64 long long int - -#endif /* FT_SIZEOF_LONG == 8 */ - - -#define FT_BEGIN_STMNT do { -#define FT_END_STMNT } while ( 0 ) -#define FT_DUMMY_STMNT FT_BEGIN_STMNT FT_END_STMNT - - - /*************************************************************************/ - /* */ - /* A 64-bit data type will create compilation problems if you compile */ - /* in strict ANSI mode. To avoid them, we disable their use if */ - /* __STDC__ is defined. You can however ignore this rule by */ - /* defining the FT_CONFIG_OPTION_FORCE_INT64 configuration macro. */ - /* */ -#if defined( FT_LONG64 ) && !defined( FT_CONFIG_OPTION_FORCE_INT64 ) - -#ifdef __STDC__ - - /* Undefine the 64-bit macros in strict ANSI compilation mode. */ - /* Since `#undef' doesn't survive in configuration header files */ - /* we use the postprocessing facility of AC_CONFIG_HEADERS to */ - /* replace the leading `/' with `#'. */ -#undef FT_LONG64 -#undef FT_INT64 - -#endif /* __STDC__ */ - -#endif /* FT_LONG64 && !FT_CONFIG_OPTION_FORCE_INT64 */ - - -#ifdef FT_MAKE_OPTION_SINGLE_OBJECT - -#define FT_LOCAL( x ) static x -#define FT_LOCAL_DEF( x ) static x - -#else - -#ifdef __cplusplus -#define FT_LOCAL( x ) extern "C" x -#define FT_LOCAL_DEF( x ) extern "C" x -#else -#define FT_LOCAL( x ) extern x -#define FT_LOCAL_DEF( x ) x -#endif - -#endif /* FT_MAKE_OPTION_SINGLE_OBJECT */ - - -#ifndef FT_BASE - -#ifdef __cplusplus -#define FT_BASE( x ) extern "C" x -#else -#define FT_BASE( x ) extern x -#endif - -#endif /* !FT_BASE */ - - -#ifndef FT_BASE_DEF - -#ifdef __cplusplus -#define FT_BASE_DEF( x ) x -#else -#define FT_BASE_DEF( x ) x -#endif - -#endif /* !FT_BASE_DEF */ - - -#ifndef FT_EXPORT - -#ifdef __cplusplus -#define FT_EXPORT( x ) extern "C" x -#else -#define FT_EXPORT( x ) extern x -#endif - -#endif /* !FT_EXPORT */ - - -#ifndef FT_EXPORT_DEF - -#ifdef __cplusplus -#define FT_EXPORT_DEF( x ) extern "C" x -#else -#define FT_EXPORT_DEF( x ) extern x -#endif - -#endif /* !FT_EXPORT_DEF */ - - -#ifndef FT_EXPORT_VAR - -#ifdef __cplusplus -#define FT_EXPORT_VAR( x ) extern "C" x -#else -#define FT_EXPORT_VAR( x ) extern x -#endif - -#endif /* !FT_EXPORT_VAR */ - - /* The following macros are needed to compile the library with a */ - /* C++ compiler and with 16bit compilers. */ - /* */ - - /* This is special. Within C++, you must specify `extern "C"' for */ - /* functions which are used via function pointers, and you also */ - /* must do that for structures which contain function pointers to */ - /* assure C linkage -- it's not possible to have (local) anonymous */ - /* functions which are accessed by (global) function pointers. */ - /* */ - /* */ - /* FT_CALLBACK_DEF is used to _define_ a callback function. */ - /* */ - /* FT_CALLBACK_TABLE is used to _declare_ a constant variable that */ - /* contains pointers to callback functions. */ - /* */ - /* FT_CALLBACK_TABLE_DEF is used to _define_ a constant variable */ - /* that contains pointers to callback functions. */ - /* */ - /* */ - /* Some 16bit compilers have to redefine these macros to insert */ - /* the infamous `_cdecl' or `__fastcall' declarations. */ - /* */ -#ifndef FT_CALLBACK_DEF -#ifdef __cplusplus -#define FT_CALLBACK_DEF( x ) extern "C" x -#else -#define FT_CALLBACK_DEF( x ) static x -#endif -#endif /* FT_CALLBACK_DEF */ - -#ifndef FT_CALLBACK_TABLE -#ifdef __cplusplus -#define FT_CALLBACK_TABLE extern "C" -#define FT_CALLBACK_TABLE_DEF extern "C" -#else -#define FT_CALLBACK_TABLE extern -#define FT_CALLBACK_TABLE_DEF /* nothing */ -#endif -#endif /* FT_CALLBACK_TABLE */ - - -FT_END_HEADER - - -#endif /* __FTCONFIG_H__ */ - - -/* END */ diff --git a/common/freetype/config/ftconfig.h b/common/freetype/config/ftconfig.h deleted file mode 100644 index b56a4d44..00000000 --- a/common/freetype/config/ftconfig.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __FTCONFIG_H__MULTILIB -#define __FTCONFIG_H__MULTILIB - -#ifdef ANDROID -#include -#elif defined(OSX) || defined(PLATFORM_BSD) -#include -#else -#include -#endif - -#if __WORDSIZE == 32 -# include "ftconfig-32.h" -#elif __WORDSIZE == 64 -# include "ftconfig-64.h" -#else -# error "unexpected value for __WORDSIZE macro" -#endif - -#endif diff --git a/common/freetype/config/ftheader.h b/common/freetype/config/ftheader.h deleted file mode 100644 index b957d05b..00000000 --- a/common/freetype/config/ftheader.h +++ /dev/null @@ -1,729 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftheader.h */ -/* */ -/* Build macros of the FreeType 2 library. */ -/* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by */ -/* David Turner, Robert Wilhelm, and Werner Lemberg. */ -/* */ -/* This file is part of the FreeType project, and may only be used, */ -/* modified, and distributed under the terms of the FreeType project */ -/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ -/* this file you indicate that you have read the license and */ -/* understand and accept it fully. */ -/* */ -/***************************************************************************/ - -#ifndef __FT_HEADER_H__ -#define __FT_HEADER_H__ - - - /*@***********************************************************************/ - /* */ - /* */ - /* FT_BEGIN_HEADER */ - /* */ - /* */ - /* This macro is used in association with @FT_END_HEADER in header */ - /* files to ensure that the declarations within are properly */ - /* encapsulated in an `extern "C" { .. }' block when included from a */ - /* C++ compiler. */ - /* */ -#ifdef __cplusplus -#define FT_BEGIN_HEADER extern "C" { -#else -#define FT_BEGIN_HEADER /* nothing */ -#endif - - - /*@***********************************************************************/ - /* */ - /* */ - /* FT_END_HEADER */ - /* */ - /* */ - /* This macro is used in association with @FT_BEGIN_HEADER in header */ - /* files to ensure that the declarations within are properly */ - /* encapsulated in an `extern "C" { .. }' block when included from a */ - /* C++ compiler. */ - /* */ -#ifdef __cplusplus -#define FT_END_HEADER } -#else -#define FT_END_HEADER /* nothing */ -#endif - - - /*************************************************************************/ - /* */ - /* Aliases for the FreeType 2 public and configuration files. */ - /* */ - /*************************************************************************/ - - /*************************************************************************/ - /* */ - /*
*/ - /* header_file_macros */ - /* */ - /* */ - /* Header File Macros */ - /* */ - /* <Abstract> */ - /* Macro definitions used to #include specific header files. */ - /* */ - /* <Description> */ - /* The following macros are defined to the name of specific */ - /* FreeType 2 header files. They can be used directly in #include */ - /* statements as in: */ - /* */ - /* { */ - /* #include FT_FREETYPE_H */ - /* #include FT_MULTIPLE_MASTERS_H */ - /* #include FT_GLYPH_H */ - /* } */ - /* */ - /* There are several reasons why we are now using macros to name */ - /* public header files. The first one is that such macros are not */ - /* limited to the infamous 8.3 naming rule required by DOS (and */ - /* `FT_MULTIPLE_MASTERS_H' is a lot more meaningful than `ftmm.h'). */ - /* */ - /* The second reason is that it allows for more flexibility in the */ - /* way FreeType 2 is installed on a given system. */ - /* */ - /*************************************************************************/ - - - /* configuration files */ - - /************************************************************************* - * - * @macro: - * FT_CONFIG_CONFIG_H - * - * @description: - * A macro used in #include statements to name the file containing - * FreeType 2 configuration data. - * - */ -#ifndef FT_CONFIG_CONFIG_H -#define FT_CONFIG_CONFIG_H <freetype/config/ftconfig.h> -#endif - - - /************************************************************************* - * - * @macro: - * FT_CONFIG_STANDARD_LIBRARY_H - * - * @description: - * A macro used in #include statements to name the file containing - * FreeType 2 interface to the standard C library functions. - * - */ -#ifndef FT_CONFIG_STANDARD_LIBRARY_H -#define FT_CONFIG_STANDARD_LIBRARY_H <freetype/config/ftstdlib.h> -#endif - - - /************************************************************************* - * - * @macro: - * FT_CONFIG_OPTIONS_H - * - * @description: - * A macro used in #include statements to name the file containing - * FreeType 2 project-specific configuration options. - * - */ -#ifndef FT_CONFIG_OPTIONS_H -#define FT_CONFIG_OPTIONS_H <freetype/config/ftoption.h> -#endif - - - /************************************************************************* - * - * @macro: - * FT_CONFIG_MODULES_H - * - * @description: - * A macro used in #include statements to name the file containing the - * list of FreeType 2 modules that are statically linked to new library - * instances in @FT_Init_FreeType. - * - */ -#ifndef FT_CONFIG_MODULES_H -#define FT_CONFIG_MODULES_H <freetype/config/ftmodule.h> -#endif - - - /* public headers */ - - /************************************************************************* - * - * @macro: - * FT_FREETYPE_H - * - * @description: - * A macro used in #include statements to name the file containing the - * base FreeType 2 API. - * - */ -#define FT_FREETYPE_H <freetype/freetype.h> - - - /************************************************************************* - * - * @macro: - * FT_ERRORS_H - * - * @description: - * A macro used in #include statements to name the file containing the - * list of FreeType 2 error codes (and messages). - * - * It is included by @FT_FREETYPE_H. - * - */ -#define FT_ERRORS_H <freetype/fterrors.h> - - - /************************************************************************* - * - * @macro: - * FT_MODULE_ERRORS_H - * - * @description: - * A macro used in #include statements to name the file containing the - * list of FreeType 2 module error offsets (and messages). - * - */ -#define FT_MODULE_ERRORS_H <freetype/ftmoderr.h> - - - /************************************************************************* - * - * @macro: - * FT_SYSTEM_H - * - * @description: - * A macro used in #include statements to name the file containing the - * FreeType 2 interface to low-level operations (i.e., memory management - * and stream i/o). - * - * It is included by @FT_FREETYPE_H. - * - */ -#define FT_SYSTEM_H <freetype/ftsystem.h> - - - /************************************************************************* - * - * @macro: - * FT_IMAGE_H - * - * @description: - * A macro used in #include statements to name the file containing type - * definitions related to glyph images (i.e., bitmaps, outlines, - * scan-converter parameters). - * - * It is included by @FT_FREETYPE_H. - * - */ -#define FT_IMAGE_H <freetype/ftimage.h> - - - /************************************************************************* - * - * @macro: - * FT_TYPES_H - * - * @description: - * A macro used in #include statements to name the file containing the - * basic data types defined by FreeType 2. - * - * It is included by @FT_FREETYPE_H. - * - */ -#define FT_TYPES_H <freetype/fttypes.h> - - - /************************************************************************* - * - * @macro: - * FT_LIST_H - * - * @description: - * A macro used in #include statements to name the file containing the - * list management API of FreeType 2. - * - * (Most applications will never need to include this file.) - * - */ -#define FT_LIST_H <freetype/ftlist.h> - - - /************************************************************************* - * - * @macro: - * FT_OUTLINE_H - * - * @description: - * A macro used in #include statements to name the file containing the - * scalable outline management API of FreeType 2. - * - */ -#define FT_OUTLINE_H <freetype/ftoutln.h> - - - /************************************************************************* - * - * @macro: - * FT_SIZES_H - * - * @description: - * A macro used in #include statements to name the file containing the - * API which manages multiple @FT_Size objects per face. - * - */ -#define FT_SIZES_H <freetype/ftsizes.h> - - - /************************************************************************* - * - * @macro: - * FT_MODULE_H - * - * @description: - * A macro used in #include statements to name the file containing the - * module management API of FreeType 2. - * - */ -#define FT_MODULE_H <freetype/ftmodapi.h> - - - /************************************************************************* - * - * @macro: - * FT_RENDER_H - * - * @description: - * A macro used in #include statements to name the file containing the - * renderer module management API of FreeType 2. - * - */ -#define FT_RENDER_H <freetype/ftrender.h> - - - /************************************************************************* - * - * @macro: - * FT_TYPE1_TABLES_H - * - * @description: - * A macro used in #include statements to name the file containing the - * types and API specific to the Type 1 format. - * - */ -#define FT_TYPE1_TABLES_H <freetype/t1tables.h> - - - /************************************************************************* - * - * @macro: - * FT_TRUETYPE_IDS_H - * - * @description: - * A macro used in #include statements to name the file containing the - * enumeration values which identify name strings, languages, encodings, - * etc. This file really contains a _large_ set of constant macro - * definitions, taken from the TrueType and OpenType specifications. - * - */ -#define FT_TRUETYPE_IDS_H <freetype/ttnameid.h> - - - /************************************************************************* - * - * @macro: - * FT_TRUETYPE_TABLES_H - * - * @description: - * A macro used in #include statements to name the file containing the - * types and API specific to the TrueType (as well as OpenType) format. - * - */ -#define FT_TRUETYPE_TABLES_H <freetype/tttables.h> - - - /************************************************************************* - * - * @macro: - * FT_TRUETYPE_TAGS_H - * - * @description: - * A macro used in #include statements to name the file containing the - * definitions of TrueType four-byte `tags' which identify blocks in - * SFNT-based font formats (i.e., TrueType and OpenType). - * - */ -#define FT_TRUETYPE_TAGS_H <freetype/tttags.h> - - - /************************************************************************* - * - * @macro: - * FT_BDF_H - * - * @description: - * A macro used in #include statements to name the file containing the - * definitions of an API which accesses BDF-specific strings from a - * face. - * - */ -#define FT_BDF_H <freetype/ftbdf.h> - - - /************************************************************************* - * - * @macro: - * FT_GZIP_H - * - * @description: - * A macro used in #include statements to name the file containing the - * definitions of an API which supports gzip-compressed files. - * - */ -#define FT_GZIP_H <freetype/ftgzip.h> - - - /************************************************************************* - * - * @macro: - * FT_LZW_H - * - * @description: - * A macro used in #include statements to name the file containing the - * definitions of an API which supports LZW-compressed files. - * - */ -#define FT_LZW_H <freetype/ftlzw.h> - - - /************************************************************************* - * - * @macro: - * FT_WINFONTS_H - * - * @description: - * A macro used in #include statements to name the file containing the - * definitions of an API which supports Windows FNT files. - * - */ -#define FT_WINFONTS_H <freetype/ftwinfnt.h> - - - /************************************************************************* - * - * @macro: - * FT_GLYPH_H - * - * @description: - * A macro used in #include statements to name the file containing the - * API of the optional glyph management component. - * - */ -#define FT_GLYPH_H <freetype/ftglyph.h> - - - /************************************************************************* - * - * @macro: - * FT_BITMAP_H - * - * @description: - * A macro used in #include statements to name the file containing the - * API of the optional bitmap conversion component. - * - */ -#define FT_BITMAP_H <freetype/ftbitmap.h> - - - /************************************************************************* - * - * @macro: - * FT_BBOX_H - * - * @description: - * A macro used in #include statements to name the file containing the - * API of the optional exact bounding box computation routines. - * - */ -#define FT_BBOX_H <freetype/ftbbox.h> - - - /************************************************************************* - * - * @macro: - * FT_CACHE_H - * - * @description: - * A macro used in #include statements to name the file containing the - * API of the optional FreeType 2 cache sub-system. - * - */ -#define FT_CACHE_H <freetype/ftcache.h> - - - /************************************************************************* - * - * @macro: - * FT_CACHE_IMAGE_H - * - * @description: - * A macro used in #include statements to name the file containing the - * `glyph image' API of the FreeType 2 cache sub-system. - * - * It is used to define a cache for @FT_Glyph elements. You can also - * use the API defined in @FT_CACHE_SMALL_BITMAPS_H if you only need to - * store small glyph bitmaps, as it will use less memory. - * - * This macro is deprecated. Simply include @FT_CACHE_H to have all - * glyph image-related cache declarations. - * - */ -#define FT_CACHE_IMAGE_H FT_CACHE_H - - - /************************************************************************* - * - * @macro: - * FT_CACHE_SMALL_BITMAPS_H - * - * @description: - * A macro used in #include statements to name the file containing the - * `small bitmaps' API of the FreeType 2 cache sub-system. - * - * It is used to define a cache for small glyph bitmaps in a relatively - * memory-efficient way. You can also use the API defined in - * @FT_CACHE_IMAGE_H if you want to cache arbitrary glyph images, - * including scalable outlines. - * - * This macro is deprecated. Simply include @FT_CACHE_H to have all - * small bitmaps-related cache declarations. - * - */ -#define FT_CACHE_SMALL_BITMAPS_H FT_CACHE_H - - - /************************************************************************* - * - * @macro: - * FT_CACHE_CHARMAP_H - * - * @description: - * A macro used in #include statements to name the file containing the - * `charmap' API of the FreeType 2 cache sub-system. - * - * This macro is deprecated. Simply include @FT_CACHE_H to have all - * charmap-based cache declarations. - * - */ -#define FT_CACHE_CHARMAP_H FT_CACHE_H - - - /************************************************************************* - * - * @macro: - * FT_MAC_H - * - * @description: - * A macro used in #include statements to name the file containing the - * Macintosh-specific FreeType 2 API. The latter is used to access - * fonts embedded in resource forks. - * - * This header file must be explicitly included by client applications - * compiled on the Mac (note that the base API still works though). - * - */ -#define FT_MAC_H <freetype/ftmac.h> - - - /************************************************************************* - * - * @macro: - * FT_MULTIPLE_MASTERS_H - * - * @description: - * A macro used in #include statements to name the file containing the - * optional multiple-masters management API of FreeType 2. - * - */ -#define FT_MULTIPLE_MASTERS_H <freetype/ftmm.h> - - - /************************************************************************* - * - * @macro: - * FT_SFNT_NAMES_H - * - * @description: - * A macro used in #include statements to name the file containing the - * optional FreeType 2 API which accesses embedded `name' strings in - * SFNT-based font formats (i.e., TrueType and OpenType). - * - */ -#define FT_SFNT_NAMES_H <freetype/ftsnames.h> - - - /************************************************************************* - * - * @macro: - * FT_OPENTYPE_VALIDATE_H - * - * @description: - * A macro used in #include statements to name the file containing the - * optional FreeType 2 API which validates OpenType tables (BASE, GDEF, - * GPOS, GSUB, JSTF). - * - */ -#define FT_OPENTYPE_VALIDATE_H <freetype/ftotval.h> - - - /************************************************************************* - * - * @macro: - * FT_GX_VALIDATE_H - * - * @description: - * A macro used in #include statements to name the file containing the - * optional FreeType 2 API which validates TrueTypeGX/AAT tables (feat, - * mort, morx, bsln, just, kern, opbd, trak, prop). - * - */ -#define FT_GX_VALIDATE_H <freetype/ftgxval.h> - - - /************************************************************************* - * - * @macro: - * FT_PFR_H - * - * @description: - * A macro used in #include statements to name the file containing the - * FreeType 2 API which accesses PFR-specific data. - * - */ -#define FT_PFR_H <freetype/ftpfr.h> - - - /************************************************************************* - * - * @macro: - * FT_STROKER_H - * - * @description: - * A macro used in #include statements to name the file containing the - * FreeType 2 API which provides functions to stroke outline paths. - */ -#define FT_STROKER_H <freetype/ftstroke.h> - - - /************************************************************************* - * - * @macro: - * FT_SYNTHESIS_H - * - * @description: - * A macro used in #include statements to name the file containing the - * FreeType 2 API which performs artificial obliquing and emboldening. - */ -#define FT_SYNTHESIS_H <freetype/ftsynth.h> - - - /************************************************************************* - * - * @macro: - * FT_XFREE86_H - * - * @description: - * A macro used in #include statements to name the file containing the - * FreeType 2 API which provides functions specific to the XFree86 and - * X.Org X11 servers. - */ -#define FT_XFREE86_H <freetype/ftxf86.h> - - - /************************************************************************* - * - * @macro: - * FT_TRIGONOMETRY_H - * - * @description: - * A macro used in #include statements to name the file containing the - * FreeType 2 API which performs trigonometric computations (e.g., - * cosines and arc tangents). - */ -#define FT_TRIGONOMETRY_H <freetype/fttrigon.h> - - - /************************************************************************* - * - * @macro: - * FT_LCD_FILTER_H - * - * @description: - * A macro used in #include statements to name the file containing the - * FreeType 2 API which performs color filtering for subpixel rendering. - */ -#define FT_LCD_FILTER_H <freetype/ftlcdfil.h> - - - /************************************************************************* - * - * @macro: - * FT_GASP_H - * - * @description: - * A macro used in #include statements to name the file containing the - * FreeType 2 API which returns entries from the TrueType GASP table. - */ -#define FT_GASP_H <freetype/ftgasp.h> - - - /* */ - -#define FT_ERROR_DEFINITIONS_H <freetype/fterrdef.h> - - - /* The internals of the cache sub-system are no longer exposed. We */ - /* default to FT_CACHE_H at the moment just in case, but we know of */ - /* no rogue client that uses them. */ - /* */ -#define FT_CACHE_MANAGER_H <freetype/ftcache.h> -#define FT_CACHE_INTERNAL_MRU_H <freetype/ftcache.h> -#define FT_CACHE_INTERNAL_MANAGER_H <freetype/ftcache.h> -#define FT_CACHE_INTERNAL_CACHE_H <freetype/ftcache.h> -#define FT_CACHE_INTERNAL_GLYPH_H <freetype/ftcache.h> -#define FT_CACHE_INTERNAL_IMAGE_H <freetype/ftcache.h> -#define FT_CACHE_INTERNAL_SBITS_H <freetype/ftcache.h> - - -#define FT_INCREMENTAL_H <freetype/ftincrem.h> - -#define FT_TRUETYPE_UNPATENTED_H <freetype/ttunpat.h> - - - /* - * Include internal headers definitions from <freetype/internal/...> - * only when building the library. - */ -#ifdef FT2_BUILD_LIBRARY -#define FT_INTERNAL_INTERNAL_H <freetype/internal/internal.h> -#include FT_INTERNAL_INTERNAL_H -#endif /* FT2_BUILD_LIBRARY */ - - -#endif /* __FT2_BUILD_H__ */ - - -/* END */ diff --git a/common/freetype/config/ftmodule.h b/common/freetype/config/ftmodule.h deleted file mode 100644 index c28052b7..00000000 --- a/common/freetype/config/ftmodule.h +++ /dev/null @@ -1,22 +0,0 @@ -/* This is a generated file. */ -FT_USE_MODULE(tt_driver_class) -FT_USE_MODULE(t1_driver_class) -FT_USE_MODULE(cff_driver_class) -FT_USE_MODULE(t1cid_driver_class) -FT_USE_MODULE(pfr_driver_class) -FT_USE_MODULE(t42_driver_class) -FT_USE_MODULE(winfnt_driver_class) -FT_USE_MODULE(pcf_driver_class) -FT_USE_MODULE(bdf_driver_class) -FT_USE_MODULE(sfnt_module_class) -FT_USE_MODULE(autofit_module_class) -FT_USE_MODULE(pshinter_module_class) -FT_USE_MODULE(ft_raster1_renderer_class) -FT_USE_MODULE(ft_smooth_renderer_class) -FT_USE_MODULE(ft_smooth_lcd_renderer_class) -FT_USE_MODULE(ft_smooth_lcdv_renderer_class) -FT_USE_MODULE(gxv_module_class) -FT_USE_MODULE(otv_module_class) -FT_USE_MODULE(psaux_module_class) -FT_USE_MODULE(psnames_module_class) -/* EOF */ diff --git a/common/freetype/config/ftoption.h b/common/freetype/config/ftoption.h deleted file mode 100644 index 532848da..00000000 --- a/common/freetype/config/ftoption.h +++ /dev/null @@ -1,669 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftoption.h */ -/* */ -/* User-selectable configuration macros (specification only). */ -/* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by */ -/* David Turner, Robert Wilhelm, and Werner Lemberg. */ -/* */ -/* This file is part of the FreeType project, and may only be used, */ -/* modified, and distributed under the terms of the FreeType project */ -/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ -/* this file you indicate that you have read the license and */ -/* understand and accept it fully. */ -/* */ -/***************************************************************************/ - - -#ifndef __FTOPTION_H__ -#define __FTOPTION_H__ - - -#include <ft2build.h> - - -FT_BEGIN_HEADER - - /*************************************************************************/ - /* */ - /* USER-SELECTABLE CONFIGURATION MACROS */ - /* */ - /* This file contains the default configuration macro definitions for */ - /* a standard build of the FreeType library. There are three ways to */ - /* use this file to build project-specific versions of the library: */ - /* */ - /* - You can modify this file by hand, but this is not recommended in */ - /* cases where you would like to build several versions of the */ - /* library from a single source directory. */ - /* */ - /* - You can put a copy of this file in your build directory, more */ - /* precisely in `$BUILD/freetype/config/ftoption.h', where `$BUILD' */ - /* is the name of a directory that is included _before_ the FreeType */ - /* include path during compilation. */ - /* */ - /* The default FreeType Makefiles and Jamfiles use the build */ - /* directory `builds/<system>' by default, but you can easily change */ - /* that for your own projects. */ - /* */ - /* - Copy the file <ft2build.h> to `$BUILD/ft2build.h' and modify it */ - /* slightly to pre-define the macro FT_CONFIG_OPTIONS_H used to */ - /* locate this file during the build. For example, */ - /* */ - /* #define FT_CONFIG_OPTIONS_H <myftoptions.h> */ - /* #include <freetype/config/ftheader.h> */ - /* */ - /* will use `$BUILD/myftoptions.h' instead of this file for macro */ - /* definitions. */ - /* */ - /* Note also that you can similarly pre-define the macro */ - /* FT_CONFIG_MODULES_H used to locate the file listing of the modules */ - /* that are statically linked to the library at compile time. By */ - /* default, this file is <freetype/config/ftmodule.h>. */ - /* */ - /* We highly recommend using the third method whenever possible. */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** G E N E R A L F R E E T Y P E 2 C O N F I G U R A T I O N ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* Uncomment the line below if you want to activate sub-pixel rendering */ - /* (a.k.a. LCD rendering, or ClearType) in this build of the library. */ - /* */ - /* Note that this feature is covered by several Microsoft patents */ - /* and should not be activated in any default build of the library. */ - /* */ - /* This macro has no impact on the FreeType API, only on its */ - /* _implementation_. For example, using FT_RENDER_MODE_LCD when calling */ - /* FT_Render_Glyph still generates a bitmap that is 3 times larger than */ - /* the original size; the difference will be that each triplet of */ - /* subpixels has R=G=B. */ - /* */ - /* This is done to allow FreeType clients to run unmodified, forcing */ - /* them to display normal gray-level anti-aliased glyphs. */ - /* */ -/* #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ - - - /*************************************************************************/ - /* */ - /* Many compilers provide a non-ANSI 64-bit data type that can be used */ - /* by FreeType to speed up some computations. However, this will create */ - /* some problems when compiling the library in strict ANSI mode. */ - /* */ - /* For this reason, the use of 64-bit integers is normally disabled when */ - /* the __STDC__ macro is defined. You can however disable this by */ - /* defining the macro FT_CONFIG_OPTION_FORCE_INT64 here. */ - /* */ - /* For most compilers, this will only create compilation warnings when */ - /* building the library. */ - /* */ - /* ObNote: The compiler-specific 64-bit integers are detected in the */ - /* file `ftconfig.h' either statically or through the */ - /* `configure' script on supported platforms. */ - /* */ -#undef FT_CONFIG_OPTION_FORCE_INT64 - - - /*************************************************************************/ - /* */ - /* LZW-compressed file support. */ - /* */ - /* FreeType now handles font files that have been compressed with the */ - /* `compress' program. This is mostly used to parse many of the PCF */ - /* files that come with various X11 distributions. The implementation */ - /* uses NetBSD's `zopen' to partially uncompress the file on the fly */ - /* (see src/lzw/ftgzip.c). */ - /* */ - /* Define this macro if you want to enable this `feature'. */ - /* */ -#define FT_CONFIG_OPTION_USE_LZW - - - /*************************************************************************/ - /* */ - /* Gzip-compressed file support. */ - /* */ - /* FreeType now handles font files that have been compressed with the */ - /* `gzip' program. This is mostly used to parse many of the PCF files */ - /* that come with XFree86. The implementation uses `zlib' to */ - /* partially uncompress the file on the fly (see src/gzip/ftgzip.c). */ - /* */ - /* Define this macro if you want to enable this `feature'. See also */ - /* the macro FT_CONFIG_OPTION_SYSTEM_ZLIB below. */ - /* */ -#define FT_CONFIG_OPTION_USE_ZLIB - - - /*************************************************************************/ - /* */ - /* ZLib library selection */ - /* */ - /* This macro is only used when FT_CONFIG_OPTION_USE_ZLIB is defined. */ - /* It allows FreeType's `ftgzip' component to link to the system's */ - /* installation of the ZLib library. This is useful on systems like */ - /* Unix or VMS where it generally is already available. */ - /* */ - /* If you let it undefined, the component will use its own copy */ - /* of the zlib sources instead. These have been modified to be */ - /* included directly within the component and *not* export external */ - /* function names. This allows you to link any program with FreeType */ - /* _and_ ZLib without linking conflicts. */ - /* */ - /* Do not #undef this macro here since the build system might define */ - /* it for certain configurations only. */ - /* */ -/* #define FT_CONFIG_OPTION_SYSTEM_ZLIB */ - - - /*************************************************************************/ - /* */ - /* DLL export compilation */ - /* */ - /* When compiling FreeType as a DLL, some systems/compilers need a */ - /* special keyword in front OR after the return type of function */ - /* declarations. */ - /* */ - /* Two macros are used within the FreeType source code to define */ - /* exported library functions: FT_EXPORT and FT_EXPORT_DEF. */ - /* */ - /* FT_EXPORT( return_type ) */ - /* */ - /* is used in a function declaration, as in */ - /* */ - /* FT_EXPORT( FT_Error ) */ - /* FT_Init_FreeType( FT_Library* alibrary ); */ - /* */ - /* */ - /* FT_EXPORT_DEF( return_type ) */ - /* */ - /* is used in a function definition, as in */ - /* */ - /* FT_EXPORT_DEF( FT_Error ) */ - /* FT_Init_FreeType( FT_Library* alibrary ) */ - /* { */ - /* ... some code ... */ - /* return FT_Err_Ok; */ - /* } */ - /* */ - /* You can provide your own implementation of FT_EXPORT and */ - /* FT_EXPORT_DEF here if you want. If you leave them undefined, they */ - /* will be later automatically defined as `extern return_type' to */ - /* allow normal compilation. */ - /* */ - /* Do not #undef these macros here since the build system might define */ - /* them for certain configurations only. */ - /* */ -/* #define FT_EXPORT(x) extern x */ -/* #define FT_EXPORT_DEF(x) x */ - - - /*************************************************************************/ - /* */ - /* Glyph Postscript Names handling */ - /* */ - /* By default, FreeType 2 is compiled with the `PSNames' module. This */ - /* module is in charge of converting a glyph name string into a */ - /* Unicode value, or return a Macintosh standard glyph name for the */ - /* use with the TrueType `post' table. */ - /* */ - /* Undefine this macro if you do not want `PSNames' compiled in your */ - /* build of FreeType. This has the following effects: */ - /* */ - /* - The TrueType driver will provide its own set of glyph names, */ - /* if you build it to support postscript names in the TrueType */ - /* `post' table. */ - /* */ - /* - The Type 1 driver will not be able to synthetize a Unicode */ - /* charmap out of the glyphs found in the fonts. */ - /* */ - /* You would normally undefine this configuration macro when building */ - /* a version of FreeType that doesn't contain a Type 1 or CFF driver. */ - /* */ -#define FT_CONFIG_OPTION_POSTSCRIPT_NAMES - - - /*************************************************************************/ - /* */ - /* Postscript Names to Unicode Values support */ - /* */ - /* By default, FreeType 2 is built with the `PSNames' module compiled */ - /* in. Among other things, the module is used to convert a glyph name */ - /* into a Unicode value. This is especially useful in order to */ - /* synthetize on the fly a Unicode charmap from the CFF/Type 1 driver */ - /* through a big table named the `Adobe Glyph List' (AGL). */ - /* */ - /* Undefine this macro if you do not want the Adobe Glyph List */ - /* compiled in your `PSNames' module. The Type 1 driver will not be */ - /* able to synthetize a Unicode charmap out of the glyphs found in the */ - /* fonts. */ - /* */ -#define FT_CONFIG_OPTION_ADOBE_GLYPH_LIST - - - /*************************************************************************/ - /* */ - /* Support for Mac fonts */ - /* */ - /* Define this macro if you want support for outline fonts in Mac */ - /* format (mac dfont, mac resource, macbinary containing a mac */ - /* resource) on non-Mac platforms. */ - /* */ - /* Note that the `FOND' resource isn't checked. */ - /* */ -#define FT_CONFIG_OPTION_MAC_FONTS - - - /*************************************************************************/ - /* */ - /* Guessing methods to access embedded resource forks */ - /* */ - /* Enable extra Mac fonts support on non-Mac platforms (e.g. */ - /* GNU/Linux). */ - /* */ - /* Resource forks which include fonts data are stored sometimes in */ - /* locations which users or developers don't expected. In some cases, */ - /* resource forks start with some offset from the head of a file. In */ - /* other cases, the actual resource fork is stored in file different */ - /* from what the user specifies. If this option is activated, */ - /* FreeType tries to guess whether such offsets or different file */ - /* names must be used. */ - /* */ - /* Note that normal, direct access of resource forks is controlled via */ - /* the FT_CONFIG_OPTION_MAC_FONTS option. */ - /* */ -#ifdef FT_CONFIG_OPTION_MAC_FONTS -#define FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK -#endif - - - /*************************************************************************/ - /* */ - /* Allow the use of FT_Incremental_Interface to load typefaces that */ - /* contain no glyph data, but supply it via a callback function. */ - /* This allows FreeType to be used with the PostScript language, using */ - /* the GhostScript interpreter. */ - /* */ -/* #define FT_CONFIG_OPTION_INCREMENTAL */ - - - /*************************************************************************/ - /* */ - /* The size in bytes of the render pool used by the scan-line converter */ - /* to do all of its work. */ - /* */ - /* This must be greater than 4KByte if you use FreeType to rasterize */ - /* glyphs; otherwise, you may set it to zero to avoid unnecessary */ - /* allocation of the render pool. */ - /* */ -#define FT_RENDER_POOL_SIZE 16384L - - - /*************************************************************************/ - /* */ - /* FT_MAX_MODULES */ - /* */ - /* The maximum number of modules that can be registered in a single */ - /* FreeType library object. 32 is the default. */ - /* */ -#define FT_MAX_MODULES 32 - - - /*************************************************************************/ - /* */ - /* Debug level */ - /* */ - /* FreeType can be compiled in debug or trace mode. In debug mode, */ - /* errors are reported through the `ftdebug' component. In trace */ - /* mode, additional messages are sent to the standard output during */ - /* execution. */ - /* */ - /* Define FT_DEBUG_LEVEL_ERROR to build the library in debug mode. */ - /* Define FT_DEBUG_LEVEL_TRACE to build it in trace mode. */ - /* */ - /* Don't define any of these macros to compile in `release' mode! */ - /* */ - /* Do not #undef these macros here since the build system might define */ - /* them for certain configurations only. */ - /* */ -/* #define FT_DEBUG_LEVEL_ERROR */ -/* #define FT_DEBUG_LEVEL_TRACE */ - - - /*************************************************************************/ - /* */ - /* Memory Debugging */ - /* */ - /* FreeType now comes with an integrated memory debugger that is */ - /* capable of detecting simple errors like memory leaks or double */ - /* deletes. To compile it within your build of the library, you */ - /* should define FT_DEBUG_MEMORY here. */ - /* */ - /* Note that the memory debugger is only activated at runtime when */ - /* when the _environment_ variable `FT2_DEBUG_MEMORY' is defined also! */ - /* */ - /* Do not #undef this macro here since the build system might define */ - /* it for certain configurations only. */ - /* */ -/* #define FT_DEBUG_MEMORY */ - - - /*************************************************************************/ - /* */ - /* Module errors */ - /* */ - /* If this macro is set (which is _not_ the default), the higher byte */ - /* of an error code gives the module in which the error has occurred, */ - /* while the lower byte is the real error code. */ - /* */ - /* Setting this macro makes sense for debugging purposes only, since */ - /* it would break source compatibility of certain programs that use */ - /* FreeType 2. */ - /* */ - /* More details can be found in the files ftmoderr.h and fterrors.h. */ - /* */ -#undef FT_CONFIG_OPTION_USE_MODULE_ERRORS - - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** S F N T D R I V E R C O N F I G U R A T I O N ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* Define TT_CONFIG_OPTION_EMBEDDED_BITMAPS if you want to support */ - /* embedded bitmaps in all formats using the SFNT module (namely */ - /* TrueType & OpenType). */ - /* */ -#define TT_CONFIG_OPTION_EMBEDDED_BITMAPS - - - /*************************************************************************/ - /* */ - /* Define TT_CONFIG_OPTION_POSTSCRIPT_NAMES if you want to be able to */ - /* load and enumerate the glyph Postscript names in a TrueType or */ - /* OpenType file. */ - /* */ - /* Note that when you do not compile the `PSNames' module by undefining */ - /* the above FT_CONFIG_OPTION_POSTSCRIPT_NAMES, the `sfnt' module will */ - /* contain additional code used to read the PS Names table from a font. */ - /* */ - /* (By default, the module uses `PSNames' to extract glyph names.) */ - /* */ -#define TT_CONFIG_OPTION_POSTSCRIPT_NAMES - - - /*************************************************************************/ - /* */ - /* Define TT_CONFIG_OPTION_SFNT_NAMES if your applications need to */ - /* access the internal name table in a SFNT-based format like TrueType */ - /* or OpenType. The name table contains various strings used to */ - /* describe the font, like family name, copyright, version, etc. It */ - /* does not contain any glyph name though. */ - /* */ - /* Accessing SFNT names is done through the functions declared in */ - /* `freetype/ftnames.h'. */ - /* */ -#define TT_CONFIG_OPTION_SFNT_NAMES - - - /*************************************************************************/ - /* */ - /* TrueType CMap support */ - /* */ - /* Here you can fine-tune which TrueType CMap table format shall be */ - /* supported. */ -#define TT_CONFIG_CMAP_FORMAT_0 -#define TT_CONFIG_CMAP_FORMAT_2 -#define TT_CONFIG_CMAP_FORMAT_4 -#define TT_CONFIG_CMAP_FORMAT_6 -#define TT_CONFIG_CMAP_FORMAT_8 -#define TT_CONFIG_CMAP_FORMAT_10 -#define TT_CONFIG_CMAP_FORMAT_12 - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** T R U E T Y P E D R I V E R C O N F I G U R A T I O N ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - /*************************************************************************/ - /* */ - /* Define TT_CONFIG_OPTION_BYTECODE_INTERPRETER if you want to compile */ - /* a bytecode interpreter in the TrueType driver. Note that there are */ - /* important patent issues related to the use of the interpreter. */ - /* */ - /* By undefining this, you will only compile the code necessary to load */ - /* TrueType glyphs without hinting. */ - /* */ - /* Do not #undef this macro here, since the build system might */ - /* define it for certain configurations only. */ - /* */ -/* #define TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ - - - /*************************************************************************/ - /* */ - /* If you define TT_CONFIG_OPTION_UNPATENTED_HINTING, a special version */ - /* of the TrueType bytecode interpreter is used that doesn't implement */ - /* any of the patented opcodes and algorithms. Note that the */ - /* the TT_CONFIG_OPTION_UNPATENTED_HINTING macro is *ignored* if you */ - /* define TT_CONFIG_OPTION_BYTECODE_INTERPRETER; with other words, */ - /* either define TT_CONFIG_OPTION_BYTECODE_INTERPRETER or */ - /* TT_CONFIG_OPTION_UNPATENTED_HINTING but not both at the same time. */ - /* */ - /* This macro is only useful for a small number of font files (mostly */ - /* for Asian scripts) that require bytecode interpretation to properly */ - /* load glyphs. For all other fonts, this produces unpleasant results, */ - /* thus the unpatented interpreter is never used to load glyphs from */ - /* TrueType fonts unless one of the following two options is used. */ - /* */ - /* - The unpatented interpreter is explicitly activated by the user */ - /* through the FT_PARAM_TAG_UNPATENTED_HINTING parameter tag */ - /* when opening the FT_Face. */ - /* */ - /* - FreeType detects that the FT_Face corresponds to one of the */ - /* `trick' fonts (e.g., `Mingliu') it knows about. The font engine */ - /* contains a hard-coded list of font names and other matching */ - /* parameters (see function `tt_face_init' in file */ - /* `src/truetype/ttobjs.c'). */ - /* */ - /* Here a sample code snippet for using FT_PARAM_TAG_UNPATENTED_HINTING. */ - /* */ - /* { */ - /* FT_Parameter parameter; */ - /* FT_Open_Args open_args; */ - /* */ - /* */ - /* parameter.tag = FT_PARAM_TAG_UNPATENTED_HINTING; */ - /* */ - /* open_args.flags = FT_OPEN_PATHNAME | FT_OPEN_PARAMS; */ - /* open_args.pathname = my_font_pathname; */ - /* open_args.num_params = 1; */ - /* open_args.params = ¶meter; */ - /* */ - /* error = FT_Open_Face( library, &open_args, index, &face ); */ - /* ... */ - /* } */ - /* */ -#define TT_CONFIG_OPTION_UNPATENTED_HINTING - - - /*************************************************************************/ - /* */ - /* Define TT_CONFIG_OPTION_INTERPRETER_SWITCH to compile the TrueType */ - /* bytecode interpreter with a huge switch statement, rather than a call */ - /* table. This results in smaller and faster code for a number of */ - /* architectures. */ - /* */ - /* Note however that on some compiler/processor combinations, undefining */ - /* this macro will generate faster, though larger, code. */ - /* */ -#define TT_CONFIG_OPTION_INTERPRETER_SWITCH - - - /*************************************************************************/ - /* */ - /* Define TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED to compile the */ - /* TrueType glyph loader to use Apple's definition of how to handle */ - /* component offsets in composite glyphs. */ - /* */ - /* Apple and MS disagree on the default behavior of component offsets */ - /* in composites. Apple says that they should be scaled by the scaling */ - /* factors in the transformation matrix (roughly, it's more complex) */ - /* while MS says they should not. OpenType defines two bits in the */ - /* composite flags array which can be used to disambiguate, but old */ - /* fonts will not have them. */ - /* */ - /* http://partners.adobe.com/asn/developer/opentype/glyf.html */ - /* http://fonts.apple.com/TTRefMan/RM06/Chap6glyf.html */ - /* */ -#undef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED - - - /*************************************************************************/ - /* */ - /* Define TT_CONFIG_OPTION_GX_VAR_SUPPORT if you want to include */ - /* support for Apple's distortable font technology (fvar, gvar, cvar, */ - /* and avar tables). This has many similarities to Type 1 Multiple */ - /* Masters support. */ - /* */ -#define TT_CONFIG_OPTION_GX_VAR_SUPPORT - - - /*************************************************************************/ - /* */ - /* Define TT_CONFIG_OPTION_BDF if you want to include support for */ - /* an embedded `BDF ' table within SFNT-based bitmap formats. */ - /* */ -#define TT_CONFIG_OPTION_BDF - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** T Y P E 1 D R I V E R C O N F I G U R A T I O N ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* T1_MAX_DICT_DEPTH is the maximal depth of nest dictionaries and */ - /* arrays in the Type 1 stream (see t1load.c). A minimum of 4 is */ - /* required. */ - /* */ -#define T1_MAX_DICT_DEPTH 5 - - - /*************************************************************************/ - /* */ - /* T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine */ - /* calls during glyph loading. */ - /* */ -#define T1_MAX_SUBRS_CALLS 16 - - - /*************************************************************************/ - /* */ - /* T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. A */ - /* minimum of 16 is required. */ - /* */ - /* The Chinese font MingTiEG-Medium (CNS 11643 character set) needs 256. */ - /* */ -#define T1_MAX_CHARSTRINGS_OPERANDS 256 - - - /*************************************************************************/ - /* */ - /* Define this configuration macro if you want to prevent the */ - /* compilation of `t1afm', which is in charge of reading Type 1 AFM */ - /* files into an existing face. Note that if set, the T1 driver will be */ - /* unable to produce kerning distances. */ - /* */ -#undef T1_CONFIG_OPTION_NO_AFM - - - /*************************************************************************/ - /* */ - /* Define this configuration macro if you want to prevent the */ - /* compilation of the Multiple Masters font support in the Type 1 */ - /* driver. */ - /* */ -#undef T1_CONFIG_OPTION_NO_MM_SUPPORT - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** A U T O F I T M O D U L E C O N F I G U R A T I O N ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* Compile autofit module with CJK script support. */ - /* */ -#define AF_CONFIG_OPTION_CJK - - /*************************************************************************/ - /* */ - /* Compile autofit module with Indic script support. */ - /* */ -#define AF_CONFIG_OPTION_INDIC - - /* */ - - - /* - * Define this variable if you want to keep the layout of internal - * structures that was used prior to FreeType 2.2. This also compiles in - * a few obsolete functions to avoid linking problems on typical Unix - * distributions. - * - * For embedded systems or building a new distribution from scratch, it - * is recommended to disable the macro since it reduces the library's code - * size and activates a few memory-saving optimizations as well. - */ -#define FT_CONFIG_OPTION_OLD_INTERNALS - - - /* - * This variable is defined if either unpatented or native TrueType - * hinting is requested by the definitions above. - */ -#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER -#define TT_USE_BYTECODE_INTERPRETER -#elif defined TT_CONFIG_OPTION_UNPATENTED_HINTING -#define TT_USE_BYTECODE_INTERPRETER -#endif - -FT_END_HEADER - - -#endif /* __FTOPTION_H__ */ - - -/* END */ diff --git a/common/freetype/config/ftstdlib.h b/common/freetype/config/ftstdlib.h deleted file mode 100644 index f923f3e4..00000000 --- a/common/freetype/config/ftstdlib.h +++ /dev/null @@ -1,180 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftstdlib.h */ -/* */ -/* ANSI-specific library and header configuration file (specification */ -/* only). */ -/* */ -/* Copyright 2002, 2003, 2004, 2005, 2006, 2007 by */ -/* David Turner, Robert Wilhelm, and Werner Lemberg. */ -/* */ -/* This file is part of the FreeType project, and may only be used, */ -/* modified, and distributed under the terms of the FreeType project */ -/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ -/* this file you indicate that you have read the license and */ -/* understand and accept it fully. */ -/* */ -/***************************************************************************/ - - - /*************************************************************************/ - /* */ - /* This file is used to group all #includes to the ANSI C library that */ - /* FreeType normally requires. It also defines macros to rename the */ - /* standard functions within the FreeType source code. */ - /* */ - /* Load a file which defines __FTSTDLIB_H__ before this one to override */ - /* it. */ - /* */ - /*************************************************************************/ - - -#ifndef __FTSTDLIB_H__ -#define __FTSTDLIB_H__ - - -#include <stddef.h> - -#define ft_ptrdiff_t ptrdiff_t - - - /**********************************************************************/ - /* */ - /* integer limits */ - /* */ - /* UINT_MAX and ULONG_MAX are used to automatically compute the size */ - /* of `int' and `long' in bytes at compile-time. So far, this works */ - /* for all platforms the library has been tested on. */ - /* */ - /* Note that on the extremely rare platforms that do not provide */ - /* integer types that are _exactly_ 16 and 32 bits wide (e.g. some */ - /* old Crays where `int' is 36 bits), we do not make any guarantee */ - /* about the correct behaviour of FT2 with all fonts. */ - /* */ - /* In these case, `ftconfig.h' will refuse to compile anyway with a */ - /* message like `couldn't find 32-bit type' or something similar. */ - /* */ - /* IMPORTANT NOTE: We do not define aliases for heap management and */ - /* i/o routines (i.e. malloc/free/fopen/fread/...) */ - /* since these functions should all be encapsulated */ - /* by platform-specific implementations of */ - /* `ftsystem.c'. */ - /* */ - /**********************************************************************/ - - -#include <limits.h> - -#define FT_CHAR_BIT CHAR_BIT -#define FT_INT_MAX INT_MAX -#define FT_UINT_MAX UINT_MAX -#define FT_ULONG_MAX ULONG_MAX - - - /**********************************************************************/ - /* */ - /* character and string processing */ - /* */ - /**********************************************************************/ - - -#include <string.h> - -#define ft_memchr memchr -#define ft_memcmp memcmp -#define ft_memcpy memcpy -#define ft_memmove memmove -#define ft_memset memset -#define ft_strcat strcat -#define ft_strcmp strcmp -#define ft_strcpy strcpy -#define ft_strlen strlen -#define ft_strncmp strncmp -#define ft_strncpy strncpy -#define ft_strrchr strrchr -#define ft_strstr strstr - - - /**********************************************************************/ - /* */ - /* file handling */ - /* */ - /**********************************************************************/ - - -#include <stdio.h> - -#define FT_FILE FILE -#define ft_fclose fclose -#define ft_fopen fopen -#define ft_fread fread -#define ft_fseek fseek -#define ft_ftell ftell -#define ft_sprintf sprintf - - - /**********************************************************************/ - /* */ - /* sorting */ - /* */ - /**********************************************************************/ - - -#include <stdlib.h> - -#define ft_qsort qsort - -#define ft_exit exit /* only used to exit from unhandled exceptions */ - - - /**********************************************************************/ - /* */ - /* memory allocation */ - /* */ - /**********************************************************************/ - - -#define ft_scalloc calloc -#define ft_sfree free -#define ft_smalloc malloc -#define ft_srealloc realloc - - - /**********************************************************************/ - /* */ - /* miscellaneous */ - /* */ - /**********************************************************************/ - - -#define ft_atol atol -#define ft_labs labs - - - /**********************************************************************/ - /* */ - /* execution control */ - /* */ - /**********************************************************************/ - - -#include <setjmp.h> - -#define ft_jmp_buf jmp_buf /* note: this cannot be a typedef since */ - /* jmp_buf is defined as a macro */ - /* on certain platforms */ - -#define ft_longjmp longjmp -#define ft_setjmp( b ) setjmp( *(jmp_buf*) &(b) ) /* same thing here */ - - - /* the following is only used for debugging purposes, i.e., if */ - /* FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined */ - -#include <stdarg.h> - - -#endif /* __FTSTDLIB_H__ */ - - -/* END */ diff --git a/engine/sv_log.cpp b/engine/sv_log.cpp index a877df22..f04d17da 100644 --- a/engine/sv_log.cpp +++ b/engine/sv_log.cpp @@ -697,12 +697,14 @@ static bool CreateTempFilename( TempFilename_t &info, const char *filenameBase, if ( info.fh.file ) return true; } +#if HAVE_ZLIB else { info.fh.gzfile = gzopen( info.Filename, "wb6" ); if ( info.fh.gzfile ) return true; } +#endif } } diff --git a/engine/sys_dll.cpp b/engine/sys_dll.cpp index c30e0122..1a041f90 100644 --- a/engine/sys_dll.cpp +++ b/engine/sys_dll.cpp @@ -1578,7 +1578,7 @@ CON_COMMAND( star_memory, "Dump memory stats" ) { // get a current stat of available memory // 32 MB is reserved and fixed by OS, so not reporting to allow memory loggers sync -#ifdef LINUX +#if defined( PLATFORM_GLIBC ) struct mallinfo memstats = mallinfo( ); Msg( "sbrk size: %.2f MB, Used: %.2f MB, #mallocs = %d\n", memstats.arena / ( 1024.0 * 1024.0), memstats.uordblks / ( 1024.0 * 1024.0 ), memstats.hblks ); @@ -1586,14 +1586,14 @@ CON_COMMAND( star_memory, "Dump memory stats" ) struct mstats memstats = mstats( ); Msg( "Available %.2f MB, Used: %.2f MB, #mallocs = %lu\n", memstats.bytes_free / ( 1024.0 * 1024.0), memstats.bytes_used / ( 1024.0 * 1024.0 ), memstats.chunks_used ); -#elif PLATFORM_BSD -# warning TODO: Implement memory stats (peace of sheet of course) -#else // Win32 +#elif defined( _WIN32 ) // Win32 MEMORYSTATUS stat; GlobalMemoryStatus( &stat ); Msg( "Available: %.2f MB, Used: %.2f MB, Free: %.2f MB\n", stat.dwTotalPhys/( 1024.0f*1024.0f ) - 32.0f, ( stat.dwTotalPhys - stat.dwAvailPhys )/( 1024.0f*1024.0f ) - 32.0f, stat.dwAvailPhys/( 1024.0f*1024.0f ) ); +#else +#warning TODO: Implement memory stats #endif } diff --git a/engine/sys_dll2.cpp b/engine/sys_dll2.cpp index 10d0c0d5..f56b4c72 100644 --- a/engine/sys_dll2.cpp +++ b/engine/sys_dll2.cpp @@ -279,10 +279,6 @@ static void posix_signal_handler( int i ) #define DO_TRY if ( sigsetjmp( g_mark, 1 ) == 0 ) #define DO_CATCH else -#if defined( OSX ) || defined(PLATFORM_BSD) -#define __sighandler_t sig_t -#endif - #else #define DO_TRY try @@ -390,7 +386,7 @@ public: _se_translator_function curfilter = _set_se_translator( &FailSafe ); #elif defined( POSIX ) // Only need to worry about this function crashing when we're dealing with a real crash. - __sighandler_t curfilter = bRealCrash ? signal( SIGSEGV, posix_signal_handler ) : 0; + sig_t curfilter = bRealCrash ? signal( SIGSEGV, posix_signal_handler ) : 0; #endif DO_TRY diff --git a/ivp b/ivp index bceb2c42..4098acbb 160000 --- a/ivp +++ b/ivp @@ -1 +1 @@ -Subproject commit bceb2c427255f181a2538ca43369989aa0d983d7 +Subproject commit 4098acbbe3bc48320496f7533851640cc40cbb89 diff --git a/public/tier0/basetypes.h b/public/tier0/basetypes.h index 0e67c9fa..6168ee56 100644 --- a/public/tier0/basetypes.h +++ b/public/tier0/basetypes.h @@ -38,11 +38,14 @@ #define XBOX_CODELINE_ONLY() Error_Compiling_Code_Only_Valid_in_Xbox_Codeline #endif -// stdio.h -#if !defined(NULL) || defined(__FreeBSD__) -#ifdef NULL -# undef NULL +#ifdef nullptr +#undef nullptr +#define nullptr 0 #endif + +// stdio.h +#ifdef NULL +#undef NULL #define NULL 0 #endif diff --git a/public/tier0/platform.h b/public/tier0/platform.h index 99ac5b3b..a8ad1b02 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -17,6 +17,10 @@ #define COMPILER_GCC 1 #endif +#ifdef __GLIBC__ +#define PLATFORM_GLIBC 1 +#endif + #ifdef __clang__ #define COMPILER_CLANG 1 #endif diff --git a/tier0/assert_dialog.cpp b/tier0/assert_dialog.cpp index e13b47e0..d0a73b8e 100644 --- a/tier0/assert_dialog.cpp +++ b/tier0/assert_dialog.cpp @@ -386,9 +386,7 @@ DBG_INTERFACE bool ShouldUseNewAssertDialog() #endif // DBGFLAG_ASSERTDLG } -#if defined( POSIX ) && !defined ( ANDROID ) - -#include <execinfo.h> +#if defined( POSIX ) && PLATFORM_GLIBC static void SpewBacktrace() { @@ -441,7 +439,7 @@ DBG_INTERFACE bool DoNewAssertDialog( const tchar *pFilename, int line, const tc pFilename, line, pExpression); if ( getenv( "POSIX_ASSERT_BACKTRACE" ) ) { -#if !defined ( ANDROID ) +#if PLATFORM_GLIBC SpewBacktrace(); #endif } diff --git a/tier0/stacktools.cpp b/tier0/stacktools.cpp index f32dc4d5..8c4aeab0 100644 --- a/tier0/stacktools.cpp +++ b/tier0/stacktools.cpp @@ -27,7 +27,7 @@ #include <set> #endif -#if defined( LINUX ) && !defined( ANDROID ) +#if defined( LINUX ) && defined( PLATFORM_GLIBC ) #include <execinfo.h> #endif @@ -38,7 +38,7 @@ #if !defined( ENABLE_RUNTIME_STACK_TRANSLATION ) //disable the whole toolset -#if defined( LINUX ) && !defined( ANDROID ) +#if defined( LINUX ) && defined( PLATFORM_GLIBC ) int GetCallStack( void **pReturnAddressesOut, int iArrayCount, int iSkipCount ) { diff --git a/tier0/threadtools.cpp b/tier0/threadtools.cpp index 06c8296f..d5194927 100644 --- a/tier0/threadtools.cpp +++ b/tier0/threadtools.cpp @@ -27,13 +27,8 @@ #define GetLastError() errno typedef void *LPVOID; #if !defined(OSX) -#if defined(ANDROID) #include <fcntl.h> #include <unistd.h> -#else - #include <sys/fcntl.h> - #include <sys/unistd.h> -#endif #define sem_unlink( arg ) #define OS_TO_PTHREAD(x) (x) #else diff --git a/tier1/strtools.cpp b/tier1/strtools.cpp index ce1adb0c..a967fbfe 100644 --- a/tier1/strtools.cpp +++ b/tier1/strtools.cpp @@ -80,7 +80,7 @@ #include "tier0/memdbgon.h" #ifdef ANDROID -#include "common/iconv.h" +#include "common/android/iconv.h" #elif POSIX #include <iconv.h> #endif From 54c339bdc0375f29ada92e02a1471bb24c5132f9 Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Mon, 24 Apr 2023 23:23:09 +0000 Subject: [PATCH 16/29] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b442d98..a29954bb 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Source code is based on TF2 2018 leak. Don't use it for commercial purposes. This project is using waf buildsystem. If you have waf-related questions look https://waf.io/book # Features: -- Android, OSX, FreeBSD, Windows support +- Android, OSX, FreeBSD, Windows, Linux( glibc, musl ) support - Arm support( except windows ) - 64bit support - Modern toolchains support From 38fdbf18c204803efb18e076271630ac7419801b Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Tue, 25 Apr 2023 00:40:23 +0000 Subject: [PATCH 17/29] fix musl-idiodic libsc problems --- public/tier0/basetypes.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/tier0/basetypes.h b/public/tier0/basetypes.h index 6168ee56..27ef9618 100644 --- a/public/tier0/basetypes.h +++ b/public/tier0/basetypes.h @@ -40,9 +40,11 @@ #ifdef nullptr #undef nullptr -#define nullptr 0 #endif +#define nullptr 0 + + // stdio.h #ifdef NULL #undef NULL From 852f4052be67d7789a27489b17ac362afc919c0b Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Tue, 25 Apr 2023 00:45:25 +0300 Subject: [PATCH 18/29] fix idiotic libs problems again --- public/tier0/basetypes.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/tier0/basetypes.h b/public/tier0/basetypes.h index 27ef9618..8a267122 100644 --- a/public/tier0/basetypes.h +++ b/public/tier0/basetypes.h @@ -38,15 +38,17 @@ #define XBOX_CODELINE_ONLY() Error_Compiling_Code_Only_Valid_in_Xbox_Codeline #endif + +#if !defined(PLATFORM_GLIBC) && defined(LINUX) // fuck musl #ifdef nullptr #undef nullptr #endif - #define nullptr 0 +#endif // stdio.h -#ifdef NULL +#if !defined( NULL ) || defined( PLATFORM_BSD ) #undef NULL #define NULL 0 #endif From a63138347b663a4bfd961627b00ad95ea7f27aef Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Tue, 25 Apr 2023 15:08:19 +0000 Subject: [PATCH 19/29] disable fortify-source headers --- wscript | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wscript b/wscript index ada484c5..f4221618 100644 --- a/wscript +++ b/wscript @@ -198,6 +198,8 @@ def define_platform(conf): 'NO_HOOK_MALLOC', '_DLL_EXT=.so' ]) + conf.env.append_unique('CFLAGS', '-U_FORTIFY_SOURCE') + conf.env.append_unique('CXXFLAGS', '-U_FORTIFY_SOURCE') elif conf.env.DEST_OS == 'android': conf.env.append_unique('DEFINES', [ 'ANDROID=1', '_ANDROID=1', @@ -207,6 +209,7 @@ def define_platform(conf): 'NO_HOOK_MALLOC', '_DLL_EXT=.so' ]) + elif conf.env.DEST_OS == 'win32': conf.env.append_unique('DEFINES', [ 'WIN32=1', '_WIN32=1', From 823e437005e69ad0764b6aa1abe6e4b869d5b94c Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Wed, 26 Apr 2023 22:30:28 +0300 Subject: [PATCH 20/29] wscript(android,windows): add sdl2 to installation path --- inputsystem/wscript | 11 +---------- wscript | 5 +++++ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/inputsystem/wscript b/inputsystem/wscript index 9089c72a..252452aa 100755 --- a/inputsystem/wscript +++ b/inputsystem/wscript @@ -43,17 +43,8 @@ def build(bld): if bld.env.DEST_OS == 'win32': libs += ['USER32'] - - install_path = bld.env.LIBDIR - # Copy SDL2 dependency - if bld.env.DEST_OS == 'win32': - bld( - rule=(('cp' if 'MSYSTEM' in os.environ or sys.platform != 'win32' else 'copy')+' ${SRC} ${TGT}'), - source='../lib/win32/'+bld.env.DEST_CPU+'/SDL2.dll', - target='SDL2.dll', - install_path=install_path, - ) + install_path = bld.env.LIBDIR bld.shlib( source = source, diff --git a/wscript b/wscript index f4221618..95871403 100644 --- a/wscript +++ b/wscript @@ -591,6 +591,11 @@ def configure(conf): def build(bld): os.environ["CCACHE_DIR"] = os.path.abspath('.ccache/'+bld.env.COMPILER_CC+'/'+bld.env.DEST_OS+'/'+bld.env.DEST_CPU) + if bld.env.DEST_OS in ['win32', 'android']: + sdl_name = 'SDL2.dll' if bld.env.DEST_OS == 'win32' else 'libSDL2.so' + sdl_path = os.path.join('lib', bld.env.DEST_OS, bld.env.DEST_CPU, sdl_name) + bld.install_files('${PREFIX}/', [sdl_path]) + if bld.env.DEST_OS == 'win32': projects['game'] += ['utils/bzip2'] projects['dedicated'] += ['utils/bzip2'] From 7ceba7761637443692384ece1d54ce3fde09b635 Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Wed, 26 Apr 2023 19:56:15 +0000 Subject: [PATCH 21/29] WIP: move vmatrix functions to header and inline them --- mathlib/mathlib_base.cpp | 58 -- mathlib/vmatrix.cpp | 1264 -------------------------- public/mathlib/math_pfns.h | 12 +- public/mathlib/mathlib.h | 31 +- public/mathlib/vector4d.h | 2 +- public/mathlib/vmatrix.h | 1730 +++++++++++++++++++++++++++++------- 6 files changed, 1443 insertions(+), 1654 deletions(-) diff --git a/mathlib/mathlib_base.cpp b/mathlib/mathlib_base.cpp index 3b8fbe2f..60113379 100644 --- a/mathlib/mathlib_base.cpp +++ b/mathlib/mathlib_base.cpp @@ -420,13 +420,6 @@ void MatrixGetColumn( const matrix3x4_t& in, int column, Vector &out ) out.z = in[2][column]; } -void MatrixSetColumn( const Vector &in, int column, matrix3x4_t& out ) -{ - out[0][column] = in.x; - out[1][column] = in.y; - out[2][column] = in.z; -} - void MatrixScaleBy ( const float flScale, matrix3x4_t &out ) { out[0][0] *= flScale; @@ -1092,57 +1085,6 @@ void SetScaleMatrix( float x, float y, float z, matrix3x4_t &dst ) dst[2][0] = 0.0f; dst[2][1] = 0.0f; dst[2][2] = z; dst[2][3] = 0.0f; } - -//----------------------------------------------------------------------------- -// Purpose: Builds the matrix for a counterclockwise rotation about an arbitrary axis. -// -// | ax2 + (1 - ax2)cosQ axay(1 - cosQ) - azsinQ azax(1 - cosQ) + aysinQ | -// Ra(Q) = | axay(1 - cosQ) + azsinQ ay2 + (1 - ay2)cosQ ayaz(1 - cosQ) - axsinQ | -// | azax(1 - cosQ) - aysinQ ayaz(1 - cosQ) + axsinQ az2 + (1 - az2)cosQ | -// -// Input : mat - -// vAxisOrRot - -// angle - -//----------------------------------------------------------------------------- -void MatrixBuildRotationAboutAxis( const Vector &vAxisOfRot, float angleDegrees, matrix3x4_t &dst ) -{ - float radians; - float axisXSquared; - float axisYSquared; - float axisZSquared; - float fSin; - float fCos; - - radians = angleDegrees * ( M_PI / 180.0 ); - fSin = sin( radians ); - fCos = cos( radians ); - - axisXSquared = vAxisOfRot[0] * vAxisOfRot[0]; - axisYSquared = vAxisOfRot[1] * vAxisOfRot[1]; - axisZSquared = vAxisOfRot[2] * vAxisOfRot[2]; - - // Column 0: - dst[0][0] = axisXSquared + (1 - axisXSquared) * fCos; - dst[1][0] = vAxisOfRot[0] * vAxisOfRot[1] * (1 - fCos) + vAxisOfRot[2] * fSin; - dst[2][0] = vAxisOfRot[2] * vAxisOfRot[0] * (1 - fCos) - vAxisOfRot[1] * fSin; - - // Column 1: - dst[0][1] = vAxisOfRot[0] * vAxisOfRot[1] * (1 - fCos) - vAxisOfRot[2] * fSin; - dst[1][1] = axisYSquared + (1 - axisYSquared) * fCos; - dst[2][1] = vAxisOfRot[1] * vAxisOfRot[2] * (1 - fCos) + vAxisOfRot[0] * fSin; - - // Column 2: - dst[0][2] = vAxisOfRot[2] * vAxisOfRot[0] * (1 - fCos) + vAxisOfRot[1] * fSin; - dst[1][2] = vAxisOfRot[1] * vAxisOfRot[2] * (1 - fCos) - vAxisOfRot[0] * fSin; - dst[2][2] = axisZSquared + (1 - axisZSquared) * fCos; - - // Column 3: - dst[0][3] = 0; - dst[1][3] = 0; - dst[2][3] = 0; -} - - //----------------------------------------------------------------------------- // Computes the transpose //----------------------------------------------------------------------------- diff --git a/mathlib/vmatrix.cpp b/mathlib/vmatrix.cpp index 01a987b4..31c1000e 100644 --- a/mathlib/vmatrix.cpp +++ b/mathlib/vmatrix.cpp @@ -24,1270 +24,6 @@ // Helper functions. // ------------------------------------------------------------------------------------------- // -#ifndef VECTOR_NO_SLOW_OPERATIONS -VMatrix SetupMatrixIdentity() -{ - return VMatrix( - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); -} - -VMatrix SetupMatrixTranslation(const Vector &vTranslation) -{ - return VMatrix( - 1.0f, 0.0f, 0.0f, vTranslation.x, - 0.0f, 1.0f, 0.0f, vTranslation.y, - 0.0f, 0.0f, 1.0f, vTranslation.z, - 0.0f, 0.0f, 0.0f, 1.0f - ); -} - -VMatrix SetupMatrixScale(const Vector &vScale) -{ - return VMatrix( - vScale.x, 0.0f, 0.0f, 0.0f, - 0.0f, vScale.y, 0.0f, 0.0f, - 0.0f, 0.0f, vScale.z, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - ); -} - -VMatrix SetupMatrixReflection(const VPlane &thePlane) -{ - VMatrix mReflect, mBack, mForward; - Vector vOrigin, N; - - N = thePlane.m_Normal; - - mReflect.Init( - -2.0f*N.x*N.x + 1.0f, -2.0f*N.x*N.y, -2.0f*N.x*N.z, 0.0f, - -2.0f*N.y*N.x, -2.0f*N.y*N.y + 1.0f, -2.0f*N.y*N.z, 0.0f, - -2.0f*N.z*N.x, -2.0f*N.z*N.y, -2.0f*N.z*N.z + 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - ); - - vOrigin = thePlane.GetPointOnPlane(); - - mBack.Identity(); - mBack.SetTranslation(-vOrigin); - - mForward.Identity(); - mForward.SetTranslation(vOrigin); - - // (multiplied in reverse order, so it translates to the origin point, - // reflects, and translates back). - return mForward * mReflect * mBack; -} - -VMatrix SetupMatrixProjection(const Vector &vOrigin, const VPlane &thePlane) -{ - vec_t dot; - VMatrix mRet; - - - #define PN thePlane.m_Normal - #define PD thePlane.m_Dist; - - dot = PN[0]*vOrigin.x + PN[1]*vOrigin.y + PN[2]*vOrigin.z - PD; - - mRet.m[0][0] = dot - vOrigin.x * PN[0]; - mRet.m[0][1] = -vOrigin.x * PN[1]; - mRet.m[0][2] = -vOrigin.x * PN[2]; - mRet.m[0][3] = -vOrigin.x * -PD; - - mRet.m[1][0] = -vOrigin.y * PN[0]; - mRet.m[1][1] = dot - vOrigin.y * PN[1]; - mRet.m[1][2] = -vOrigin.y * PN[2]; - mRet.m[1][3] = -vOrigin.y * -PD; - - mRet.m[2][0] = -vOrigin.z * PN[0]; - mRet.m[2][1] = -vOrigin.z * PN[1]; - mRet.m[2][2] = dot - vOrigin.z * PN[2]; - mRet.m[2][3] = -vOrigin.z * -PD; - - mRet.m[3][0] = -PN[0]; - mRet.m[3][1] = -PN[1]; - mRet.m[3][2] = -PN[2]; - mRet.m[3][3] = dot + PD; - - #undef PN - #undef PD - - return mRet; -} - -VMatrix SetupMatrixAxisRot(const Vector &vAxis, vec_t fDegrees) -{ - vec_t s, c, t; - vec_t tx, ty, tz; - vec_t sx, sy, sz; - vec_t fRadians; - - - fRadians = fDegrees * (M_PI / 180.0f); - - s = (vec_t)sin(fRadians); - c = (vec_t)cos(fRadians); - t = 1.0f - c; - - tx = t * vAxis.x; ty = t * vAxis.y; tz = t * vAxis.z; - sx = s * vAxis.x; sy = s * vAxis.y; sz = s * vAxis.z; - - return VMatrix( - tx*vAxis.x + c, tx*vAxis.y - sz, tx*vAxis.z + sy, 0.0f, - tx*vAxis.y + sz, ty*vAxis.y + c, ty*vAxis.z - sx, 0.0f, - tx*vAxis.z - sy, ty*vAxis.z + sx, tz*vAxis.z + c, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); -} - -VMatrix SetupMatrixAngles(const QAngle &vAngles) -{ - VMatrix mRet; - MatrixFromAngles( vAngles, mRet ); - return mRet; -} - -VMatrix SetupMatrixOrgAngles(const Vector &origin, const QAngle &vAngles) -{ - VMatrix mRet; - mRet.SetupMatrixOrgAngles( origin, vAngles ); - return mRet; -} - -#endif // VECTOR_NO_SLOW_OPERATIONS - - -bool PlaneIntersection( const VPlane &vp1, const VPlane &vp2, const VPlane &vp3, Vector &vOut ) -{ - VMatrix mMat, mInverse; - - mMat.Init( - vp1.m_Normal.x, vp1.m_Normal.y, vp1.m_Normal.z, -vp1.m_Dist, - vp2.m_Normal.x, vp2.m_Normal.y, vp2.m_Normal.z, -vp2.m_Dist, - vp3.m_Normal.x, vp3.m_Normal.y, vp3.m_Normal.z, -vp3.m_Dist, - 0.0f, 0.0f, 0.0f, 1.0f - ); - - if(mMat.InverseGeneral(mInverse)) - { - //vOut = mInverse * Vector(0.0f, 0.0f, 0.0f); - mInverse.GetTranslation( vOut ); - return true; - } - else - { - return false; - } -} - - - -// ------------------------------------------------------------------------------------------- // -// VMatrix functions. -// ------------------------------------------------------------------------------------------- // - -VMatrix& VMatrix::operator=(const VMatrix &mOther) -{ - m[0][0] = mOther.m[0][0]; - m[0][1] = mOther.m[0][1]; - m[0][2] = mOther.m[0][2]; - m[0][3] = mOther.m[0][3]; - - m[1][0] = mOther.m[1][0]; - m[1][1] = mOther.m[1][1]; - m[1][2] = mOther.m[1][2]; - m[1][3] = mOther.m[1][3]; - - m[2][0] = mOther.m[2][0]; - m[2][1] = mOther.m[2][1]; - m[2][2] = mOther.m[2][2]; - m[2][3] = mOther.m[2][3]; - - m[3][0] = mOther.m[3][0]; - m[3][1] = mOther.m[3][1]; - m[3][2] = mOther.m[3][2]; - m[3][3] = mOther.m[3][3]; - - return *this; -} - -bool VMatrix::operator==( const VMatrix& src ) const -{ - return !memcmp( src.m, m, sizeof(m) ); -} - -void VMatrix::MatrixMul( const VMatrix &vm, VMatrix &out ) const -{ - out.Init( - m[0][0]*vm.m[0][0] + m[0][1]*vm.m[1][0] + m[0][2]*vm.m[2][0] + m[0][3]*vm.m[3][0], - m[0][0]*vm.m[0][1] + m[0][1]*vm.m[1][1] + m[0][2]*vm.m[2][1] + m[0][3]*vm.m[3][1], - m[0][0]*vm.m[0][2] + m[0][1]*vm.m[1][2] + m[0][2]*vm.m[2][2] + m[0][3]*vm.m[3][2], - m[0][0]*vm.m[0][3] + m[0][1]*vm.m[1][3] + m[0][2]*vm.m[2][3] + m[0][3]*vm.m[3][3], - - m[1][0]*vm.m[0][0] + m[1][1]*vm.m[1][0] + m[1][2]*vm.m[2][0] + m[1][3]*vm.m[3][0], - m[1][0]*vm.m[0][1] + m[1][1]*vm.m[1][1] + m[1][2]*vm.m[2][1] + m[1][3]*vm.m[3][1], - m[1][0]*vm.m[0][2] + m[1][1]*vm.m[1][2] + m[1][2]*vm.m[2][2] + m[1][3]*vm.m[3][2], - m[1][0]*vm.m[0][3] + m[1][1]*vm.m[1][3] + m[1][2]*vm.m[2][3] + m[1][3]*vm.m[3][3], - - m[2][0]*vm.m[0][0] + m[2][1]*vm.m[1][0] + m[2][2]*vm.m[2][0] + m[2][3]*vm.m[3][0], - m[2][0]*vm.m[0][1] + m[2][1]*vm.m[1][1] + m[2][2]*vm.m[2][1] + m[2][3]*vm.m[3][1], - m[2][0]*vm.m[0][2] + m[2][1]*vm.m[1][2] + m[2][2]*vm.m[2][2] + m[2][3]*vm.m[3][2], - m[2][0]*vm.m[0][3] + m[2][1]*vm.m[1][3] + m[2][2]*vm.m[2][3] + m[2][3]*vm.m[3][3], - - m[3][0]*vm.m[0][0] + m[3][1]*vm.m[1][0] + m[3][2]*vm.m[2][0] + m[3][3]*vm.m[3][0], - m[3][0]*vm.m[0][1] + m[3][1]*vm.m[1][1] + m[3][2]*vm.m[2][1] + m[3][3]*vm.m[3][1], - m[3][0]*vm.m[0][2] + m[3][1]*vm.m[1][2] + m[3][2]*vm.m[2][2] + m[3][3]*vm.m[3][2], - m[3][0]*vm.m[0][3] + m[3][1]*vm.m[1][3] + m[3][2]*vm.m[2][3] + m[3][3]*vm.m[3][3] - ); -} - -#ifndef VECTOR_NO_SLOW_OPERATIONS - -VMatrix VMatrix::operator*(const VMatrix &vm) const -{ - VMatrix ret; - MatrixMul( vm, ret ); - return ret; -} - -#endif - -bool VMatrix::InverseGeneral(VMatrix &vInverse) const -{ - return MatrixInverseGeneral( *this, vInverse ); -} - - -bool MatrixInverseGeneral(const VMatrix& src, VMatrix& dst) -{ - int iRow, i, j, iTemp, iTest; - vec_t mul, fTest, fLargest; - vec_t mat[4][8]; - int rowMap[4], iLargest; - vec_t *pOut, *pRow, *pScaleRow; - - - // How it's done. - // AX = I - // A = this - // X = the matrix we're looking for - // I = identity - - // Setup AI - for(i=0; i < 4; i++) - { - const vec_t *pIn = src[i]; - pOut = mat[i]; - - for(j=0; j < 4; j++) - { - pOut[j] = pIn[j]; - } - - pOut[4] = 0.0f; - pOut[5] = 0.0f; - pOut[6] = 0.0f; - pOut[7] = 0.0f; - pOut[i+4] = 1.0f; - - rowMap[i] = i; - } - - // Use row operations to get to reduced row-echelon form using these rules: - // 1. Multiply or divide a row by a nonzero number. - // 2. Add a multiple of one row to another. - // 3. Interchange two rows. - - for(iRow=0; iRow < 4; iRow++) - { - // Find the row with the largest element in this column. - fLargest = 0.00001f; - iLargest = -1; - for(iTest=iRow; iTest < 4; iTest++) - { - fTest = (vec_t)FloatMakePositive(mat[rowMap[iTest]][iRow]); - if(fTest > fLargest) - { - iLargest = iTest; - fLargest = fTest; - } - } - - // They're all too small.. sorry. - if(iLargest == -1) - { - return false; - } - - // Swap the rows. - iTemp = rowMap[iLargest]; - rowMap[iLargest] = rowMap[iRow]; - rowMap[iRow] = iTemp; - - pRow = mat[rowMap[iRow]]; - - // Divide this row by the element. - mul = 1.0f / pRow[iRow]; - for(j=0; j < 8; j++) - pRow[j] *= mul; - - pRow[iRow] = 1.0f; // Preserve accuracy... - - // Eliminate this element from the other rows using operation 2. - for(i=0; i < 4; i++) - { - if(i == iRow) - continue; - - pScaleRow = mat[rowMap[i]]; - - // Multiply this row by -(iRow*the element). - mul = -pScaleRow[iRow]; - for(j=0; j < 8; j++) - { - pScaleRow[j] += pRow[j] * mul; - } - - pScaleRow[iRow] = 0.0f; // Preserve accuracy... - } - } - - // The inverse is on the right side of AX now (the identity is on the left). - for(i=0; i < 4; i++) - { - const vec_t *pIn = mat[rowMap[i]] + 4; - pOut = dst.m[i]; - - for(j=0; j < 4; j++) - { - pOut[j] = pIn[j]; - } - } - - return true; -} - - -//----------------------------------------------------------------------------- -// Does a fast inverse, assuming the matrix only contains translation and rotation. -//----------------------------------------------------------------------------- -void MatrixInverseTR( const VMatrix& src, VMatrix &dst ) -{ - Vector vTrans, vNewTrans; - - // Transpose the upper 3x3. - dst.m[0][0] = src.m[0][0]; dst.m[0][1] = src.m[1][0]; dst.m[0][2] = src.m[2][0]; - dst.m[1][0] = src.m[0][1]; dst.m[1][1] = src.m[1][1]; dst.m[1][2] = src.m[2][1]; - dst.m[2][0] = src.m[0][2]; dst.m[2][1] = src.m[1][2]; dst.m[2][2] = src.m[2][2]; - - // Transform the translation. - vTrans.Init( -src.m[0][3], -src.m[1][3], -src.m[2][3] ); - Vector3DMultiply( dst, vTrans, vNewTrans ); - MatrixSetColumn( dst, 3, vNewTrans ); - - // Fill in the bottom row. - dst.m[3][0] = dst.m[3][1] = dst.m[3][2] = 0.0f; - dst.m[3][3] = 1.0f; -} - - -void VMatrix::InverseTR( VMatrix &ret ) const -{ - MatrixInverseTR( *this, ret ); -} - -void MatrixInverseTranspose( const VMatrix& src, VMatrix& dst ) -{ - src.InverseGeneral( dst ); - MatrixTranspose( dst, dst ); -} - -//----------------------------------------------------------------------------- -// Computes the inverse transpose -//----------------------------------------------------------------------------- -void MatrixInverseTranspose( const matrix3x4_t& src, matrix3x4_t& dst ) -{ - VMatrix tmp, out; - tmp.CopyFrom3x4( src ); - ::MatrixInverseTranspose( tmp, out ); - out.Set3x4( dst ); -} - - -#ifndef VECTOR_NO_SLOW_OPERATIONS - -VMatrix VMatrix::InverseTR() const -{ - VMatrix ret; - MatrixInverseTR( *this, ret ); - return ret; -} - -Vector VMatrix::GetScale() const -{ - Vector vecs[3]; - - GetBasisVectors(vecs[0], vecs[1], vecs[2]); - - return Vector( - vecs[0].Length(), - vecs[1].Length(), - vecs[2].Length() - ); -} - -VMatrix VMatrix::Scale(const Vector &vScale) -{ - return VMatrix( - m[0][0]*vScale.x, m[0][1]*vScale.y, m[0][2]*vScale.z, m[0][3], - m[1][0]*vScale.x, m[1][1]*vScale.y, m[1][2]*vScale.z, m[1][3], - m[2][0]*vScale.x, m[2][1]*vScale.y, m[2][2]*vScale.z, m[2][3], - m[3][0]*vScale.x, m[3][1]*vScale.y, m[3][2]*vScale.z, 1.0f - ); -} - -VMatrix VMatrix::NormalizeBasisVectors() const -{ - Vector vecs[3]; - VMatrix mRet; - - - GetBasisVectors(vecs[0], vecs[1], vecs[2]); - - VectorNormalize( vecs[0] ); - VectorNormalize( vecs[1] ); - VectorNormalize( vecs[2] ); - - mRet.SetBasisVectors(vecs[0], vecs[1], vecs[2]); - - // Set everything but basis vectors to identity. - mRet.m[3][0] = mRet.m[3][1] = mRet.m[3][2] = 0.0f; - mRet.m[3][3] = 1.0f; - - return mRet; -} - -VMatrix VMatrix::Transpose() const -{ - return VMatrix( - m[0][0], m[1][0], m[2][0], m[3][0], - m[0][1], m[1][1], m[2][1], m[3][1], - m[0][2], m[1][2], m[2][2], m[3][2], - m[0][3], m[1][3], m[2][3], m[3][3]); -} - -// Transpose upper-left 3x3. -VMatrix VMatrix::Transpose3x3() const -{ - return VMatrix( - m[0][0], m[1][0], m[2][0], m[0][3], - m[0][1], m[1][1], m[2][1], m[1][3], - m[0][2], m[1][2], m[2][2], m[2][3], - m[3][0], m[3][1], m[3][2], m[3][3]); -} - -#endif // VECTOR_NO_SLOW_OPERATIONS - - -bool VMatrix::IsRotationMatrix() const -{ - Vector &v1 = (Vector&)m[0][0]; - Vector &v2 = (Vector&)m[1][0]; - Vector &v3 = (Vector&)m[2][0]; - - return - FloatMakePositive( 1 - v1.Length() ) < 0.01f && - FloatMakePositive( 1 - v2.Length() ) < 0.01f && - FloatMakePositive( 1 - v3.Length() ) < 0.01f && - FloatMakePositive( v1.Dot(v2) ) < 0.01f && - FloatMakePositive( v1.Dot(v3) ) < 0.01f && - FloatMakePositive( v2.Dot(v3) ) < 0.01f; -} - -static void SetupMatrixAnglesInternal( vec_t m[4][4], const QAngle & vAngles ) -{ - float sr, sp, sy, cr, cp, cy; - - SinCos( DEG2RAD( vAngles[YAW] ), &sy, &cy ); - SinCos( DEG2RAD( vAngles[PITCH] ), &sp, &cp ); - SinCos( DEG2RAD( vAngles[ROLL] ), &sr, &cr ); - - // matrix = (YAW * PITCH) * ROLL - m[0][0] = cp*cy; - m[1][0] = cp*sy; - m[2][0] = -sp; - m[0][1] = sr*sp*cy+cr*-sy; - m[1][1] = sr*sp*sy+cr*cy; - m[2][1] = sr*cp; - m[0][2] = (cr*sp*cy+-sr*-sy); - m[1][2] = (cr*sp*sy+-sr*cy); - m[2][2] = cr*cp; - m[0][3] = 0.f; - m[1][3] = 0.f; - m[2][3] = 0.f; -} - -void VMatrix::SetupMatrixOrgAngles( const Vector &origin, const QAngle &vAngles ) -{ - SetupMatrixAnglesInternal( m, vAngles ); - - // Add translation - m[0][3] = origin.x; - m[1][3] = origin.y; - m[2][3] = origin.z; - m[3][0] = 0.0f; - m[3][1] = 0.0f; - m[3][2] = 0.0f; - m[3][3] = 1.0f; -} - - -void VMatrix::SetupMatrixAngles( const QAngle &vAngles ) -{ - SetupMatrixAnglesInternal( m, vAngles ); - - // Zero everything else - m[0][3] = 0.0f; - m[1][3] = 0.0f; - m[2][3] = 0.0f; - m[3][0] = 0.0f; - m[3][1] = 0.0f; - m[3][2] = 0.0f; - m[3][3] = 1.0f; -} - - -//----------------------------------------------------------------------------- -// Sets matrix to identity -//----------------------------------------------------------------------------- -void MatrixSetIdentity( VMatrix &dst ) -{ - dst[0][0] = 1.0f; dst[0][1] = 0.0f; dst[0][2] = 0.0f; dst[0][3] = 0.0f; - dst[1][0] = 0.0f; dst[1][1] = 1.0f; dst[1][2] = 0.0f; dst[1][3] = 0.0f; - dst[2][0] = 0.0f; dst[2][1] = 0.0f; dst[2][2] = 1.0f; dst[2][3] = 0.0f; - dst[3][0] = 0.0f; dst[3][1] = 0.0f; dst[3][2] = 0.0f; dst[3][3] = 1.0f; -} - - -//----------------------------------------------------------------------------- -// Setup a matrix from euler angles. -//----------------------------------------------------------------------------- -void MatrixFromAngles( const QAngle& vAngles, VMatrix& dst ) -{ - dst.SetupMatrixOrgAngles( vec3_origin, vAngles ); -} - - -//----------------------------------------------------------------------------- -// Creates euler angles from a matrix -//----------------------------------------------------------------------------- -void MatrixToAngles( const VMatrix& src, QAngle& vAngles ) -{ - float forward[3]; - float left[3]; - float up[3]; - - // Extract the basis vectors from the matrix. Since we only need the Z - // component of the up vector, we don't get X and Y. - forward[0] = src[0][0]; - forward[1] = src[1][0]; - forward[2] = src[2][0]; - left[0] = src[0][1]; - left[1] = src[1][1]; - left[2] = src[2][1]; - up[2] = src[2][2]; - - float xyDist = sqrtf( forward[0] * forward[0] + forward[1] * forward[1] ); - - // enough here to get angles? - if ( xyDist > 0.001f ) - { - // (yaw) y = ATAN( forward.y, forward.x ); -- in our space, forward is the X axis - vAngles[1] = RAD2DEG( atan2f( forward[1], forward[0] ) ); - - // The engine does pitch inverted from this, but we always end up negating it in the DLL - // UNDONE: Fix the engine to make it consistent - // (pitch) x = ATAN( -forward.z, sqrt(forward.x*forward.x+forward.y*forward.y) ); - vAngles[0] = RAD2DEG( atan2f( -forward[2], xyDist ) ); - - // (roll) z = ATAN( left.z, up.z ); - vAngles[2] = RAD2DEG( atan2f( left[2], up[2] ) ); - } - else // forward is mostly Z, gimbal lock- - { - // (yaw) y = ATAN( -left.x, left.y ); -- forward is mostly z, so use right for yaw - vAngles[1] = RAD2DEG( atan2f( -left[0], left[1] ) ); - - // The engine does pitch inverted from this, but we always end up negating it in the DLL - // UNDONE: Fix the engine to make it consistent - // (pitch) x = ATAN( -forward.z, sqrt(forward.x*forward.x+forward.y*forward.y) ); - vAngles[0] = RAD2DEG( atan2f( -forward[2], xyDist ) ); - - // Assume no roll in this case as one degree of freedom has been lost (i.e. yaw == roll) - vAngles[2] = 0; - } -} - - -//----------------------------------------------------------------------------- -// Transpose -//----------------------------------------------------------------------------- -inline void Swap( float& a, float& b ) -{ - float tmp = a; - a = b; - b = tmp; -} - -void MatrixTranspose( const VMatrix& src, VMatrix& dst ) -{ - if (&src == &dst) - { - Swap( dst[0][1], dst[1][0] ); - Swap( dst[0][2], dst[2][0] ); - Swap( dst[0][3], dst[3][0] ); - Swap( dst[1][2], dst[2][1] ); - Swap( dst[1][3], dst[3][1] ); - Swap( dst[2][3], dst[3][2] ); - } - else - { - dst[0][0] = src[0][0]; dst[0][1] = src[1][0]; dst[0][2] = src[2][0]; dst[0][3] = src[3][0]; - dst[1][0] = src[0][1]; dst[1][1] = src[1][1]; dst[1][2] = src[2][1]; dst[1][3] = src[3][1]; - dst[2][0] = src[0][2]; dst[2][1] = src[1][2]; dst[2][2] = src[2][2]; dst[2][3] = src[3][2]; - dst[3][0] = src[0][3]; dst[3][1] = src[1][3]; dst[3][2] = src[2][3]; dst[3][3] = src[3][3]; - } -} - - -//----------------------------------------------------------------------------- -// Matrix copy -//----------------------------------------------------------------------------- - -void MatrixCopy( const VMatrix& src, VMatrix& dst ) -{ - if (&src != &dst) - { - memcpy( dst.m, src.m, 16 * sizeof(float) ); - } -} - -//----------------------------------------------------------------------------- -// Matrix multiply -//----------------------------------------------------------------------------- -typedef float VMatrixRaw_t[4]; - -void MatrixMultiply( const VMatrix& src1, const VMatrix& src2, VMatrix& dst ) -{ - // Make sure it works if src1 == dst or src2 == dst - VMatrix tmp1, tmp2; - const VMatrixRaw_t* s1 = (&src1 == &dst) ? tmp1.m : src1.m; - const VMatrixRaw_t* s2 = (&src2 == &dst) ? tmp2.m : src2.m; - - if (&src1 == &dst) - { - MatrixCopy( src1, tmp1 ); - } - if (&src2 == &dst) - { - MatrixCopy( src2, tmp2 ); - } - - dst[0][0] = s1[0][0] * s2[0][0] + s1[0][1] * s2[1][0] + s1[0][2] * s2[2][0] + s1[0][3] * s2[3][0]; - dst[0][1] = s1[0][0] * s2[0][1] + s1[0][1] * s2[1][1] + s1[0][2] * s2[2][1] + s1[0][3] * s2[3][1]; - dst[0][2] = s1[0][0] * s2[0][2] + s1[0][1] * s2[1][2] + s1[0][2] * s2[2][2] + s1[0][3] * s2[3][2]; - dst[0][3] = s1[0][0] * s2[0][3] + s1[0][1] * s2[1][3] + s1[0][2] * s2[2][3] + s1[0][3] * s2[3][3]; - - dst[1][0] = s1[1][0] * s2[0][0] + s1[1][1] * s2[1][0] + s1[1][2] * s2[2][0] + s1[1][3] * s2[3][0]; - dst[1][1] = s1[1][0] * s2[0][1] + s1[1][1] * s2[1][1] + s1[1][2] * s2[2][1] + s1[1][3] * s2[3][1]; - dst[1][2] = s1[1][0] * s2[0][2] + s1[1][1] * s2[1][2] + s1[1][2] * s2[2][2] + s1[1][3] * s2[3][2]; - dst[1][3] = s1[1][0] * s2[0][3] + s1[1][1] * s2[1][3] + s1[1][2] * s2[2][3] + s1[1][3] * s2[3][3]; - - dst[2][0] = s1[2][0] * s2[0][0] + s1[2][1] * s2[1][0] + s1[2][2] * s2[2][0] + s1[2][3] * s2[3][0]; - dst[2][1] = s1[2][0] * s2[0][1] + s1[2][1] * s2[1][1] + s1[2][2] * s2[2][1] + s1[2][3] * s2[3][1]; - dst[2][2] = s1[2][0] * s2[0][2] + s1[2][1] * s2[1][2] + s1[2][2] * s2[2][2] + s1[2][3] * s2[3][2]; - dst[2][3] = s1[2][0] * s2[0][3] + s1[2][1] * s2[1][3] + s1[2][2] * s2[2][3] + s1[2][3] * s2[3][3]; - - dst[3][0] = s1[3][0] * s2[0][0] + s1[3][1] * s2[1][0] + s1[3][2] * s2[2][0] + s1[3][3] * s2[3][0]; - dst[3][1] = s1[3][0] * s2[0][1] + s1[3][1] * s2[1][1] + s1[3][2] * s2[2][1] + s1[3][3] * s2[3][1]; - dst[3][2] = s1[3][0] * s2[0][2] + s1[3][1] * s2[1][2] + s1[3][2] * s2[2][2] + s1[3][3] * s2[3][2]; - dst[3][3] = s1[3][0] * s2[0][3] + s1[3][1] * s2[1][3] + s1[3][2] * s2[2][3] + s1[3][3] * s2[3][3]; -} - -//----------------------------------------------------------------------------- -// Matrix/vector multiply -//----------------------------------------------------------------------------- - -void Vector4DMultiply( const VMatrix& src1, Vector4D const& src2, Vector4D& dst ) -{ - // Make sure it works if src2 == dst - Vector4D tmp; - Vector4D const&v = (&src2 == &dst) ? tmp : src2; - - if (&src2 == &dst) - { - Vector4DCopy( src2, tmp ); - } - - dst[0] = src1[0][0] * v[0] + src1[0][1] * v[1] + src1[0][2] * v[2] + src1[0][3] * v[3]; - dst[1] = src1[1][0] * v[0] + src1[1][1] * v[1] + src1[1][2] * v[2] + src1[1][3] * v[3]; - dst[2] = src1[2][0] * v[0] + src1[2][1] * v[1] + src1[2][2] * v[2] + src1[2][3] * v[3]; - dst[3] = src1[3][0] * v[0] + src1[3][1] * v[1] + src1[3][2] * v[2] + src1[3][3] * v[3]; -} - -//----------------------------------------------------------------------------- -// Matrix/vector multiply -//----------------------------------------------------------------------------- - -void Vector4DMultiplyPosition( const VMatrix& src1, Vector const& src2, Vector4D& dst ) -{ - // Make sure it works if src2 == dst - Vector tmp; - Vector const&v = ( &src2 == &dst.AsVector3D() ) ? static_cast<const Vector&>(tmp) : src2; - - if (&src2 == &dst.AsVector3D()) - { - VectorCopy( src2, tmp ); - } - - dst[0] = src1[0][0] * v[0] + src1[0][1] * v[1] + src1[0][2] * v[2] + src1[0][3]; - dst[1] = src1[1][0] * v[0] + src1[1][1] * v[1] + src1[1][2] * v[2] + src1[1][3]; - dst[2] = src1[2][0] * v[0] + src1[2][1] * v[1] + src1[2][2] * v[2] + src1[2][3]; - dst[3] = src1[3][0] * v[0] + src1[3][1] * v[1] + src1[3][2] * v[2] + src1[3][3]; -} - - - -//----------------------------------------------------------------------------- -// Matrix/vector multiply -//----------------------------------------------------------------------------- - -void Vector3DMultiply( const VMatrix &src1, const Vector &src2, Vector &dst ) -{ - // Make sure it works if src2 == dst - Vector tmp; - const Vector &v = (&src2 == &dst) ? static_cast<const Vector&>(tmp) : src2; - - if( &src2 == &dst ) - { - VectorCopy( src2, tmp ); - } - - dst[0] = src1[0][0] * v[0] + src1[0][1] * v[1] + src1[0][2] * v[2]; - dst[1] = src1[1][0] * v[0] + src1[1][1] * v[1] + src1[1][2] * v[2]; - dst[2] = src1[2][0] * v[0] + src1[2][1] * v[1] + src1[2][2] * v[2]; -} - - -//----------------------------------------------------------------------------- -// Vector3DMultiplyPositionProjective treats src2 as if it's a point -// and does the perspective divide at the end -//----------------------------------------------------------------------------- -void Vector3DMultiplyPositionProjective( const VMatrix& src1, const Vector &src2, Vector& dst ) -{ - // Make sure it works if src2 == dst - Vector tmp; - const Vector &v = (&src2 == &dst) ? static_cast<const Vector&>(tmp): src2; - if( &src2 == &dst ) - { - VectorCopy( src2, tmp ); - } - - float w = src1[3][0] * v[0] + src1[3][1] * v[1] + src1[3][2] * v[2] + src1[3][3]; - if ( w != 0.0f ) - { - w = 1.0f / w; - } - - dst[0] = src1[0][0] * v[0] + src1[0][1] * v[1] + src1[0][2] * v[2] + src1[0][3]; - dst[1] = src1[1][0] * v[0] + src1[1][1] * v[1] + src1[1][2] * v[2] + src1[1][3]; - dst[2] = src1[2][0] * v[0] + src1[2][1] * v[1] + src1[2][2] * v[2] + src1[2][3]; - dst *= w; -} - - -//----------------------------------------------------------------------------- -// Vector3DMultiplyProjective treats src2 as if it's a direction -// and does the perspective divide at the end -//----------------------------------------------------------------------------- -void Vector3DMultiplyProjective( const VMatrix& src1, const Vector &src2, Vector& dst ) -{ - // Make sure it works if src2 == dst - Vector tmp; - const Vector &v = (&src2 == &dst) ? static_cast<const Vector&>(tmp) : src2; - if( &src2 == &dst ) - { - VectorCopy( src2, tmp ); - } - - float w; - dst[0] = src1[0][0] * v[0] + src1[0][1] * v[1] + src1[0][2] * v[2]; - dst[1] = src1[1][0] * v[0] + src1[1][1] * v[1] + src1[1][2] * v[2]; - dst[2] = src1[2][0] * v[0] + src1[2][1] * v[1] + src1[2][2] * v[2]; - w = src1[3][0] * v[0] + src1[3][1] * v[1] + src1[3][2] * v[2]; - if (w != 0.0f) - { - dst /= w; - } - else - { - dst = vec3_origin; - } -} - - -//----------------------------------------------------------------------------- -// Multiplies the vector by the transpose of the matrix -//----------------------------------------------------------------------------- -void Vector4DMultiplyTranspose( const VMatrix& src1, Vector4D const& src2, Vector4D& dst ) -{ - // Make sure it works if src2 == dst - bool srcEqualsDst = (&src2 == &dst); - - Vector4D tmp; - Vector4D const&v = srcEqualsDst ? tmp : src2; - - if (srcEqualsDst) - { - Vector4DCopy( src2, tmp ); - } - - dst[0] = src1[0][0] * v[0] + src1[1][0] * v[1] + src1[2][0] * v[2] + src1[3][0] * v[3]; - dst[1] = src1[0][1] * v[0] + src1[1][1] * v[1] + src1[2][1] * v[2] + src1[3][1] * v[3]; - dst[2] = src1[0][2] * v[0] + src1[1][2] * v[1] + src1[2][2] * v[2] + src1[3][2] * v[3]; - dst[3] = src1[0][3] * v[0] + src1[1][3] * v[1] + src1[2][3] * v[2] + src1[3][3] * v[3]; -} - -//----------------------------------------------------------------------------- -// Multiplies the vector by the transpose of the matrix -//----------------------------------------------------------------------------- -void Vector3DMultiplyTranspose( const VMatrix& src1, const Vector& src2, Vector& dst ) -{ - // Make sure it works if src2 == dst - bool srcEqualsDst = (&src2 == &dst); - - Vector tmp; - const Vector&v = srcEqualsDst ? static_cast<const Vector&>(tmp) : src2; - - if (srcEqualsDst) - { - VectorCopy( src2, tmp ); - } - - dst[0] = src1[0][0] * v[0] + src1[1][0] * v[1] + src1[2][0] * v[2]; - dst[1] = src1[0][1] * v[0] + src1[1][1] * v[1] + src1[2][1] * v[2]; - dst[2] = src1[0][2] * v[0] + src1[1][2] * v[1] + src1[2][2] * v[2]; -} - - -//----------------------------------------------------------------------------- -// Transform a plane -//----------------------------------------------------------------------------- -void MatrixTransformPlane( const VMatrix &src, const cplane_t &inPlane, cplane_t &outPlane ) -{ - // What we want to do is the following: - // 1) transform the normal into the new space. - // 2) Determine a point on the old plane given by plane dist * plane normal - // 3) Transform that point into the new space - // 4) Plane dist = DotProduct( new normal, new point ) - - // An optimized version, which works if the plane is orthogonal. - // 1) Transform the normal into the new space - // 2) Realize that transforming the old plane point into the new space - // is given by [ d * n'x + Tx, d * n'y + Ty, d * n'z + Tz ] - // where d = old plane dist, n' = transformed normal, Tn = translational component of transform - // 3) Compute the new plane dist using the dot product of the normal result of #2 - - // For a correct result, this should be an inverse-transpose matrix - // but that only matters if there are nonuniform scale or skew factors in this matrix. - Vector vTrans; - Vector3DMultiply( src, inPlane.normal, outPlane.normal ); - outPlane.dist = inPlane.dist * DotProduct( outPlane.normal, outPlane.normal ); - outPlane.dist += DotProduct( outPlane.normal, src.GetTranslation(vTrans) ); -} - - -#ifndef VECTOR_NO_SLOW_OPERATIONS - -VPlane VMatrix::operator*(const VPlane &thePlane) const -{ - VPlane ret; - TransformPlane( thePlane, ret ); - return ret; -} - -#endif - - -//----------------------------------------------------------------------------- -// Builds a rotation matrix that rotates one direction vector into another -//----------------------------------------------------------------------------- -void MatrixBuildTranslation( VMatrix& dst, float x, float y, float z ) -{ - MatrixSetIdentity( dst ); - dst[0][3] = x; - dst[1][3] = y; - dst[2][3] = z; -} - -void MatrixBuildTranslation( VMatrix& dst, const Vector &translation ) -{ - MatrixSetIdentity( dst ); - dst[0][3] = translation[0]; - dst[1][3] = translation[1]; - dst[2][3] = translation[2]; -} - - -//----------------------------------------------------------------------------- -// Purpose: Builds the matrix for a counterclockwise rotation about an arbitrary axis. -// -// | ax2 + (1 - ax2)cosQ axay(1 - cosQ) - azsinQ azax(1 - cosQ) + aysinQ | -// Ra(Q) = | axay(1 - cosQ) + azsinQ ay2 + (1 - ay2)cosQ ayaz(1 - cosQ) - axsinQ | -// | azax(1 - cosQ) - aysinQ ayaz(1 - cosQ) + axsinQ az2 + (1 - az2)cosQ | -// -// Input : mat - -// vAxisOrRot - -// angle - -//----------------------------------------------------------------------------- -void MatrixBuildRotationAboutAxis( VMatrix &dst, const Vector &vAxisOfRot, float angleDegrees ) -{ - MatrixBuildRotationAboutAxis( vAxisOfRot, angleDegrees, const_cast< matrix3x4_t &> ( dst.As3x4() ) ); - dst[3][0] = 0; - dst[3][1] = 0; - dst[3][2] = 0; - dst[3][3] = 1; -} - - -//----------------------------------------------------------------------------- -// Builds a rotation matrix that rotates one direction vector into another -//----------------------------------------------------------------------------- -void MatrixBuildRotation( VMatrix &dst, const Vector& initialDirection, const Vector& finalDirection ) -{ - float angle = DotProduct( initialDirection, finalDirection ); - Assert( IsFinite(angle) ); - - Vector axis; - - // No rotation required - if (angle - 1.0 > -1e-3) - { - // parallel case - MatrixSetIdentity(dst); - return; - } - else if (angle + 1.0 < 1e-3) - { - // antiparallel case, pick any axis in the plane - // perpendicular to the final direction. Choose the direction (x,y,z) - // which has the minimum component of the final direction, use that - // as an initial guess, then subtract out the component which is - // parallel to the final direction - int idx = 0; - if (FloatMakePositive(finalDirection[1]) < FloatMakePositive(finalDirection[idx])) - idx = 1; - if (FloatMakePositive(finalDirection[2]) < FloatMakePositive(finalDirection[idx])) - idx = 2; - - axis.Init( 0, 0, 0 ); - axis[idx] = 1.0f; - VectorMA( axis, -DotProduct( axis, finalDirection ), finalDirection, axis ); - VectorNormalize(axis); - angle = 180.0f; - } - else - { - CrossProduct( initialDirection, finalDirection, axis ); - VectorNormalize( axis ); - angle = acos(angle) * 180 / M_PI; - } - - MatrixBuildRotationAboutAxis( dst, axis, angle ); - -#ifdef _DEBUG - Vector test; - Vector3DMultiply( dst, initialDirection, test ); - test -= finalDirection; - Assert( test.LengthSqr() < 1e-3 ); -#endif -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void MatrixBuildRotateZ( VMatrix &dst, float angleDegrees ) -{ - float radians = angleDegrees * ( M_PI / 180.0f ); - - float fSin = ( float )sin( radians ); - float fCos = ( float )cos( radians ); - - dst[0][0] = fCos; dst[0][1] = -fSin; dst[0][2] = 0.0f; dst[0][3] = 0.0f; - dst[1][0] = fSin; dst[1][1] = fCos; dst[1][2] = 0.0f; dst[1][3] = 0.0f; - dst[2][0] = 0.0f; dst[2][1] = 0.0f; dst[2][2] = 1.0f; dst[2][3] = 0.0f; - dst[3][0] = 0.0f; dst[3][1] = 0.0f; dst[3][2] = 0.0f; dst[3][3] = 1.0f; -} - -// Builds a scale matrix -void MatrixBuildScale( VMatrix &dst, float x, float y, float z ) -{ - dst[0][0] = x; dst[0][1] = 0.0f; dst[0][2] = 0.0f; dst[0][3] = 0.0f; - dst[1][0] = 0.0f; dst[1][1] = y; dst[1][2] = 0.0f; dst[1][3] = 0.0f; - dst[2][0] = 0.0f; dst[2][1] = 0.0f; dst[2][2] = z; dst[2][3] = 0.0f; - dst[3][0] = 0.0f; dst[3][1] = 0.0f; dst[3][2] = 0.0f; dst[3][3] = 1.0f; -} - -void MatrixBuildScale( VMatrix &dst, const Vector& scale ) -{ - MatrixBuildScale( dst, scale.x, scale.y, scale.z ); -} - -void MatrixBuildPerspective( VMatrix &dst, float fovX, float fovY, float zNear, float zFar ) -{ - // FIXME: collapse all of this into one matrix after we figure out what all should be in here. - float width = 2 * zNear * tan( fovX * ( M_PI/180.0f ) * 0.5f ); - float height = 2 * zNear * tan( fovY * ( M_PI/180.0f ) * 0.5f ); - - memset( dst.Base(), 0, sizeof( dst ) ); - dst[0][0] = 2.0F * zNear / width; - dst[1][1] = 2.0F * zNear / height; - dst[2][2] = -zFar / ( zNear - zFar ); - dst[3][2] = 1.0f; - dst[2][3] = zNear * zFar / ( zNear - zFar ); - - // negate X and Y so that X points right, and Y points up. - VMatrix negateXY; - negateXY.Identity(); - negateXY[0][0] = -1.0f; - negateXY[1][1] = -1.0f; - MatrixMultiply( negateXY, dst, dst ); - - VMatrix addW; - addW.Identity(); - addW[0][3] = 1.0f; - addW[1][3] = 1.0f; - addW[2][3] = 0.0f; - MatrixMultiply( addW, dst, dst ); - - VMatrix scaleHalf; - scaleHalf.Identity(); - scaleHalf[0][0] = 0.5f; - scaleHalf[1][1] = 0.5f; - MatrixMultiply( scaleHalf, dst, dst ); -} - -static inline void CalculateAABBForNormalizedFrustum_Helper( float x, float y, float z, const VMatrix &volumeToWorld, Vector &mins, Vector &maxs ) -{ - Vector volumeSpacePos( x, y, z ); - - // Make sure it's been clipped - Assert( volumeSpacePos[0] >= -1e-3f ); - Assert( volumeSpacePos[0] - 1.0f <= 1e-3f ); - Assert( volumeSpacePos[1] >= -1e-3f ); - Assert( volumeSpacePos[1] - 1.0f <= 1e-3f ); - Assert( volumeSpacePos[2] >= -1e-3f ); - Assert( volumeSpacePos[2] - 1.0f <= 1e-3f ); - - Vector worldPos; - Vector3DMultiplyPositionProjective( volumeToWorld, volumeSpacePos, worldPos ); - AddPointToBounds( worldPos, mins, maxs ); -} - -//----------------------------------------------------------------------------- -// Given an inverse projection matrix, take the extremes of the space in transformed into world space and -// get a bounding box. -//----------------------------------------------------------------------------- -void CalculateAABBFromProjectionMatrixInverse( const VMatrix &volumeToWorld, Vector *pMins, Vector *pMaxs ) -{ - // FIXME: Could maybe do better than the compile with all of these multiplies by 0 and 1. - ClearBounds( *pMins, *pMaxs ); - CalculateAABBForNormalizedFrustum_Helper( 0, 0, 0, volumeToWorld, *pMins, *pMaxs ); - CalculateAABBForNormalizedFrustum_Helper( 0, 0, 1, volumeToWorld, *pMins, *pMaxs ); - CalculateAABBForNormalizedFrustum_Helper( 0, 1, 0, volumeToWorld, *pMins, *pMaxs ); - CalculateAABBForNormalizedFrustum_Helper( 0, 1, 1, volumeToWorld, *pMins, *pMaxs ); - CalculateAABBForNormalizedFrustum_Helper( 1, 0, 0, volumeToWorld, *pMins, *pMaxs ); - CalculateAABBForNormalizedFrustum_Helper( 1, 0, 1, volumeToWorld, *pMins, *pMaxs ); - CalculateAABBForNormalizedFrustum_Helper( 1, 1, 0, volumeToWorld, *pMins, *pMaxs ); - CalculateAABBForNormalizedFrustum_Helper( 1, 1, 1, volumeToWorld, *pMins, *pMaxs ); -} - -void CalculateAABBFromProjectionMatrix( const VMatrix &worldToVolume, Vector *pMins, Vector *pMaxs ) -{ - VMatrix volumeToWorld; - MatrixInverseGeneral( worldToVolume, volumeToWorld ); - CalculateAABBFromProjectionMatrixInverse( volumeToWorld, pMins, pMaxs ); -} - -//----------------------------------------------------------------------------- -// Given an inverse projection matrix, take the extremes of the space in transformed into world space and -// get a bounding sphere. -//----------------------------------------------------------------------------- -void CalculateSphereFromProjectionMatrixInverse( const VMatrix &volumeToWorld, Vector *pCenter, float *pflRadius ) -{ - // FIXME: Could maybe do better than the compile with all of these multiplies by 0 and 1. - - // Need 3 points: the endpoint of the line through the center of the near + far planes, - // and one point on the far plane. From that, we can derive a point somewhere on the center line - // which would produce the smallest bounding sphere. - Vector vecCenterNear, vecCenterFar, vecNearEdge, vecFarEdge; - Vector3DMultiplyPositionProjective( volumeToWorld, Vector( 0.5f, 0.5f, 0.0f ), vecCenterNear ); - Vector3DMultiplyPositionProjective( volumeToWorld, Vector( 0.5f, 0.5f, 1.0f ), vecCenterFar ); - Vector3DMultiplyPositionProjective( volumeToWorld, Vector( 0.0f, 0.0f, 0.0f ), vecNearEdge ); - Vector3DMultiplyPositionProjective( volumeToWorld, Vector( 0.0f, 0.0f, 1.0f ), vecFarEdge ); - - // Let the distance between the near + far center points = l - // Let the distance between the near center point + near edge point = h1 - // Let the distance between the far center point + far edge point = h2 - // Let the distance along the center line from the near point to the sphere center point = x - // Then let the distance between the sphere center point + near edge point == - // the distance between the sphere center point + far edge point == r == radius of sphere - // Then h1^2 + x^2 == r^2 == (l-x)^2 + h2^2 - // h1^x + x^2 = l^2 - 2 * l * x + x^2 + h2^2 - // 2 * l * x = l^2 + h2^2 - h1^2 - // x = (l^2 + h2^2 - h1^2) / (2 * l) - // r = sqrt( hl^1 + x^2 ) - Vector vecDelta; - VectorSubtract( vecCenterFar, vecCenterNear, vecDelta ); - float l = vecDelta.Length(); - float h1Sqr = vecCenterNear.DistToSqr( vecNearEdge ); - float h2Sqr = vecCenterFar.DistToSqr( vecFarEdge ); - float x = (l*l + h2Sqr - h1Sqr) / (2.0f * l); - VectorMA( vecCenterNear, (x / l), vecDelta, *pCenter ); - *pflRadius = sqrt( h1Sqr + x*x ); -} - -//----------------------------------------------------------------------------- -// Given a projection matrix, take the extremes of the space in transformed into world space and -// get a bounding sphere. -//----------------------------------------------------------------------------- -void CalculateSphereFromProjectionMatrix( const VMatrix &worldToVolume, Vector *pCenter, float *pflRadius ) -{ - VMatrix volumeToWorld; - MatrixInverseGeneral( worldToVolume, volumeToWorld ); - CalculateSphereFromProjectionMatrixInverse( volumeToWorld, pCenter, pflRadius ); -} - - -static inline void FrustumPlanesFromMatrixHelper( const VMatrix &shadowToWorld, const Vector &p1, const Vector &p2, const Vector &p3, - Vector &normal, float &dist ) -{ - Vector world1, world2, world3; - Vector3DMultiplyPositionProjective( shadowToWorld, p1, world1 ); - Vector3DMultiplyPositionProjective( shadowToWorld, p2, world2 ); - Vector3DMultiplyPositionProjective( shadowToWorld, p3, world3 ); - - Vector v1, v2; - VectorSubtract( world2, world1, v1 ); - VectorSubtract( world3, world1, v2 ); - - CrossProduct( v1, v2, normal ); - VectorNormalize( normal ); - dist = DotProduct( normal, world1 ); -} - -void FrustumPlanesFromMatrix( const VMatrix &clipToWorld, Frustum_t &frustum ) -{ - Vector normal; - float dist; - - FrustumPlanesFromMatrixHelper( clipToWorld, - Vector( 0.0f, 0.0f, 0.0f ), Vector( 1.0f, 0.0f, 0.0f ), Vector( 0.0f, 1.0f, 0.0f ), normal, dist ); - frustum.SetPlane( FRUSTUM_NEARZ, PLANE_ANYZ, normal, dist ); - - FrustumPlanesFromMatrixHelper( clipToWorld, - Vector( 0.0f, 0.0f, 1.0f ), Vector( 0.0f, 1.0f, 1.0f ), Vector( 1.0f, 0.0f, 1.0f ), normal, dist ); - frustum.SetPlane( FRUSTUM_FARZ, PLANE_ANYZ, normal, dist ); - - FrustumPlanesFromMatrixHelper( clipToWorld, - Vector( 1.0f, 0.0f, 0.0f ), Vector( 1.0f, 1.0f, 1.0f ), Vector( 1.0f, 1.0f, 0.0f ), normal, dist ); - frustum.SetPlane( FRUSTUM_RIGHT, PLANE_ANYZ, normal, dist ); - - FrustumPlanesFromMatrixHelper( clipToWorld, - Vector( 0.0f, 0.0f, 0.0f ), Vector( 0.0f, 1.0f, 1.0f ), Vector( 0.0f, 0.0f, 1.0f ), normal, dist ); - frustum.SetPlane( FRUSTUM_LEFT, PLANE_ANYZ, normal, dist ); - - FrustumPlanesFromMatrixHelper( clipToWorld, - Vector( 1.0f, 1.0f, 0.0f ), Vector( 1.0f, 1.0f, 1.0f ), Vector( 0.0f, 1.0f, 1.0f ), normal, dist ); - frustum.SetPlane( FRUSTUM_TOP, PLANE_ANYZ, normal, dist ); - - FrustumPlanesFromMatrixHelper( clipToWorld, - Vector( 1.0f, 0.0f, 0.0f ), Vector( 0.0f, 0.0f, 1.0f ), Vector( 1.0f, 0.0f, 1.0f ), normal, dist ); - frustum.SetPlane( FRUSTUM_BOTTOM, PLANE_ANYZ, normal, dist ); -} - -void MatrixBuildOrtho( VMatrix& dst, double left, double top, double right, double bottom, double zNear, double zFar ) -{ - // FIXME: This is being used incorrectly! Should read: - // D3DXMatrixOrthoOffCenterRH( &matrix, left, right, bottom, top, zNear, zFar ); - // Which is certainly why we need these extra -1 scales in y. Bleah - - // NOTE: The camera can be imagined as the following diagram: - // /z - // / - // /____ x Z is going into the screen - // | - // | - // |y - // - // (0,0,z) represents the upper-left corner of the screen. - // Our projection transform needs to transform from this space to a LH coordinate - // system that looks thusly: - // - // y| /z - // | / - // |/____ x Z is going into the screen - // - // Where x,y lies between -1 and 1, and z lies from 0 to 1 - // This is because the viewport transformation from projection space to pixels - // introduces a -1 scale in the y coordinates - // D3DXMatrixOrthoOffCenterRH( &matrix, left, right, top, bottom, zNear, zFar ); - - dst.Init( 2.0f / ( right - left ), 0.0f, 0.0f, ( left + right ) / ( left - right ), - 0.0f, 2.0f / ( bottom - top ), 0.0f, ( bottom + top ) / ( top - bottom ), - 0.0f, 0.0f, 1.0f / ( zNear - zFar ), zNear / ( zNear - zFar ), - 0.0f, 0.0f, 0.0f, 1.0f ); -} - -void MatrixBuildPerspectiveZRange( VMatrix& dst, double flZNear, double flZFar ) -{ - dst.m[2][0] = 0.0f; - dst.m[2][1] = 0.0f; - dst.m[2][2] = flZFar / ( flZNear - flZFar ); - dst.m[2][3] = flZNear * flZFar / ( flZNear - flZFar ); -} - -void MatrixBuildPerspectiveX( VMatrix& dst, double flFovX, double flAspect, double flZNear, double flZFar ) -{ - float flWidthScale = 1.0f / tanf( flFovX * M_PI / 360.0f ); - float flHeightScale = flAspect * flWidthScale; - dst.Init( flWidthScale, 0.0f, 0.0f, 0.0f, - 0.0f, flHeightScale, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, -1.0f, 0.0f ); - - MatrixBuildPerspectiveZRange ( dst, flZNear, flZFar ); -} - -void MatrixBuildPerspectiveOffCenterX( VMatrix& dst, double flFovX, double flAspect, double flZNear, double flZFar, double bottom, double top, double left, double right ) -{ - float flWidth = tanf( flFovX * M_PI / 360.0f ); - float flHeight = flWidth / flAspect; - - // bottom, top, left, right are 0..1 so convert to -<val>/2..<val>/2 - float flLeft = -(flWidth/2.0f) * (1.0f - left) + left * (flWidth/2.0f); - float flRight = -(flWidth/2.0f) * (1.0f - right) + right * (flWidth/2.0f); - float flBottom = -(flHeight/2.0f) * (1.0f - bottom) + bottom * (flHeight/2.0f); - float flTop = -(flHeight/2.0f) * (1.0f - top) + top * (flHeight/2.0f); - - dst.Init( 1.0f / (flRight-flLeft), 0.0f, (flLeft+flRight)/(flRight-flLeft), 0.0f, - 0.0f, 1.0f /(flTop-flBottom), (flTop+flBottom)/(flTop-flBottom), 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, -1.0f, 0.0f ); - - MatrixBuildPerspectiveZRange ( dst, flZNear, flZFar ); -} #endif // !_STATIC_LINKED || _SHARED_LIB diff --git a/public/mathlib/math_pfns.h b/public/mathlib/math_pfns.h index d43411ce..5ff8a53b 100644 --- a/public/mathlib/math_pfns.h +++ b/public/mathlib/math_pfns.h @@ -22,10 +22,16 @@ extern float (*pfFastCos)(float x); // The following are not declared as macros because they are often used in limiting situations, // and sometimes the compiler simply refuses to inline them for some reason -#define FastSqrt(x) (*pfSqrt)(x) -#define FastRSqrt(x) (*pfRSqrt)(x) -#define FastRSqrtFast(x) (*pfRSqrtFast)(x) +#define FastSqrt(x) sqrtf(x) +#define FastRSqrt(x) (1.f/sqrtf(x)) +#define FastRSqrtFast(x) (1.f/sqrtf(x)) + +#ifdef _WIN32 #define FastSinCos(x,s,c) (*pfFastSinCos)(x,s,c) +#else +#define FastSinCos(x,s,c) sincosf(x,s,c) +#endif + #define FastCos(x) (*pfFastCos)(x) #if defined(__i386__) || defined(_M_IX86) diff --git a/public/mathlib/mathlib.h b/public/mathlib/mathlib.h index 75a21ad7..ca752def 100644 --- a/public/mathlib/mathlib.h +++ b/public/mathlib/mathlib.h @@ -237,8 +237,8 @@ bool R_CullBoxSkipNear( const Vector& mins, const Vector& maxs, const Frustum_t struct matrix3x4_t { - matrix3x4_t() = default; - matrix3x4_t( + inline matrix3x4_t() = default; + inline matrix3x4_t( float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23 ) @@ -252,7 +252,7 @@ struct matrix3x4_t // Creates a matrix where the X axis = forward // the Y axis = left, and the Z axis = up //----------------------------------------------------------------------------- - void Init( const Vector& xAxis, const Vector& yAxis, const Vector& zAxis, const Vector &vecOrigin ) + inline void Init( const Vector& xAxis, const Vector& yAxis, const Vector& zAxis, const Vector &vecOrigin ) { m_flMatVal[0][0] = xAxis.x; m_flMatVal[0][1] = yAxis.x; m_flMatVal[0][2] = zAxis.x; m_flMatVal[0][3] = vecOrigin.x; m_flMatVal[1][0] = xAxis.y; m_flMatVal[1][1] = yAxis.y; m_flMatVal[1][2] = zAxis.y; m_flMatVal[1][3] = vecOrigin.y; @@ -263,26 +263,23 @@ struct matrix3x4_t // Creates a matrix where the X axis = forward // the Y axis = left, and the Z axis = up //----------------------------------------------------------------------------- - matrix3x4_t( const Vector& xAxis, const Vector& yAxis, const Vector& zAxis, const Vector &vecOrigin ) + inline matrix3x4_t( const Vector& xAxis, const Vector& yAxis, const Vector& zAxis, const Vector &vecOrigin ) { Init( xAxis, yAxis, zAxis, vecOrigin ); } inline void Invalidate( void ) { - for (int i = 0; i < 3; i++) + for( int i=0; i < 12; i++ ) { - for (int j = 0; j < 4; j++) - { - m_flMatVal[i][j] = VEC_T_NAN; - } + ((float*)m_flMatVal)[i] = VEC_T_NAN; } } - float *operator[]( int i ) { Assert(( i >= 0 ) && ( i < 3 )); return m_flMatVal[i]; } - const float *operator[]( int i ) const { Assert(( i >= 0 ) && ( i < 3 )); return m_flMatVal[i]; } - float *Base() { return &m_flMatVal[0][0]; } - const float *Base() const { return &m_flMatVal[0][0]; } + inline float *operator[]( int i ) { Assert(( i >= 0 ) && ( i < 3 )); return m_flMatVal[i]; } + inline const float *operator[]( int i ) const { Assert(( i >= 0 ) && ( i < 3 )); return m_flMatVal[i]; } + inline float *Base() { return &m_flMatVal[0][0]; } + inline const float *Base() const { return &m_flMatVal[0][0]; } float m_flMatVal[3][4]; }; @@ -565,7 +562,13 @@ void MatrixInvert( const matrix3x4_t &in, matrix3x4_t &out ); bool MatricesAreEqual( const matrix3x4_t &src1, const matrix3x4_t &src2, float flTolerance = 1e-5 ); void MatrixGetColumn( const matrix3x4_t &in, int column, Vector &out ); -void MatrixSetColumn( const Vector &in, int column, matrix3x4_t &out ); + +inline void MatrixSetColumn( const Vector &in, int column, matrix3x4_t& out ) +{ + out[0][column] = in.x; + out[1][column] = in.y; + out[2][column] = in.z; +} inline void MatrixGetTranslation( const matrix3x4_t &in, Vector &out ) { diff --git a/public/mathlib/vector4d.h b/public/mathlib/vector4d.h index 63aebe85..99e0995f 100644 --- a/public/mathlib/vector4d.h +++ b/public/mathlib/vector4d.h @@ -35,7 +35,7 @@ class Vector2D; // 4D Vector4D //========================================================= -class Vector4D +class alignas(16) Vector4D { public: // Members diff --git a/public/mathlib/vmatrix.h b/public/mathlib/vmatrix.h index 48738df0..2170f9c7 100644 --- a/public/mathlib/vmatrix.h +++ b/public/mathlib/vmatrix.h @@ -30,6 +30,7 @@ #pragma once #endif +#include <math.h> #include <string.h> #include "mathlib/vector.h" #include "mathlib/vplane.h" @@ -38,8 +39,11 @@ struct cplane_t; +#ifndef M_PI + #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h +#endif -class VMatrix +class alignas(16) VMatrix { public: @@ -58,6 +62,7 @@ public: // Construct from a 3x4 matrix VMatrix( const matrix3x4_t& matrix3x4 ); + VMatrix( const VMatrix& ) = default; // Set the values in the matrix. void Init( @@ -111,7 +116,9 @@ public: void CopyFrom3x4( const matrix3x4_t &m3x4 ); void Set3x4( matrix3x4_t& matrix3x4 ) const; - bool operator==( const VMatrix& src ) const; + bool operator==( const VMatrix& src ) const { + return !memcmp( src.m, m, sizeof(m) ); + } bool operator!=( const VMatrix& src ) const { return !( *this == src ); } #ifndef VECTOR_NO_SLOW_OPERATIONS @@ -234,189 +241,286 @@ public: public: // The matrix. - vec_t m[4][4]; + vec_t m[4][4]; }; +inline void MatrixSetColumn( VMatrix &src, int nCol, const Vector &column ) +{ + Assert( (nCol >= 0) && (nCol <= 3) ); + src.m[0][nCol] = column.x; + src.m[1][nCol] = column.y; + src.m[2][nCol] = column.z; +} //----------------------------------------------------------------------------- -// Helper functions. -//----------------------------------------------------------------------------- - -#ifndef VECTOR_NO_SLOW_OPERATIONS - -// Setup an identity matrix. -VMatrix SetupMatrixIdentity(); - -// Setup as a scaling matrix. -VMatrix SetupMatrixScale(const Vector &vScale); - -// Setup a translation matrix. -VMatrix SetupMatrixTranslation(const Vector &vTranslation); - -// Setup a matrix to reflect around the plane. -VMatrix SetupMatrixReflection(const VPlane &thePlane); - -// Setup a matrix to project from vOrigin onto thePlane. -VMatrix SetupMatrixProjection(const Vector &vOrigin, const VPlane &thePlane); - -// Setup a matrix to rotate the specified amount around the specified axis. -VMatrix SetupMatrixAxisRot(const Vector &vAxis, vec_t fDegrees); - -// Setup a matrix from euler angles. Just sets identity and calls MatrixAngles. -VMatrix SetupMatrixAngles(const QAngle &vAngles); - -// Setup a matrix for origin and angles. -VMatrix SetupMatrixOrgAngles(const Vector &origin, const QAngle &vAngles); - -#endif - -#define VMatToString(mat) (static_cast<const char *>(CFmtStr("[ (%f, %f, %f), (%f, %f, %f), (%f, %f, %f), (%f, %f, %f) ]", mat.m[0][0], mat.m[0][1], mat.m[0][2], mat.m[0][3], mat.m[1][0], mat.m[1][1], mat.m[1][2], mat.m[1][3], mat.m[2][0], mat.m[2][1], mat.m[2][2], mat.m[2][3], mat.m[3][0], mat.m[3][1], mat.m[3][2], mat.m[3][3] ))) // ** Note: this generates a temporary, don't hold reference! - -//----------------------------------------------------------------------------- -// Returns the point at the intersection on the 3 planes. -// Returns false if it can't be solved (2 or more planes are parallel). -//----------------------------------------------------------------------------- -bool PlaneIntersection( const VPlane &vp1, const VPlane &vp2, const VPlane &vp3, Vector &vOut ); - - -//----------------------------------------------------------------------------- -// These methods are faster. Use them if you want faster code -//----------------------------------------------------------------------------- -void MatrixSetIdentity( VMatrix &dst ); -void MatrixTranspose( const VMatrix& src, VMatrix& dst ); -void MatrixCopy( const VMatrix& src, VMatrix& dst ); -void MatrixMultiply( const VMatrix& src1, const VMatrix& src2, VMatrix& dst ); - -// Accessors -void MatrixGetColumn( const VMatrix &src, int nCol, Vector *pColumn ); -void MatrixSetColumn( VMatrix &src, int nCol, const Vector &column ); -void MatrixGetRow( const VMatrix &src, int nCol, Vector *pColumn ); -void MatrixSetRow( VMatrix &src, int nCol, const Vector &column ); - -// Vector3DMultiply treats src2 as if it's a direction vector -void Vector3DMultiply( const VMatrix& src1, const Vector& src2, Vector& dst ); - // Vector3DMultiplyPosition treats src2 as if it's a point (adds the translation) -inline void Vector3DMultiplyPosition( const VMatrix& src1, const VectorByValue src2, Vector& dst ); - -// Vector3DMultiplyPositionProjective treats src2 as if it's a point -// and does the perspective divide at the end -void Vector3DMultiplyPositionProjective( const VMatrix& src1, const Vector &src2, Vector& dst ); - -// Vector3DMultiplyPosition treats src2 as if it's a direction -// and does the perspective divide at the end -// NOTE: src1 had better be an inverse transpose to use this correctly -void Vector3DMultiplyProjective( const VMatrix& src1, const Vector &src2, Vector& dst ); - -void Vector4DMultiply( const VMatrix& src1, const Vector4D& src2, Vector4D& dst ); - -// Same as Vector4DMultiply except that src2 has an implicit W of 1 -void Vector4DMultiplyPosition( const VMatrix& src1, const Vector &src2, Vector4D& dst ); - -// Multiplies the vector by the transpose of the matrix -void Vector3DMultiplyTranspose( const VMatrix& src1, const Vector& src2, Vector& dst ); -void Vector4DMultiplyTranspose( const VMatrix& src1, const Vector4D& src2, Vector4D& dst ); - -// Transform a plane -void MatrixTransformPlane( const VMatrix &src, const cplane_t &inPlane, cplane_t &outPlane ); - -// Transform a plane that has an axis-aligned normal -void MatrixTransformAxisAlignedPlane( const VMatrix &src, int nDim, float flSign, float flDist, cplane_t &outPlane ); - -void MatrixBuildTranslation( VMatrix& dst, float x, float y, float z ); -void MatrixBuildTranslation( VMatrix& dst, const Vector &translation ); - -inline void MatrixTranslate( VMatrix& dst, const Vector &translation ) +//----------------------------------------------------------------------------- +// NJS: src2 is passed in as a full vector rather than a reference to prevent the need +// for 2 branches and a potential copy in the body. (ie, handling the case when the src2 +// reference is the same as the dst reference ). +inline void Vector3DMultiplyPosition( const VMatrix& src1, const VectorByValue src2, Vector& dst ) { - VMatrix matTranslation, temp; - MatrixBuildTranslation( matTranslation, translation ); - MatrixMultiply( dst, matTranslation, temp ); - dst = temp; + dst[0] = src1[0][0] * src2.x + src1[0][1] * src2.y + src1[0][2] * src2.z + src1[0][3]; + dst[1] = src1[1][0] * src2.x + src1[1][1] * src2.y + src1[1][2] * src2.z + src1[1][3]; + dst[2] = src1[2][0] * src2.x + src1[2][1] * src2.y + src1[2][2] * src2.z + src1[2][3]; +} + +//----------------------------------------------------------------------------- +// Sets matrix to identity +//----------------------------------------------------------------------------- +inline void MatrixSetIdentity( VMatrix &dst ) +{ + dst[0][0] = 1.0f; dst[0][1] = 0.0f; dst[0][2] = 0.0f; dst[0][3] = 0.0f; + dst[1][0] = 0.0f; dst[1][1] = 1.0f; dst[1][2] = 0.0f; dst[1][3] = 0.0f; + dst[2][0] = 0.0f; dst[2][1] = 0.0f; dst[2][2] = 1.0f; dst[2][3] = 0.0f; + dst[3][0] = 0.0f; dst[3][1] = 0.0f; dst[3][2] = 0.0f; dst[3][3] = 1.0f; +} + +//----------------------------------------------------------------------------- +// Matrix/vector multiply +//----------------------------------------------------------------------------- +inline void Vector3DMultiply( const VMatrix &src1, const Vector &src2, Vector &dst ) +{ + // Make sure it works if src2 == dst + Vector tmp; + const Vector &v = (&src2 == &dst) ? static_cast<const Vector&>(tmp) : src2; + + if( &src2 == &dst ) + VectorCopy( src2, tmp ); + + dst[0] = src1[0][0] * v[0] + src1[0][1] * v[1] + src1[0][2] * v[2]; + dst[1] = src1[1][0] * v[0] + src1[1][1] * v[1] + src1[1][2] * v[2]; + dst[2] = src1[2][0] * v[0] + src1[2][1] * v[1] + src1[2][2] * v[2]; } -void MatrixBuildRotationAboutAxis( VMatrix& dst, const Vector& vAxisOfRot, float angleDegrees ); -void MatrixBuildRotateZ( VMatrix& dst, float angleDegrees ); - -inline void MatrixRotate( VMatrix& dst, const Vector& vAxisOfRot, float angleDegrees ) +inline bool MatrixInverseGeneral(const VMatrix& src, VMatrix& dst) { - VMatrix rotation, temp; - MatrixBuildRotationAboutAxis( rotation, vAxisOfRot, angleDegrees ); - MatrixMultiply( dst, rotation, temp ); - dst = temp; + int iRow, i, j, iTemp, iTest; + vec_t mul, fTest, fLargest; + vec_t mat[4][8]; + int rowMap[4], iLargest; + vec_t *pOut, *pRow, *pScaleRow; + + + // How it's done. + // AX = I + // A = this + // X = the matrix we're looking for + // I = identity + + // Setup AI + for(i=0; i < 4; i++) + { + const vec_t *pIn = src[i]; + pOut = mat[i]; + + for(j=0; j < 4; j++) + { + pOut[j] = pIn[j]; + } + + pOut[4] = 0.0f; + pOut[5] = 0.0f; + pOut[6] = 0.0f; + pOut[7] = 0.0f; + pOut[i+4] = 1.0f; + + rowMap[i] = i; + } + + // Use row operations to get to reduced row-echelon form using these rules: + // 1. Multiply or divide a row by a nonzero number. + // 2. Add a multiple of one row to another. + // 3. Interchange two rows. + + for(iRow=0; iRow < 4; iRow++) + { + // Find the row with the largest element in this column. + fLargest = 0.00001f; + iLargest = -1; + for(iTest=iRow; iTest < 4; iTest++) + { + fTest = (vec_t)FloatMakePositive(mat[rowMap[iTest]][iRow]); + if(fTest > fLargest) + { + iLargest = iTest; + fLargest = fTest; + } + } + + // They're all too small.. sorry. + if(iLargest == -1) + { + return false; + } + + // Swap the rows. + iTemp = rowMap[iLargest]; + rowMap[iLargest] = rowMap[iRow]; + rowMap[iRow] = iTemp; + + pRow = mat[rowMap[iRow]]; + + // Divide this row by the element. + mul = 1.0f / pRow[iRow]; + for(j=0; j < 8; j++) + pRow[j] *= mul; + + pRow[iRow] = 1.0f; // Preserve accuracy... + + // Eliminate this element from the other rows using operation 2. + for(i=0; i < 4; i++) + { + if(i == iRow) + continue; + + pScaleRow = mat[rowMap[i]]; + + // Multiply this row by -(iRow*the element). + mul = -pScaleRow[iRow]; + for(j=0; j < 8; j++) + { + pScaleRow[j] += pRow[j] * mul; + } + + pScaleRow[iRow] = 0.0f; // Preserve accuracy... + } + } + + // The inverse is on the right side of AX now (the identity is on the left). + for(i=0; i < 4; i++) + { + const vec_t *pIn = mat[rowMap[i]] + 4; + pOut = dst.m[i]; + + for(j=0; j < 4; j++) + { + pOut[j] = pIn[j]; + } + } + + return true; } -// Builds a rotation matrix that rotates one direction vector into another -void MatrixBuildRotation( VMatrix &dst, const Vector& initialDirection, const Vector& finalDirection ); +static inline void SetupMatrixAnglesInternal( vec_t m[4][4], const QAngle & vAngles ) +{ + float sr, sp, sy, cr, cp, cy; -// Builds a scale matrix -void MatrixBuildScale( VMatrix &dst, float x, float y, float z ); -void MatrixBuildScale( VMatrix &dst, const Vector& scale ); + SinCos( DEG2RAD( vAngles[YAW] ), &sy, &cy ); + SinCos( DEG2RAD( vAngles[PITCH] ), &sp, &cp ); + SinCos( DEG2RAD( vAngles[ROLL] ), &sr, &cr ); + + // matrix = (YAW * PITCH) * ROLL + m[0][0] = cp*cy; + m[1][0] = cp*sy; + m[2][0] = -sp; + m[0][1] = sr*sp*cy+cr*-sy; + m[1][1] = sr*sp*sy+cr*cy; + m[2][1] = sr*cp; + m[0][2] = (cr*sp*cy+-sr*-sy); + m[1][2] = (cr*sp*sy+-sr*cy); + m[2][2] = cr*cp; + m[0][3] = 0.f; + m[1][3] = 0.f; + m[2][3] = 0.f; +} -// Build a perspective matrix. -// zNear and zFar are assumed to be positive. -// You end up looking down positive Z, X is to the right, Y is up. -// X range: [0..1] -// Y range: [0..1] -// Z range: [0..1] -void MatrixBuildPerspective( VMatrix &dst, float fovX, float fovY, float zNear, float zFar ); //----------------------------------------------------------------------------- -// Given a projection matrix, take the extremes of the space in transformed into world space and -// get a bounding box. +// Transpose //----------------------------------------------------------------------------- -void CalculateAABBFromProjectionMatrix( const VMatrix &worldToVolume, Vector *pMins, Vector *pMaxs ); +inline void Swap( float& a, float& b ) +{ + float tmp = a; + a = b; + b = tmp; +} -//----------------------------------------------------------------------------- -// Given a projection matrix, take the extremes of the space in transformed into world space and -// get a bounding sphere. -//----------------------------------------------------------------------------- -void CalculateSphereFromProjectionMatrix( const VMatrix &worldToVolume, Vector *pCenter, float *pflRadius ); - -//----------------------------------------------------------------------------- -// Given an inverse projection matrix, take the extremes of the space in transformed into world space and -// get a bounding box. -//----------------------------------------------------------------------------- -void CalculateAABBFromProjectionMatrixInverse( const VMatrix &volumeToWorld, Vector *pMins, Vector *pMaxs ); - -//----------------------------------------------------------------------------- -// Given an inverse projection matrix, take the extremes of the space in transformed into world space and -// get a bounding sphere. -//----------------------------------------------------------------------------- -void CalculateSphereFromProjectionMatrixInverse( const VMatrix &volumeToWorld, Vector *pCenter, float *pflRadius ); - -//----------------------------------------------------------------------------- -// Calculate frustum planes given a clip->world space transform. -//----------------------------------------------------------------------------- -void FrustumPlanesFromMatrix( const VMatrix &clipToWorld, Frustum_t &frustum ); - -//----------------------------------------------------------------------------- -// Setup a matrix from euler angles. -//----------------------------------------------------------------------------- -void MatrixFromAngles( const QAngle& vAngles, VMatrix& dst ); - -//----------------------------------------------------------------------------- -// Creates euler angles from a matrix -//----------------------------------------------------------------------------- -void MatrixToAngles( const VMatrix& src, QAngle& vAngles ); +inline void MatrixTranspose( const VMatrix& src, VMatrix& dst ) +{ + if (&src == &dst) + { + Swap( dst[0][1], dst[1][0] ); + Swap( dst[0][2], dst[2][0] ); + Swap( dst[0][3], dst[3][0] ); + Swap( dst[1][2], dst[2][1] ); + Swap( dst[1][3], dst[3][1] ); + Swap( dst[2][3], dst[3][2] ); + } + else + { + dst[0][0] = src[0][0]; dst[0][1] = src[1][0]; dst[0][2] = src[2][0]; dst[0][3] = src[3][0]; + dst[1][0] = src[0][1]; dst[1][1] = src[1][1]; dst[1][2] = src[2][1]; dst[1][3] = src[3][1]; + dst[2][0] = src[0][2]; dst[2][1] = src[1][2]; dst[2][2] = src[2][2]; dst[2][3] = src[3][2]; + dst[3][0] = src[0][3]; dst[3][1] = src[1][3]; dst[3][2] = src[2][3]; dst[3][3] = src[3][3]; + } +} //----------------------------------------------------------------------------- // Does a fast inverse, assuming the matrix only contains translation and rotation. //----------------------------------------------------------------------------- -void MatrixInverseTR( const VMatrix& src, VMatrix &dst ); +inline void MatrixInverseTR( const VMatrix& src, VMatrix &dst ) +{ + Vector vTrans, vNewTrans; -//----------------------------------------------------------------------------- -// Inverts any matrix at all -//----------------------------------------------------------------------------- -bool MatrixInverseGeneral(const VMatrix& src, VMatrix& dst); + // Transpose the upper 3x3. + dst.m[0][0] = src.m[0][0]; dst.m[0][1] = src.m[1][0]; dst.m[0][2] = src.m[2][0]; + dst.m[1][0] = src.m[0][1]; dst.m[1][1] = src.m[1][1]; dst.m[1][2] = src.m[2][1]; + dst.m[2][0] = src.m[0][2]; dst.m[2][1] = src.m[1][2]; dst.m[2][2] = src.m[2][2]; -//----------------------------------------------------------------------------- -// Computes the inverse transpose -//----------------------------------------------------------------------------- -void MatrixInverseTranspose( const VMatrix& src, VMatrix& dst ); + // Transform the translation. + vTrans.Init( -src.m[0][3], -src.m[1][3], -src.m[2][3] ); + Vector3DMultiply( dst, vTrans, vNewTrans ); + MatrixSetColumn( dst, 3, vNewTrans ); + + // Fill in the bottom row. + dst.m[3][0] = dst.m[3][1] = dst.m[3][2] = 0.0f; + dst.m[3][3] = 1.0f; +} + +inline void VMatrix::Init( + vec_t m00, vec_t m01, vec_t m02, vec_t m03, + vec_t m10, vec_t m11, vec_t m12, vec_t m13, + vec_t m20, vec_t m21, vec_t m22, vec_t m23, + vec_t m30, vec_t m31, vec_t m32, vec_t m33 + ) +{ + m[0][0] = m00; + m[0][1] = m01; + m[0][2] = m02; + m[0][3] = m03; + + m[1][0] = m10; + m[1][1] = m11; + m[1][2] = m12; + m[1][3] = m13; + + m[2][0] = m20; + m[2][1] = m21; + m[2][2] = m22; + m[2][3] = m23; + + m[3][0] = m30; + m[3][1] = m31; + m[3][2] = m32; + m[3][3] = m33; +} +//----------------------------------------------------------------------------- +// Initialize from a 3x4 +//----------------------------------------------------------------------------- +inline void VMatrix::Init( const matrix3x4_t& matrix3x4 ) +{ + memcpy(m, matrix3x4.Base(), sizeof( matrix3x4_t ) ); + + m[3][0] = 0.0f; + m[3][1] = 0.0f; + m[3][2] = 0.0f; + m[3][3] = 1.0f; +} //----------------------------------------------------------------------------- // VMatrix inlines. @@ -476,56 +580,153 @@ inline VMatrix::VMatrix( const Vector& xAxis, const Vector& yAxis, const Vector& ); } - -inline void VMatrix::Init( - vec_t m00, vec_t m01, vec_t m02, vec_t m03, - vec_t m10, vec_t m11, vec_t m12, vec_t m13, - vec_t m20, vec_t m21, vec_t m22, vec_t m23, - vec_t m30, vec_t m31, vec_t m32, vec_t m33 - ) -{ - m[0][0] = m00; - m[0][1] = m01; - m[0][2] = m02; - m[0][3] = m03; - - m[1][0] = m10; - m[1][1] = m11; - m[1][2] = m12; - m[1][3] = m13; - - m[2][0] = m20; - m[2][1] = m21; - m[2][2] = m22; - m[2][3] = m23; - - m[3][0] = m30; - m[3][1] = m31; - m[3][2] = m32; - m[3][3] = m33; -} - - -//----------------------------------------------------------------------------- -// Initialize from a 3x4 -//----------------------------------------------------------------------------- -inline void VMatrix::Init( const matrix3x4_t& matrix3x4 ) -{ - memcpy(m, matrix3x4.Base(), sizeof( matrix3x4_t ) ); - - m[3][0] = 0.0f; - m[3][1] = 0.0f; - m[3][2] = 0.0f; - m[3][3] = 1.0f; -} - - //----------------------------------------------------------------------------- // Methods related to the basis vectors of the matrix //----------------------------------------------------------------------------- +inline VMatrix& VMatrix::operator=(const VMatrix &mOther) +{ + m[0][0] = mOther.m[0][0]; + m[0][1] = mOther.m[0][1]; + m[0][2] = mOther.m[0][2]; + m[0][3] = mOther.m[0][3]; + + m[1][0] = mOther.m[1][0]; + m[1][1] = mOther.m[1][1]; + m[1][2] = mOther.m[1][2]; + m[1][3] = mOther.m[1][3]; + + m[2][0] = mOther.m[2][0]; + m[2][1] = mOther.m[2][1]; + m[2][2] = mOther.m[2][2]; + m[2][3] = mOther.m[2][3]; + + m[3][0] = mOther.m[3][0]; + m[3][1] = mOther.m[3][1]; + m[3][2] = mOther.m[3][2]; + m[3][3] = mOther.m[3][3]; + + return *this; +} + + #ifndef VECTOR_NO_SLOW_OPERATIONS +inline VMatrix VMatrix::operator+(const VMatrix &other) const +{ + VMatrix ret; + for(int i=0; i < 16; i++) + { + ((float*)ret.m)[i] = ((float*)m)[i] + ((float*)other.m)[i]; + } + return ret; +} + +inline VMatrix VMatrix::operator-(const VMatrix &other) const +{ + VMatrix ret; + for(int i=0; i < 16; i++) + { + ((float*)ret.m)[i] = ((float*)m)[i] - ((float*)other.m)[i]; + } + return ret; +} + +inline VMatrix VMatrix::operator-() const +{ + VMatrix ret; + for( int i=0; i < 16; i++ ) + { + ((float*)ret.m)[i] = ((float*)m)[i]; + } + return ret; +} + +//----------------------------------------------------------------------------- +// Matrix math operations +//----------------------------------------------------------------------------- +inline const VMatrix& VMatrix::operator+=(const VMatrix &other) +{ + for(int i=0; i < 16; i++) + { + ((float*)m)[i] += ((float*)other.m)[i]; + } + return *this; +} + + +inline Vector VMatrix::operator*(const Vector &vVec) const +{ + Vector vRet; + vRet.x = m[0][0]*vVec.x + m[0][1]*vVec.y + m[0][2]*vVec.z + m[0][3]; + vRet.y = m[1][0]*vVec.x + m[1][1]*vVec.y + m[1][2]*vVec.z + m[1][3]; + vRet.z = m[2][0]*vVec.x + m[2][1]*vVec.y + m[2][2]*vVec.z + m[2][3]; + + return vRet; +} + +//----------------------------------------------------------------------------- +// Plane transformation +//----------------------------------------------------------------------------- +inline void VMatrix::TransformPlane( const VPlane &inPlane, VPlane &outPlane ) const +{ + Vector vTrans; + Vector3DMultiply( *this, inPlane.m_Normal, outPlane.m_Normal ); + outPlane.m_Dist = inPlane.m_Dist * DotProduct( outPlane.m_Normal, outPlane.m_Normal ); + outPlane.m_Dist += DotProduct( outPlane.m_Normal, GetTranslation( vTrans ) ); +} + +inline VPlane VMatrix::operator*(const VPlane &thePlane) const +{ + VPlane ret; + TransformPlane( thePlane, ret ); + return ret; +} + +inline bool VMatrix::InverseGeneral(VMatrix &vInverse) const +{ + return MatrixInverseGeneral( *this, vInverse ); +} + +inline VMatrix VMatrix::operator~() const +{ + VMatrix mRet; + InverseGeneral(mRet); + return mRet; +} + +inline void VMatrix::MatrixMul( const VMatrix &vm, VMatrix &out ) const +{ + out.Init( + m[0][0]*vm.m[0][0] + m[0][1]*vm.m[1][0] + m[0][2]*vm.m[2][0] + m[0][3]*vm.m[3][0], + m[0][0]*vm.m[0][1] + m[0][1]*vm.m[1][1] + m[0][2]*vm.m[2][1] + m[0][3]*vm.m[3][1], + m[0][0]*vm.m[0][2] + m[0][1]*vm.m[1][2] + m[0][2]*vm.m[2][2] + m[0][3]*vm.m[3][2], + m[0][0]*vm.m[0][3] + m[0][1]*vm.m[1][3] + m[0][2]*vm.m[2][3] + m[0][3]*vm.m[3][3], + + m[1][0]*vm.m[0][0] + m[1][1]*vm.m[1][0] + m[1][2]*vm.m[2][0] + m[1][3]*vm.m[3][0], + m[1][0]*vm.m[0][1] + m[1][1]*vm.m[1][1] + m[1][2]*vm.m[2][1] + m[1][3]*vm.m[3][1], + m[1][0]*vm.m[0][2] + m[1][1]*vm.m[1][2] + m[1][2]*vm.m[2][2] + m[1][3]*vm.m[3][2], + m[1][0]*vm.m[0][3] + m[1][1]*vm.m[1][3] + m[1][2]*vm.m[2][3] + m[1][3]*vm.m[3][3], + + m[2][0]*vm.m[0][0] + m[2][1]*vm.m[1][0] + m[2][2]*vm.m[2][0] + m[2][3]*vm.m[3][0], + m[2][0]*vm.m[0][1] + m[2][1]*vm.m[1][1] + m[2][2]*vm.m[2][1] + m[2][3]*vm.m[3][1], + m[2][0]*vm.m[0][2] + m[2][1]*vm.m[1][2] + m[2][2]*vm.m[2][2] + m[2][3]*vm.m[3][2], + m[2][0]*vm.m[0][3] + m[2][1]*vm.m[1][3] + m[2][2]*vm.m[2][3] + m[2][3]*vm.m[3][3], + + m[3][0]*vm.m[0][0] + m[3][1]*vm.m[1][0] + m[3][2]*vm.m[2][0] + m[3][3]*vm.m[3][0], + m[3][0]*vm.m[0][1] + m[3][1]*vm.m[1][1] + m[3][2]*vm.m[2][1] + m[3][3]*vm.m[3][1], + m[3][0]*vm.m[0][2] + m[3][1]*vm.m[1][2] + m[3][2]*vm.m[2][2] + m[3][3]*vm.m[3][2], + m[3][0]*vm.m[0][3] + m[3][1]*vm.m[1][3] + m[3][2]*vm.m[2][3] + m[3][3]*vm.m[3][3] + ); +} + +inline VMatrix VMatrix::operator*(const VMatrix &vm) const +{ + VMatrix ret; + MatrixMul( vm, ret ); + return ret; +} + inline Vector VMatrix::GetForward() const { return Vector(m[0][0], m[1][0], m[2][0]); @@ -578,7 +779,6 @@ inline void VMatrix::SetBasisVectors(const Vector &vForward, const Vector &vLeft SetUp(vUp); } - //----------------------------------------------------------------------------- // Methods related to the translation component of the matrix //----------------------------------------------------------------------------- @@ -647,80 +847,8 @@ inline void VMatrix::Set3x4( matrix3x4_t& matrix3x4 ) const memcpy(matrix3x4.Base(), m, sizeof( matrix3x4_t ) ); } - -//----------------------------------------------------------------------------- -// Matrix math operations -//----------------------------------------------------------------------------- -inline const VMatrix& VMatrix::operator+=(const VMatrix &other) -{ - for(int i=0; i < 4; i++) - { - for(int j=0; j < 4; j++) - { - m[i][j] += other.m[i][j]; - } - } - - return *this; -} - - #ifndef VECTOR_NO_SLOW_OPERATIONS -inline VMatrix VMatrix::operator+(const VMatrix &other) const -{ - VMatrix ret; - for(int i=0; i < 16; i++) - { - ((float*)ret.m)[i] = ((float*)m)[i] + ((float*)other.m)[i]; - } - return ret; -} - -inline VMatrix VMatrix::operator-(const VMatrix &other) const -{ - VMatrix ret; - - for(int i=0; i < 4; i++) - { - for(int j=0; j < 4; j++) - { - ret.m[i][j] = m[i][j] - other.m[i][j]; - } - } - - return ret; -} - -inline VMatrix VMatrix::operator-() const -{ - VMatrix ret; - for( int i=0; i < 16; i++ ) - { - ((float*)ret.m)[i] = ((float*)m)[i]; - } - return ret; -} - -#endif // VECTOR_NO_SLOW_OPERATIONS - - -//----------------------------------------------------------------------------- -// Vector transformation -//----------------------------------------------------------------------------- - -#ifndef VECTOR_NO_SLOW_OPERATIONS - -inline Vector VMatrix::operator*(const Vector &vVec) const -{ - Vector vRet; - vRet.x = m[0][0]*vVec.x + m[0][1]*vVec.y + m[0][2]*vVec.z + m[0][3]; - vRet.y = m[1][0]*vVec.x + m[1][1]*vVec.y + m[1][2]*vVec.z + m[1][3]; - vRet.z = m[2][0]*vVec.x + m[2][1]*vVec.y + m[2][2]*vVec.z + m[2][3]; - - return vRet; -} - inline Vector VMatrix::VMul4x3(const Vector &vVec) const { Vector vResult; @@ -783,18 +911,6 @@ inline void VMatrix::V4Mul(const Vector4D &vIn, Vector4D &vOut) const } -//----------------------------------------------------------------------------- -// Plane transformation -//----------------------------------------------------------------------------- -inline void VMatrix::TransformPlane( const VPlane &inPlane, VPlane &outPlane ) const -{ - Vector vTrans; - Vector3DMultiply( *this, inPlane.m_Normal, outPlane.m_Normal ); - outPlane.m_Dist = inPlane.m_Dist * DotProduct( outPlane.m_Normal, outPlane.m_Normal ); - outPlane.m_Dist += DotProduct( outPlane.m_Normal, GetTranslation( vTrans ) ); -} - - //----------------------------------------------------------------------------- // Other random stuff //----------------------------------------------------------------------------- @@ -820,14 +936,529 @@ inline Vector VMatrix::ApplyRotation(const Vector &vVec) const return VMul3x3(vVec); } -inline VMatrix VMatrix::operator~() const +#endif + +inline void VMatrix::InverseTR( VMatrix &ret ) const { + MatrixInverseTR( *this, ret ); +} + +inline void MatrixInverseTranspose( const VMatrix& src, VMatrix& dst ) +{ + src.InverseGeneral( dst ); + MatrixTranspose( dst, dst ); +} + +//----------------------------------------------------------------------------- +// Computes the inverse transpose +//----------------------------------------------------------------------------- +inline void MatrixInverseTranspose( const matrix3x4_t& src, matrix3x4_t& dst ) +{ + VMatrix tmp, out; + tmp.CopyFrom3x4( src ); + ::MatrixInverseTranspose( tmp, out ); + out.Set3x4( dst ); +} + + +#ifndef VECTOR_NO_SLOW_OPERATIONS + +inline VMatrix VMatrix::InverseTR() const +{ + VMatrix ret; + MatrixInverseTR( *this, ret ); + return ret; +} + +inline Vector VMatrix::GetScale() const +{ + Vector vecs[3]; + + GetBasisVectors(vecs[0], vecs[1], vecs[2]); + + return Vector( + vecs[0].Length(), + vecs[1].Length(), + vecs[2].Length() + ); +} + +inline VMatrix VMatrix::Scale(const Vector &vScale) +{ + return VMatrix( + m[0][0]*vScale.x, m[0][1]*vScale.y, m[0][2]*vScale.z, m[0][3], + m[1][0]*vScale.x, m[1][1]*vScale.y, m[1][2]*vScale.z, m[1][3], + m[2][0]*vScale.x, m[2][1]*vScale.y, m[2][2]*vScale.z, m[2][3], + m[3][0]*vScale.x, m[3][1]*vScale.y, m[3][2]*vScale.z, 1.0f + ); +} + +inline VMatrix VMatrix::NormalizeBasisVectors() const +{ + Vector vecs[3]; VMatrix mRet; - InverseGeneral(mRet); + + GetBasisVectors(vecs[0], vecs[1], vecs[2]); + + VectorNormalize( vecs[0] ); + VectorNormalize( vecs[1] ); + VectorNormalize( vecs[2] ); + + mRet.SetBasisVectors(vecs[0], vecs[1], vecs[2]); + + // Set everything but basis vectors to identity. + mRet.m[3][0] = mRet.m[3][1] = mRet.m[3][2] = 0.0f; + mRet.m[3][3] = 1.0f; + return mRet; } -#endif +inline VMatrix VMatrix::Transpose() const +{ + return VMatrix( + m[0][0], m[1][0], m[2][0], m[3][0], + m[0][1], m[1][1], m[2][1], m[3][1], + m[0][2], m[1][2], m[2][2], m[3][2], + m[0][3], m[1][3], m[2][3], m[3][3]); +} + +// Transpose upper-left 3x3. +inline VMatrix VMatrix::Transpose3x3() const +{ + return VMatrix( + m[0][0], m[1][0], m[2][0], m[0][3], + m[0][1], m[1][1], m[2][1], m[1][3], + m[0][2], m[1][2], m[2][2], m[2][3], + m[3][0], m[3][1], m[3][2], m[3][3]); +} + +#endif // VECTOR_NO_SLOW_OPERATIONS + + +inline bool VMatrix::IsRotationMatrix() const +{ + Vector &v1 = (Vector&)m[0][0]; + Vector &v2 = (Vector&)m[1][0]; + Vector &v3 = (Vector&)m[2][0]; + + return + FloatMakePositive( 1 - v1.Length() ) < 0.01f && + FloatMakePositive( 1 - v2.Length() ) < 0.01f && + FloatMakePositive( 1 - v3.Length() ) < 0.01f && + FloatMakePositive( v1.Dot(v2) ) < 0.01f && + FloatMakePositive( v1.Dot(v3) ) < 0.01f && + FloatMakePositive( v2.Dot(v3) ) < 0.01f; +} + +inline void VMatrix::SetupMatrixOrgAngles( const Vector &origin, const QAngle &vAngles ) +{ + SetupMatrixAnglesInternal( m, vAngles ); + + // Add translation + m[0][3] = origin.x; + m[1][3] = origin.y; + m[2][3] = origin.z; + m[3][0] = 0.0f; + m[3][1] = 0.0f; + m[3][2] = 0.0f; + m[3][3] = 1.0f; +} + + +inline void VMatrix::SetupMatrixAngles( const QAngle &vAngles ) +{ + SetupMatrixAnglesInternal( m, vAngles ); + + // Zero everything else + m[0][3] = 0.0f; + m[1][3] = 0.0f; + m[2][3] = 0.0f; + m[3][0] = 0.0f; + m[3][1] = 0.0f; + m[3][2] = 0.0f; + m[3][3] = 1.0f; +} + +//----------------------------------------------------------------------------- +// Creates euler angles from a matrix +//----------------------------------------------------------------------------- +inline void MatrixToAngles( const VMatrix& src, QAngle& vAngles ) +{ + float forward[3]; + float left[3]; + float up[3]; + + // Extract the basis vectors from the matrix. Since we only need the Z + // component of the up vector, we don't get X and Y. + forward[0] = src[0][0]; + forward[1] = src[1][0]; + forward[2] = src[2][0]; + left[0] = src[0][1]; + left[1] = src[1][1]; + left[2] = src[2][1]; + up[2] = src[2][2]; + + float xyDist = sqrtf( forward[0] * forward[0] + forward[1] * forward[1] ); + + // enough here to get angles? + if ( xyDist > 0.001f ) + { + // (yaw) y = ATAN( forward.y, forward.x ); -- in our space, forward is the X axis + vAngles[1] = RAD2DEG( atan2f( forward[1], forward[0] ) ); + + // The engine does pitch inverted from this, but we always end up negating it in the DLL + // UNDONE: Fix the engine to make it consistent + // (pitch) x = ATAN( -forward.z, sqrt(forward.x*forward.x+forward.y*forward.y) ); + vAngles[0] = RAD2DEG( atan2f( -forward[2], xyDist ) ); + + // (roll) z = ATAN( left.z, up.z ); + vAngles[2] = RAD2DEG( atan2f( left[2], up[2] ) ); + } + else // forward is mostly Z, gimbal lock- + { + // (yaw) y = ATAN( -left.x, left.y ); -- forward is mostly z, so use right for yaw + vAngles[1] = RAD2DEG( atan2f( -left[0], left[1] ) ); + + // The engine does pitch inverted from this, but we always end up negating it in the DLL + // UNDONE: Fix the engine to make it consistent + // (pitch) x = ATAN( -forward.z, sqrt(forward.x*forward.x+forward.y*forward.y) ); + vAngles[0] = RAD2DEG( atan2f( -forward[2], xyDist ) ); + + // Assume no roll in this case as one degree of freedom has been lost (i.e. yaw == roll) + vAngles[2] = 0; + } +} + +//----------------------------------------------------------------------------- +// Transform a plane +//----------------------------------------------------------------------------- +inline void MatrixTransformPlane( const VMatrix &src, const cplane_t &inPlane, cplane_t &outPlane ) +{ + // What we want to do is the following: + // 1) transform the normal into the new space. + // 2) Determine a point on the old plane given by plane dist * plane normal + // 3) Transform that point into the new space + // 4) Plane dist = DotProduct( new normal, new point ) + + // An optimized version, which works if the plane is orthogonal. + // 1) Transform the normal into the new space + // 2) Realize that transforming the old plane point into the new space + // is given by [ d * n'x + Tx, d * n'y + Ty, d * n'z + Tz ] + // where d = old plane dist, n' = transformed normal, Tn = translational component of transform + // 3) Compute the new plane dist using the dot product of the normal result of #2 + + // For a correct result, this should be an inverse-transpose matrix + // but that only matters if there are nonuniform scale or skew factors in this matrix. + Vector vTrans; + Vector3DMultiply( src, inPlane.normal, outPlane.normal ); + outPlane.dist = inPlane.dist * DotProduct( outPlane.normal, outPlane.normal ); + outPlane.dist += DotProduct( outPlane.normal, src.GetTranslation(vTrans) ); +} + + +//----------------------------------------------------------------------------- +// Helper functions. +//----------------------------------------------------------------------------- + +#define VMatToString(mat) (static_cast<const char *>(CFmtStr("[ (%f, %f, %f), (%f, %f, %f), (%f, %f, %f), (%f, %f, %f) ]", mat.m[0][0], mat.m[0][1], mat.m[0][2], mat.m[0][3], mat.m[1][0], mat.m[1][1], mat.m[1][2], mat.m[1][3], mat.m[2][0], mat.m[2][1], mat.m[2][2], mat.m[2][3], mat.m[3][0], mat.m[3][1], mat.m[3][2], mat.m[3][3] ))) // ** Note: this generates a temporary, don't hold reference! + +//----------------------------------------------------------------------------- +// Matrix multiply +//----------------------------------------------------------------------------- +typedef ALIGN16 float VMatrixRaw_t[4]; + +//----------------------------------------------------------------------------- +// Matrix/vector multiply +//----------------------------------------------------------------------------- + +inline void Vector4DMultiply( const VMatrix& src1, Vector4D const& src2, Vector4D& dst ) +{ + // Make sure it works if src2 == dst + Vector4D tmp; + Vector4D const&v = (&src2 == &dst) ? tmp : src2; + + if (&src2 == &dst) + { + Vector4DCopy( src2, tmp ); + } + + dst[0] = src1[0][0] * v[0] + src1[0][1] * v[1] + src1[0][2] * v[2] + src1[0][3] * v[3]; + dst[1] = src1[1][0] * v[0] + src1[1][1] * v[1] + src1[1][2] * v[2] + src1[1][3] * v[3]; + dst[2] = src1[2][0] * v[0] + src1[2][1] * v[1] + src1[2][2] * v[2] + src1[2][3] * v[3]; + dst[3] = src1[3][0] * v[0] + src1[3][1] * v[1] + src1[3][2] * v[2] + src1[3][3] * v[3]; +} + +//----------------------------------------------------------------------------- +// Matrix/vector multiply +//----------------------------------------------------------------------------- + +inline void Vector4DMultiplyPosition( const VMatrix& src1, Vector const& src2, Vector4D& dst ) +{ + // Make sure it works if src2 == dst + Vector tmp; + Vector const&v = ( &src2 == &dst.AsVector3D() ) ? static_cast<const Vector&>(tmp) : src2; + + if (&src2 == &dst.AsVector3D()) + { + VectorCopy( src2, tmp ); + } + + dst[0] = src1[0][0] * v[0] + src1[0][1] * v[1] + src1[0][2] * v[2] + src1[0][3]; + dst[1] = src1[1][0] * v[0] + src1[1][1] * v[1] + src1[1][2] * v[2] + src1[1][3]; + dst[2] = src1[2][0] * v[0] + src1[2][1] * v[1] + src1[2][2] * v[2] + src1[2][3]; + dst[3] = src1[3][0] * v[0] + src1[3][1] * v[1] + src1[3][2] * v[2] + src1[3][3]; +} + +//----------------------------------------------------------------------------- +// Vector3DMultiplyPositionProjective treats src2 as if it's a point +// and does the perspective divide at the end +//----------------------------------------------------------------------------- +inline void Vector3DMultiplyPositionProjective( const VMatrix& src1, const Vector &src2, Vector& dst ) +{ + // Make sure it works if src2 == dst + Vector tmp; + const Vector &v = (&src2 == &dst) ? static_cast<const Vector&>(tmp): src2; + if( &src2 == &dst ) + { + VectorCopy( src2, tmp ); + } + + float w = src1[3][0] * v[0] + src1[3][1] * v[1] + src1[3][2] * v[2] + src1[3][3]; + if ( w != 0.0f ) + { + w = 1.0f / w; + } + + dst[0] = src1[0][0] * v[0] + src1[0][1] * v[1] + src1[0][2] * v[2] + src1[0][3]; + dst[1] = src1[1][0] * v[0] + src1[1][1] * v[1] + src1[1][2] * v[2] + src1[1][3]; + dst[2] = src1[2][0] * v[0] + src1[2][1] * v[1] + src1[2][2] * v[2] + src1[2][3]; + dst *= w; +} + + +//----------------------------------------------------------------------------- +// Vector3DMultiplyProjective treats src2 as if it's a direction +// and does the perspective divide at the end +//----------------------------------------------------------------------------- +inline void Vector3DMultiplyProjective( const VMatrix& src1, const Vector &src2, Vector& dst ) +{ + // Make sure it works if src2 == dst + Vector tmp; + const Vector &v = (&src2 == &dst) ? static_cast<const Vector&>(tmp) : src2; + if( &src2 == &dst ) + { + VectorCopy( src2, tmp ); + } + + float w; + dst[0] = src1[0][0] * v[0] + src1[0][1] * v[1] + src1[0][2] * v[2]; + dst[1] = src1[1][0] * v[0] + src1[1][1] * v[1] + src1[1][2] * v[2]; + dst[2] = src1[2][0] * v[0] + src1[2][1] * v[1] + src1[2][2] * v[2]; + w = src1[3][0] * v[0] + src1[3][1] * v[1] + src1[3][2] * v[2]; + if (w != 0.0f) + { + dst /= w; + } + else + { + dst = vec3_origin; + } +} + + +//----------------------------------------------------------------------------- +// Multiplies the vector by the transpose of the matrix +//----------------------------------------------------------------------------- +inline void Vector4DMultiplyTranspose( const VMatrix& src1, Vector4D const& src2, Vector4D& dst ) +{ + // Make sure it works if src2 == dst + bool srcEqualsDst = (&src2 == &dst); + + Vector4D tmp; + Vector4D const&v = srcEqualsDst ? tmp : src2; + + if (srcEqualsDst) + { + Vector4DCopy( src2, tmp ); + } + + dst[0] = src1[0][0] * v[0] + src1[1][0] * v[1] + src1[2][0] * v[2] + src1[3][0] * v[3]; + dst[1] = src1[0][1] * v[0] + src1[1][1] * v[1] + src1[2][1] * v[2] + src1[3][1] * v[3]; + dst[2] = src1[0][2] * v[0] + src1[1][2] * v[1] + src1[2][2] * v[2] + src1[3][2] * v[3]; + dst[3] = src1[0][3] * v[0] + src1[1][3] * v[1] + src1[2][3] * v[2] + src1[3][3] * v[3]; +} + +//----------------------------------------------------------------------------- +// Multiplies the vector by the transpose of the matrix +//----------------------------------------------------------------------------- +inline void Vector3DMultiplyTranspose( const VMatrix& src1, const Vector& src2, Vector& dst ) +{ + // Make sure it works if src2 == dst + bool srcEqualsDst = (&src2 == &dst); + + Vector tmp; + const Vector&v = srcEqualsDst ? static_cast<const Vector&>(tmp) : src2; + + if (srcEqualsDst) + { + VectorCopy( src2, tmp ); + } + + dst[0] = src1[0][0] * v[0] + src1[1][0] * v[1] + src1[2][0] * v[2]; + dst[1] = src1[0][1] * v[0] + src1[1][1] * v[1] + src1[2][1] * v[2]; + dst[2] = src1[0][2] * v[0] + src1[1][2] * v[1] + src1[2][2] * v[2]; +} + + +//----------------------------------------------------------------------------- +// Matrix copy +//----------------------------------------------------------------------------- +inline void MatrixCopy( const VMatrix& src, VMatrix& dst ) +{ + if (&src != &dst) + dst = src; +} + +inline void MatrixMultiply( const VMatrix& src1, const VMatrix& src2, VMatrix& dst ) +{ + // Make sure it works if src1 == dst or src2 == dst + VMatrix tmp1, tmp2; + const VMatrixRaw_t* s1 = (&src1 == &dst) ? tmp1.m : src1.m; + const VMatrixRaw_t* s2 = (&src2 == &dst) ? tmp2.m : src2.m; + + if (&src1 == &dst) + MatrixCopy( src1, tmp1 ); + + if (&src2 == &dst) + MatrixCopy( src2, tmp2 ); + + dst[0][0] = s1[0][0] * s2[0][0] + s1[0][1] * s2[1][0] + s1[0][2] * s2[2][0] + s1[0][3] * s2[3][0]; + dst[0][1] = s1[0][0] * s2[0][1] + s1[0][1] * s2[1][1] + s1[0][2] * s2[2][1] + s1[0][3] * s2[3][1]; + dst[0][2] = s1[0][0] * s2[0][2] + s1[0][1] * s2[1][2] + s1[0][2] * s2[2][2] + s1[0][3] * s2[3][2]; + dst[0][3] = s1[0][0] * s2[0][3] + s1[0][1] * s2[1][3] + s1[0][2] * s2[2][3] + s1[0][3] * s2[3][3]; + + dst[1][0] = s1[1][0] * s2[0][0] + s1[1][1] * s2[1][0] + s1[1][2] * s2[2][0] + s1[1][3] * s2[3][0]; + dst[1][1] = s1[1][0] * s2[0][1] + s1[1][1] * s2[1][1] + s1[1][2] * s2[2][1] + s1[1][3] * s2[3][1]; + dst[1][2] = s1[1][0] * s2[0][2] + s1[1][1] * s2[1][2] + s1[1][2] * s2[2][2] + s1[1][3] * s2[3][2]; + dst[1][3] = s1[1][0] * s2[0][3] + s1[1][1] * s2[1][3] + s1[1][2] * s2[2][3] + s1[1][3] * s2[3][3]; + + dst[2][0] = s1[2][0] * s2[0][0] + s1[2][1] * s2[1][0] + s1[2][2] * s2[2][0] + s1[2][3] * s2[3][0]; + dst[2][1] = s1[2][0] * s2[0][1] + s1[2][1] * s2[1][1] + s1[2][2] * s2[2][1] + s1[2][3] * s2[3][1]; + dst[2][2] = s1[2][0] * s2[0][2] + s1[2][1] * s2[1][2] + s1[2][2] * s2[2][2] + s1[2][3] * s2[3][2]; + dst[2][3] = s1[2][0] * s2[0][3] + s1[2][1] * s2[1][3] + s1[2][2] * s2[2][3] + s1[2][3] * s2[3][3]; + + dst[3][0] = s1[3][0] * s2[0][0] + s1[3][1] * s2[1][0] + s1[3][2] * s2[2][0] + s1[3][3] * s2[3][0]; + dst[3][1] = s1[3][0] * s2[0][1] + s1[3][1] * s2[1][1] + s1[3][2] * s2[2][1] + s1[3][3] * s2[3][1]; + dst[3][2] = s1[3][0] * s2[0][2] + s1[3][1] * s2[1][2] + s1[3][2] * s2[2][2] + s1[3][3] * s2[3][2]; + dst[3][3] = s1[3][0] * s2[0][3] + s1[3][1] * s2[1][3] + s1[3][2] * s2[2][3] + s1[3][3] * s2[3][3]; +} + + +//----------------------------------------------------------------------------- +// Purpose: Builds the matrix for a counterclockwise rotation about an arbitrary axis. +// +// | ax2 + (1 - ax2)cosQ axay(1 - cosQ) - azsinQ azax(1 - cosQ) + aysinQ | +// Ra(Q) = | axay(1 - cosQ) + azsinQ ay2 + (1 - ay2)cosQ ayaz(1 - cosQ) - axsinQ | +// | azax(1 - cosQ) - aysinQ ayaz(1 - cosQ) + axsinQ az2 + (1 - az2)cosQ | +// +// Input : mat - +// vAxisOrRot - +// angle - +//----------------------------------------------------------------------------- +inline void MatrixBuildRotationAboutAxis( const Vector &vAxisOfRot, float angleDegrees, matrix3x4_t &dst ) +{ + float radians; + float axisXSquared; + float axisYSquared; + float axisZSquared; + float fSin; + float fCos; + + radians = angleDegrees * ( M_PI / 180.0 ); + fSin = sinf( radians ); + fCos = cosf( radians ); + + axisXSquared = vAxisOfRot[0] * vAxisOfRot[0]; + axisYSquared = vAxisOfRot[1] * vAxisOfRot[1]; + axisZSquared = vAxisOfRot[2] * vAxisOfRot[2]; + + // Column 0: + dst[0][0] = axisXSquared + (1 - axisXSquared) * fCos; + dst[1][0] = vAxisOfRot[0] * vAxisOfRot[1] * (1 - fCos) + vAxisOfRot[2] * fSin; + dst[2][0] = vAxisOfRot[2] * vAxisOfRot[0] * (1 - fCos) - vAxisOfRot[1] * fSin; + + // Column 1: + dst[0][1] = vAxisOfRot[0] * vAxisOfRot[1] * (1 - fCos) - vAxisOfRot[2] * fSin; + dst[1][1] = axisYSquared + (1 - axisYSquared) * fCos; + dst[2][1] = vAxisOfRot[1] * vAxisOfRot[2] * (1 - fCos) + vAxisOfRot[0] * fSin; + + // Column 2: + dst[0][2] = vAxisOfRot[2] * vAxisOfRot[0] * (1 - fCos) + vAxisOfRot[1] * fSin; + dst[1][2] = vAxisOfRot[1] * vAxisOfRot[2] * (1 - fCos) - vAxisOfRot[0] * fSin; + dst[2][2] = axisZSquared + (1 - axisZSquared) * fCos; + + // Column 3: + dst[0][3] = 0; + dst[1][3] = 0; + dst[2][3] = 0; +} + +//----------------------------------------------------------------------------- +// Purpose: Builds the matrix for a counterclockwise rotation about an arbitrary axis. +// +// | ax2 + (1 - ax2)cosQ axay(1 - cosQ) - azsinQ azax(1 - cosQ) + aysinQ | +// Ra(Q) = | axay(1 - cosQ) + azsinQ ay2 + (1 - ay2)cosQ ayaz(1 - cosQ) - axsinQ | +// | azax(1 - cosQ) - aysinQ ayaz(1 - cosQ) + axsinQ az2 + (1 - az2)cosQ | +// +// Input : mat - +// vAxisOrRot - +// angle - +//----------------------------------------------------------------------------- +inline void MatrixBuildRotationAboutAxis( VMatrix &dst, const Vector &vAxisOfRot, float angleDegrees ) +{ + MatrixBuildRotationAboutAxis( vAxisOfRot, angleDegrees, const_cast< matrix3x4_t &> ( dst.As3x4() ) ); + dst[3][0] = 0; + dst[3][1] = 0; + dst[3][2] = 0; + dst[3][3] = 1; +} + + +//----------------------------------------------------------------------------- +// Builds a rotation matrix that rotates one direction vector into another +//----------------------------------------------------------------------------- +inline void MatrixBuildTranslation( VMatrix& dst, float x, float y, float z ) +{ + MatrixSetIdentity( dst ); + dst[0][3] = x; + dst[1][3] = y; + dst[2][3] = z; +} + +inline void MatrixBuildTranslation( VMatrix& dst, const Vector &translation ) +{ + MatrixSetIdentity( dst ); + dst[0][3] = translation[0]; + dst[1][3] = translation[1]; + dst[2][3] = translation[2]; +} + + +inline void MatrixTranslate( VMatrix& dst, const Vector &translation ) +{ + VMatrix matTranslation, temp; + MatrixBuildTranslation( matTranslation, translation ); + MatrixMultiply( dst, matTranslation, temp ); + dst = temp; +} + +inline void MatrixRotate( VMatrix& dst, const Vector& vAxisOfRot, float angleDegrees ) +{ + VMatrix rotation, temp; + MatrixBuildRotationAboutAxis( rotation, vAxisOfRot, angleDegrees ); + MatrixMultiply( dst, rotation, temp ); + dst = temp; +} //----------------------------------------------------------------------------- @@ -842,15 +1473,6 @@ inline void MatrixGetColumn( const VMatrix &src, int nCol, Vector *pColumn ) pColumn->z = src[2][nCol]; } -inline void MatrixSetColumn( VMatrix &src, int nCol, const Vector &column ) -{ - Assert( (nCol >= 0) && (nCol <= 3) ); - - src.m[0][nCol] = column.x; - src.m[1][nCol] = column.y; - src.m[2][nCol] = column.z; -} - inline void MatrixGetRow( const VMatrix &src, int nRow, Vector *pRow ) { Assert( (nRow >= 0) && (nRow <= 3) ); @@ -863,21 +1485,6 @@ inline void MatrixSetRow( VMatrix &dst, int nRow, const Vector &row ) *(Vector*)dst[nRow] = row; } - -//----------------------------------------------------------------------------- -// Vector3DMultiplyPosition treats src2 as if it's a point (adds the translation) -//----------------------------------------------------------------------------- -// NJS: src2 is passed in as a full vector rather than a reference to prevent the need -// for 2 branches and a potential copy in the body. (ie, handling the case when the src2 -// reference is the same as the dst reference ). -inline void Vector3DMultiplyPosition( const VMatrix& src1, const VectorByValue src2, Vector& dst ) -{ - dst[0] = src1[0][0] * src2.x + src1[0][1] * src2.y + src1[0][2] * src2.z + src1[0][3]; - dst[1] = src1[1][0] * src2.x + src1[1][1] * src2.y + src1[1][2] * src2.z + src1[1][3]; - dst[2] = src1[2][0] * src2.x + src1[2][1] * src2.y + src1[2][2] * src2.z + src1[2][3]; -} - - //----------------------------------------------------------------------------- // Transform a plane that has an axis-aligned normal //----------------------------------------------------------------------------- @@ -948,6 +1555,501 @@ inline void MatrixPerspectiveOffCenterX( VMatrix& dst, double flFovX, double flA dst = temp; } + +#ifndef VECTOR_NO_SLOW_OPERATIONS + +inline VMatrix SetupMatrixIdentity() +{ + return VMatrix( + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f); +} + +inline VMatrix SetupMatrixTranslation(const Vector &vTranslation) +{ + return VMatrix( + 1.0f, 0.0f, 0.0f, vTranslation.x, + 0.0f, 1.0f, 0.0f, vTranslation.y, + 0.0f, 0.0f, 1.0f, vTranslation.z, + 0.0f, 0.0f, 0.0f, 1.0f + ); +} + +inline VMatrix SetupMatrixScale(const Vector &vScale) +{ + return VMatrix( + vScale.x, 0.0f, 0.0f, 0.0f, + 0.0f, vScale.y, 0.0f, 0.0f, + 0.0f, 0.0f, vScale.z, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); +} + +inline VMatrix SetupMatrixReflection(const VPlane &thePlane) +{ + VMatrix mReflect, mBack, mForward; + Vector vOrigin, N; + + N = thePlane.m_Normal; + + mReflect.Init( + -2.0f*N.x*N.x + 1.0f, -2.0f*N.x*N.y, -2.0f*N.x*N.z, 0.0f, + -2.0f*N.y*N.x, -2.0f*N.y*N.y + 1.0f, -2.0f*N.y*N.z, 0.0f, + -2.0f*N.z*N.x, -2.0f*N.z*N.y, -2.0f*N.z*N.z + 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + vOrigin = thePlane.GetPointOnPlane(); + + mBack.Identity(); + mBack.SetTranslation(-vOrigin); + + mForward.Identity(); + mForward.SetTranslation(vOrigin); + + // (multiplied in reverse order, so it translates to the origin point, + // reflects, and translates back). + return mForward * mReflect * mBack; +} + +inline VMatrix SetupMatrixProjection(const Vector &vOrigin, const VPlane &thePlane) +{ + vec_t dot; + VMatrix mRet; + + + #define PN thePlane.m_Normal + #define PD thePlane.m_Dist; + + dot = PN[0]*vOrigin.x + PN[1]*vOrigin.y + PN[2]*vOrigin.z - PD; + + mRet.m[0][0] = dot - vOrigin.x * PN[0]; + mRet.m[0][1] = -vOrigin.x * PN[1]; + mRet.m[0][2] = -vOrigin.x * PN[2]; + mRet.m[0][3] = -vOrigin.x * -PD; + + mRet.m[1][0] = -vOrigin.y * PN[0]; + mRet.m[1][1] = dot - vOrigin.y * PN[1]; + mRet.m[1][2] = -vOrigin.y * PN[2]; + mRet.m[1][3] = -vOrigin.y * -PD; + + mRet.m[2][0] = -vOrigin.z * PN[0]; + mRet.m[2][1] = -vOrigin.z * PN[1]; + mRet.m[2][2] = dot - vOrigin.z * PN[2]; + mRet.m[2][3] = -vOrigin.z * -PD; + + mRet.m[3][0] = -PN[0]; + mRet.m[3][1] = -PN[1]; + mRet.m[3][2] = -PN[2]; + mRet.m[3][3] = dot + PD; + + #undef PN + #undef PD + + return mRet; +} + +inline VMatrix SetupMatrixAxisRot(const Vector &vAxis, vec_t fDegrees) +{ + vec_t s, c, t; + vec_t tx, ty, tz; + vec_t sx, sy, sz; + vec_t fRadians; + + + fRadians = fDegrees * (M_PI / 180.0f); + + s = (vec_t)sin(fRadians); + c = (vec_t)cos(fRadians); + t = 1.0f - c; + + tx = t * vAxis.x; ty = t * vAxis.y; tz = t * vAxis.z; + sx = s * vAxis.x; sy = s * vAxis.y; sz = s * vAxis.z; + + return VMatrix( + tx*vAxis.x + c, tx*vAxis.y - sz, tx*vAxis.z + sy, 0.0f, + tx*vAxis.y + sz, ty*vAxis.y + c, ty*vAxis.z - sx, 0.0f, + tx*vAxis.z - sy, ty*vAxis.z + sx, tz*vAxis.z + c, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f); +} + +//----------------------------------------------------------------------------- +// Setup a matrix from euler angles. +//----------------------------------------------------------------------------- +inline void MatrixFromAngles( const QAngle& vAngles, VMatrix& dst ) +{ + dst.SetupMatrixOrgAngles( vec3_origin, vAngles ); +} + +inline VMatrix SetupMatrixAngles(const QAngle &vAngles) +{ + VMatrix mRet; + MatrixFromAngles( vAngles, mRet ); + return mRet; +} + +inline VMatrix SetupMatrixOrgAngles(const Vector &origin, const QAngle &vAngles) +{ + VMatrix mRet; + mRet.SetupMatrixOrgAngles( origin, vAngles ); + return mRet; +} + +#endif // VECTOR_NO_SLOW_OPERATIONS + + +inline bool PlaneIntersection( const VPlane &vp1, const VPlane &vp2, const VPlane &vp3, Vector &vOut ) +{ + VMatrix mMat, mInverse; + + mMat.Init( + vp1.m_Normal.x, vp1.m_Normal.y, vp1.m_Normal.z, -vp1.m_Dist, + vp2.m_Normal.x, vp2.m_Normal.y, vp2.m_Normal.z, -vp2.m_Dist, + vp3.m_Normal.x, vp3.m_Normal.y, vp3.m_Normal.z, -vp3.m_Dist, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + if(mMat.InverseGeneral(mInverse)) + { + //vOut = mInverse * Vector(0.0f, 0.0f, 0.0f); + mInverse.GetTranslation( vOut ); + return true; + } + else + { + return false; + } +} + +//----------------------------------------------------------------------------- +// Builds a rotation matrix that rotates one direction vector into another +//----------------------------------------------------------------------------- +inline void MatrixBuildRotation( VMatrix &dst, const Vector& initialDirection, const Vector& finalDirection ) +{ + float angle = DotProduct( initialDirection, finalDirection ); + Assert( IsFinite(angle) ); + + Vector axis; + + // No rotation required + if (angle - 1.0 > -1e-3) + { + // parallel case + MatrixSetIdentity(dst); + return; + } + else if (angle + 1.0 < 1e-3) + { + // antiparallel case, pick any axis in the plane + // perpendicular to the final direction. Choose the direction (x,y,z) + // which has the minimum component of the final direction, use that + // as an initial guess, then subtract out the component which is + // parallel to the final direction + int idx = 0; + if (FloatMakePositive(finalDirection[1]) < FloatMakePositive(finalDirection[idx])) + idx = 1; + if (FloatMakePositive(finalDirection[2]) < FloatMakePositive(finalDirection[idx])) + idx = 2; + + axis.Init( 0, 0, 0 ); + axis[idx] = 1.0f; + VectorMA( axis, -DotProduct( axis, finalDirection ), finalDirection, axis ); + VectorNormalize(axis); + angle = 180.0f; + } + else + { + CrossProduct( initialDirection, finalDirection, axis ); + VectorNormalize( axis ); + angle = acos(angle) * 180 / M_PI; + } + + MatrixBuildRotationAboutAxis( dst, axis, angle ); + +#ifdef _DEBUG + Vector test; + Vector3DMultiply( dst, initialDirection, test ); + test -= finalDirection; + Assert( test.LengthSqr() < 1e-3 ); +#endif +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline void MatrixBuildRotateZ( VMatrix &dst, float angleDegrees ) +{ + float radians = angleDegrees * ( M_PI / 180.0f ); + + float fSin = ( float )sin( radians ); + float fCos = ( float )cos( radians ); + + dst[0][0] = fCos; dst[0][1] = -fSin; dst[0][2] = 0.0f; dst[0][3] = 0.0f; + dst[1][0] = fSin; dst[1][1] = fCos; dst[1][2] = 0.0f; dst[1][3] = 0.0f; + dst[2][0] = 0.0f; dst[2][1] = 0.0f; dst[2][2] = 1.0f; dst[2][3] = 0.0f; + dst[3][0] = 0.0f; dst[3][1] = 0.0f; dst[3][2] = 0.0f; dst[3][3] = 1.0f; +} + +// Builds a scale matrix +inline void MatrixBuildScale( VMatrix &dst, float x, float y, float z ) +{ + dst[0][0] = x; dst[0][1] = 0.0f; dst[0][2] = 0.0f; dst[0][3] = 0.0f; + dst[1][0] = 0.0f; dst[1][1] = y; dst[1][2] = 0.0f; dst[1][3] = 0.0f; + dst[2][0] = 0.0f; dst[2][1] = 0.0f; dst[2][2] = z; dst[2][3] = 0.0f; + dst[3][0] = 0.0f; dst[3][1] = 0.0f; dst[3][2] = 0.0f; dst[3][3] = 1.0f; +} + +inline void MatrixBuildScale( VMatrix &dst, const Vector& scale ) +{ + MatrixBuildScale( dst, scale.x, scale.y, scale.z ); +} + +inline void MatrixBuildPerspective( VMatrix &dst, float fovX, float fovY, float zNear, float zFar ) +{ + // FIXME: collapse all of this into one matrix after we figure out what all should be in here. + float width = 2 * zNear * tan( fovX * ( M_PI/180.0f ) * 0.5f ); + float height = 2 * zNear * tan( fovY * ( M_PI/180.0f ) * 0.5f ); + + memset( dst.Base(), 0, sizeof( dst ) ); + dst[0][0] = 2.0F * zNear / width; + dst[1][1] = 2.0F * zNear / height; + dst[2][2] = -zFar / ( zNear - zFar ); + dst[3][2] = 1.0f; + dst[2][3] = zNear * zFar / ( zNear - zFar ); + + // negate X and Y so that X points right, and Y points up. + VMatrix negateXY; + negateXY.Identity(); + negateXY[0][0] = -1.0f; + negateXY[1][1] = -1.0f; + MatrixMultiply( negateXY, dst, dst ); + + VMatrix addW; + addW.Identity(); + addW[0][3] = 1.0f; + addW[1][3] = 1.0f; + addW[2][3] = 0.0f; + MatrixMultiply( addW, dst, dst ); + + VMatrix scaleHalf; + scaleHalf.Identity(); + scaleHalf[0][0] = 0.5f; + scaleHalf[1][1] = 0.5f; + MatrixMultiply( scaleHalf, dst, dst ); +} + +static inline void CalculateAABBForNormalizedFrustum_Helper( float x, float y, float z, const VMatrix &volumeToWorld, Vector &mins, Vector &maxs ) +{ + Vector volumeSpacePos( x, y, z ); + + // Make sure it's been clipped + Assert( volumeSpacePos[0] >= -1e-3f ); + Assert( volumeSpacePos[0] - 1.0f <= 1e-3f ); + Assert( volumeSpacePos[1] >= -1e-3f ); + Assert( volumeSpacePos[1] - 1.0f <= 1e-3f ); + Assert( volumeSpacePos[2] >= -1e-3f ); + Assert( volumeSpacePos[2] - 1.0f <= 1e-3f ); + + Vector worldPos; + Vector3DMultiplyPositionProjective( volumeToWorld, volumeSpacePos, worldPos ); + AddPointToBounds( worldPos, mins, maxs ); +} + +//----------------------------------------------------------------------------- +// Given an inverse projection matrix, take the extremes of the space in transformed into world space and +// get a bounding box. +//----------------------------------------------------------------------------- +inline void CalculateAABBFromProjectionMatrixInverse( const VMatrix &volumeToWorld, Vector *pMins, Vector *pMaxs ) +{ + // FIXME: Could maybe do better than the compile with all of these multiplies by 0 and 1. + ClearBounds( *pMins, *pMaxs ); + CalculateAABBForNormalizedFrustum_Helper( 0, 0, 0, volumeToWorld, *pMins, *pMaxs ); + CalculateAABBForNormalizedFrustum_Helper( 0, 0, 1, volumeToWorld, *pMins, *pMaxs ); + CalculateAABBForNormalizedFrustum_Helper( 0, 1, 0, volumeToWorld, *pMins, *pMaxs ); + CalculateAABBForNormalizedFrustum_Helper( 0, 1, 1, volumeToWorld, *pMins, *pMaxs ); + CalculateAABBForNormalizedFrustum_Helper( 1, 0, 0, volumeToWorld, *pMins, *pMaxs ); + CalculateAABBForNormalizedFrustum_Helper( 1, 0, 1, volumeToWorld, *pMins, *pMaxs ); + CalculateAABBForNormalizedFrustum_Helper( 1, 1, 0, volumeToWorld, *pMins, *pMaxs ); + CalculateAABBForNormalizedFrustum_Helper( 1, 1, 1, volumeToWorld, *pMins, *pMaxs ); +} + +inline void CalculateAABBFromProjectionMatrix( const VMatrix &worldToVolume, Vector *pMins, Vector *pMaxs ) +{ + VMatrix volumeToWorld; + MatrixInverseGeneral( worldToVolume, volumeToWorld ); + CalculateAABBFromProjectionMatrixInverse( volumeToWorld, pMins, pMaxs ); +} + +//----------------------------------------------------------------------------- +// Given an inverse projection matrix, take the extremes of the space in transformed into world space and +// get a bounding sphere. +//----------------------------------------------------------------------------- +inline void CalculateSphereFromProjectionMatrixInverse( const VMatrix &volumeToWorld, Vector *pCenter, float *pflRadius ) +{ + // FIXME: Could maybe do better than the compile with all of these multiplies by 0 and 1. + + // Need 3 points: the endpoint of the line through the center of the near + far planes, + // and one point on the far plane. From that, we can derive a point somewhere on the center line + // which would produce the smallest bounding sphere. + Vector vecCenterNear, vecCenterFar, vecNearEdge, vecFarEdge; + Vector3DMultiplyPositionProjective( volumeToWorld, Vector( 0.5f, 0.5f, 0.0f ), vecCenterNear ); + Vector3DMultiplyPositionProjective( volumeToWorld, Vector( 0.5f, 0.5f, 1.0f ), vecCenterFar ); + Vector3DMultiplyPositionProjective( volumeToWorld, Vector( 0.0f, 0.0f, 0.0f ), vecNearEdge ); + Vector3DMultiplyPositionProjective( volumeToWorld, Vector( 0.0f, 0.0f, 1.0f ), vecFarEdge ); + + // Let the distance between the near + far center points = l + // Let the distance between the near center point + near edge point = h1 + // Let the distance between the far center point + far edge point = h2 + // Let the distance along the center line from the near point to the sphere center point = x + // Then let the distance between the sphere center point + near edge point == + // the distance between the sphere center point + far edge point == r == radius of sphere + // Then h1^2 + x^2 == r^2 == (l-x)^2 + h2^2 + // h1^x + x^2 = l^2 - 2 * l * x + x^2 + h2^2 + // 2 * l * x = l^2 + h2^2 - h1^2 + // x = (l^2 + h2^2 - h1^2) / (2 * l) + // r = sqrt( hl^1 + x^2 ) + Vector vecDelta; + VectorSubtract( vecCenterFar, vecCenterNear, vecDelta ); + float l = vecDelta.Length(); + float h1Sqr = vecCenterNear.DistToSqr( vecNearEdge ); + float h2Sqr = vecCenterFar.DistToSqr( vecFarEdge ); + float x = (l*l + h2Sqr - h1Sqr) / (2.0f * l); + VectorMA( vecCenterNear, (x / l), vecDelta, *pCenter ); + *pflRadius = sqrt( h1Sqr + x*x ); +} + +//----------------------------------------------------------------------------- +// Given a projection matrix, take the extremes of the space in transformed into world space and +// get a bounding sphere. +//----------------------------------------------------------------------------- +inline void CalculateSphereFromProjectionMatrix( const VMatrix &worldToVolume, Vector *pCenter, float *pflRadius ) +{ + VMatrix volumeToWorld; + MatrixInverseGeneral( worldToVolume, volumeToWorld ); + CalculateSphereFromProjectionMatrixInverse( volumeToWorld, pCenter, pflRadius ); +} + + +static inline void FrustumPlanesFromMatrixHelper( const VMatrix &shadowToWorld, const Vector &p1, const Vector &p2, const Vector &p3, + Vector &normal, float &dist ) +{ + Vector world1, world2, world3; + Vector3DMultiplyPositionProjective( shadowToWorld, p1, world1 ); + Vector3DMultiplyPositionProjective( shadowToWorld, p2, world2 ); + Vector3DMultiplyPositionProjective( shadowToWorld, p3, world3 ); + + Vector v1, v2; + VectorSubtract( world2, world1, v1 ); + VectorSubtract( world3, world1, v2 ); + + CrossProduct( v1, v2, normal ); + VectorNormalize( normal ); + dist = DotProduct( normal, world1 ); +} + +inline void FrustumPlanesFromMatrix( const VMatrix &clipToWorld, Frustum_t &frustum ) +{ + Vector normal; + float dist; + + FrustumPlanesFromMatrixHelper( clipToWorld, + Vector( 0.0f, 0.0f, 0.0f ), Vector( 1.0f, 0.0f, 0.0f ), Vector( 0.0f, 1.0f, 0.0f ), normal, dist ); + frustum.SetPlane( FRUSTUM_NEARZ, PLANE_ANYZ, normal, dist ); + + FrustumPlanesFromMatrixHelper( clipToWorld, + Vector( 0.0f, 0.0f, 1.0f ), Vector( 0.0f, 1.0f, 1.0f ), Vector( 1.0f, 0.0f, 1.0f ), normal, dist ); + frustum.SetPlane( FRUSTUM_FARZ, PLANE_ANYZ, normal, dist ); + + FrustumPlanesFromMatrixHelper( clipToWorld, + Vector( 1.0f, 0.0f, 0.0f ), Vector( 1.0f, 1.0f, 1.0f ), Vector( 1.0f, 1.0f, 0.0f ), normal, dist ); + frustum.SetPlane( FRUSTUM_RIGHT, PLANE_ANYZ, normal, dist ); + + FrustumPlanesFromMatrixHelper( clipToWorld, + Vector( 0.0f, 0.0f, 0.0f ), Vector( 0.0f, 1.0f, 1.0f ), Vector( 0.0f, 0.0f, 1.0f ), normal, dist ); + frustum.SetPlane( FRUSTUM_LEFT, PLANE_ANYZ, normal, dist ); + + FrustumPlanesFromMatrixHelper( clipToWorld, + Vector( 1.0f, 1.0f, 0.0f ), Vector( 1.0f, 1.0f, 1.0f ), Vector( 0.0f, 1.0f, 1.0f ), normal, dist ); + frustum.SetPlane( FRUSTUM_TOP, PLANE_ANYZ, normal, dist ); + + FrustumPlanesFromMatrixHelper( clipToWorld, + Vector( 1.0f, 0.0f, 0.0f ), Vector( 0.0f, 0.0f, 1.0f ), Vector( 1.0f, 0.0f, 1.0f ), normal, dist ); + frustum.SetPlane( FRUSTUM_BOTTOM, PLANE_ANYZ, normal, dist ); +} + +inline void MatrixBuildOrtho( VMatrix& dst, double left, double top, double right, double bottom, double zNear, double zFar ) +{ + // FIXME: This is being used incorrectly! Should read: + // D3DXMatrixOrthoOffCenterRH( &matrix, left, right, bottom, top, zNear, zFar ); + // Which is certainly why we need these extra -1 scales in y. Bleah + + // NOTE: The camera can be imagined as the following diagram: + // /z + // / + // /____ x Z is going into the screen + // | + // | + // |y + // + // (0,0,z) represents the upper-left corner of the screen. + // Our projection transform needs to transform from this space to a LH coordinate + // system that looks thusly: + // + // y| /z + // | / + // |/____ x Z is going into the screen + // + // Where x,y lies between -1 and 1, and z lies from 0 to 1 + // This is because the viewport transformation from projection space to pixels + // introduces a -1 scale in the y coordinates + // D3DXMatrixOrthoOffCenterRH( &matrix, left, right, top, bottom, zNear, zFar ); + + dst.Init( 2.0f / ( right - left ), 0.0f, 0.0f, ( left + right ) / ( left - right ), + 0.0f, 2.0f / ( bottom - top ), 0.0f, ( bottom + top ) / ( top - bottom ), + 0.0f, 0.0f, 1.0f / ( zNear - zFar ), zNear / ( zNear - zFar ), + 0.0f, 0.0f, 0.0f, 1.0f ); +} + +inline void MatrixBuildPerspectiveZRange( VMatrix& dst, double flZNear, double flZFar ) +{ + dst.m[2][0] = 0.0f; + dst.m[2][1] = 0.0f; + dst.m[2][2] = flZFar / ( flZNear - flZFar ); + dst.m[2][3] = flZNear * flZFar / ( flZNear - flZFar ); +} + +inline void MatrixBuildPerspectiveX( VMatrix& dst, double flFovX, double flAspect, double flZNear, double flZFar ) +{ + float flWidthScale = 1.0f / tanf( flFovX * M_PI / 360.0f ); + float flHeightScale = flAspect * flWidthScale; + dst.Init( flWidthScale, 0.0f, 0.0f, 0.0f, + 0.0f, flHeightScale, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, -1.0f, 0.0f ); + + MatrixBuildPerspectiveZRange ( dst, flZNear, flZFar ); +} + +inline void MatrixBuildPerspectiveOffCenterX( VMatrix& dst, double flFovX, double flAspect, double flZNear, double flZFar, double bottom, double top, double left, double right ) +{ + float flWidth = tanf( flFovX * M_PI / 360.0f ); + float flHeight = flWidth / flAspect; + + // bottom, top, left, right are 0..1 so convert to -<val>/2..<val>/2 + float flLeft = -(flWidth/2.0f) * (1.0f - left) + left * (flWidth/2.0f); + float flRight = -(flWidth/2.0f) * (1.0f - right) + right * (flWidth/2.0f); + float flBottom = -(flHeight/2.0f) * (1.0f - bottom) + bottom * (flHeight/2.0f); + float flTop = -(flHeight/2.0f) * (1.0f - top) + top * (flHeight/2.0f); + + dst.Init( 1.0f / (flRight-flLeft), 0.0f, (flLeft+flRight)/(flRight-flLeft), 0.0f, + 0.0f, 1.0f /(flTop-flBottom), (flTop+flBottom)/(flTop-flBottom), 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, -1.0f, 0.0f ); + + MatrixBuildPerspectiveZRange ( dst, flZNear, flZFar ); +} + #endif From e3edbc2d9602edae37724c509e5d28934c90bf53 Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Wed, 26 Apr 2023 22:33:20 +0300 Subject: [PATCH 22/29] mathlib: make Gain and Bias inline --- mathlib/mathlib_base.cpp | 27 --------------------------- public/mathlib/mathlib.h | 25 +++++++++++++++++++++---- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/mathlib/mathlib_base.cpp b/mathlib/mathlib_base.cpp index 60113379..872ffec5 100644 --- a/mathlib/mathlib_base.cpp +++ b/mathlib/mathlib_base.cpp @@ -1392,33 +1392,6 @@ void VectorYawRotate( const Vector &in, float flYaw, Vector &out) out.z = in.z; } - - -float Bias( float x, float biasAmt ) -{ - // WARNING: not thread safe - static float lastAmt = -1; - static float lastExponent = 0; - if( lastAmt != biasAmt ) - { - lastExponent = log( biasAmt ) * -1.4427f; // (-1.4427 = 1 / log(0.5)) - } - float fRet = pow( x, lastExponent ); - Assert ( !IS_NAN( fRet ) ); - return fRet; -} - - -float Gain( float x, float biasAmt ) -{ - // WARNING: not thread safe - if( x < 0.5 ) - return 0.5f * Bias( 2*x, 1-biasAmt ); - else - return 1 - 0.5f * Bias( 2 - 2*x, 1-biasAmt ); -} - - float SmoothCurve( float x ) { // Actual smooth curve. Visualization: diff --git a/public/mathlib/mathlib.h b/public/mathlib/mathlib.h index ca752def..2c24ba94 100644 --- a/public/mathlib/mathlib.h +++ b/public/mathlib/mathlib.h @@ -1082,7 +1082,19 @@ void VectorYawRotate( const Vector& in, float flYaw, Vector &out); // 0 1 // // With a biasAmt of 0.5, Bias returns X. -float Bias( float x, float biasAmt ); +inline float Bias( float x, float biasAmt ) +{ + // WARNING: not thread safe + static float lastAmt = -1; + static float lastExponent = 0; + if( lastAmt != biasAmt ) + { + lastExponent = log( biasAmt ) * -1.4427f; // (-1.4427 = 1 / log(0.5)) + } + float fRet = pow( x, lastExponent ); + Assert ( !IS_NAN( fRet ) ); + return fRet; +} // Gain is similar to Bias, but biasAmt biases towards or away from 0.5. @@ -1114,9 +1126,14 @@ float Bias( float x, float biasAmt ); // |***** // |___________________ // 0 1 -float Gain( float x, float biasAmt ); - - +inline float Gain( float x, float biasAmt ) +{ + // WARNING: not thread safe + if( x < 0.5 ) + return 0.5f * Bias( 2*x, 1-biasAmt ); + else + return 1 - 0.5f * Bias( 2 - 2*x, 1-biasAmt ); +} // SmoothCurve maps a 0-1 value into another 0-1 value based on a cosine wave // where the derivatives of the function at 0 and 1 (and 0.5) are 0. This is useful for // any fadein/fadeout effect where it should start and end smoothly. From 657f59ada3117a8afeed8acc0303db97a2c2f80d Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Wed, 26 Apr 2023 23:42:49 +0300 Subject: [PATCH 23/29] materialsystem: set allocator alignment 16( fixes crash in release build ) --- materialsystem/imaterialsysteminternal.h | 4 +-- public/mathlib/mathlib.h | 44 +++--------------------- 2 files changed, 7 insertions(+), 41 deletions(-) diff --git a/materialsystem/imaterialsysteminternal.h b/materialsystem/imaterialsysteminternal.h index 40f775d4..34ddc071 100644 --- a/materialsystem/imaterialsysteminternal.h +++ b/materialsystem/imaterialsysteminternal.h @@ -31,9 +31,9 @@ public: { MEM_ALLOC_CREDIT_( "CMatCallQueue.m_Allocator" ); #ifdef SWDS - m_Allocator.Init( 2*1024, 0, 0, 4 ); + m_Allocator.Init( 2*1024, 0, 0, 16 ); #else - m_Allocator.Init( IsX360() ? 2*1024*1024 : 8*1024*1024, 64*1024, 256*1024, 4 ); + m_Allocator.Init( IsX360() ? 2*1024*1024 : 8*1024*1024, 64*1024, 256*1024, 16 ); #endif m_FunctorFactory.SetAllocator( &m_Allocator ); m_pHead = m_pTail = NULL; diff --git a/public/mathlib/mathlib.h b/public/mathlib/mathlib.h index 2c24ba94..1e8e0266 100644 --- a/public/mathlib/mathlib.h +++ b/public/mathlib/mathlib.h @@ -30,7 +30,6 @@ // FP exception clean so this not a turnkey operation. //#define FP_EXCEPTIONS_ENABLED - #ifdef FP_EXCEPTIONS_ENABLED #include <float.h> // For _clearfp and _controlfp_s #endif @@ -93,37 +92,11 @@ private: FPExceptionEnabler& operator=(const FPExceptionEnabler&); }; - - -#ifdef DEBUG // stop crashing edit-and-continue -FORCEINLINE float clamp( float val, float minVal, float maxVal ) +inline float clamp( const float val, const float minVal, const float maxVal ) { - if ( maxVal < minVal ) - return maxVal; - else if( val < minVal ) - return minVal; - else if( val > maxVal ) - return maxVal; - else - return val; + const float t = val < minVal ? minVal : val; + return t > maxVal ? maxVal : t; } -#else // DEBUG -FORCEINLINE float clamp( float val, float minVal, float maxVal ) -{ -#if defined(__i386__) || defined(_M_IX86) - _mm_store_ss( &val, - _mm_min_ss( - _mm_max_ss( - _mm_load_ss(&val), - _mm_load_ss(&minVal) ), - _mm_load_ss(&maxVal) ) ); -#else - val = fpmax(minVal, val); - val = fpmin(maxVal, val); -#endif - return val; -} -#endif // DEBUG // // Returns a clamped value in the range [min, max]. @@ -131,17 +104,10 @@ FORCEINLINE float clamp( float val, float minVal, float maxVal ) template< class T > inline T clamp( T const &val, T const &minVal, T const &maxVal ) { - if ( maxVal < minVal ) - return maxVal; - else if( val < minVal ) - return minVal; - else if( val > maxVal ) - return maxVal; - else - return val; + const T t = val< minVal ? minVal : val; + return t > maxVal ? maxVal : t; } - // plane_t structure // !!! if this is changed, it must be changed in asm code too !!! // FIXME: does the asm code even exist anymore? From 30f1e02cda708f849e60f937f45c9d4ed7c17b1d Mon Sep 17 00:00:00 2001 From: SanyaSho <68691958+SanyaSho@users.noreply.github.com> Date: Fri, 28 Apr 2023 19:45:47 +0300 Subject: [PATCH 24/29] wscript: use "/LARGEADDRESSAWARE" on windows --- wscript | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/wscript b/wscript index 95871403..352e3209 100644 --- a/wscript +++ b/wscript @@ -514,30 +514,32 @@ def configure(conf): '/TP', '/EHsc' ] - + if conf.options.BUILD_TYPE == 'debug': linkflags += [ '/INCREMENTAL:NO', '/NODEFAULTLIB:libc', '/NODEFAULTLIB:libcd', '/NODEFAULTLIB:libcmt', - '/FORCE' + '/FORCE', + '/LARGEADDRESSAWARE' ] else: linkflags += [ '/INCREMENTAL', '/NODEFAULTLIB:libc', '/NODEFAULTLIB:libcd', - '/NODEFAULTLIB:libcmtd' + '/NODEFAULTLIB:libcmtd', + '/LARGEADDRESSAWARE' ] linkflags += [ '/LIBPATH:'+os.path.abspath('.')+'/lib/win32/'+conf.env.DEST_CPU+'/', '/LIBPATH:'+os.path.abspath('.')+'/dx9sdk/lib/'+conf.env.DEST_CPU+'/' ] - + # And here C++ flags starts to be treated separately - cxxflags = list(cflags) + cxxflags = list(cflags) if conf.env.DEST_OS != 'win32': cxxflags += ['-std=c++11','-fpermissive'] From 965ef972126b6b55bb33f4b994b361a94604fb95 Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Sat, 29 Apr 2023 15:34:11 +0300 Subject: [PATCH 25/29] togl/togles: set D3DMATRIX alignment to 16 --- public/mathlib/vmatrix.h | 47 ++++++++++++----------- public/togl/linuxwin/dxabstract_types.h | 2 +- public/togles/linuxwin/dxabstract_types.h | 2 +- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/public/mathlib/vmatrix.h b/public/mathlib/vmatrix.h index 2170f9c7..b435a421 100644 --- a/public/mathlib/vmatrix.h +++ b/public/mathlib/vmatrix.h @@ -114,11 +114,15 @@ public: const matrix3x4_t& As3x4() const; void CopyFrom3x4( const matrix3x4_t &m3x4 ); - void Set3x4( matrix3x4_t& matrix3x4 ) const; + void Set3x4( const matrix3x4_t& matrix3x4 ); bool operator==( const VMatrix& src ) const { - return !memcmp( src.m, m, sizeof(m) ); + return src.m[0][0] == m[0][0] && src.m[0][1] == m[0][1] && src.m[0][2] == m[0][2] && src.m[0][3] == m[0][3] && + src.m[1][0] == m[1][0] && src.m[1][1] == m[1][1] && src.m[1][2] == m[1][2] && src.m[1][3] == m[1][3] && + src.m[2][0] == m[2][0] && src.m[2][1] == m[2][1] && src.m[2][2] == m[2][2] && src.m[2][3] == m[2][3] && + src.m[3][0] == m[3][0] && src.m[3][1] == m[3][1] && src.m[3][2] == m[3][2] && src.m[3][3] == m[3][3]; } + bool operator!=( const VMatrix& src ) const { return !( *this == src ); } #ifndef VECTOR_NO_SLOW_OPERATIONS @@ -512,14 +516,12 @@ inline void VMatrix::Init( //----------------------------------------------------------------------------- // Initialize from a 3x4 //----------------------------------------------------------------------------- -inline void VMatrix::Init( const matrix3x4_t& matrix3x4 ) +inline void VMatrix::Init( const matrix3x4_t& _m ) { - memcpy(m, matrix3x4.Base(), sizeof( matrix3x4_t ) ); - - m[3][0] = 0.0f; - m[3][1] = 0.0f; - m[3][2] = 0.0f; - m[3][3] = 1.0f; + m[0][0] = _m[0][0]; m[0][1] = _m[0][1]; m[0][2] = _m[0][2]; m[0][3] = _m[0][3]; + m[1][0] = _m[1][0]; m[1][1] = _m[1][1]; m[1][2] = _m[1][2]; m[1][3] = _m[1][3]; + m[2][0] = _m[2][0]; m[2][1] = _m[2][1]; m[2][2] = _m[2][2]; m[2][3] = _m[2][3]; + m[3][0] = 0.0f; m[3][1] = 0.0f; m[3][2] = 0.0f; m[3][3] = 1.0f; } //----------------------------------------------------------------------------- @@ -837,14 +839,14 @@ inline const matrix3x4_t& VMatrix::As3x4() const inline void VMatrix::CopyFrom3x4( const matrix3x4_t &m3x4 ) { - memcpy( m, m3x4.Base(), sizeof( matrix3x4_t ) ); - m[3][0] = m[3][1] = m[3][2] = 0; - m[3][3] = 1; -} + Init(m3x4); +} -inline void VMatrix::Set3x4( matrix3x4_t& matrix3x4 ) const +inline void VMatrix::Set3x4( const matrix3x4_t& _m ) { - memcpy(matrix3x4.Base(), m, sizeof( matrix3x4_t ) ); + m[0][0] = _m[0][0]; m[0][1] = _m[0][1]; m[0][2] = _m[0][2]; m[0][3] = _m[0][3]; + m[1][0] = _m[1][0]; m[1][1] = _m[1][1]; m[1][2] = _m[1][2]; m[1][3] = _m[1][3]; + m[2][0] = _m[2][0]; m[2][1] = _m[2][1]; m[2][2] = _m[2][2]; m[2][3] = _m[2][3]; } #ifndef VECTOR_NO_SLOW_OPERATIONS @@ -1805,18 +1807,19 @@ inline void MatrixBuildScale( VMatrix &dst, const Vector& scale ) MatrixBuildScale( dst, scale.x, scale.y, scale.z ); } +// nillerusr: optimize this bruh later inline void MatrixBuildPerspective( VMatrix &dst, float fovX, float fovY, float zNear, float zFar ) { // FIXME: collapse all of this into one matrix after we figure out what all should be in here. float width = 2 * zNear * tan( fovX * ( M_PI/180.0f ) * 0.5f ); float height = 2 * zNear * tan( fovY * ( M_PI/180.0f ) * 0.5f ); - memset( dst.Base(), 0, sizeof( dst ) ); - dst[0][0] = 2.0F * zNear / width; - dst[1][1] = 2.0F * zNear / height; - dst[2][2] = -zFar / ( zNear - zFar ); - dst[3][2] = 1.0f; - dst[2][3] = zNear * zFar / ( zNear - zFar ); + dst. Init( + 2.0f * zNear / width, 0.f, 0.f, 0.f, + 0.f, 2.0f * zNear / height, 0.f, 0.f, + 0.f, 0.f, -zFar / ( zNear - zFar ), zNear * zFar / ( zNear - zFar ), + 0.f, 0.f, 1.f, 0.f + ); // negate X and Y so that X points right, and Y points up. VMatrix negateXY; @@ -1824,7 +1827,7 @@ inline void MatrixBuildPerspective( VMatrix &dst, float fovX, float fovY, float negateXY[0][0] = -1.0f; negateXY[1][1] = -1.0f; MatrixMultiply( negateXY, dst, dst ); - + VMatrix addW; addW.Identity(); addW[0][3] = 1.0f; diff --git a/public/togl/linuxwin/dxabstract_types.h b/public/togl/linuxwin/dxabstract_types.h index aa3013f3..3ad0ee48 100644 --- a/public/togl/linuxwin/dxabstract_types.h +++ b/public/togl/linuxwin/dxabstract_types.h @@ -1042,7 +1042,7 @@ typedef enum _D3DSHADER_PARAM_REGISTER_TYPE D3DSPR_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum } D3DSHADER_PARAM_REGISTER_TYPE; -struct D3DMATRIX +struct alignas(16) D3DMATRIX { union { diff --git a/public/togles/linuxwin/dxabstract_types.h b/public/togles/linuxwin/dxabstract_types.h index 49861e86..f85deddc 100644 --- a/public/togles/linuxwin/dxabstract_types.h +++ b/public/togles/linuxwin/dxabstract_types.h @@ -1042,7 +1042,7 @@ typedef enum _D3DSHADER_PARAM_REGISTER_TYPE D3DSPR_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum } D3DSHADER_PARAM_REGISTER_TYPE; -struct D3DMATRIX +struct alignas(16) D3DMATRIX { union { From 271c9993da9a2f1263237ee70ed8966ce7411d0a Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Sun, 30 Apr 2023 17:03:03 +0300 Subject: [PATCH 26/29] hl2: fix random crash when combine throws a can --- .gitignore | 2 -- game/server/hl2/ai_behavior_police.cpp | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 37d8b4c9..717bd12d 100644 --- a/.gitignore +++ b/.gitignore @@ -37,5 +37,3 @@ waf3*/ .vscode/ .depproj/ source-engine.sln -hl2/ - diff --git a/game/server/hl2/ai_behavior_police.cpp b/game/server/hl2/ai_behavior_police.cpp index eb1b45b3..a3062ddc 100644 --- a/game/server/hl2/ai_behavior_police.cpp +++ b/game/server/hl2/ai_behavior_police.cpp @@ -33,6 +33,7 @@ CAI_PolicingBehavior::CAI_PolicingBehavior( void ) m_bEnabled = false; m_nNumWarnings = 0; m_bTargetIsHostile = false; + m_hPoliceGoal = NULL; } //----------------------------------------------------------------------------- From 3b1b08fd93e8d6a362b4fc4d5f023f41c612009f Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Fri, 5 May 2023 19:14:50 +0300 Subject: [PATCH 27/29] win32: fix sdl2 install path --- wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wscript b/wscript index 352e3209..4690d56d 100644 --- a/wscript +++ b/wscript @@ -596,7 +596,7 @@ def build(bld): if bld.env.DEST_OS in ['win32', 'android']: sdl_name = 'SDL2.dll' if bld.env.DEST_OS == 'win32' else 'libSDL2.so' sdl_path = os.path.join('lib', bld.env.DEST_OS, bld.env.DEST_CPU, sdl_name) - bld.install_files('${PREFIX}/', [sdl_path]) + bld.install_files(bld.env.LIBDIR, [sdl_path]) if bld.env.DEST_OS == 'win32': projects['game'] += ['utils/bzip2'] From 523f4e9eaa6442f4a9792420f55e69d8bd072217 Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Fri, 5 May 2023 19:17:06 +0300 Subject: [PATCH 28/29] vgui_controls: fix unitialized variable --- vgui2/vgui_controls/TextEntry.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vgui2/vgui_controls/TextEntry.cpp b/vgui2/vgui_controls/TextEntry.cpp index d5fa9179..882cb17f 100644 --- a/vgui2/vgui_controls/TextEntry.cpp +++ b/vgui2/vgui_controls/TextEntry.cpp @@ -95,6 +95,8 @@ TextEntry::TextEntry(Panel *parent, const char *panelName) : BaseClass(parent, p SetEditable(true); + _dataChanged = false; + // initialize the line break array m_LineBreaks.AddToTail(BUFFER_SIZE); From a6c26f4271006fb2ae4e861f1bc2ac333d996b2f Mon Sep 17 00:00:00 2001 From: nillerusr <nillerusr@gmail.com> Date: Wed, 17 May 2023 16:06:34 +0000 Subject: [PATCH 29/29] replace stlport with gnustl --- scripts/waifulib/xcompile.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/waifulib/xcompile.py b/scripts/waifulib/xcompile.py index 074f01bc..2db9b7f9 100644 --- a/scripts/waifulib/xcompile.py +++ b/scripts/waifulib/xcompile.py @@ -215,7 +215,6 @@ class Android: # TODO: proper STL support return [ #os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'system', 'include')), - os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'stlport', 'stlport')), os.path.abspath(os.path.join(self.ndk_home, 'sources', 'android', 'support', 'include')) ] @@ -346,8 +345,12 @@ def configure(conf): conf.env.CXXFLAGS += android.cflags(True) conf.env.LINKFLAGS += android.linkflags() conf.env.LDFLAGS += android.ldflags() - conf.env.STLIBPATH += [os.path.abspath(os.path.join(android.ndk_home, 'sources','cxx-stl','stlport','libs',stlarch))] - conf.env.LDFLAGS += ['-lstlport_static'] + conf.env.INCLUDES += [ + os.path.abspath(os.path.join(android.ndk_home, 'sources', 'cxx-stl', 'gnu-libstdc++', '4.9', 'include')), + os.path.abspath(os.path.join(android.ndk_home, 'sources', 'cxx-stl', 'gnu-libstdc++', '4.9', 'libs', stlarch, 'include')) + ] + conf.env.STLIBPATH += [os.path.abspath(os.path.join(android.ndk_home, 'sources','cxx-stl','gnu-libstdc++','4.9','libs',stlarch))] + conf.env.LDFLAGS += ['-lgnustl_static'] conf.env.HAVE_M = True if android.is_hardfp():