From f8ae35f8a504de2058a528fa19aaf8ca75f8e8a6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 27 Sep 2020 10:27:30 +0200 Subject: [PATCH] - macOS backend update, plus moving base64.cpp around. --- source/CMakeLists.txt | 2 +- source/common/2d/v_drawtext.cpp | 2 +- source/common/platform/posix/cocoa/i_main.mm | 31 +++++++---- source/common/platform/posix/cocoa/i_video.mm | 15 ++++-- .../platform/posix/osx/iwadpicker_cocoa.mm | 36 ++++--------- source/common/platform/posix/sdl/i_system.cpp | 53 +++++++++++++++---- source/common/platform/win32/st_start.cpp | 2 + .../src => common/thirdparty}/base64.cpp | 0 .../include => common/thirdparty}/base64.h | 0 9 files changed, 93 insertions(+), 48 deletions(-) rename source/{thirdparty/src => common/thirdparty}/base64.cpp (100%) rename source/{thirdparty/include => common/thirdparty}/base64.h (100%) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 8a7ce61e2..52af19b7b 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -761,7 +761,6 @@ set (PCH_SOURCES glbackend/gl_palmanager.cpp glbackend/gl_texture.cpp - thirdparty/src/base64.cpp thirdparty/src/md4.cpp # Todo: Split out the license-safe code from this. @@ -893,6 +892,7 @@ set (PCH_SOURCES common/utility/zstrformat.cpp common/utility/name.cpp common/utility/r_memory.cpp + common/thirdparty/base64.cpp common/thirdparty/md5.cpp common/thirdparty/superfasthash.cpp common/filesystem/filesystem.cpp diff --git a/source/common/2d/v_drawtext.cpp b/source/common/2d/v_drawtext.cpp index 6a67e6851..539d72a04 100644 --- a/source/common/2d/v_drawtext.cpp +++ b/source/common/2d/v_drawtext.cpp @@ -262,7 +262,7 @@ void DrawTextCommon(F2DDrawer *drawer, FFont *font, int normalcolor, double x, d double scaley = parms.scaley * parms.patchscaley; if (parms.celly == 0) parms.celly = font->GetHeight() + 1; - parms.celly *= scaley; + parms.celly = int (parms.celly * scaley); bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0); diff --git a/source/common/platform/posix/cocoa/i_main.mm b/source/common/platform/posix/cocoa/i_main.mm index f33b206fd..7159d31ea 100644 --- a/source/common/platform/posix/cocoa/i_main.mm +++ b/source/common/platform/posix/cocoa/i_main.mm @@ -101,15 +101,26 @@ void I_DetectOS() const char* name = "Unknown version"; - if (10 == version.majorVersion) switch (version.minorVersion) + if (10 == version.majorVersion) { - case 9: name = "OS X Mavericks"; break; - case 10: name = "OS X Yosemite"; break; - case 11: name = "OS X El Capitan"; break; - case 12: name = "macOS Sierra"; break; - case 13: name = "macOS High Sierra"; break; - case 14: name = "macOS Mojave"; break; - case 15: name = "macOS Catalina"; break; + switch (version.minorVersion) + { + case 9: name = "OS X Mavericks"; break; + case 10: name = "OS X Yosemite"; break; + case 11: name = "OS X El Capitan"; break; + case 12: name = "macOS Sierra"; break; + case 13: name = "macOS High Sierra"; break; + case 14: name = "macOS Mojave"; break; + case 15: name = "macOS Catalina"; break; + case 16: name = "macOS Big Sur"; break; + } + } + else if (11 == version.majorVersion) + { + switch (version.minorVersion) + { + case 0: name = "macOS Big Sur"; break; + } } char release[16] = "unknown"; @@ -124,7 +135,9 @@ void I_DetectOS() #ifdef __i386__ "32-bit Intel"; #elif defined __x86_64__ - "64-bit Intel"; + "64-bit Intel"; +#elif defined __aarch64__ + "64-bit ARM"; #else "Unknown"; #endif diff --git a/source/common/platform/posix/cocoa/i_video.mm b/source/common/platform/posix/cocoa/i_video.mm index a7465cfab..b9b1be72e 100644 --- a/source/common/platform/posix/cocoa/i_video.mm +++ b/source/common/platform/posix/cocoa/i_video.mm @@ -102,6 +102,7 @@ EXTERN_CVAR(Int, vid_preferbackend) EXTERN_CVAR(Bool, vk_debug) CVAR(Bool, mvk_debug, false, 0) +CVAR(Bool, vid_nativefullscreen, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CUSTOM_CVAR(Bool, vid_autoswitch, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) { @@ -290,6 +291,7 @@ CocoaWindow* CreateWindow(const NSUInteger styleMask) [window setOpaque:YES]; [window makeFirstResponder:appCtrl]; [window setAcceptsMouseMovedEvents:YES]; + [window exitAppOnClose]; NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; [nc addObserver:window @@ -633,7 +635,6 @@ void SystemBaseFrameBuffer::SetWindowedMode() const NSRect frameSize = NSMakeRect(win_x, win_y, win_w, win_h); [m_window setFrame:frameSize display:YES]; [m_window enterFullscreenOnZoom]; - [m_window exitAppOnClose]; } void SystemBaseFrameBuffer::SetMode(const bool fullscreen, const bool hiDPI) @@ -650,7 +651,11 @@ void SystemBaseFrameBuffer::SetMode(const bool fullscreen, const bool hiDPI) [m_window.contentView layer].contentsScale = hiDPI ? m_window.screen.backingScaleFactor : 1.0; } - if (fullscreen) + if (vid_nativefullscreen && fullscreen != m_fullscreen) + { + [m_window toggleFullScreen:(nil)]; + } + else if (fullscreen) { SetFullscreenMode(); } @@ -742,7 +747,11 @@ void SystemGLFrameBuffer::SetMode(const bool fullscreen, const bool hiDPI) NSOpenGLView* const glView = [m_window contentView]; [glView setWantsBestResolutionOpenGLSurface:hiDPI]; - if (fullscreen) + if (vid_nativefullscreen && fullscreen != m_fullscreen) + { + [m_window toggleFullScreen:(nil)]; + } + else if (fullscreen) { SetFullscreenMode(); } diff --git a/source/common/platform/posix/osx/iwadpicker_cocoa.mm b/source/common/platform/posix/osx/iwadpicker_cocoa.mm index 8670ec2bd..d751a1edd 100644 --- a/source/common/platform/posix/osx/iwadpicker_cocoa.mm +++ b/source/common/platform/posix/osx/iwadpicker_cocoa.mm @@ -375,6 +375,8 @@ static NSString* GetArchitectureString() return @"i386"; #elif defined __x86_64__ return @"x86_64"; +#elif defined __aarch64__ + return @"arm64"; #endif } @@ -382,13 +384,6 @@ static void RestartWithParameters(const WadStuff& wad, NSString* parameters) { assert(nil != parameters); - defaultiwad = wad.Name; - - GameConfig->ArchiveGlobalData(); - GameConfig->WriteConfigFile(); - delete GameConfig; - GameConfig = nullptr; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @try @@ -396,22 +391,14 @@ static void RestartWithParameters(const WadStuff& wad, NSString* parameters) NSString* executablePath = [NSString stringWithUTF8String:Args->GetArg(0)]; NSMutableArray* const arguments = [[NSMutableArray alloc] init]; - - // The following value shoud be equal to NSAppKitVersionNumber10_5 - // It's hard-coded in order to build with earlier SDKs - const bool canSelectArchitecture = NSAppKitVersionNumber >= 949; - - if (canSelectArchitecture) - { - [arguments addObject:@"-arch"]; - [arguments addObject:GetArchitectureString()]; - [arguments addObject:executablePath]; - - executablePath = @"/usr/bin/arch"; - } - + [arguments addObject:@"-arch"]; + [arguments addObject:GetArchitectureString()]; + [arguments addObject:executablePath]; [arguments addObject:@"-iwad"]; [arguments addObject:[NSString stringWithUTF8String:wad.Path]]; + [arguments addObject:@"+defaultiwad"]; + [arguments addObject:[NSString stringWithUTF8String:wad.Name]]; + [arguments addObject:[NSString stringWithFormat:@"+osx_additional_parameters \"%@\"", parameters]]; for (int i = 1, count = Args->NumArgs(); i < count; ++i) { @@ -433,7 +420,7 @@ static void RestartWithParameters(const WadStuff& wad, NSString* parameters) wordfree(&expansion); } - [NSTask launchedTaskWithLaunchPath:executablePath + [NSTask launchedTaskWithLaunchPath:@"/usr/bin/arch" arguments:arguments]; _exit(0); // to avoid atexit()'s functions @@ -454,11 +441,10 @@ int I_PickIWad_Cocoa (WadStuff *wads, int numwads, bool showwin, int defaultiwad IWADPicker *picker = [IWADPicker alloc]; int ret = [picker pickIWad:wads num:numwads showWindow:showwin defaultWad:defaultiwad]; - NSString* parametersToAppend = [picker commandLineParameters]; - osx_additional_parameters = [parametersToAppend UTF8String]; - if (ret >= 0) { + NSString* parametersToAppend = [picker commandLineParameters]; + if (0 != [parametersToAppend length]) { RestartWithParameters(wads[ret], parametersToAppend); diff --git a/source/common/platform/posix/sdl/i_system.cpp b/source/common/platform/posix/sdl/i_system.cpp index 6e2f3f35d..b3381efad 100644 --- a/source/common/platform/posix/sdl/i_system.cpp +++ b/source/common/platform/posix/sdl/i_system.cpp @@ -54,6 +54,9 @@ #include "m_argv.h" #include "i_sound.h" #include "i_interface.h" +#include "v_font.h" +#include "c_cvars.h" +#include "palutil.h" #ifndef NO_GTK @@ -65,6 +68,8 @@ int I_PickIWad_Cocoa (WadStuff *wads, int numwads, bool showwin, int defaultiwad #endif double PerfToSec, PerfToMillisec; +CVAR(Bool, con_printansi, true, CVAR_GLOBALCONFIG|CVAR_ARCHIVE); +CVAR(Bool, con_4bitansi, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE); void I_SetIWADInfo() { @@ -129,16 +134,47 @@ void CalculateCPUSpeed() void I_PrintStr(const char *cp) { - // Strip out any color escape sequences before writing to debug output - TArray copy(strlen(cp) + 1, true); const char * srcp = cp; - char * dstp = copy.Data(); + FString printData = ""; while (*srcp != 0) { - if (*srcp != 0x1c && *srcp != 0x1d && *srcp != 0x1e && *srcp != 0x1f) + if (*srcp == 0x1c && con_printansi) { - *dstp++ = *srcp++; + srcp += 1; + EColorRange range = V_ParseFontColor((const uint8_t*&)srcp, CR_UNTRANSLATED, CR_YELLOW); + if (range != CR_UNDEFINED) + { + PalEntry color = V_LogColorFromColorRange(range); + if (con_4bitansi) + { + float h, s, v, r, g, b; + int attrib = 0; + + RGBtoHSV(color.r / 255.f, color.g / 255.f, color.b / 255.f, &h, &s, &v); + if (s != 0) + { // color + HSVtoRGB(&r, &g, &b, h, 1, 1); + if (r == 1) attrib = 0x1; + if (g == 1) attrib |= 0x2; + if (b == 1) attrib |= 0x4; + if (v > 0.6) attrib |= 0x8; + } + else + { // gray + if (v < 0.33) attrib = 0x8; + else if (v < 0.90) attrib = 0x7; + else attrib = 0x15; + } + + printData.AppendFormat("\033[%um",((attrib & 0x8) ? 90 : 30) + (attrib & 0x7)); + } + else printData.AppendFormat("\033[38;2;%u;%u;%um",color.r,color.g,color.b); + } + } + else if (*srcp != 0x1c && *srcp != 0x1d && *srcp != 0x1e && *srcp != 0x1f) + { + printData += *srcp++; } else { @@ -146,10 +182,9 @@ void I_PrintStr(const char *cp) else break; } } - *dstp = 0; - - fputs(copy.Data(), stdout); - fflush(stdout); + + fputs(printData.GetChars(),stdout); + fputs("\033[0m",stdout); } int I_PickIWad (WadStuff *wads, int numwads, bool showwin, int defaultiwad) diff --git a/source/common/platform/win32/st_start.cpp b/source/common/platform/win32/st_start.cpp index 32aa3c1c6..f36371a9b 100644 --- a/source/common/platform/win32/st_start.cpp +++ b/source/common/platform/win32/st_start.cpp @@ -52,6 +52,7 @@ #include "printf.h" #include "startupinfo.h" #include "i_interface.h" +#include "texturemanager.h" // MACROS ------------------------------------------------------------------ @@ -607,6 +608,7 @@ int RunEndoom() void ST_Endoom() { + TexMan.DeleteAll(); int code = RunEndoom(); throw CExitEvent(code); diff --git a/source/thirdparty/src/base64.cpp b/source/common/thirdparty/base64.cpp similarity index 100% rename from source/thirdparty/src/base64.cpp rename to source/common/thirdparty/base64.cpp diff --git a/source/thirdparty/include/base64.h b/source/common/thirdparty/base64.h similarity index 100% rename from source/thirdparty/include/base64.h rename to source/common/thirdparty/base64.h