From: <av...@us...> - 2009-11-05 06:12:41
|
Revision: 3278 http://sc2.svn.sourceforge.net/sc2/?rev=3278&view=rev Author: avolkov Date: 2009-11-05 06:12:33 +0000 (Thu, 05 Nov 2009) Log Message: ----------- Moved static ship variables to per-instance RACE_DESC Modified Paths: -------------- trunk/sc2/src/uqm/races.h trunk/sc2/src/uqm/ships/androsyn/androsyn.c trunk/sc2/src/uqm/ships/mmrnmhrm/mmrnmhrm.c trunk/sc2/src/uqm/ships/pkunk/pkunk.c trunk/sc2/src/uqm/ships/umgah/umgah.c Modified: trunk/sc2/src/uqm/races.h =================================================================== --- trunk/sc2/src/uqm/races.h 2009-11-05 04:09:55 UTC (rev 3277) +++ trunk/sc2/src/uqm/races.h 2009-11-05 06:12:33 UTC (rev 3278) @@ -217,6 +217,8 @@ POSTPROCESS_FUNC *postprocess_func; INIT_WEAPON_FUNC *init_weapon_func; + intptr_t data; // private ship data, ship code owns this + void *CodeRef; }; @@ -276,8 +278,6 @@ // -1: neutral; this should currently never happen (asserts) BYTE control; // HUMAN, COMPUTER or NETWORK control flags, see intel.h - - intptr_t data; // private ship data, ship code owns this }; #define RPG_PLAYER_NUM 0 Modified: trunk/sc2/src/uqm/ships/androsyn/androsyn.c =================================================================== --- trunk/sc2/src/uqm/ships/androsyn/androsyn.c 2009-11-05 04:09:55 UTC (rev 3277) +++ trunk/sc2/src/uqm/ships/androsyn/androsyn.c 2009-11-05 06:12:33 UTC (rev 3278) @@ -20,8 +20,6 @@ #include "resinst.h" #include "libs/mathlib.h" -#include "uqm/init.h" - // for NUM_PLAYERS #define MAX_CREW 20 @@ -324,8 +322,6 @@ } } -static CollisionFunc *ship_collision_func[NUM_PLAYERS]; - #define BLAZER_TURN_WAIT 1 static void @@ -357,8 +353,10 @@ ElementPtr->mass_points = BLAZER_MASS; StarShipPtr->RaceDescPtr->characteristics.turn_wait = BLAZER_TURN_WAIT; - ship_collision_func[StarShipPtr->playerNr] - = ElementPtr->collision_func; + /* Save the current collision func because we were not the + * ones who set it */ + StarShipPtr->RaceDescPtr->data = (intptr_t) + ElementPtr->collision_func; ElementPtr->collision_func = blazer_collision; } } @@ -426,7 +424,8 @@ StarShipPtr->RaceDescPtr->characteristics.special_wait; StarShipPtr->RaceDescPtr->characteristics.energy_regeneration = ENERGY_REGENERATION; ElementPtr->mass_points = SHIP_MASS; - ElementPtr->collision_func = ship_collision_func[StarShipPtr->playerNr]; + ElementPtr->collision_func = (CollisionFunc *) + StarShipPtr->RaceDescPtr->data; ElementPtr->next.image.farray = StarShipPtr->RaceDescPtr->ship_data.ship; ElementPtr->next.image.frame = Modified: trunk/sc2/src/uqm/ships/mmrnmhrm/mmrnmhrm.c =================================================================== --- trunk/sc2/src/uqm/ships/mmrnmhrm/mmrnmhrm.c 2009-11-05 04:09:55 UTC (rev 3277) +++ trunk/sc2/src/uqm/ships/mmrnmhrm/mmrnmhrm.c 2009-11-05 06:12:33 UTC (rev 3278) @@ -19,10 +19,7 @@ #include "../ship.h" #include "resinst.h" -#include "uqm/init.h" - // for NUM_PLAYERS - #define MAX_CREW 20 #define MAX_ENERGY 10 #define ENERGY_REGENERATION 2 @@ -51,7 +48,6 @@ #define MMRNMHRM_OFFSET 16 #define LASER_RANGE DISPLAY_TO_WORLD (125 + MMRNMHRM_OFFSET) -static CHARACTERISTIC_STUFF otherwing_desc[NUM_PLAYERS]; static RACE_DESC mmrnmhrm_desc = { @@ -366,6 +362,7 @@ if (ElementPtr->next.image.farray != ElementPtr->current.image.farray) { CHARACTERISTIC_STUFF t; + CHARACTERISTIC_STUFF *otherwing_desc; ProcessSound (SetAbsSoundIndex ( /* TRANSFORM */ @@ -373,8 +370,11 @@ StarShipPtr->weapon_counter = 0; - t = otherwing_desc[StarShipPtr->playerNr]; - otherwing_desc[StarShipPtr->playerNr] = StarShipPtr->RaceDescPtr->characteristics; + /* Swap characteristics descriptors around */ + otherwing_desc = (CHARACTERISTIC_STUFF *) + StarShipPtr->RaceDescPtr->data; + t = *otherwing_desc; + *otherwing_desc = StarShipPtr->RaceDescPtr->characteristics; StarShipPtr->RaceDescPtr->characteristics = t; StarShipPtr->RaceDescPtr->cyborg_control.ManeuverabilityIndex = 0; @@ -412,24 +412,8 @@ GetElementStarShip (ElementPtr, &StarShipPtr); - if (ElementPtr->state_flags & APPEARING) + if (!(ElementPtr->state_flags & APPEARING)) { - // Set here because playerNr is unknown during init() - COUNT i = StarShipPtr->playerNr; - otherwing_desc[i].max_thrust = YWING_MAX_THRUST; - otherwing_desc[i].thrust_increment = YWING_THRUST_INCREMENT; - otherwing_desc[i].energy_regeneration = YWING_ENERGY_REGENERATION; - otherwing_desc[i].weapon_energy_cost = YWING_WEAPON_ENERGY_COST; - otherwing_desc[i].special_energy_cost = YWING_SPECIAL_ENERGY_COST; - otherwing_desc[i].energy_wait = YWING_ENERGY_WAIT; - otherwing_desc[i].turn_wait = YWING_TURN_WAIT; - otherwing_desc[i].thrust_wait = YWING_THRUST_WAIT; - otherwing_desc[i].weapon_wait = YWING_WEAPON_WAIT; - otherwing_desc[i].special_wait = YWING_SPECIAL_WAIT; - otherwing_desc[i].ship_mass = SHIP_MASS; - } - else - { if ((StarShipPtr->cur_status_flags & SPECIAL) && StarShipPtr->special_counter == 0) { @@ -455,18 +439,46 @@ } } +static void +uninit_mmrnmhrm (RACE_DESC *pRaceDesc) +{ + HFree ((void *)pRaceDesc->data); + pRaceDesc->data = 0; +} + RACE_DESC* init_mmrnmhrm (void) { RACE_DESC *RaceDescPtr; + static RACE_DESC new_mmrnmhrm_desc; + CHARACTERISTIC_STUFF *otherwing_desc; + + mmrnmhrm_desc.uninit_func = uninit_mmrnmhrm; mmrnmhrm_desc.preprocess_func = mmrnmhrm_preprocess; mmrnmhrm_desc.postprocess_func = mmrnmhrm_postprocess; mmrnmhrm_desc.init_weapon_func = initialize_dual_weapons; mmrnmhrm_desc.cyborg_control.intelligence_func = mmrnmhrm_intelligence; - RaceDescPtr = &mmrnmhrm_desc; + new_mmrnmhrm_desc = mmrnmhrm_desc; + otherwing_desc = HMalloc (sizeof (*otherwing_desc)); + otherwing_desc->max_thrust = YWING_MAX_THRUST; + otherwing_desc->thrust_increment = YWING_THRUST_INCREMENT; + otherwing_desc->energy_regeneration = YWING_ENERGY_REGENERATION; + otherwing_desc->weapon_energy_cost = YWING_WEAPON_ENERGY_COST; + otherwing_desc->special_energy_cost = YWING_SPECIAL_ENERGY_COST; + otherwing_desc->energy_wait = YWING_ENERGY_WAIT; + otherwing_desc->turn_wait = YWING_TURN_WAIT; + otherwing_desc->thrust_wait = YWING_THRUST_WAIT; + otherwing_desc->weapon_wait = YWING_WEAPON_WAIT; + otherwing_desc->special_wait = YWING_SPECIAL_WAIT; + otherwing_desc->ship_mass = SHIP_MASS; + + new_mmrnmhrm_desc.data = (intptr_t) otherwing_desc; + + RaceDescPtr = &new_mmrnmhrm_desc; + return (RaceDescPtr); } Modified: trunk/sc2/src/uqm/ships/pkunk/pkunk.c =================================================================== --- trunk/sc2/src/uqm/ships/pkunk/pkunk.c 2009-11-05 04:09:55 UTC (rev 3277) +++ trunk/sc2/src/uqm/ships/pkunk/pkunk.c 2009-11-05 06:12:33 UTC (rev 3278) @@ -187,12 +187,12 @@ HELEMENT hPhoenix; GetElementStarShip (ShipPtr, &StarShipPtr); - hPhoenix = (HELEMENT) StarShipPtr->data; + hPhoenix = (HELEMENT) StarShipPtr->RaceDescPtr->data; if (hPhoenix && (StarShipPtr->control & STANDARD_RATING)) { RemoveElement (hPhoenix); FreeElement (hPhoenix); - StarShipPtr->data = 0; + StarShipPtr->RaceDescPtr->data = 0; } if (StarShipPtr->RaceDescPtr->ship_info.energy_level < @@ -463,7 +463,7 @@ UnlockElement (hPhoenix); InsertElement (hPhoenix, GetHeadElement ()); } - StarShipPtr->data = (intptr_t) hPhoenix; + StarShipPtr->RaceDescPtr->data = (intptr_t) hPhoenix; if (ElementPtr->hTarget == 0) StarShipPtr->RaceDescPtr->preprocess_func = 0; Modified: trunk/sc2/src/uqm/ships/umgah/umgah.c =================================================================== --- trunk/sc2/src/uqm/ships/umgah/umgah.c 2009-11-05 04:09:55 UTC (rev 3277) +++ trunk/sc2/src/uqm/ships/umgah/umgah.c 2009-11-05 06:12:33 UTC (rev 3278) @@ -20,8 +20,6 @@ #include "resinst.h" #include "libs/mathlib.h" -#include "uqm/init.h" - // for NUM_PLAYERS #define MAX_CREW 10 @@ -39,7 +37,6 @@ #define SHIP_MASS 1 -static FRAME LastShipFrame[NUM_PLAYERS]; static RACE_DESC umgah_desc = { @@ -286,9 +283,9 @@ // This func is called every frame while the player is holding down WEAPON // Don't reset the cone FRAME to the first image every time - if (ShipPtr->next.image.frame != LastShipFrame[StarShipPtr->playerNr]) + if (ShipPtr->next.image.frame != (FRAME) StarShipPtr->RaceDescPtr->data) { - LastShipFrame[StarShipPtr->playerNr] = ShipPtr->next.image.frame; + StarShipPtr->RaceDescPtr->data = (intptr_t) ShipPtr->next.image.frame; StarShipPtr->RaceDescPtr->ship_data.special[0] = SetAbsFrameIndex ( @@ -341,9 +338,8 @@ if (ElementPtr->state_flags & APPEARING) { - // Reset prevously set value, if any. It could only have been - // set by another ship of the same player, though. - LastShipFrame[StarShipPtr->playerNr] = 0; + // Reset the value just in case + StarShipPtr->RaceDescPtr->data = 0; } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |