Ticket #8157: comi-usagebits.diff

File comi-usagebits.diff, 16.2 KB (added by eriktorbjorn, 21 years ago)

Patch against a January 13 CVS snapshot

  • scummvm/scumm/actor.cpp

    diff -urN ScummVM-cvs20030113/scummvm/scumm/actor.cpp ScummVM-cvs20030113+usagebits/scummvm/scumm/actor.cpp
    old new  
    2828#include "costume.h"
    2929#include "resource.h"
    3030#include "sound.h"
     31#include "usage_bits.h"
    3132
    3233#include <math.h>
    3334
     
    11001101void Scumm::setActorRedrawFlags(bool fg, bool bg)
    11011102{
    11021103        int i, j;
    1103         uint32 bits;
    11041104
    11051105        if (_fullRedraw) {
    11061106                for (j = 0; j < NUM_ACTORS; j++) {
     
    11121112                }
    11131113        } else {
    11141114                for (i = 0; i < gdi._numStrips; i++) {
    1115                         bits = gfxUsageBits[_screenStartStrip + i];
    1116                         if (bits & 0x3FFFFFFF) {
     1115                        int strip = _screenStartStrip + i;
     1116                        if (testGfxAnyUsageBits(strip)) {
    11171117                                for (j = 0; j < NUM_ACTORS; j++) {
    1118                                         if ((bits & (1 << j)) && bits != (uint32)(1 << j)) {
     1118                                        if (testGfxUsageBit(strip, j) && testGfxOtherUsageBits(strip, j)) {
    11191119                                                Actor *a = derefActor(j);
    11201120                                                if (fg)
    11211121                                                        a->needRedraw = true;
     
    11301130
    11311131int Scumm::getActorFromPos(int x, int y)
    11321132{
    1133         uint32 drawbits;
    11341133        int i;
    11351134
    1136         drawbits = gfxUsageBits[x >> 3];
    1137         if (!(drawbits & 0x3FFFFFFF))
     1135        if (!testGfxAnyUsageBits(x >> 3))
    11381136                return 0;
    11391137        for (i = 1; i < NUM_ACTORS; i++) {
    11401138                Actor *a = derefActor(i);
    1141                 if (drawbits & (1 << i) && !getClass(i, 32) && y >= a->top && y <= a->bottom) {
     1139                if (testGfxUsageBit(x >> 3, i) && !getClass(i, 32) && y >= a->top && y <= a->bottom) {
    11421140                        return i;
    11431141                }
    11441142        }
     
    15411539void Scumm::resetActorBgs()
    15421540{
    15431541        Actor *a;
    1544         int i;
    1545         uint32 onlyActorFlags, bitpos;
     1542        int i, j;
    15461543
    15471544        for (i = 0; i < gdi._numStrips; i++) {
    1548                 onlyActorFlags = (gfxUsageBits[_screenStartStrip + i] &= 0x3FFFFFFF);
     1545                int strip = _screenStartStrip + i;
    15491546                a = getFirstActor();
    1550                 bitpos = 1;
    1551 
    1552                 while (onlyActorFlags) {
    1553                         if (onlyActorFlags & 1 && a->top != 0xFF && a->needBgReset) {
    1554                                 gfxUsageBits[_screenStartStrip + i] ^= bitpos;
    1555 
     1547                for (j = 0; j < NUM_ACTORS; j++) {
     1548                        if (testGfxUsageBit(strip, j) && a->top != 0xFF && a->needBgReset) {
     1549                                clearGfxUsageBit(strip, j);
    15561550                                if ((a->bottom - a->top) >= 0)
    15571551                                        gdi.resetBackground(a->top, a->bottom, i);
    15581552                        }
    1559                         bitpos <<= 1;
    1560                         onlyActorFlags >>= 1;
    15611553                        a++;
    15621554                }
    15631555        }
  • scummvm/scumm/akos.cpp

    diff -urN ScummVM-cvs20030113/scummvm/scumm/akos.cpp ScummVM-cvs20030113+usagebits/scummvm/scumm/akos.cpp
    old new  
    829829        if (v1.skip_width <= 0 || _height <= 0)
    830830                return;
    831831
    832         _vm->updateDirtyRect(0, x_left, x_right, y_top, y_bottom, 1 << _dirty_id);
     832        _vm->updateDirtyRect(0, x_left, x_right, y_top, y_bottom, _dirty_id);
    833833
    834834        y_clipping = ((uint) y_bottom > outheight || y_top < 0);
    835835
     
    949949        if ((clip_right <= clip_left) || (clip_top >= clip_bottom))
    950950                return;
    951951
    952         _vm->updateDirtyRect(0, clip_left, clip_right + 1, clip_top, clip_bottom + 1, 1 << _dirty_id);
     952        _vm->updateDirtyRect(0, clip_left, clip_right + 1, clip_top, clip_bottom + 1, _dirty_id);
    953953
    954954        if (_draw_top > clip_top)
    955955                _draw_top = clip_top;
     
    12801280        if ((clip_left >= clip_right) || (clip_top >= clip_bottom))
    12811281                return;
    12821282
    1283         _vm->updateDirtyRect(0, clip_left, clip_right + 1, clip_top, clip_bottom + 1, 1 << _dirty_id);
     1283        _vm->updateDirtyRect(0, clip_left, clip_right + 1, clip_top, clip_bottom + 1, _dirty_id);
    12841284
    12851285        if (_draw_top > clip_top)
    12861286                _draw_top = clip_top;
  • scummvm/scumm/costume.cpp

    diff -urN ScummVM-cvs20030113/scummvm/scumm/costume.cpp ScummVM-cvs20030113+usagebits/scummvm/scumm/costume.cpp
    old new  
    213213                _scaleIndexXStep = 1;
    214214        _ypostop = _ypos;
    215215
    216         _vm->updateDirtyRect(0, _left, _right + 1, _top, _bottom, 1 << _dirty_id);
     216        _vm->updateDirtyRect(0, _left, _right + 1, _top, _bottom, _dirty_id);
    217217
    218218        if (_top >= (int)_outheight || _bottom <= 0)
    219219                return 0;
  • scummvm/scumm/gfx.cpp

    diff -urN ScummVM-cvs20030113/scummvm/scumm/gfx.cpp ScummVM-cvs20030113+usagebits/scummvm/scumm/gfx.cpp
    old new  
    2424#include "actor.h"
    2525#include "charset.h"
    2626#include "resource.h"
     27#include "usage_bits.h"
    2728#include "util.h"
    2829
    2930
     
    295296        return NULL;
    296297}
    297298
    298 void Scumm::updateDirtyRect(int virt, int left, int right, int top, int bottom, uint32 dirtybits)
     299void Scumm::updateDirtyRect(int virt, int left, int right, int top, int bottom, int dirtybit)
    299300{
    300301        VirtScreen *vs = &virtscr[virt];
    301302        int lp, rp;
    302         uint32 *sp;
    303         int num;
    304303
    305304        if (top > vs->height || left > vs->width || right < 0 || bottom < 0)
    306305                return;
     
    314313        if (right > vs->width)
    315314                right = vs->width;
    316315
    317         if (virt == 0 && dirtybits) {
     316        if (virt == 0 && dirtybit) {
    318317                lp = (left >> 3) + _screenStartStrip;
    319318                if (lp < 0)
    320319                        lp = 0;
     
    331330                        if (rp >= 200)
    332331                                rp = 200;
    333332                }
    334                 if (lp <= rp) {
    335                         num = rp - lp + 1;
    336                         sp = &gfxUsageBits[lp];
    337                         do {
    338                                 *sp++ |= dirtybits;
    339                         } while (--num);
    340                 }
     333                for (; lp <= rp; lp++)
     334                        setGfxUsageBit(lp, dirtybit);
    341335        }
    342336
    343337        setVirtscreenDirty(vs, left, top, right, bottom);
     
    632626
    633627        // Redraw any actors "under" the flashlight
    634628        for (i = _flashlight.x/8; i < (_flashlight.x+_flashlight.w)/8; i++) {
    635                 gfxUsageBits[_screenStartStrip + i] |= 0x80000000;
     629                setGfxUsageBit(_screenStartStrip + i, USAGE_BIT_DIRTY);
    636630                virtscr[0].tdirty[i] = 0;
    637631                virtscr[0].bdirty[i] = virtscr[0].height;
    638632        }
     
    682676        // Redraw parts of the background which are marked as dirty.
    683677        if (!_fullRedraw && _BgNeedsRedraw) {
    684678                for (i = 0; i != gdi._numStrips; i++) {
    685                         if (gfxUsageBits[_screenStartStrip + i] & 0x80000000) {
     679                        if (testGfxUsageBit(_screenStartStrip + i, USAGE_BIT_DIRTY)) {
    686680                                redrawBGStrip(i, 1);
    687681                        }
    688682                }
     
    723717{
    724718        int s = _screenStartStrip + start;
    725719
    726         assert(s >= 0 && (size_t) s < sizeof(gfxUsageBits) / sizeof(gfxUsageBits[0]));
     720        assert(s >= 0 && (size_t) s < sizeof(gfxUsageBits) / (3 * sizeof(gfxUsageBits[0])));
    727721
    728722        for (int i = 0; i < num; i++)
    729                 gfxUsageBits[s + i] |= 0x80000000;
     723                setGfxUsageBit(s + i, USAGE_BIT_DIRTY);
    730724
    731725        gdi.drawBitmap(getResourceAddress(rtRoom, _roomResource) + _IM00_offs,
    732726                       &virtscr[0], s, 0, virtscr[0].height, s, num, 0);
     
    775769        if (bottom >= height)
    776770                bottom = height;
    777771
    778         updateDirtyRect(vs->number, left, right, top - topline, bottom - topline, 0x40000000);
     772        updateDirtyRect(vs->number, left, right, top - topline, bottom - topline, USAGE_BIT_RESTORED);
    779773
    780774        int offset = (top - topline) * _realWidth + vs->xstart + left;
    781775        backbuff = vs->screenPtr + offset;
  • scummvm/scumm/module.mk

    diff -urN ScummVM-cvs20030113/scummvm/scumm/module.mk ScummVM-cvs20030113+usagebits/scummvm/scumm/module.mk
    old new  
    2727        scumm/scummvm.o \
    2828        scumm/sound.o \
    2929        scumm/string.o \
     30        scumm/usage_bits.o \
    3031        scumm/vars.o \
    3132        scumm/verbs.o
    3233
  • scummvm/scumm/object.cpp

    diff -urN ScummVM-cvs20030113/scummvm/scumm/object.cpp ScummVM-cvs20030113+usagebits/scummvm/scumm/object.cpp
    old new  
    2525#include "actor.h"
    2626#include "object.h"
    2727#include "resource.h"
     28#include "usage_bits.h"
    2829
    2930bool Scumm::getClass(int obj, int cls)
    3031{
     
    393394                        continue;
    394395                if (tmp < _screenStartStrip || tmp > _screenEndStrip)
    395396                        continue;
    396                 gfxUsageBits[tmp] |= 0x80000000;
     397                setGfxUsageBit(tmp, USAGE_BIT_DIRTY);
    397398                if (tmp < x)
    398399                        x = tmp;
    399400                numstrip++;
     
    762763
    763764void Scumm::removeObjectFromRoom(int obj)
    764765{
    765         int i, cnt;
    766         uint32 *ptr;
     766        int i, j;
    767767
    768768        for (i = 1; i < _numLocalObjects; i++) {
    769769                if (_objs[i].obj_nr == (uint16)obj) {
    770770                        if (_objs[i].width != 0) {
    771                                 ptr = &gfxUsageBits[_objs[i].x_pos >> 3];
    772                                 cnt = _objs[i].width >> 3;
    773                                 do {
    774                                         *ptr++ |= 0x80000000;
    775                                 } while (--cnt);
     771                                for (j = 0; j < _objs[i].width; j++)
     772                                        setGfxUsageBit((_objs[i].x_pos >> 3) + j, USAGE_BIT_DIRTY);
    776773                        }
    777774                        _BgNeedsRedraw = true;
    778775                        return;
     
    16191616        for (i = left_strip; i <= right_strip; i++)
    16201617                gdi.resetBackground(top, bottom, i);
    16211618
    1622         updateDirtyRect(0, left, right, top, bottom, 0x40000000);
     1619        updateDirtyRect(0, left, right, top, bottom, USAGE_BIT_RESTORED);
    16231620}
    16241621
    16251622int Scumm::findLocalObjectSlot()
  • scummvm/scumm/saveload.cpp

    diff -urN ScummVM-cvs20030113/scummvm/scumm/saveload.cpp ScummVM-cvs20030113+usagebits/scummvm/scumm/saveload.cpp
    old new  
    424424                MKLINE(Scumm, _palManipEnd, sleByte, VER_V10),
    425425                MKLINE(Scumm, _palManipCounter, sleUint16, VER_V10),
    426426
    427                 // gfxUsageBits grew from 200 to 410 entries:
     427                // gfxUsageBits grew from 200 to 410 entries. Then 3 * 410 entries:
    428428                MKARRAY_OLD(Scumm, gfxUsageBits[0], sleUint32, 200, VER_V8, VER_V9),
    429                 MKARRAY(Scumm, gfxUsageBits[0], sleUint32, 410, VER_V10),
     429                MKARRAY_OLD(Scumm, gfxUsageBits[0], sleUint32, 410, VER_V10, VER_V13),
     430                MKARRAY(Scumm, gfxUsageBits[0], sleUint32, 3 * 410, VER_V14),
    430431
    431432                MKLINE(Scumm, gdi._transparentColor, sleByte, VER_V8),
    432433                MKARRAY(Scumm, _currentPalette[0], sleByte, 768, VER_V8),
     
    557558                }
    558559        }
    559560
     561        // Because old savegames won't fill the entire gfxUsageBits[] array,
     562        // clear it here just to be sure it won't hold any unforseen garbage.
     563        memset(gfxUsageBits, 0, sizeof(gfxUsageBits));
     564
    560565        s->saveLoadEntries(this, mainEntries);
    561566
     567        if (!s->isSaving() && savegameVersion < VER_V14)
     568                upgradeGfxUsageBits();
     569
    562570        s->saveLoadArrayOf(_actors, NUM_ACTORS, sizeof(_actors[0]), actorEntries);
    563571
    564572        if (savegameVersion < VER_V9)
  • scummvm/scumm/saveload.h

    diff -urN ScummVM-cvs20030113/scummvm/scumm/saveload.h ScummVM-cvs20030113+usagebits/scummvm/scumm/saveload.h
    old new  
    3232        VER_V10,
    3333        VER_V11,
    3434        VER_V12,
    35         VER_V13
     35        VER_V13,
     36        VER_V14
    3637};
    3738
    38 #define CURRENT_VER VER_V13
     39#define CURRENT_VER VER_V14
    3940
    4041
    4142// To work around a warning in GCC 3.2 (and 3.1 ?) regarding non-POD types,
  • scummvm/scumm/scumm.h

    diff -urN ScummVM-cvs20030113/scummvm/scumm/scumm.h ScummVM-cvs20030113+usagebits/scummvm/scumm/scumm.h
    old new  
    748748        void useBompCursor(byte *im, int w, int h);
    749749
    750750
    751         void updateDirtyRect(int virt, int left, int right, int top, int bottom, uint32 dirtybits);
     751        void updateDirtyRect(int virt, int left, int right, int top, int bottom, int dirtybit);
    752752        void setDirtyRange(int slot, int a, int height);
    753753        void drawDirtyScreenParts();
    754754        void updateDirtyScreen(int slot);
     
    810810        byte *_palManipPalette;
    811811        byte *_palManipIntermediatePal;
    812812       
    813         /* For each screen strip, gfxUsageBits contains a bitmask.
    814          * The lower 30 bits each correspond to one actor and signify if any part
    815          * of that actor is currently contained in that strip.
    816          * If the left most bit is set, the strip (background) is dirty needs to be redrawn.
     813        /* For each of the 410 screen strips, gfxUsageBits contains a
     814         * bitmask. The lower 80 bits each correspond to one actor and
     815         * signify if any part of that actor is currently contained in
     816         * that strip.
     817         *
     818         * If the leftmost bit is set, the strip (background) is dirty
     819         * needs to be redrawn.
     820         *
     821         * The second leftmost bit is set by removeBlastObject() and
     822         * restoreBG(), but I'm not yet sure why.
    817823         */
    818         uint32 gfxUsageBits[410];
     824        uint32 gfxUsageBits[410 * 3];
    819825       
    820826        byte *_shadowPalette;
    821827        int _shadowPaletteSize;
     
    924930        uint32 fileReadDword() { return _fileHandle.readUint32BE(); }
    925931#endif
    926932
     933        void upgradeGfxUsageBits();
     934        void setGfxUsageBit(int strip, int bit);
     935        void clearGfxUsageBit(int strip, int bit);
     936        bool testGfxUsageBit(int strip, int bit);
     937        bool testGfxAnyUsageBits(int strip);
     938        bool testGfxOtherUsageBits(int strip, int bit);
     939
    927940        /* Scumm Vars */
    928941        byte VAR_KEYPRESS;
    929942        byte VAR_EGO;
  • scummvm/scumm/usage_bits.cpp

    diff -urN ScummVM-cvs20030113/scummvm/scumm/usage_bits.cpp ScummVM-cvs20030113+usagebits/scummvm/scumm/usage_bits.cpp
    old new  
     1/* ScummVM - Scumm Interpreter
     2 * Copyright (C) 2001  Ludvig Strigeus
     3 * Copyright (C) 2001-2003 The ScummVM project
     4 *
     5 * This program is free software; you can redistribute it and/or
     6 * modify it under the terms of the GNU General Public License
     7 * as published by the Free Software Foundation; either version 2
     8 * of the License, or (at your option) any later version.
     9
     10 * This program is distributed in the hope that it will be useful,
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 * GNU General Public License for more details.
     14
     15 * You should have received a copy of the GNU General Public License
     16 * along with this program; if not, write to the Free Software
     17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     18 */
     19
     20#include "stdafx.h"
     21#include "scumm.h"
     22#include "usage_bits.h"
     23
     24void Scumm::upgradeGfxUsageBits()
     25{
     26        int i;
     27
     28        for (i = 409; i >= 0; i--) {
     29                bool dirty_bit = gfxUsageBits[i] & 0x80000000;
     30                bool restored_bit = gfxUsageBits[i] & 0x40000000;
     31               
     32                gfxUsageBits[3 * i] = gfxUsageBits[i] & 0x3FFFFFFF;
     33                if (dirty_bit)
     34                        setGfxUsageBit(i, USAGE_BIT_DIRTY);
     35                if (restored_bit)
     36                        setGfxUsageBit(i, USAGE_BIT_RESTORED);
     37        }
     38}
     39
     40void Scumm::setGfxUsageBit(int strip, int bit)
     41{
     42        gfxUsageBits[3 * strip + bit / 32] |= (1 << (bit - 1));
     43}
     44
     45void Scumm::clearGfxUsageBit(int strip, int bit)
     46{
     47        gfxUsageBits[3 * strip + bit / 32] &= ~(1 << (bit - 1));
     48}
     49
     50bool Scumm::testGfxUsageBit(int strip, int bit)
     51{
     52        return (gfxUsageBits[3 * strip + bit / 32] & (1 << (bit - 1))) != 0;
     53}
     54
     55bool Scumm::testGfxAnyUsageBits(int strip)
     56{
     57        // Exclude the DIRTY and RESTORED bits from the test
     58        uint32 bitmask[3] = { 0x3FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
     59        int i;
     60
     61        for (i = 0; i < 3; i++)
     62                if (gfxUsageBits[3 * strip + i] & bitmask[i])
     63                        return true;
     64
     65        return false;
     66}
     67
     68bool Scumm::testGfxOtherUsageBits(int strip, int bit)
     69{
     70        // Don't exclude the DIRTY and RESTORED bits from the test
     71        uint32 bitmask[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
     72        int i;
     73
     74        bitmask[bit / 32] &= ~(1 << (bit - 1));
     75
     76        for (i = 0; i < 3; i++)
     77                if (gfxUsageBits[3 * strip + i] & bitmask[i])
     78                        return true;
     79
     80        return false;
     81}
  • scummvm/scumm/usage_bits.h

    diff -urN ScummVM-cvs20030113/scummvm/scumm/usage_bits.h ScummVM-cvs20030113+usagebits/scummvm/scumm/usage_bits.h
    old new  
     1/* ScummVM - Scumm Interpreter
     2 * Copyright (C) 2001  Ludvig Strigeus
     3 * Copyright (C) 2001-2003 The ScummVM project
     4 *
     5 * This program is free software; you can redistribute it and/or
     6 * modify it under the terms of the GNU General Public License
     7 * as published by the Free Software Foundation; either version 2
     8 * of the License, or (at your option) any later version.
     9
     10 * This program is distributed in the hope that it will be useful,
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 * GNU General Public License for more details.
     14
     15 * You should have received a copy of the GNU General Public License
     16 * along with this program; if not, write to the Free Software
     17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     18 */
     19
     20#ifndef USAGE_BITS_H
     21#define USAGE_BITS_H
     22
     23enum {
     24        USAGE_BIT_DIRTY = 96,
     25        USAGE_BIT_RESTORED = 95
     26};
     27
     28#endif