From 4584bdca78c4840b983fb74e692f1a91b8b352d7 Mon Sep 17 00:00:00 2001 From: Death Killer <884052+deathkiller@users.noreply.github.com> Date: Sat, 30 Nov 2024 23:44:43 +0100 Subject: [PATCH] Reworked menu layout, improved Discord integration, replaced `Interlocked` with `std::atomic` --- Content/Translations/cs.mo | Bin 27301 -> 27424 bytes Content/Translations/cs.po | 8 +- Sources/Jazz2.vcxproj | 3 - Sources/Jazz2.vcxproj.filters | 3 - Sources/Jazz2/IStateHandler.h | 3 + Sources/Jazz2/LevelHandler.cpp | 17 +- Sources/Jazz2/LevelHandler.h | 4 +- Sources/Jazz2/Multiplayer/NetworkManager.cpp | 10 +- Sources/Jazz2/Multiplayer/NetworkManager.h | 2 - Sources/Jazz2/UI/Cinematics.cpp | 5 + Sources/Jazz2/UI/Cinematics.h | 2 + Sources/Jazz2/UI/DiscordRpcClient.cpp | 139 ++++++--- Sources/Jazz2/UI/DiscordRpcClient.h | 19 +- Sources/Jazz2/UI/LoadingHandler.cpp | 5 + Sources/Jazz2/UI/LoadingHandler.h | 2 + Sources/Jazz2/UI/Menu/BeginSection.cpp | 21 +- .../UI/Menu/CreateServerOptionsSection.cpp | 12 +- .../Jazz2/UI/Menu/GameplayOptionsSection.cpp | 7 +- Sources/Jazz2/UI/Menu/HighscoresSection.cpp | 15 +- Sources/Jazz2/UI/Menu/InGameMenu.h | 1 - Sources/Jazz2/UI/Menu/MainMenu.cpp | 15 +- Sources/Jazz2/UI/Menu/MainMenu.h | 6 +- Sources/Main.cpp | 16 +- Sources/Shared/CommonWindows.h | 7 + Sources/Shared/Threading/Event.h | 21 +- .../Threading/Implementation/WaitOnAddress.h | 24 +- Sources/Shared/Threading/Interlocked.h | 294 ------------------ Sources/nCine/Threading/Atomic.h | 160 ---------- Sources/nCine/Threading/GccAtomic.cpp | 169 ---------- Sources/nCine/Threading/StdAtomic.cpp | 163 ---------- Sources/nCine/Threading/WindowsAtomic.cpp | 207 ------------ cmake/ncine_extra_sources.cmake | 15 +- cmake/ncine_headers.cmake | 2 - 33 files changed, 230 insertions(+), 1147 deletions(-) delete mode 100644 Sources/Shared/Threading/Interlocked.h delete mode 100644 Sources/nCine/Threading/Atomic.h delete mode 100644 Sources/nCine/Threading/GccAtomic.cpp delete mode 100644 Sources/nCine/Threading/StdAtomic.cpp delete mode 100644 Sources/nCine/Threading/WindowsAtomic.cpp diff --git a/Content/Translations/cs.mo b/Content/Translations/cs.mo index b947b16079fd3b66b2d11098db001c5651bcad4a..9daa198d9daf7331c93252cb00a563003b7252cf 100644 GIT binary patch delta 5901 zcmYk=34Bdg0>|+avLhmqNC=(~yTlet5Frt3>{~OnJPBDuq9H*I&o-sjmZGSlrDH7` zRizzjYb|4Gs4!}b4yJZhRnw`?@Bi-2bk4{Bea}7b-g}mN?$g?I(PRBL9Qy!b41LM&fN7(IS z(39f{R=dkgrV>tr3)SZ;tbkk55BFguJZyUb8H2fnjMe;#>d>2;=r|b5VFXsj`l$PL zK!5CMI~aY9%NQq>V7|ykjcmH@Z1mxH9@fJ*kV%?-s1DCz5Pplg?h&@cr>Kq^R<$M& ziy<6$!~h(G8fdzte>0AXZcu1D6*c1-s2eTCNL-5z@Q~ep2ctQDijA;NHDfAbU)1#@ zQTNTqnm7s7@k-P{)}u=&?4+V+vK=^L8qGdfEuj7Dnn_|g~L!wG!8Z5Lexy>p*mcST9M6I zmbYXtYNq?Ss|I=kb^a~X{hpv!uB^j)OZ-tQ9EcilWfv9g)|#l@-Uv0rSk#P@F#%Ii z16YH);fJW#?qmD-0O~%6QTI86gRunFQ4GtVfySZE>yDa;YY-LPI1Tme3Q;RC1@%Z~ zp-xki`z3?b@#&+ma+Za~gBw~GZqJ#d;d@7A;*oM(q zf_2fSjST36te?$-Fa+?FHqMth%%-V_QiNyiu^I>`Ox*xuoXHuxvk#+ zAyjxw=1tTMcJrYbl%Q@D!ppDse+VB*=tAA-C^o|Tn1JCl#$YOH!1GZZ?ZIAn7qwDt z_%azMV`KU^2dU_SdwdMQP^P03vXN`dZfuTM?BfdbsvEY#-Z&e(;Mdp`!&nxrOm{wX zeIaTk)?rJ$hB_~}36p6{C5ejO-|47FuopG+n@FFg9*tU&{>Ws_66}tjpjO0#X;U@H z*a8bs?ORYQ@BkArieA$(3!CAYrmVld(2+VwLd|?8s)MhPNtqy~uNlUpzMq3V@D%F$ zPpzK<|Gs6(7F1fx&nOL-7TMV+iY34r8z)wzH3Wq94aYQ0F-@5U1MTFSLCdHSmq7 z0qjICJc-`)Z_ZKi#Y@PmX|AJgSfQ)caXr+tY=Jtj8*2CWLk;L1tbp6G2JXj7cp1y$ zUG%|+sOz8E$J%hNYBcy#3Bo$q5L=@**(eOaRahH0V=X+5I{yJyK@WDKCx)X2Py;o? z4yf}I(HjS&9}YteD5E>;-=9hz4I1%b`-BUqCA)^2;rFN&d5&yw6U_A4GNw1`QT0P@ z-b~a0-?H6{Q5=`p-@m{xjvMwgMiWo$$@=?K89_r$%tm!MA2ssTs2T1+J%VHQ_g654 z<2x9M`aRaJu8rFLLs2WX0)25mY6Xsc;tCv!AE0jd8)}zV?rWVFV;hfpyHZg1abkJB|Cv;@#06G^S!AEE z8nq%DFc7yPKN03L)UJMk&9Mx>Ld6)1{3aQ{{??=HhT1cksOx8;R$>`8!d+NJ@BdXQ zdR9N$Cxi{KHc>1(Xdhx9Pe$EvHEPB7px%;m*bIFJT1(s(wKsZULmY+reh~)aLDWEs zF02kiFCsPmrM$882%dtx9qr+pl<`er@0!bg~h^@dmz z8jBkEBIGB)Y(bYs_Lzz`S8X1oR-!$I;z&%uNyz>)`%rtt`z7m!J+T4D<516hC2IG7 zge~w9*2g-j){>`S498PY*KJ8<{o|+<)6f_L{$S0d9cm!Cs1BDReVa=dj!j>-{ub+j zTB)h1_k16=!)rJms}8f;7hqG4cVjf(Ko;Fp8qWG_0Au(YCJZ+qzY%6XYNTExtPWx^ znd5xa$UjBB_upX?^d4!=xFxpaI1|;;T6ExPRQr8YKaoyrPqcGUSwO=$tccH1Gxr;1 zz2{AA2VpGj)36#Ap_cY6cEX=A2;ey+cs#bp6<7m{ak}3B zAE+=W^Gc>M>=$zpBQYk+TGIZg3tvOMPDii`KESrpGgS2dhAJPCVt38@ zVDa3gyX|!PH&e+y5ycuq$1#7kOwO=i?)?(>|_^+7F))FFMzKdHu}q?R_<3+YYcMnPLD642DsPY&@|g}OOUQllLOF{l;4Y}0B$BsD9kPvlt##tfF@GZC$UJh4lp)W^Y_g1~bhU7Q7V^23=#ALp zZu$Mg&z^wZf)7anDIv88FNeFF zIjWt=FC>$MleMHK`6p>lR2GpxlWW9>P+ac6IF?gOC+pNi8AQ&KP2^3ol9ZO2RJ=(t zNh3cKmA&LQ@{$hh@&PWk>o4N~@;!NEN#Mdv3b`zazoq z?{=GLMVgYsWCwXn))19Sq(50jc9Z!ei-eNOgc58nS{3)_SUz)1QFLg_G8LWUCl=(7 zb_~oM?MTjXW)zJK+wNOoVE$<51T}Xn$embJu9keUAKO`UzR!iK F{{?D%oB;p; delta 5777 zcmYk=33yId9>?*MO(GIYh#+LMhXj#WgEzG$mXwHyl#p6#Um~G&cr8^!inf-{bQnu( zkYZXT9ZO2q;EkiOTT1L^%_m_L}JaZqv_jAsD@4e@q|2_B3OgCQg*z%Q! z`@10THHNLShcWeWw4X6Kw0Bh3USnF`|^uf=uC7#9re1s8L zsSd%WsQt0%jh&tSZsVd+mmR$^5Oc6HPQ@BH+ggB(ZPp|AX!f8kc+mDwVio!qu@+uI zUGHb~M^6TkfvEHAU`^vTCX$BkD8bqZed%|@rq~;qjG2lWa0v$CYSejKF&=lI2Dplv zKnVup1FVVx^_+o2t&Px|@lA{x7>Am1d(?$eFbdPLInJ{CH(@OO9oPc@iPg|I)Hy!{ zb-m^ojGq+%KZd%Y)2Ip*qbl$tw#SF)iLF>b z8Xyk!sFF|<%0yLg0#XdK5W{d?ed@1gb-*5Q4psVF$Uk$JkD3_Rz!rWcN~M7X*bk>{ZJJdfnK~F zlTkCB&Q*1z^HImIM_sQFRk{7Bx8o?P!pBiJdVmmy69Z@GyT+<1g=>5;4 zp&2YdUFZ<%z1K$%XokAbWYi6=MHha8tVj7=6FkPDhnUM*T1?K^^xo zssg2`*S2X4_2(Iw5i~UO704Lo9I7IZkx7~k9F&41Q57jfo%a(TZ83~8Xnz{20&ik> zJcFY#h|$~NEY$w(sOy)urv93FG~a4~>BuC^0n`j{qP~xz9DOhkb%Dd!3B4Fy19n9h z=A#zhUQEC;EPsTQK{q@Zb-i_{O8pQ|{arKyIC?Jj$NG2*HNY+GfDIXiYnfrFO1*|E z=>^pHUer_j6EOnkp(d~ab;H-O5jN*wPBE#NjEmhgbmAG*3DtQ(sze5A@oYq$@V(t1 z!d6X$o~BKQ#X z?9*6DE}Vlp@c^pCf!tjaOhFDc)9@MGg{&`g4^^=+m$L}dkbhZ{|MS>sVR?7|@Ii$0i*m2for;Y3u0 z@~|%Bn@u!yp#!LAcpP=$Wz?#_j=G`Nz3opkhS5*O8aNrf(2c&h2z7pe?XSjA`s+|P z_8~^&DRgUbJ)ofy#jqqBVj@Q3NYn`nF$CA3H||8;z;4tG&!dhj#!7e_Rk3^Mi;po4 zy;7VT&Om)XE`|E5WV!6n4CkUsyc}83W-GE*%r&fy*HNqX3F-!$Q6AX`8{;I@_itbw zJcOEgG5X_u49DM4*0J>VPR2jPo!GS0le2W*=(Rm!K*Z-Onj` zDyjlQQ0Hf(Dl`SPX7aEyE=G;J(oG|f#%8SQ!CyhtogeP+ynbJ!Zb(1;IxZNiU_(@C zTcI9Fd#sO%s0$CZ-%moFpNFc%Qsf0PTTqYGeVc~v(DPa6!hWb3)WWJ5iq$Y0GqDru zf~!!k*EZB~pQ2u?3#jvNU;vh)2Kv?Zg9bR?ha;76n)F8H!d3b zA{%w!9NRyLS_|J`9F`$fG>tQy8_UP;^mm|UbQg7YqqsKRbHiL)4vj9pSw1<1mJP0cyq{VLX*J7NK{N%2r{XX#|Ysgaa9?2z#ND*m4Dz>{cHrUQf=+g7A*t*g< zYCC5!!nPlx)`7O|WD#NUn*C%Q8B8j+bQ&MnP65s&#kOC9dV_Y8-|fB=72}t(BZjaxQA$KO1>v=lYJzG+#}vZTRqLc9T`P@ zh<+x0$@3(SoFxAsTJc^al{_VXA=npXk4S9K#=pwo?w~KlmBBL|!Kgh_+1fXR?CCk&5ji zjc@e)U!$QaXxm11l(+b=T2|55w*45~n^bIVX*?$9$)D`b?$$F_@sVxkTR+F%#KK6}67R1Tus)CjTW5 zH1jCZi#$hyiMDUabkdwOBgy16@n!Z$@UP@=L|a2Lne}TCjbBd diff --git a/Content/Translations/cs.po b/Content/Translations/cs.po index 49fdbcaf..47a87d7d 100644 --- a/Content/Translations/cs.po +++ b/Content/Translations/cs.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: jazz2-resurrection\n" "POT-Creation-Date: 2024-11-30 15:44+0100\n" -"PO-Revision-Date: 2024-11-30 15:46+0100\n" +"PO-Revision-Date: 2024-11-30 23:12+0100\n" "Last-Translator: \n" "Language-Team: Dan R.\n" "Language: cs\n" @@ -1737,7 +1737,7 @@ msgstr "Přepisovat dokončení epizody" #. TRANSLATORS: Menu item in Options > Gameplay section #: Sources/Jazz2/UI/Menu/GameplayOptionsSection.cpp:57 msgid "Discord Integration" -msgstr "Integrace Discordu" +msgstr "Integrace aplikace Discord" #. TRANSLATORS: Menu item in Options > Gameplay section #: Sources/Jazz2/UI/Menu/GameplayOptionsSection.cpp:61 @@ -1902,7 +1902,7 @@ msgstr "Týmová bitva" #. TRANSLATORS: Menu item in Select Game Mode section #: Sources/Jazz2/UI/Menu/MultiplayerGameModeSelectSection.cpp:22 msgid "Capture The Flag" -msgstr "" +msgstr "Boj o vlajku" #. TRANSLATORS: Menu item in Select Game Mode section #: Sources/Jazz2/UI/Menu/MultiplayerGameModeSelectSection.cpp:24 @@ -1917,7 +1917,7 @@ msgstr "Týmový závod" #. TRANSLATORS: Menu item in Select Game Mode section #: Sources/Jazz2/UI/Menu/MultiplayerGameModeSelectSection.cpp:28 msgid "Treasure Hunt" -msgstr "" +msgstr "Lovci pokladů" #. TRANSLATORS: Menu item in Select Game Mode section #: Sources/Jazz2/UI/Menu/MultiplayerGameModeSelectSection.cpp:30 diff --git a/Sources/Jazz2.vcxproj b/Sources/Jazz2.vcxproj index 1f5c5122..cb00cbde 100644 --- a/Sources/Jazz2.vcxproj +++ b/Sources/Jazz2.vcxproj @@ -660,7 +660,6 @@ - @@ -702,7 +701,6 @@ - @@ -1011,7 +1009,6 @@ - diff --git a/Sources/Jazz2.vcxproj.filters b/Sources/Jazz2.vcxproj.filters index 0d06c356..dbda9da7 100644 --- a/Sources/Jazz2.vcxproj.filters +++ b/Sources/Jazz2.vcxproj.filters @@ -1356,9 +1356,6 @@ Header Files\Jazz2\Tiles - - Header Files\Shared\Threading - Header Files\Jazz2\UI\Menu diff --git a/Sources/Jazz2/IStateHandler.h b/Sources/Jazz2/IStateHandler.h index f9e3eee9..ca755093 100644 --- a/Sources/Jazz2/IStateHandler.h +++ b/Sources/Jazz2/IStateHandler.h @@ -2,6 +2,7 @@ #include "../Common.h" #include "../nCine/Input/InputEvents.h" +#include "../nCine/Primitives/Vector2.h" namespace Jazz2 { @@ -14,6 +15,8 @@ namespace Jazz2 IStateHandler(const IStateHandler&) = delete; IStateHandler& operator=(const IStateHandler&) = delete; + virtual nCine::Vector2i GetViewSize() const { return {}; } + virtual void OnBeginFrame() {} virtual void OnEndFrame() {} virtual void OnInitializeViewport(std::int32_t width, std::int32_t height) {} diff --git a/Sources/Jazz2/LevelHandler.cpp b/Sources/Jazz2/LevelHandler.cpp index fa589cf1..1e329bf9 100644 --- a/Sources/Jazz2/LevelHandler.cpp +++ b/Sources/Jazz2/LevelHandler.cpp @@ -1,13 +1,10 @@ #include "LevelHandler.h" #include "PlayerViewport.h" #include "PreferencesCache.h" +#include "UI/DiscordRpcClient.h" #include "UI/HUD.h" #include "../Common.h" -#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || defined(DEATH_TARGET_UNIX) -# include "UI/DiscordRpcClient.h" -#endif - #if defined(WITH_ANGELSCRIPT) # include "Scripting/LevelScriptLoader.h" #endif @@ -452,6 +449,11 @@ namespace Jazz2 } } + Vector2i LevelHandler::GetViewSize() const + { + return _viewSize; + } + void LevelHandler::OnBeginFrame() { ZoneScopedC(0x4876AF); @@ -1446,11 +1448,6 @@ namespace Jazz2 } } - Vector2i LevelHandler::GetViewSize() const - { - return _viewSize; - } - void LevelHandler::BeforeActorDestroyed(Actors::ActorBase* actor) { // Nothing to do here @@ -2021,7 +2018,7 @@ namespace Jazz2 void LevelHandler::UpdateRichPresence() { -#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || defined(DEATH_TARGET_UNIX) +#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || (defined(DEATH_TARGET_UNIX) && !defined(DEATH_TARGET_SWITCH)) if (!PreferencesCache::EnableDiscordIntegration || !UI::DiscordRpcClient::Get().IsSupported()) { return; } diff --git a/Sources/Jazz2/LevelHandler.h b/Sources/Jazz2/LevelHandler.h index a1d1f6e0..3cf997bf 100644 --- a/Sources/Jazz2/LevelHandler.h +++ b/Sources/Jazz2/LevelHandler.h @@ -103,6 +103,8 @@ namespace Jazz2 float GetAmbientLight(Actors::Player* player) const override; void SetAmbientLight(Actors::Player* player, float value) override; + Vector2i GetViewSize() const override; + void OnBeginFrame() override; void OnEndFrame() override; void OnInitializeViewport(std::int32_t width, std::int32_t height) override; @@ -157,8 +159,6 @@ namespace Jazz2 void OnAdvanceDestructibleTileAnimation(std::int32_t tx, std::int32_t ty, std::int32_t amount) override { } void OnTileFrozen(std::int32_t x, std::int32_t y) override; - Vector2i GetViewSize() const; - virtual void AttachComponents(LevelDescriptor&& descriptor); virtual void SpawnPlayers(const LevelInitialization& levelInit); diff --git a/Sources/Jazz2/Multiplayer/NetworkManager.cpp b/Sources/Jazz2/Multiplayer/NetworkManager.cpp index 5d7cbe42..7836584d 100644 --- a/Sources/Jazz2/Multiplayer/NetworkManager.cpp +++ b/Sources/Jazz2/Multiplayer/NetworkManager.cpp @@ -21,15 +21,15 @@ #undef far */ +#include + #include -#include using namespace Death; -using namespace Death::Threading; namespace Jazz2::Multiplayer { - std::int32_t NetworkManager::_initializeCount = 0; + static std::atomic_int32_t _initializeCount{0}; NetworkManager::NetworkManager() : _host(nullptr), _state(NetworkState::None), _handler(nullptr) @@ -190,7 +190,7 @@ namespace Jazz2::Multiplayer void NetworkManager::InitializeBackend() { - if (Interlocked::Increment(&_initializeCount) == 1) { + if (++_initializeCount == 1) { std::int32_t error = enet_initialize(); RETURN_ASSERT_MSG(error == 0, "enet_initialize() failed with error %i", error); } @@ -198,7 +198,7 @@ namespace Jazz2::Multiplayer void NetworkManager::ReleaseBackend() { - if (Interlocked::Decrement(&_initializeCount) == 0) { + if (--_initializeCount == 0) { enet_deinitialize(); } } diff --git a/Sources/Jazz2/Multiplayer/NetworkManager.h b/Sources/Jazz2/Multiplayer/NetworkManager.h index bef5d852..bfc91103 100644 --- a/Sources/Jazz2/Multiplayer/NetworkManager.h +++ b/Sources/Jazz2/Multiplayer/NetworkManager.h @@ -73,8 +73,6 @@ namespace Jazz2::Multiplayer Mutex _lock; std::unique_ptr _discovery; - static std::int32_t _initializeCount; - static void InitializeBackend(); static void ReleaseBackend(); diff --git a/Sources/Jazz2/UI/Cinematics.cpp b/Sources/Jazz2/UI/Cinematics.cpp index 9d70467f..ed86af55 100644 --- a/Sources/Jazz2/UI/Cinematics.cpp +++ b/Sources/Jazz2/UI/Cinematics.cpp @@ -28,6 +28,11 @@ namespace Jazz2::UI _canvas->setParent(nullptr); } + Vector2i Cinematics::GetViewSize() const + { + return _upscalePass.GetViewSize(); + } + void Cinematics::OnBeginFrame() { float timeMult = theApplication().GetTimeMult(); diff --git a/Sources/Jazz2/UI/Cinematics.h b/Sources/Jazz2/UI/Cinematics.h index ac63c3a7..9aa6833d 100644 --- a/Sources/Jazz2/UI/Cinematics.h +++ b/Sources/Jazz2/UI/Cinematics.h @@ -30,6 +30,8 @@ namespace Jazz2::UI Cinematics(IRootController* root, const StringView path, Function&& callback); ~Cinematics() override; + Vector2i GetViewSize() const override; + void OnBeginFrame() override; void OnInitializeViewport(std::int32_t width, std::int32_t height) override; diff --git a/Sources/Jazz2/UI/DiscordRpcClient.cpp b/Sources/Jazz2/UI/DiscordRpcClient.cpp index 25108aed..1b2fc081 100644 --- a/Sources/Jazz2/UI/DiscordRpcClient.cpp +++ b/Sources/Jazz2/UI/DiscordRpcClient.cpp @@ -1,19 +1,24 @@ #include "DiscordRpcClient.h" -#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || defined(DEATH_TARGET_UNIX) +#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || (defined(DEATH_TARGET_UNIX) && !defined(DEATH_TARGET_SWITCH)) #include "../../nCine/Base/Algorithms.h" +#define SIMDJSON_EXCEPTIONS 0 +#include "../../simdjson/simdjson.h" + +#include + #if defined(DEATH_TARGET_UNIX) # include # include # include #endif -#include - using namespace Death::Containers::Literals; -using namespace Death::Threading; + +using namespace simdjson; +using namespace std::string_view_literals; namespace Jazz2::UI { @@ -26,11 +31,11 @@ namespace Jazz2::UI DiscordRpcClient::DiscordRpcClient() : #if defined(DEATH_TARGET_WINDOWS) - _hPipe(NULL), _hEventRead(NULL), _hEventWrite(NULL), + _hPipe(INVALID_HANDLE_VALUE), _hEventRead(NULL), _hEventWrite(NULL), #else _sockFd(-1), #endif - _nonce(0) + _nonce(0), _userId(0) { } @@ -46,7 +51,7 @@ namespace Jazz2::UI } #if defined(DEATH_TARGET_WINDOWS) - if (_hPipe != NULL) { + if (_hPipe != INVALID_HANDLE_VALUE) { return true; } @@ -54,15 +59,14 @@ namespace Jazz2::UI for (std::int32_t i = 0; i < 10; i++) { swprintf_s(pipeName, L"\\\\.\\pipe\\discord-ipc-%i", i); - _hPipe = CreateFile(pipeName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, + _hPipe = ::CreateFile(pipeName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); - if (_hPipe != NULL && _hPipe != INVALID_HANDLE_VALUE) { + if (_hPipe != INVALID_HANDLE_VALUE) { break; } } - if (_hPipe == NULL || _hPipe == INVALID_HANDLE_VALUE) { - _hPipe = NULL; + if (_hPipe == INVALID_HANDLE_VALUE) { return false; } @@ -133,8 +137,8 @@ namespace Jazz2::UI void DiscordRpcClient::Disconnect() { #if defined(DEATH_TARGET_WINDOWS) - HANDLE pipe = Interlocked::Exchange(&_hPipe, NULL); - if (pipe != NULL) { + HANDLE pipe = _hPipe.exchange(INVALID_HANDLE_VALUE); + if (pipe != INVALID_HANDLE_VALUE) { ::CancelIoEx(pipe, NULL); ::CloseHandle(pipe); _thread.Join(); @@ -148,7 +152,7 @@ namespace Jazz2::UI _hEventWrite = NULL; } #else - int32_t sockFd = Interlocked::Exchange(&_sockFd, -1); + std::int32_t sockFd = _sockFd.exchange(-1); if (sockFd >= 0) { _thread.Abort(); ::close(sockFd); @@ -159,12 +163,22 @@ namespace Jazz2::UI bool DiscordRpcClient::IsSupported() const { #if defined(DEATH_TARGET_WINDOWS) - return (_hPipe != nullptr); + return (_hPipe != INVALID_HANDLE_VALUE); #else return (_sockFd >= 0); #endif } + std::uint64_t DiscordRpcClient::GetUserId() const + { + return _userId; + } + + StringView DiscordRpcClient::GetUserDisplayName() const + { + return _userDisplayName; + } + bool DiscordRpcClient::SetRichPresence(const RichPresence& richPresence) { #if defined(DEATH_TARGET_WINDOWS) @@ -233,6 +247,27 @@ namespace Jazz2::UI return true; } + void DiscordRpcClient::ProcessInboundFrame(const char* json, std::size_t length, std::size_t allocated) + { + LOGD("%s", String(json, length).data()); + + ondemand::parser parser; + ondemand::document doc; + if (parser.iterate(json, length, allocated).get(doc) == SUCCESS) { + std::string_view cmd; + ondemand::object data; + if (doc["cmd"].get(cmd) == SUCCESS && cmd == "DISPATCH"sv && doc["data"].get(data) == SUCCESS) { + ondemand::object user; // {"id":"123456789","username":"nick.name","discriminator":"0","global_name":"Display Name","avatar":"123456789abcdef","avatar_decoration_data":null,"bot":false,"flags":32,"premium_type":0} + std::string_view userId, userGlobalName; + if (data["user"].get(user) == SUCCESS && user["id"].get(userId) == SUCCESS && user["global_name"].get(userGlobalName) == SUCCESS) { + _userId = stou64(userId.data(), userId.size()); + _userDisplayName = userGlobalName; + LOGD("Connected to Discord as user \"%s\" (%llu)", _userDisplayName.data(), _userId); + } + } + } + } + bool DiscordRpcClient::WriteFrame(Opcodes opcode, const char* buffer, std::uint32_t bufferSize) { char frameHeader[8]; @@ -241,7 +276,8 @@ namespace Jazz2::UI #if defined(DEATH_TARGET_WINDOWS) DWORD bytesWritten = 0; - return ::WriteFile(_hPipe, frameHeader, sizeof(frameHeader), &bytesWritten, NULL) && ::WriteFile(_hPipe, buffer, bufferSize, &bytesWritten, NULL); + return ::WriteFile(_hPipe, frameHeader, sizeof(frameHeader), &bytesWritten, NULL) && + ::WriteFile(_hPipe, buffer, bufferSize, &bytesWritten, NULL); #else if (::write(_sockFd, frameHeader, sizeof(frameHeader)) < 0) { return false; @@ -261,34 +297,35 @@ namespace Jazz2::UI void DiscordRpcClient::OnBackgroundThread(void* args) { - DiscordRpcClient* client = static_cast(args); + DiscordRpcClient* _this = static_cast(args); // Handshake char buffer[2048]; - std::int32_t bufferSize = formatString(buffer, sizeof(buffer), "{\"v\":1,\"client_id\":\"%s\"}", client->_clientId.data()); - client->WriteFrame(Opcodes::Handshake, buffer, bufferSize); + std::int32_t bufferSize = formatString(buffer, sizeof(buffer), "{\"v\":1,\"client_id\":\"%s\"}", _this->_clientId.data()); + _this->WriteFrame(Opcodes::Handshake, buffer, bufferSize); #if defined(DEATH_TARGET_WINDOWS) - DWORD bytesRead = 0; - OVERLAPPED ov = { }; - ov.hEvent = client->_hEventRead; - if (!::ReadFile(client->_hPipe, buffer, sizeof(buffer), &bytesRead, &ov)) { + HANDLE hPipe = _this->_hPipe; + OVERLAPPED ov = {}; + ov.hEvent = _this->_hEventRead; + if (!::ReadFile(hPipe, buffer, sizeof(buffer), NULL, &ov)) { DWORD error = ::GetLastError(); if (error == ERROR_BROKEN_PIPE) { - HANDLE pipe = Interlocked::Exchange(&client->_hPipe, NULL); - if (pipe != NULL) { - ::CloseHandle(client->_hPipe); + _this->_hPipe = INVALID_HANDLE_VALUE; + if (hPipe != INVALID_HANDLE_VALUE) { + ::CloseHandle(hPipe); } return; } } - HANDLE waitHandles[] = { client->_hEventRead, client->_hEventWrite }; - while (client->_hPipe != NULL) { + HANDLE waitHandles[] = { _this->_hEventRead, _this->_hEventWrite }; + while (_this->_hPipe != INVALID_HANDLE_VALUE) { DWORD dwEvent = ::WaitForMultipleObjects(static_cast(arraySize(waitHandles)), waitHandles, FALSE, INFINITE); switch (dwEvent) { case WAIT_OBJECT_0: { - if (bytesRead > 0) { + DWORD bytesRead; + if (::GetOverlappedResult(hPipe, &ov, &bytesRead, FALSE) && bytesRead > 0) { Opcodes opcode = (Opcodes)*(std::uint32_t*)&buffer[0]; std::uint32_t frameSize = *(std::uint32_t*)&buffer[4]; if (frameSize >= sizeof(buffer)) { @@ -296,16 +333,20 @@ namespace Jazz2::UI } switch (opcode) { - case Opcodes::Handshake: + case Opcodes::Handshake: // Invalid response opcode case Opcodes::Close: { - HANDLE pipe = Interlocked::Exchange(&client->_hPipe, NULL); - if (pipe != NULL) { - ::CloseHandle(client->_hPipe); + _this->_hPipe = INVALID_HANDLE_VALUE; + if (hPipe != INVALID_HANDLE_VALUE) { + ::CloseHandle(hPipe); } return; } case Opcodes::Ping: { - client->WriteFrame(Opcodes::Pong, &buffer[8], frameSize); + _this->WriteFrame(Opcodes::Pong, &buffer[8], frameSize); + break; + } + case Opcodes::Frame: { + _this->ProcessInboundFrame(&buffer[8], frameSize, sizeof(buffer) - 8); break; } } @@ -315,12 +356,12 @@ namespace Jazz2::UI //} } - if (!::ReadFile(client->_hPipe, buffer, sizeof(buffer), &bytesRead, &ov)) { + if (!::ReadFile(hPipe, buffer, sizeof(buffer), NULL, &ov)) { DWORD error = ::GetLastError(); if (error == ERROR_BROKEN_PIPE) { - HANDLE pipe = Interlocked::Exchange(&client->_hPipe, NULL); - if (pipe != NULL) { - ::CloseHandle(client->_hPipe); + _this->_hPipe = INVALID_HANDLE_VALUE; + if (hPipe != INVALID_HANDLE_VALUE) { + ::CloseHandle(hPipe); } return; } @@ -328,22 +369,21 @@ namespace Jazz2::UI break; } case WAIT_OBJECT_0 + 1: { - if (!client->_pendingFrame.empty()) { - client->WriteFrame(Opcodes::Frame, client->_pendingFrame.data(), client->_pendingFrame.size()); - client->_pendingFrame = { }; + if (!_this->_pendingFrame.empty()) { + _this->WriteFrame(Opcodes::Frame, _this->_pendingFrame.data(), _this->_pendingFrame.size()); + _this->_pendingFrame = {}; } break; } } } #else - while (client->_sockFd >= 0) { - std::int32_t bytesRead = ::read(client->_sockFd, buffer, sizeof(buffer)); + while (_this->_sockFd >= 0) { + std::int32_t bytesRead = ::read(_this->_sockFd, buffer, sizeof(buffer)); if (bytesRead <= 0) { LOGE("Failed to read from socket: %i", bytesRead); - std::int32_t sockFd = client->_sockFd; + std::int32_t sockFd = _this->_sockFd.exchange(-1); if (sockFd >= 0) { - client->_sockFd = -1; ::close(sockFd); } break; @@ -358,15 +398,18 @@ namespace Jazz2::UI switch (opcode) { case Opcodes::Handshake: case Opcodes::Close: { - std::int32_t sockFd = client->_sockFd; + std::int32_t sockFd = _this->_sockFd.exchange(-1); if (sockFd >= 0) { - client->_sockFd = -1; ::close(sockFd); } return; } case Opcodes::Ping: { - client->WriteFrame(Opcodes::Pong, &buffer[8], frameSize); + _this->WriteFrame(Opcodes::Pong, &buffer[8], frameSize); + break; + } + case Opcodes::Frame: { + _this->ProcessInboundFrame(&buffer[8], frameSize, sizeof(buffer) - 8); break; } } diff --git a/Sources/Jazz2/UI/DiscordRpcClient.h b/Sources/Jazz2/UI/DiscordRpcClient.h index a49c968d..9af5f42e 100644 --- a/Sources/Jazz2/UI/DiscordRpcClient.h +++ b/Sources/Jazz2/UI/DiscordRpcClient.h @@ -2,10 +2,12 @@ #include "../../Common.h" -#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || defined(DEATH_TARGET_UNIX) +#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || (defined(DEATH_TARGET_UNIX) && !defined(DEATH_TARGET_SWITCH)) #include "../../nCine/Threading/Thread.h" +#include + #include #include #include @@ -34,6 +36,8 @@ namespace Jazz2::UI bool Connect(const StringView clientId); void Disconnect(); bool IsSupported() const; + std::uint64_t GetUserId() const; + StringView GetUserDisplayName() const; bool SetRichPresence(const RichPresence& richPresence); static DiscordRpcClient& Get(); @@ -50,18 +54,21 @@ namespace Jazz2::UI Pong }; -#if defined(DEATH_TARGET_WINDOWS) - HANDLE _hPipe; +# if defined(DEATH_TARGET_WINDOWS) + std::atomic _hPipe; HANDLE _hEventRead; HANDLE _hEventWrite; String _pendingFrame; -#else - std::int32_t _sockFd; -#endif +# else + std::atomic_int32_t _sockFd; +# endif Thread _thread; std::int32_t _nonce; String _clientId; + std::uint64_t _userId; + String _userDisplayName; + void ProcessInboundFrame(const char* json, std::size_t length, std::size_t allocated); bool WriteFrame(Opcodes opcode, const char* buffer, std::uint32_t bufferSize); static void OnBackgroundThread(void* args); diff --git a/Sources/Jazz2/UI/LoadingHandler.cpp b/Sources/Jazz2/UI/LoadingHandler.cpp index c1e14490..21659850 100644 --- a/Sources/Jazz2/UI/LoadingHandler.cpp +++ b/Sources/Jazz2/UI/LoadingHandler.cpp @@ -24,6 +24,11 @@ namespace Jazz2::UI _canvasBackground->setParent(nullptr); } + Vector2i LoadingHandler::GetViewSize() const + { + return _upscalePass.GetViewSize(); + } + void LoadingHandler::OnBeginFrame() { if (_callback && _callback(_root)) { diff --git a/Sources/Jazz2/UI/LoadingHandler.h b/Sources/Jazz2/UI/LoadingHandler.h index b14a1d12..ce38b77c 100644 --- a/Sources/Jazz2/UI/LoadingHandler.h +++ b/Sources/Jazz2/UI/LoadingHandler.h @@ -18,6 +18,8 @@ namespace Jazz2::UI LoadingHandler(IRootController* root, Function&& callback); ~LoadingHandler() override; + Vector2i GetViewSize() const override; + void OnBeginFrame() override; void OnInitializeViewport(std::int32_t width, std::int32_t height) override; diff --git a/Sources/Jazz2/UI/Menu/BeginSection.cpp b/Sources/Jazz2/UI/Menu/BeginSection.cpp index b2ddc418..d1511c6c 100644 --- a/Sources/Jazz2/UI/Menu/BeginSection.cpp +++ b/Sources/Jazz2/UI/Menu/BeginSection.cpp @@ -183,7 +183,7 @@ namespace Jazz2::UI::Menu _skipSecondItem = canGrantPermission && !permissionGranted; std::int32_t itemCount = (std::int32_t)_items.size(); - float baseReduction = (canvas->ViewSize.Y >= 300 ? -32.0f : -20.0f); + float baseReduction = (canvas->ViewSize.Y >= 300 ? 10.0f : 24.0f); if (!_isPlayable) { itemCount += 2; @@ -191,21 +191,18 @@ namespace Jazz2::UI::Menu } Recti contentBounds = _root->GetContentBounds(); - Vector2f center = Vector2f(contentBounds.X + contentBounds.W * 0.5f, contentBounds.Y + baseReduction + contentBounds.H * 0.3f * (1.0f - 0.048f * itemCount)); - if (contentBounds.H < 230) { - center.Y *= 0.85f; - } + Vector2f center = Vector2f(contentBounds.X + contentBounds.W * 0.5f, contentBounds.Y + baseReduction + (0.2f * (float)canvas->ViewSize.Y / itemCount)); std::int32_t charOffset = 0; #if !defined(DEATH_TARGET_EMSCRIPTEN) if (!_isPlayable) { - if (_selectedIndex == 0) { - _root->DrawElement(MenuGlow, 0, center.X, center.Y * 0.96f - 30.0f, IMenuContainer::MainLayer, Alignment::Center, Colorf(1.0f, 1.0f, 1.0f, 0.16f), 26.0f, 12.0f, true, true); - } - # if defined(DEATH_TARGET_ANDROID) if (permissionGranted) { + if (_selectedIndex == 0) { + _root->DrawElement(MenuGlow, 0, center.X, center.Y * 0.96f - 14.0f, IMenuContainer::MainLayer, Alignment::Center, Colorf(1.0f, 1.0f, 1.0f, 0.16f), 26.0f, 12.0f, true, true); + } + _root->DrawStringShadow(_("Access to external storage has been granted!"), charOffset, center.X, center.Y * 0.96f - 20.0f, IMenuContainer::FontLayer, Alignment::Bottom, Colorf(0.2f, 0.45f, 0.2f, 0.5f), 1.0f, 0.7f, 0.4f, 0.4f, 0.4f, 0.8f, 1.2f); _root->DrawStringShadow(_("\f[c:#337233]Restart the game to read \f[c:#9e7056]Jazz Jackrabbit 2\f[c:#337233] files correctly."), charOffset, center.X, center.Y * 0.96f, IMenuContainer::FontLayer, @@ -213,6 +210,10 @@ namespace Jazz2::UI::Menu } else # endif { + if (_selectedIndex == 0) { + _root->DrawElement(MenuGlow, 0, center.X, center.Y * 0.96f - 26.0f, IMenuContainer::MainLayer, Alignment::Center, Colorf(1.0f, 1.0f, 1.0f, 0.16f), 26.0f, 12.0f, true, true); + } + _root->DrawStringShadow(_("\f[c:#704a4a]This game requires original \f[c:#9e7056]Jazz Jackrabbit 2\f[c:#704a4a] files!"), charOffset, center.X, center.Y - 40.0f, IMenuContainer::FontLayer, Alignment::Bottom, Font::DefaultColor, 1.0f, 0.7f, 0.4f, 0.4f, 0.4f, 0.8f, 1.2f); _root->DrawStringShadow(_("Make sure Jazz Jackrabbit 2 files are present in following path:"), charOffset, center.X, center.Y - 20.0f, IMenuContainer::FontLayer, @@ -274,7 +275,7 @@ namespace Jazz2::UI::Menu Alignment::Center, Font::DefaultColor, 0.9f); } - center.Y += (contentBounds.H >= 260 ? 36.0f : 28.0f) + 32.0f * (1.0f - 0.15f * itemCount); + center.Y += 6.0f + (0.54f * (float)canvas->ViewSize.Y / itemCount); } } diff --git a/Sources/Jazz2/UI/Menu/CreateServerOptionsSection.cpp b/Sources/Jazz2/UI/Menu/CreateServerOptionsSection.cpp index b5040067..34443fd3 100644 --- a/Sources/Jazz2/UI/Menu/CreateServerOptionsSection.cpp +++ b/Sources/Jazz2/UI/Menu/CreateServerOptionsSection.cpp @@ -212,12 +212,12 @@ namespace Jazz2::UI::Menu } else if (i == 1) { StringView gameModeString; switch (_gameMode) { - case MultiplayerGameMode::Battle: gameModeString = "Battle"_s; break; - case MultiplayerGameMode::TeamBattle: gameModeString = "Team Battle"_s; break; - case MultiplayerGameMode::CaptureTheFlag: gameModeString = "Capture The Flag"_s; break; - case MultiplayerGameMode::Race: gameModeString = "Race"_s; break; - case MultiplayerGameMode::TreasureHunt: gameModeString = "Treasure Hunt"_s; break; - case MultiplayerGameMode::Cooperation: gameModeString = "Cooperation"_s; break; + case MultiplayerGameMode::Battle: gameModeString = _("Battle"); break; + case MultiplayerGameMode::TeamBattle: gameModeString = _("Team Battle"); break; + case MultiplayerGameMode::CaptureTheFlag: gameModeString = _("Capture The Flag"); break; + case MultiplayerGameMode::Race: gameModeString = _("Race"); break; + case MultiplayerGameMode::TreasureHunt: gameModeString = _("Treasure Hunt"); break; + case MultiplayerGameMode::Cooperation: gameModeString = _("Cooperation"); break; } _root->DrawStringShadow(gameModeString, charOffset, center.X, center.Y + 28.0f, IMenuContainer::FontLayer, diff --git a/Sources/Jazz2/UI/Menu/GameplayOptionsSection.cpp b/Sources/Jazz2/UI/Menu/GameplayOptionsSection.cpp index 72637f3f..41afb400 100644 --- a/Sources/Jazz2/UI/Menu/GameplayOptionsSection.cpp +++ b/Sources/Jazz2/UI/Menu/GameplayOptionsSection.cpp @@ -4,13 +4,10 @@ #include "GameplayEnhancementsSection.h" #include "LanguageSelectSection.h" #include "RefreshCacheSection.h" +#include "../DiscordRpcClient.h" #include "../RgbLights.h" #include "../../PreferencesCache.h" -#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || defined(DEATH_TARGET_UNIX) -# include "../DiscordRpcClient.h" -#endif - #include using namespace Jazz2::UI::Menu::Resources; @@ -206,7 +203,7 @@ namespace Jazz2::UI::Menu _animation = 0.0f; break; } -#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || defined(DEATH_TARGET_UNIX) +#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || (defined(DEATH_TARGET_UNIX) && !defined(DEATH_TARGET_SWITCH)) case GameplayOptionsItemType::EnableDiscordIntegration: { PreferencesCache::EnableDiscordIntegration = !PreferencesCache::EnableDiscordIntegration; if (!PreferencesCache::EnableDiscordIntegration) { diff --git a/Sources/Jazz2/UI/Menu/HighscoresSection.cpp b/Sources/Jazz2/UI/Menu/HighscoresSection.cpp index 328b78c6..a55e8a79 100644 --- a/Sources/Jazz2/UI/Menu/HighscoresSection.cpp +++ b/Sources/Jazz2/UI/Menu/HighscoresSection.cpp @@ -1,5 +1,6 @@ #include "HighscoresSection.h" #include "MenuResources.h" +#include "../DiscordRpcClient.h" #include "../../../nCine/Application.h" @@ -33,7 +34,17 @@ namespace Jazz2::UI::Menu if (seriesIndex >= 0 && seriesIndex < (std::int32_t)SeriesName::Count) { _selectedSeries = seriesIndex; - String name = TryGetDefaultName(); + String name; + std::uint64_t id = 0; +#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || (defined(DEATH_TARGET_UNIX) && !defined(DEATH_TARGET_SWITCH)) + if (PreferencesCache::EnableDiscordIntegration && DiscordRpcClient::Get().IsSupported()) { + name = DiscordRpcClient::Get().GetUserDisplayName(); + id = DiscordRpcClient::Get().GetUserId(); + } +#endif + if (name.empty()) { + name = TryGetDefaultName(); + } if (name.size() > MaxNameLength) { auto [_, prevChar] = Utf8::PrevChar(name, MaxNameLength); name = name.prefix(prevChar); @@ -44,7 +55,7 @@ namespace Jazz2::UI::Menu if (cheatsUsed) flags |= HighscoreFlags::CheatsUsed; // TODO: PlayerId is unused - AddItemAndFocus(HighscoreItem { std::move(name), 0, flags, itemToAdd.Type, difficulty, itemToAdd.Lives, itemToAdd.Score, + AddItemAndFocus(HighscoreItem { std::move(name), id, flags, itemToAdd.Type, difficulty, itemToAdd.Lives, itemToAdd.Score, { itemToAdd.Gems[0], itemToAdd.Gems[1], itemToAdd.Gems[2], itemToAdd.Gems[3] }, DateTime::UtcNow().ToUnixMilliseconds(), elapsedMilliseconds }); } } diff --git a/Sources/Jazz2/UI/Menu/InGameMenu.h b/Sources/Jazz2/UI/Menu/InGameMenu.h index 5f2ed8a5..84b3e349 100644 --- a/Sources/Jazz2/UI/Menu/InGameMenu.h +++ b/Sources/Jazz2/UI/Menu/InGameMenu.h @@ -2,7 +2,6 @@ #include "IMenuContainer.h" #include "MenuSection.h" -#include "../../IStateHandler.h" #include "../../LevelHandler.h" #include "../Canvas.h" #include "../../ContentResolver.h" diff --git a/Sources/Jazz2/UI/Menu/MainMenu.cpp b/Sources/Jazz2/UI/Menu/MainMenu.cpp index db6a102a..3ed22145 100644 --- a/Sources/Jazz2/UI/Menu/MainMenu.cpp +++ b/Sources/Jazz2/UI/Menu/MainMenu.cpp @@ -3,13 +3,10 @@ #include "../../ContentResolver.h" #include "../../PreferencesCache.h" #include "../ControlScheme.h" +#include "../DiscordRpcClient.h" #include "BeginSection.h" #include "FirstRunSection.h" -#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || defined(DEATH_TARGET_UNIX) -# include "../DiscordRpcClient.h" -#endif - #include "../../../nCine/Application.h" #include "../../../nCine/Graphics/RenderQueue.h" #include "../../../nCine/Audio/AudioReaderMpt.h" @@ -98,6 +95,11 @@ namespace Jazz2::UI::Menu SwitchToSection(); } + Vector2i MainMenu::GetViewSize() const + { + return _upscalePass.GetViewSize(); + } + void MainMenu::OnBeginFrame() { float timeMult = theApplication().GetTimeMult(); @@ -233,7 +235,8 @@ namespace Jazz2::UI::Menu std::int32_t charOffset = 0; std::int32_t charOffsetShadow = 0; - float titleY = _owner->_contentBounds.Y - (ViewSize.Y > 330 ? 30.0f : (ViewSize.Y >= 300 ? 50.0f : 12.0f)); + float titleY = _owner->_contentBounds.Y - (ViewSize.Y >= 300 ? 30.0f : 12.0f); + //titleY = _owner->_contentBounds.Y - (/*ViewSize.Y > 330 ? 30.0f :*/ (ViewSize.Y >= 300 ? 50.0f : 12.0f)); float logoBaseScale = (ViewSize.Y >= 300 ? 1.0f : 0.85f); float logoScale = logoBaseScale + (1.0f - _owner->_logoTransition) * 7.0f; float logoTextScale = logoBaseScale + (1.0f - _owner->_logoTransition) * 2.0f; @@ -632,7 +635,7 @@ namespace Jazz2::UI::Menu void MainMenu::UpdateRichPresence() { -#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || defined(DEATH_TARGET_UNIX) +#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || (defined(DEATH_TARGET_UNIX) && !defined(DEATH_TARGET_SWITCH)) if (!PreferencesCache::EnableDiscordIntegration || !DiscordRpcClient::Get().IsSupported()) { return; } diff --git a/Sources/Jazz2/UI/Menu/MainMenu.h b/Sources/Jazz2/UI/Menu/MainMenu.h index ac273297..7db71365 100644 --- a/Sources/Jazz2/UI/Menu/MainMenu.h +++ b/Sources/Jazz2/UI/Menu/MainMenu.h @@ -43,6 +43,8 @@ namespace Jazz2::UI::Menu void Reset(); + Vector2i GetViewSize() const override; + void OnBeginFrame() override; void OnInitializeViewport(std::int32_t width, std::int32_t height) override; @@ -65,10 +67,6 @@ namespace Jazz2::UI::Menu bool ActionPressed(PlayerActions action) override; bool ActionHit(PlayerActions action) override; - Vector2i GetViewSize() const override { - return _canvasBackground->ViewSize; - } - Recti GetContentBounds() const override { return _contentBounds; } diff --git a/Sources/Main.cpp b/Sources/Main.cpp index 89b9991d..8c1c9b51 100644 --- a/Sources/Main.cpp +++ b/Sources/Main.cpp @@ -26,6 +26,7 @@ #include "Jazz2/PreferencesCache.h" #include "Jazz2/UI/Cinematics.h" #include "Jazz2/UI/ControlScheme.h" +#include "Jazz2/UI/DiscordRpcClient.h" #include "Jazz2/UI/LoadingHandler.h" #include "Jazz2/UI/Menu/MainMenu.h" #include "Jazz2/UI/Menu/HighscoresSection.h" @@ -52,10 +53,6 @@ using namespace Jazz2::Multiplayer; # include "TermLogo.h" #endif -#if (defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)) || defined(DEATH_TARGET_UNIX) -# include "Jazz2/UI/DiscordRpcClient.h" -#endif - #if defined(DEATH_TARGET_WINDOWS) && !defined(WITH_QT5) # include // for `__argc` and `__argv` #endif @@ -340,8 +337,13 @@ void GameEventHandler::OnInitialize() })); #endif + Vector2i viewSize; + if (_currentHandler != nullptr) { + viewSize = _currentHandler->GetViewSize(); + } + Vector2i res = theApplication().GetResolution(); - LOGI("Rendering resolution: %ix%i", res.X, res.Y); + LOGI("Rendering resolution: %ix%i (%ix%i)", res.X, res.Y, viewSize.X, viewSize.Y); } void GameEventHandler::OnBeginFrame() @@ -369,15 +371,17 @@ void GameEventHandler::OnResizeWindow(std::int32_t width, std::int32_t height) // Resolution was changed, all viewports have to be recreated Viewport::chain().clear(); + Vector2i viewSize; if (_currentHandler != nullptr) { _currentHandler->OnInitializeViewport(width, height); + viewSize = _currentHandler->GetViewSize(); } #if defined(NCINE_HAS_WINDOWS) PreferencesCache::EnableFullscreen = theApplication().GetGfxDevice().isFullscreen(); #endif - LOGI("Rendering resolution: %ix%i", width, height); + LOGI("Rendering resolution: %ix%i (%ix%i)", width, height, viewSize.X, viewSize.Y); } void GameEventHandler::OnShutdown() diff --git a/Sources/Shared/CommonWindows.h b/Sources/Shared/CommonWindows.h index c7862f0c..eda0de99 100644 --- a/Sources/Shared/CommonWindows.h +++ b/Sources/Shared/CommonWindows.h @@ -55,6 +55,13 @@ DEATH_ALWAYS_INLINE BOOL WINAPI CreateDirectory(LPCWSTR lpPathName, LPSECURITY_A } #endif +#if defined(CreateEvent) +# undef CreateEvent +DEATH_ALWAYS_INLINE HANDLE WINAPI CreateEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCWSTR lpName) { + return ::CreateEventW(lpEventAttributes, bManualReset, bInitialState, lpName); +} +#endif + #if defined(CreateFile) # undef CreateFile DEATH_ALWAYS_INLINE HANDLE WINAPI CreateFile(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { diff --git a/Sources/Shared/Threading/Event.h b/Sources/Shared/Threading/Event.h index 401e8631..35551636 100644 --- a/Sources/Shared/Threading/Event.h +++ b/Sources/Shared/Threading/Event.h @@ -2,9 +2,10 @@ #include "../Common.h" #include "../Environment.h" -#include "Interlocked.h" #include "Implementation/WaitOnAddress.h" +#include + #if defined(DEATH_TARGET_APPLE) # include #endif @@ -23,7 +24,7 @@ namespace Death { namespace Threading { { public: Event(bool isSignaled = false) noexcept - : _isSignaled(isSignaled ? 1L : 0L) + : _isSignaled(isSignaled ? 1 : 0) { if DEATH_LIKELY(Implementation::IsWaitOnAddressSupported()) { Implementation::InitializeWaitOnAddress(); @@ -60,10 +61,10 @@ namespace Death { namespace Threading { { bool result; if DEATH_LIKELY(Implementation::IsWaitOnAddressSupported()) { - result = !!Interlocked::Exchange(&_isSignaled, 0L); + result = !!_isSignaled.exchange(0); } else { #if defined(DEATH_TARGET_WINDOWS) - result = !!Interlocked::Exchange(&_isSignaled, 0L); + result = !!_isSignaled.exchange(0); ::ResetEvent(_fallbackEvent); #elif !defined(__DEATH_ALWAYS_USE_WAKEONADDRESS) pthread_mutex_lock(&_mutex); @@ -81,7 +82,7 @@ namespace Death { namespace Threading { { if DEATH_LIKELY(Implementation::IsWaitOnAddressSupported()) { // FYI: 'WakeByAddress*' invokes a full memory barrier - Interlocked::WriteRelease(&_isSignaled, 1L); + _isSignaled.store(1, std::memory_order_release); #pragma warning(suppress: 4127) // Conditional expression is constant if constexpr (Type == EventType::AutoReset) { @@ -91,11 +92,11 @@ namespace Death { namespace Threading { } } else { #if defined(DEATH_TARGET_WINDOWS) - Interlocked::WriteRelease(&_isSignaled, 1L); + _isSignaled.store(1, std::memory_order_release); ::SetEvent(_fallbackEvent); #elif !defined(__DEATH_ALWAYS_USE_WAKEONADDRESS) pthread_mutex_lock(&_mutex); - _isSignaled = 1L; + _isSignaled.store(1, std::memory_order_relaxed); if constexpr (Type == EventType::AutoReset) { pthread_cond_signal(&_cond); } else { @@ -110,7 +111,7 @@ namespace Death { namespace Threading { // Note: Unlike Win32 auto-reset event objects, this will not reset the event bool IsSignaled() const noexcept { - return !!Interlocked::ReadAcquire(&_isSignaled); + return !!_isSignaled.load(std::memory_order_acquire); } bool Wait(std::uint32_t timeoutMilliseconds) noexcept @@ -166,7 +167,7 @@ namespace Death { namespace Threading { bool WaitForSignal(std::uint32_t timeoutMilliseconds) noexcept { if DEATH_LIKELY(Implementation::IsWaitOnAddressSupported()) { - return Implementation::WaitOnAddress(_isSignaled, 0L, timeoutMilliseconds); + return Implementation::WaitOnAddress(_isSignaled, 0, timeoutMilliseconds); } else { #if defined(DEATH_TARGET_WINDOWS) return (::WaitForSingleObject(_fallbackEvent, timeoutMilliseconds) == WAIT_OBJECT_0); @@ -205,7 +206,7 @@ namespace Death { namespace Threading { } } - long _isSignaled; + std::atomic_int32_t _isSignaled; #if defined(DEATH_TARGET_WINDOWS) HANDLE _fallbackEvent; #elif !defined(__DEATH_ALWAYS_USE_WAKEONADDRESS) diff --git a/Sources/Shared/Threading/Implementation/WaitOnAddress.h b/Sources/Shared/Threading/Implementation/WaitOnAddress.h index d897032b..324f1fc5 100644 --- a/Sources/Shared/Threading/Implementation/WaitOnAddress.h +++ b/Sources/Shared/Threading/Implementation/WaitOnAddress.h @@ -3,6 +3,8 @@ #include "../../CommonWindows.h" #include "../../Asserts.h" +#include + #if defined(DEATH_TARGET_WINDOWS) # include "../../Environment.h" #elif defined(DEATH_TARGET_APPLE) @@ -54,6 +56,16 @@ extern "C" namespace Death { namespace Threading { namespace Implementation { //###==##====#=====--==~--~=~- --- -- - - - - + template + struct RemoveAtomic { + using type = T; + }; + + template + struct RemoveAtomic> { + using type = T; + }; + #if defined(DEATH_TARGET_WINDOWS) using WaitOnAddressDelegate = decltype(::WaitOnAddress); using WakeByAddressAllDelegate = decltype(::WakeByAddressAll); @@ -68,7 +80,7 @@ namespace Death { namespace Threading { namespace Implementation { void InitializeWaitOnAddress(); template - inline bool WaitOnAddress(T& futex, T expectedValue, std::uint32_t timeoutMilliseconds) + inline bool WaitOnAddress(T& futex, typename RemoveAtomic::type expectedValue, std::uint32_t timeoutMilliseconds) { BOOL waitResult = _waitOnAddress(&futex, &expectedValue, sizeof(T), timeoutMilliseconds); DEATH_DEBUG_ASSERT(waitResult || ::GetLastError() == ERROR_TIMEOUT); @@ -113,7 +125,7 @@ namespace Death { namespace Threading { namespace Implementation { } template - inline bool WaitOnAddress(T& futex, T expectedValue, std::uint32_t timeoutMilliseconds) + inline bool WaitOnAddress(T& futex, typename RemoveAtomic::type expectedValue, std::uint32_t timeoutMilliseconds) { // Source code inspection shows __ulock_wait2 uses nanoseconds for timeout std::uint64_t timeoutNanoseconds = (timeoutMilliseconds == Infinite ? UINT64_MAX : (timeoutMilliseconds * 1000000ull)); @@ -147,7 +159,7 @@ namespace Death { namespace Threading { namespace Implementation { } template - inline int WaitOnAddressInner(T& futex, T expectedValue, _umtx_time* tmp = nullptr) + inline int WaitOnAddressInner(T& futex, typename RemoveAtomic::type expectedValue, _umtx_time* tmp = nullptr) { // FreeBSD UMTX_OP_WAIT does not apply acquire or release memory barriers int op = UMTX_OP_WAIT_UINT_PRIVATE; @@ -161,7 +173,7 @@ namespace Death { namespace Threading { namespace Implementation { } template - inline bool WaitOnAddress(T& futex, T expectedValue, std::uint32_t timeoutMilliseconds) + inline bool WaitOnAddress(T& futex, typename RemoveAtomic::type expectedValue, std::uint32_t timeoutMilliseconds) { if (timeoutMilliseconds == Infinite) { int r = WaitOnAddressInner(futex, expectedValue); @@ -229,7 +241,7 @@ namespace Death { namespace Threading { namespace Implementation { } template - inline bool WaitOnAddress(T& futex, T expectedValue, std::uint32_t timeoutMilliseconds) + inline bool WaitOnAddress(T& futex, typename RemoveAtomic::type expectedValue, std::uint32_t timeoutMilliseconds) { if (timeoutMilliseconds == Infinite) { long r = FutexOp(GetFutexAddress(&futex), FUTEX_WAIT, (std::uintptr_t)expectedValue); @@ -274,7 +286,7 @@ namespace Death { namespace Threading { namespace Implementation { } template - inline bool WaitOnAddress(T& futex, T expectedValue, std::uint32_t timeoutMilliseconds) + inline bool WaitOnAddress(T& futex, typename RemoveAtomic::type expectedValue, std::uint32_t timeoutMilliseconds) { return false; } diff --git a/Sources/Shared/Threading/Interlocked.h b/Sources/Shared/Threading/Interlocked.h deleted file mode 100644 index c958673c..00000000 --- a/Sources/Shared/Threading/Interlocked.h +++ /dev/null @@ -1,294 +0,0 @@ -#pragma once - -#include "../Common.h" - -#if defined(DEATH_TARGET_MSVC) -# include -#endif - -namespace Death { namespace Threading { -//###==##====#=====--==~--~=~- --- -- - - - - - - /** - @brief Provides atomic operations for variables that are shared by multiple threads - */ - class Interlocked - { - public: - Interlocked() = delete; - ~Interlocked() = delete; - - /** - * @brief Reads the value of the specified 32/64-bit variable as an atomic operation with acquire semantics - * @param source Variable to be read - * @return The resulting value - */ - template - static T ReadAcquire(T volatile* source); - - /** - * @brief Writes the value to the specified 32/64-bit variable as an atomic operation with release semantics - * @param destination Variable to be written - * @param value New value - */ - template - static void WriteRelease(T volatile* destination, T value); - - /** - * @brief Increments the value of the specified 32/64-bit variable as an atomic operation - * @param addend Variable to be incremented - * @return The resulting incremented value - */ - template - static T Increment(T volatile* addend); - - /** - * @brief Decrements the value of the specified 32/64-bit variable as an atomic operation - * @param addend Variable to be decremented - * @return The resulting decremented value - */ - template - static T Decrement(T volatile* addend); - - /** - * @brief Performs an atomic AND operation on the values of the specified 32/64-bit variables - * @param destination The first operand and the destination - * @param value The second operand - * @return The resulting value - */ - template - static T And(T volatile* destination, T value); - - /** - * @brief Performs an atomic OR operation on the values of the specified 32/64-bit variables - * @param destination The first operand and the destination - * @param value The second operand - * @return The resulting value - */ - template - static T Or(T volatile* destination, T value); - - /** - * @brief Exchanges a 32/64-bit variable to the specified value as an atomic operation - * @param destination Value to be exchanged - * @param value Value to set the destination to - * @return The previous value of the destination - */ - template - static T Exchange(T volatile* destination, T value); - - /** @overload */ - template::value>::type> - static T Exchange(T volatile* destination, U); - - /** - * @brief Performs an atomic exchange and addition of two 32/64-bit values - * @param addend Variable to be added to - * @param value Value to add - * @return The previous value of the destination - */ - template - static T ExchangeAdd(T volatile* addend, T value); - - /** - * @brief Performs an atomic compare-and-exchange operation on the specified 32/64-bit variables - * @param destination Value to be exchanged - * @param exchange Value to set the destination to - * @param comparand Value to compare the destination to before setting it to the exchange, the destination is set only if the destination is equal to the comparand - * @return The original value of the destination - */ - template - static T CompareExchange(T volatile* destination, T exchange, T comparand); - - private: -#if !defined(DEATH_TARGET_MSVC) - static void InterlockedOperationBarrier(); -#endif - }; - - template - DEATH_ALWAYS_INLINE T Interlocked::ReadAcquire(T volatile* source) - { -#if defined(DEATH_TARGET_MSVC) - if constexpr (sizeof(T) == sizeof(LONG)) { - return (T)::ReadAcquire((LONG*)source); - } else if constexpr (sizeof(T) == sizeof(LONG64)) { - return (T)::ReadAcquire64((LONG64*)source); - } else { - static_assert(sizeof(T) == sizeof(LONG) || sizeof(T) == sizeof(LONG64), "Size of T must be 32-bit or 64-bit"); - } -#else - return __atomic_load_n(source, __ATOMIC_ACQUIRE); -#endif - } - - template - DEATH_ALWAYS_INLINE void Interlocked::WriteRelease(T volatile* destination, T value) - { -#if defined(DEATH_TARGET_MSVC) - if constexpr (sizeof(T) == sizeof(LONG)) { - ::WriteRelease((LONG*)destination, (LONG)value); - } else if constexpr (sizeof(T) == sizeof(LONG64)) { - ::WriteRelease64((LONG64*)destination, (LONG64)value); - } else { - static_assert(sizeof(T) == sizeof(LONG) || sizeof(T) == sizeof(LONG64), "Size of T must be 32-bit or 64-bit"); - } -#else - __atomic_store_n(destination, value, __ATOMIC_RELEASE); -#endif - } - - template - DEATH_ALWAYS_INLINE T Interlocked::Increment(T volatile* addend) - { -#if defined(DEATH_TARGET_MSVC) - if constexpr (sizeof(T) == sizeof(LONG)) { - return (T)_InterlockedIncrement((LONG*)addend); - } else if constexpr (sizeof(T) == sizeof(LONG64)) { - return (T)_InterlockedIncrement64((LONG64*)addend); - } else { - static_assert(sizeof(T) == sizeof(LONG) || sizeof(T) == sizeof(LONG64), "Size of T must be 32-bit or 64-bit"); - } -#else - T result = __sync_add_and_fetch(addend, 1); - InterlockedOperationBarrier(); - return result; -#endif - } - - template - DEATH_ALWAYS_INLINE T Interlocked::Decrement(T volatile* addend) - { -#if defined(DEATH_TARGET_MSVC) - if constexpr (sizeof(T) == sizeof(LONG)) { - return (T)_InterlockedDecrement((LONG*)addend); - } else if constexpr (sizeof(T) == sizeof(LONG64)) { - return (T)_InterlockedDecrement64((LONG64*)addend); - } else { - static_assert(sizeof(T) == sizeof(LONG) || sizeof(T) == sizeof(LONG64), "Size of T must be 32-bit or 64-bit"); - } -#else - T result = __sync_sub_and_fetch(addend, 1); - InterlockedOperationBarrier(); - return result; -#endif - } - - template - DEATH_ALWAYS_INLINE T Interlocked::Exchange(T volatile* destination, T value) - { -#if defined(DEATH_TARGET_MSVC) - if constexpr (sizeof(T) == sizeof(LONG)) { - return (T)_InterlockedExchange((LONG*)destination, (LONG)value); - } else if constexpr (sizeof(T) == sizeof(LONG64)) { - return (T)_InterlockedExchange64((LONG64*)destination, (LONG64)value); - } else { - static_assert(sizeof(T) == sizeof(LONG) || sizeof(T) == sizeof(LONG64), "Size of T must be 32-bit or 64-bit"); - } -#else - T result = __atomic_exchange_n(destination, value, __ATOMIC_ACQ_REL); - InterlockedOperationBarrier(); - return result; -#endif - } - - template - DEATH_ALWAYS_INLINE T Interlocked::Exchange(T volatile* destination, U) - { -#if defined(DEATH_TARGET_MSVC) - if constexpr (sizeof(T) == sizeof(LONG)) { - return (T)_InterlockedExchange((LONG*)destination, {}); - } else if constexpr (sizeof(T) == sizeof(LONG64)) { - return (T)_InterlockedExchange64((LONG64*)destination, {}); - } else { - static_assert(sizeof(T) == sizeof(LONG) || sizeof(T) == sizeof(LONG64), "Size of T must be 32-bit or 64-bit"); - } -#else - T result = __atomic_exchange_n(destination, {}, __ATOMIC_ACQ_REL); - InterlockedOperationBarrier(); - return result; -#endif - } - - template - DEATH_ALWAYS_INLINE T Interlocked::CompareExchange(T volatile* destination, T exchange, T comparand) - { -#if defined(DEATH_TARGET_MSVC) - if constexpr (sizeof(T) == sizeof(LONG)) { - return (T)_InterlockedCompareExchange((LONG*)destination, (LONG)exchange, (LONG)comparand); - } else if constexpr (sizeof(T) == sizeof(LONG64)) { - return (T)_InterlockedCompareExchange64((LONG64*)destination, (LONG64)exchange, (LONG64)comparand); - } else { - static_assert(sizeof(T) == sizeof(LONG) || sizeof(T) == sizeof(LONG64), "Size of T must be 32-bit or 64-bit"); - } -#else - T result = __sync_val_compare_and_swap(destination, comparand, exchange); - InterlockedOperationBarrier(); - return result; -#endif - } - - template - DEATH_ALWAYS_INLINE T Interlocked::ExchangeAdd(T volatile* addend, T value) - { -#if defined(DEATH_TARGET_MSVC) - if constexpr (sizeof(T) == sizeof(LONG)) { - return (T)_InterlockedExchangeAdd((LONG*)addend, (LONG)value); - } else if constexpr (sizeof(T) == sizeof(LONG64)) { - return (T)_InterlockedExchangeAdd64((LONG64*)addend, (LONG64)value); - } else { - static_assert(sizeof(T) == sizeof(LONG) || sizeof(T) == sizeof(LONG64), "Size of T must be 32-bit or 64-bit"); - } -#else - T result = __sync_fetch_and_add(addend, value); - InterlockedOperationBarrier(); - return result; -#endif - } - - template - DEATH_ALWAYS_INLINE T Interlocked::And(T volatile* destination, T value) - { -#if defined(DEATH_TARGET_MSVC) - if constexpr (sizeof(T) == sizeof(LONG)) { - return (T)_InterlockedAnd((LONG*)destination, (LONG)value); - } else if constexpr (sizeof(T) == sizeof(LONG64)) { - return (T)_InterlockedAnd64((LONG64*)destination, (LONG64)value); - } else { - static_assert(sizeof(T) == sizeof(LONG) || sizeof(T) == sizeof(LONG64), "Size of T must be 32-bit or 64-bit"); - } -#else - T result = __sync_and_and_fetch(destination, value); - InterlockedOperationBarrier(); - return result; -#endif - } - - template - DEATH_ALWAYS_INLINE T Interlocked::Or(T volatile* destination, T value) - { -#if defined(DEATH_TARGET_MSVC) - if constexpr (sizeof(T) == sizeof(LONG)) { - return (T)_InterlockedOr((LONG*)destination, (LONG)value); - } else if constexpr (sizeof(T) == sizeof(LONG64)) { - return (T)_InterlockedOr64((LONG64*)destination, (LONG64)value); - } else { - static_assert(sizeof(T) == sizeof(LONG) || sizeof(T) == sizeof(LONG64), "Size of T must be 32-bit or 64-bit"); - } -#else - T result = __sync_or_and_fetch(destination, value); - InterlockedOperationBarrier(); - return result; -#endif - } - -#if !defined(DEATH_TARGET_MSVC) - DEATH_ALWAYS_INLINE void Interlocked::InterlockedOperationBarrier() - { -# if defined(DEATH_TARGET_ARM) || defined(DEATH_TARGET_RISCV) - __sync_synchronize(); -# endif - } -#endif - -}} \ No newline at end of file diff --git a/Sources/nCine/Threading/Atomic.h b/Sources/nCine/Threading/Atomic.h deleted file mode 100644 index b19dce95..00000000 --- a/Sources/nCine/Threading/Atomic.h +++ /dev/null @@ -1,160 +0,0 @@ -#pragma once - -#include - -#if defined(DEATH_TARGET_APPLE) -# include -#endif - -namespace nCine -{ - /// An atomic `int32_t` class - class Atomic32 - { - public: - enum class MemoryModel { - RELAXED, - ACQUIRE, - RELEASE, - SEQ_CST - }; - - Atomic32() : value_(0) {} - explicit Atomic32(int32_t value) : value_(value) {} - ~Atomic32() = default; - - int32_t load(MemoryModel memModel); - inline int32_t load() { - return load(MemoryModel::SEQ_CST); - } - void store(int32_t value, MemoryModel memModel); - inline void store(int32_t value) { - store(value, MemoryModel::SEQ_CST); - } - - int32_t fetchAdd(int32_t value, MemoryModel memModel); - inline int32_t fetchAdd(int32_t value) { - return fetchAdd(value, MemoryModel::SEQ_CST); - } - int32_t fetchSub(int32_t value, MemoryModel memModel); - inline int32_t fetchSub(int32_t value) { - return fetchSub(value, MemoryModel::SEQ_CST); - } - bool cmpExchange(int32_t newValue, int32_t cmpValue, MemoryModel memModel); - inline bool cmpExchange(int32_t newValue, int32_t cmpValue) { - return cmpExchange(newValue, cmpValue, MemoryModel::SEQ_CST); - } - - int32_t operator=(int32_t value) - { - store(value); - return value_; - } - - operator int32_t() { - return load(); - } - - inline int32_t operator++() { - return fetchAdd(1) + 1; - } - inline int32_t operator++(int) { - return fetchAdd(1); - } - inline int32_t operator--() { - return fetchSub(1) - 1; - } - inline int32_t operator--(int) { - return fetchSub(1); - } - - private: -#if defined(DEATH_TARGET_APPLE) - std::atomic value_; -#else - int32_t value_; -#endif - - /// Deleted copy constructor - Atomic32(const Atomic32&) = delete; - /// Deleted move constructor - Atomic32(Atomic32&&) = delete; - /// Deleted assignment operator - Atomic32& operator=(const Atomic32&) = delete; - }; - - /// An atomic `int64_t` class - class Atomic64 - { - public: - enum class MemoryModel { - RELAXED, - ACQUIRE, - RELEASE, - SEQ_CST - }; - - Atomic64() : value_(0) {} - explicit Atomic64(int64_t value) : value_(value) {} - ~Atomic64() = default; - - int64_t load(MemoryModel memModel); - inline int64_t load() { - return load(MemoryModel::SEQ_CST); - } - void store(int64_t value, MemoryModel memModel); - inline void store(int64_t value) { - store(value, MemoryModel::SEQ_CST); - } - - int64_t fetchAdd(int64_t value, MemoryModel memModel); - inline int64_t fetchAdd(int64_t value) { - return fetchAdd(value, MemoryModel::SEQ_CST); - } - int64_t fetchSub(int64_t value, MemoryModel memModel); - inline int64_t fetchSub(int64_t value) { - return fetchSub(value, MemoryModel::SEQ_CST); - } - bool cmpExchange(int64_t newValue, int64_t cmpValue, MemoryModel memModel); - inline bool cmpExchange(int64_t newValue, int64_t cmpValue) { - return cmpExchange(newValue, cmpValue, MemoryModel::SEQ_CST); - } - - inline int64_t operator=(int64_t value) - { - store(value); - return value_; - } - - operator int64_t() { - return load(); - } - - inline int64_t operator++() { - return fetchAdd(1) + 1; - } - inline int64_t operator++(int) { - return fetchAdd(1); - } - inline int64_t operator--() { - return fetchSub(1) - 1; - } - inline int64_t operator--(int) { - return fetchSub(1); - } - - private: -#if defined(DEATH_TARGET_APPLE) - std::atomic value_; -#else - int64_t value_; -#endif - - /// Deleted copy constructor - Atomic64(const Atomic64&) = delete; - /// Deleted move constructor - Atomic64(Atomic64&&) = delete; - /// Deleted assignment operator - Atomic64& operator=(const Atomic64&) = delete; - }; -} diff --git a/Sources/nCine/Threading/GccAtomic.cpp b/Sources/nCine/Threading/GccAtomic.cpp deleted file mode 100644 index cdfacab9..00000000 --- a/Sources/nCine/Threading/GccAtomic.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#include "Atomic.h" -#include "../../Common.h" - -namespace nCine -{ - int32_t Atomic32::load(MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - __atomic_load_n(&value_, __ATOMIC_RELAXED); - return value_; - case MemoryModel::ACQUIRE: - __atomic_load_n(&value_, __ATOMIC_ACQUIRE); - return value_; - case MemoryModel::RELEASE: - FATAL_MSG("Incompatible memory model"); - return 0; - case MemoryModel::SEQ_CST: - default: - __atomic_load_n(&value_, __ATOMIC_SEQ_CST); - return value_; - } - } - - void Atomic32::store(int32_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - __atomic_store_n(&value_, value, __ATOMIC_RELAXED); - break; - case MemoryModel::ACQUIRE: - FATAL_MSG("Incompatible memory model"); - break; - case MemoryModel::RELEASE: - __atomic_store_n(&value_, value, __ATOMIC_RELEASE); - break; - case MemoryModel::SEQ_CST: - default: - __atomic_store_n(&value_, value, __ATOMIC_SEQ_CST); - break; - } - } - - int32_t Atomic32::fetchAdd(int32_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return __atomic_fetch_add(&value_, value, __ATOMIC_RELAXED); - case MemoryModel::ACQUIRE: - return __atomic_fetch_add(&value_, value, __ATOMIC_ACQUIRE); - case MemoryModel::RELEASE: - return __atomic_fetch_add(&value_, value, __ATOMIC_RELEASE); - case MemoryModel::SEQ_CST: - default: - return __atomic_fetch_add(&value_, value, __ATOMIC_SEQ_CST); - } - } - - int32_t Atomic32::fetchSub(int32_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return __atomic_fetch_sub(&value_, value, __ATOMIC_RELAXED); - case MemoryModel::ACQUIRE: - return __atomic_fetch_sub(&value_, value, __ATOMIC_ACQUIRE); - case MemoryModel::RELEASE: - return __atomic_fetch_sub(&value_, value, __ATOMIC_RELEASE); - case MemoryModel::SEQ_CST: - default: - return __atomic_fetch_sub(&value_, value, __ATOMIC_SEQ_CST); - } - } - - bool Atomic32::cmpExchange(int32_t newValue, int32_t cmpValue, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return __atomic_compare_exchange_n(&value_, &cmpValue, newValue, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED); - case MemoryModel::ACQUIRE: - return __atomic_compare_exchange_n(&value_, &cmpValue, newValue, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); - case MemoryModel::RELEASE: - return __atomic_compare_exchange_n(&value_, &cmpValue, newValue, false, __ATOMIC_RELEASE, __ATOMIC_RELAXED); - case MemoryModel::SEQ_CST: - default: - return __atomic_compare_exchange_n(&value_, &cmpValue, newValue, false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); - } - } - - int64_t Atomic64::load(MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - __atomic_load_n(&value_, __ATOMIC_RELAXED); - return value_; - case MemoryModel::ACQUIRE: - __atomic_load_n(&value_, __ATOMIC_ACQUIRE); - return value_; - case MemoryModel::RELEASE: - FATAL_MSG("Incompatible memory model"); - return 0; - case MemoryModel::SEQ_CST: - default: - __atomic_load_n(&value_, __ATOMIC_SEQ_CST); - return value_; - } - } - - void Atomic64::store(int64_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - __atomic_store_n(&value_, value, __ATOMIC_RELAXED); - break; - case MemoryModel::ACQUIRE: FATAL_MSG("Incompatible memory model"); - case MemoryModel::RELEASE: - __atomic_store_n(&value_, value, __ATOMIC_RELEASE); - break; - case MemoryModel::SEQ_CST: - default: - __atomic_store_n(&value_, value, __ATOMIC_SEQ_CST); - break; - } - } - - int64_t Atomic64::fetchAdd(int64_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return __atomic_fetch_add(&value_, value, __ATOMIC_RELAXED); - case MemoryModel::ACQUIRE: - return __atomic_fetch_add(&value_, value, __ATOMIC_ACQUIRE); - case MemoryModel::RELEASE: - return __atomic_fetch_add(&value_, value, __ATOMIC_RELEASE); - case MemoryModel::SEQ_CST: - default: - return __atomic_fetch_add(&value_, value, __ATOMIC_SEQ_CST); - } - } - - int64_t Atomic64::fetchSub(int64_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return __atomic_fetch_sub(&value_, value, __ATOMIC_RELAXED); - case MemoryModel::ACQUIRE: - return __atomic_fetch_sub(&value_, value, __ATOMIC_ACQUIRE); - case MemoryModel::RELEASE: - return __atomic_fetch_sub(&value_, value, __ATOMIC_RELEASE); - case MemoryModel::SEQ_CST: - default: - return __atomic_fetch_sub(&value_, value, __ATOMIC_SEQ_CST); - } - } - - bool Atomic64::cmpExchange(int64_t newValue, int64_t cmpValue, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return __atomic_compare_exchange_n(&value_, &cmpValue, newValue, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED); - case MemoryModel::ACQUIRE: - return __atomic_compare_exchange_n(&value_, &cmpValue, newValue, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); - case MemoryModel::RELEASE: - return __atomic_compare_exchange_n(&value_, &cmpValue, newValue, false, __ATOMIC_RELEASE, __ATOMIC_RELAXED); - case MemoryModel::SEQ_CST: - default: - return __atomic_compare_exchange_n(&value_, &cmpValue, newValue, false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); - } - } -} \ No newline at end of file diff --git a/Sources/nCine/Threading/StdAtomic.cpp b/Sources/nCine/Threading/StdAtomic.cpp deleted file mode 100644 index 80f3be10..00000000 --- a/Sources/nCine/Threading/StdAtomic.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include "Atomic.h" -#include "../../Common.h" - -namespace nCine -{ - int32_t Atomic32::load(MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return std::atomic_load_explicit(&value_, std::memory_order_relaxed); - case MemoryModel::RELEASE: - FATAL_MSG("Incompatible memory model"); - return 0; - case MemoryModel::ACQUIRE: - return std::atomic_load_explicit(&value_, std::memory_order_acquire); - case MemoryModel::SEQ_CST: - default: - return std::atomic_load_explicit(&value_, std::memory_order_seq_cst); - } - } - - void Atomic32::store(int32_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - std::atomic_store_explicit(&value_, value, std::memory_order_relaxed); - break; - case MemoryModel::ACQUIRE: - FATAL_MSG("Incompatible memory model"); - break; - case MemoryModel::RELEASE: - std::atomic_store_explicit(&value_, value, std::memory_order_release); - break; - case MemoryModel::SEQ_CST: - default: - std::atomic_store_explicit(&value_, value, std::memory_order_seq_cst); - break; - } - } - - int32_t Atomic32::fetchAdd(int32_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return atomic_fetch_add_explicit(&value_, value, std::memory_order_relaxed); - case MemoryModel::ACQUIRE: - return atomic_fetch_add_explicit(&value_, value, std::memory_order_acquire); - case MemoryModel::RELEASE: - return atomic_fetch_add_explicit(&value_, value, std::memory_order_release); - case MemoryModel::SEQ_CST: - default: - return atomic_fetch_add_explicit(&value_, value, std::memory_order_seq_cst); - } - } - - int32_t Atomic32::fetchSub(int32_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return atomic_fetch_sub_explicit(&value_, value, std::memory_order_relaxed); - case MemoryModel::ACQUIRE: - return atomic_fetch_sub_explicit(&value_, value, std::memory_order_acquire); - case MemoryModel::RELEASE: - return atomic_fetch_sub_explicit(&value_, value, std::memory_order_release); - case MemoryModel::SEQ_CST: - default: - return atomic_fetch_sub_explicit(&value_, value, std::memory_order_seq_cst); - } - } - - bool Atomic32::cmpExchange(int32_t newValue, int32_t cmpValue, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return std::atomic_compare_exchange_weak_explicit(&value_, &cmpValue, newValue, std::memory_order_relaxed, std::memory_order_relaxed); - case MemoryModel::ACQUIRE: - return std::atomic_compare_exchange_weak_explicit(&value_, &cmpValue, newValue, std::memory_order_acquire, std::memory_order_relaxed); - case MemoryModel::RELEASE: - return std::atomic_compare_exchange_weak_explicit(&value_, &cmpValue, newValue, std::memory_order_release, std::memory_order_relaxed); - case MemoryModel::SEQ_CST: - default: - return std::atomic_compare_exchange_weak_explicit(&value_, &cmpValue, newValue, std::memory_order_seq_cst, std::memory_order_relaxed); - } - } - - int64_t Atomic64::load(MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return std::atomic_load_explicit(&value_, std::memory_order_relaxed); - case MemoryModel::RELEASE: - FATAL_MSG("Incompatible memory model"); - return 0; - case MemoryModel::ACQUIRE: - return std::atomic_load_explicit(&value_, std::memory_order_acquire); - case MemoryModel::SEQ_CST: - default: - return std::atomic_load_explicit(&value_, std::memory_order_seq_cst); - } - } - - void Atomic64::store(int64_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - std::atomic_store_explicit(&value_, value, std::memory_order_relaxed); - break; - case MemoryModel::ACQUIRE: FATAL_MSG("Incompatible memory model"); - case MemoryModel::RELEASE: - std::atomic_store_explicit(&value_, value, std::memory_order_release); - break; - case MemoryModel::SEQ_CST: - default: - std::atomic_store_explicit(&value_, value, std::memory_order_seq_cst); - break; - } - } - - int64_t Atomic64::fetchAdd(int64_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return atomic_fetch_add_explicit(&value_, value, std::memory_order_relaxed); - case MemoryModel::ACQUIRE: - return atomic_fetch_add_explicit(&value_, value, std::memory_order_acquire); - case MemoryModel::RELEASE: - return atomic_fetch_add_explicit(&value_, value, std::memory_order_release); - case MemoryModel::SEQ_CST: - default: - return atomic_fetch_add_explicit(&value_, value, std::memory_order_seq_cst); - } - } - - int64_t Atomic64::fetchSub(int64_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return atomic_fetch_sub_explicit(&value_, value, std::memory_order_relaxed); - case MemoryModel::ACQUIRE: - return atomic_fetch_sub_explicit(&value_, value, std::memory_order_acquire); - case MemoryModel::RELEASE: - return atomic_fetch_sub_explicit(&value_, value, std::memory_order_release); - case MemoryModel::SEQ_CST: - default: - return atomic_fetch_sub_explicit(&value_, value, std::memory_order_seq_cst); - } - } - - bool Atomic64::cmpExchange(int64_t newValue, int64_t cmpValue, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return std::atomic_compare_exchange_weak_explicit(&value_, &cmpValue, newValue, std::memory_order_relaxed, std::memory_order_relaxed); - case MemoryModel::ACQUIRE: - return std::atomic_compare_exchange_weak_explicit(&value_, &cmpValue, newValue, std::memory_order_acquire, std::memory_order_relaxed); - case MemoryModel::RELEASE: - return std::atomic_compare_exchange_weak_explicit(&value_, &cmpValue, newValue, std::memory_order_release, std::memory_order_relaxed); - case MemoryModel::SEQ_CST: - default: - return std::atomic_compare_exchange_weak_explicit(&value_, &cmpValue, newValue, std::memory_order_seq_cst, std::memory_order_relaxed); - } - } -} diff --git a/Sources/nCine/Threading/WindowsAtomic.cpp b/Sources/nCine/Threading/WindowsAtomic.cpp deleted file mode 100644 index 9ad368db..00000000 --- a/Sources/nCine/Threading/WindowsAtomic.cpp +++ /dev/null @@ -1,207 +0,0 @@ -#include "Atomic.h" -#include "../../Common.h" - -#include - -namespace nCine -{ - int32_t Atomic32::load(MemoryModel memModel) - { -#if defined(DEATH_TARGET_WINDOWS_RT) - // ReadNoFence/ReadAcquire/ReadRelease is not supported on Windows RT - return value_; -#else - switch (memModel) { - case MemoryModel::RELAXED: - return ReadNoFence(reinterpret_cast(&value_)); - case MemoryModel::ACQUIRE: - return ReadAcquire(reinterpret_cast(&value_)); - case MemoryModel::RELEASE: - FATAL_MSG("Incompatible memory model"); - return 0; - case MemoryModel::SEQ_CST: - default: - return ReadAcquire(reinterpret_cast(&value_)); - } -#endif - } - - void Atomic32::store(int32_t value, MemoryModel memModel) - { -#if defined(DEATH_TARGET_WINDOWS_RT) - // WriteNoFence/WriteAcquire/WriteRelease is not supported on Windows RT - value_ = value; -#else - switch (memModel) { - case MemoryModel::RELAXED: - WriteNoFence(reinterpret_cast(&value_), value); - break; - case MemoryModel::ACQUIRE: - FATAL_MSG("Incompatible memory model"); - break; - case MemoryModel::RELEASE: - WriteRelease(reinterpret_cast(&value_), value); - break; - case MemoryModel::SEQ_CST: - default: - WriteRelease(reinterpret_cast(&value_), value); - break; - } -#endif - } - - int32_t Atomic32::fetchAdd(int32_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return InterlockedExchangeAddNoFence(reinterpret_cast(&value_), value); - case MemoryModel::ACQUIRE: - return InterlockedExchangeAddAcquire(reinterpret_cast(&value_), value); - case MemoryModel::RELEASE: - return InterlockedExchangeAddRelease(reinterpret_cast(&value_), value); - case MemoryModel::SEQ_CST: - default: - return InterlockedExchangeAdd(reinterpret_cast(&value_), value); - } - } - - int32_t Atomic32::fetchSub(int32_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return InterlockedExchangeAddNoFence(reinterpret_cast(&value_), -value); - case MemoryModel::ACQUIRE: - return InterlockedExchangeAddAcquire(reinterpret_cast(&value_), -value); - case MemoryModel::RELEASE: - return InterlockedExchangeAddRelease(reinterpret_cast(&value_), -value); - case MemoryModel::SEQ_CST: - default: - return InterlockedExchangeAdd(reinterpret_cast(&value_), -value); - } - } - - bool Atomic32::cmpExchange(int32_t newValue, int32_t cmpValue, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return InterlockedCompareExchangeNoFence(reinterpret_cast(&value_), newValue, cmpValue) == cmpValue; - case MemoryModel::ACQUIRE: - return InterlockedCompareExchangeAcquire(reinterpret_cast(&value_), newValue, cmpValue) == cmpValue; - case MemoryModel::RELEASE: - return InterlockedCompareExchangeRelease(reinterpret_cast(&value_), newValue, cmpValue) == cmpValue; - case MemoryModel::SEQ_CST: - default: - return InterlockedCompareExchange(reinterpret_cast(&value_), newValue, cmpValue) == cmpValue; - } - } - - int64_t Atomic64::load(MemoryModel memModel) - { -#if defined(DEATH_TARGET_WINDOWS_RT) - // ReadNoFence/ReadAcquire/ReadRelease is not supported on Windows RT - return value_; -#else - switch (memModel) { - case MemoryModel::RELAXED: - return ReadNoFence64(reinterpret_cast(&value_)); - case MemoryModel::ACQUIRE: - return ReadAcquire64(reinterpret_cast(&value_)); - case MemoryModel::RELEASE: - FATAL_MSG("Incompatible memory model"); - return 0; - case MemoryModel::SEQ_CST: - default: - return ReadAcquire64(reinterpret_cast(&value_)); - } -#endif - } - - void Atomic64::store(int64_t value, MemoryModel memModel) - { -#if defined(DEATH_TARGET_WINDOWS_RT) - // WriteNoFence/WriteAcquire/WriteRelease is not supported on Windows RT - value_ = value; -#else - switch (memModel) { - case MemoryModel::RELAXED: - WriteNoFence64(reinterpret_cast(&value_), value); - break; - case MemoryModel::ACQUIRE: - FATAL_MSG("Incompatible memory model"); - break; - case MemoryModel::RELEASE: - WriteRelease64(reinterpret_cast(&value_), value); - break; - case MemoryModel::SEQ_CST: - default: - WriteRelease64(reinterpret_cast(&value_), value); - break; - } -#endif - } - - int64_t Atomic64::fetchAdd(int64_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return InterlockedExchangeAddNoFence64(reinterpret_cast(&value_), value); - case MemoryModel::ACQUIRE: -#if defined(DEATH_TARGET_X86) && defined(DEATH_TARGET_32BIT) - FATAL_MSG("Incompatible memory model"); - return 0; -#else - return InterlockedExchangeAddAcquire64(reinterpret_cast(&value_), value); -#endif - case MemoryModel::RELEASE: -#if defined(DEATH_TARGET_X86) && defined(DEATH_TARGET_32BIT) - FATAL_MSG("Incompatible memory model"); - return 0; -#else - return InterlockedExchangeAddRelease64(reinterpret_cast(&value_), value); -#endif - case MemoryModel::SEQ_CST: - default: - return InterlockedExchangeAdd64(reinterpret_cast(&value_), value); - } - } - - int64_t Atomic64::fetchSub(int64_t value, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return InterlockedExchangeAddNoFence64(reinterpret_cast(&value_), -value); - case MemoryModel::ACQUIRE: -#if defined(DEATH_TARGET_X86) && defined(DEATH_TARGET_32BIT) - FATAL_MSG("Incompatible memory model"); - return 0; -#else - return InterlockedExchangeAddAcquire64(reinterpret_cast(&value_), -value); -#endif - case MemoryModel::RELEASE: -#if defined(DEATH_TARGET_X86) && defined(DEATH_TARGET_32BIT) - FATAL_MSG("Incompatible memory model"); - return 0; -#else - return InterlockedExchangeAddRelease64(reinterpret_cast(&value_), -value); -#endif - case MemoryModel::SEQ_CST: - default: - return InterlockedExchangeAdd64(reinterpret_cast(&value_), -value); - } - } - - bool Atomic64::cmpExchange(int64_t newValue, int64_t cmpValue, MemoryModel memModel) - { - switch (memModel) { - case MemoryModel::RELAXED: - return InterlockedCompareExchangeNoFence64(reinterpret_cast(&value_), newValue, cmpValue) == cmpValue; - case MemoryModel::ACQUIRE: - return InterlockedCompareExchangeAcquire64(reinterpret_cast(&value_), newValue, cmpValue) == cmpValue; - case MemoryModel::RELEASE: - return InterlockedCompareExchangeRelease64(reinterpret_cast(&value_), newValue, cmpValue) == cmpValue; - case MemoryModel::SEQ_CST: - default: - return InterlockedCompareExchange64(reinterpret_cast(&value_), newValue, cmpValue) == cmpValue; - } - } -} \ No newline at end of file diff --git a/cmake/ncine_extra_sources.cmake b/cmake/ncine_extra_sources.cmake index dae18384..cce7e6ef 100644 --- a/cmake/ncine_extra_sources.cmake +++ b/cmake/ncine_extra_sources.cmake @@ -1,18 +1,7 @@ target_include_directories(${NCINE_APP} PRIVATE "${NCINE_SOURCE_DIR}/Shared") -if(WIN32) - if(NOT MINGW) - list(APPEND SOURCES ${NCINE_SOURCE_DIR}/nCine/Threading/WindowsAtomic.cpp) - else() - list(APPEND SOURCES ${NCINE_SOURCE_DIR}/nCine/Threading/GccAtomic.cpp) - endif() -elseif(APPLE) - list(APPEND SOURCES ${NCINE_SOURCE_DIR}/nCine/Threading/StdAtomic.cpp) -else() - if(ATOMIC_FOUND) - target_link_libraries(${NCINE_APP} PRIVATE Atomic::Atomic) - endif() - list(APPEND SOURCES ${NCINE_SOURCE_DIR}/nCine/Threading/GccAtomic.cpp) +if(ATOMIC_FOUND) + target_link_libraries(${NCINE_APP} PRIVATE Atomic::Atomic) endif() if(EMSCRIPTEN) diff --git a/cmake/ncine_headers.cmake b/cmake/ncine_headers.cmake index 4dd93983..8988ade1 100644 --- a/cmake/ncine_headers.cmake +++ b/cmake/ncine_headers.cmake @@ -44,7 +44,6 @@ set(HEADERS ${NCINE_SOURCE_DIR}/Shared/IO/PakFile.h ${NCINE_SOURCE_DIR}/Shared/IO/Stream.h ${NCINE_SOURCE_DIR}/Shared/Threading/Event.h - ${NCINE_SOURCE_DIR}/Shared/Threading/Interlocked.h ${NCINE_SOURCE_DIR}/Shared/Threading/Spinlock.h ${NCINE_SOURCE_DIR}/Shared/Threading/Implementation/WaitOnAddress.h ) @@ -158,7 +157,6 @@ list(APPEND HEADERS ${NCINE_SOURCE_DIR}/nCine/Primitives/Vector2.h ${NCINE_SOURCE_DIR}/nCine/Primitives/Vector3.h ${NCINE_SOURCE_DIR}/nCine/Primitives/Vector4.h - ${NCINE_SOURCE_DIR}/nCine/Threading/Atomic.h ${NCINE_SOURCE_DIR}/nCine/Threading/IThreadCommand.h ${NCINE_SOURCE_DIR}/nCine/Threading/IThreadPool.h )