From 90e408e02c337b9be967ebc6576ff3414dbe790a Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Tue, 19 Apr 2016 07:20:41 +0200 Subject: [PATCH 01/13] Don't regulate Framerate on Pandora --- Sources/SeriousSam/SeriousSam.cpp | 3 +++ 1 file changed, 3 insertions(+) mode change 100644 => 100755 Sources/SeriousSam/SeriousSam.cpp diff --git a/Sources/SeriousSam/SeriousSam.cpp b/Sources/SeriousSam/SeriousSam.cpp old mode 100644 new mode 100755 index 9b76471..b28ffff --- a/Sources/SeriousSam/SeriousSam.cpp +++ b/Sources/SeriousSam/SeriousSam.cpp @@ -281,6 +281,8 @@ static void UpdatePauseState(void) // limit current frame rate if neeeded void LimitFrameRate(void) { + // do not limit FPS on the Pandora, it's not powerfull enough and doesn't "iconise" games either + #ifndef PLATFORM_PANDORA // measure passed time for each loop static CTimerValue tvLast(-1.0f); CTimerValue tvNow = _pTimer->GetHighPrecisionTimer(); @@ -299,6 +301,7 @@ void LimitFrameRate(void) // remember new time tvLast = _pTimer->GetHighPrecisionTimer(); + #endif } // load first demo From b6d54121a58793deeca9e55387d3e0b00faa9708 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 17 Apr 2016 09:45:01 +0200 Subject: [PATCH 02/13] Restrict the Eps precision change only to Pandora platform --- Sources/Engine/Math/Quaternion.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/Engine/Math/Quaternion.h b/Sources/Engine/Math/Quaternion.h index b46c078..19dbae5 100755 --- a/Sources/Engine/Math/Quaternion.h +++ b/Sources/Engine/Math/Quaternion.h @@ -370,7 +370,11 @@ void Quaternion::FromEuler(const Vector &a) template Type Quaternion::EPS(Type orig) const { +#ifdef PLATFORM_PANDORA + if ((orig <= 1e-4f) && (orig >= -1e-4f)) +#else if ((orig <= 10e-6f) && (orig >= -10e-6f)) +#endif return(0.0f); return(orig); From 4db3022cbd63d6ed14d92993967394a9eaab89ac Mon Sep 17 00:00:00 2001 From: Tan Wang Leng Date: Sat, 23 Apr 2016 22:49:07 +0800 Subject: [PATCH 03/13] Fix mouse wheel for switching weapons This fixes #32. Strictly follows the Win32 version. --- Sources/Engine/Base/SDL/SDLInput.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/Sources/Engine/Base/SDL/SDLInput.cpp b/Sources/Engine/Base/SDL/SDLInput.cpp index d378cc1..6b39711 100755 --- a/Sources/Engine/Base/SDL/SDLInput.cpp +++ b/Sources/Engine/Base/SDL/SDLInput.cpp @@ -251,6 +251,10 @@ static int _iMouseZ = 0; static BOOL _bWheelUp = FALSE; static BOOL _bWheelDn = FALSE; +// emulate Win32: A single mouse wheel rotation +// is +120 (upwards) or -120 (downwards) +#define MOUSE_SCROLL_INTERVAL 120 + CTCriticalSection csInput; // which keys are pressed, as recorded by message interception (by KIDs) @@ -319,10 +323,7 @@ static void sdl_event_handler(const SDL_Event *event) break; case SDL_MOUSEWHEEL: - if (event->wheel.y > 0) - _abKeysPressed[KID_MOUSEWHEELUP] = TRUE; - else if (event->wheel.y < 0) - _abKeysPressed[KID_MOUSEWHEELDOWN] = TRUE; + _iMouseZ += event->wheel.y * MOUSE_SCROLL_INTERVAL; break; case SDL_KEYDOWN: @@ -744,10 +745,6 @@ void CInput::GetInput(BOOL bPreScan) } } - // reset this every frame (since we explicitly ignore the button-up events). - _abKeysPressed[KID_MOUSEWHEELUP] = FALSE; - _abKeysPressed[KID_MOUSEWHEELDOWN] = FALSE; - // read mouse position #ifdef USE_MOUSEWARP int iMx, iMy; @@ -816,17 +813,16 @@ void CInput::GetInput(BOOL bPreScan) } #endif -/* // if not pre-scanning if (!bPreScan) { // detect wheel up/down movement - _bWheelDn = FALSE; + if (_iMouseZ>0) { if (_bWheelUp) { inp_ubButtonsBuffer[KID_MOUSEWHEELUP] = 0x00; } else { inp_ubButtonsBuffer[KID_MOUSEWHEELUP] = 0xFF; - _iMouseZ = ClampDn(_iMouseZ-120, 0); + _iMouseZ = ClampDn(_iMouseZ-MOUSE_SCROLL_INTERVAL, 0); } } _bWheelUp = inp_ubButtonsBuffer[KID_MOUSEWHEELUP]; @@ -835,12 +831,11 @@ void CInput::GetInput(BOOL bPreScan) inp_ubButtonsBuffer[KID_MOUSEWHEELDOWN] = 0x00; } else { inp_ubButtonsBuffer[KID_MOUSEWHEELDOWN] = 0xFF; - _iMouseZ = ClampUp(_iMouseZ+120, 0); + _iMouseZ = ClampUp(_iMouseZ+MOUSE_SCROLL_INTERVAL, 0); } } _bWheelDn = inp_ubButtonsBuffer[KID_MOUSEWHEELDOWN]; } -*/ inp_bLastPrescan = bPreScan; From 07e64e787e0cf8d4bfaf5eca38b8df91e0320575 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Tue, 19 Apr 2016 07:20:41 +0200 Subject: [PATCH 04/13] Don't regulate Framerate on Pandora From 86ef2fee09675ca7ef5304bf19dc74ccae94a655 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 17 Apr 2016 09:45:01 +0200 Subject: [PATCH 05/13] Restrict the Eps precision change only to Pandora platform From 6bb2f81134260694897a729faf43b6aeb4656b30 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 16 Apr 2016 13:10:32 +0200 Subject: [PATCH 06/13] fix Inverted Right and Middle button on certain case with SDL --- Sources/Engine/Base/SDL/SDLInput.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sources/Engine/Base/SDL/SDLInput.cpp b/Sources/Engine/Base/SDL/SDLInput.cpp index 6b39711..8596a5f 100755 --- a/Sources/Engine/Base/SDL/SDLInput.cpp +++ b/Sources/Engine/Base/SDL/SDLInput.cpp @@ -318,8 +318,16 @@ static void sdl_event_handler(const SDL_Event *event) case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: - if (event->button.button <= 5) - _abKeysPressed[KID_MOUSE1 + (event->button.button-1)] = (event->button.state == SDL_PRESSED) ? TRUE : FALSE; + if (event->button.button <= 5) { + int button = KID_MOUSE1; + switch(event->button.button) { + case SDL_BUTTON_RIGHT: button = KID_MOUSE2; break; + case SDL_BUTTON_MIDDLE: button = KID_MOUSE3; break; + case 4: button = KID_MOUSE4; break; + case 5: button = KID_MOUSE5; break; + } + _abKeysPressed[button] = (event->button.state == SDL_PRESSED) ? TRUE : FALSE; + } break; case SDL_MOUSEWHEEL: From 16d6cb99fa586ed23414c05a172ac4e93cfce599 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 23 Apr 2016 10:49:31 +0200 Subject: [PATCH 07/13] Added some Failsafe. Fixed a crash in the new game intro cinematic (when Boss of TFE die and Sam goes to the UFO) on the Pandora --- Sources/Engine/Rendering/RendASER.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) mode change 100644 => 100755 Sources/Engine/Rendering/RendASER.cpp diff --git a/Sources/Engine/Rendering/RendASER.cpp b/Sources/Engine/Rendering/RendASER.cpp old mode 100644 new mode 100755 index e5d52b0..7428a11 --- a/Sources/Engine/Rendering/RendASER.cpp +++ b/Sources/Engine/Rendering/RendASER.cpp @@ -34,7 +34,6 @@ void CRenderer::AddAddListToActiveList(INDEX iScanLine) // allocate space in destination for sum of source and add INDEX ctActiveEdges = re_aaceActiveEdges.Count(); re_aaceActiveEdgesTmp.Push(ctAddEdges+ctActiveEdges); - // check that the add list is sorted right #if ASER_EXTREME_CHECKING { @@ -66,18 +65,18 @@ void CRenderer::AddAddListToActiveList(INDEX iScanLine) // start at begining of add list, source active list and destination active list LISTITER(CAddEdge, ade_lnInAdd) itadeAdd(lhAdd); CActiveEdge *paceSrc = &re_aaceActiveEdges[0]; + CActiveEdge *paceEnd = &re_aaceActiveEdges[re_aaceActiveEdges.Count()-1]; CActiveEdge *paceDst = &re_aaceActiveEdgesTmp[0]; IFDEBUG(INDEX ctNewActive=0); IFDEBUG(INDEX ctOldActive1=0); IFDEBUG(INDEX ctOldActive2=0); - // for each edge in add list while(!itadeAdd.IsPastEnd()) { CAddEdge &ade = *itadeAdd; // while the edge in active list is left of the edge in add list - while (paceSrc->ace_xI.slHolder < itadeAdd->ade_xI.slHolder) { + while ((paceSrc->ace_xI.slHolder < ade.ade_xI.slHolder) && (paceSrc!=paceEnd)) { // copy the active edge ASSERT(paceSrc<=&re_aaceActiveEdges[ctActiveEdges-1]); *paceDst++=*paceSrc++; From 45429a88d8c0735bfd35a7f43673f9068f739e50 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 23 Apr 2016 18:01:27 +0200 Subject: [PATCH 08/13] Some Pandora fine-tunning --- Sources/Engine/Engine.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) mode change 100644 => 100755 Sources/Engine/Engine.cpp diff --git a/Sources/Engine/Engine.cpp b/Sources/Engine/Engine.cpp old mode 100644 new mode 100755 index 15021ca..84e5944 --- a/Sources/Engine/Engine.cpp +++ b/Sources/Engine/Engine.cpp @@ -127,6 +127,9 @@ static void DetectCPU(void) { #if (defined USE_PORTABLE_C) // rcg10072001 CPrintF(TRANSV(" (No CPU detection in this binary.)\n")); + #ifdef PLATFORM_PANDORA + sys_iCPUMHz = 400; // conservative, ARM -> x86 cpu translation is not 1 to 1. + #endif #else char strVendor[12+1]; @@ -398,7 +401,19 @@ static void SetupMemoryManager(void) sys_iRAMSwap = ms.dwTotalPageFile/MB; #elif (defined PLATFORM_UNIX) + #ifdef PLATFORM_PANDORA + sys_iRAMPhys = 256; // conservative here, there is 256MB models and 512MB... + FILE* esrev = fopen("/etc/powervr-esrev", "r"); + if (esrev) { + int rev = 0; + fscanf(esrev,"%d", &rev); + if (rev==3 || rev==5) + sys_iRAMPhys = 512; + fclose(esrev); + }; + #else sys_iRAMPhys = 1; // !!! FIXME: This is bad. Bad. BAD. + #endif sys_iRAMSwap = 1; #else From 3e0171ea1b81ca273e2e62047965876021017edb Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 23 Apr 2016 18:02:57 +0200 Subject: [PATCH 09/13] Tried some asynchronus input method, but doesn't seems to works --- Sources/Engine/Base/SDL/SDLInput.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/Engine/Base/SDL/SDLInput.cpp b/Sources/Engine/Base/SDL/SDLInput.cpp index 8596a5f..17ebefa 100755 --- a/Sources/Engine/Base/SDL/SDLInput.cpp +++ b/Sources/Engine/Base/SDL/SDLInput.cpp @@ -724,6 +724,7 @@ void CInput::GetInput(BOOL bPreScan) // clear button's buffer memset( inp_ubButtonsBuffer, 0, sizeof( inp_ubButtonsBuffer)); + Uint8 *keystate = SDL_GetKeyboardState(NULL); // for each Key for (INDEX iKey=0; iKey=0) { // is state is pressed - if (SDL_GetKeyboardState(NULL)[SDL_GetScancodeFromKey((SDL_Keycode)iVirt)]) { + if (keystate[SDL_GetScancodeFromKey((SDL_Keycode)iVirt)]) { // mark it as pressed inp_ubButtonsBuffer[iKID] = 0xFF; } From ae30b8b4dec20199487566b1dd25e55f340cb6e3 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Mon, 17 Apr 2017 13:11:58 +0200 Subject: [PATCH 10/13] Experimental fast-math for Pandora --- Sources/CMakeLists.txt | 24 +++++++++++++++------ Sources/Engine/Terrain/TerrainMisc.cpp | 21 +++++++++++------- Sources/Engine/World/WorldCollisionGrid.cpp | 22 ++++++++++++++----- 3 files changed, 48 insertions(+), 19 deletions(-) mode change 100644 => 100755 Sources/CMakeLists.txt mode change 100644 => 100755 Sources/Engine/Terrain/TerrainMisc.cpp mode change 100644 => 100755 Sources/Engine/World/WorldCollisionGrid.cpp diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt old mode 100644 new mode 100755 index ef8aee2..2e2aef2 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -99,15 +99,27 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") ## For C flags set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -D_DEBUG=1 -DDEBUG=1 -O0") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -O3 -fno-unsafe-math-optimizations") - set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 -fno-unsafe-math-optimizations") - set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -Os -fno-unsafe-math-optimizations") + if(PANDORA) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -O3 -ffast-math") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 -ffast-math") + set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -Os -ffast-math") + else() + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -O3 -fno-unsafe-math-optimizations") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 -fno-unsafe-math-optimizations") + set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -Os -fno-unsafe-math-optimizations") + endif() ## For C++ flags set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -D_DEBUG=1 -DDEBUG=1 -O0") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -O3 -fno-unsafe-math-optimizations") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 -fno-unsafe-math-optimizations") ## RAKE! Does -DNDEBUG=1 and -D_NDEBUG=1 mess with RelWithDebInfo? - set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -Os -fno-unsafe-math-optimizations") + if(PANDORA) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -O3 -ffast-math") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 -ffast-math") + set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -Os -ffast-math") + else() + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -O3 -fno-unsafe-math-optimizations") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 -fno-unsafe-math-optimizations") ## RAKE! Does -DNDEBUG=1 and -D_NDEBUG=1 mess with RelWithDebInfo? + set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -Os -fno-unsafe-math-optimizations") + endif() # TODO fix these warnings add_compile_options(-Wno-switch) diff --git a/Sources/Engine/Terrain/TerrainMisc.cpp b/Sources/Engine/Terrain/TerrainMisc.cpp old mode 100644 new mode 100755 index 3ff1753..5b199d4 --- a/Sources/Engine/Terrain/TerrainMisc.cpp +++ b/Sources/Engine/Terrain/TerrainMisc.cpp @@ -310,10 +310,15 @@ Rect ExtractPolygonsInBox(CTerrain *ptrTerrain, const FLOATaabbox3D &bboxExtract if(!bFixSize) { // max vector of bbox in incremented for one, because first vertex is at 0,0,0 in world and in heightmap is at 1,1 #ifdef __arm__ - rc.rc_iLeft = (isinf(bbox.minvect(1)))?(INDEX)0:Clamp((INDEX)(bbox.minvect(1)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapWidth); - rc.rc_iTop = (isinf(bbox.minvect(3)))?(INDEX)0:Clamp((INDEX)(bbox.minvect(3)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapHeight); - rc.rc_iRight = (isinf(bbox.maxvect(1)))?(INDEX)0:Clamp((INDEX)ceil(bbox.maxvect(1)+1),(INDEX)0,ptrTerrain->tr_pixHeightMapWidth); - rc.rc_iBottom = (isinf(bbox.maxvect(3)))?(INDEX)0:Clamp((INDEX)ceil(bbox.maxvect(3)+1),(INDEX)0,ptrTerrain->tr_pixHeightMapHeight); +#ifdef PANDORA + #define Isinf(a) (((*(unsigned int*)&a)&0x7fffffff)==0x7f800000) +#else + #define Isinf insif +#endif + rc.rc_iLeft = (Isinf(bbox.minvect(1)))?(INDEX)0:Clamp((INDEX)(bbox.minvect(1)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapWidth); + rc.rc_iTop = (Isinf(bbox.minvect(3)))?(INDEX)0:Clamp((INDEX)(bbox.minvect(3)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapHeight); + rc.rc_iRight = (Isinf(bbox.maxvect(1)))?(INDEX)0:Clamp((INDEX)ceil(bbox.maxvect(1)+1),(INDEX)0,ptrTerrain->tr_pixHeightMapWidth); + rc.rc_iBottom = (Isinf(bbox.maxvect(3)))?(INDEX)0:Clamp((INDEX)ceil(bbox.maxvect(3)+1),(INDEX)0,ptrTerrain->tr_pixHeightMapHeight); #else rc.rc_iLeft = Clamp((INDEX)(bbox.minvect(1)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapWidth); rc.rc_iTop = Clamp((INDEX)(bbox.minvect(3)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapHeight); @@ -323,10 +328,10 @@ Rect ExtractPolygonsInBox(CTerrain *ptrTerrain, const FLOATaabbox3D &bboxExtract } else { // max vector of bbox in incremented for one, because first vertex is at 0,0,0 in world and in heightmap is at 1,1 #ifdef __arm__ - rc.rc_iLeft = (isinf(bbox.minvect(1)))?(INDEX)0:Clamp((INDEX)(bbox.minvect(1)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapWidth); - rc.rc_iTop = (isinf(bbox.minvect(3)))?(INDEX)0:Clamp((INDEX)(bbox.minvect(3)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapHeight); - rc.rc_iRight = (isinf(bbox.maxvect(1)))?(INDEX)0:Clamp((INDEX)(bbox.maxvect(1)+0),(INDEX)0,ptrTerrain->tr_pixHeightMapWidth); - rc.rc_iBottom = (isinf(bbox.maxvect(3)))?(INDEX)0:Clamp((INDEX)(bbox.maxvect(3)+0),(INDEX)0,ptrTerrain->tr_pixHeightMapHeight); + rc.rc_iLeft = (Isinf(bbox.minvect(1)))?(INDEX)0:Clamp((INDEX)(bbox.minvect(1)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapWidth); + rc.rc_iTop = (Isinf(bbox.minvect(3)))?(INDEX)0:Clamp((INDEX)(bbox.minvect(3)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapHeight); + rc.rc_iRight = (Isinf(bbox.maxvect(1)))?(INDEX)0:Clamp((INDEX)(bbox.maxvect(1)+0),(INDEX)0,ptrTerrain->tr_pixHeightMapWidth); + rc.rc_iBottom = (Isinf(bbox.maxvect(3)))?(INDEX)0:Clamp((INDEX)(bbox.maxvect(3)+0),(INDEX)0,ptrTerrain->tr_pixHeightMapHeight); #else rc.rc_iLeft = Clamp((INDEX)(bbox.minvect(1)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapWidth); rc.rc_iTop = Clamp((INDEX)(bbox.minvect(3)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapHeight); diff --git a/Sources/Engine/World/WorldCollisionGrid.cpp b/Sources/Engine/World/WorldCollisionGrid.cpp old mode 100644 new mode 100755 index 1b94f21..1dac910 --- a/Sources/Engine/World/WorldCollisionGrid.cpp +++ b/Sources/Engine/World/WorldCollisionGrid.cpp @@ -14,7 +14,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include -#pragma GCC optimize 0 +//#pragma GCC optimize 0 #include #include #include @@ -47,15 +47,27 @@ static inline void BoxToGrid( FLOAT fMinZ = boxEntity.Min()(3); FLOAT fMaxX = boxEntity.Max()(1); FLOAT fMaxZ = boxEntity.Max()(3); - iMinX = (isinf(fMinX))?INDEX(GRID_MIN):INDEX(floor(fMinX/GRID_CELLSIZE)); - iMinZ = (isinf(fMinZ))?INDEX(GRID_MIN):INDEX(floor(fMinZ/GRID_CELLSIZE)); - iMaxX = (isinf(fMaxX))?INDEX(GRID_MIN):INDEX(ceil(fMaxX/GRID_CELLSIZE)); - iMaxZ = (isinf(fMaxZ))?INDEX(GRID_MIN):INDEX(ceil(fMaxZ/GRID_CELLSIZE)); +#ifdef __arm__ +#ifdef PANDORA + #define Isinf(a) (((*(unsigned int*)&a)&0x7fffffff)==0x7f800000) +#else + #define Isinf insif +#endif + iMinX = (Isinf(fMinX))?INDEX(GRID_MIN):Clamp(INDEX(floor(fMinX/GRID_CELLSIZE)), (INDEX)GRID_MIN, (INDEX)GRID_MAX); + iMinZ = (Isinf(fMinZ))?INDEX(GRID_MIN):Clamp(INDEX(floor(fMinZ/GRID_CELLSIZE)), (INDEX)GRID_MIN, (INDEX)GRID_MAX); + iMaxX = (Isinf(fMaxX))?INDEX(GRID_MIN):Clamp(INDEX(ceil(fMaxX/GRID_CELLSIZE)), (INDEX)GRID_MIN, (INDEX)GRID_MAX); + iMaxZ = (Isinf(fMaxZ))?INDEX(GRID_MIN):Clamp(INDEX(ceil(fMaxZ/GRID_CELLSIZE)), (INDEX)GRID_MIN, (INDEX)GRID_MAX); +#else + iMinX = INDEX(GRID_MIN):INDEX(floor(fMinX/GRID_CELLSIZE)); + iMinZ = INDEX(GRID_MIN):INDEX(floor(fMinZ/GRID_CELLSIZE)); + iMaxX = INDEX(GRID_MIN):INDEX(ceil(fMaxX/GRID_CELLSIZE)); + iMaxZ = INDEX(GRID_MIN):INDEX(ceil(fMaxZ/GRID_CELLSIZE)); iMinX = Clamp(iMinX, (INDEX)GRID_MIN, (INDEX)GRID_MAX); iMinZ = Clamp(iMinZ, (INDEX)GRID_MIN, (INDEX)GRID_MAX); iMaxX = Clamp(iMaxX, (INDEX)GRID_MIN, (INDEX)GRID_MAX); iMaxZ = Clamp(iMaxZ, (INDEX)GRID_MIN, (INDEX)GRID_MAX); +#endif } // key calculations From ad81a5606a482503c1bc7f26214d34c9ac152bc4 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Mon, 17 Apr 2017 14:52:58 +0200 Subject: [PATCH 11/13] Improvements and fixes to Pandora fast-math --- Sources/CMakeLists.txt | 6 ++++-- Sources/Engine/Terrain/TerrainMisc.cpp | 4 ++-- Sources/Engine/World/WorldCollisionGrid.cpp | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 2e2aef2..142b993 100755 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -90,7 +90,9 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") add_compile_options(-Wall) add_compile_options(-pipe) add_compile_options(-fPIC) - add_compile_options(-march=native) + if(NOT PANDORA) + add_compile_options(-march=native) + endif() add_compile_options(-fno-strict-aliasing) add_definitions(-D_REENTRANT=1) add_definitions(-D_MT=1) @@ -130,7 +132,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") add_compile_options(-Wno-missing-braces) add_compile_options(-Wno-overloaded-virtual) add_compile_options(-Wno-invalid-offsetof) - MESSAGE(WARNING, "re-enable some of the warnings some day!") + #MESSAGE(WARNING, "re-enable some of the warnings some day!") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") # !!! FIXME: turn a bunch of these off, this is just for now. I hope. --ryan. diff --git a/Sources/Engine/Terrain/TerrainMisc.cpp b/Sources/Engine/Terrain/TerrainMisc.cpp index 5b199d4..dbbca58 100755 --- a/Sources/Engine/Terrain/TerrainMisc.cpp +++ b/Sources/Engine/Terrain/TerrainMisc.cpp @@ -310,10 +310,10 @@ Rect ExtractPolygonsInBox(CTerrain *ptrTerrain, const FLOATaabbox3D &bboxExtract if(!bFixSize) { // max vector of bbox in incremented for one, because first vertex is at 0,0,0 in world and in heightmap is at 1,1 #ifdef __arm__ -#ifdef PANDORA +#ifdef PLATFORM_PANDORA #define Isinf(a) (((*(unsigned int*)&a)&0x7fffffff)==0x7f800000) #else - #define Isinf insif + #define Isinf insiff #endif rc.rc_iLeft = (Isinf(bbox.minvect(1)))?(INDEX)0:Clamp((INDEX)(bbox.minvect(1)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapWidth); rc.rc_iTop = (Isinf(bbox.minvect(3)))?(INDEX)0:Clamp((INDEX)(bbox.minvect(3)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapHeight); diff --git a/Sources/Engine/World/WorldCollisionGrid.cpp b/Sources/Engine/World/WorldCollisionGrid.cpp index 1dac910..cd1b6d4 100755 --- a/Sources/Engine/World/WorldCollisionGrid.cpp +++ b/Sources/Engine/World/WorldCollisionGrid.cpp @@ -48,10 +48,10 @@ static inline void BoxToGrid( FLOAT fMaxX = boxEntity.Max()(1); FLOAT fMaxZ = boxEntity.Max()(3); #ifdef __arm__ -#ifdef PANDORA +#ifdef PLATFORM_PANDORA #define Isinf(a) (((*(unsigned int*)&a)&0x7fffffff)==0x7f800000) #else - #define Isinf insif + #define Isinf insiff #endif iMinX = (Isinf(fMinX))?INDEX(GRID_MIN):Clamp(INDEX(floor(fMinX/GRID_CELLSIZE)), (INDEX)GRID_MIN, (INDEX)GRID_MAX); iMinZ = (Isinf(fMinZ))?INDEX(GRID_MIN):Clamp(INDEX(floor(fMinZ/GRID_CELLSIZE)), (INDEX)GRID_MIN, (INDEX)GRID_MAX); From 0731a9d79a673233368d70c7eab034b01ac464be Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Fri, 19 May 2017 23:42:33 +0200 Subject: [PATCH 12/13] More fast-math experiment on Pandora --- Sources/CMakeLists.txt | 55 +++++++++++++-------- Sources/Engine/Terrain/TerrainMisc.cpp | 4 +- Sources/Engine/World/WorldCollisionGrid.cpp | 4 +- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 142b993..6de674a 100755 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -102,11 +102,11 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") ## For C flags set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -D_DEBUG=1 -DDEBUG=1 -O0") if(PANDORA) - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -O3 -ffast-math") - set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 -ffast-math") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 - -faligned-new -ffast-math") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 -faligned-new -ffast-math") set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -Os -ffast-math") else() - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -O3 -fno-unsafe-math-optimizations") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 -fno-unsafe-math-optimizations") set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 -fno-unsafe-math-optimizations") set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -Os -fno-unsafe-math-optimizations") endif() @@ -114,8 +114,8 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") ## For C++ flags set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -D_DEBUG=1 -DDEBUG=1 -O0") if(PANDORA) - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -O3 -ffast-math") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 -ffast-math") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -O3 -faligned-new -ffast-math") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -g -O3 -faligned-new -ffast-math") set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -Os -ffast-math") else() set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -O3 -fno-unsafe-math-optimizations") @@ -716,6 +716,32 @@ if(NOT USE_SYSTEM_ZLIB) Engine/zlib/uncompr.c) endif() +set(ENGINE_SAFEMATH_SRCS + Engine/Brushes/Brush.cpp + Engine/Brushes/BrushPolygon.cpp + Engine/Brushes/BrushSector.cpp + Engine/Entities/Entity.cpp + Engine/Entities/EntityClass.cpp + Engine/Entities/EntityCollision.cpp + Engine/Entities/PlayerCharacter.cpp + Engine/Terrain/TerrainMisc.cpp + Engine/Terrain/TerrainRayCasting.cpp + Engine/World/WorldCSG.cpp + Engine/World/WorldRayCasting.cpp + Engine/World/WorldCollision.cpp + Engine/World/WorldCollisionGrid.cpp + + Engine/Math/Projection_Simple_DOUBLE.cpp + Engine/Math/Geometry_DOUBLE.cpp +) +add_library(engine_safemath STATIC + ${ENGINE_SAFEMATH_SRCS} +) +target_compile_options(engine_safemath PRIVATE "-fno-unsafe-math-optimizations") +if(PANDORA) + target_compile_options(engine_safemath PRIVATE "-mfpu=vfpv3") +endif() + set(ENGINE_SRCS ${ENGINE_ENTITIES_CPP} Engine/Engine.cpp @@ -755,23 +781,16 @@ set(ENGINE_SRCS Engine/Base/SDL/SDLInput.cpp Engine/Base/SDL/SDLEvents.cpp ${SYNCHRO_SRCS} - Engine/Brushes/Brush.cpp Engine/Brushes/BrushIO.cpp Engine/Brushes/BrushShadows.cpp Engine/Brushes/BrushTriangularize.cpp Engine/Brushes/BrushArchive.cpp Engine/Brushes/BrushImport.cpp Engine/Brushes/BrushMip.cpp - Engine/Brushes/BrushPolygon.cpp Engine/Brushes/BrushExport.cpp - Engine/Brushes/BrushSector.cpp - Engine/Entities/Entity.cpp Engine/Entities/NearestPolygon.cpp Engine/Entities/EntityProperties.cpp - Engine/Entities/PlayerCharacter.cpp - Engine/Entities/EntityClass.cpp Engine/Entities/FieldBSPTesting.cpp - Engine/Entities/EntityCollision.cpp Engine/Entities/EntityCopying.cpp Engine/Entities/LastPositions.cpp Engine/Math/Projection_Isometric.cpp @@ -781,14 +800,12 @@ set(ENGINE_SRCS Engine/Math/Float.cpp Engine/Math/Object3D_CSG.cpp Engine/Math/Projection_Simple.cpp - Engine/Math/Projection_Simple_DOUBLE.cpp Engine/Math/Functions.cpp Engine/Math/ObjectSector.cpp Engine/Math/Placement.cpp Engine/Math/TextureMapping.cpp Engine/Math/Geometry.cpp Engine/Math/Projection.cpp - Engine/Math/Geometry_DOUBLE.cpp #Engine/Math/Object3D_IO.cpp # Exploration 3D support. #Engine/Models/EditModel.cpp Engine/Models/Model.cpp @@ -851,8 +868,6 @@ set(ENGINE_SRCS Engine/Terrain/TerrainArchive.cpp Engine/Terrain/TerrainEditing.cpp Engine/Terrain/TerrainLayer.cpp - Engine/Terrain/TerrainMisc.cpp - Engine/Terrain/TerrainRayCasting.cpp Engine/Terrain/TerrainRender.cpp Engine/Terrain/TerrainTile.cpp Engine/Rendering/Render.cpp @@ -887,14 +902,10 @@ set(ENGINE_SRCS Engine/Templates/NameTable_CTFileName.cpp Engine/Templates/NameTable_CTranslationPair.cpp Engine/Templates/BSP.cpp - Engine/World/WorldCSG.cpp Engine/World/PhysicsProfile.cpp - Engine/World/WorldCollision.cpp - Engine/World/WorldIO.cpp - Engine/World/WorldRayCasting.cpp Engine/World/World.cpp - Engine/World/WorldCollisionGrid.cpp Engine/World/WorldEditingProfile.cpp + Engine/World/WorldIO.cpp ${ADDITIONAL_ENGINE_SRCS} ${ZLIB_SRCS} ) @@ -914,10 +925,12 @@ add_executable(ssam SeriousSam/MenuGadgets.cpp SeriousSam/MenuPrinting.cpp ) +target_link_libraries(ssam engine_safemath) add_dependencies(ssam ParseEntities) # Make symbols in the main executable available to dynamic objects set_target_properties(ssam PROPERTIES ENABLE_EXPORTS ON) + # !!! FIXME: this is an option because you have to recompile the entire engine twice. # !!! FIXME: If we can put the engine in a static library and not lose symbols, # !!! FIXME: that's a better plan and we can remove the toggle here. diff --git a/Sources/Engine/Terrain/TerrainMisc.cpp b/Sources/Engine/Terrain/TerrainMisc.cpp index dbbca58..5b199d4 100755 --- a/Sources/Engine/Terrain/TerrainMisc.cpp +++ b/Sources/Engine/Terrain/TerrainMisc.cpp @@ -310,10 +310,10 @@ Rect ExtractPolygonsInBox(CTerrain *ptrTerrain, const FLOATaabbox3D &bboxExtract if(!bFixSize) { // max vector of bbox in incremented for one, because first vertex is at 0,0,0 in world and in heightmap is at 1,1 #ifdef __arm__ -#ifdef PLATFORM_PANDORA +#ifdef PANDORA #define Isinf(a) (((*(unsigned int*)&a)&0x7fffffff)==0x7f800000) #else - #define Isinf insiff + #define Isinf insif #endif rc.rc_iLeft = (Isinf(bbox.minvect(1)))?(INDEX)0:Clamp((INDEX)(bbox.minvect(1)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapWidth); rc.rc_iTop = (Isinf(bbox.minvect(3)))?(INDEX)0:Clamp((INDEX)(bbox.minvect(3)-0),(INDEX)0,ptrTerrain->tr_pixHeightMapHeight); diff --git a/Sources/Engine/World/WorldCollisionGrid.cpp b/Sources/Engine/World/WorldCollisionGrid.cpp index cd1b6d4..1dac910 100755 --- a/Sources/Engine/World/WorldCollisionGrid.cpp +++ b/Sources/Engine/World/WorldCollisionGrid.cpp @@ -48,10 +48,10 @@ static inline void BoxToGrid( FLOAT fMaxX = boxEntity.Max()(1); FLOAT fMaxZ = boxEntity.Max()(3); #ifdef __arm__ -#ifdef PLATFORM_PANDORA +#ifdef PANDORA #define Isinf(a) (((*(unsigned int*)&a)&0x7fffffff)==0x7f800000) #else - #define Isinf insiff + #define Isinf insif #endif iMinX = (Isinf(fMinX))?INDEX(GRID_MIN):Clamp(INDEX(floor(fMinX/GRID_CELLSIZE)), (INDEX)GRID_MIN, (INDEX)GRID_MAX); iMinZ = (Isinf(fMinZ))?INDEX(GRID_MIN):Clamp(INDEX(floor(fMinZ/GRID_CELLSIZE)), (INDEX)GRID_MIN, (INDEX)GRID_MAX); From 4720b55ca5aa95125462da5e7665091804a8b3b1 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 20 May 2017 00:18:13 +0200 Subject: [PATCH 13/13] Need a dependencie on the libengine_safemath --- Sources/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 6de674a..4f26013 100755 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -741,6 +741,7 @@ target_compile_options(engine_safemath PRIVATE "-fno-unsafe-math-optimizations") if(PANDORA) target_compile_options(engine_safemath PRIVATE "-mfpu=vfpv3") endif() +add_dependencies(engine_safemath ParseEntities) set(ENGINE_SRCS ${ENGINE_ENTITIES_CPP}