From 6184d31e6aa1b37f803202c09d322172b6ba0e99 Mon Sep 17 00:00:00 2001 From: Jon Thysell Date: Fri, 15 Oct 2021 09:43:09 -0700 Subject: [PATCH] Factored out GameWindow, added error alert dialogs, simplified stdbool.h --- src/GameEngine.h | 2 +- src/GameWindow.c | 29 +++++++++++++++++++++++++++++ src/GameWindow.h | 16 ++++++++++++++++ src/MacCommon.c | 26 ++++++++++++++++++++++++++ src/MacCommon.h | 13 +++++++++++-- src/MacLO.c | 26 +++++++------------------- src/MacLO.h | 6 +++--- src/MacLO.pi.bin | Bin 11392 -> 11520 bytes src/MacLO.pi.rsrc.bin | Bin 3072 -> 3200 bytes src/main.c | 6 +++--- src/stdbool.h | 6 +----- 11 files changed, 97 insertions(+), 33 deletions(-) create mode 100644 src/GameWindow.c create mode 100644 src/GameWindow.h create mode 100644 src/MacCommon.c diff --git a/src/GameEngine.h b/src/GameEngine.h index 6206946..ebd84ef 100644 --- a/src/GameEngine.h +++ b/src/GameEngine.h @@ -16,7 +16,7 @@ extern const uint16_t PerfectScore; typedef struct GameEngine { - int8_t Level; + int8_t Level; uint32_t Lights; uint16_t Par; uint16_t Moves; diff --git a/src/GameWindow.c b/src/GameWindow.c new file mode 100644 index 0000000..fd6e848 --- /dev/null +++ b/src/GameWindow.c @@ -0,0 +1,29 @@ +// Copyright (c) Jon Thysell +// Licensed under the MIT License. + +#include "GameWindow.h" + +void GameWindow_Init(GameWindow *gameWindow) +{ + if (gameWindow->Window != nil) + { + ShowError("\pGameWindow already initialized!", false); + } + + gameWindow->Window = GetNewWindow(kBaseResID, nil, kMoveToFront); + + if (gameWindow->Window == nil) + { + ShowError("\pGameWindow resource WIND kBaseResID missing!", true); + } + + CenterWindow(gameWindow->Window); + + ShowWindow(gameWindow->Window); + SetPort(gameWindow->Window); + + MoveTo(10, 20); + DrawString("\pHello MacLO"); +} + + diff --git a/src/GameWindow.h b/src/GameWindow.h new file mode 100644 index 0000000..42a9034 --- /dev/null +++ b/src/GameWindow.h @@ -0,0 +1,16 @@ +// Copyright (c) Jon Thysell +// Licensed under the MIT License. + +#ifndef GAMEWINDOW_H +#define GAMEWINDOW_H + +#include "MacCommon.h" + +typedef struct GameWindow +{ + WindowPtr Window; +} GameWindow; + +void GameWindow_Init(GameWindow *gameWindow); + +#endif diff --git a/src/MacCommon.c b/src/MacCommon.c new file mode 100644 index 0000000..8a0d4ba --- /dev/null +++ b/src/MacCommon.c @@ -0,0 +1,26 @@ +// Copyright (c) Jon Thysell +// Licensed under the MIT License. + +#include "MacCommon.h" + +void CenterWindow(WindowPtr window) +{ + +} + +Boolean IsCompactDisplay() +{ + return screenBits.bounds.right == 512 + && screenBits.bounds.bottom == 342; +} + +void ShowError(Str255 message, Boolean isFatal) +{ + ParamText(message, kEmptyString, kEmptyString, kEmptyString); + StopAlert(kErrorAlertID, kNilFilterProc); + + if (isFatal) + { + ExitToShell(); + } +} diff --git a/src/MacCommon.h b/src/MacCommon.h index 865a0d0..c7b5ec9 100644 --- a/src/MacCommon.h +++ b/src/MacCommon.h @@ -4,7 +4,16 @@ #ifndef MACCOMMON_H #define MACCOMMON_H -#define kBaseResID 128 -#define kMoveToFront (WindowPtr)-1L +#define kBaseResID 128 +#define kMoveToFront (WindowPtr)-1L + +#define kEmptyString "\p" +#define kNilFilterProc nil + +#define kErrorAlertID kBaseResID + +void CenterWindow(WindowPtr window); +Boolean IsCompactDisplay(); +void ShowError(Str255 message, Boolean isFatal); #endif diff --git a/src/MacLO.c b/src/MacLO.c index e1fed4d..71f0ee6 100644 --- a/src/MacLO.c +++ b/src/MacLO.c @@ -1,10 +1,12 @@ // Copyright (c) Jon Thysell // Licensed under the MIT License. -#include "MacCommon.h" +#include "GameWindow.h" #include "MacLO.h" -void InitToolBox() +GameWindow gGameWindow; + +void MacLO_InitToolBox() { InitGraf(&thePort); InitFonts(); @@ -16,26 +18,12 @@ void InitToolBox() InitCursor(); } -void InitMainWindow() +void MacLO_InitWindows() { - WindowPtr window; - - window = GetNewWindow(kBaseResID, nil, kMoveToFront); - - if (window == nil) - { - SysBeep(0); - ExitToShell(); - } - - ShowWindow(window); - SetPort(window); - - MoveTo(30, 50); - DrawString("\pHello MacLO"); + GameWindow_Init(&gGameWindow); } -void ProcessEvents() +void MacLO_MainLoop() { while (!Button()) { } } diff --git a/src/MacLO.h b/src/MacLO.h index ac9d94e..7e9e1c6 100644 --- a/src/MacLO.h +++ b/src/MacLO.h @@ -4,8 +4,8 @@ #ifndef MACLO_H #define MACLO_H -void InitToolBox(); -void InitMainWindow(); -void ProcessEvents(); +void MacLO_InitToolBox(); +void MacLO_InitWindows(); +void MacLO_MainLoop(); #endif diff --git a/src/MacLO.pi.bin b/src/MacLO.pi.bin index 7c30880149ca3c2e3787642498550b4f3ead3d8d..2684838f668969b9da564d3bb3f041306df8c9d5 100644 GIT binary patch literal 11520 zcmeHN4^&iVcE4}lFbv}q&>D7PDZET9i!KE+rPgvLIx~PX;P^m5M2{N>l^JjWDN4%P zMA4XvsecH1HoCQOk~OXvYh5<+7}i)Il3+Hw^$=s-oRH+WuCZydVY8YbQeJ=G`vU{` z2i84jd%C_e-@CtizkBa@zd!H3@4Yt^zMy2KH#hk;`W=tF{M?-RPLG!xWuFw+^Yni% z=-JsR(vKh&ANi@!iSg_<=|hwl~k)$XwS}@Zz(7#?$yu4x1Q?y5HSFdlF zK6(Duhc|9~`i)+iY4kH*Rp+vO{s^*4)1`EQ>vR zAUJoL_|1KnCrx?7y>)BHzeoJn?l}+ceQ-$u5#Kv9zWdz$5x74B|Bpu?0(~=5n3PH< zr0c+DGCW>XHkWknpxkQ<%Wdqi(&TsCbq?ZB9ox>IdifQIOehAm5LZl;8b*|vUz86S zam)CMozsb!XT~qy%g#886*d5wF*&nQ}F!@IIyZ6hPm*-uO;mySu)uShR zxi`a9Wyg@1hs�R@AO473>JWQ(CgBv}WxbrshM@Zhm>d0>#d?6W81uc0r||s&r7H zhG{CzQ)#tIn^fAO(1;|3!l!n`s34lnh?uE~i7do-{@Z@O^T({5;yY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