fetchObjectName() no longer assumes that the resource will still be in the

cache after it's been closed. (Currently it always is, but ideally I'd like
for BS to work even if resource caching is disabled.)

svn-id: r13610
This commit is contained in:
Torbjörn Andersson 2004-04-24 12:29:35 +00:00
parent 94962f6655
commit a575576890
10 changed files with 68 additions and 44 deletions

View File

@ -282,10 +282,12 @@ void Sword2Engine::processLayer(byte *file, uint32 layer_number) {
uint32 current_layer_area = layer_head->width * layer_head->height;
if (current_layer_area > _largestLayerArea) {
byte buf[NAME_LEN];
_largestLayerArea = current_layer_area;
sprintf(_largestLayerInfo,
"largest layer: %s layer(%d) is %dx%d",
fetchObjectName(_thisScreen.background_layer_id),
fetchObjectName(_thisScreen.background_layer_id, buf),
layer_number, layer_head->width, layer_head->height);
}
@ -366,10 +368,12 @@ void Sword2Engine::processImage(BuildUnit *build_unit) {
uint32 current_sprite_area = frame_head->width * frame_head->height;
if (current_sprite_area > _largestSpriteArea) {
byte buf[NAME_LEN];
_largestSpriteArea = current_sprite_area;
sprintf(_largestSpriteInfo,
"largest sprite: %s frame(%d) is %dx%d",
fetchObjectName(build_unit->anim_resource),
fetchObjectName(build_unit->anim_resource, buf),
build_unit->anim_pc,
frame_head->width,
frame_head->height);
@ -398,10 +402,13 @@ void Sword2Engine::processImage(BuildUnit *build_unit) {
}
uint32 rv = _graphics->drawSprite(&spriteInfo);
if (rv)
if (rv) {
byte buf[NAME_LEN];
error("Driver Error %.8x with sprite %s (%d) in processImage",
rv, fetchObjectName(build_unit->anim_resource),
rv, fetchObjectName(build_unit->anim_resource, buf),
build_unit->anim_resource);
}
// release the anim resource
_resman->closeResource(build_unit->anim_resource);

View File

@ -158,6 +158,8 @@ void Debugger::buildDebugText(void) {
// general debug info
if (_displayDebugText) {
byte name[NAME_LEN];
/*
// CD in use
sprintf(buf, "CD-%d", currentCD);
@ -171,7 +173,7 @@ void Debugger::buildDebugText(void) {
Logic::_scriptVars[MOUSE_X],
Logic::_scriptVars[MOUSE_Y],
Logic::_scriptVars[CLICKED_ID],
_vm->fetchObjectName(Logic::_scriptVars[CLICKED_ID]));
_vm->fetchObjectName(Logic::_scriptVars[CLICKED_ID], name));
else
sprintf(buf, "last click at %d,%d (---)",
Logic::_scriptVars[MOUSE_X],
@ -184,7 +186,7 @@ void Debugger::buildDebugText(void) {
_vm->_input->_mouseX + _vm->_thisScreen.scroll_offset_x,
_vm->_input->_mouseY + _vm->_thisScreen.scroll_offset_y,
_vm->_mouseTouching,
_vm->fetchObjectName(_vm->_mouseTouching));
_vm->fetchObjectName(_vm->_mouseTouching, name));
else
sprintf(buf, "mouse %d,%d (not touching)",
_vm->_input->_mouseX + _vm->_thisScreen.scroll_offset_x,
@ -199,7 +201,7 @@ void Debugger::buildDebugText(void) {
sprintf(buf, "player %d,%d %s (%d) #%d/%d",
_vm->_thisScreen.player_feet_x,
_vm->_thisScreen.player_feet_y,
_vm->fetchObjectName(_playerGraphic.anim_resource),
_vm->fetchObjectName(_playerGraphic.anim_resource, name),
_playerGraphic.anim_resource,
_playerGraphic.anim_pc,
_playerGraphicNoFrames);
@ -265,7 +267,7 @@ void Debugger::buildDebugText(void) {
if (_vm->_logic->_speechScriptWaiting) {
sprintf(buf, "script waiting for %s (%d)",
_vm->fetchObjectName(_vm->_logic->_speechScriptWaiting),
_vm->fetchObjectName(_vm->_logic->_speechScriptWaiting, name),
_vm->_logic->_speechScriptWaiting);
makeDebugTextBlock(buf, 0, 90);
}

View File

@ -194,11 +194,12 @@ void Logic::printEventList(void) {
for (uint32 i = 0; i < MAX_events; i++) {
if (_eventList[i].id) {
byte buf[NAME_LEN];
uint32 target = _eventList[i].id;
uint32 script = _eventList[i].interact_id;
Debug_Printf("slot %2d: id = %s (%d)\n", i, _vm->fetchObjectName(target), target);
Debug_Printf(" script = %s (%d) pos %d\n", _vm->fetchObjectName(script / 65536), script / 65536, script % 65536);
Debug_Printf("slot %2d: id = %s (%d)\n", i, _vm->fetchObjectName(target, buf), target);
Debug_Printf(" script = %s (%d) pos %d\n", _vm->fetchObjectName(script / 65536, buf), script / 65536, script % 65536);
}
}
}

View File

@ -50,10 +50,11 @@ int32 Logic::fnInitBackground(int32 *params) {
*/
int32 Sword2Engine::initBackground(int32 res, int32 new_palette) {
byte buf[NAME_LEN];
int i;
assert(res);
debug(1, "CHANGED TO LOCATION \"%s\"", fetchObjectName(res));
debug(1, "CHANGED TO LOCATION \"%s\"", fetchObjectName(res, buf));
// The resources age every time a new room is entered.
_resman->passTime();

View File

@ -258,6 +258,7 @@ void Sword2Engine::systemMenuMouse(void) {
}
void Sword2Engine::dragMouse(void) {
byte buf1[NAME_LEN], buf2[NAME_LEN];
MouseEvent *me;
int hit;
@ -329,8 +330,8 @@ void Sword2Engine::dragMouse(void) {
_logic->setPlayerActionEvent(CUR_PLAYER_ID, _mouseTouching);
debug(2, "Used \"%s\" on \"%s\"",
fetchObjectName(Logic::_scriptVars[OBJECT_HELD]),
fetchObjectName(Logic::_scriptVars[CLICKED_ID]));
fetchObjectName(Logic::_scriptVars[OBJECT_HELD], buf1),
fetchObjectName(Logic::_scriptVars[CLICKED_ID], buf2));
// Hide menu - back to normal menu mode
@ -370,8 +371,8 @@ void Sword2Engine::dragMouse(void) {
noHuman();
debug(2, "Used \"%s\" on \"%s\"",
fetchObjectName(Logic::_scriptVars[OBJECT_HELD]),
fetchObjectName(Logic::_scriptVars[COMBINE_BASE]));
fetchObjectName(Logic::_scriptVars[OBJECT_HELD], buf1),
fetchObjectName(Logic::_scriptVars[COMBINE_BASE], buf2));
}
// Refresh the menu
@ -380,6 +381,7 @@ void Sword2Engine::dragMouse(void) {
}
void Sword2Engine::menuMouse(void) {
byte buf[NAME_LEN];
MouseEvent *me;
int hit;
@ -427,7 +429,7 @@ void Sword2Engine::menuMouse(void) {
noHuman();
debug(2, "Right-click on \"%s\" icon",
fetchObjectName(Logic::_scriptVars[OBJECT_HELD]));
fetchObjectName(Logic::_scriptVars[OBJECT_HELD], buf));
return;
}
@ -455,7 +457,7 @@ void Sword2Engine::menuMouse(void) {
setLuggage(_masterMenuList[hit].luggage_resource);
debug(2, "Left-clicked on \"%s\" icon - switch to drag mode",
fetchObjectName(Logic::_scriptVars[OBJECT_HELD]));
fetchObjectName(Logic::_scriptVars[OBJECT_HELD], buf));
}
}
@ -664,16 +666,18 @@ void Sword2Engine::normalMouse(void) {
} else
_logic->setPlayerActionEvent(CUR_PLAYER_ID, _mouseTouching);
byte buf1[NAME_LEN], buf2[NAME_LEN];
if (Logic::_scriptVars[OBJECT_HELD])
debug(2, "Used \"%s\" on \"%s\"",
fetchObjectName(Logic::_scriptVars[OBJECT_HELD]),
fetchObjectName(Logic::_scriptVars[CLICKED_ID]));
fetchObjectName(Logic::_scriptVars[OBJECT_HELD], buf1),
fetchObjectName(Logic::_scriptVars[CLICKED_ID], buf2));
else if (Logic::_scriptVars[LEFT_BUTTON])
debug(2, "Left-clicked on \"%s\"",
fetchObjectName(Logic::_scriptVars[CLICKED_ID]));
fetchObjectName(Logic::_scriptVars[CLICKED_ID], buf1));
else // RIGHT BUTTON
debug(2, "Right-clicked on \"%s\"",
fetchObjectName(Logic::_scriptVars[CLICKED_ID]));
fetchObjectName(Logic::_scriptVars[CLICKED_ID], buf1));
}
}
@ -731,8 +735,11 @@ void Sword2Engine::mouseOnOff(void) {
if (Logic::_scriptVars[OBJECT_HELD]) {
setLuggage(_currentLuggageResource);
}
} else
error("ERROR: mouse.pointer==0 for object %d (%s) - update logic script!", _mouseTouching, fetchObjectName(_mouseTouching));
} else {
byte buf[NAME_LEN];
error("ERROR: mouse.pointer==0 for object %d (%s) - update logic script!", _mouseTouching, fetchObjectName(_mouseTouching, buf));
}
} else if (_oldMouseTouching && !_mouseTouching) {
// the cursor has moved off something - reset cursor to
// normal pointer

View File

@ -208,19 +208,12 @@ bool Sword2Engine::checkTextLine(byte *file, uint32 text_line) {
return text_line < text_header->noOfLines;
}
byte *Sword2Engine::fetchObjectName(int32 resourceId) {
StandardHeader *header;
header = (StandardHeader *) _resman->openResource(resourceId);
byte *Sword2Engine::fetchObjectName(int32 resourceId, byte *buf) {
StandardHeader *header = (StandardHeader *) _resman->openResource(resourceId);
memcpy(buf, header->name, NAME_LEN);
_resman->closeResource(resourceId);
// Note this pointer is no longer valid, but it should be ok until
// another resource is opened!
// FIXME: I don't like the sound of this at all. Though thanks to the
// resource caching, at least it will still point to malloced memory.
return header->name;
return buf;
}
} // End of namespace Sword2

View File

@ -186,7 +186,9 @@ int32 Logic::fnPlayFx(int32 *params) {
break;
}
debug(0, "SFX (sample=\"%s\", vol=%d, pan=%d, delay=%d, type=%s)", _vm->fetchObjectName(params[0]), params[3], params[4], params[2], type);
byte buf[NAME_LEN];
debug(0, "SFX (sample=\"%s\", vol=%d, pan=%d, delay=%d, type=%s)", _vm->fetchObjectName(params[0], buf), params[3], params[4], params[2], type);
}
while (j < FXQ_LENGTH && _vm->_fxQueue[j].resource != 0)

