Patch 667613: Extend gfxUsageBits[]

svn-id: r6453
This commit is contained in:
James Brown 2003-01-14 10:06:56 +00:00
parent 639cb13da1
commit 5bf741f960
12 changed files with 647 additions and 528 deletions

View file

@ -347,7 +347,11 @@ SOURCE=.\scumm\gfx.h
# End Source File
# Begin Source File
SOURCE=.\scumm\imuse.cpp
SOURCE=.\scumm\usage_bits.cpp
# End Source File
# Begin Source File
SOURCE=.\scumm\usage_bits.h
# End Source File
# Begin Source File

View file

@ -28,6 +28,7 @@
#include "costume.h"
#include "resource.h"
#include "sound.h"
#include "usage_bits.h"
#include <math.h>
@ -1100,7 +1101,6 @@ void Actor::animateLimb(int limb, int f)
void Scumm::setActorRedrawFlags(bool fg, bool bg)
{
int i, j;
uint32 bits;
if (_fullRedraw) {
for (j = 0; j < NUM_ACTORS; j++) {
@ -1112,10 +1112,10 @@ void Scumm::setActorRedrawFlags(bool fg, bool bg)
}
} else {
for (i = 0; i < gdi._numStrips; i++) {
bits = gfxUsageBits[_screenStartStrip + i];
if (bits & 0x3FFFFFFF) {
int strip = _screenStartStrip + i;
if (testGfxAnyUsageBits(strip)) {
for (j = 0; j < NUM_ACTORS; j++) {
if ((bits & (1 << j)) && bits != (uint32)(1 << j)) {
if (testGfxUsageBit(strip, j) && testGfxOtherUsageBits(strip, j)) {
Actor *a = derefActor(j);
if (fg)
a->needRedraw = true;
@ -1130,15 +1130,13 @@ void Scumm::setActorRedrawFlags(bool fg, bool bg)
int Scumm::getActorFromPos(int x, int y)
{
uint32 drawbits;
int i;
drawbits = gfxUsageBits[x >> 3];
if (!(drawbits & 0x3FFFFFFF))
if (!testGfxAnyUsageBits(x >> 3))
return 0;
for (i = 1; i < NUM_ACTORS; i++) {
Actor *a = derefActor(i);
if (drawbits & (1 << i) && !getClass(i, 32) && y >= a->top && y <= a->bottom) {
if (testGfxUsageBit(x >> 3, i) && !getClass(i, 32) && y >= a->top && y <= a->bottom) {
return i;
}
}
@ -1541,23 +1539,17 @@ void Actor::remapActorPalette(int r_fact, int g_fact, int b_fact, int threshold)
void Scumm::resetActorBgs()
{
Actor *a;
int i;
uint32 onlyActorFlags, bitpos;
int i, j;
for (i = 0; i < gdi._numStrips; i++) {
onlyActorFlags = (gfxUsageBits[_screenStartStrip + i] &= 0x3FFFFFFF);
int strip = _screenStartStrip + i;
a = getFirstActor();
bitpos = 1;
while (onlyActorFlags) {
if (onlyActorFlags & 1 && a->top != 0xFF && a->needBgReset) {
gfxUsageBits[_screenStartStrip + i] ^= bitpos;
for (j = 0; j < NUM_ACTORS; j++) {
if (testGfxUsageBit(strip, j) && a->top != 0xFF && a->needBgReset) {
clearGfxUsageBit(strip, j);
if ((a->bottom - a->top) >= 0)
gdi.resetBackground(a->top, a->bottom, i);
}
bitpos <<= 1;
onlyActorFlags >>= 1;
a++;
}
}

View file

@ -829,7 +829,7 @@ void AkosRenderer::codec1()
if (v1.skip_width <= 0 || _height <= 0)
return;
_vm->updateDirtyRect(0, x_left, x_right, y_top, y_bottom, 1 << _dirty_id);
_vm->updateDirtyRect(0, x_left, x_right, y_top, y_bottom, _dirty_id);
y_clipping = ((uint) y_bottom > outheight || y_top < 0);
@ -949,7 +949,7 @@ void AkosRenderer::codec5() {
if ((clip_right <= clip_left) || (clip_top >= clip_bottom))
return;
_vm->updateDirtyRect(0, clip_left, clip_right + 1, clip_top, clip_bottom + 1, 1 << _dirty_id);
_vm->updateDirtyRect(0, clip_left, clip_right + 1, clip_top, clip_bottom + 1, _dirty_id);
if (_draw_top > clip_top)
_draw_top = clip_top;
@ -1280,7 +1280,7 @@ void AkosRenderer::codec16() {
if ((clip_left >= clip_right) || (clip_top >= clip_bottom))
return;
_vm->updateDirtyRect(0, clip_left, clip_right + 1, clip_top, clip_bottom + 1, 1 << _dirty_id);
_vm->updateDirtyRect(0, clip_left, clip_right + 1, clip_top, clip_bottom + 1, _dirty_id);
if (_draw_top > clip_top)
_draw_top = clip_top;

View file

@ -213,7 +213,7 @@ byte CostumeRenderer::mainRoutine(int slot, int frame)
_scaleIndexXStep = 1;
_ypostop = _ypos;
_vm->updateDirtyRect(0, _left, _right + 1, _top, _bottom, 1 << _dirty_id);
_vm->updateDirtyRect(0, _left, _right + 1, _top, _bottom, _dirty_id);
if (_top >= (int)_outheight || _bottom <= 0)
return 0;

View file

@ -24,6 +24,7 @@
#include "actor.h"
#include "charset.h"
#include "resource.h"
#include "usage_bits.h"
#include "util.h"
@ -295,12 +296,10 @@ VirtScreen *Scumm::findVirtScreen(int y)
return NULL;
}
void Scumm::updateDirtyRect(int virt, int left, int right, int top, int bottom, uint32 dirtybits)
void Scumm::updateDirtyRect(int virt, int left, int right, int top, int bottom, int dirtybit)
{
VirtScreen *vs = &virtscr[virt];
int lp, rp;
uint32 *sp;
int num;
if (top > vs->height || left > vs->width || right < 0 || bottom < 0)
return;
@ -314,7 +313,7 @@ void Scumm::updateDirtyRect(int virt, int left, int right, int top, int bottom,
if (right > vs->width)
right = vs->width;
if (virt == 0 && dirtybits) {
if (virt == 0 && dirtybit) {
lp = (left >> 3) + _screenStartStrip;
if (lp < 0)
lp = 0;
@ -331,13 +330,8 @@ void Scumm::updateDirtyRect(int virt, int left, int right, int top, int bottom,
if (rp >= 200)
rp = 200;
}
if (lp <= rp) {
num = rp - lp + 1;
sp = &gfxUsageBits[lp];
do {
*sp++ |= dirtybits;
} while (--num);
}
for (; lp <= rp; lp++)
setGfxUsageBit(lp, dirtybit);
}
setVirtscreenDirty(vs, left, top, right, bottom);
@ -632,7 +626,7 @@ void Scumm::drawFlashlight()
// Redraw any actors "under" the flashlight
for (i = _flashlight.x/8; i < (_flashlight.x+_flashlight.w)/8; i++) {
gfxUsageBits[_screenStartStrip + i] |= 0x80000000;
setGfxUsageBit(_screenStartStrip + i, USAGE_BIT_DIRTY);
virtscr[0].tdirty[i] = 0;
virtscr[0].bdirty[i] = virtscr[0].height;
}
@ -682,7 +676,7 @@ void Scumm::redrawBGAreas()
// Redraw parts of the background which are marked as dirty.
if (!_fullRedraw && _BgNeedsRedraw) {
for (i = 0; i != gdi._numStrips; i++) {
if (gfxUsageBits[_screenStartStrip + i] & 0x80000000) {
if (testGfxUsageBit(_screenStartStrip + i, USAGE_BIT_DIRTY)) {
redrawBGStrip(i, 1);
}
}
@ -723,10 +717,10 @@ void Scumm::redrawBGStrip(int start, int num)
{
int s = _screenStartStrip + start;
assert(s >= 0 && (size_t) s < sizeof(gfxUsageBits) / sizeof(gfxUsageBits[0]));
assert(s >= 0 && (size_t) s < sizeof(gfxUsageBits) / (3 * sizeof(gfxUsageBits[0])));
for (int i = 0; i < num; i++)
gfxUsageBits[s + i] |= 0x80000000;
setGfxUsageBit(s + i, USAGE_BIT_DIRTY);
gdi.drawBitmap(getResourceAddress(rtRoom, _roomResource) + _IM00_offs,
&virtscr[0], s, 0, virtscr[0].height, s, num, 0);
@ -775,7 +769,7 @@ void Scumm::restoreBG(int left, int top, int right, int bottom, byte backColor)
if (bottom >= height)
bottom = height;
updateDirtyRect(vs->number, left, right, top - topline, bottom - topline, 0x40000000);
updateDirtyRect(vs->number, left, right, top - topline, bottom - topline, USAGE_BIT_RESTORED);
int offset = (top - topline) * _realWidth + vs->xstart + left;
backbuff = vs->screenPtr + offset;

View file

@ -27,6 +27,7 @@ SCUMM_OBJS = \
scumm/scummvm.o \
scumm/sound.o \
scumm/string.o \
scumm/usage_bits.o \
scumm/vars.o \
scumm/verbs.o

View file

@ -25,6 +25,7 @@
#include "actor.h"
#include "object.h"
#include "resource.h"
#include "usage_bits.h"
bool Scumm::getClass(int obj, int cls)
{
@ -393,7 +394,7 @@ void Scumm::drawObject(int obj, int arg)
continue;
if (tmp < _screenStartStrip || tmp > _screenEndStrip)
continue;
gfxUsageBits[tmp] |= 0x80000000;
setGfxUsageBit(tmp, USAGE_BIT_DIRTY);
if (tmp < x)
x = tmp;
numstrip++;
@ -762,17 +763,13 @@ void Scumm::clearOwnerOf(int obj)
void Scumm::removeObjectFromRoom(int obj)
{
int i, cnt;
uint32 *ptr;
int i, j;
for (i = 1; i < _numLocalObjects; i++) {
if (_objs[i].obj_nr == (uint16)obj) {
if (_objs[i].width != 0) {
ptr = &gfxUsageBits[_objs[i].x_pos >> 3];
cnt = _objs[i].width >> 3;
do {
*ptr++ |= 0x80000000;
} while (--cnt);
for (j = 0; j < _objs[i].width; j++)
setGfxUsageBit((_objs[i].x_pos >> 3) + j, USAGE_BIT_DIRTY);
}
_BgNeedsRedraw = true;
return;
@ -1619,7 +1616,7 @@ void Scumm::removeBlastObject(BlastObject *eo)
for (i = left_strip; i <= right_strip; i++)
gdi.resetBackground(top, bottom, i);
updateDirtyRect(0, left, right, top, bottom, 0x40000000);
updateDirtyRect(0, left, right, top, bottom, USAGE_BIT_RESTORED);
}
int Scumm::findLocalObjectSlot()

View file

@ -424,9 +424,10 @@ void Scumm::saveOrLoad(Serializer *s, uint32 savegameVersion)
MKLINE(Scumm, _palManipEnd, sleByte, VER_V10),
MKLINE(Scumm, _palManipCounter, sleUint16, VER_V10),
// gfxUsageBits grew from 200 to 410 entries:
// gfxUsageBits grew from 200 to 410 entries. Then 3 * 410 entries:
MKARRAY_OLD(Scumm, gfxUsageBits[0], sleUint32, 200, VER_V8, VER_V9),
MKARRAY(Scumm, gfxUsageBits[0], sleUint32, 410, VER_V10),
MKARRAY_OLD(Scumm, gfxUsageBits[0], sleUint32, 410, VER_V10, VER_V13),
MKARRAY(Scumm, gfxUsageBits[0], sleUint32, 3 * 410, VER_V14),
MKLINE(Scumm, gdi._transparentColor, sleByte, VER_V8),
MKARRAY(Scumm, _currentPalette[0], sleByte, 768, VER_V8),
@ -557,8 +558,15 @@ void Scumm::saveOrLoad(Serializer *s, uint32 savegameVersion)
}
}
// Because old savegames won't fill the entire gfxUsageBits[] array,
// clear it here just to be sure it won't hold any unforseen garbage.
memset(gfxUsageBits, 0, sizeof(gfxUsageBits));
s->saveLoadEntries(this, mainEntries);
if (!s->isSaving() && savegameVersion < VER_V14)
upgradeGfxUsageBits();
s->saveLoadArrayOf(_actors, NUM_ACTORS, sizeof(_actors[0]), actorEntries);
if (savegameVersion < VER_V9)

View file

@ -32,10 +32,11 @@ enum {
VER_V10,
VER_V11,
VER_V12,
VER_V13
VER_V13,
VER_V14
};
#define CURRENT_VER VER_V13
#define CURRENT_VER VER_V14
// To work around a warning in GCC 3.2 (and 3.1 ?) regarding non-POD types,

View file

@ -748,7 +748,7 @@ public:
void useBompCursor(byte *im, int w, int h);
void updateDirtyRect(int virt, int left, int right, int top, int bottom, uint32 dirtybits);
void updateDirtyRect(int virt, int left, int right, int top, int bottom, int dirtybit);
void setDirtyRange(int slot, int a, int height);
void drawDirtyScreenParts();
void updateDirtyScreen(int slot);
@ -810,12 +810,18 @@ public:
byte *_palManipPalette;
byte *_palManipIntermediatePal;
/* For each screen strip, gfxUsageBits contains a bitmask.
* The lower 30 bits each correspond to one actor and signify if any part
* of that actor is currently contained in that strip.
* If the left most bit is set, the strip (background) is dirty needs to be redrawn.
/* For each of the 410 screen strips, gfxUsageBits contains a
* bitmask. The lower 80 bits each correspond to one actor and
* signify if any part of that actor is currently contained in
* that strip.
*
* If the leftmost bit is set, the strip (background) is dirty
* needs to be redrawn.
*
* The second leftmost bit is set by removeBlastObject() and
* restoreBG(), but I'm not yet sure why.
*/
uint32 gfxUsageBits[410];
uint32 gfxUsageBits[410 * 3];
byte *_shadowPalette;
int _shadowPaletteSize;
@ -924,6 +930,13 @@ public:
uint32 fileReadDword() { return _fileHandle.readUint32BE(); }
#endif
void upgradeGfxUsageBits();
void setGfxUsageBit(int strip, int bit);
void clearGfxUsageBit(int strip, int bit);
bool testGfxUsageBit(int strip, int bit);
bool testGfxAnyUsageBits(int strip);
bool testGfxOtherUsageBits(int strip, int bit);
/* Scumm Vars */
byte VAR_KEYPRESS;
byte VAR_EGO;

81
scumm/usage_bits.cpp Normal file
View file

@ -0,0 +1,81 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001 Ludvig Strigeus
* Copyright (C) 2001-2003 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
#include "scumm.h"
#include "usage_bits.h"
void Scumm::upgradeGfxUsageBits()
{
int i;
for (i = 409; i >= 0; i--) {
bool dirty_bit = gfxUsageBits[i] & 0x80000000;
bool restored_bit = gfxUsageBits[i] & 0x40000000;
gfxUsageBits[3 * i] = gfxUsageBits[i] & 0x3FFFFFFF;
if (dirty_bit)
setGfxUsageBit(i, USAGE_BIT_DIRTY);
if (restored_bit)
setGfxUsageBit(i, USAGE_BIT_RESTORED);
}
}
void Scumm::setGfxUsageBit(int strip, int bit)
{
gfxUsageBits[3 * strip + bit / 32] |= (1 << (bit - 1));
}
void Scumm::clearGfxUsageBit(int strip, int bit)
{
gfxUsageBits[3 * strip + bit / 32] &= ~(1 << (bit - 1));
}
bool Scumm::testGfxUsageBit(int strip, int bit)
{
return (gfxUsageBits[3 * strip + bit / 32] & (1 << (bit - 1))) != 0;
}
bool Scumm::testGfxAnyUsageBits(int strip)
{
// Exclude the DIRTY and RESTORED bits from the test
uint32 bitmask[3] = { 0x3FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
int i;
for (i = 0; i < 3; i++)
if (gfxUsageBits[3 * strip + i] & bitmask[i])
return true;
return false;
}
bool Scumm::testGfxOtherUsageBits(int strip, int bit)
{
// Don't exclude the DIRTY and RESTORED bits from the test
uint32 bitmask[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
int i;
bitmask[bit / 32] &= ~(1 << (bit - 1));
for (i = 0; i < 3; i++)
if (gfxUsageBits[3 * strip + i] & bitmask[i])
return true;
return false;
}

28
scumm/usage_bits.h Normal file
View file

@ -0,0 +1,28 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001 Ludvig Strigeus
* Copyright (C) 2001-2003 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef USAGE_BITS_H
#define USAGE_BITS_H
enum {
USAGE_BIT_DIRTY = 96,
USAGE_BIT_RESTORED = 95
};
#endif