aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2011-12-23 22:58:54 +0100
committerWillem Jan Palenstijn2011-12-23 23:46:38 +0100
commit8e79608a1de77c54cc6bf0eb23b32b1cc3175677 (patch)
tree82b16216cf6dbbebab9a9853fcbd0718c2380c17
parentbbdbffc10744e4d9e789150ba151c1884c740ae0 (diff)
downloadscummvm-rg350-8e79608a1de77c54cc6bf0eb23b32b1cc3175677.tar.gz
scummvm-rg350-8e79608a1de77c54cc6bf0eb23b32b1cc3175677.tar.bz2
scummvm-rg350-8e79608a1de77c54cc6bf0eb23b32b1cc3175677.zip
DREAMWEB: Move sprite table out of buffers
-rw-r--r--engines/dreamweb/backdrop.cpp2
-rw-r--r--engines/dreamweb/dreambase.h3
-rw-r--r--engines/dreamweb/sprite.cpp67
-rw-r--r--engines/dreamweb/structs.h6
-rw-r--r--engines/dreamweb/stubs.cpp17
5 files changed, 45 insertions, 50 deletions
diff --git a/engines/dreamweb/backdrop.cpp b/engines/dreamweb/backdrop.cpp
index b806ba43a0..875e16805e 100644
--- a/engines/dreamweb/backdrop.cpp
+++ b/engines/dreamweb/backdrop.cpp
@@ -121,7 +121,7 @@ void DreamBase::makeBackOb(SetObject *objData, uint16 x, uint16 y) {
uint16 objDataOffset = (uint8 *)objData - getSegment(data.word(kSetdat)).ptr(0, 0);
assert(objDataOffset % sizeof(SetObject) == 0);
assert(objDataOffset < 128 * sizeof(SetObject));
- sprite->setObjData(objDataOffset);
+ sprite->_objData = objDataOffset;
if (priority == 255)
priority = 0;
sprite->priority = priority;
diff --git a/engines/dreamweb/dreambase.h b/engines/dreamweb/dreambase.h
index 1601cb44b5..32b36a56da 100644
--- a/engines/dreamweb/dreambase.h
+++ b/engines/dreamweb/dreambase.h
@@ -87,7 +87,7 @@ protected:
uint8 _startPal[3*256];
uint8 _endPal[3*256];
uint8 _mainPal[3*256];
- // _spriteTable
+ Common::List<Sprite> _spriteTable;
Common::List<ObjPos> _setList;
Common::List<ObjPos> _freeList;
Common::List<ObjPos> _exList;
@@ -311,7 +311,6 @@ public:
void playChannel1(uint8 index);
// from sprite.cpp
- Sprite *spriteTable();
void printSprites();
void printASprite(const Sprite *sprite);
void clearSprites();
diff --git a/engines/dreamweb/sprite.cpp b/engines/dreamweb/sprite.cpp
index 754f91401b..e2e27bc417 100644
--- a/engines/dreamweb/sprite.cpp
+++ b/engines/dreamweb/sprite.cpp
@@ -24,18 +24,12 @@
namespace DreamGen {
-Sprite *DreamBase::spriteTable() {
- Sprite *sprite = (Sprite *)getSegment(data.word(kBuffers)).ptr(kSpritetable, 16 * sizeof(Sprite));
- return sprite;
-}
-
void DreamBase::printSprites() {
for (size_t priority = 0; priority < 7; ++priority) {
- Sprite *sprites = spriteTable();
- for (size_t j = 0; j < 16; ++j) {
- const Sprite &sprite = sprites[j];
- if (sprite.updateCallback() == 0x0ffff)
- continue;
+ Common::List<Sprite>::const_iterator i;
+ for (i = _spriteTable.begin(); i != _spriteTable.end(); ++i) {
+ const Sprite &sprite = *i;
+ assert(sprite._updateCallback != 0x0ffff);
if (priority != sprite.priority)
continue;
if (sprite.hidden == 1)
@@ -64,24 +58,27 @@ void DreamBase::printASprite(const Sprite *sprite) {
c = 8;
else
c = 0;
- showFrame((const Frame *)getSegment(sprite->frameData()).ptr(0, 0), x, y, sprite->frameNumber, c);
+ showFrame((const Frame *)getSegment(sprite->_frameData).ptr(0, 0), x, y, sprite->frameNumber, c);
}
void DreamBase::clearSprites() {
- memset(spriteTable(), 0xff, sizeof(Sprite) * 16);
+ _spriteTable.clear();
}
Sprite *DreamBase::makeSprite(uint8 x, uint8 y, uint16 updateCallback, uint16 frameData, uint16 somethingInDi) {
- Sprite *sprite = spriteTable();
- while (sprite->frameNumber != 0xff) { // NB: No boundchecking in the original code either
- ++sprite;
- }
+ // Note: the original didn't append sprites here, but filled up the
+ // first unused entry. This can change the order of entries, but since they
+ // are drawn based on the priority field, this shouldn't matter.
+ _spriteTable.push_back(Sprite());
+ Sprite *sprite = &_spriteTable.back();
+
+ memset(sprite, 0xff, sizeof(Sprite));
- sprite->setUpdateCallback(updateCallback);
+ sprite->_updateCallback = updateCallback;
sprite->x = x;
sprite->y = y;
- sprite->setFrameData(frameData);
- WRITE_LE_UINT16(&sprite->w8, somethingInDi);
+ sprite->_frameData = frameData;
+ sprite->w8 = somethingInDi;
sprite->w2 = 0xffff;
sprite->frameNumber = 0;
sprite->delay = 0;
@@ -89,25 +86,25 @@ Sprite *DreamBase::makeSprite(uint8 x, uint8 y, uint16 updateCallback, uint16 fr
}
void DreamBase::spriteUpdate() {
- Sprite *sprites = spriteTable();
- sprites[0].hidden = data.byte(kRyanon);
-
- Sprite *sprite = sprites;
- for (size_t i=0; i < 16; ++i) {
- uint16 updateCallback = sprite->updateCallback();
- if (updateCallback != 0xffff) {
- sprite->w24 = sprite->w2;
- if (updateCallback == addr_mainman) // NB : Let's consider the callback as an enum while more code is not ported to C++
- mainMan(sprite);
- else {
- assert(updateCallback == addr_backobject);
- backObject(sprite);
- }
+ // During the intro the sprite table can be empty
+ if (!_spriteTable.empty())
+ _spriteTable.front().hidden = data.byte(kRyanon);
+
+ Common::List<Sprite>::iterator i;
+ for (i = _spriteTable.begin(); i != _spriteTable.end(); ++i) {
+ Sprite &sprite = *i;
+ assert(sprite._updateCallback != 0xffff);
+
+ sprite.w24 = sprite.w2;
+ if (sprite._updateCallback == addr_mainman) // NB : Let's consider the callback as an enum while more code is not ported to C++
+ mainMan(&sprite);
+ else {
+ assert(sprite._updateCallback == addr_backobject);
+ backObject(&sprite);
}
if (data.byte(kNowinnewroom) == 1)
break;
- ++sprite;
}
}
@@ -228,7 +225,7 @@ void DreamBase::aboutTurn(Sprite *sprite) {
}
void DreamBase::backObject(Sprite *sprite) {
- SetObject *objData = (SetObject *)getSegment(data.word(kSetdat)).ptr(sprite->objData(), 0);
+ SetObject *objData = (SetObject *)getSegment(data.word(kSetdat)).ptr(sprite->_objData, 0);
if (sprite->delay != 0) {
--sprite->delay;
diff --git a/engines/dreamweb/structs.h b/engines/dreamweb/structs.h
index 558b000f19..4d1b1420f9 100644
--- a/engines/dreamweb/structs.h
+++ b/engines/dreamweb/structs.h
@@ -30,13 +30,9 @@ namespace DreamGen {
struct Sprite {
uint16 _updateCallback;
- uint16 updateCallback() const { return READ_LE_UINT16(&_updateCallback); }
- void setUpdateCallback(uint16 v) { WRITE_LE_UINT16(&_updateCallback, v); }
uint16 w2;
uint16 w4;
uint16 _frameData;
- uint16 frameData() const { return READ_LE_UINT16(&_frameData); }
- void setFrameData(uint16 v) { WRITE_LE_UINT16(&_frameData, v); }
uint16 w8;
uint8 x;
uint8 y;
@@ -48,8 +44,6 @@ struct Sprite {
uint8 delay;
uint8 animFrame; // index into SetObject::frames
uint16 _objData;
- uint16 objData() const { return READ_LE_UINT16(&_objData); }
- void setObjData(uint16 v) { WRITE_LE_UINT16(&_objData, v); }
uint8 speed;
uint8 priority;
uint16 w24;
diff --git a/engines/dreamweb/stubs.cpp b/engines/dreamweb/stubs.cpp
index dd1a03411f..b302bce18b 100644
--- a/engines/dreamweb/stubs.cpp
+++ b/engines/dreamweb/stubs.cpp
@@ -981,12 +981,17 @@ void DreamBase::eraseOldObs() {
if (data.byte(kNewobs) == 0)
return;
- Sprite *sprites = spriteTable();
- for (size_t i = 0; i < 16; ++i) {
- Sprite &sprite = sprites[i];
- if (sprite.objData() != 0xffff) {
- memset(&sprite, 0xff, sizeof(Sprite));
- }
+ // Note: the original didn't delete sprites here, but marked the
+ // entries as unused, to be filled again by makeSprite. This can
+ // change the order of entries, but since they are drawn based on the
+ // priority field, this shouldn't matter.
+ Common::List<Sprite>::iterator i;
+ for (i = _spriteTable.begin(); i != _spriteTable.end(); ) {
+ Sprite &sprite = *i;
+ if (sprite._objData != 0xffff)
+ i = _spriteTable.erase(i);
+ else
+ ++i;
}
}