Ticket #8270: sword2-graphics.diff
File sword2-graphics.diff, 14.3 KB (added by , 21 years ago) |
---|
-
scummvm/bs2/driver/d_draw.cpp
diff -ur ScummVM-cvs20030816/scummvm/bs2/driver/d_draw.cpp ScummVM-cvs20030816+hack/scummvm/bs2/driver/d_draw.cpp
old new 45 45 #define MILLISECSPERCYCLE 83 46 46 47 47 48 // Surface *lpPrimarySurface; 49 Surface *lpBackBuffer; 48 50 49 51 /* 50 52 LPDIRECTDRAW7 m_pDD; … … 234 236 235 237 int32 InitialiseDisplay(int16 width, int16 height, int16 colourDepth, int32 windowType) 236 238 { 239 screenWide = width; 240 screenDeep = height; 241 242 // lpPrimarySurface = new Surface(width, height); 243 lpBackBuffer = new Surface(width, height); 244 237 245 /* 238 246 DDSURFACEDESC ddsd; 239 247 DDSCAPS ddscaps; … … 715 723 int32 FlipScreens(void) 716 724 717 725 { 718 warning("stub FlipScreens"); 726 // I think this function can be removed. We render to lpBackBuffer, 727 // and the backend acts as the primary buffer. 728 729 debug(0, "FlipScreens"); 730 719 731 /* 720 732 HRESULT hr; 721 733 BOOL vbl; … … 825 837 826 838 int32 EraseBackBuffer( void ) 827 839 { 828 warning("stub EraseBackBuffer"); 840 debug(0, "EraseBackBuffer"); 841 lpBackBuffer->clear(); 842 829 843 /* 830 844 DDBLTFX ddbltfx; 831 845 HRESULT hr; … … 1224 1238 // s->lpDraw = lpDraw; 1225 1239 // s->lpDD2 = lpDD2; 1226 1240 // s->lpPrimarySurface = lpPrimarySurface; 1227 //s->lpBackBuffer = lpBackBuffer;1241 s->lpBackBuffer = lpBackBuffer; 1228 1242 // s->lpPalette = lpPalette; 1229 1243 s->screenDeep = screenDeep; 1230 1244 s->screenWide = screenWide; -
scummvm/bs2/driver/d_draw.h
diff -ur ScummVM-cvs20030816/scummvm/bs2/driver/d_draw.h ScummVM-cvs20030816+hack/scummvm/bs2/driver/d_draw.h
old new 78 78 79 79 80 80 extern uint8 *lpPalette; // palette 81 extern uint8*lpBackBuffer; // back surface82 extern uint8*lpPrimarySurface; // DirectDraw front buffer.81 extern Surface *lpBackBuffer; // back surface 82 // extern Surface *lpPrimarySurface; // DirectDraw front buffer. 83 83 extern uint8 *lpDD2; // DirectDraw2 object 84 84 extern BOOL bFullScreen; // Defines whether the app is running in full screen mode or not. 85 85 //extern DDCOLORKEY blackColorKey; // transparent pixel for color key blitting. -
scummvm/bs2/driver/driver96.h
diff -ur ScummVM-cvs20030816/scummvm/bs2/driver/driver96.h ScummVM-cvs20030816+hack/scummvm/bs2/driver/driver96.h
old new 1053 1053 #include "common/scummsys.h" 1054 1054 #include "common/engine.h" // for warning() 1055 1055 #include "common/system.h" 1056 #include "common/rect.h" 1056 1057 //#include "ddraw.h" 1057 1058 //#include "dsound.h" 1058 1059 … … 1254 1255 #define TRUE 1 1255 1256 #define FALSE 0 1256 1257 1258 // FIXME: Temporary (?) surface class to replace LPDIRECTDRAWSURFACE for now. 1259 1260 class Surface { 1261 public: 1262 uint16 _width, _height; 1263 uint16 _pitch; 1264 byte *_pixels; 1265 1266 Surface(uint width, uint height) { 1267 _width = width; 1268 _height = height; 1269 _pixels = (byte *) calloc(_width, _height); 1270 }; 1271 1272 ~Surface() { 1273 free(_pixels); 1274 }; 1275 1276 void clear(); 1277 void blit(Surface *s, ScummVM::Rect *r); 1278 void blit(Surface *s, ScummVM::Rect *r, ScummVM::Rect *clip_rect); 1279 }; 1280 1257 1281 // 1258 1282 // Structure definitions 1259 1283 // --------------------- … … 1351 1375 // HWND hwnd; 1352 1376 // LPDIRECTDRAW lpDraw; 1353 1377 // LPDIRECTDRAW2 lpDD2; 1354 // LPDIRECTDRAWSURFACElpPrimarySurface;1355 // LPDIRECTDRAWSURFACElpBackBuffer;1378 // Surface *lpPrimarySurface; 1379 Surface *lpBackBuffer; 1356 1380 // LPDIRECTDRAWPALETTE lpPalette; 1357 1381 int16 screenDeep; 1358 1382 int16 screenWide; -
scummvm/bs2/driver/palette.cpp
diff -ur ScummVM-cvs20030816/scummvm/bs2/driver/palette.cpp ScummVM-cvs20030816+hack/scummvm/bs2/driver/palette.cpp
old new 318 318 int32 SetPalette(int16 startEntry, int16 noEntries, uint8 *colourTable, uint8 fadeNow) 319 319 320 320 { 321 warning("stub SetPalette( %d, %d, %d )", startEntry, noEntries, fadeNow); 321 debug(0, "SetPalette(%d, %d, %d)", startEntry, noEntries, fadeNow); 322 323 StackLock lock(g_sword2->_paletteMutex); 324 325 if (noEntries == 0) { 326 RestorePalette(); 327 return RD_OK; 328 } 329 330 // FIXME: Handle the fadeNow parameter 331 332 memcpy(&palCopy[startEntry][0], colourTable, noEntries * 4); 333 g_sword2->_system->set_palette((byte *) palCopy, startEntry, noEntries); 334 322 335 /* 323 336 324 337 int32 hr; -
scummvm/bs2/driver/render.cpp
diff -ur ScummVM-cvs20030816/scummvm/bs2/driver/render.cpp ScummVM-cvs20030816+hack/scummvm/bs2/driver/render.cpp
old new 208 208 #include "_mouse.h" 209 209 #include "render.h" 210 210 #include "menu.h" 211 #include "../sword2.h" 211 212 212 213 213 214 … … 248 249 static int16 scrollyTarget; 249 250 static int16 scrollxOld; 250 251 static int16 scrollyOld; 251 //static uint16 layer = 0;252 static uint16 layer = 0; 252 253 253 254 254 255 … … 275 276 uint8 xblocks[MAXLAYERS]; 276 277 uint8 yblocks[MAXLAYERS]; 277 278 uint8 restoreLayer[MAXLAYERS]; 278 //LPDIRECTDRAWSURFACE *blockSurfaces[MAXLAYERS] = {0,0,0,0,0};279 279 280 // Each layer is composed by several sub-blocks 281 282 Surface **blockSurfaces[MAXLAYERS] = { 0, 0, 0, 0, 0 }; 283 284 285 286 void Surface::clear() { 287 memset(_pixels, 0, _width * _height); 288 g_sword2->_system->copy_rect(_pixels, _width, 0, 0, _width, _height); 289 } 290 291 void Surface::blit(Surface *s, ScummVM::Rect *r) { 292 ScummVM::Rect clip_rect; 293 294 clip_rect.left = 0; 295 clip_rect.top = 0; 296 clip_rect.right = 640; 297 clip_rect.bottom = 480; 298 299 blit(s, r, &clip_rect); 300 } 301 302 void Surface::blit(Surface *s, ScummVM::Rect *r, ScummVM::Rect *clip_rect) { 303 if (r->top > clip_rect->bottom || r->left > clip_rect->right || r->bottom <= clip_rect->top || r->right <= clip_rect->left) 304 return; 305 306 byte *src = s->_pixels; 307 308 if (r->top < clip_rect->top) { 309 src -= s->_width * (r->top - clip_rect->top); 310 r->top = clip_rect->top; 311 } 312 if (r->left < clip_rect->left) { 313 src -= (r->left - clip_rect->left); 314 r->left = clip_rect->left; 315 } 316 if (r->bottom > clip_rect->bottom) 317 r->bottom = clip_rect->bottom; 318 if (r->right > clip_rect->right) 319 r->right = clip_rect->right; 320 321 byte *dst = _pixels + r->top * _width + r->left; 322 int i, j; 323 324 // FIXME: We first render the data to the back buffer, and then copy 325 // it to the backend. Since the same area will probably be copied 326 // several times, as each new parallax layer is rendered, this may be 327 // a bit inefficient. 328 329 for (i = 0; i < r->bottom - r->top; i++) { 330 for (j = 0; j < r->right - r->left; j++) { 331 if (src[j]) 332 dst[j] = src[j]; 333 } 334 src += s->_width; 335 dst += _width; 336 } 337 338 g_sword2->_system->copy_rect(_pixels + r->top * _width + r->left, _width, r->left, r->top, r->right - r->left, r->bottom - r->top); 339 } 280 340 281 341 282 342 283 343 int32 RestoreBackgroundLayer(_parallax *p, int16 l) 284 344 { 285 warning("stub RestoreBackgroundLayer %d", l); 345 int16 oldLayer = layer; 346 int16 i; 347 348 debug(0, "RestoreBackgroundLayer %d", l); 349 350 layer = l; 351 if (blockSurfaces[l]) { 352 for (i = 0; i < xblocks[l] * yblocks[l]; i++) 353 if (blockSurfaces[l][i]) 354 delete blockSurfaces[l][i]; 355 356 free(blockSurfaces[l]); 357 blockSurfaces[l] = NULL; 358 } 359 RestoreSurfaces(); 360 InitialiseBackgroundLayer(p); 361 layer = oldLayer; 362 286 363 /* 287 364 int16 oldLayer = layer; 288 365 int16 i; … … 605 682 606 683 607 684 608 int32 RenderParallax(_parallax *p, int16 layer) 685 int32 RenderParallax(_parallax *p, int16 l) { 686 int16 x, y; 687 int16 i, j; 688 ScummVM::Rect r; 689 690 debug(0, "RenderParallax %d", l); 691 692 if (locationWide == screenWide) 693 x = 0; 694 else 695 x = ((int32) ((p->w - screenWide) * scrollx) / (int32) (locationWide - screenWide)); 696 697 if (locationDeep == (screenDeep - MENUDEEP * 2)) 698 y = 0; 699 else 700 y = ((int32) ((p->h - (screenDeep - MENUDEEP * 2)) * scrolly) / (int32) (locationDeep - (screenDeep - MENUDEEP * 2))); 701 702 ScummVM::Rect clip_rect; 703 704 // Leave enough space for the top and bottom menues 705 706 clip_rect.left = 0; 707 clip_rect.right = 640; 708 clip_rect.top = 40; 709 clip_rect.bottom = 440; 710 711 for (j = 0; j < yblocks[l]; j++) { 712 for (i = 0; i < xblocks[l]; i++) { 713 if (blockSurfaces[l][i + j * xblocks[l]]) { 714 r.left = i * BLOCKWIDTH - x; 715 r.right = r.left + BLOCKWIDTH; 716 r.top = j * BLOCKHEIGHT - y + 40; 717 r.bottom = r.top + BLOCKHEIGHT; 718 lpBackBuffer->blit(blockSurfaces[l][i + j * xblocks[l]], &r, &clip_rect); 719 } 720 } 721 } 722 723 parallaxScrollx = scrollx - x; 724 parallaxScrolly = scrolly - y; 609 725 610 {611 warning("stub RenderParallax %d", layer);612 726 /* 613 727 614 728 #if PROFILING == 1 … … 619 733 620 734 #endif 621 735 622 if ((renderCaps & RDBLTFX_ALLHARDWARE) || ((renderCaps & RDBLTFX_FGPARALLAX) && (l ayer> 2)))736 if ((renderCaps & RDBLTFX_ALLHARDWARE) || ((renderCaps & RDBLTFX_FGPARALLAX) && (l > 2))) 623 737 { 624 738 625 739 int16 x, y; … … 628 742 HRESULT hr = 0; 629 743 RECT r, rd; 630 744 631 if (restoreLayer[l ayer])745 if (restoreLayer[l]) 632 746 { 633 RestoreBackgroundLayer(p, l ayer);634 restoreLayer[l ayer] = 0;747 RestoreBackgroundLayer(p, l); 748 restoreLayer[l] = 0; 635 749 } 636 750 637 751 if (locationWide == screenWide) … … 648 762 while (TRUE) 649 763 { 650 764 j = 0; 651 while (j < yblocks[l ayer])765 while (j < yblocks[l]) 652 766 { 653 767 i = 0; 654 while (i < xblocks[l ayer])768 while (i < xblocks[l]) 655 769 { 656 if (*(blockSurfaces[l ayer] + i + j * xblocks[layer]))770 if (*(blockSurfaces[l] + i + j * xblocks[l])) 657 771 { 658 772 r.left = i * BLOCKWIDTH - x; 659 773 r.right = r.left + BLOCKWIDTH; … … 684 798 rd.bottom = BLOCKHEIGHT - (r.bottom - 440); 685 799 r.bottom = 440; 686 800 } 687 hr = IDirectDrawSurface2_Blt(lpBackBuffer, &r, *(blockSurfaces[l ayer] + i + j * xblocks[layer]), &rd, DDBLT_WAIT | DDBLT_KEYSRC, NULL);801 hr = IDirectDrawSurface2_Blt(lpBackBuffer, &r, *(blockSurfaces[l] + i + j * xblocks[l]), &rd, DDBLT_WAIT | DDBLT_KEYSRC, NULL); 688 802 if (hr == DDERR_INVALIDRECT) 689 803 hr = 0; 690 804 if (hr) … … 707 821 if (++restoreSurfaces == 4) 708 822 return(RDERR_RESTORELAYERS); 709 823 else 710 RestoreBackgroundLayer(p, l ayer);824 RestoreBackgroundLayer(p, l); 711 825 } 712 826 else 713 827 return(RD_OK); … … 996 1110 int32 CopyScreenBuffer(void) 997 1111 998 1112 { 999 warning("stub CopyScreenBuffer"); 1113 debug(0, "CopyScreenBuffer"); 1114 1115 // FIXME: The backend should keep track of dirty rects, but I have a 1116 // feeling each one may be drawn several times, so we may have do add 1117 // our own handling of them instead. 1118 1119 g_sword2->_system->update_screen(); 1120 1000 1121 /* 1001 1122 1002 1123 uint8 *dst, *src; … … 1065 1186 1066 1187 1067 1188 1068 int32 InitialiseBackgroundLayer(_parallax *p) 1189 int32 InitialiseBackgroundLayer(_parallax *p) { 1190 uint8 *memchunk; 1191 uint32 *quaddata; 1192 uint8 zeros; 1193 uint16 count; 1194 uint16 i, j, k; 1195 uint16 x; 1196 uint8 *data; 1197 uint8 *dst; 1198 _parallaxLine *line; 1199 1200 debug(0, "InitialiseBackgroundLayer"); 1201 1202 // This function is called to re-initialise the layers if they have 1203 // been lost. We know this if the layers have already been assigned. 1204 1205 // TODO: Can layers still be lost, or is that a DirectDraw-ism? 1206 1207 if (layer == MAXLAYERS) 1208 CloseBackgroundLayer(); 1209 1210 if (!p) { 1211 layer++; 1212 return RD_OK; 1213 } 1214 1215 xblocks[layer] = (p->w + BLOCKWIDTH - 1) >> BLOCKWBITS; 1216 yblocks[layer] = (p->h + BLOCKHEIGHT - 1) >> BLOCKHBITS; 1217 1218 blockSurfaces[layer] = (Surface **) calloc(xblocks[layer] * yblocks[layer], sizeof(Surface *)); 1219 if (!blockSurfaces[layer]) 1220 return RDERR_OUTOFMEMORY; 1221 1222 // Decode the parallax layer into a large chunk of memory 1223 1224 memchunk = (uint8 *) malloc(xblocks[layer] * BLOCKWIDTH * yblocks[layer] * BLOCKHEIGHT); 1225 if (!memchunk) 1226 return RDERR_OUTOFMEMORY; 1227 1228 // We clear not the entire memory chunk, but enough of it to store 1229 // the entire parallax layer. 1230 1231 memset(memchunk, 0, p->w * p->h); 1232 1233 for (i = 0; i < p->h; i++) { 1234 if (p->offset[i] == 0) 1235 continue; 1236 1237 line = (_parallaxLine *) ((uint8 *) p + p->offset[i]); 1238 data = (uint8 *) line + sizeof(_parallaxLine); 1239 x = line->offset; 1240 1241 dst = memchunk + i * p->w + x; 1242 1243 zeros = 0; 1244 if (line->packets == 0) { 1245 memcpy(dst, data, p->w); 1246 continue; 1247 } 1248 1249 for (j = 0; j < line->packets; j++) { 1250 if (zeros) { 1251 dst += *data; 1252 x += *data; 1253 data++; 1254 zeros = 0; 1255 } else if (*data == 0) { 1256 data++; 1257 zeros = 1; 1258 } else { 1259 count = *data++; 1260 memcpy(dst, data, count); 1261 data += count; 1262 dst += count; 1263 x += count; 1264 zeros = 1; 1265 } 1266 } 1267 } 1268 1269 // Now create the surfaces! 1270 1271 for (i = 0; i < xblocks[layer] * yblocks[layer]; i++) { 1272 bool block_has_data = false; 1273 1274 data = memchunk + (p->w * BLOCKHEIGHT * (i / xblocks[layer])) + BLOCKWIDTH * (i % xblocks[layer]); 1275 1276 quaddata = (uint32 *) data; 1277 1278 for (j = 0; j < BLOCKHEIGHT; j++) { 1279 for (k = 0; k < BLOCKWIDTH / 4; k++) { 1280 if (*quaddata) { 1281 block_has_data = true; 1282 goto bailout; 1283 } 1284 quaddata++; 1285 } 1286 quaddata += ((p->w - BLOCKWIDTH) / 4); 1287 } 1288 1289 bailout: 1290 1291 // Only assign a surface to the block if it contains data. 1292 1293 if (block_has_data) { 1294 blockSurfaces[layer][i] = new Surface(BLOCKWIDTH, BLOCKHEIGHT); 1295 1296 // Copy the data into the surfaces. 1297 dst = blockSurfaces[layer][i]->_pixels; 1298 for (j = 0; j < BLOCKHEIGHT; j++) { 1299 memcpy(dst, data, BLOCKWIDTH); 1300 data += p->w; 1301 dst += BLOCKWIDTH; 1302 } 1303 } else 1304 blockSurfaces[layer][i] = NULL; 1305 } 1306 free(memchunk); 1307 layer++; 1069 1308 1070 {1071 warning("stub InitialiseBackgroundLayer");1072 1309 /* 1073 1310 uint8 *memchunk; 1074 1311 uint32 *quaddata; … … 1252 1489 int32 CloseBackgroundLayer(void) 1253 1490 1254 1491 { 1255 warning("stub CloseBackgroundLayer"); 1492 debug(0, "CloseBackgroundLayer"); 1493 1494 int16 i, j; 1495 1496 for (j = 0; j < MAXLAYERS; j++) { 1497 if (blockSurfaces[j]) { 1498 for (i = 0; i < xblocks[j] * yblocks[j]; i++) 1499 if (blockSurfaces[j][i]) 1500 delete blockSurfaces[j][i]; 1501 free(blockSurfaces[j]); 1502 } 1503 } 1504 1505 layer = 0; 1256 1506 /* 1257 1507 int16 i, j; 1258 1508 -
scummvm/bs2/sword2.cpp
diff -ur ScummVM-cvs20030816/scummvm/bs2/sword2.cpp ScummVM-cvs20030816+hack/scummvm/bs2/sword2.cpp
old new 281 281 282 282 283 283 Zdebug("CALLING: InitialiseDisplay"); 284 // rv = InitialiseDisplay(640, 480, 8, RD_FULLSCREEN);285 284 _system->init_size(640, 480); 286 rv = RD_OK;285 rv = InitialiseDisplay(640, 480, 8, RD_FULLSCREEN); 287 286 288 287 Zdebug("RETURNED with rv = %.8x", rv); 289 288 if (rv != RD_OK)