diff --git a/Engine/lib/convexDecomp/NvThreadConfig.cpp b/Engine/lib/convexDecomp/NvThreadConfig.cpp index 5756bafa8..75d604a84 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__ ) + pthread_yield_np(); #else __asm { pause }; #endif diff --git a/Engine/source/console/codeBlock.cpp b/Engine/source/console/codeBlock.cpp index 9c1ddda17..e7c3d4adb 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 128088827..4e6676d4c 100644 --- a/Engine/source/console/compiler.h +++ b/Engine/source/console/compiler.h @@ -237,7 +237,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/console/consoleInternal.cpp b/Engine/source/console/consoleInternal.cpp index bd8e230ff..05118787b 100644 --- a/Engine/source/console/consoleInternal.cpp +++ b/Engine/source/console/consoleInternal.cpp @@ -1401,7 +1401,7 @@ ConsoleValue Namespace::Entry::execute(S32 argc, ConsoleValue *argv, ExprEvalSta result.setInt(cb.mIntCallbackFunc(state->thisObject, argc, argv)); break; case FloatCallbackType: - result.setFloat(cb.mBoolCallbackFunc(state->thisObject, argc, argv)); + result.setFloat(cb.mFloatCallbackFunc(state->thisObject, argc, argv)); break; case VoidCallbackType: cb.mVoidCallbackFunc(state->thisObject, argc, argv); 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/gui/core/guiCanvas.cpp b/Engine/source/gui/core/guiCanvas.cpp index f50cc0152..7cbea6d64 100644 --- a/Engine/source/gui/core/guiCanvas.cpp +++ b/Engine/source/gui/core/guiCanvas.cpp @@ -1760,7 +1760,11 @@ 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); + // 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." ); } @@ -1772,7 +1776,11 @@ 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); + // 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." ); } 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 } //-------------------------------------- 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; } diff --git a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript index 9f040f1e9..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 @@ -184,6 +191,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; @@ -238,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 d22d847c3..63488c8d7 100644 --- a/Templates/BaseGame/game/data/ui/guis/optionsMenu.tscript +++ b/Templates/BaseGame/game/data/ui/guis/optionsMenu.tscript @@ -627,9 +627,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); 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/template.torsion.in b/Tools/CMake/template.torsion.in index a1eeab78e..93d9d52bf 100644 --- a/Tools/CMake/template.torsion.in +++ b/Tools/CMake/template.torsion.in @@ -1,18 +1,14 @@ @TORQUE_APP_NAME@ -main.cs +main.@TORQUE_SCRIPT_EXTENSION@ dbgSetParameters( #port#, "#password#", true ); core -scripts -art -levels -shaders data tools -cs; gui; taml; module; +@TORQUE_SCRIPT_EXTENSION@; gui; taml; module; Release 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)