Some more integration of background code into BackgroundInfo.

svn-id: r30731
This commit is contained in:
Nicola Mettifogo 2008-02-02 09:48:07 +00:00
parent 4227c0f7ce
commit 015ad5e469
6 changed files with 53 additions and 60 deletions

View File

@ -330,8 +330,8 @@ void Parallaction_ns::_c_onMouse(void *parm) {
void Parallaction_ns::_c_setMask(void *parm) {
memset(_gfx->_backgroundInfo->mask.data + 3600, 0, 3600);
_gfx->_backgroundInfo->layers[1] = 500;
memset(_gfx->_backgroundInfo.mask.data + 3600, 0, 3600);
_gfx->_backgroundInfo.layers[1] = 500;
return;
}
@ -584,7 +584,7 @@ void Parallaction_ns::_c_sketch(void *parm) {
newx = _rightHandPositions[2*index];
}
Graphics::drawLine(oldx, oldy, newx, newy, 0, zeroMask, _gfx->_backgroundInfo);
Graphics::drawLine(oldx, oldy, newx, newy, 0, zeroMask, &_gfx->_backgroundInfo);
_rightHandAnim->_left = newx;
_rightHandAnim->_top = newy - 20;
@ -606,11 +606,11 @@ void Parallaction_ns::_c_shade(void *parm) {
_rightHandAnim->_top
);
uint16 _di = r.left/4 + r.top * _gfx->_backgroundInfo->mask.internalWidth;
uint16 _di = r.left/4 + r.top * _gfx->_backgroundInfo.mask.internalWidth;
for (uint16 _si = r.top; _si < r.bottom; _si++) {
memset(_gfx->_backgroundInfo->mask.data + _di, 0, r.width()/4+1);
_di += _gfx->_backgroundInfo->mask.internalWidth;
memset(_gfx->_backgroundInfo.mask.data + _di, 0, r.width()/4+1);
_di += _gfx->_backgroundInfo.mask.internalWidth;
}
return;

View File

@ -333,7 +333,7 @@ void Parallaction_ns::drawAnimations() {
if (v18->_flags & kFlagsNoMasked)
layer = 3;
else
layer = _gfx->queryMask(v18->_top + v18->height());
layer = _gfx->_backgroundInfo.getLayer(v18->_top + v18->height());
_gfx->showGfxObj(obj, true);

View File

@ -32,7 +32,6 @@
namespace Parallaction {
#define BUFFER_FOREGROUND 3
#define LABEL_TRANSPARENT_COLOR 0xFF
#define BALLOON_TRANSPARENT_COLOR 2
@ -262,7 +261,7 @@ void Gfx::animatePalette() {
PaletteFxRange *range;
for (uint16 i = 0; i < 4; i++) {
range = &_backgroundInfo->ranges[i];
range = &_backgroundInfo.ranges[i];
if ((range->_flags & 1) == 0) continue; // animated palette
range->_timer += range->_step * 2; // update timer
@ -326,7 +325,7 @@ void Gfx::drawItems() {
Graphics::Surface *surf = g_system->lockScreen();
for (uint i = 0; i < _numItems; i++) {
blt(_items[i].rect, _items[i].data->getData(_items[i].frame), surf, BUFFER_FOREGROUND, 0);
blt(_items[i].rect, _items[i].data->getData(_items[i].frame), surf, LAYER_FOREGROUND, 0);
}
g_system->unlockScreen();
}
@ -340,14 +339,14 @@ void Gfx::drawBalloons() {
for (uint i = 0; i < _numBalloons; i++) {
Common::Rect r(_balloons[i].surface.w, _balloons[i].surface.h);
r.moveTo(_balloons[i].x, _balloons[i].y);
blt(r, (byte*)_balloons[i].surface.getBasePtr(0, 0), surf, BUFFER_FOREGROUND, BALLOON_TRANSPARENT_COLOR);
blt(r, (byte*)_balloons[i].surface.getBasePtr(0, 0), surf, LAYER_FOREGROUND, BALLOON_TRANSPARENT_COLOR);
}
g_system->unlockScreen();
}
void Gfx::updateScreen() {
g_system->copyRectToScreen((const byte*)_backgroundInfo->bg.pixels, _backgroundInfo->bg.pitch, _screenX, _screenY, _vm->_screenWidth, _vm->_screenHeight);
g_system->copyRectToScreen((const byte*)_backgroundInfo.bg.pixels, _backgroundInfo.bg.pitch, _screenX, _screenY, _vm->_screenWidth, _vm->_screenHeight);
Graphics::Surface *surf = g_system->lockScreen();
drawGfxObjects(*surf);
@ -355,7 +354,7 @@ void Gfx::updateScreen() {
if (_halfbrite) {
// FIXME: the implementation of halfbrite is now largely sub-optimal in that a full screen
// rewrite is needed to apply the effect.
byte *src = (byte*)_backgroundInfo->bg.pixels;
byte *src = (byte*)_backgroundInfo.bg.pixels;
byte *dst = (byte*)surf->pixels;
for (int i = 0; i < surf->w*surf->h; i++) {
*dst++ = *src++ | 0x20;
@ -384,7 +383,7 @@ void Gfx::updateScreen() {
// graphic primitives
//
void Gfx::clearBackground() {
memset(_backgroundInfo->bg.pixels, 0, _vm->_screenSize);
memset(_backgroundInfo.bg.pixels, 0, _vm->_screenSize);
}
@ -393,17 +392,17 @@ void Gfx::patchBackground(Graphics::Surface &surf, int16 x, int16 y, bool mask)
Common::Rect r(surf.w, surf.h);
r.moveTo(x, y);
uint16 z = (mask) ? queryMask(y) : BUFFER_FOREGROUND;
blt(r, (byte*)surf.pixels, &_backgroundInfo->bg, z, 0);
uint16 z = (mask) ? _backgroundInfo.getLayer(y) : LAYER_FOREGROUND;
blt(r, (byte*)surf.pixels, &_backgroundInfo.bg, z, 0);
}
void Gfx::fillBackground(const Common::Rect& r, byte color) {
_backgroundInfo->bg.fillRect(r, color);
_backgroundInfo.bg.fillRect(r, color);
}
void Gfx::invertBackground(const Common::Rect& r) {
byte *d = (byte*)_backgroundInfo->bg.getBasePtr(r.left, r.top);
byte *d = (byte*)_backgroundInfo.bg.getBasePtr(r.left, r.top);
for (int i = 0; i < r.height(); i++) {
for (int j = 0; j < r.width(); j++) {
@ -411,7 +410,7 @@ void Gfx::invertBackground(const Common::Rect& r) {
d++;
}
d += (_backgroundInfo->bg.pitch - r.width());
d += (_backgroundInfo.bg.pitch - r.width());
}
}
@ -437,13 +436,13 @@ void Gfx::blt(const Common::Rect& r, byte *data, Graphics::Surface *surf, uint16
uint sPitch = r.width() - q.width();
uint dPitch = surf->w - q.width();
if (_backgroundInfo->mask.data && (z < BUFFER_FOREGROUND)) {
if (_backgroundInfo.mask.data && (z < LAYER_FOREGROUND)) {
for (uint16 i = 0; i < q.height(); i++) {
for (uint16 j = 0; j < q.width(); j++) {
if (*s != transparentColor) {
byte v = _backgroundInfo->mask.getValue(dp.x + j, dp.y + i);
byte v = _backgroundInfo.mask.getValue(dp.x + j, dp.y + i);
if (z >= v) *d = *s;
}
@ -627,14 +626,14 @@ void Gfx::drawLabels() {
if (_labels[i]->_visible) {
Common::Rect r(_labels[i]->_cnv.w, _labels[i]->_cnv.h);
r.moveTo(_labels[i]->_pos);
blt(r, (byte*)_labels[i]->_cnv.getBasePtr(0, 0), surf, BUFFER_FOREGROUND, LABEL_TRANSPARENT_COLOR);
blt(r, (byte*)_labels[i]->_cnv.getBasePtr(0, 0), surf, LAYER_FOREGROUND, LABEL_TRANSPARENT_COLOR);
}
}
if (_floatingLabel) {
Common::Rect r(_floatingLabel->_cnv.w, _floatingLabel->_cnv.h);
r.moveTo(_floatingLabel->_pos);
blt(r, (byte*)_floatingLabel->_cnv.getBasePtr(0, 0), surf, BUFFER_FOREGROUND, LABEL_TRANSPARENT_COLOR);
blt(r, (byte*)_floatingLabel->_cnv.getBasePtr(0, 0), surf, LAYER_FOREGROUND, LABEL_TRANSPARENT_COLOR);
}
g_system->unlockScreen();
@ -727,19 +726,10 @@ void Gfx::copyRect(const Common::Rect &r, Graphics::Surface &src, Graphics::Surf
}
void Gfx::grabBackground(const Common::Rect& r, Graphics::Surface &dst) {
copyRect(r, _backgroundInfo->bg, dst);
copyRect(r, _backgroundInfo.bg, dst);
}
uint16 Gfx::queryMask(uint16 v) {
for (uint16 _si = 0; _si < 3; _si++) {
if (_backgroundInfo->layers[_si+1] > v) return _si;
}
return BUFFER_FOREGROUND;
}
Gfx::Gfx(Parallaction* vm) :
_vm(vm), _disk(vm->_disk) {
@ -762,7 +752,6 @@ Gfx::Gfx(Parallaction* vm) :
_hbCircleRadius = 0;
_font = NULL;
_backgroundInfo = new BackgroundInfo;
return;
}
@ -770,7 +759,6 @@ Gfx::Gfx(Parallaction* vm) :
Gfx::~Gfx() {
freeBackground();
delete _backgroundInfo;
return;
}
@ -826,7 +814,7 @@ int Gfx::createBalloon(int16 w, int16 h, int16 winding, uint16 borderThickness)
winding = (winding == 0 ? 1 : 0);
Common::Rect s(BALLOON_TAIL_WIDTH, BALLOON_TAIL_HEIGHT);
s.moveTo(r.width()/2 - 5, r.bottom - 1);
blt(s, _resBalloonTail[winding], &balloon->surface, BUFFER_FOREGROUND, BALLOON_TRANSPARENT_COLOR);
blt(s, _resBalloonTail[winding], &balloon->surface, LAYER_FOREGROUND, BALLOON_TRANSPARENT_COLOR);
}
_numBalloons++;
@ -1000,25 +988,18 @@ bool Gfx::drawWrappedText(Graphics::Surface* surf, char *text, byte color, int16
}
void Gfx::freeBackground() {
if (!_backgroundInfo)
return;
_backgroundInfo->bg.free();
_backgroundInfo->mask.free();
_backgroundInfo->path.free();
_backgroundInfo.free();
}
void Gfx::setBackground(uint type, const char* name, const char* mask, const char* path) {
if (type == kBackgroundLocation) {
_disk->loadScenery(*_backgroundInfo, name, mask, path);
setPalette(_backgroundInfo->palette);
_palette.clone(_backgroundInfo->palette);
_disk->loadScenery(_backgroundInfo, name, mask, path);
setPalette(_backgroundInfo.palette);
_palette.clone(_backgroundInfo.palette);
} else {
_disk->loadSlide(*_backgroundInfo, name);
setPalette(_backgroundInfo->palette);
_disk->loadSlide(_backgroundInfo, name);
setPalette(_backgroundInfo.palette);
}
}

View File

@ -326,6 +326,8 @@ public:
typedef Common::List<GfxObj*> GfxObjList;
#define LAYER_FOREGROUND 3
struct BackgroundInfo {
uint width;
uint height;
@ -348,6 +350,20 @@ struct BackgroundInfo {
assert(index < 6);
memcpy(&ranges[index], &range, sizeof(PaletteFxRange));
}
uint16 getLayer(uint16 z) {
for (uint16 i = 0; i < 3; i++) {
if (layers[i+1] > z) return i;
}
return LAYER_FOREGROUND;
}
void free() {
bg.free();
mask.free();
path.free();
}
};
@ -394,7 +410,7 @@ public:
void freeItems();
// background surface
BackgroundInfo *_backgroundInfo;
BackgroundInfo _backgroundInfo;
void setBackground(uint type, const char* name, const char* mask, const char* path);
void clearBackground();
void patchBackground(Graphics::Surface &surf, int16 x, int16 y, bool mask = false);
@ -412,10 +428,6 @@ public:
void setHalfbriteMode(bool enable);
void setProjectorPos(int x, int y);
// misc
uint16 queryMask(uint16 v);
void setMask(MaskBuffer *buffer);
// init
Gfx(Parallaction* vm);
virtual ~Gfx();

View File

@ -745,7 +745,7 @@ void Parallaction::freeBackground() {
void Parallaction::setBackground(const char* name, const char* mask, const char* path) {
_gfx->setBackground(kBackgroundLocation, name, mask, path);
_pathBuffer = &_gfx->_backgroundInfo->path;
_pathBuffer = &_gfx->_backgroundInfo.path;
return;
}

View File

@ -132,9 +132,9 @@ DECLARE_LOCATION_PARSER(location) {
// flip();
// }
_gfx->setBackground(&_backgroundInfo->bg);
_gfx->_palette.clone(_backgroundInfo->palette);
_gfx->setPalette(_backgroundInfo->palette);
_gfx->setBackground(&_backgroundInfo.bg);
_gfx->_palette.clone(_backgroundInfo.palette);
_gfx->setPalette(_backgroundInfo.palette);
#endif
if (_tokens[nextToken][0] != '\0') {
@ -273,7 +273,7 @@ DECLARE_LOCATION_PARSER(mask) {
debugC(7, kDebugParser, "LOCATION_PARSER(mask) ");
#if 0
_disk->loadScenery(*_backgroundInfo, NULL, _tokens[1], NULL);
_gfx->setMask(&_backgroundInfo->mask);
_gfx->setMask(&_backgroundInfo.mask);
_gfx->_bgLayers[0] = atoi(_tokens[2]);
_gfx->_bgLayers[1] = atoi(_tokens[3]);
@ -286,7 +286,7 @@ DECLARE_LOCATION_PARSER(path) {
debugC(7, kDebugParser, "LOCATION_PARSER(path) ");
#if 0
_disk->loadScenery(*_backgroundInfo, NULL, NULL, _tokens[1]);
_pathBuffer = &_backgroundInfo->path;
_pathBuffer = &_backgroundInfo.path;
#endif
}