Ticket #7933: directx-20020215.diff
File directx-20020215.diff, 11.3 KB (added by , 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 44 44 #define NOCTLMGR 45 45 #define NOCLIPBOARD 46 46 #define NOMEMMGR 47 #define NOSYSMETRICS 48 #define NOMENUS 47 //#define NOSYSMETRICS // DIRECTX 48 //#define NOMENUS // DIRECTX 49 49 #define NOOPENFILE 50 50 #define NOWH 51 51 #define NOSOUND … … 53 53 54 54 #include <SDL.h> 55 55 #include <windows.h> 56 #include <windowsx.h> // DIRECTX 56 57 #include <stdio.h> 57 58 #include <stdlib.h> 58 59 #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 18 18 * $Header: /cvsroot/scummvm/scummvm/windows.cpp,v 1.24 2001/12/28 15:26:28 strigeus Exp $ 19 19 */ 20 20 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 21 28 #include "stdafx.h" 22 29 #include <assert.h> 23 30 … … 36 43 #define DEST_WIDTH 320 37 44 #define DEST_HEIGHT 200 38 45 39 #define USE_DIRECTX 046 #define USE_DIRECTX 1 40 47 #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 42 53 43 54 #define SAMPLES_PER_SEC 22050 44 55 #define BUFFER_SIZE (8192) 45 56 #define BITS_PER_SAMPLE 16 46 57 47 static bool shutdown;58 //static bool shutdown; 48 59 49 60 50 61 #if USE_GDI … … 63 74 64 75 bool terminated; 65 76 77 #if USE_DIRECTX 78 LPDIRECTDRAW lpdd; 79 LPDIRECTDRAWSURFACE lpddsPrimary; 80 LPDIRECTDRAWSURFACE lpddsSecondary; 81 #endif 82 66 83 #if USE_GDI 67 84 public: 68 85 DIB dib; … … 94 111 #if USE_GDI 95 112 bool allocateDIB(int w, int h); 96 113 #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 97 123 }; 98 124 99 125 void Error(const char *msg) { … … 164 190 break; 165 191 166 192 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 167 199 wm->_scumm->mouse.x = ((int16*)&lParam)[0]; 168 200 wm->_scumm->mouse.y = ((int16*)&lParam)[1]; 201 #endif 169 202 break; 170 203 case WM_LBUTTONDOWN: 171 204 wm->_scumm->_leftBtnPressed |= msClicked|msDown; … … 303 336 ShowWindow(hWnd, SW_SHOW); 304 337 #endif 305 338 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 366 static 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 377 void 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 428 void 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 447 BOOL 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 487 void WndMan::ddrawReleaseSurfaces() 488 { 489 if(lpddsPrimary != NULL) lpddsPrimary->Release(); 490 if(lpddsSecondary != NULL) lpddsSecondary->Release(); 491 } 492 493 494 void WndMan::ddrawRestoreSurfaces() 495 { 496 if(lpddsPrimary->IsLost() == DDERR_SURFACELOST) 497 lpddsPrimary->Restore(); 498 if(lpddsSecondary->IsLost() == DDERR_SURFACELOST) 499 lpddsSecondary->Restore(); 500 } 501 502 503 void WndMan::ddrawRelease() 504 { 505 ddrawReleaseSurfaces(); 506 if(lpdd != NULL) lpdd->Release(); 306 507 } 307 508 509 #endif 510 511 308 512 309 513 bool WndMan::handleMessage() { 310 514 MSG msg; … … 365 569 void outputlittlemask(byte *mask, int w, int h) { 366 570 byte *old = wm->_vgabuf; 367 571 wm->_vgabuf = NULL; 572 #if !USE_DIRECTX 368 573 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 369 578 wm->writeToScreen(); 370 579 wm->_vgabuf = old; 371 580 } … … 388 597 break; 389 598 case 2: 390 599 wm->_vgabuf = NULL; 600 #if !USE_DIRECTX 391 601 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 392 606 break; 393 607 case 3: 394 608 wm->_vgabuf = NULL; 609 #if !USE_DIRECTX 395 610 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 396 615 break; 397 616 case 4: 398 617 wm->_vgabuf = NULL; 618 #if !USE_DIRECTX 399 619 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 400 624 break; 401 625 case 5: 402 626 wm->_vgabuf = NULL; 627 #if !USE_DIRECTX 403 628 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 404 633 break; 405 634 } 406 635 wm->writeToScreen(); … … 409 638 410 639 void blitToScreen(Scumm *s, byte *src,int x, int y, int w, int h) { 411 640 byte *dst; 412 SDL_Rect *r;641 // SDL_Rect *r; 413 642 int i; 414 415 643 dst = (byte*)wm->_vgabuf + y*320 + x; 416 644 417 645 do { … … 429 657 430 658 void updateScreen(Scumm *s) { 431 659 if (s->_palDirtyMax != -1) { 432 wm->setPalette(s->_currentPalette, 0, 256); 660 #if !USE_DIRECTX 661 wm->setPalette(s->_currentPalette, 0, 256); 662 #endif 433 663 s->_palDirtyMax = -1; 434 664 } 435 665 … … 455 685 } 456 686 457 687 void 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 458 721 } 459 722 460 723 void fill_buffer(int16 *buf, int len) {