View File

@ -208,9 +208,11 @@ int32 Logic::fnChoose(int32 *params) {
debug(5, "Icons available:");
byte buf[NAME_LEN];
// change icons
for (i = 0; i < _scriptVars[IN_SUBJECT]; i++) {
debug(5, "%s", _vm->fetchObjectName(_subjectList[i].res));
debug(5, "%s", _vm->fetchObjectName(_subjectList[i].res, buf));
// change all others to grey
if (i != (uint32) hit) {
@ -220,7 +222,7 @@ int32 Logic::fnChoose(int32 *params) {
}
}
debug(2, "Selected: %s", _vm->fetchObjectName(_subjectList[hit].res));
debug(2, "Selected: %s", _vm->fetchObjectName(_subjectList[hit].res, buf));
// this is our looping flag
_choosing = false;
@ -982,8 +984,11 @@ int32 Logic::fnISpeak(int32 *params) {
if (_scriptVars[PLAYER_ID] != CUR_PLAYER_ID)
debug(5, "(%d) Nico: %s", _officialTextNumber, text + 2);
else
debug(5, "(%d) %s: %s", _officialTextNumber, _vm->fetchObjectName(_scriptVars[ID]), text + 2);
else {
byte buf[NAME_LEN];
debug(5, "(%d) %s: %s", _officialTextNumber, _vm->fetchObjectName(_scriptVars[ID], buf), text + 2);
}
// Set up the speech animation

View File

@ -275,7 +275,7 @@ public:
byte *fetchTextLine(byte *file, uint32 text_line);
bool checkTextLine(byte *file, uint32 text_line);
byte *fetchPaletteMatchTable(byte *screenFile);
byte *fetchObjectName(int32 resourceId);
byte *fetchObjectName(int32 resourceId, byte *buf);
// savegame file header

View File

@ -243,11 +243,13 @@ int32 Logic::fnWalkToAnim(int32 *params) {
// coords (which should be set beforehand in the script).
if (pars[4] == 0 && pars[5] == 0) {
byte buf[NAME_LEN];
pars[4] = _standbyX;
pars[5] = _standbyY;
pars[6] = _standbyDir;
debug(3, "WARNING: fnWalkToAnim(%s) used standby coords", _vm->fetchObjectName(params[4]));
debug(3, "WARNING: fnWalkToAnim(%s) used standby coords", _vm->fetchObjectName(params[4], buf));
}
assert(pars[6] >= 0 && pars[6] <= 7);
@ -374,11 +376,13 @@ int32 Logic::fnStandAfterAnim(int32 *params) {
// should be set beforehand in the script)
if (pars[2] == 0 && pars[3] == 0) {
byte buf[NAME_LEN];
pars[2] = _standbyX;
pars[3] = _standbyY;
pars[4] = _standbyDir;
debug(3, "WARNING: fnStandAfterAnim(%s) used standby coords", _vm->fetchObjectName(params[2]));
debug(3, "WARNING: fnStandAfterAnim(%s) used standby coords", _vm->fetchObjectName(params[2], buf));
}
assert(pars[4] >= 0 && pars[4] <= 7);
@ -412,11 +416,13 @@ int32 Logic::fnStandAtAnim(int32 *params) {
// be set beforehand in the script)
if (pars[2] == 0 && pars[3] == 0) {
byte buf[NAME_LEN];
pars[2] = _standbyX;
pars[3] = _standbyY;
pars[4] = _standbyDir;
debug(3, "WARNING: fnStandAtAnim(%s) used standby coords", _vm->fetchObjectName(params[2]));
debug(3, "WARNING: fnStandAtAnim(%s) used standby coords", _vm->fetchObjectName(params[2], buf));
}
assert(pars[4] >= 0 && pars[4] <= 7);