From e3862aefcd8b04ac5458b3a0a8e88dc79bffc7c7 Mon Sep 17 00:00:00 2001 From: Meep-Eep Date: Sat, 28 Nov 2009 15:07:38 +0000 Subject: [PATCH] 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 --- sc2/src/uqm/element.h | 5 +- sc2/src/uqm/tactrans.c | 178 +++++++++++++++++++++-------------------- 2 files changed, 95 insertions(+), 88 deletions(-) diff --git a/sc2/src/uqm/element.h b/sc2/src/uqm/element.h index 8a87532da..7a5b3ea7e 100644 --- a/sc2/src/uqm/element.h +++ b/sc2/src/uqm/element.h @@ -123,7 +123,10 @@ struct element COUNT crew_level; COUNT hit_points; 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 { diff --git a/sc2/src/uqm/tactrans.c b/sc2/src/uqm/tactrans.c index 28c343e7e..d597094cc 100644 --- a/sc2/src/uqm/tactrans.c +++ b/sc2/src/uqm/tactrans.c @@ -578,101 +578,101 @@ ship_death (ELEMENT *ShipPtr) #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 spawn_ion_trail (ELEMENT *ElementPtr) { - - if (ElementPtr->state_flags & PLAYER_SHIP) - { - HELEMENT hIonElement; + HELEMENT hIonElement; - hIonElement = AllocElement (); - if (hIonElement) - { + assert (ElementPtr->state_flags & PLAYER_SHIP); + + hIonElement = AllocElement (); + if (hIonElement) + { #define ION_LIFE 1 - COUNT angle; - RECT r; - ELEMENT *IonElementPtr; - STARSHIP *StarShipPtr; + COUNT angle; + RECT r; + ELEMENT *IonElementPtr; + STARSHIP *StarShipPtr; - GetElementStarShip (ElementPtr, &StarShipPtr); - angle = FACING_TO_ANGLE (StarShipPtr->ShipFacing) + HALF_CIRCLE; - GetFrameRect (StarShipPtr->RaceDescPtr->ship_data.ship[0], &r); - r.extent.height = DISPLAY_TO_WORLD (r.extent.height + r.corner.y); + GetElementStarShip (ElementPtr, &StarShipPtr); + angle = FACING_TO_ANGLE (StarShipPtr->ShipFacing) + HALF_CIRCLE; + GetFrameRect (StarShipPtr->RaceDescPtr->ship_data.ship[0], &r); + r.extent.height = DISPLAY_TO_WORLD (r.extent.height + r.corner.y); - InsertElement (hIonElement, GetHeadElement ()); - LockElement (hIonElement, &IonElementPtr); - IonElementPtr->playerNr = NEUTRAL_PLAYER_NUM; - IonElementPtr->state_flags = APPEARING | FINITE_LIFE | NONSOLID; - IonElementPtr->life_span = IonElementPtr->thrust_wait = ION_LIFE; - SetPrimType (&DisplayArray[IonElementPtr->PrimIndex], POINT_PRIM); - SetPrimColor (&DisplayArray[IonElementPtr->PrimIndex], - START_ION_COLOR); - IonElementPtr->current.image.frame = - DecFrameIndex (stars_in_space); - IonElementPtr->current.image.farray = &stars_in_space; - IonElementPtr->current.location = ElementPtr->current.location; - IonElementPtr->current.location.x += - (COORD)COSINE (angle, r.extent.height); - IonElementPtr->current.location.y += - (COORD)SINE (angle, r.extent.height); - IonElementPtr->death_func = spawn_ion_trail; + InsertElement (hIonElement, GetHeadElement ()); + LockElement (hIonElement, &IonElementPtr); + IonElementPtr->playerNr = NEUTRAL_PLAYER_NUM; + IonElementPtr->state_flags = APPEARING | FINITE_LIFE | NONSOLID; + 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); + SetPrimColor (&DisplayArray[IonElementPtr->PrimIndex], + START_ION_COLOR); + IonElementPtr->cycle = 0; + IonElementPtr->current.image.frame = + DecFrameIndex (stars_in_space); + IonElementPtr->current.image.farray = &stars_in_space; + IonElementPtr->current.location = ElementPtr->current.location; + IonElementPtr->current.location.x += + (COORD)COSINE (angle, r.extent.height); + IonElementPtr->current.location.y += + (COORD)SINE (angle, r.extent.height); + IonElementPtr->death_func = cycle_ion_trail; - SetElementStarShip (IonElementPtr, StarShipPtr); + SetElementStarShip (IonElementPtr, StarShipPtr); - { - /* normally done during preprocess, but because - * object is being inserted at head rather than - * appended after tail it may never get preprocessed. - */ - IonElementPtr->next = IonElementPtr->current; - --IonElementPtr->life_span; - IonElementPtr->state_flags |= PRE_PROCESS; - } - - 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; + /* normally done during preprocess, but because + * object is being inserted at head rather than + * appended after tail it may never get preprocessed. + */ + IonElementPtr->next = IonElementPtr->current; + --IonElementPtr->life_span; + IonElementPtr->state_flags |= PRE_PROCESS; } + + UnlockElement (hIonElement); } } @@ -743,12 +743,16 @@ ship_transition (ELEMENT *ElementPtr) LockElement (hShipImage, &ShipImagePtr); ShipImagePtr->playerNr = NEUTRAL_PLAYER_NUM; ShipImagePtr->state_flags = APPEARING | FINITE_LIFE | NONSOLID; - ShipImagePtr->life_span = ShipImagePtr->thrust_wait = - TRANSITION_LIFE; + ShipImagePtr->thrust_wait = 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], STAMPFILL_PRIM); SetPrimColor (&DisplayArray[ShipImagePtr->PrimIndex], START_ION_COLOR); + ShipImagePtr->cycle = 0; ShipImagePtr->current.image = ElementPtr->current.image; ShipImagePtr->current.location = ElementPtr->current.location; if (!(ElementPtr->state_flags & PLAYER_SHIP)) @@ -774,7 +778,7 @@ ship_transition (ELEMENT *ElementPtr) WRAP_Y (ShipImagePtr->current.location.y); } ShipImagePtr->preprocess_func = ship_transition; - ShipImagePtr->death_func = spawn_ion_trail; + ShipImagePtr->death_func = cycle_ion_trail; SetElementStarShip (ShipImagePtr, StarShipPtr); UnlockElement (hShipImage);