Ticket #4774: made.patch
File made.patch, 13.0 KB (added by , 14 years ago) |
---|
-
screenfx.cpp
61 61 } 62 62 63 63 void ScreenEffects::run(int16 effectNum, Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 64 // Workaround: we set up the final palette beforehand, to reduce CPU usage during the screen effect.65 // The visual difference is not noticeable, but CPU load is much much less (as palette updates are very expensive).66 // The palette changes in the effects have been removed, where applicable, to reduce CPU load67 setPalette(palette);68 64 69 65 // TODO: Put effect functions into an array 70 66 71 67 switch (effectNum) { 72 68 73 69 case 0: // No effect … … 191 187 } 192 188 } 193 189 190 void ScreenEffects::startBlendedPalette(byte *palette, byte *newPalette, int colorCount, int16 maxValue) { 191 _blendedPaletteStatus._palette = palette; 192 _blendedPaletteStatus._newPalette = newPalette; 193 _blendedPaletteStatus._colorCount = colorCount; 194 _blendedPaletteStatus._maxValue = maxValue; 195 _blendedPaletteStatus._incr = maxValue / 10; // ~10 palette updates 196 _blendedPaletteStatus._value = 0; 197 // Don't do anything if the two palettes are identical 198 _blendedPaletteStatus._active = memcmp(palette, newPalette, colorCount * 3) != 0; 199 } 200 201 void ScreenEffects::stepBlendedPalette() { 202 if (_blendedPaletteStatus._active && _blendedPaletteStatus._value < _blendedPaletteStatus._maxValue) { 203 setBlendedPalette(_blendedPaletteStatus._palette, _blendedPaletteStatus._newPalette, 204 _blendedPaletteStatus._colorCount, _blendedPaletteStatus._value, _blendedPaletteStatus._maxValue); 205 if (_blendedPaletteStatus._value == _blendedPaletteStatus._maxValue) 206 _blendedPaletteStatus._value++; 207 else 208 _blendedPaletteStatus._value = MIN<int16>(_blendedPaletteStatus._value + _blendedPaletteStatus._incr, _blendedPaletteStatus._maxValue); 209 } 210 } 211 194 212 void ScreenEffects::copyFxRect(Graphics::Surface *surface, int16 x1, int16 y1, int16 x2, int16 y2) { 195 213 196 214 // TODO: Clean up … … 276 294 } 277 295 278 296 void ScreenEffects::vfx01(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 297 startBlendedPalette(palette, newPalette, colorCount, 312); 279 298 for (int x = 0; x < 320; x += 8) { 280 299 _screen->copyRectToScreen((const byte*)surface->getBasePtr(x, 0), surface->pitch, x, 0, 8, 200); 281 //setBlendedPalette(palette, newPalette, colorCount, x, 312); // original behavior300 stepBlendedPalette(); 282 301 _screen->updateScreenAndWait(25); 283 302 } 284 //setPalette(palette); // original behavior303 setPalette(palette); 285 304 } 286 305 287 306 void ScreenEffects::vfx02(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 307 startBlendedPalette(palette, newPalette, colorCount, 312); 288 308 for (int x = 312; x >= 0; x -= 8) { 289 309 _screen->copyRectToScreen((const byte*)surface->getBasePtr(x, 0), surface->pitch, x, 0, 8, 200); 290 //setBlendedPalette(palette, newPalette, colorCount, 312 - x, 312); // original behavior310 stepBlendedPalette(); 291 311 _screen->updateScreenAndWait(25); 292 312 } 293 //setPalette(palette); // original behavior313 setPalette(palette); 294 314 } 295 315 296 316 void ScreenEffects::vfx03(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 317 startBlendedPalette(palette, newPalette, colorCount, 190); 297 318 for (int y = 0; y < 200; y += 10) { 298 319 _screen->copyRectToScreen((const byte*)surface->getBasePtr(0, y), surface->pitch, 0, y, 320, 10); 299 //setBlendedPalette(palette, newPalette, colorCount, y, 190); // original behavior320 stepBlendedPalette(); 300 321 _screen->updateScreenAndWait(25); 301 322 } 302 //setPalette(palette); // original behavior323 setPalette(palette); 303 324 } 304 325 305 326 void ScreenEffects::vfx04(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 327 startBlendedPalette(palette, newPalette, colorCount, 190); 306 328 for (int y = 190; y >= 0; y -= 10) { 307 329 _screen->copyRectToScreen((const byte*)surface->getBasePtr(0, y), surface->pitch, 0, y, 320, 10); 308 //setBlendedPalette(palette, newPalette, colorCount, 190 - y, 190); // original behavior330 stepBlendedPalette(); 309 331 _screen->updateScreenAndWait(25); 310 332 } 311 //setPalette(palette); // original behavior333 setPalette(palette); 312 334 } 313 335 314 336 void ScreenEffects::vfx05(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 337 startBlendedPalette(palette, newPalette, colorCount, 90); 315 338 for (int y = 0; y < 100; y += 10) { 316 339 _screen->copyRectToScreen((const byte*)surface->getBasePtr(0, y + 100), surface->pitch, 0, y + 100, 320, 10); 317 340 _screen->copyRectToScreen((const byte*)surface->getBasePtr(0, 90 - y), surface->pitch, 0, 90 - y, 320, 10); 318 //setBlendedPalette(palette, newPalette, colorCount, y, 90); // original behavior341 stepBlendedPalette(); 319 342 _screen->updateScreenAndWait(25); 320 343 } 321 //setPalette(palette); // original behavior344 setPalette(palette); 322 345 } 323 346 324 347 // "Curtain open" effect 325 348 void ScreenEffects::vfx06(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 349 startBlendedPalette(palette, newPalette, colorCount, 152); 326 350 for (int x = 0; x < 160; x += 8) { 327 351 _screen->copyRectToScreen((const byte*)surface->getBasePtr(x + 160, 0), surface->pitch, x + 160, 0, 8, 200); 328 352 _screen->copyRectToScreen((const byte*)surface->getBasePtr(152 - x, 0), surface->pitch, 152 - x, 0, 8, 200); 329 //setBlendedPalette(palette, newPalette, colorCount, x, 152); // original behavior353 stepBlendedPalette(); 330 354 _screen->updateScreenAndWait(25); 331 355 } 332 //setPalette(palette); // original behavior356 setPalette(palette); 333 357 } 334 358 335 359 // "Curtain close" effect 336 360 void ScreenEffects::vfx07(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 361 startBlendedPalette(palette, newPalette, colorCount, 152); 337 362 for (int x = 152; x >= 0; x -= 8) { 338 363 _screen->copyRectToScreen((const byte*)surface->getBasePtr(x + 160, 0), surface->pitch, x + 160, 0, 8, 200); 339 364 _screen->copyRectToScreen((const byte*)surface->getBasePtr(152 - x, 0), surface->pitch, 152 - x, 0, 8, 200); 340 //setBlendedPalette(palette, newPalette, colorCount, 152 - x, 152); // original behavior365 stepBlendedPalette(); 341 366 _screen->updateScreenAndWait(25); 342 367 } 343 //setPalette(palette); // original behavior368 setPalette(palette); 344 369 } 345 370 346 371 // "Screen slide in" right to left … … 349 374 _screen->copyRectToScreen((const byte*)surface->getBasePtr(0, 0), surface->pitch, 320 - x, 0, x, 200); 350 375 _screen->updateScreenAndWait(25); 351 376 } 352 //setPalette(palette); // original behavior377 setPalette(palette); 353 378 } 354 379 355 380 // "Checkerboard" effect … … 368 393 369 394 // "Screen wipe in", left to right 370 395 void ScreenEffects::vfx10(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 396 startBlendedPalette(palette, newPalette, colorCount, 368); 371 397 for (int x = -56; x < 312; x += 8) { 372 398 copyFxRect(surface, x, 0, x + 64, 200); 373 //setBlendedPalette(palette, newPalette, colorCount, x + 56, 368); // original behavior399 stepBlendedPalette(); 374 400 _screen->updateScreenAndWait(25); 375 401 } 376 //setPalette(palette); // original behavior402 setPalette(palette); 377 403 } 378 404 379 405 // "Screen wipe in", right to left 380 406 void ScreenEffects::vfx11(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 407 startBlendedPalette(palette, newPalette, colorCount, 368); 381 408 for (int x = 312; x > -56; x -= 8) { 382 409 copyFxRect(surface, x, 0, x + 64, 200); 383 //setBlendedPalette(palette, newPalette, colorCount, x + 56, 368); // original behavior410 stepBlendedPalette(); 384 411 _screen->updateScreenAndWait(25); 385 412 } 386 //setPalette(palette); // original behavior413 setPalette(palette); 387 414 } 388 415 389 416 // "Screen wipe in", top to bottom 390 417 void ScreenEffects::vfx12(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 418 startBlendedPalette(palette, newPalette, colorCount, 260); 391 419 for (int y = -70; y < 312; y += 10) { 392 420 copyFxRect(surface, 0, y, 320, y + 80); 393 //setBlendedPalette(palette, newPalette, colorCount, y + 70, 260); // original behavior421 stepBlendedPalette(); 394 422 _screen->updateScreenAndWait(25); 395 423 } 396 //setPalette(palette); // original behavior424 setPalette(palette); 397 425 } 398 426 399 427 // "Screen wipe in", bottom to top 400 428 void ScreenEffects::vfx13(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 429 startBlendedPalette(palette, newPalette, colorCount, 260); 401 430 for (int y = 312; y > -70; y -= 10) { 402 431 copyFxRect(surface, 0, y, 320, y + 80); 403 //setBlendedPalette(palette, newPalette, colorCount, y + 70, 260); // original behavior432 stepBlendedPalette(); 404 433 _screen->updateScreenAndWait(25); 405 434 } 406 //setPalette(palette); // original behavior435 setPalette(palette); 407 436 } 408 437 409 438 // "Screen open" effect 410 439 void ScreenEffects::vfx14(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 411 440 int16 x = 8, y = 5; 441 startBlendedPalette(palette, newPalette, colorCount, 27); 412 442 for (int i = 0; i < 27; i++) { 413 443 copyFxRect(surface, 160 - x, 100 - y, 160 + x, 100 + y); 414 444 x += 8; 415 445 y += 5; 416 //setBlendedPalette(palette, newPalette, colorCount, i, 27); // original behavior446 stepBlendedPalette(); 417 447 _screen->updateScreenAndWait(25); 418 448 } 419 //setPalette(palette); // original behavior449 setPalette(palette); 420 450 } 421 451 422 452 void ScreenEffects::vfx15(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 423 453 int16 x = 8; 454 startBlendedPalette(palette, newPalette, colorCount, 27); 424 455 for (int i = 0; i < 27; i++) { 425 456 copyFxRect(surface, 160 - x, 0, 160 + x, 200); 426 457 x += 8; 427 //setBlendedPalette(palette, newPalette, colorCount, i, 27); // original behavior458 stepBlendedPalette(); 428 459 _screen->updateScreenAndWait(25); 429 460 } 430 //setPalette(palette); // original behavior461 setPalette(palette); 431 462 } 432 463 433 464 void ScreenEffects::vfx16(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount) { 434 465 int16 y = 8; 466 startBlendedPalette(palette, newPalette, colorCount, 27); 435 467 for (int i = 0; i < 27; i++) { 436 468 copyFxRect(surface, 0, 100 - y, 320, 100 + y); 437 469 y += 5; 438 //setBlendedPalette(palette, newPalette, colorCount, i, 27); // original behavior470 stepBlendedPalette(); 439 471 _screen->updateScreenAndWait(25); 440 472 } 441 //setPalette(palette); // original behavior473 setPalette(palette); 442 474 } 443 475 444 476 // Palette fadeout/fadein … … 451 483 452 484 memcpy(tempPalette, palette, 768); 453 485 454 // We reduce the number of palette updates by the following factor (e.g. a factor of 5 would mean 5455 // times less updates). This is done to reduce CPU load while performing the very expensive full456 // screen palette changes. The original behavior is to set factor to 1.457 int factor = 5;458 459 486 // Fade out to black 460 487 memset(palette, 0, 768); 461 for (int i = 0; i < 50 / factor; i++) { 462 setBlendedPalette(palette, newPalette, colorCount, i * factor, 50); 463 _screen->updateScreenAndWait(25 * factor); 488 startBlendedPalette(palette, newPalette, colorCount, 50); 489 for (int i = 0; i < 50; i++) { 490 stepBlendedPalette(); 491 _screen->updateScreenAndWait(25); 464 492 } 465 493 _screen->setRGBPalette(palette, 0, colorCount); 466 494 … … 470 498 471 499 // Fade from black to palette 472 500 memset(newPalette, 0, 768); 473 for (int i = 0; i < 50 / factor; i++) { 474 setBlendedPalette(palette, newPalette, colorCount, i * factor, 50); 475 _screen->updateScreenAndWait(25 * factor); 501 startBlendedPalette(palette, newPalette, colorCount, 50); 502 for (int i = 0; i < 50; i++) { 503 stepBlendedPalette(); 504 _screen->updateScreenAndWait(25); 476 505 } 477 506 _screen->setRGBPalette(palette, 0, colorCount); 478 507 … … 486 515 _screen->copyRectToScreen((const byte*)surface->getBasePtr(320 - x, 0), surface->pitch, 0, 0, x, 200); 487 516 _screen->updateScreenAndWait(25); 488 517 } 489 490 //setPalette(palette); // original behavior 518 setPalette(palette); 491 519 } 492 520 493 521 // "Screen slide in" top to bottom … … 496 524 _screen->copyRectToScreen((const byte*)surface->getBasePtr(0, 200 - y), surface->pitch, 0, 0, 320, y); 497 525 _screen->updateScreenAndWait(25); 498 526 } 499 500 //setPalette(palette); // original behavior 527 setPalette(palette); 501 528 } 502 529 503 530 // "Screen slide in" bottom to top … … 506 533 _screen->copyRectToScreen((const byte*)surface->getBasePtr(0, 0), surface->pitch, 0, 200 - y, 320, y); 507 534 _screen->updateScreenAndWait(25); 508 535 } 509 510 //setPalette(palette); // original behavior 536 setPalette(palette); 511 537 } 512 538 513 539 } // End of namespace Made -
screenfx.h
37 37 38 38 namespace Made { 39 39 40 struct BlendedPaletteStatus { 41 bool _active; 42 byte *_palette, *_newPalette; 43 int _colorCount; 44 int16 _value, _maxValue, _incr; 45 int cnt; 46 }; 47 40 48 class ScreenEffects { 41 49 public: 42 50 ScreenEffects(Screen *screen); … … 50 58 static const byte vfxOffsIndexTable[8]; 51 59 const byte *vfxOffsTablePtr; 52 60 int16 vfxX1, vfxY1, vfxWidth, vfxHeight; 61 BlendedPaletteStatus _blendedPaletteStatus; 53 62 void setPalette(byte *palette); 54 63 void setBlendedPalette(byte *palette, byte *newPalette, int colorCount, int16 value, int16 maxValue); 64 void startBlendedPalette(byte *palette, byte *newPalette, int colorCount, int16 maxValue); 65 void stepBlendedPalette(); 55 66 void copyFxRect(Graphics::Surface *surface, int16 x1, int16 y1, int16 x2, int16 y2); 56 67 57 68 void vfx00(Graphics::Surface *surface, byte *palette, byte *newPalette, int colorCount);