From 9a0de40505db27071ec8b16d92a522b69381a895 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sat, 13 Mar 2021 23:47:18 -0600 Subject: [PATCH 01/10] Updates the torsion.in file to properly be configured to handle tscript extension --- Tools/CMake/template.torsion.in | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Tools/CMake/template.torsion.in b/Tools/CMake/template.torsion.in index a1eeab78e..84e93f36b 100644 --- a/Tools/CMake/template.torsion.in +++ b/Tools/CMake/template.torsion.in @@ -1,18 +1,14 @@ @TORQUE_APP_NAME@ -main.cs +main.tscript dbgSetParameters( #port#, "#password#", true ); core -scripts -art -levels -shaders data tools -cs; gui; taml; module; +cs; gui; taml; module; tscript; Release From e981fd2cc3d92c4e818f008225ec266e47c51292 Mon Sep 17 00:00:00 2001 From: Jeff Hutchinson Date: Sat, 8 May 2021 22:18:45 -0400 Subject: [PATCH 02/10] Add support for aarch64 / apple silicon --- Engine/lib/convexDecomp/NvThreadConfig.cpp | 2 ++ Engine/source/console/codeBlock.cpp | 2 +- Engine/source/console/compiler.cpp | 2 +- Engine/source/console/compiler.h | 2 +- Engine/source/core/util/uuid.cpp | 2 +- Engine/source/platform/types.gcc.h | 5 +++++ Engine/source/platform/types.h | 2 +- Engine/source/platformMac/macMath.mm | 8 ++++++++ 8 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Engine/lib/convexDecomp/NvThreadConfig.cpp b/Engine/lib/convexDecomp/NvThreadConfig.cpp index 5756bafa8..7a1b08750 100644 --- a/Engine/lib/convexDecomp/NvThreadConfig.cpp +++ b/Engine/lib/convexDecomp/NvThreadConfig.cpp @@ -135,6 +135,8 @@ void tc_spinloop() // Pause would do nothing on the Xbox. Threads are not scheduled. #elif defined( _WIN64 ) YieldProcessor( ); + #elif (defined( __arm64__ ) && defined( __APPLE__ )) || defined( __arch64__ ) + asm( "yield" ); #else __asm { pause }; #endif diff --git a/Engine/source/console/codeBlock.cpp b/Engine/source/console/codeBlock.cpp index b4dd6b2c6..ad363dc17 100644 --- a/Engine/source/console/codeBlock.cpp +++ b/Engine/source/console/codeBlock.cpp @@ -447,7 +447,7 @@ bool CodeBlock::read(StringTableEntry fileName, Stream &st) { U32 ip; st.read(&ip); -#ifdef TORQUE_CPU_X64 +#if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64) *(U64*)(code + ip) = (U64)ste; #else code[ip] = *((U32 *)&ste); diff --git a/Engine/source/console/compiler.cpp b/Engine/source/console/compiler.cpp index 073e33ed7..8b1e15a8f 100644 --- a/Engine/source/console/compiler.cpp +++ b/Engine/source/console/compiler.cpp @@ -65,7 +65,7 @@ namespace Compiler void evalSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr) { -#ifdef TORQUE_CPU_X64 +#if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64) *(U64*)(ptr) = (U64)ste; #else *ptr = (U32)ste; diff --git a/Engine/source/console/compiler.h b/Engine/source/console/compiler.h index 26dc93c13..74dd6d2a0 100644 --- a/Engine/source/console/compiler.h +++ b/Engine/source/console/compiler.h @@ -254,7 +254,7 @@ namespace Compiler inline StringTableEntry CodeToSTE(U32 *code, U32 ip) { -#ifdef TORQUE_CPU_X64 +#if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64) return (StringTableEntry)(*((U64*)(code + ip))); #else return (StringTableEntry)(*(code + ip)); diff --git a/Engine/source/core/util/uuid.cpp b/Engine/source/core/util/uuid.cpp index 6eb5c2fda..795a5a7f2 100644 --- a/Engine/source/core/util/uuid.cpp +++ b/Engine/source/core/util/uuid.cpp @@ -70,7 +70,7 @@ #include "core/util/md5.h" #include "console/enginePrimitives.h" -#if defined (TORQUE_OS_MAC) && defined(TORQUE_CPU_X64) +#if defined (TORQUE_OS_MAC) && (defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64)) typedef unsigned int unsigned32; #else typedef unsigned long unsigned32; diff --git a/Engine/source/platform/types.gcc.h b/Engine/source/platform/types.gcc.h index 6f7ad9f08..53538dd8d 100644 --- a/Engine/source/platform/types.gcc.h +++ b/Engine/source/platform/types.gcc.h @@ -120,6 +120,11 @@ typedef unsigned long U64; # define TORQUE_CPU_X64 # define TORQUE_LITTLE_ENDIAN +#elif (defined( __arm64__ ) && defined( __APPLE__ )) || defined( __arch64__ ) +# define TORQUE_CPU_STRING "Arm 64" +# define TORQUE_CPU_ARM64 +# define TORQUE_LITTLE_ENDIAN + #else # error "GCC: Unsupported Target CPU" #endif diff --git a/Engine/source/platform/types.h b/Engine/source/platform/types.h index 96ceb12f0..9acdefae0 100644 --- a/Engine/source/platform/types.h +++ b/Engine/source/platform/types.h @@ -128,7 +128,7 @@ static const F32 F32_MAX = F32(3.402823466e+38F); ///< Constant #endif /// Integral type matching the host's memory address width. -#ifdef TORQUE_CPU_X64 +#if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64) typedef U64 MEM_ADDRESS; #else typedef U32 MEM_ADDRESS; diff --git a/Engine/source/platformMac/macMath.mm b/Engine/source/platformMac/macMath.mm index a59bf6609..542fa27c8 100644 --- a/Engine/source/platformMac/macMath.mm +++ b/Engine/source/platformMac/macMath.mm @@ -34,21 +34,29 @@ static MRandomLCG sgPlatRandom; U32 Platform::getMathControlState() { +#ifdef TORQUE_CPU_X86 U16 cw; asm("fstcw %0" : "=m" (cw) :); return cw; +#else + return 0; +#endif } void Platform::setMathControlState(U32 state) { +#ifdef TORQUE_CPU_X86 U16 cw = state; asm("fldcw %0" : : "m" (cw)); +#endif } void Platform::setMathControlStateKnown() { +#ifdef TORQUE_CPU_X86 U16 cw = 0x27F; asm("fldcw %0" : : "m" (cw)); +#endif } //-------------------------------------- From 61fef8080b6446672f3f0f400a3f9ddb631a9380 Mon Sep 17 00:00:00 2001 From: Jeff Hutchinson Date: Mon, 10 May 2021 16:15:45 -0400 Subject: [PATCH 03/10] mend --- Engine/lib/convexDecomp/NvThreadConfig.cpp | 2 +- Tools/CMake/libraries/lpng.cmake | 5 ++++ Tools/CMake/torque3d.cmake | 30 ++++++++++++++++++---- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Engine/lib/convexDecomp/NvThreadConfig.cpp b/Engine/lib/convexDecomp/NvThreadConfig.cpp index 7a1b08750..75d604a84 100644 --- a/Engine/lib/convexDecomp/NvThreadConfig.cpp +++ b/Engine/lib/convexDecomp/NvThreadConfig.cpp @@ -136,7 +136,7 @@ void tc_spinloop() #elif defined( _WIN64 ) YieldProcessor( ); #elif (defined( __arm64__ ) && defined( __APPLE__ )) || defined( __arch64__ ) - asm( "yield" ); + pthread_yield_np(); #else __asm { pause }; #endif diff --git a/Tools/CMake/libraries/lpng.cmake b/Tools/CMake/libraries/lpng.cmake index 44271904a..93a32a406 100644 --- a/Tools/CMake/libraries/lpng.cmake +++ b/Tools/CMake/libraries/lpng.cmake @@ -24,6 +24,11 @@ project(lpng) # addDef(PNG_NO_ASSEMBLER_CODE) +# Issues with Neon at the moment (Arm support) +# https://sourceforge.net/p/libpng/bugs/281/ +set(PNG_ARM_NEON off CACHE STRING "") +add_definitions(-DPNG_ARM_NEON_OPT=0) + addInclude(${libDir}/zlib) finishLibrary("${libDir}/${PROJECT_NAME}") diff --git a/Tools/CMake/torque3d.cmake b/Tools/CMake/torque3d.cmake index c64a18986..afff2d5c8 100644 --- a/Tools/CMake/torque3d.cmake +++ b/Tools/CMake/torque3d.cmake @@ -692,8 +692,8 @@ if(WIN32) endif() if (APPLE) - addFramework("Cocoa") - addFramework("OpenGL") + addFramework("Cocoa") + addFramework("OpenGL") #These are needed by sdl2 static lib addFramework("CoreAudio") addFramework("AudioUnit") @@ -704,9 +704,29 @@ if (APPLE) addFramework("Carbon") addFramework("AudioToolbox") addLib("iconv") - #set a few arch defaults - set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "OSX Architecture" FORCE) - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "OSX Deployment target" FORCE) +endif() + +#detect Architecture +if (APPLE AND NOT IOS) + option(TORQUE_MACOS_UNIVERSAL_BINARY OFF) + + # Detect architecture if not using universal + if (TORQUE_MACOS_UNIVERSAL_BINARY) + set(ARCHITECTURE_STRING_APPLE "x86_64;arm64") + set(DEPLOYMENT_TARGET_APPLE "10.13") + else() + check_c_compiler_flag("-arch arm64" armSupportedApple) + if(armSupportedApple) + set(ARCHITECTURE_STRING_APPLE "arm64") + set(DEPLOYMENT_TARGET_APPLE "11.0") + else() + set(ARCHITECTURE_STRING_APPLE "x86_64") + set(DEPLOYMENT_TARGET_APPLE "10.9") + endif() + endif() + + set(CMAKE_OSX_ARCHITECTURES ${ARCHITECTURE_STRING_APPLE} CACHE STRING "OSX Architecture" FORCE) + set(CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET_APPLE} CACHE STRING "OSX Deployment target" FORCE) endif() if(UNIX AND NOT APPLE) From 438788c9b3bc4a1e1296d062fcba81e2951cd50a Mon Sep 17 00:00:00 2001 From: Areloch Date: Thu, 13 May 2021 19:30:53 -0500 Subject: [PATCH 04/10] Rolled in Az's suggested fixes --- Tools/CMake/template.torsion.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tools/CMake/template.torsion.in b/Tools/CMake/template.torsion.in index 84e93f36b..93d9d52bf 100644 --- a/Tools/CMake/template.torsion.in +++ b/Tools/CMake/template.torsion.in @@ -1,14 +1,14 @@ @TORQUE_APP_NAME@ -main.tscript +main.@TORQUE_SCRIPT_EXTENSION@ dbgSetParameters( #port#, "#password#", true ); core data tools -cs; gui; taml; module; tscript; +@TORQUE_SCRIPT_EXTENSION@; gui; taml; module; Release From a5c809a7381874d264790e86eb0c4910d497d776 Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Thu, 13 May 2021 20:52:04 -0400 Subject: [PATCH 05/10] Limit fullscreen resolution to options that match the monitor aspect ratio. --- Templates/BaseGame/game/core/gui/scripts/canvas.tscript | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript index 9f040f1e9..efb98b7c4 100644 --- a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript +++ b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript @@ -184,6 +184,12 @@ function GuiCanvas::checkCanvasRes(%this, %mode, %deviceId, %deviceMode, %startu return true; } + else if (%deviceMode == $Video::ModeFullscreen) + { // Fullscreen must match the aspect ratio of the monitor + %deviceRes = getWords(%this.getMonitorRect(%deviceId), 2); + if (mRoundColour(%resX / %resY, 2) != mRoundColour(%deviceRes.x / %deviceRes.y, 2)) + return false; + } if (!%startup) return true; From de1e6df64b7ab6951770cb0989f2683877f395e3 Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Fri, 14 May 2021 03:50:28 -0400 Subject: [PATCH 06/10] Removes redundant ScreenResChangeSignal trigger. --- Engine/source/windowManager/sdl/sdlWindow.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Engine/source/windowManager/sdl/sdlWindow.cpp b/Engine/source/windowManager/sdl/sdlWindow.cpp index 2faccb555..2c725a2d1 100644 --- a/Engine/source/windowManager/sdl/sdlWindow.cpp +++ b/Engine/source/windowManager/sdl/sdlWindow.cpp @@ -207,7 +207,6 @@ void PlatformWindowSDL::_setVideoMode( const GFXVideoMode &mode ) SDL_MaximizeWindow(mWindowHandle); } - getScreenResChangeSignal().trigger(this, true); mSuppressReset = false; } From 1ba7070bb674c82e8032a8d6c8eca2bc83479e7f Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Fri, 14 May 2021 03:52:43 -0400 Subject: [PATCH 07/10] Maintains window position when updating video mode for LightManager compatibility. --- Engine/source/gui/core/guiCanvas.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Engine/source/gui/core/guiCanvas.cpp b/Engine/source/gui/core/guiCanvas.cpp index f50cc0152..abbf10561 100644 --- a/Engine/source/gui/core/guiCanvas.cpp +++ b/Engine/source/gui/core/guiCanvas.cpp @@ -1760,7 +1760,9 @@ void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */) const char *pref = Con::getVariable( "$pref::Video::mode" ); mode.parseFromString( pref ); mode.antialiasLevel = 0; + Point2I winPos = mPlatformWindow->getPosition(); // Save position so we can put window back. mPlatformWindow->setVideoMode(mode); + mPlatformWindow->setPosition(winPos); Con::printf( "AntiAliasing has been disabled; it is not compatible with AdvancedLighting." ); } @@ -1772,7 +1774,9 @@ void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */) if ( prefAA != mode.antialiasLevel ) { mode.parseFromString( pref ); + Point2I winPos = mPlatformWindow->getPosition(); // Save position so we can put window back. mPlatformWindow->setVideoMode(mode); + mPlatformWindow->setPosition(winPos); Con::printf( "AntiAliasing has been enabled while running BasicLighting." ); } From dd665496d1d62fce5f8b5971974f6cdf07696d3e Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Fri, 14 May 2021 03:57:00 -0400 Subject: [PATCH 08/10] Borderless window defaults. Limits borderless windows to the monitor usable area on non windows platforms to prevent the window from rendering behind taskbar/title bars. --- .../BaseGame/game/core/gui/scripts/canvas.tscript | 15 +++++++++++++++ .../rendering/scripts/graphicsOptions.tscript | 7 +++++++ .../game/data/ui/guis/optionsMenu.tscript | 9 +++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript index efb98b7c4..5a22d909a 100644 --- a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript +++ b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript @@ -120,6 +120,13 @@ function configureCanvas() // Actually set the new video mode Canvas.setVideoMode(%resX, %resY, %fs, %bpp, %rate, %aa); + + // For borderless on non-windows OS, move the window into position. + if (($pref::Video::deviceMode == $Video::ModeBorderless) && ($platform !$= "windows")) + { + %borderlessPos = getWords(Canvas.getMonitorUsableRect($pref::Video::deviceId), 0, 1); + Canvas.setWindowPosition(%borderlessPos); + } Canvas.setFocus(); // Lock and unlock the mouse to force the position to sync with the platform window @@ -244,5 +251,13 @@ function GuiCanvas::getBestCanvasRes(%this, %deviceId, %deviceMode) %bestRes = %testRes; } + // Borderless on non-windows OS should be the usable screen area. + if ((%deviceMode == $Video::ModeBorderless) && ($platform !$= "windows")) + { + %deviceRect = getWords(%this.getMonitorUsableRect(%deviceId), 2); + %bestRes = setWord(%bestRes, $WORD::RES_X, %deviceRect.x); + %bestRes = setWord(%bestRes, $WORD::RES_Y, %deviceRect.y); + } + return %bestRes; } diff --git a/Templates/BaseGame/game/core/rendering/scripts/graphicsOptions.tscript b/Templates/BaseGame/game/core/rendering/scripts/graphicsOptions.tscript index 353b9b795..21b5ae9c2 100644 --- a/Templates/BaseGame/game/core/rendering/scripts/graphicsOptions.tscript +++ b/Templates/BaseGame/game/core/rendering/scripts/graphicsOptions.tscript @@ -845,6 +845,13 @@ function getScreenResolutionList(%deviceID, %deviceMode) { %returnsList = ""; + // For borderless on non-windows OS only add the usable area. + if ((%deviceMode == $Video::ModeBorderless) && ($platform !$= "windows")) + { + %borderlessRes = getWords(Canvas.getMonitorUsableRect(%newDeviceID), 2); + return _makePrettyResString(%borderlessRes); + } + %resCount = Canvas.getModeCount(); for (%i = 0; %i < %resCount; %i++) { diff --git a/Templates/BaseGame/game/data/ui/guis/optionsMenu.tscript b/Templates/BaseGame/game/data/ui/guis/optionsMenu.tscript index eba6e173b..416bbe36b 100644 --- a/Templates/BaseGame/game/data/ui/guis/optionsMenu.tscript +++ b/Templates/BaseGame/game/data/ui/guis/optionsMenu.tscript @@ -634,9 +634,14 @@ function onDisplayModeChange(%val) } %resolutionList = getScreenResolutionList(%newDeviceID, %newDeviceMode); - // If we're switching to borderless, default to monitor res if (%newDeviceMode == $Video::ModeBorderless) - %newRes = getWords(Canvas.getMonitorRect(%newDeviceID), 2); + { // If we're switching to borderless, default to monitor res on Windows OS, + // monitor usable area for other platforms. + if ($platform $= "windows") + %newRes = getWords(Canvas.getMonitorRect(%newDeviceID), 2); + else + %newRes = getWords(Canvas.getMonitorUsableRect(%newDeviceID), 2); + } else { // Otherwise, if our old resolution is still in the list, attempt to reset it. %oldRes = getWord(OptionsMenuSettingsList.getCurrentOption(3), 0) SPC getWord(OptionsMenuSettingsList.getCurrentOption(3), 2); From 9539a4a0555a3ae24d64cd2af9e5130d2dd7d00f Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Fri, 14 May 2021 17:30:23 -0400 Subject: [PATCH 09/10] Adds comment explaining window position change in GuiCanvas. --- Engine/source/gui/core/guiCanvas.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Engine/source/gui/core/guiCanvas.cpp b/Engine/source/gui/core/guiCanvas.cpp index abbf10561..7cbea6d64 100644 --- a/Engine/source/gui/core/guiCanvas.cpp +++ b/Engine/source/gui/core/guiCanvas.cpp @@ -1762,6 +1762,8 @@ void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */) mode.antialiasLevel = 0; Point2I winPos = mPlatformWindow->getPosition(); // Save position so we can put window back. mPlatformWindow->setVideoMode(mode); + // setVideoMode (above) will center the window on the display device. If the window had been positioned + // by the user or from script, put it back where it was before the light manager change. mPlatformWindow->setPosition(winPos); Con::printf( "AntiAliasing has been disabled; it is not compatible with AdvancedLighting." ); @@ -1776,6 +1778,8 @@ void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */) mode.parseFromString( pref ); Point2I winPos = mPlatformWindow->getPosition(); // Save position so we can put window back. mPlatformWindow->setVideoMode(mode); + // setVideoMode (above) will center the window on the display device. If the window had been positioned + // by the user or from script, put it back where it was before the light manager change. mPlatformWindow->setPosition(winPos); Con::printf( "AntiAliasing has been enabled while running BasicLighting." ); From 5d1c29f54bef2fc243120249944b4d00f8430f37 Mon Sep 17 00:00:00 2001 From: bank Date: Tue, 15 Jun 2021 19:03:43 +0300 Subject: [PATCH 10/10] Fix return value conversion when using SimObject::call() method from scripts. --- Engine/source/console/consoleInternal.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Engine/source/console/consoleInternal.cpp b/Engine/source/console/consoleInternal.cpp index 420d5a033..1184716ba 100644 --- a/Engine/source/console/consoleInternal.cpp +++ b/Engine/source/console/consoleInternal.cpp @@ -1451,9 +1451,9 @@ ConsoleValueRef Namespace::Entry::execute(S32 argc, ConsoleValueRef *argv, ExprE case StringCallbackType: return ConsoleValueRef::fromValue(CSTK.pushStackString(cb.mStringCallbackFunc(state->thisObject, argc, argv))); case IntCallbackType: - return ConsoleValueRef::fromValue(CSTK.pushUINT((U32)cb.mBoolCallbackFunc(state->thisObject, argc, argv))); + return ConsoleValueRef::fromValue(CSTK.pushUINT((U32)cb.mIntCallbackFunc(state->thisObject, argc, argv))); case FloatCallbackType: - return ConsoleValueRef::fromValue(CSTK.pushFLT((U32)cb.mBoolCallbackFunc(state->thisObject, argc, argv))); + return ConsoleValueRef::fromValue(CSTK.pushFLT((U32)cb.mFloatCallbackFunc(state->thisObject, argc, argv))); case VoidCallbackType: cb.mVoidCallbackFunc(state->thisObject, argc, argv); return ConsoleValueRef();