crt.diff 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. This is a mod for Anarch that adds a simple CRT screen effect (scanlines plus
  2. screen warp). By drummyfish.
  3. diff --git a/game.h b/game.h
  4. index 24285cb..4625ba1 100755
  5. --- a/game.h
  6. +++ b/game.h
  7. @@ -816,24 +816,32 @@ uint16_t SFG_keyRegisters(uint8_t key)
  8. return SFG_keyJustPressed(key) || SFG_keyRepeated(key);
  9. }
  10. -#if SFG_RESOLUTION_SCALEDOWN == 1
  11. - #define SFG_setGamePixel SFG_setPixel
  12. -#else
  13. +uint8_t SFG_screenWarpMap[SFG_GAME_RESOLUTION_X][SFG_GAME_RESOLUTION_Y];
  14. /**
  15. Sets the game pixel (a pixel that can potentially be bigger than the screen
  16. pixel).
  17. */
  18. -static inline void SFG_setGamePixel(uint16_t x, uint16_t y, uint8_t colorIndex)
  19. +static inline void SFG_setGamePixel(int16_t x, int16_t y, uint8_t colorIndex)
  20. {
  21. - uint16_t screenY = y * SFG_RESOLUTION_SCALEDOWN;
  22. - uint16_t screenX = x * SFG_RESOLUTION_SCALEDOWN;
  23. + int16_t screenX = x - SFG_GAME_RESOLUTION_X / 2;
  24. + int16_t screenY = y - SFG_GAME_RESOLUTION_Y / 2;
  25. +
  26. + uint8_t mul = SFG_screenWarpMap[x][y];
  27. +
  28. + screenX = (screenX * mul) / 128;
  29. + screenY = (screenY * mul) / 128;
  30. - for (uint16_t j = screenY; j < screenY + SFG_RESOLUTION_SCALEDOWN; ++j)
  31. - for (uint16_t i = screenX; i < screenX + SFG_RESOLUTION_SCALEDOWN; ++i)
  32. + screenX = (screenX + SFG_GAME_RESOLUTION_X / 2) * SFG_RESOLUTION_SCALEDOWN;
  33. + screenY = (screenY + SFG_GAME_RESOLUTION_Y / 2) * SFG_RESOLUTION_SCALEDOWN;
  34. +
  35. + // scanline effect:
  36. + colorIndex -= ((screenY / 2) % 2) && (colorIndex % 8 != 0);
  37. +
  38. + for (int16_t j = screenY; j < screenY + SFG_RESOLUTION_SCALEDOWN; ++j)
  39. + for (int16_t i = screenX; i < screenX + SFG_RESOLUTION_SCALEDOWN; ++i)
  40. SFG_setPixel(i,j,colorIndex);
  41. }
  42. -#endif
  43. void SFG_recomputePLayerDirection(void)
  44. {
  45. @@ -1691,6 +1699,23 @@ void SFG_init()
  46. SFG_game.cheatState = 0;
  47. SFG_game.continues = 1;
  48. + for (int32_t y = 0; y < SFG_GAME_RESOLUTION_Y; ++y)
  49. + for (int32_t x = 0; x < SFG_GAME_RESOLUTION_X; ++x)
  50. + {
  51. + int32_t dx = x - SFG_GAME_RESOLUTION_X / 2;
  52. + dx = (dx * dx) / 512;
  53. +
  54. + int32_t dy = y - SFG_GAME_RESOLUTION_Y / 2;
  55. + dy = (dy * dy) / 512;
  56. +
  57. + SFG_screenWarpMap[x][y] = 128 -
  58. + ((dx + dy) * SFG_SCREEN_WARP) /
  59. + (
  60. + ((SFG_GAME_RESOLUTION_X * SFG_GAME_RESOLUTION_X) +
  61. + (SFG_GAME_RESOLUTION_Y * SFG_GAME_RESOLUTION_Y)) / (4 * 512)
  62. + );
  63. + }
  64. +
  65. RCL_initRayConstraints(&SFG_game.rayConstraints);
  66. SFG_game.rayConstraints.maxHits = SFG_RAYCASTING_MAX_HITS;
  67. SFG_game.rayConstraints.maxSteps = SFG_RAYCASTING_MAX_STEPS;
  68. diff --git a/settings.h b/settings.h
  69. index 2c8820a..663fcec 100644
  70. --- a/settings.h
  71. +++ b/settings.h
  72. @@ -84,6 +84,13 @@
  73. #define SFG_SCREEN_RESOLUTION_Y 600
  74. #endif
  75. +/**
  76. + Sets the amount of screen warp for the CRT simulation effect.
  77. +*/
  78. +#ifndef SFG_SCREEN_WARP
  79. + #define SFG_SCREEN_WARP 16
  80. +#endif
  81. +
  82. /**
  83. How quickly player turns left/right, in degrees per second.
  84. */