- implemented destructor for Cnv, thus removing calls to Gfx::freeCnv()

- enforced use of getFramePtr instead of Cnv::_array member

svn-id: r26317
This commit is contained in:
Nicola Mettifogo 2007-03-29 18:34:31 +00:00
parent 623ca88022
commit 711865ef63
9 changed files with 34 additions and 53 deletions

View File

@ -168,7 +168,6 @@ void Parallaction::freeAnimations() {
Animation *v4 = (Animation*)_animations._next;
while (v4) {
freeScript(v4->_program);
_vm->_gfx->freeCnv(v4->_cnv);
if (v4->_cnv) delete v4->_cnv;
v4 = (Animation*)v4->_next;

View File

@ -101,6 +101,17 @@ public:
_array = NULL;
}
~Cnv() {
if (_count == 0 || _array == NULL) return;
for (uint16 _si = 0; _si < _count; _si++) {
if (_array[_si])
free(_array[_si]);
}
free(_array);
}
byte* getFramePtr(uint16 index) {
if (index >= _count)
return NULL;

View File

@ -318,7 +318,7 @@ void displayQuestion(Dialogue *q, Cnv *cnv) {
StaticCnv face;
face._width = cnv->_width;
face._height = cnv->_height;
face._data0 = cnv->_array[q->_mood & 0xF];
face._data0 = cnv->getFramePtr(q->_mood & 0xF);
face._data1 = NULL; // cnv->field_8[v60->_mood & 0xF];
_vm->_gfx->flatBlitCnv(&face, QUESTION_CHARACTER_X, QUESTION_CHARACTER_Y, Gfx::kBitFront);
@ -344,7 +344,7 @@ uint16 getDialogueAnswer(Dialogue *q, Cnv *cnv) {
StaticCnv face;
face._width = cnv->_width;
face._height = cnv->_height;
face._data0 = cnv->_array[0];
face._data0 = cnv->getFramePtr(0);
face._data1 = NULL; // cnv->field_8[0];
_vm->_gfx->flatBlitCnv(&face, ANSWER_CHARACTER_X, ANSWER_CHARACTER_Y, Gfx::kBitFront);
@ -399,7 +399,6 @@ void Parallaction::runDialogue(SpeakData *data) {
_vm->_gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
if (isNpc) {
_vm->_gfx->freeCnv(face);
delete face;
}
@ -427,7 +426,7 @@ int16 selectAnswer(Question *q, StaticCnv *cnv) {
if (numAvailableAnswers == 1) {
_vm->_gfx->displayWrappedString(q->_answers[_di], _answerBalloonX[_di], _answerBalloonY[_di], MAX_BALLOON_WIDTH, 0);
cnv->_data0 = _vm->_char._talk->_array[q->_answer_moods[_di] & 0xF];
cnv->_data0 = _vm->_char._talk->getFramePtr(q->_answer_moods[_di] & 0xF);
// cnv->_data1 = _vm->_char._talk->field_8[q->_answer_moods[_di] & 0xF];
_vm->_gfx->flatBlitCnv(cnv, ANSWER_CHARACTER_X, ANSWER_CHARACTER_Y, Gfx::kBitFront);
waitUntilLeftClick();
@ -447,7 +446,7 @@ int16 selectAnswer(Question *q, StaticCnv *cnv) {
_vm->_gfx->displayWrappedString(q->_answers[v2], _answerBalloonX[v2], _answerBalloonY[v2], MAX_BALLOON_WIDTH, 3);
_vm->_gfx->displayWrappedString(q->_answers[_si], _answerBalloonX[_si], _answerBalloonY[_si], MAX_BALLOON_WIDTH, 0);
cnv->_data0 = _vm->_char._talk->_array[q->_answer_moods[_si] & 0xF];
cnv->_data0 = _vm->_char._talk->getFramePtr(q->_answer_moods[_si] & 0xF);
// cnv->_data1 = _vm->_char._talk->field_8[q->_answer_moods[_si] & 0xF];
_vm->_gfx->flatBlitCnv(cnv, ANSWER_CHARACTER_X, ANSWER_CHARACTER_Y, Gfx::kBitFront);
}

View File

@ -552,7 +552,7 @@ void Gfx::displayString(uint16 x, uint16 y, const char *text) {
tmp._width = _font->_width;
tmp._height = _font->_height;
tmp._data0 = _font->_array[c];
tmp._data0 = _font->getFramePtr(c);
flatBlitCnv(&tmp, x, y, kBitFront);
@ -572,7 +572,7 @@ void Gfx::displayBalloonString(uint16 x, uint16 y, const char *text, byte color)
byte c = mapChar(text[i]);
uint16 w = _proportionalFont ? _glyphWidths[(int)c] : 8;
byte *s = _font->_array[c];
byte *s = _font->getFramePtr(c);
byte *d = _buffers[kBitFront] + x + y*SCREEN_WIDTH;
// printf("%i\n", text[i]);
@ -705,7 +705,6 @@ void Gfx::getStringExtent(char *text, uint16 maxwidth, int16* width, int16* heig
void Gfx::setFont(const char* name) {
freeCnv(_font);
if (_font) delete _font;
_font = _vm->_disk->loadFont(name);
@ -757,7 +756,7 @@ void Gfx::makeCnvFromString(StaticCnv *cnv, char *text) {
for (uint16 i = 0; i < len; i++) {
byte c = mapChar(text[i]);
byte *s = _font->_array[c];
byte *s = _font->getFramePtr(c);
byte *d = cnv->_data0 + _font->_width * i;
for (uint16 j = 0; j < _font->_height; j++) {
@ -785,31 +784,6 @@ byte Gfx::mapChar(byte c) {
}
void Gfx::freeCnv(Cnv *cnv) {
// printf("Gfx::freeCnv()\n");
if (!cnv) return;
if (cnv->_count == 0) return;
if (!cnv->_array) return;
for (uint16 _si = 0; _si < cnv->_count; _si++) {
if (cnv->_array[_si]) {
free(cnv->_array[_si]);
}
cnv->_array[_si] = NULL;
}
if (cnv->_array)
free(cnv->_array);
cnv->_count = 0;
cnv->_array = NULL;
return;
}
void Gfx::freeStaticCnv(StaticCnv *cnv) {
// printf("free_static_cnv()\n");
@ -944,7 +918,6 @@ Gfx::~Gfx() {
free(_buffers[kBitBack]);
free(_buffers[kBit2]);
freeCnv(_font);
if (_font) delete _font;
return;

View File

@ -98,7 +98,6 @@ public:
// cnv management
void makeCnvFromString(StaticCnv *cnv, char *text);
void freeCnv(Cnv *cnv);
void freeStaticCnv(StaticCnv *cnv);
void backupDoorBackground(DoorData *data, int16 x, int16 y);
void backupGetBackground(GetData *data, int16 x, int16 y);

View File

@ -187,7 +187,7 @@ void drawInventoryItem(uint16 pos, InventoryItem *item) {
uint16 col = pos % INVENTORY_ITEMS_PER_LINE;
// FIXME: this will end up in a general blit function
byte* s = _vm->_char._objs->_array[item->_index];
byte* s = _vm->_char._objs->getFramePtr(item->_index);
byte* d = _buffer + col * INVENTORYITEM_WIDTH + line * _vm->_char._objs->_height * INVENTORY_WIDTH;
for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) {
memcpy(d, s, INVENTORYITEM_WIDTH);

View File

@ -696,24 +696,26 @@ void Parallaction::changeCursor(int32 index) {
void Parallaction::freeCharacter() {
_vm->_gfx->freeCnv(_vm->_char._normalFrames);
if (_vm->_char._normalFrames) delete _vm->_char._normalFrames;
if (_vm->_char._normalFrames)
delete _vm->_char._normalFrames;
if (!IS_DUMMY_CHARACTER(_vm->_characterName)) {
_vm->_gfx->freeCnv(_vm->_char._miniFrames);
if (_vm->_char._miniFrames) delete _vm->_char._miniFrames;
if (_vm->_char._miniFrames)
delete _vm->_char._miniFrames;
if (_objectsNames) delete _objectsNames;
if (_objectsNames)
delete _objectsNames;
_objectsNames = NULL;
_vm->_gfx->freeCnv(_vm->_char._talk);
if (_vm->_char._talk) delete _vm->_char._talk;
if (_vm->_char._talk)
delete _vm->_char._talk;
_vm->_gfx->freeStaticCnv(_vm->_char._head);
if (_vm->_char._head) delete _vm->_char._head;
if (_vm->_char._head)
delete _vm->_char._head;
_vm->_gfx->freeCnv(_vm->_char._objs);
if (_vm->_char._objs) delete _vm->_char._objs;
if (_vm->_char._objs)
delete _vm->_char._objs;
}
return;

View File

@ -229,7 +229,6 @@ struct Character {
// ._width = 0;
// _talk._height = 0;
// _talk._count = 0;
// _talk._array = NULL;
_head = NULL;
// _head._width = 0;

View File

@ -150,7 +150,6 @@ void Parallaction::freeZones(Node *list) {
case kZoneDoor:
free(z->u.door->_location);
free(z->u.door->_background);
_vm->_gfx->freeCnv(z->u.door->_cnv);
if (z->u.door->_cnv)
delete z->u.door->_cnv;
delete z->u.door;
@ -276,7 +275,7 @@ void Parallaction::parseZoneTypeBlock(Script &script, Zone *z) {
vE0._height = u->door->_cnv->_height;
uint16 _ax = (z->_flags & kFlagsClosed ? 0 : 1);
vE0._data0 = u->door->_cnv->_array[_ax];
vE0._data0 = u->door->_cnv->getFramePtr(_ax);
// _ax = (z->_flags & kFlagsClosed ? 0 : 1);
// vE0._data1 = doorcnv->field_8[_ax];
@ -356,7 +355,7 @@ void displayCharacterComment(ExamineData *data) {
StaticCnv v3C;
v3C._width = _vm->_char._talk->_width;
v3C._height = _vm->_char._talk->_height;
v3C._data0 = _vm->_char._talk->_array[0];
v3C._data0 = _vm->_char._talk->getFramePtr(0);
v3C._data1 = NULL; //_talk->field_8[0];
_vm->_gfx->setFont("comic");
@ -484,7 +483,7 @@ void jobToggleDoor(void *parm, Job *j) {
uint16 _ax = (z->_flags & kFlagsClosed ? 0 : 1);
v14._data0 = z->u.door->_cnv->_array[_ax];
v14._data0 = z->u.door->_cnv->getFramePtr(_ax);
_vm->_gfx->flatBlitCnv(&v14, z->_left, z->_top, Gfx::kBitBack);
_vm->_gfx->flatBlitCnv(&v14, z->_left, z->_top, Gfx::kBit2);