Get rid of one abuse of the vga palette index of a COLOR to store state.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3358 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
Meep-Eep
2009-11-28 15:07:38 +00:00
parent 74c013217e
commit e3862aefcd
2 changed files with 95 additions and 88 deletions
+4 -1
View File
@@ -123,7 +123,10 @@ struct element
COUNT crew_level; COUNT crew_level;
COUNT hit_points; COUNT hit_points;
COUNT facing; /* Planetside: lava-spot direction of travel */ COUNT facing; /* Planetside: lava-spot direction of travel */
COUNT cycle; /* Planetside: lightning cycle length */ COUNT cycle;
/* Planetside: lightning cycle length
* Melee: color cycle index of ion trails and warp shadows
*/
}; };
union union
{ {
+54 -50
View File
@@ -578,14 +578,51 @@ ship_death (ELEMENT *ShipPtr)
#define START_ION_COLOR BUILD_COLOR (MAKE_RGB15 (0x1F, 0x15, 0x00), 0x7A) #define START_ION_COLOR BUILD_COLOR (MAKE_RGB15 (0x1F, 0x15, 0x00), 0x7A)
// Called from the death_func of an element for an ion trail pixel, or a
// ship shadow (when warping in/out).
void
cycle_ion_trail (ELEMENT *ElementPtr)
{
static const COLOR color_tab[] =
{
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x15, 0x00), 0x7a),
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x11, 0x00), 0x7b),
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x0E, 0x00), 0x7c),
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x0A, 0x00), 0x7d),
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x07, 0x00), 0x7e),
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x03, 0x00), 0x7f),
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x00, 0x00), 0x2a),
BUILD_COLOR (MAKE_RGB15 (0x1B, 0x00, 0x00), 0x2b),
BUILD_COLOR (MAKE_RGB15 (0x17, 0x00, 0x00), 0x2c),
BUILD_COLOR (MAKE_RGB15 (0x13, 0x00, 0x00), 0x2d),
BUILD_COLOR (MAKE_RGB15 (0x0F, 0x00, 0x00), 0x2e),
BUILD_COLOR (MAKE_RGB15 (0x0B, 0x00, 0x00), 0x2f),
};
#define NUM_TAB_COLORS (sizeof color_tab / sizeof color_tab[0])
assert (!(ElementPtr->state_flags & PLAYER_SHIP));
ElementPtr->cycle++;
if (ElementPtr->cycle != NUM_TAB_COLORS)
{
ElementPtr->life_span = ElementPtr->thrust_wait;
// Reset the life span.
SetPrimColor (&DisplayArray[ElementPtr->PrimIndex],
color_tab[ElementPtr->cycle]);
ElementPtr->state_flags &= ~DISAPPEARING;
ElementPtr->state_flags |= CHANGING;
} // else, the element disappears.
}
void void
spawn_ion_trail (ELEMENT *ElementPtr) spawn_ion_trail (ELEMENT *ElementPtr)
{
if (ElementPtr->state_flags & PLAYER_SHIP)
{ {
HELEMENT hIonElement; HELEMENT hIonElement;
assert (ElementPtr->state_flags & PLAYER_SHIP);
hIonElement = AllocElement (); hIonElement = AllocElement ();
if (hIonElement) if (hIonElement)
{ {
@@ -604,10 +641,15 @@ spawn_ion_trail (ELEMENT *ElementPtr)
LockElement (hIonElement, &IonElementPtr); LockElement (hIonElement, &IonElementPtr);
IonElementPtr->playerNr = NEUTRAL_PLAYER_NUM; IonElementPtr->playerNr = NEUTRAL_PLAYER_NUM;
IonElementPtr->state_flags = APPEARING | FINITE_LIFE | NONSOLID; IonElementPtr->state_flags = APPEARING | FINITE_LIFE | NONSOLID;
IonElementPtr->life_span = IonElementPtr->thrust_wait = ION_LIFE; IonElementPtr->thrust_wait = ION_LIFE;
IonElementPtr->life_span = IonElementPtr->thrust_wait;
// When the element "dies", in the death_func
// 'cycle_ion_trail', it is given new life a number of
// times, by setting life_span to thrust_wait.
SetPrimType (&DisplayArray[IonElementPtr->PrimIndex], POINT_PRIM); SetPrimType (&DisplayArray[IonElementPtr->PrimIndex], POINT_PRIM);
SetPrimColor (&DisplayArray[IonElementPtr->PrimIndex], SetPrimColor (&DisplayArray[IonElementPtr->PrimIndex],
START_ION_COLOR); START_ION_COLOR);
IonElementPtr->cycle = 0;
IonElementPtr->current.image.frame = IonElementPtr->current.image.frame =
DecFrameIndex (stars_in_space); DecFrameIndex (stars_in_space);
IonElementPtr->current.image.farray = &stars_in_space; IonElementPtr->current.image.farray = &stars_in_space;
@@ -616,7 +658,7 @@ spawn_ion_trail (ELEMENT *ElementPtr)
(COORD)COSINE (angle, r.extent.height); (COORD)COSINE (angle, r.extent.height);
IonElementPtr->current.location.y += IonElementPtr->current.location.y +=
(COORD)SINE (angle, r.extent.height); (COORD)SINE (angle, r.extent.height);
IonElementPtr->death_func = spawn_ion_trail; IonElementPtr->death_func = cycle_ion_trail;
SetElementStarShip (IonElementPtr, StarShipPtr); SetElementStarShip (IonElementPtr, StarShipPtr);
@@ -633,48 +675,6 @@ spawn_ion_trail (ELEMENT *ElementPtr)
UnlockElement (hIonElement); UnlockElement (hIonElement);
} }
} }
else
{
static const COLOR color_tab[] =
{
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x00, 0x00), 0x2a),
BUILD_COLOR (MAKE_RGB15 (0x1B, 0x00, 0x00), 0x2b),
BUILD_COLOR (MAKE_RGB15 (0x17, 0x00, 0x00), 0x2c),
BUILD_COLOR (MAKE_RGB15 (0x13, 0x00, 0x00), 0x2d),
BUILD_COLOR (MAKE_RGB15 (0x0F, 0x00, 0x00), 0x2e),
BUILD_COLOR (MAKE_RGB15 (0x0B, 0x00, 0x00), 0x2f),
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x15, 0x00), 0x7a),
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x11, 0x00), 0x7b),
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x0E, 0x00), 0x7c),
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x0A, 0x00), 0x7d),
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x07, 0x00), 0x7e),
BUILD_COLOR (MAKE_RGB15 (0x1F, 0x03, 0x00), 0x7f),
};
#define NUM_TAB_COLORS (sizeof (color_tab) / sizeof (color_tab[0]))
COUNT color_index = 0;
COLOR Color;
Color = COLOR_256 (GetPrimColor (&DisplayArray[ElementPtr->PrimIndex]));
if (Color != 0x2F)
{
ElementPtr->life_span = ElementPtr->thrust_wait;
++Color;
if (Color > 0x7F)
Color = 0x2A;
if (Color <= 0x2f && Color >= 0x2a)
color_index = (COUNT)Color - 0x2a;
else /* color is between 0x7a and 0x7f */
color_index = (COUNT)(Color - 0x7a) + (NUM_TAB_COLORS >> 1);
SetPrimColor (&DisplayArray[ElementPtr->PrimIndex],
color_tab[color_index]);
ElementPtr->state_flags &= ~DISAPPEARING;
ElementPtr->state_flags |= CHANGING;
}
}
}
// Preprocess function for spawning a ship into or out of battle. // Preprocess function for spawning a ship into or out of battle.
// Used when a new ship warps in, or a ship escapes by warping out, but not // Used when a new ship warps in, or a ship escapes by warping out, but not
@@ -743,12 +743,16 @@ ship_transition (ELEMENT *ElementPtr)
LockElement (hShipImage, &ShipImagePtr); LockElement (hShipImage, &ShipImagePtr);
ShipImagePtr->playerNr = NEUTRAL_PLAYER_NUM; ShipImagePtr->playerNr = NEUTRAL_PLAYER_NUM;
ShipImagePtr->state_flags = APPEARING | FINITE_LIFE | NONSOLID; ShipImagePtr->state_flags = APPEARING | FINITE_LIFE | NONSOLID;
ShipImagePtr->life_span = ShipImagePtr->thrust_wait = ShipImagePtr->thrust_wait = TRANSITION_LIFE;
TRANSITION_LIFE; ShipImagePtr->life_span = ShipImagePtr->thrust_wait;
// When the element "dies", in the death_func
// 'cycle_ion_trail', it is given new life a number of
// times, by setting life_span to thrust_wait.
SetPrimType (&DisplayArray[ShipImagePtr->PrimIndex], SetPrimType (&DisplayArray[ShipImagePtr->PrimIndex],
STAMPFILL_PRIM); STAMPFILL_PRIM);
SetPrimColor (&DisplayArray[ShipImagePtr->PrimIndex], SetPrimColor (&DisplayArray[ShipImagePtr->PrimIndex],
START_ION_COLOR); START_ION_COLOR);
ShipImagePtr->cycle = 0;
ShipImagePtr->current.image = ElementPtr->current.image; ShipImagePtr->current.image = ElementPtr->current.image;
ShipImagePtr->current.location = ElementPtr->current.location; ShipImagePtr->current.location = ElementPtr->current.location;
if (!(ElementPtr->state_flags & PLAYER_SHIP)) if (!(ElementPtr->state_flags & PLAYER_SHIP))
@@ -774,7 +778,7 @@ ship_transition (ELEMENT *ElementPtr)
WRAP_Y (ShipImagePtr->current.location.y); WRAP_Y (ShipImagePtr->current.location.y);
} }
ShipImagePtr->preprocess_func = ship_transition; ShipImagePtr->preprocess_func = ship_transition;
ShipImagePtr->death_func = spawn_ion_trail; ShipImagePtr->death_func = cycle_ion_trail;
SetElementStarShip (ShipImagePtr, StarShipPtr); SetElementStarShip (ShipImagePtr, StarShipPtr);
UnlockElement (hShipImage); UnlockElement (hShipImage);