Ticket #7933: directx-20020215.diff

File directx-20020215.diff, 11.3 KB (added by cyxx, 23 years ago)
  • .1.0b/stdafx.h

    Only in scummvmdx-0.1.0b: Makefile
    Only in scummvmdx-0.1.0b: Release
    Only in scummvmdx-0.1.0b: _windows.cpp
    Only in scummvmdx-0.1.0b: actor.cpp
    Only in scummvmdx-0.1.0b: akos.cpp
    Only in scummvmdx-0.1.0b: boxes.cpp
    Only in scummvmdx-0.1.0b: copying.txt
    Only in scummvmdx-0.1.0b: costume.cpp
    Only in scummvmdx-0.1.0b: debug.cpp
    Only in scummvmdx-0.1.0b: debugrl.cpp
    Only in scummvmdx-0.1.0b: debugrl.h
    Only in scummvmdx-0.1.0b: gfx.cpp
    Only in scummvmdx-0.1.0b: gui.cpp
    Only in scummvmdx-0.1.0b: gui.h
    Only in scummvmdx-0.1.0b: object.cpp
    Only in scummvmdx-0.1.0b: readme.txt
    Only in scummvmdx-0.1.0b: resource.cpp
    Only in scummvmdx-0.1.0b: saveload.cpp
    Only in scummvmdx-0.1.0b: script.cpp
    Only in scummvmdx-0.1.0b: script_v1.cpp
    Only in scummvmdx-0.1.0b: script_v2.cpp
    Only in scummvmdx-0.1.0b: scumm.h
    Only in scummvmdx-0.1.0b: scummsys.h
    Only in scummvmdx-0.1.0b: scummvm.cpp
    Only in scummvmdx-0.1.0b: scummvm.dsp
    Only in scummvmdx-0.1.0b: scummvm.dsw
    Only in scummvmdx-0.1.0b: scummvm.ncb
    Only in scummvmdx-0.1.0b: scummvm.opt
    Only in scummvmdx-0.1.0b: sdl.cpp
    Only in scummvmdx-0.1.0b: sound
    Only in scummvmdx-0.1.0b: sound.cpp
    Only in scummvmdx-0.1.0b: sound.h
    Only in scummvmdx-0.1.0b: stdafx.cpp
    diff -u scummvm-0.1.0b/stdafx.h scummvmdx-0.1.0b/stdafx.h
    old new  
    4444#define NOCTLMGR
    4545#define NOCLIPBOARD
    4646#define NOMEMMGR
    47 #define NOSYSMETRICS
    48 #define NOMENUS
     47//#define NOSYSMETRICS // DIRECTX
     48//#define NOMENUS // DIRECTX
    4949#define NOOPENFILE
    5050#define NOWH
    5151#define NOSOUND
     
    5353
    5454#include <SDL.h>
    5555#include <windows.h>
     56#include <windowsx.h> // DIRECTX
    5657#include <stdio.h>
    5758#include <stdlib.h>
    5859#include <string.h>
  • .1.0b/windows.cpp

    Only in scummvmdx-0.1.0b: string.cpp
    Only in scummvmdx-0.1.0b: sys.cpp
    Only in scummvmdx-0.1.0b: verbs.cpp
    Only in scummvmdx-0.1.0b: whatsnew.txt
    diff -u scummvm-0.1.0b/windows.cpp scummvmdx-0.1.0b/windows.cpp
    old new  
    1818 * $Header: /cvsroot/scummvm/scummvm/windows.cpp,v 1.24 2001/12/28 15:26:28 strigeus Exp $
    1919 */
    2020
     21/*
     22   (Very ugly) DirectX additions by Gregory Montoir (cyx@frenchkiss.net)
     23   2002.02.12 - started
     24   2002.02.13 - corrected screen bounds, play screen is now completely displayed
     25   2002.02.15 - added mouse cursor
     26 */
     27
    2128#include "stdafx.h"
    2229#include <assert.h>
    2330
     
    3643#define DEST_WIDTH 320
    3744#define DEST_HEIGHT 200
    3845
    39 #define USE_DIRECTX 0
     46#define USE_DIRECTX 1
    4047#define USE_DRAWDIB 0
    41 #define USE_GDI 1
     48#define USE_GDI 0
     49
     50#if USE_DIRECTX
     51#include <ddraw.h>
     52#endif
    4253
    4354#define SAMPLES_PER_SEC 22050
    4455#define BUFFER_SIZE (8192)
    4556#define BITS_PER_SAMPLE 16
    4657
    47 static bool shutdown;
     58//static bool shutdown;
    4859
    4960
    5061#if USE_GDI
     
    6374
    6475        bool terminated;       
    6576
     77#if USE_DIRECTX
     78        LPDIRECTDRAW lpdd;
     79        LPDIRECTDRAWSURFACE lpddsPrimary;
     80        LPDIRECTDRAWSURFACE lpddsSecondary;
     81#endif
     82
    6683#if USE_GDI
    6784public:
    6885        DIB dib;
     
    94111#if USE_GDI
    95112        bool allocateDIB(int w, int h);
    96113#endif
     114
     115#if USE_DIRECTX
     116        byte _realbuf[SRC_WIDTH*SRC_HEIGHT];
     117        BOOL ddrawInit();
     118        void ddrawReleaseSurfaces();
     119        void ddrawRestoreSurfaces();
     120        void ddrawRelease();
     121        void ddrawUpdateBuffer();
     122#endif
    97123};
    98124
    99125void Error(const char *msg) {
     
    164190                        break;
    165191
    166192                case WM_MOUSEMOVE:
     193#if USE_DIRECTX
     194                        RECT r;
     195                        GetClientRect(hWnd, &r);
     196                        wm->_scumm->mouse.x = (SRC_WIDTH * GET_X_LPARAM(lParam)) / (r.right - r.left);
     197                        wm->_scumm->mouse.y = (SRC_HEIGHT * GET_Y_LPARAM(lParam)) / (r.bottom - r.top);
     198#else
    167199                        wm->_scumm->mouse.x = ((int16*)&lParam)[0];
    168200                        wm->_scumm->mouse.y = ((int16*)&lParam)[1];
     201#endif
    169202                        break;
    170203                case WM_LBUTTONDOWN:
    171204                        wm->_scumm->_leftBtnPressed |= msClicked|msDown;
     
    303336        ShowWindow(hWnd, SW_SHOW);
    304337#endif
    305338
     339
     340#if USE_DIRECTX
     341
     342  HWND hwnd;
     343  globWnd = hwnd = CreateWindow("ScummVM", "ScummVM",
     344                                          WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_SIZEBOX,
     345                                          0, 0, 0, 0,  NULL, NULL, hInst, NULL);
     346  SetWindowLong(hwnd, GWL_USERDATA, (long)this);
     347
     348  RECT r;
     349  SetRect(&r, 0, 0, SRC_WIDTH, SRC_HEIGHT);
     350  AdjustWindowRectEx(&r, GetWindowStyle(hwnd), GetMenu(hwnd) != NULL, GetWindowExStyle(hwnd));
     351  MoveWindow(hwnd,
     352                         (GetSystemMetrics(SM_CXSCREEN) - SRC_WIDTH) / 2,
     353             (GetSystemMetrics(SM_CYSCREEN) - SRC_HEIGHT) / 2,
     354             r.right - r.left, r.bottom - r.top, FALSE);
     355  if(!ddrawInit())
     356        Error("DirectDraw init failed!");
     357  ShowWindow(hwnd, SW_SHOW);
     358
     359#endif
     360
     361}
     362
     363
     364#ifdef USE_DIRECTX
     365
     366static unsigned char GetLowestBit(unsigned long p)
     367{
     368  unsigned char pos = 0;
     369  while((p & 1) == 0) {
     370        ++pos;
     371        p >>= 1;
     372  }
     373  return pos;
     374}
     375
     376
     377void WndMan::ddrawUpdateBuffer()
     378{
     379  DDSURFACEDESC ddsd;
     380  memset(&ddsd, '\0', sizeof(ddsd));
     381  ddsd.dwSize = sizeof(ddsd);
     382
     383  HRESULT hr;
     384  hr = lpddsSecondary->Lock(NULL, &ddsd, DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_SURFACEMEMORYPTR, NULL);
     385  if(hr == DDERR_SURFACELOST)
     386        ddrawRestoreSurfaces();
     387  else if(hr == DD_OK) {
     388        _scumm->drawMouse();
     389        byte *p = _vgabuf ? _vgabuf : _realbuf;
     390
     391        DDPIXELFORMAT ddpf = ddsd.ddpfPixelFormat;
     392        int Rshift = GetLowestBit(ddpf.dwRBitMask);
     393        int Gshift = GetLowestBit(ddpf.dwGBitMask);
     394        int Bshift = GetLowestBit(ddpf.dwBBitMask);
     395
     396        BYTE *dst = (BYTE*)ddsd.lpSurface;
     397
     398        int size = ddsd.dwHeight * ddsd.dwWidth;
     399        int i = 0;
     400        while(i < size) {
     401          BYTE r = _scumm->_currentPalette[p[i]*3];
     402          BYTE g = _scumm->_currentPalette[p[i]*3+1];
     403          BYTE b = _scumm->_currentPalette[p[i]*3+2];
     404
     405          DWORD pixel = (r << Rshift) | (g << Gshift) | (b << Bshift);
     406
     407          switch(ddpf.dwRGBBitCount) {
     408          case 32:
     409                *((DWORD*)dst) = pixel;
     410            break;
     411          case 24:
     412            dst[0] = (BYTE)((pixel & 0xFF0000) >> 16);
     413            dst[1] = (BYTE)((pixel & 0x00FF00) >> 8);
     414            dst[2] = (BYTE)((pixel & 0x0000FF));
     415            break;
     416          case 16:
     417                *((WORD*)dst) = (WORD)pixel;
     418            break;
     419          }
     420          dst += ddpf.dwRGBBitCount >> 3;
     421          i++;
     422        }
     423    lpddsSecondary->Unlock(NULL);
     424  }
     425}
     426
     427
     428void WndMan::writeToScreen()
     429{
     430  ddrawUpdateBuffer();
     431  RECT r;
     432  GetClientRect(globWnd, &r);
     433  POINT p;
     434  p.x = r.left;
     435  p.y = r.top;
     436  ClientToScreen(globWnd, &p);
     437  r.left   = p.x;
     438  r.top    = p.y;
     439  r.right  += r.left;
     440  r.bottom += r.top;
     441  HRESULT hr = lpddsPrimary->Blt(&r, lpddsSecondary, NULL, DDBLT_WAIT, NULL);
     442  if(hr == DDERR_SURFACELOST)
     443        ddrawRestoreSurfaces();
     444}
     445
     446
     447BOOL WndMan::ddrawInit()
     448{
     449  DDSURFACEDESC ddsd;
     450  LPDIRECTDRAWCLIPPER lpddc;
     451
     452  if(DirectDrawCreate(NULL, &lpdd, NULL) != DD_OK)
     453        return FALSE;
     454
     455  if(lpdd->SetCooperativeLevel(globWnd, DDSCL_NORMAL) != DD_OK)
     456        return FALSE;
     457 
     458  memset(&ddsd, '\0', sizeof(ddsd));
     459  ddsd.dwSize = sizeof(ddsd);
     460  ddsd.dwFlags = DDSD_CAPS;
     461  ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY;
     462  if(lpdd->CreateSurface(&ddsd, &lpddsPrimary, NULL) != DD_OK)
     463        return FALSE;
     464
     465  if(lpdd->CreateClipper(0, &lpddc, NULL) != DD_OK)
     466        return FALSE;
     467  if(lpddc->SetHWnd(0, globWnd) != DD_OK)
     468        return FALSE;
     469  if(lpddsPrimary->SetClipper(lpddc) != DD_OK)
     470        return FALSE;
     471  lpddc->Release();
     472
     473  memset(&ddsd, '\0', sizeof(ddsd));
     474  ddsd.dwSize = sizeof(ddsd);
     475  ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
     476  ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
     477  ddsd.dwWidth = SRC_WIDTH;
     478  ddsd.dwHeight = SRC_HEIGHT;
     479  if(lpdd->CreateSurface(&ddsd, &lpddsSecondary, NULL) != DD_OK)
     480        return FALSE;
     481
     482  memset(_realbuf, '\0', sizeof(_realbuf));
     483  return TRUE;
     484}
     485
     486
     487void WndMan::ddrawReleaseSurfaces()
     488{
     489  if(lpddsPrimary != NULL) lpddsPrimary->Release();
     490  if(lpddsSecondary != NULL) lpddsSecondary->Release();
     491}
     492
     493
     494void WndMan::ddrawRestoreSurfaces()
     495{
     496  if(lpddsPrimary->IsLost() == DDERR_SURFACELOST)
     497        lpddsPrimary->Restore();
     498  if(lpddsSecondary->IsLost() == DDERR_SURFACELOST)
     499        lpddsSecondary->Restore();
     500}
     501
     502
     503void WndMan::ddrawRelease()
     504{
     505  ddrawReleaseSurfaces();
     506  if(lpdd != NULL) lpdd->Release();
    306507}
    307508
     509#endif
     510
     511
    308512
    309513bool WndMan::handleMessage() {
    310514        MSG msg;
     
    365569void outputlittlemask(byte *mask, int w, int h) {
    366570        byte *old = wm->_vgabuf;
    367571        wm->_vgabuf = NULL;
     572#if !USE_DIRECTX
    368573        decompressMask(wm->dib.buf, mask, w, h);
     574#else
     575        memset(wm->_realbuf, '\0', sizeof(wm->_realbuf));
     576        decompressMask(wm->_realbuf, mask, w, h);
     577#endif
    369578        wm->writeToScreen();   
    370579        wm->_vgabuf = old;
    371580}
     
    388597                break;
    389598        case 2:
    390599                wm->_vgabuf = NULL;
     600#if !USE_DIRECTX
    391601                decompressMask(wm->dib.buf, s->getResourceAddress(rtBuffer, 9)+s->_screenStartStrip);
     602#else
     603                memset(wm->_realbuf, '\0', sizeof(wm->_realbuf));
     604                decompressMask(wm->_realbuf, s->getResourceAddress(rtBuffer, 9)+s->_screenStartStrip);
     605#endif
    392606                break;
    393607        case 3:
    394608                wm->_vgabuf = NULL;
     609#if !USE_DIRECTX
    395610                decompressMask(wm->dib.buf, s->getResourceAddress(rtBuffer, 9)+8160+s->_screenStartStrip);
     611#else
     612                memset(wm->_realbuf, '\0', sizeof(wm->_realbuf));
     613                decompressMask(wm->_realbuf, s->getResourceAddress(rtBuffer, 9)+8160+s->_screenStartStrip);
     614#endif
    396615                break;
    397616        case 4:
    398617                wm->_vgabuf = NULL;
     618#if !USE_DIRECTX
    399619                decompressMask(wm->dib.buf, s->getResourceAddress(rtBuffer, 9)+8160*2+s->_screenStartStrip);
     620#else
     621                memset(wm->_realbuf, '\0', sizeof(wm->_realbuf));
     622                decompressMask(wm->_realbuf, s->getResourceAddress(rtBuffer, 9)+8160*2+s->_screenStartStrip);
     623#endif
    400624                break;
    401625        case 5:
    402626                wm->_vgabuf = NULL;
     627#if !USE_DIRECTX
    403628                decompressMask(wm->dib.buf, s->getResourceAddress(rtBuffer, 9)+8160*3+s->_screenStartStrip);
     629#else
     630                memset(wm->_realbuf, '\0', sizeof(wm->_realbuf));
     631                decompressMask(wm->_realbuf, s->getResourceAddress(rtBuffer, 9)+8160*2+s->_screenStartStrip);
     632#endif
    404633                break;
    405634        }
    406635        wm->writeToScreen();   
     
    409638
    410639void blitToScreen(Scumm *s, byte *src,int x, int y, int w, int h) {
    411640        byte *dst;
    412         SDL_Rect *r;
     641//      SDL_Rect *r;
    413642        int i;
    414 
    415643        dst = (byte*)wm->_vgabuf + y*320 + x;
    416644
    417645        do {
     
    429657
    430658void updateScreen(Scumm *s) {
    431659        if (s->_palDirtyMax != -1) {
    432                 wm->setPalette(s->_currentPalette, 0, 256);     
     660#if !USE_DIRECTX
     661          wm->setPalette(s->_currentPalette, 0, 256);   
     662#endif
    433663                s->_palDirtyMax = -1;
    434664        }
    435665
     
    455685}
    456686
    457687void drawMouse(Scumm *s, int x, int y, int w, int h, byte *buf, bool visible) {
     688#ifdef USE_DIRECTX
     689  static struct {
     690        int offset;
     691        int color;
     692  } old_mouse[4000];
     693  static int nb = 0;
     694
     695  if(wm->_vgabuf) {
     696        if(visible) {
     697          /* clear previous mouse cursor positions */
     698          int i, j;
     699
     700          for(i = 0; i < nb; ++i)
     701                wm->_vgabuf[old_mouse[i].offset] = old_mouse[i].color;
     702          nb = 0;
     703
     704          for(j = 0; j < h && y + j < SRC_HEIGHT && y + j >= 0; ++j, buf+=w) {
     705                for(i = 0; i < w && x + i < SRC_WIDTH && x + i >= 0; ++i) {
     706                  byte color = buf[i];
     707                  if(color != 0xFF) {
     708                        int off = (y + j) * SRC_WIDTH + (x + i);;
     709                        if(nb < 4000) {
     710                          old_mouse[nb].offset = off;
     711                          old_mouse[nb].color  = wm->_vgabuf[off];
     712                          wm->_vgabuf[off] = color;
     713                          ++nb;
     714                        }
     715                  }
     716                }
     717          }
     718        }
     719  }
     720#endif
    458721}
    459722
    460723void fill_buffer(int16 *buf, int len) {