Refactor artLockFrameData with FrmImage
This commit is contained in:
parent
5b7a676b35
commit
9ceb490f72
148
src/elevator.cc
148
src/elevator.cc
|
@ -25,12 +25,6 @@ namespace fallout {
|
|||
// The maximum number of elevator levels.
|
||||
#define ELEVATOR_LEVEL_MAX (4)
|
||||
|
||||
// NOTE: There are two variables which hold background data used in the
|
||||
// elevator window - [gElevatorBackgroundFrmData] and [gElevatorPanelFrmData].
|
||||
// For unknown reason they are using -1 to denote that they are not set
|
||||
// (instead of using NULL).
|
||||
#define ELEVATOR_BACKGROUND_NULL ((unsigned char*)(-1))
|
||||
|
||||
// Max number of elevators that can be loaded from elevators.ini. This limit is
|
||||
// emposed by Sfall.
|
||||
#define ELEVATORS_MAX 50
|
||||
|
@ -322,47 +316,18 @@ static const char* gElevatorSoundEffects[ELEVATOR_LEVEL_MAX - 1][ELEVATOR_LEVEL_
|
|||
},
|
||||
};
|
||||
|
||||
// 0x570A2C
|
||||
static Size gElevatorFrmSizes[ELEVATOR_FRM_COUNT];
|
||||
|
||||
// 0x570A44
|
||||
static int gElevatorBackgroundFrmWidth;
|
||||
|
||||
// 0x570A48
|
||||
static int gElevatorBackgroundFrmHeight;
|
||||
|
||||
// 0x570A4C
|
||||
static int gElevatorPanelFrmWidth;
|
||||
|
||||
// 0x570A50
|
||||
static int gElevatorPanelFrmHeight;
|
||||
|
||||
// 0x570A54
|
||||
static int gElevatorWindow;
|
||||
|
||||
// 0x570A58
|
||||
static CacheEntry* gElevatorFrmHandles[ELEVATOR_FRM_COUNT];
|
||||
|
||||
// 0x570A64
|
||||
static CacheEntry* gElevatorBackgroundFrmHandle;
|
||||
|
||||
// 0x570A68
|
||||
static CacheEntry* gElevatorPanelFrmHandle;
|
||||
|
||||
// 0x570A6C
|
||||
static unsigned char* gElevatorWindowBuffer;
|
||||
|
||||
// 0x570A70
|
||||
static bool gElevatorWindowIsoWasEnabled;
|
||||
|
||||
// 0x570A74
|
||||
static unsigned char* gElevatorFrmData[ELEVATOR_FRM_COUNT];
|
||||
|
||||
// 0x570A80
|
||||
static unsigned char* gElevatorBackgroundFrmData;
|
||||
|
||||
// 0x570A84
|
||||
static unsigned char* gElevatorPanelFrmData;
|
||||
static FrmImage _elevatorFrmImages[ELEVATOR_FRM_COUNT];
|
||||
static FrmImage _elevatorBackgroundFrmImage;
|
||||
static FrmImage _elevatorPanelFrmImage;
|
||||
|
||||
// Presents elevator dialog for player to pick a desired level.
|
||||
//
|
||||
|
@ -413,15 +378,15 @@ int elevatorSelectLevel(int elevator, int* mapPtr, int* elevationPtr, int* tileP
|
|||
|
||||
debugPrint("\n the start elev level %d\n", *elevationPtr);
|
||||
|
||||
int v18 = (gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width * gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].height) / 13;
|
||||
int v18 = (_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth() * _elevatorFrmImages[ELEVATOR_FRM_GAUGE].getHeight()) / 13;
|
||||
float v42 = 12.0f / (float)(gElevatorLevels[elevator] - 1);
|
||||
blitBufferToBuffer(
|
||||
gElevatorFrmData[ELEVATOR_FRM_GAUGE] + v18 * (int)((float)(*elevationPtr) * v42),
|
||||
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width,
|
||||
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].height / 13,
|
||||
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width,
|
||||
gElevatorWindowBuffer + gElevatorBackgroundFrmWidth * 41 + 121,
|
||||
gElevatorBackgroundFrmWidth);
|
||||
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getData() + v18 * (int)((float)(*elevationPtr) * v42),
|
||||
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth(),
|
||||
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getHeight() / 13,
|
||||
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth(),
|
||||
gElevatorWindowBuffer + _elevatorBackgroundFrmImage.getWidth() * 41 + 121,
|
||||
_elevatorBackgroundFrmImage.getWidth());
|
||||
windowRefresh(gElevatorWindow);
|
||||
|
||||
bool done = false;
|
||||
|
@ -470,12 +435,12 @@ int elevatorSelectLevel(int elevator, int* mapPtr, int* elevationPtr, int* tileP
|
|||
unsigned int tick = _get_time();
|
||||
v44 += v43;
|
||||
blitBufferToBuffer(
|
||||
gElevatorFrmData[ELEVATOR_FRM_GAUGE] + v18 * (int)v44,
|
||||
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width,
|
||||
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].height / 13,
|
||||
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width,
|
||||
gElevatorWindowBuffer + gElevatorBackgroundFrmWidth * 41 + 121,
|
||||
gElevatorBackgroundFrmWidth);
|
||||
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getData() + v18 * (int)v44,
|
||||
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth(),
|
||||
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getHeight() / 13,
|
||||
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth(),
|
||||
gElevatorWindowBuffer + _elevatorBackgroundFrmImage.getWidth() * 41 + 121,
|
||||
_elevatorBackgroundFrmImage.getWidth());
|
||||
|
||||
windowRefresh(gElevatorWindow);
|
||||
|
||||
|
@ -514,15 +479,14 @@ static int elevatorWindowInit(int elevator)
|
|||
int index;
|
||||
for (index = 0; index < ELEVATOR_FRM_COUNT; index++) {
|
||||
int fid = buildFid(OBJ_TYPE_INTERFACE, gElevatorFrmIds[index], 0, 0, 0);
|
||||
gElevatorFrmData[index] = artLockFrameDataReturningSize(fid, &(gElevatorFrmHandles[index]), &(gElevatorFrmSizes[index].width), &(gElevatorFrmSizes[index].height));
|
||||
if (gElevatorFrmData[index] == NULL) {
|
||||
if (!_elevatorFrmImages[index].lock(fid)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index != ELEVATOR_FRM_COUNT) {
|
||||
for (int reversedIndex = index - 1; reversedIndex >= 0; reversedIndex--) {
|
||||
artUnlock(gElevatorFrmHandles[reversedIndex]);
|
||||
_elevatorFrmImages[reversedIndex].unlock();
|
||||
}
|
||||
|
||||
if (gElevatorWindowIsoWasEnabled) {
|
||||
|
@ -534,39 +498,27 @@ static int elevatorWindowInit(int elevator)
|
|||
return -1;
|
||||
}
|
||||
|
||||
gElevatorPanelFrmData = ELEVATOR_BACKGROUND_NULL;
|
||||
gElevatorBackgroundFrmData = ELEVATOR_BACKGROUND_NULL;
|
||||
|
||||
const ElevatorBackground* elevatorBackground = &(gElevatorBackgrounds[elevator]);
|
||||
bool backgroundsLoaded = true;
|
||||
|
||||
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, elevatorBackground->backgroundFrmId, 0, 0, 0);
|
||||
gElevatorBackgroundFrmData = artLockFrameDataReturningSize(backgroundFid, &gElevatorBackgroundFrmHandle, &gElevatorBackgroundFrmWidth, &gElevatorBackgroundFrmHeight);
|
||||
if (gElevatorBackgroundFrmData != NULL) {
|
||||
if (_elevatorBackgroundFrmImage.lock(backgroundFid)) {
|
||||
if (elevatorBackground->panelFrmId != -1) {
|
||||
int panelFid = buildFid(OBJ_TYPE_INTERFACE, elevatorBackground->panelFrmId, 0, 0, 0);
|
||||
gElevatorPanelFrmData = artLockFrameDataReturningSize(panelFid, &gElevatorPanelFrmHandle, &gElevatorPanelFrmWidth, &gElevatorPanelFrmHeight);
|
||||
if (gElevatorPanelFrmData == NULL) {
|
||||
gElevatorPanelFrmData = ELEVATOR_BACKGROUND_NULL;
|
||||
if (!_elevatorPanelFrmImage.lock(panelFid)) {
|
||||
backgroundsLoaded = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gElevatorBackgroundFrmData = ELEVATOR_BACKGROUND_NULL;
|
||||
backgroundsLoaded = false;
|
||||
}
|
||||
|
||||
if (!backgroundsLoaded) {
|
||||
if (gElevatorBackgroundFrmData != ELEVATOR_BACKGROUND_NULL) {
|
||||
artUnlock(gElevatorBackgroundFrmHandle);
|
||||
}
|
||||
|
||||
if (gElevatorPanelFrmData != ELEVATOR_BACKGROUND_NULL) {
|
||||
artUnlock(gElevatorPanelFrmHandle);
|
||||
}
|
||||
_elevatorBackgroundFrmImage.unlock();
|
||||
_elevatorPanelFrmImage.unlock();
|
||||
|
||||
for (int index = 0; index < ELEVATOR_FRM_COUNT; index++) {
|
||||
artUnlock(gElevatorFrmHandles[index]);
|
||||
_elevatorFrmImages[index].unlock();
|
||||
}
|
||||
|
||||
if (gElevatorWindowIsoWasEnabled) {
|
||||
|
@ -578,26 +530,21 @@ static int elevatorWindowInit(int elevator)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int elevatorWindowX = (screenGetWidth() - gElevatorBackgroundFrmWidth) / 2;
|
||||
int elevatorWindowY = (screenGetHeight() - INTERFACE_BAR_HEIGHT - 1 - gElevatorBackgroundFrmHeight) / 2;
|
||||
int elevatorWindowX = (screenGetWidth() - _elevatorBackgroundFrmImage.getWidth()) / 2;
|
||||
int elevatorWindowY = (screenGetHeight() - INTERFACE_BAR_HEIGHT - 1 - _elevatorBackgroundFrmImage.getHeight()) / 2;
|
||||
gElevatorWindow = windowCreate(
|
||||
elevatorWindowX,
|
||||
elevatorWindowY,
|
||||
gElevatorBackgroundFrmWidth,
|
||||
gElevatorBackgroundFrmHeight,
|
||||
_elevatorBackgroundFrmImage.getWidth(),
|
||||
_elevatorBackgroundFrmImage.getHeight(),
|
||||
256,
|
||||
WINDOW_FLAG_0x10 | WINDOW_FLAG_0x02);
|
||||
if (gElevatorWindow == -1) {
|
||||
if (gElevatorBackgroundFrmData != ELEVATOR_BACKGROUND_NULL) {
|
||||
artUnlock(gElevatorBackgroundFrmHandle);
|
||||
}
|
||||
|
||||
if (gElevatorPanelFrmData != ELEVATOR_BACKGROUND_NULL) {
|
||||
artUnlock(gElevatorPanelFrmHandle);
|
||||
}
|
||||
_elevatorBackgroundFrmImage.unlock();
|
||||
_elevatorPanelFrmImage.unlock();
|
||||
|
||||
for (int index = 0; index < ELEVATOR_FRM_COUNT; index++) {
|
||||
artUnlock(gElevatorFrmHandles[index]);
|
||||
_elevatorFrmImages[index].unlock();
|
||||
}
|
||||
|
||||
if (gElevatorWindowIsoWasEnabled) {
|
||||
|
@ -610,15 +557,15 @@ static int elevatorWindowInit(int elevator)
|
|||
}
|
||||
|
||||
gElevatorWindowBuffer = windowGetBuffer(gElevatorWindow);
|
||||
memcpy(gElevatorWindowBuffer, (unsigned char*)gElevatorBackgroundFrmData, gElevatorBackgroundFrmWidth * gElevatorBackgroundFrmHeight);
|
||||
memcpy(gElevatorWindowBuffer, _elevatorBackgroundFrmImage.getData(), _elevatorBackgroundFrmImage.getWidth() * _elevatorBackgroundFrmImage.getHeight());
|
||||
|
||||
if (gElevatorPanelFrmData != ELEVATOR_BACKGROUND_NULL) {
|
||||
blitBufferToBuffer((unsigned char*)gElevatorPanelFrmData,
|
||||
gElevatorPanelFrmWidth,
|
||||
gElevatorPanelFrmHeight,
|
||||
gElevatorPanelFrmWidth,
|
||||
gElevatorWindowBuffer + gElevatorBackgroundFrmWidth * (gElevatorBackgroundFrmHeight - gElevatorPanelFrmHeight),
|
||||
gElevatorBackgroundFrmWidth);
|
||||
if (_elevatorPanelFrmImage.isLocked()) {
|
||||
blitBufferToBuffer(_elevatorPanelFrmImage.getData(),
|
||||
_elevatorPanelFrmImage.getWidth(),
|
||||
_elevatorPanelFrmImage.getHeight(),
|
||||
_elevatorPanelFrmImage.getWidth(),
|
||||
gElevatorWindowBuffer + _elevatorBackgroundFrmImage.getWidth() * (_elevatorBackgroundFrmImage.getHeight() - _elevatorPanelFrmImage.getHeight()),
|
||||
_elevatorBackgroundFrmImage.getWidth());
|
||||
}
|
||||
|
||||
int y = 40;
|
||||
|
@ -626,14 +573,14 @@ static int elevatorWindowInit(int elevator)
|
|||
int btn = buttonCreate(gElevatorWindow,
|
||||
13,
|
||||
y,
|
||||
gElevatorFrmSizes[ELEVATOR_FRM_BUTTON_DOWN].width,
|
||||
gElevatorFrmSizes[ELEVATOR_FRM_BUTTON_DOWN].height,
|
||||
_elevatorFrmImages[ELEVATOR_FRM_BUTTON_DOWN].getWidth(),
|
||||
_elevatorFrmImages[ELEVATOR_FRM_BUTTON_DOWN].getHeight(),
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
500 + level,
|
||||
gElevatorFrmData[ELEVATOR_FRM_BUTTON_UP],
|
||||
gElevatorFrmData[ELEVATOR_FRM_BUTTON_DOWN],
|
||||
_elevatorFrmImages[ELEVATOR_FRM_BUTTON_UP].getData(),
|
||||
_elevatorFrmImages[ELEVATOR_FRM_BUTTON_DOWN].getData(),
|
||||
NULL,
|
||||
BUTTON_FLAG_TRANSPARENT);
|
||||
if (btn != -1) {
|
||||
|
@ -650,16 +597,11 @@ static void elevatorWindowFree()
|
|||
{
|
||||
windowDestroy(gElevatorWindow);
|
||||
|
||||
if (gElevatorBackgroundFrmData != ELEVATOR_BACKGROUND_NULL) {
|
||||
artUnlock(gElevatorBackgroundFrmHandle);
|
||||
}
|
||||
|
||||
if (gElevatorPanelFrmData != ELEVATOR_BACKGROUND_NULL) {
|
||||
artUnlock(gElevatorPanelFrmHandle);
|
||||
}
|
||||
_elevatorBackgroundFrmImage.unlock();
|
||||
_elevatorPanelFrmImage.unlock();
|
||||
|
||||
for (int index = 0; index < ELEVATOR_FRM_COUNT; index++) {
|
||||
artUnlock(gElevatorFrmHandles[index]);
|
||||
_elevatorFrmImages[index].unlock();
|
||||
}
|
||||
|
||||
scriptsEnable();
|
||||
|
|
Loading…
Reference in New Issue