MORPHPAL.CPP 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***************************************************************************
  19. ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  20. ***************************************************************************
  21. * *
  22. * Project Name : wwlib32 *
  23. * *
  24. * File Name : PALTOPAL.CPP *
  25. * *
  26. * Programmer : Bill Randolph *
  27. * *
  28. * Start Date : May 2, 1994 *
  29. * *
  30. * Last Update : May 2, 1994 [BR] *
  31. * *
  32. *-------------------------------------------------------------------------*
  33. * Functions: *
  34. * Morph_Palette -- morphs a palette from source to destination *
  35. * Palette_To_Palette -- morph src palette to a dst palette *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. /*
  38. ********************************* Includes **********************************
  39. */
  40. #include "wwstd.h"
  41. #include "palette.h"
  42. #include "timer.h"
  43. /*
  44. ********************************* Constants *********************************
  45. */
  46. #define SCALE(a,b,c) (((((long)(a)<<8) / (long)(b) ) * (unsigned long)(c)) >>8)
  47. /*
  48. ********************************** Globals **********************************
  49. */
  50. /*
  51. ******************************** Prototypes *********************************
  52. */
  53. PRIVATE int __cdecl Palette_To_Palette(void *src_palette, void *dst_palette, unsigned long current_time, unsigned long delay);
  54. /***************************************************************************
  55. * Morph_Palette -- morphs a palette from source to destination *
  56. * *
  57. * INPUT: *
  58. * void *src_pal - starting palette *
  59. * void *dst_pal - ending palette *
  60. * unsigned int delay - time delay in 60ths of a second *
  61. * void *callback - user-defined callback, NULL if none *
  62. * *
  63. * OUTPUT: *
  64. * none. *
  65. * *
  66. * WARNINGS: *
  67. * *
  68. * HISTORY: *
  69. * 05/02/1994 BR : Created. *
  70. *=========================================================================*/
  71. void cdecl Morph_Palette (void *src_pal, void *dst_pal, unsigned int delay,
  72. void (*callback) (void) )
  73. {
  74. int result;
  75. unsigned long pal_start = TickCount.Time();
  76. extern void (*cb_ptr) ( void ) ; // callback function pointer
  77. // (void *)cb_ptr = callback;
  78. cb_ptr = callback ;
  79. /*===================================================================*/
  80. /* Make sure that we don't go too fast but also make sure we keep */
  81. /* processing the morph palette if we have one. */
  82. /*===================================================================*/
  83. while (1) {
  84. if (src_pal && dst_pal) {
  85. result = Palette_To_Palette (src_pal, dst_pal,
  86. (TickCount.Time() - pal_start), (unsigned long)delay);
  87. if (!result)
  88. break;
  89. if (callback) {
  90. (*cb_ptr)();
  91. }
  92. }
  93. }
  94. return;
  95. } /* end of Morph_Palette */
  96. /***************************************************************************
  97. * Palette_To_Palette -- morph src palette to a dst palette *
  98. * *
  99. * Creates & sets a palette that's in-between 'src_palette' & *
  100. * 'dst_palette'; how close it is to dst_palette is based on how close *
  101. * 'current_time' is to 'delay'. 'current_time' & 'delay' are based on *
  102. * 0 being the start time. *
  103. * *
  104. * INPUT: void *src_palette = palette we want to morph from *
  105. * void *dst_palette = palette we want to morph to *
  106. * long current_time = time we started morph pal *
  107. * long delay = time we want the morph to take*
  108. * *
  109. * OUTPUT: int if the time had elapsed and no chages were *
  110. * necessary this routine returns FALSE *
  111. * otherwise it will always return TRUE (this *
  112. * was necessary to detect the end of the ice *
  113. * effect. *
  114. * *
  115. * HISTORY: *
  116. * 05/24/1993 MC : Created. *
  117. *=========================================================================*/
  118. PRIVATE int cdecl Palette_To_Palette(void *src_palette, void *dst_palette,
  119. unsigned long current_time, unsigned long delay)
  120. {
  121. char colour;
  122. char diff;
  123. int chgval;
  124. int lp;
  125. int change;
  126. static char palette[768];
  127. char *src_pal = (char*)src_palette;
  128. char *dst_pal = (char*)dst_palette;
  129. /*======================================================================*/
  130. /* Loop through each RGB value attempting to change it to the correct */
  131. /* color. */
  132. /*======================================================================*/
  133. for (change = lp = 0; lp < 768; lp++) {
  134. if (current_time < delay ) {
  135. diff = dst_pal[lp] & (char)63;
  136. diff -= src_pal[lp] & (char)63;
  137. if (diff)
  138. change = TRUE;
  139. chgval = SCALE(diff, delay, current_time);
  140. colour = src_pal[lp] & (char)63;
  141. colour +=(char)chgval;
  142. }
  143. else {
  144. colour = dst_pal[lp] & (char)63;
  145. change = FALSE;
  146. }
  147. palette[lp] = colour;
  148. }
  149. /*======================================================================*/
  150. /* Set the palette to the color that we created. */
  151. /*======================================================================*/
  152. Set_Palette(palette);
  153. return(change);
  154. } /* end of Palette_To_Palette */
  155. /*************************** End of morphpal.cpp ***************************/
  156.