CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

MORPHPAL.CPP (7770B)


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