cyberslak
/lightsout
/amendments
/17
code cleanup, move memory_init to util
cyberslak made amendment 17 22 days ago
--- main.c Wed Mar 12 01:18:31 2025
+++ main.c Thu Mar 13 01:51:04 2025
@@ -69,8 +69,6 @@ void resolve_entity_ldef();
pascal void dialog_list_update(WindowPtr theWin, short itemNo);
-void memory_init(void);
-
void bars_draw();
void draw_background();
void bars_update();
@@ -100,19 +98,6 @@ enum control_type
CONTROL_SCROLLBAR,
};
-void memory_init(void)
-{
- short i;
- Ptr applLimit;
-
- applLimit = GetApplLimit();
- SetApplLimit(applLimit - 0x8000);
-
- MaxApplZone();
- for (i = 0; i < 5; ++i)
- MoreMasters();
-}
-
void ensure_valid_prefs(void)
{
bool updatedPrefs = false;
@@ -372,30 +357,26 @@ void entity_list_mousedown(EventRecord* evt, WindowPtr
DialogPtr theDialog;
short itemHit;
struct dialog_info* dinfo = (void*)GetWRefCon(win);
- GrafPtr oldPort;
- GetPort(&oldPort);
- SetPort(win);
-
- DialogSelect(evt, &theDialog, &itemHit);
+ with_port(win, {
+ DialogSelect(evt, &theDialog, &itemHit);
- GlobalToLocal(&evt->where);
-
- switch (itemHit)
- {
- case 1:
- entity_list_add(dinfo);
+ GlobalToLocal(&evt->where);
- // must dispose of list before dialog
- dialog_info_free(dinfo);
- DisposeDialog(theDialog);
- break;
- case 2:
- LClick(evt->where, evt->modifiers, dinfo->lHnd);
- break;
- }
-
- SetPort(oldPort);
+ switch (itemHit)
+ {
+ case 1:
+ entity_list_add(dinfo);
+
+ // must dispose of list before dialog
+ dialog_info_free(dinfo);
+ DisposeDialog(theDialog);
+ break;
+ case 2:
+ LClick(evt->where, evt->modifiers, dinfo->lHnd);
+ break;
+ }
+ })
}
void entity_list_activate(bool activate, WindowPtr win)
@@ -639,7 +620,7 @@ static void bar_draw(struct entity *ent)
FrameRect(&barBounds);
snprintf(buf, 128, "%d%%",
- (val * 100 + 127) / 255);
+ (val * 100 + 127) / 254);
pBuf = c2pstr(buf);
width = StringWidth(pBuf);
@@ -693,7 +674,6 @@ void bars_update()
static uint32_t lastTickCount = 0;
WindowPeek win = (WindowPeek)gMainWindow;
short val;
- GrafPtr oldPort;
bool changed = false;
if (lastTickCount + kBarUpdateRate > TickCount())
@@ -714,10 +694,9 @@ void bars_update()
if (changed)
{
- GetPort(&oldPort);
- SetPort(gMainWindow);
- InvalRect(&gMainWindow->portRect);
- SetPort(oldPort);
+ with_port(gMainWindow, {
+ InvalRect(&gMainWindow->portRect);
+ })
}
lastTickCount = TickCount();
@@ -756,19 +735,15 @@ struct entity *entity_for_control(ControlHandle hnd)
void event_update(WindowPtr win)
{
WindowPeek wPeek = (WindowPeek)win;
- GrafPtr oldPort;
- GetPort(&oldPort);
- SetPort(win);
-
- if (win == gMainWindow)
- {
- bars_draw(win);
- draw_background(win);
- UpdateControls(win, win->visRgn);
- }
-
- SetPort(oldPort);
+ with_port(win, {
+ if (win == gMainWindow)
+ {
+ bars_draw(win);
+ draw_background(win);
+ UpdateControls(win, win->visRgn);
+ }
+ })
}
void update_entity_positions(WindowPtr win, short scrollValue)
--- util.c Sun Mar 9 23:44:12 2025
+++ util.c Wed Mar 12 21:17:16 2025
@@ -90,6 +90,19 @@ void toolbox_init(void)
InitCursor();
}
+void memory_init(void)
+{
+ short i;
+ Ptr applLimit;
+
+ applLimit = GetApplLimit();
+ SetApplLimit(applLimit - 0x8000);
+
+ MaxApplZone();
+ for (i = 0; i < 5; ++i)
+ MoreMasters();
+}
+
size_t lo_strlcpy(char* dest, const char* src, size_t len)
{
size_t srclen = strlen(src);
--- util.h Wed Mar 12 00:36:12 2025
+++ util.h Thu Mar 13 01:51:42 2025
@@ -75,5 +75,6 @@ short lo_vsnprintf(char* s, size_t size,
#endif
void toolbox_init(void);
+void memory_init(void);
#endif // _LO_UTIL_H_