Refactor artLockFrameData with FrmImage

This commit is contained in:
Alexander Batalov 2022-09-26 10:36:54 +03:00
parent 2205077d36
commit 45278f66a5
1 changed files with 28 additions and 43 deletions

View File

@ -128,15 +128,6 @@ static int gMainMenuWindow = -1;
// 0x5194F4 // 0x5194F4
static unsigned char* gMainMenuWindowBuffer = NULL; static unsigned char* gMainMenuWindowBuffer = NULL;
// 0x5194F8
static unsigned char* gMainMenuBackgroundFrmData = NULL;
// 0x5194FC
static unsigned char* gMainMenuButtonUpFrmData = NULL;
// 0x519500
static unsigned char* gMainMenuButtonDownFrmData = NULL;
// 0x519504 // 0x519504
static bool _in_main_menu = false; static bool _in_main_menu = false;
@ -175,14 +166,9 @@ static int gMainMenuButtons[MAIN_MENU_BUTTON_COUNT];
// 0x614858 // 0x614858
static bool gMainMenuWindowHidden; static bool gMainMenuWindowHidden;
// 0x61485C static FrmImage _mainMenuBackgroundFrmImage;
static CacheEntry* gMainMenuButtonUpFrmHandle; static FrmImage _mainMenuButtonNormalFrmImage;
static FrmImage _mainMenuButtonPressedFrmImage;
// 0x614860
static CacheEntry* gMainMenuButtonDownFrmHandle;
// 0x614864
static CacheEntry* gMainMenuBackgroundFrmHandle;
// 0x48099C // 0x48099C
int falloutMain(int argc, char** argv) int falloutMain(int argc, char** argv)
@ -618,10 +604,9 @@ static void showDeath()
} }
// DEATH.FRM // DEATH.FRM
CacheEntry* backgroundHandle; FrmImage backgroundFrmImage;
int fid = buildFid(OBJ_TYPE_INTERFACE, 309, 0, 0, 0); int fid = buildFid(OBJ_TYPE_INTERFACE, 309, 0, 0, 0);
unsigned char* background = artLockFrameData(fid, 0, 0, &backgroundHandle); if (!backgroundFrmImage.lock(fid)) {
if (background == NULL) {
break; break;
} }
@ -632,8 +617,8 @@ static void showDeath()
keyboardReset(); keyboardReset();
inputEventQueueReset(); inputEventQueueReset();
blitBufferToBuffer(background, 640, 480, 640, windowBuffer, 640); blitBufferToBuffer(backgroundFrmImage.getData(), 640, 480, 640, windowBuffer, 640);
artUnlock(backgroundHandle); backgroundFrmImage.unlock();
const char* deathFileName = endgameDeathEndingGetFileName(); const char* deathFileName = endgameDeathEndingGetFileName();
@ -831,14 +816,13 @@ static int mainMenuWindowInit()
// mainmenu.frm // mainmenu.frm
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 140, 0, 0, 0); int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 140, 0, 0, 0);
gMainMenuBackgroundFrmData = artLockFrameData(backgroundFid, 0, 0, &gMainMenuBackgroundFrmHandle); if (!_mainMenuBackgroundFrmImage.lock(backgroundFid)) {
if (gMainMenuBackgroundFrmData == NULL) {
// NOTE: Uninline. // NOTE: Uninline.
return main_menu_fatal_error(); return main_menu_fatal_error();
} }
blitBufferToBuffer(gMainMenuBackgroundFrmData, 640, 480, 640, gMainMenuWindowBuffer, 640); blitBufferToBuffer(_mainMenuBackgroundFrmImage.getData(), 640, 480, 640, gMainMenuWindowBuffer, 640);
artUnlock(gMainMenuBackgroundFrmHandle); _mainMenuBackgroundFrmImage.unlock();
int oldFont = fontGetCurrent(); int oldFont = fontGetCurrent();
fontSetCurrent(100); fontSetCurrent(100);
@ -877,16 +861,14 @@ static int mainMenuWindowInit()
// menuup.frm // menuup.frm
fid = buildFid(OBJ_TYPE_INTERFACE, 299, 0, 0, 0); fid = buildFid(OBJ_TYPE_INTERFACE, 299, 0, 0, 0);
gMainMenuButtonUpFrmData = artLockFrameData(fid, 0, 0, &gMainMenuButtonUpFrmHandle); if (!_mainMenuButtonNormalFrmImage.lock(fid)) {
if (gMainMenuButtonUpFrmData == NULL) {
// NOTE: Uninline. // NOTE: Uninline.
return main_menu_fatal_error(); return main_menu_fatal_error();
} }
// menudown.frm // menudown.frm
fid = buildFid(OBJ_TYPE_INTERFACE, 300, 0, 0, 0); fid = buildFid(OBJ_TYPE_INTERFACE, 300, 0, 0, 0);
gMainMenuButtonDownFrmData = artLockFrameData(fid, 0, 0, &gMainMenuButtonDownFrmHandle); if (!_mainMenuButtonPressedFrmImage.lock(fid)) {
if (gMainMenuButtonDownFrmData == NULL) {
// NOTE: Uninline. // NOTE: Uninline.
return main_menu_fatal_error(); return main_menu_fatal_error();
} }
@ -901,13 +883,25 @@ static int mainMenuWindowInit()
configGetInt(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_MAIN_MENU_OFFSET_Y_KEY, &offsetY); configGetInt(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_MAIN_MENU_OFFSET_Y_KEY, &offsetY);
for (int index = 0; index < MAIN_MENU_BUTTON_COUNT; index++) { for (int index = 0; index < MAIN_MENU_BUTTON_COUNT; index++) {
gMainMenuButtons[index] = buttonCreate(gMainMenuWindow, offsetX + 30, offsetY + 19 + index * 42 - index, 26, 26, -1, -1, 1111, gMainMenuButtonKeyBindings[index], gMainMenuButtonUpFrmData, gMainMenuButtonDownFrmData, 0, 32); gMainMenuButtons[index] = buttonCreate(gMainMenuWindow,
offsetX + 30,
offsetY + 19 + index * 42 - index,
26,
26,
-1,
-1,
1111,
gMainMenuButtonKeyBindings[index],
_mainMenuButtonNormalFrmImage.getData(),
_mainMenuButtonPressedFrmImage.getData(),
0,
BUTTON_FLAG_TRANSPARENT);
if (gMainMenuButtons[index] == -1) { if (gMainMenuButtons[index] == -1) {
// NOTE: Uninline. // NOTE: Uninline.
return main_menu_fatal_error(); return main_menu_fatal_error();
} }
buttonSetMask(gMainMenuButtons[index], gMainMenuButtonUpFrmData); buttonSetMask(gMainMenuButtons[index], _mainMenuButtonNormalFrmImage.getData());
} }
fontSetCurrent(104); fontSetCurrent(104);
@ -949,17 +943,8 @@ static void mainMenuWindowFree()
} }
} }
if (gMainMenuButtonDownFrmData) { _mainMenuButtonPressedFrmImage.unlock();
artUnlock(gMainMenuButtonDownFrmHandle); _mainMenuButtonNormalFrmImage.unlock();
gMainMenuButtonDownFrmHandle = NULL;
gMainMenuButtonDownFrmData = NULL;
}
if (gMainMenuButtonUpFrmData) {
artUnlock(gMainMenuButtonUpFrmHandle);
gMainMenuButtonUpFrmHandle = NULL;
gMainMenuButtonUpFrmData = NULL;
}
if (gMainMenuWindow != -1) { if (gMainMenuWindow != -1) {
windowDestroy(gMainMenuWindow); windowDestroy(gMainMenuWindow);