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.
|
// The maximum number of elevator levels.
|
||||||
#define ELEVATOR_LEVEL_MAX (4)
|
#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
|
// Max number of elevators that can be loaded from elevators.ini. This limit is
|
||||||
// emposed by Sfall.
|
// emposed by Sfall.
|
||||||
#define ELEVATORS_MAX 50
|
#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
|
// 0x570A54
|
||||||
static int gElevatorWindow;
|
static int gElevatorWindow;
|
||||||
|
|
||||||
// 0x570A58
|
|
||||||
static CacheEntry* gElevatorFrmHandles[ELEVATOR_FRM_COUNT];
|
|
||||||
|
|
||||||
// 0x570A64
|
|
||||||
static CacheEntry* gElevatorBackgroundFrmHandle;
|
|
||||||
|
|
||||||
// 0x570A68
|
|
||||||
static CacheEntry* gElevatorPanelFrmHandle;
|
|
||||||
|
|
||||||
// 0x570A6C
|
// 0x570A6C
|
||||||
static unsigned char* gElevatorWindowBuffer;
|
static unsigned char* gElevatorWindowBuffer;
|
||||||
|
|
||||||
// 0x570A70
|
// 0x570A70
|
||||||
static bool gElevatorWindowIsoWasEnabled;
|
static bool gElevatorWindowIsoWasEnabled;
|
||||||
|
|
||||||
// 0x570A74
|
static FrmImage _elevatorFrmImages[ELEVATOR_FRM_COUNT];
|
||||||
static unsigned char* gElevatorFrmData[ELEVATOR_FRM_COUNT];
|
static FrmImage _elevatorBackgroundFrmImage;
|
||||||
|
static FrmImage _elevatorPanelFrmImage;
|
||||||
// 0x570A80
|
|
||||||
static unsigned char* gElevatorBackgroundFrmData;
|
|
||||||
|
|
||||||
// 0x570A84
|
|
||||||
static unsigned char* gElevatorPanelFrmData;
|
|
||||||
|
|
||||||
// Presents elevator dialog for player to pick a desired level.
|
// 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);
|
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);
|
float v42 = 12.0f / (float)(gElevatorLevels[elevator] - 1);
|
||||||
blitBufferToBuffer(
|
blitBufferToBuffer(
|
||||||
gElevatorFrmData[ELEVATOR_FRM_GAUGE] + v18 * (int)((float)(*elevationPtr) * v42),
|
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getData() + v18 * (int)((float)(*elevationPtr) * v42),
|
||||||
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width,
|
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth(),
|
||||||
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].height / 13,
|
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getHeight() / 13,
|
||||||
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width,
|
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth(),
|
||||||
gElevatorWindowBuffer + gElevatorBackgroundFrmWidth * 41 + 121,
|
gElevatorWindowBuffer + _elevatorBackgroundFrmImage.getWidth() * 41 + 121,
|
||||||
gElevatorBackgroundFrmWidth);
|
_elevatorBackgroundFrmImage.getWidth());
|
||||||
windowRefresh(gElevatorWindow);
|
windowRefresh(gElevatorWindow);
|
||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
@ -470,12 +435,12 @@ int elevatorSelectLevel(int elevator, int* mapPtr, int* elevationPtr, int* tileP
|
||||||
unsigned int tick = _get_time();
|
unsigned int tick = _get_time();
|
||||||
v44 += v43;
|
v44 += v43;
|
||||||
blitBufferToBuffer(
|
blitBufferToBuffer(
|
||||||
gElevatorFrmData[ELEVATOR_FRM_GAUGE] + v18 * (int)v44,
|
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getData() + v18 * (int)v44,
|
||||||
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width,
|
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth(),
|
||||||
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].height / 13,
|
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getHeight() / 13,
|
||||||
gElevatorFrmSizes[ELEVATOR_FRM_GAUGE].width,
|
_elevatorFrmImages[ELEVATOR_FRM_GAUGE].getWidth(),
|
||||||
gElevatorWindowBuffer + gElevatorBackgroundFrmWidth * 41 + 121,
|
gElevatorWindowBuffer + _elevatorBackgroundFrmImage.getWidth() * 41 + 121,
|
||||||
gElevatorBackgroundFrmWidth);
|
_elevatorBackgroundFrmImage.getWidth());
|
||||||
|
|
||||||
windowRefresh(gElevatorWindow);
|
windowRefresh(gElevatorWindow);
|
||||||
|
|
||||||
|
@ -514,15 +479,14 @@ static int elevatorWindowInit(int elevator)
|
||||||
int index;
|
int index;
|
||||||
for (index = 0; index < ELEVATOR_FRM_COUNT; index++) {
|
for (index = 0; index < ELEVATOR_FRM_COUNT; index++) {
|
||||||
int fid = buildFid(OBJ_TYPE_INTERFACE, gElevatorFrmIds[index], 0, 0, 0);
|
int fid = buildFid(OBJ_TYPE_INTERFACE, gElevatorFrmIds[index], 0, 0, 0);
|
||||||
gElevatorFrmData[index] = artLockFrameDataReturningSize(fid, &(gElevatorFrmHandles[index]), &(gElevatorFrmSizes[index].width), &(gElevatorFrmSizes[index].height));
|
if (!_elevatorFrmImages[index].lock(fid)) {
|
||||||
if (gElevatorFrmData[index] == NULL) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index != ELEVATOR_FRM_COUNT) {
|
if (index != ELEVATOR_FRM_COUNT) {
|
||||||
for (int reversedIndex = index - 1; reversedIndex >= 0; reversedIndex--) {
|
for (int reversedIndex = index - 1; reversedIndex >= 0; reversedIndex--) {
|
||||||
artUnlock(gElevatorFrmHandles[reversedIndex]);
|
_elevatorFrmImages[reversedIndex].unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gElevatorWindowIsoWasEnabled) {
|
if (gElevatorWindowIsoWasEnabled) {
|
||||||
|
@ -534,39 +498,27 @@ static int elevatorWindowInit(int elevator)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gElevatorPanelFrmData = ELEVATOR_BACKGROUND_NULL;
|
|
||||||
gElevatorBackgroundFrmData = ELEVATOR_BACKGROUND_NULL;
|
|
||||||
|
|
||||||
const ElevatorBackground* elevatorBackground = &(gElevatorBackgrounds[elevator]);
|
const ElevatorBackground* elevatorBackground = &(gElevatorBackgrounds[elevator]);
|
||||||
bool backgroundsLoaded = true;
|
bool backgroundsLoaded = true;
|
||||||
|
|
||||||
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, elevatorBackground->backgroundFrmId, 0, 0, 0);
|
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, elevatorBackground->backgroundFrmId, 0, 0, 0);
|
||||||
gElevatorBackgroundFrmData = artLockFrameDataReturningSize(backgroundFid, &gElevatorBackgroundFrmHandle, &gElevatorBackgroundFrmWidth, &gElevatorBackgroundFrmHeight);
|
if (_elevatorBackgroundFrmImage.lock(backgroundFid)) {
|
||||||
if (gElevatorBackgroundFrmData != NULL) {
|
|
||||||
if (elevatorBackground->panelFrmId != -1) {
|
if (elevatorBackground->panelFrmId != -1) {
|
||||||
int panelFid = buildFid(OBJ_TYPE_INTERFACE, elevatorBackground->panelFrmId, 0, 0, 0);
|
int panelFid = buildFid(OBJ_TYPE_INTERFACE, elevatorBackground->panelFrmId, 0, 0, 0);
|
||||||
gElevatorPanelFrmData = artLockFrameDataReturningSize(panelFid, &gElevatorPanelFrmHandle, &gElevatorPanelFrmWidth, &gElevatorPanelFrmHeight);
|
if (!_elevatorPanelFrmImage.lock(panelFid)) {
|
||||||
if (gElevatorPanelFrmData == NULL) {
|
|
||||||
gElevatorPanelFrmData = ELEVATOR_BACKGROUND_NULL;
|
|
||||||
backgroundsLoaded = false;
|
backgroundsLoaded = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
gElevatorBackgroundFrmData = ELEVATOR_BACKGROUND_NULL;
|
|
||||||
backgroundsLoaded = false;
|
backgroundsLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!backgroundsLoaded) {
|
if (!backgroundsLoaded) {
|
||||||
if (gElevatorBackgroundFrmData != ELEVATOR_BACKGROUND_NULL) {
|
_elevatorBackgroundFrmImage.unlock();
|
||||||
artUnlock(gElevatorBackgroundFrmHandle);
|
_elevatorPanelFrmImage.unlock();
|
||||||
}
|
|
||||||
|
|
||||||
if (gElevatorPanelFrmData != ELEVATOR_BACKGROUND_NULL) {
|
|
||||||
artUnlock(gElevatorPanelFrmHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int index = 0; index < ELEVATOR_FRM_COUNT; index++) {
|
for (int index = 0; index < ELEVATOR_FRM_COUNT; index++) {
|
||||||
artUnlock(gElevatorFrmHandles[index]);
|
_elevatorFrmImages[index].unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gElevatorWindowIsoWasEnabled) {
|
if (gElevatorWindowIsoWasEnabled) {
|
||||||
|
@ -578,26 +530,21 @@ static int elevatorWindowInit(int elevator)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int elevatorWindowX = (screenGetWidth() - gElevatorBackgroundFrmWidth) / 2;
|
int elevatorWindowX = (screenGetWidth() - _elevatorBackgroundFrmImage.getWidth()) / 2;
|
||||||
int elevatorWindowY = (screenGetHeight() - INTERFACE_BAR_HEIGHT - 1 - gElevatorBackgroundFrmHeight) / 2;
|
int elevatorWindowY = (screenGetHeight() - INTERFACE_BAR_HEIGHT - 1 - _elevatorBackgroundFrmImage.getHeight()) / 2;
|
||||||
gElevatorWindow = windowCreate(
|
gElevatorWindow = windowCreate(
|
||||||
elevatorWindowX,
|
elevatorWindowX,
|
||||||
elevatorWindowY,
|
elevatorWindowY,
|
||||||
gElevatorBackgroundFrmWidth,
|
_elevatorBackgroundFrmImage.getWidth(),
|
||||||
gElevatorBackgroundFrmHeight,
|
_elevatorBackgroundFrmImage.getHeight(),
|
||||||
256,
|
256,
|
||||||
WINDOW_FLAG_0x10 | WINDOW_FLAG_0x02);
|
WINDOW_FLAG_0x10 | WINDOW_FLAG_0x02);
|
||||||
if (gElevatorWindow == -1) {
|
if (gElevatorWindow == -1) {
|
||||||
if (gElevatorBackgroundFrmData != ELEVATOR_BACKGROUND_NULL) {
|
_elevatorBackgroundFrmImage.unlock();
|
||||||
artUnlock(gElevatorBackgroundFrmHandle);
|
_elevatorPanelFrmImage.unlock();
|
||||||
}
|
|
||||||
|
|
||||||
if (gElevatorPanelFrmData != ELEVATOR_BACKGROUND_NULL) {
|
|
||||||
artUnlock(gElevatorPanelFrmHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int index = 0; index < ELEVATOR_FRM_COUNT; index++) {
|
for (int index = 0; index < ELEVATOR_FRM_COUNT; index++) {
|
||||||
artUnlock(gElevatorFrmHandles[index]);
|
_elevatorFrmImages[index].unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gElevatorWindowIsoWasEnabled) {
|
if (gElevatorWindowIsoWasEnabled) {
|
||||||
|
@ -610,15 +557,15 @@ static int elevatorWindowInit(int elevator)
|
||||||
}
|
}
|
||||||
|
|
||||||
gElevatorWindowBuffer = windowGetBuffer(gElevatorWindow);
|
gElevatorWindowBuffer = windowGetBuffer(gElevatorWindow);
|
||||||
memcpy(gElevatorWindowBuffer, (unsigned char*)gElevatorBackgroundFrmData, gElevatorBackgroundFrmWidth * gElevatorBackgroundFrmHeight);
|
memcpy(gElevatorWindowBuffer, _elevatorBackgroundFrmImage.getData(), _elevatorBackgroundFrmImage.getWidth() * _elevatorBackgroundFrmImage.getHeight());
|
||||||
|
|
||||||
if (gElevatorPanelFrmData != ELEVATOR_BACKGROUND_NULL) {
|
if (_elevatorPanelFrmImage.isLocked()) {
|
||||||
blitBufferToBuffer((unsigned char*)gElevatorPanelFrmData,
|
blitBufferToBuffer(_elevatorPanelFrmImage.getData(),
|
||||||
gElevatorPanelFrmWidth,
|
_elevatorPanelFrmImage.getWidth(),
|
||||||
gElevatorPanelFrmHeight,
|
_elevatorPanelFrmImage.getHeight(),
|
||||||
gElevatorPanelFrmWidth,
|
_elevatorPanelFrmImage.getWidth(),
|
||||||
gElevatorWindowBuffer + gElevatorBackgroundFrmWidth * (gElevatorBackgroundFrmHeight - gElevatorPanelFrmHeight),
|
gElevatorWindowBuffer + _elevatorBackgroundFrmImage.getWidth() * (_elevatorBackgroundFrmImage.getHeight() - _elevatorPanelFrmImage.getHeight()),
|
||||||
gElevatorBackgroundFrmWidth);
|
_elevatorBackgroundFrmImage.getWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
int y = 40;
|
int y = 40;
|
||||||
|
@ -626,14 +573,14 @@ static int elevatorWindowInit(int elevator)
|
||||||
int btn = buttonCreate(gElevatorWindow,
|
int btn = buttonCreate(gElevatorWindow,
|
||||||
13,
|
13,
|
||||||
y,
|
y,
|
||||||
gElevatorFrmSizes[ELEVATOR_FRM_BUTTON_DOWN].width,
|
_elevatorFrmImages[ELEVATOR_FRM_BUTTON_DOWN].getWidth(),
|
||||||
gElevatorFrmSizes[ELEVATOR_FRM_BUTTON_DOWN].height,
|
_elevatorFrmImages[ELEVATOR_FRM_BUTTON_DOWN].getHeight(),
|
||||||
-1,
|
-1,
|
||||||
-1,
|
-1,
|
||||||
-1,
|
-1,
|
||||||
500 + level,
|
500 + level,
|
||||||
gElevatorFrmData[ELEVATOR_FRM_BUTTON_UP],
|
_elevatorFrmImages[ELEVATOR_FRM_BUTTON_UP].getData(),
|
||||||
gElevatorFrmData[ELEVATOR_FRM_BUTTON_DOWN],
|
_elevatorFrmImages[ELEVATOR_FRM_BUTTON_DOWN].getData(),
|
||||||
NULL,
|
NULL,
|
||||||
BUTTON_FLAG_TRANSPARENT);
|
BUTTON_FLAG_TRANSPARENT);
|
||||||
if (btn != -1) {
|
if (btn != -1) {
|
||||||
|
@ -650,16 +597,11 @@ static void elevatorWindowFree()
|
||||||
{
|
{
|
||||||
windowDestroy(gElevatorWindow);
|
windowDestroy(gElevatorWindow);
|
||||||
|
|
||||||
if (gElevatorBackgroundFrmData != ELEVATOR_BACKGROUND_NULL) {
|
_elevatorBackgroundFrmImage.unlock();
|
||||||
artUnlock(gElevatorBackgroundFrmHandle);
|
_elevatorPanelFrmImage.unlock();
|
||||||
}
|
|
||||||
|
|
||||||
if (gElevatorPanelFrmData != ELEVATOR_BACKGROUND_NULL) {
|
|
||||||
artUnlock(gElevatorPanelFrmHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int index = 0; index < ELEVATOR_FRM_COUNT; index++) {
|
for (int index = 0; index < ELEVATOR_FRM_COUNT; index++) {
|
||||||
artUnlock(gElevatorFrmHandles[index]);
|
_elevatorFrmImages[index].unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
scriptsEnable();
|
scriptsEnable();
|
||||||
|
|
Loading…
Reference in New Issue