Ticket #7927: scummvm-shake2.patch

File scummvm-shake2.patch, 8.0 KB (added by SF/stauff1, 22 years ago)
  • gfx.cpp

    diff -Naur scummvm/gfx.cpp scummvm-shake-patch/gfx.cpp
    old new  
    14091409}
    14101410
    14111411void Scumm::setShake(int mode) {
    1412         if (mode!=-1)
     1412        if (mode < 0)
     1413                _shakeMode = 0;
     1414        else
    14131415                _shakeMode = mode;
    1414         else
    1415                 mode = 0;
    1416         /* XXX: not implemented */
    1417         warning("stub setShake(%d)",mode);
     1416
     1417        if (_shakeMode) _shakeFrame = 0;
     1418
     1419        updateScreen(this);
     1420
     1421        warning("stub setShake(%d) - half implemented",mode);
    14181422}
    14191423
    14201424void Gdi::clearUpperMask() {
  • scumm.h

    diff -Naur scummvm/scumm.h scummvm-shake-patch/scumm.h
    old new  
    10341034               
    10351035        int16 _talkDelay;
    10361036        int16 _shakeMode;
     1037        int16 _shakeFrame;
     1038        uint32 _shakeTicks;
    10371039
    10381040        int16 _virtual_mouse_x, _virtual_mouse_y;
    10391041
  • sdl.cpp

    diff -Naur scummvm/sdl.cpp scummvm-shake-patch/sdl.cpp
    old new  
    2929#include "SDL_thread.h"
    3030
    3131#define SCALEUP_2x2
     32#define MIN_SHAKE_MS 150
    3233
    3334Scumm scumm;
    3435ScummDebugger debugger;
     
    3839SOUND_DRIVER_TYPE snd_driv;
    3940
    4041static SDL_Surface *screen;
     42static SDL_Surface *shakebuf;
     43static SDL_Surface *blackness;
    4144
    4245void updateScreen(Scumm *s);
    4346
     
    5659                colors[i].unused = 0;
    5760        }
    5861       
     62        SDL_SetColors(shakebuf, colors, first, num);
    5963        SDL_SetColors(screen, colors, first, num);
    6064       
    6165        s->_palDirtyMax = -1;
     
    202206void blitToScreen(Scumm *s, byte *src,int x, int y, int w, int h) {
    203207        byte *dst;
    204208        int i;
     209        SDL_Surface *target;
    205210
    206211        hide_mouse = true;
    207212        if (has_mouse) {
    208213                s->drawMouse();
    209214        }
    210215
    211         if (SDL_LockSurface(screen)==-1)
     216        if (s->_shakeMode || s->_shakeFrame) {
     217                target = shakebuf;
     218        } else {
     219                target = screen;
     220        }
     221
     222        if (SDL_LockSurface(target)==-1)
    212223                error("SDL_LockSurface failed: %s.\n", SDL_GetError());
    213224
    214225#if !defined(SCALEUP_2x2)
    215         dst = (byte*)screen->pixels + y*320 + x;
    216         addDirtyRect(x,y,w,h);
     226        dst = (byte*)target->pixels + y*320 + x;
     227                if (s->_shakeMode)
     228                        addDirtyRectClipped(x, y-4, w, h+8);
     229                else
     230                        addDirtyRect(x,y,w,h);
    217231        do {
    218232                memcpy(dst, src, w);
    219233                dst += 320;
    220234                src += 320;
    221235        } while (--h);
    222236#else
    223         dst = (byte*)screen->pixels + y*640*2 + x*2;
    224         addDirtyRect(x,y,w,h);         
     237        dst = (byte*)target->pixels + y*640*2 + x*2;
     238        if (s->_shakeMode)
     239                addDirtyRectClipped(x, y-4, w, h+8);
     240        else
     241                addDirtyRect(x,y,w,h);
    225242        do {
    226243                i=0;
    227244                do {
     
    234251
    235252#endif
    236253
    237         SDL_UnlockSurface(screen);
     254        SDL_UnlockSurface(target);
    238255}
    239256
    240257void updateScreen(Scumm *s) {
     258        SDL_Rect srcr, destr;
    241259
    242260        if (s->_fastMode&2)
    243261                return;
     
    247265                s->drawMouse();
    248266        }
    249267       
     268        if (s->_shakeMode) {
     269                /* if a shake has just begun, we take a copy of the screen */
     270                if (s->_shakeFrame == 0) {
     271                        if (SDL_BlitSurface(screen, NULL, shakebuf, NULL))
     272                                error("SDL_BlitSurface failed: %s.\n", SDL_GetError());
     273                }
     274
     275
     276
     277                destr.x = 0; destr.y = 0;
     278                destr.w = shakebuf->w;
     279                srcr.x = 0; srcr.y = 0;
     280                srcr.w = screen->w;
     281
     282#if defined(SCALEUP_2x2)
     283                destr.h = shakebuf->h-4;
     284                srcr.h = screen->h-4;
     285#else
     286                destr.h = shakebuf->h-2;
     287                srcr.h = screen->h-2;
     288#endif
     289
     290                /* compensate for the fact that this will be called much more
     291                 * during mouse movement */
     292                if (((SDL_GetTicks()) >= s->_shakeTicks + MIN_SHAKE_MS) ||
     293                                (s->_shakeFrame == 0)) {
     294                        s->_shakeFrame++;
     295                        s->_shakeTicks = SDL_GetTicks();
     296                        fullRedraw = true;
     297                }
     298                if (s->_shakeFrame % 2) {
     299#if defined(SCALEUP_2x2)
     300                        srcr.y += 4;
     301#else
     302                        srcr.y += 2;
     303#endif
     304
     305                } else {
     306#if defined(SCALEUP_2x2)
     307                        destr.y += 4;
     308#else
     309                        destr.y += 2;
     310#endif
     311                }
     312
     313
     314                if (SDL_BlitSurface(shakebuf, &srcr, screen, &destr))
     315                        error("SDL_BlitSurface failed: %s.\n", SDL_GetError());
     316
     317
     318#if defined(SCALEUP_2x2)
     319                destr.h = 4;
     320                if (s->_shakeFrame % 2)
     321                        destr.y = screen->h-4;
     322                else
     323                        destr.y = 0;
     324#else
     325                destr.h = 2;
     326                if (s->_shakeFrame % 2)
     327                        destr.y = screen->h-2;
     328                else
     329                        destr.y = 0;
     330#endif
     331                if (SDL_BlitSurface(blackness, NULL, screen, &destr))
     332                        error("SDL_BlitSurface failed: %s.\n", SDL_GetError());
     333
     334        } else if (s->_shakeFrame) {
     335                /* shake has just ended, clean up */
     336                fullRedraw = true;
     337                if (SDL_BlitSurface(shakebuf, NULL, screen, NULL))
     338                        error("SDL_BlitSurface failed: %s.\n", SDL_GetError());
     339                s->_shakeFrame = 0;
     340        }
     341
    250342        if(s->_palDirtyMax != -1) {
    251343                updatePalette(s);
    252344        }
     345
    253346        if (fullRedraw) {
    254347                SDL_UpdateRect(screen, 0,0,0,0);
     348                fullRedraw = false;
    255349#if defined(SHOW_AREA)
    256350                debug(2,"update area 100 %%");
    257351#endif
     
    273367        int x,y;
    274368        byte *dst,*bak;
    275369        byte color;
     370        SDL_Surface *target;
    276371
    277372        if (hide_mouse)
    278373                visible = false;
    279374
    280         if (SDL_LockSurface(screen)==-1)
     375        if (s->_shakeMode || s->_shakeFrame) {
     376                target = shakebuf;
     377        } else {
     378                target = screen;
     379        }
     380
     381        if (SDL_LockSurface(target)==-1)
    281382                error("SDL_LockSurface failed: %s.\n", SDL_GetError());
    282383
    283384#if defined(SCALEUP_2x2)
    284385
    285386        if (has_mouse) {
    286                 dst = (byte*)screen->pixels + old_mouse_y*640*2 + old_mouse_x*2;
     387                dst = (byte*)target->pixels + old_mouse_y*640*2 + old_mouse_x*2;
    287388                bak = old_backup;
    288389
    289390                for (y=0; y<old_mouse_h; y++,bak+=BAK_WIDTH*2,dst+=640*2) {
     
    299400        }
    300401
    301402        if (visible) {
    302                 dst = (byte*)screen->pixels + ydraw*640*2 + xdraw*2;
     403                dst = (byte*)target->pixels + ydraw*640*2 + xdraw*2;
    303404                bak = old_backup;
    304405
    305406                for (y=0; y<h; y++,dst+=640*2,bak+=BAK_WIDTH*2,buf+=w) {
     
    321422        }
    322423#else
    323424        if (has_mouse) {
    324                 dst = (byte*)screen->pixels + old_mouse_y*320 + old_mouse_x;
     425                dst = (byte*)target->pixels + old_mouse_y*320 + old_mouse_x;
    325426                bak = old_backup;
    326427
    327428                for (y=0; y<old_mouse_h; y++,bak+=BAK_WIDTH,dst+=320) {
     
    335436                }
    336437        }
    337438        if (visible) {
    338                 dst = (byte*)screen->pixels + ydraw*320 + xdraw;
     439                dst = (byte*)target->pixels + ydraw*320 + xdraw;
    339440                bak = old_backup;
    340441
    341442                for (y=0; y<h; y++,dst+=320,bak+=BAK_WIDTH,buf+=w) {
     
    355456
    356457#endif 
    357458
    358         SDL_UnlockSurface(screen);
     459        SDL_UnlockSurface(target);
    359460
    360461        if (has_mouse) {
    361462                has_mouse = false;
    362                 addDirtyRectClipped(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h);
     463                if (s->_shakeMode)
     464                        addDirtyRectClipped(old_mouse_x, old_mouse_y-4, old_mouse_w, old_mouse_h+8);
     465                else
     466                        addDirtyRectClipped(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h);
    363467        }
    364468
    365469        if (visible) {
    366470                has_mouse = true;
    367                 addDirtyRectClipped(xdraw, ydraw, w, h);
     471                if (s->_shakeMode)
     472                        addDirtyRectClipped(xdraw, ydraw-4, w, h+8);
     473                else
     474                        addDirtyRectClipped(xdraw, ydraw, w, h);
    368475                old_mouse_x = xdraw;
    369476                old_mouse_y = ydraw;
    370477                old_mouse_w = w;
     
    430537        }
    431538
    432539#if !defined(SCALEUP_2x2)
    433         screen = SDL_SetVideoMode(320, 200, 8, fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN) : SDL_SWSURFACE);
     540        if (!(screen = SDL_SetVideoMode(320, 200, 8,
     541                        fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN) : SDL_SWSURFACE)))
     542#else
     543        if (!(screen = SDL_SetVideoMode(640, 400, 8,
     544                        fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN) : SDL_SWSURFACE)))
     545#endif
     546                error("SDL_SetVideoMode failed: %s.\n", SDL_GetError());
     547
     548        if (!(shakebuf = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w,
     549                                        screen->h, 8, 0, 0, 0, 0)))
     550                error("SDL_CreateRGBSurface failed: %s.\n", SDL_GetError());
     551
     552#if !defined(SCALEUP_2x2)
     553        if (!(blackness = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, 2,
     554                                        8, 0, 0, 0, 0)))
    434555#else
    435         screen = SDL_SetVideoMode(640, 400, 8, fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN) : SDL_SWSURFACE);
     556        if (!(blackness = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, 4,
     557                                        8, 0, 0, 0, 0)))
    436558#endif
     559                error("SDL_CreateRGBSurface failed: %s.\n", SDL_GetError());
     560
     561        if(SDL_FillRect(blackness, NULL, 0))
     562                error("SDL_FillRect failed: %s.\n", SDL_GetError());
    437563
    438564        printf("%d %d, %d %d, %d %d %d, %d %d %d %d %d\n",
    439565                sizeof(int8), sizeof(uint8),