From 5b7a676b356dc87f6f6693e81370da1a92cd5165 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sat, 24 Sep 2022 16:51:16 +0300 Subject: [PATCH] Refactor artLockFrameData with FrmImage --- src/automap.cc | 59 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/src/automap.cc b/src/automap.cc index 94788f5..dea8b57 100644 --- a/src/automap.cc +++ b/src/automap.cc @@ -301,15 +301,10 @@ void automapShow(bool isInGame, bool isUsingScanner) int frmIds[AUTOMAP_FRM_COUNT]; memcpy(frmIds, gAutomapFrmIds, sizeof(gAutomapFrmIds)); - unsigned char* frmData[AUTOMAP_FRM_COUNT]; - CacheEntry* frmHandle[AUTOMAP_FRM_COUNT]; + FrmImage frmImages[AUTOMAP_FRM_COUNT]; for (int index = 0; index < AUTOMAP_FRM_COUNT; index++) { int fid = buildFid(OBJ_TYPE_INTERFACE, frmIds[index], 0, 0, 0); - frmData[index] = artLockFrameData(fid, 0, 0, &(frmHandle[index])); - if (frmData[index] == NULL) { - while (--index >= 0) { - artUnlock(frmHandle[index]); - } + if (!frmImages[index].lock(fid)) { return; } } @@ -329,17 +324,53 @@ void automapShow(bool isInGame, bool isUsingScanner) int automapWindowY = (screenGetHeight() - AUTOMAP_WINDOW_HEIGHT) / 2; int window = windowCreate(automapWindowX, automapWindowY, AUTOMAP_WINDOW_WIDTH, AUTOMAP_WINDOW_HEIGHT, color, WINDOW_FLAG_0x10 | WINDOW_FLAG_0x04); - int scannerBtn = buttonCreate(window, 111, 454, 15, 16, -1, -1, -1, KEY_LOWERCASE_S, frmData[AUTOMAP_FRM_BUTTON_UP], frmData[AUTOMAP_FRM_BUTTON_DOWN], NULL, BUTTON_FLAG_TRANSPARENT); + int scannerBtn = buttonCreate(window, + 111, + 454, + 15, + 16, + -1, + -1, + -1, + KEY_LOWERCASE_S, + frmImages[AUTOMAP_FRM_BUTTON_UP].getData(), + frmImages[AUTOMAP_FRM_BUTTON_DOWN].getData(), + NULL, + BUTTON_FLAG_TRANSPARENT); if (scannerBtn != -1) { buttonSetCallbacks(scannerBtn, _gsound_red_butt_press, _gsound_red_butt_release); } - int cancelBtn = buttonCreate(window, 277, 454, 15, 16, -1, -1, -1, KEY_ESCAPE, frmData[AUTOMAP_FRM_BUTTON_UP], frmData[AUTOMAP_FRM_BUTTON_DOWN], NULL, BUTTON_FLAG_TRANSPARENT); + int cancelBtn = buttonCreate(window, + 277, + 454, + 15, + 16, + -1, + -1, + -1, + KEY_ESCAPE, + frmImages[AUTOMAP_FRM_BUTTON_UP].getData(), + frmImages[AUTOMAP_FRM_BUTTON_DOWN].getData(), + NULL, + BUTTON_FLAG_TRANSPARENT); if (cancelBtn != -1) { buttonSetCallbacks(cancelBtn, _gsound_red_butt_press, _gsound_red_butt_release); } - int switchBtn = buttonCreate(window, 457, 340, 42, 74, -1, -1, KEY_LOWERCASE_L, KEY_LOWERCASE_H, frmData[AUTOMAP_FRM_SWITCH_UP], frmData[AUTOMAP_FRM_SWITCH_DOWN], NULL, BUTTON_FLAG_TRANSPARENT | BUTTON_FLAG_0x01); + int switchBtn = buttonCreate(window, + 457, + 340, + 42, + 74, + -1, + -1, + KEY_LOWERCASE_L, + KEY_LOWERCASE_H, + frmImages[AUTOMAP_FRM_SWITCH_UP].getData(), + frmImages[AUTOMAP_FRM_SWITCH_DOWN].getData(), + NULL, + BUTTON_FLAG_TRANSPARENT | BUTTON_FLAG_0x01); if (switchBtn != -1) { buttonSetCallbacks(switchBtn, _gsound_toggle_butt_press_, _gsound_toggle_butt_press_); } @@ -360,7 +391,7 @@ void automapShow(bool isInGame, bool isUsingScanner) gAutomapFlags |= AUTOMAP_WITH_SCANNER; } - automapRenderInMapWindow(window, elevation, frmData[AUTOMAP_FRM_BACKGROUND], gAutomapFlags); + automapRenderInMapWindow(window, elevation, frmImages[AUTOMAP_FRM_BACKGROUND].getData(), gAutomapFlags); bool isoWasEnabled = isoDisable(); gameMouseSetCursor(MOUSE_CURSOR_ARROW); @@ -444,7 +475,7 @@ void automapShow(bool isInGame, bool isUsingScanner) } if (needsRefresh) { - automapRenderInMapWindow(window, elevation, frmData[AUTOMAP_FRM_BACKGROUND], gAutomapFlags); + automapRenderInMapWindow(window, elevation, frmImages[AUTOMAP_FRM_BACKGROUND].getData(), gAutomapFlags); needsRefresh = false; } } @@ -455,10 +486,6 @@ void automapShow(bool isInGame, bool isUsingScanner) windowDestroy(window); fontSetCurrent(oldFont); - - for (int index = 0; index < AUTOMAP_FRM_COUNT; index++) { - artUnlock(frmHandle[index]); - } } // Renders automap in Map window.