From: <av...@us...> - 2011-08-24 16:22:46
|
Revision: 3667 http://sc2.svn.sourceforge.net/sc2/?rev=3667&view=rev Author: avolkov Date: 2011-08-24 16:22:39 +0000 (Wed, 24 Aug 2011) Log Message: ----------- Various warning cleanups from Scott A. Colcord, bug #50; reworked Umgah ship code so as not to compare FRAMEs Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/build/msvc6/UrQuanMasters.dsp trunk/sc2/src/uqm/cleanup.c trunk/sc2/src/uqm/planets/Makeinfo trunk/sc2/src/uqm/planets/oval.c trunk/sc2/src/uqm/planets/solarsys.c trunk/sc2/src/uqm/races.h trunk/sc2/src/uqm/setupmenu.c 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/sis_ship/sis_ship.c trunk/sc2/src/uqm/ships/umgah/umgah.c Added Paths: ----------- trunk/sc2/src/uqm/planets/solarsys.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/ChangeLog 2011-08-24 16:22:39 UTC (rev 3667) @@ -1,4 +1,5 @@ Changes towards version 0.8: +- Various warnings cleanup (bug #50), from Scott A. Colcord - Fixed various Pkunk reincarnation and Shofixti Glory device interactions; Pkunk ditty plays in a simultaneous destruction (bug #666) - Alex - Preparing for linking with C++ code, from Scott A. Colcord Modified: trunk/sc2/build/msvc6/UrQuanMasters.dsp =================================================================== --- trunk/sc2/build/msvc6/UrQuanMasters.dsp 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/build/msvc6/UrQuanMasters.dsp 2011-08-24 16:22:39 UTC (rev 3667) @@ -2217,6 +2217,10 @@ # End Source File # Begin Source File +SOURCE=..\..\src\uqm\planets\solarsys.h +# End Source File +# Begin Source File + SOURCE=..\..\src\uqm\planets\sundata.h # End Source File # Begin Source File Modified: trunk/sc2/src/uqm/cleanup.c =================================================================== --- trunk/sc2/src/uqm/cleanup.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/cleanup.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -25,15 +25,12 @@ #include "planets/lander.h" #include "starcon.h" #include "setup.h" +#include "planets/solarsys.h" #include "sounds.h" #include "libs/sndlib.h" #include "libs/vidlib.h" -// XXX: we do not current have a header for this prototype to live in -// should be something like solarsys.h -extern void FreeIPData (void); - void FreeKernel (void) { Modified: trunk/sc2/src/uqm/planets/Makeinfo =================================================================== --- trunk/sc2/src/uqm/planets/Makeinfo 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/planets/Makeinfo 2011-08-24 16:22:39 UTC (rev 3667) @@ -3,5 +3,5 @@ oval.c pl_stuff.c planets.c plangen.c pstarmap.c report.c roster.c scan.c solarsys.c surface.c" uqm_HFILES="elemdata.h generate.h lander.h lifeform.h plandata.h planets.h - scan.h sundata.h" + scan.h solarsys.h sundata.h" Modified: trunk/sc2/src/uqm/planets/oval.c =================================================================== --- trunk/sc2/src/uqm/planets/oval.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/planets/oval.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -21,6 +21,7 @@ #include "libs/graphics/context.h" #include "libs/graphics/drawable.h" +#include "planets.h" #define NUM_QUADS 4 Modified: trunk/sc2/src/uqm/planets/solarsys.c =================================================================== --- trunk/sc2/src/uqm/planets/solarsys.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/planets/solarsys.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -16,6 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "solarsys.h" #include "lander.h" #include "../colors.h" #include "../controls.h" Added: trunk/sc2/src/uqm/planets/solarsys.h =================================================================== --- trunk/sc2/src/uqm/planets/solarsys.h (rev 0) +++ trunk/sc2/src/uqm/planets/solarsys.h 2011-08-24 16:22:39 UTC (rev 3667) @@ -0,0 +1,34 @@ +//Copyright (C) 2011, Scott A. Colcord + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef SOLARSYS_H +#define SOLARSYS_H + +#if defined(__cplusplus) +extern "C" { +#endif + +extern void LoadIPData (void); +extern void FreeIPData (void); + +#if defined(__cplusplus) +} +#endif + +#endif /* SOLARSYS_H */ + Property changes on: trunk/sc2/src/uqm/planets/solarsys.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/sc2/src/uqm/races.h =================================================================== --- trunk/sc2/src/uqm/races.h 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/races.h 2011-08-24 16:22:39 UTC (rev 3667) @@ -221,7 +221,7 @@ POSTPROCESS_FUNC *postprocess_func; INIT_WEAPON_FUNC *init_weapon_func; - intptr_t data; // private ship data, ship code owns this + void* data; // private ship data, ship code owns this void *CodeRef; }; Modified: trunk/sc2/src/uqm/setupmenu.c =================================================================== --- trunk/sc2/src/uqm/setupmenu.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/setupmenu.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -766,7 +766,7 @@ } static int -count_widgets (const WIDGET **widgets) +count_widgets (WIDGET **widgets) { int count; Modified: trunk/sc2/src/uqm/ships/androsyn/androsyn.c =================================================================== --- trunk/sc2/src/uqm/ships/androsyn/androsyn.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/ships/androsyn/androsyn.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -110,6 +110,46 @@ 0, /* CodeRef */ }; + +// Private per-instance ship data +typedef struct +{ + ElementCollisionFunc* collision_func; +} ANDROSYNTH_DATA; + +// Local typedef +typedef ANDROSYNTH_DATA CustomShipData_t; + +// Retrieve race-specific ship data from a race desc +static CustomShipData_t * +GetCustomShipData (RACE_DESC *pRaceDesc) +{ + return pRaceDesc->data; +} + +// Set the race-specific data in a race desc +// (Re)Allocates its own storage for the data. +static void +SetCustomShipData (RACE_DESC *pRaceDesc, const CustomShipData_t *data) +{ + if (pRaceDesc->data == data) + return; // no-op + + if (pRaceDesc->data) // Out with the old + { + HFree (pRaceDesc->data); + pRaceDesc->data = NULL; + } + + if (data) // In with the new + { + CustomShipData_t* newData = HMalloc (sizeof (*data)); + *newData = *data; + pRaceDesc->data = newData; + } +} + + #define BLAZER_DAMAGE 3 #define BLAZER_MASS 1 @@ -355,11 +395,14 @@ ElementPtr->mass_points = BLAZER_MASS; StarShipPtr->RaceDescPtr->characteristics.turn_wait = BLAZER_TURN_WAIT; + /* 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; + { + const ANDROSYNTH_DATA shipData = { ElementPtr->collision_func }; + SetCustomShipData (StarShipPtr->RaceDescPtr, &shipData); + ElementPtr->collision_func = blazer_collision; + } } } @@ -426,8 +469,8 @@ StarShipPtr->RaceDescPtr->characteristics.special_wait; StarShipPtr->RaceDescPtr->characteristics.energy_regeneration = ENERGY_REGENERATION; ElementPtr->mass_points = SHIP_MASS; - ElementPtr->collision_func = (ElementCollisionFunc *) - StarShipPtr->RaceDescPtr->data; + ElementPtr->collision_func = + GetCustomShipData (StarShipPtr->RaceDescPtr)->collision_func; ElementPtr->next.image.farray = StarShipPtr->RaceDescPtr->ship_data.ship; ElementPtr->next.image.frame = @@ -463,11 +506,19 @@ StarShipPtr->cur_status_flags = cur_status_flags; } +static void +uninit_androsynth (RACE_DESC *pRaceDesc) +{ + SetCustomShipData (pRaceDesc, NULL); +} + + RACE_DESC* init_androsynth (void) { RACE_DESC *RaceDescPtr; + androsynth_desc.uninit_func = uninit_androsynth; androsynth_desc.preprocess_func = androsynth_preprocess; androsynth_desc.postprocess_func = androsynth_postprocess; androsynth_desc.init_weapon_func = initialize_bubble; Modified: trunk/sc2/src/uqm/ships/mmrnmhrm/mmrnmhrm.c =================================================================== --- trunk/sc2/src/uqm/ships/mmrnmhrm/mmrnmhrm.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/ships/mmrnmhrm/mmrnmhrm.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -124,7 +124,42 @@ #define MISSILE_SPEED DISPLAY_TO_WORLD (20) #define TRACK_WAIT 5 +// Private per-instance ship data +typedef CHARACTERISTIC_STUFF MMRNMHRM_DATA; + +// Local typedef +typedef MMRNMHRM_DATA CustomShipData_t; + +// Retrieve race-specific ship data from a race desc +static CustomShipData_t * +GetCustomShipData (RACE_DESC *pRaceDesc) +{ + return pRaceDesc->data; +} + +// Set the race-specific data in a race desc +// (Re)Allocates its own storage for the data. static void +SetCustomShipData (RACE_DESC *pRaceDesc, const CustomShipData_t *data) +{ + if (pRaceDesc->data == data) + return; // no-op + + if (pRaceDesc->data) // Out with the old + { + HFree (pRaceDesc->data); + pRaceDesc->data = NULL; + } + + if (data) // In with the new + { + CustomShipData_t* newData = HMalloc (sizeof (*data)); + *newData = *data; + pRaceDesc->data = newData; + } +} + +static void missile_preprocess (ELEMENT *ElementPtr) { if (ElementPtr->turn_wait > 0) @@ -363,8 +398,8 @@ /* take care of transform effect */ if (ElementPtr->next.image.farray != ElementPtr->current.image.farray) { - CHARACTERISTIC_STUFF t; - CHARACTERISTIC_STUFF *otherwing_desc; + MMRNMHRM_DATA tempShipData; + MMRNMHRM_DATA *otherwing_desc; ProcessSound (SetAbsSoundIndex ( /* TRANSFORM */ @@ -373,11 +408,13 @@ StarShipPtr->weapon_counter = 0; /* Swap characteristics descriptors around */ - otherwing_desc = (CHARACTERISTIC_STUFF *) - StarShipPtr->RaceDescPtr->data; - t = *otherwing_desc; - *otherwing_desc = StarShipPtr->RaceDescPtr->characteristics; - StarShipPtr->RaceDescPtr->characteristics = t; + otherwing_desc = GetCustomShipData (StarShipPtr->RaceDescPtr); + if (!otherwing_desc) + return; // No ship data (?!) + + tempShipData = *otherwing_desc; + SetCustomShipData (StarShipPtr->RaceDescPtr, &StarShipPtr->RaceDescPtr->characteristics); + StarShipPtr->RaceDescPtr->characteristics = tempShipData; StarShipPtr->RaceDescPtr->cyborg_control.ManeuverabilityIndex = 0; if (ElementPtr->next.image.farray == StarShipPtr->RaceDescPtr->ship_data.special) @@ -444,8 +481,7 @@ static void uninit_mmrnmhrm (RACE_DESC *pRaceDesc) { - HFree ((void *)pRaceDesc->data); - pRaceDesc->data = 0; + SetCustomShipData (pRaceDesc, NULL); } RACE_DESC* @@ -454,7 +490,7 @@ RACE_DESC *RaceDescPtr; // The caller of this func will copy the struct static RACE_DESC new_mmrnmhrm_desc; - CHARACTERISTIC_STUFF *otherwing_desc; + MMRNMHRM_DATA otherwing_desc; mmrnmhrm_desc.uninit_func = uninit_mmrnmhrm; mmrnmhrm_desc.preprocess_func = mmrnmhrm_preprocess; @@ -464,20 +500,19 @@ 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; + 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; + SetCustomShipData (&new_mmrnmhrm_desc, &otherwing_desc); RaceDescPtr = &new_mmrnmhrm_desc; Modified: trunk/sc2/src/uqm/ships/pkunk/pkunk.c =================================================================== --- trunk/sc2/src/uqm/ships/pkunk/pkunk.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/ships/pkunk/pkunk.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -123,7 +123,39 @@ } PKUNK_DATA; +// Local typedef +typedef PKUNK_DATA CustomShipData_t; + +// Retrieve race-specific ship data from a race desc +static CustomShipData_t * +GetCustomShipData (RACE_DESC *pRaceDesc) +{ + return pRaceDesc->data; +} + +// Set the race-specific data in a race desc +// (Re)Allocates its own storage for the data. static void +SetCustomShipData (RACE_DESC *pRaceDesc, const CustomShipData_t *data) +{ + if (pRaceDesc->data == data) + return; // no-op + + if (pRaceDesc->data) // Out with the old + { + HFree (pRaceDesc->data); + pRaceDesc->data = NULL; + } + + if (data) // In with the new + { + CustomShipData_t* newData = HMalloc (sizeof (*data)); + *newData = *data; + pRaceDesc->data = newData; + } +} + +static void animate (ELEMENT *ElementPtr) { if (ElementPtr->turn_wait > 0) @@ -200,7 +232,7 @@ PKUNK_DATA *PkunkData; GetElementStarShip (ShipPtr, &StarShipPtr); - PkunkData = (PKUNK_DATA *) StarShipPtr->RaceDescPtr->data; + PkunkData = GetCustomShipData (StarShipPtr->RaceDescPtr); if (PkunkData->hPhoenix && (StarShipPtr->control & STANDARD_RATING)) { RemoveElement (PkunkData->hPhoenix); @@ -227,7 +259,7 @@ PKUNK_DATA *PkunkData; GetElementStarShip (ElementPtr, &StarShipPtr); - PkunkData = (PKUNK_DATA *) StarShipPtr->RaceDescPtr->data; + PkunkData = GetCustomShipData (StarShipPtr->RaceDescPtr); ElementPtr->state_flags = APPEARING | PLAYER_SHIP | IGNORE_SIMILAR; ElementPtr->mass_points = SHIP_MASS; @@ -301,7 +333,7 @@ ELEMENT *ShipPtr; GetElementStarShip (ElementPtr, &StarShipPtr); - PkunkData = (PKUNK_DATA *) StarShipPtr->RaceDescPtr->data; + PkunkData = GetCustomShipData (StarShipPtr->RaceDescPtr); if (StarShipPtr->RaceDescPtr->ship_info.crew_level != 0) { // Ship not dead yet. @@ -447,7 +479,7 @@ PKUNK_DATA *PkunkData; GetElementStarShip (ElementPtr, &StarShipPtr); - PkunkData = (PKUNK_DATA *) StarShipPtr->RaceDescPtr->data; + PkunkData = GetCustomShipData (StarShipPtr->RaceDescPtr); if (ElementPtr->state_flags & APPEARING) { HELEMENT hPhoenix = 0; @@ -572,8 +604,7 @@ static void uninit_pkunk (RACE_DESC *pRaceDesc) { - HFree ((void *)pRaceDesc->data); - pRaceDesc->data = 0; + SetCustomShipData (pRaceDesc, NULL); } RACE_DESC* @@ -582,6 +613,8 @@ RACE_DESC *RaceDescPtr; // The caller of this func will copy the struct static RACE_DESC new_pkunk_desc; + PKUNK_DATA empty_data; + memset (&empty_data, 0, sizeof (empty_data)); pkunk_desc.uninit_func = uninit_pkunk; pkunk_desc.preprocess_func = pkunk_preprocess; @@ -591,7 +624,7 @@ /* copy initial ship settings to the new descriptor */ new_pkunk_desc = pkunk_desc; - new_pkunk_desc.data = (intptr_t) HCalloc (sizeof (PKUNK_DATA)); + SetCustomShipData (&new_pkunk_desc, &empty_data); RaceDescPtr = &new_pkunk_desc; Modified: trunk/sc2/src/uqm/ships/sis_ship/sis_ship.c =================================================================== --- trunk/sc2/src/uqm/ships/sis_ship/sis_ship.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/ships/sis_ship/sis_ship.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -136,10 +136,42 @@ const BYTE *DriveSlots); static void InitJetSlots (RACE_DESC *RaceDescPtr, const BYTE *JetSlots); -void uninit_sis (RACE_DESC *pRaceDesc); +static void uninit_sis (RACE_DESC *pRaceDesc); +// Local typedef +typedef SIS_DATA CustomShipData_t; + +// Retrieve race-specific ship data from a race desc +static CustomShipData_t * +GetCustomShipData (RACE_DESC *pRaceDesc) +{ + return pRaceDesc->data; +} + +// Set the race-specific data in a race desc +// (Re)Allocates its own storage for the data. static void +SetCustomShipData (RACE_DESC *pRaceDesc, const CustomShipData_t *data) +{ + if (pRaceDesc->data == data) + return; // no-op + + if (pRaceDesc->data) // Out with the old + { + HFree (pRaceDesc->data); + pRaceDesc->data = NULL; + } + + if (data) // In with the new + { + CustomShipData_t* newData = HMalloc (sizeof (*data)); + *newData = *data; + pRaceDesc->data = newData; + } +} + +static void sis_hyper_preprocess (ELEMENT *ElementPtr) { SIZE udx = 0, udy = 0; @@ -566,7 +598,7 @@ SIS_DATA *SisData; GetElementStarShip (ShipPtr, &StarShipPtr); - SisData = (SIS_DATA *) StarShipPtr->RaceDescPtr->data; + SisData = GetCustomShipData (StarShipPtr->RaceDescPtr); nt = (BYTE)((4 - SisData->num_trackers) & 3); @@ -606,7 +638,7 @@ SIS_DATA *SisData; GetElementStarShip (ShipPtr, &StarShipPtr); - SisData = (SIS_DATA *) StarShipPtr->RaceDescPtr->data; + SisData = GetCustomShipData (StarShipPtr->RaceDescPtr); lpEvalDesc = &ObjectsOfConcern[ENEMY_WEAPON_INDEX]; if (lpEvalDesc->ObjectPtr) @@ -680,7 +712,7 @@ #define BLASTER_HITS 2 #define BLASTER_OFFSET 8 COUNT i; - SIS_DATA *SisData = (SIS_DATA *) RaceDescPtr->data; + SIS_DATA *SisData = GetCustomShipData (RaceDescPtr); MISSILE_BLOCK *lpMB = SisData->MissileBlock; SisData->num_blasters = 0; @@ -760,7 +792,7 @@ { COUNT i; COUNT num_trackers; - SIS_DATA *SisData = (SIS_DATA *) RaceDescPtr->data; + SIS_DATA *SisData = GetCustomShipData (RaceDescPtr); RaceDescPtr->ship_info.max_crew = 0; num_trackers = 0; @@ -851,6 +883,8 @@ COUNT i; // The caller of this func will copy the struct static RACE_DESC new_sis_desc; + SIS_DATA empty_data; + memset (&empty_data, 0, sizeof (empty_data)); /* copy initial ship settings to new_sis_desc */ new_sis_desc = sis_desc; @@ -888,7 +922,7 @@ SET_GAME_STATE (BOMB_CARRIER, 1); } - new_sis_desc.data = (intptr_t) HCalloc (sizeof (SIS_DATA)); + SetCustomShipData (&new_sis_desc, &empty_data); InitModuleSlots (&new_sis_desc, GLOBAL_SIS (ModuleSlots)); InitWeaponSlots (&new_sis_desc, GLOBAL_SIS (ModuleSlots)); InitDriveSlots (&new_sis_desc, GLOBAL_SIS (DriveSlots)); @@ -913,7 +947,7 @@ return (RaceDescPtr); } -void +static void uninit_sis (RACE_DESC *pRaceDesc) { if (LOBYTE (GLOBAL (CurrentActivity)) != IN_HYPERSPACE) @@ -923,8 +957,7 @@ GLOBAL_SIS (CrewEnlisted)--; } - HFree ((void *)pRaceDesc->data); - pRaceDesc->data = 0; + SetCustomShipData (pRaceDesc, NULL); } Modified: trunk/sc2/src/uqm/ships/umgah/umgah.c =================================================================== --- trunk/sc2/src/uqm/ships/umgah/umgah.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/ships/umgah/umgah.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -110,7 +110,47 @@ 0, /* CodeRef */ }; + +// Private per-instance ship data +typedef struct +{ + UWORD prevFacing; +} UMGAH_DATA; + +// Local typedef +typedef UMGAH_DATA CustomShipData_t; + +// Retrieve race-specific ship data from a race desc +static CustomShipData_t * +GetCustomShipData (RACE_DESC *pRaceDesc) +{ + return pRaceDesc->data; +} + +// Set the race-specific data in a race desc +// (Re)Allocates its own storage for the data. static void +SetCustomShipData (RACE_DESC *pRaceDesc, const CustomShipData_t *data) +{ + if (pRaceDesc->data == data) + return; // no-op + + if (pRaceDesc->data) // Out with the old + { + HFree (pRaceDesc->data); + pRaceDesc->data = NULL; + } + + if (data) // In with the new + { + CustomShipData_t* newData = HMalloc (sizeof (*data)); + *newData = *data; + pRaceDesc->data = newData; + } +} + + +static void cone_preprocess (ELEMENT *ElementPtr) { STARSHIP *StarShipPtr; @@ -266,6 +306,7 @@ #define MISSILE_LIFE 1 #define MISSILE_OFFSET 0 STARSHIP *StarShipPtr; + UMGAH_DATA* UmgahData; MISSILE_BLOCK MissileBlock; GetElementStarShip (ShipPtr, &StarShipPtr); @@ -285,15 +326,17 @@ // 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 != (FRAME) StarShipPtr->RaceDescPtr->data) + UmgahData = GetCustomShipData (StarShipPtr->RaceDescPtr); + if (!UmgahData || StarShipPtr->ShipFacing != UmgahData->prevFacing) { - StarShipPtr->RaceDescPtr->data = (intptr_t) ShipPtr->next.image.frame; + const UMGAH_DATA shipData = {StarShipPtr->ShipFacing}; + SetCustomShipData (StarShipPtr->RaceDescPtr, &shipData); + StarShipPtr->RaceDescPtr->ship_data.special[0] = SetAbsFrameIndex ( StarShipPtr->RaceDescPtr->ship_data.special[0], - StarShipPtr->ShipFacing - ); + StarShipPtr->ShipFacing); } MissileBlock.index = GetFrameIndex (StarShipPtr->RaceDescPtr->ship_data.special[0]); @@ -341,7 +384,7 @@ if (ElementPtr->state_flags & APPEARING) { // Reset the value just in case - StarShipPtr->RaceDescPtr->data = 0; + SetCustomShipData (StarShipPtr->RaceDescPtr, NULL); } else { @@ -366,11 +409,18 @@ } } +static void +uninit_umgah (RACE_DESC *pRaceDesc) +{ + SetCustomShipData (pRaceDesc, NULL); +} + RACE_DESC* init_umgah (void) { RACE_DESC *RaceDescPtr; + umgah_desc.uninit_func = uninit_umgah; umgah_desc.preprocess_func = umgah_preprocess; umgah_desc.postprocess_func = umgah_postprocess; umgah_desc.init_weapon_func = initialize_cone; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <av...@us...> - 2011-09-09 01:59:20
|
Revision: 3694 http://sc2.svn.sourceforge.net/sc2/?rev=3694&view=rev Author: avolkov Date: 2011-09-09 01:59:12 +0000 (Fri, 09 Sep 2011) Log Message: ----------- Planet/system generation code cleanup: isolate generation code with an own RandomContext; generation funcs do not return the random seed anymore; move and cleanup some calculation funcs; clarify deliberate Random() truncation; other random cleanups Modified Paths: -------------- trunk/sc2/build/msvc6/UrQuanMasters.dsp trunk/sc2/src/libs/math/random.h trunk/sc2/src/libs/math/random2.c trunk/sc2/src/uqm/Makeinfo trunk/sc2/src/uqm/comm.c trunk/sc2/src/uqm/encount.c trunk/sc2/src/uqm/encount.h trunk/sc2/src/uqm/gameev.c trunk/sc2/src/uqm/gameopt.c trunk/sc2/src/uqm/gendef.c trunk/sc2/src/uqm/gendef.h trunk/sc2/src/uqm/globdata.c trunk/sc2/src/uqm/grpinfo.c trunk/sc2/src/uqm/hyper.c trunk/sc2/src/uqm/load.c trunk/sc2/src/uqm/plandata.c trunk/sc2/src/uqm/planets/calc.c trunk/sc2/src/uqm/planets/devices.c trunk/sc2/src/uqm/planets/generate/genburv.c trunk/sc2/src/uqm/planets/generate/genchmmr.c trunk/sc2/src/uqm/planets/generate/gendefault.c trunk/sc2/src/uqm/planets/generate/genmel.c trunk/sc2/src/uqm/planets/generate/genmyc.c trunk/sc2/src/uqm/planets/generate/genorz.c trunk/sc2/src/uqm/planets/generate/genpet.c trunk/sc2/src/uqm/planets/generate/genrain.c trunk/sc2/src/uqm/planets/generate/gensam.c trunk/sc2/src/uqm/planets/generate/gensol.c trunk/sc2/src/uqm/planets/generate/genspa.c trunk/sc2/src/uqm/planets/generate/genthrad.c trunk/sc2/src/uqm/planets/generate/genutw.c trunk/sc2/src/uqm/planets/generate/genvux.c trunk/sc2/src/uqm/planets/gentopo.c trunk/sc2/src/uqm/planets/lander.c trunk/sc2/src/uqm/planets/orbits.c trunk/sc2/src/uqm/planets/plandata.h trunk/sc2/src/uqm/planets/planets.h trunk/sc2/src/uqm/planets/plangen.c trunk/sc2/src/uqm/planets/pstarmap.c trunk/sc2/src/uqm/planets/scan.c trunk/sc2/src/uqm/planets/solarsys.c trunk/sc2/src/uqm/planets/sundata.h trunk/sc2/src/uqm/planets/surface.c trunk/sc2/src/uqm/restart.c trunk/sc2/src/uqm/save.c trunk/sc2/src/uqm/sis.c trunk/sc2/src/uqm/starbase.c trunk/sc2/src/uqm/starmap.c trunk/sc2/src/uqm/state.c trunk/sc2/src/uqm/uqmdebug.c Added Paths: ----------- trunk/sc2/src/uqm/starmap.h Modified: trunk/sc2/build/msvc6/UrQuanMasters.dsp =================================================================== --- trunk/sc2/build/msvc6/UrQuanMasters.dsp 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/build/msvc6/UrQuanMasters.dsp 2011-09-09 01:59:12 UTC (rev 3694) @@ -3482,6 +3482,10 @@ # End Source File # Begin Source File +SOURCE=..\..\src\uqm\starmap.h +# End Source File +# Begin Source File + SOURCE=..\..\src\uqm\state.c # End Source File # Begin Source File Modified: trunk/sc2/src/libs/math/random.h =================================================================== --- trunk/sc2/src/libs/math/random.h 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/libs/math/random.h 2011-09-09 01:59:12 UTC (rev 3694) @@ -29,13 +29,6 @@ #ifndef _RANDOM_H #define _RANDOM_H -/* ----------------------------DEFINES------------------------------------ */ - -#define RAND(n) ( (int) ( (unsigned int)TFB_Random() % (n) ) ) -#define SRAND(n) ( (int)TFB_Random() % (n) ) -#define AND_RAND(n) ( (int)TFB_Random() & (n) ) - - /* ----------------------------GLOBALS/EXTERNS---------------------------- */ DWORD TFB_SeedRandom (DWORD seed); @@ -55,6 +48,7 @@ RandomContext *RandomContext_Copy (const RandomContext *source); DWORD RandomContext_Random (RandomContext *context); DWORD RandomContext_SeedRandom (RandomContext *context, DWORD new_seed); +DWORD RandomContext_GetSeed (RandomContext *context); #endif /* _RANDOM_H */ Modified: trunk/sc2/src/libs/math/random2.c =================================================================== --- trunk/sc2/src/libs/math/random2.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/libs/math/random2.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -82,4 +82,8 @@ return old_seed; } - +DWORD +RandomContext_GetSeed (RandomContext *context) +{ + return context->seed; +} Modified: trunk/sc2/src/uqm/Makeinfo =================================================================== --- trunk/sc2/src/uqm/Makeinfo 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/Makeinfo 2011-09-09 01:59:12 UTC (rev 3694) @@ -18,5 +18,6 @@ nameref.h oscill.h pickship.h process.h races.h resinst.h respkg.h restart.h save.h settings.h setup.h setupmenu.h shipcont.h ship.h sis.h sounds.h starbase.h starcon.h state.h status.h tactrans.h + starmap.h units.h uqmdebug.h util.h velocity.h weapon.h" Modified: trunk/sc2/src/uqm/comm.c =================================================================== --- trunk/sc2/src/uqm/comm.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/comm.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -27,6 +27,7 @@ #include "sis.h" #include "units.h" #include "encount.h" +#include "starmap.h" #include "endian_uqm.h" #include "gamestr.h" #include "options.h" Modified: trunk/sc2/src/uqm/encount.c =================================================================== --- trunk/sc2/src/uqm/encount.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/encount.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -22,6 +22,7 @@ #include "battlecontrols.h" #include "build.h" #include "colors.h" +#include "starmap.h" #include "cons_res.h" #include "controls.h" #include "menustat.h" Modified: trunk/sc2/src/uqm/encount.h =================================================================== --- trunk/sc2/src/uqm/encount.h 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/encount.h 2011-09-09 01:59:12 UTC (rev 3694) @@ -95,76 +95,10 @@ enum { - SOL_DEFINED = 1, - SHOFIXTI_DEFINED, - MAIDENS_DEFINED, - START_COLONY_DEFINED, - SPATHI_DEFINED, - ZOQFOT_DEFINED, - - MELNORME0_DEFINED, - MELNORME1_DEFINED, - MELNORME2_DEFINED, - MELNORME3_DEFINED, - MELNORME4_DEFINED, - MELNORME5_DEFINED, - MELNORME6_DEFINED, - MELNORME7_DEFINED, - MELNORME8_DEFINED, - - TALKING_PET_DEFINED, - CHMMR_DEFINED, - SYREEN_DEFINED, - BURVIXESE_DEFINED, - SLYLANDRO_DEFINED, - DRUUGE_DEFINED, - BOMB_DEFINED, - AQUA_HELIX_DEFINED, - SUN_DEVICE_DEFINED, - TAALO_PROTECTOR_DEFINED, - SHIP_VAULT_DEFINED, - URQUAN_WRECK_DEFINED, - VUX_BEAST_DEFINED, - SAMATRA_DEFINED, - ZOQ_SCOUT_DEFINED, - MYCON_DEFINED, - EGG_CASE0_DEFINED, - EGG_CASE1_DEFINED, - EGG_CASE2_DEFINED, - PKUNK_DEFINED, - UTWIG_DEFINED, - SUPOX_DEFINED, - YEHAT_DEFINED, - VUX_DEFINED, - ORZ_DEFINED, - THRADD_DEFINED, - RAINBOW_DEFINED, - ILWRATH_DEFINED, - ANDROSYNTH_DEFINED, - MYCON_TRAP_DEFINED -}; - -#define UMGAH_DEFINED TALKING_PET_DEFINED - -// XXX: The stuff till EOC does not belong here -extern STAR_DESC *CurStarDescPtr; -extern STAR_DESC *star_array; - -#define NUM_SOLAR_SYSTEMS 502 - -extern STAR_DESC* FindStar (STAR_DESC *pLastStar, POINT *puniverse, - SIZE xbounds, SIZE ybounds); - -extern void GetClusterName (const STAR_DESC *pSD, UNICODE buf[]); -// <<< EOC - -enum -{ HAIL = 0, ATTACK }; - extern void EncounterBattle (void); extern void BuildBattle (COUNT which_player); extern COUNT InitEncounter (void); @@ -172,35 +106,6 @@ extern BOOLEAN FleetIsInfinite (COUNT playerNr); extern void UpdateShipFragCrew (STARSHIP *); -// XXX: in comm.h, temporary, until solsys generation code is redone -extern COUNT InitCommunication (CONVERSATION which_comm); - -extern void GenerateSOL (BYTE control); -extern void GenerateShofixti (BYTE control); -extern void GenerateColony (BYTE control); -extern void GenerateSpathi (BYTE control); -extern void GenerateZoqFotPik (BYTE control); -extern void GenerateMelnorme (BYTE control); -extern void GenerateTalkingPet (BYTE control); -extern void GenerateChmmr (BYTE control); -extern void GenerateSyreen (BYTE control); -extern void GenerateBurvixes (BYTE control); -extern void GenerateSlylandro (BYTE control); -extern void GenerateDruuge (BYTE control); -extern void GenerateUtwig (BYTE control); -extern void GenerateThradd (BYTE control); -extern void GenerateMycon (BYTE control); -extern void GenerateOrz (BYTE control); -extern void GenerateShipVault (BYTE control); -extern void GenerateUrquanWreck (BYTE control); -extern void GenerateVUX (BYTE control); -extern void GenerateSamatra (BYTE control); -extern void GenerateYehat (BYTE control); -extern void GeneratePkunk (BYTE control); -extern void GenerateSupox (BYTE control); -extern void GenerateRainbow (BYTE control); -extern void GenerateIlwrath (BYTE control); - // Last race the player battled with, or -1 if no battle took place. // Set to -1 by some funcs to inhibit IP groups from intercepting // the flagship. Modified: trunk/sc2/src/uqm/gameev.c =================================================================== --- trunk/sc2/src/uqm/gameev.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/gameev.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -19,8 +19,8 @@ #include "build.h" #include "clock.h" -// XXX: for CurStarDescPtr and XXX_DEFINED constants -#include "encount.h" +#include "starmap.h" +#include "gendef.h" #include "globdata.h" #include "hyper.h" #include "libs/compiler.h" Modified: trunk/sc2/src/uqm/gameopt.c =================================================================== --- trunk/sc2/src/uqm/gameopt.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/gameopt.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -21,8 +21,7 @@ #include "build.h" #include "colors.h" #include "controls.h" -// XXX: for FindStart(), GetClusterName() -#include "encount.h" +#include "starmap.h" #include "menustat.h" #include "sis.h" #include "units.h" Modified: trunk/sc2/src/uqm/gendef.c =================================================================== --- trunk/sc2/src/uqm/gendef.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/gendef.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -17,7 +17,6 @@ */ #include "gendef.h" -#include "encount.h" #include "planets/generate.h" Modified: trunk/sc2/src/uqm/gendef.h =================================================================== --- trunk/sc2/src/uqm/gendef.h 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/gendef.h 2011-09-09 01:59:12 UTC (rev 3694) @@ -10,6 +10,59 @@ const GenerateFunctions *getGenerateFunctions (BYTE Index); +enum +{ + SOL_DEFINED = 1, + SHOFIXTI_DEFINED, + MAIDENS_DEFINED, + START_COLONY_DEFINED, + SPATHI_DEFINED, + ZOQFOT_DEFINED, + + MELNORME0_DEFINED, + MELNORME1_DEFINED, + MELNORME2_DEFINED, + MELNORME3_DEFINED, + MELNORME4_DEFINED, + MELNORME5_DEFINED, + MELNORME6_DEFINED, + MELNORME7_DEFINED, + MELNORME8_DEFINED, + + TALKING_PET_DEFINED, + CHMMR_DEFINED, + SYREEN_DEFINED, + BURVIXESE_DEFINED, + SLYLANDRO_DEFINED, + DRUUGE_DEFINED, + BOMB_DEFINED, + AQUA_HELIX_DEFINED, + SUN_DEVICE_DEFINED, + TAALO_PROTECTOR_DEFINED, + SHIP_VAULT_DEFINED, + URQUAN_WRECK_DEFINED, + VUX_BEAST_DEFINED, + SAMATRA_DEFINED, + ZOQ_SCOUT_DEFINED, + MYCON_DEFINED, + EGG_CASE0_DEFINED, + EGG_CASE1_DEFINED, + EGG_CASE2_DEFINED, + PKUNK_DEFINED, + UTWIG_DEFINED, + SUPOX_DEFINED, + YEHAT_DEFINED, + VUX_DEFINED, + ORZ_DEFINED, + THRADD_DEFINED, + RAINBOW_DEFINED, + ILWRATH_DEFINED, + ANDROSYNTH_DEFINED, + MYCON_TRAP_DEFINED +}; + +#define UMGAH_DEFINED TALKING_PET_DEFINED + #if defined(__cplusplus) } #endif Modified: trunk/sc2/src/uqm/globdata.c =================================================================== --- trunk/sc2/src/uqm/globdata.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/globdata.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -20,6 +20,7 @@ #include "coderes.h" #include "encount.h" +#include "starmap.h" #include "master.h" #include "setup.h" #include "units.h" Modified: trunk/sc2/src/uqm/grpinfo.c =================================================================== --- trunk/sc2/src/uqm/grpinfo.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/grpinfo.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -17,8 +17,8 @@ */ #include "build.h" -// XXX: for CurStarDescPtr and XXX_DEFINED constants -#include "encount.h" +#include "starmap.h" +#include "gendef.h" #include "libs/file.h" #include "globdata.h" #include "intel.h" Modified: trunk/sc2/src/uqm/hyper.c =================================================================== --- trunk/sc2/src/uqm/hyper.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/hyper.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -26,6 +26,7 @@ #include "menustat.h" // for DrawMenuStateStrings() #include "encount.h" +#include "starmap.h" #include "ship.h" #include "shipcont.h" #include "process.h" Modified: trunk/sc2/src/uqm/load.c =================================================================== --- trunk/sc2/src/uqm/load.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/load.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -23,6 +23,7 @@ #include "build.h" #include "libs/declib.h" #include "encount.h" +#include "starmap.h" #include "libs/file.h" #include "globdata.h" #include "load.h" Modified: trunk/sc2/src/uqm/plandata.c =================================================================== --- trunk/sc2/src/uqm/plandata.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/plandata.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -16,8 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// XXX: for XXX_DEFINED constants -#include "encount.h" +#include "gendef.h" #include "resinst.h" #include "planets/planets.h" #include "planets/elemdata.h" Modified: trunk/sc2/src/uqm/planets/calc.c =================================================================== --- trunk/sc2/src/uqm/planets/calc.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/calc.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -17,7 +17,8 @@ */ /* ----------------------------- INCLUDES ---------------------------- */ -#include "../encount.h" +#include "planets.h" +#include "uqm/starmap.h" #include "libs/mathlib.h" #include "libs/log.h" /* -------------------------------- DATA -------------------------------- */ @@ -26,9 +27,6 @@ //#define DEBUG_PLANET_CALC -#define CalcMass(b) CalcFromBase (b, b) -#define CalcRadius(b) CalcFromBase (b, ((b) >> 1) + 1) - #define LOW_TEMP 0 #define MED_TEMP 500 #define HIGH_TEMP 1500 @@ -36,15 +34,6 @@ #define MED_TEMP_BONUS 25 #define HIGH_TEMP_BONUS 50 #define MAX_TECTONICS 255 -#ifdef OLD -#define CalcTectonics(b,t) (CalcFromBase(b, 3 << 5) \ - + (UWORD)((t) < LOW_TEMP ? 0 : \ - ((t) < MED_TEMP ? LOW_TEMP_BONUS : \ - ((t) < HIGH_TEMP ? MED_TEMP_BONUS : \ - HIGH_TEMP_BONUS)))) -#else /* OLD */ -#define CalcTectonics(b,t) CalcFromBase(b, 3 << 5) -#endif /* OLD */ enum { @@ -56,6 +45,18 @@ WHITE_SUN_INTENSITY }; +static UWORD +CalcFromBase (UWORD base, UWORD variance) +{ + return base + LOWORD (RandomContext_Random (SysGenRNG)) % variance; +} + +static inline UWORD +CalcHalfBaseVariance (UWORD base) +{ + return CalcFromBase (base, (base >> 1) + 1); +} + static void CalcSysInfo (SYSTEM_INFO *SysInfoPtr) { @@ -149,7 +150,7 @@ PlanetInfoPtr->Weather += 1 << 5; else if (radius > 10) PlanetInfoPtr->Weather -= 1 << 5; - atmo = CalcFromBase (atmo, (atmo >> 1) + 1); + atmo = CalcHalfBaseVariance (atmo); } } @@ -194,7 +195,7 @@ bonus = COLD_BONUS; bonus <<= HINIBBLE (SysInfoPtr->PlanetInfo.PlanDataPtr->AtmoAndDensity); - bonus = CalcFromBase (bonus, (bonus >> 1) + 1); + bonus = CalcHalfBaseVariance (bonus); } return (centigrade + bonus); @@ -204,11 +205,11 @@ CalcRotation (PLANET_INFO *PlanetInfoPtr) { if (PLANSIZE (PlanetInfoPtr->PlanDataPtr->Type) == GAS_GIANT) - return ((COUNT)CalcFromBase (80, 80)); - else if (((BYTE)TFB_Random () % 10) == 0) - return ((COUNT)CalcFromBase ((UWORD)50 * 240, (UWORD)200 * 240)); + return CalcFromBase (80, 80); + else if (LOBYTE (RandomContext_Random (SysGenRNG)) % 10 == 0) + return CalcFromBase (50 * 240, 200 * 240); else - return ((COUNT)CalcFromBase (150, 150)); + return CalcFromBase (150, 150); } static SIZE @@ -223,23 +224,138 @@ i = NUM_TOSSES; do /* Using added Randomom values to give bell curve */ { - tilt += (UWORD)TFB_Random () % ((TILT_RANGE / NUM_TOSSES) + 1); + tilt += LOWORD (RandomContext_Random (SysGenRNG)) + % ((TILT_RANGE / NUM_TOSSES) + 1); } while (--i); return (tilt); } -// NB. Returns the RNG to the state it found it in. -DWORD +UWORD +CalcGravity (const PLANET_INFO *PlanetInfoPtr) +{ + return (DWORD)PlanetInfoPtr->PlanetDensity * PlanetInfoPtr->PlanetRadius + / 100; +} + +static UWORD +CalcTectonics (UWORD base, UWORD temp) +{ + UWORD tect = CalcFromBase (base, 3 << 5); +#ifdef OLD + if (temp >= HIGH_TEMP) + tect += HIGH_TEMP_BONUS; + else if (temp >= MED_TEMP) + tect += MED_TEMP_BONUS; + else if (temp >= LOW_TEMP) + tect += LOW_TEMP_BONUS; +#else /* !OLD */ + (void) temp; /* silence compiler whining */ +#endif /* OLD */ + return tect; +} + +// This code moved from planets/surface.c:CalcLifeForms() +static int +CalcLifeChance (const PLANET_INFO *PlanetInfoPtr) +{ + SIZE life_var = 0; + + if (PLANSIZE (PlanetInfoPtr->PlanDataPtr->Type) == GAS_GIANT) + return -1; + + if (PlanetInfoPtr->SurfaceTemperature < -151) + life_var -= 300; + else if (PlanetInfoPtr->SurfaceTemperature < -51) + life_var -= 100; + else if (PlanetInfoPtr->SurfaceTemperature < 0) + life_var += 100; + else if (PlanetInfoPtr->SurfaceTemperature < 50) + life_var += 300; + else if (PlanetInfoPtr->SurfaceTemperature < 150) + life_var += 50; + else if (PlanetInfoPtr->SurfaceTemperature < 250) + life_var -= 100; + else if (PlanetInfoPtr->SurfaceTemperature < 500) + life_var -= 400; + else + life_var -= 800; + + if (PlanetInfoPtr->AtmoDensity == 0) + life_var -= 1000; + else if (PlanetInfoPtr->AtmoDensity < 15) + life_var += 100; + else if (PlanetInfoPtr->AtmoDensity < 30) + life_var += 200; + else if (PlanetInfoPtr->AtmoDensity < 100) + life_var += 300; + else if (PlanetInfoPtr->AtmoDensity < 1000) + life_var += 150; + else if (PlanetInfoPtr->AtmoDensity < 2500) + ; + else + life_var -= 100; + +#ifndef NOTYET + life_var += 200 + 80 + 80; +#else /* NOTYET */ + if (PlanetInfoPtr->SurfaceGravity < 10) + ; + else if (PlanetInfoPtr->SurfaceGravity < 35) + life_var += 50; + else if (PlanetInfoPtr->SurfaceGravity < 75) + life_var += 100; + else if (PlanetInfoPtr->SurfaceGravity < 150) + life_var += 200; + else if (PlanetInfoPtr->SurfaceGravity < 400) + life_var += 50; + else if (PlanetInfoPtr->SurfaceGravity < 800) + ; + else + life_var -= 100; + + if (PlanetInfoPtr->Tectonics < 1) + life_var += 80; + else if (PlanetInfoPtr->Tectonics < 2) + life_var += 70; + else if (PlanetInfoPtr->Tectonics < 3) + life_var += 60; + else if (PlanetInfoPtr->Tectonics < 4) + life_var += 50; + else if (PlanetInfoPtr->Tectonics < 5) + life_var += 25; + else if (PlanetInfoPtr->Tectonics < 6) + ; + else + life_var -= 100; + + if (PlanetInfoPtr->Weather < 1) + life_var += 80; + else if (PlanetInfoPtr->Weather < 2) + life_var += 70; + else if (PlanetInfoPtr->Weather < 3) + life_var += 60; + else if (PlanetInfoPtr->Weather < 4) + life_var += 50; + else if (PlanetInfoPtr->Weather < 5) + life_var += 25; + else if (PlanetInfoPtr->Weather < 6) + ; + else + life_var -= 100; +#endif /* NOTYET */ + + return life_var; +} + +// Sets the SysGenRNG to the required state first. +void DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr, PLANET_DESC *pPlanetDesc) { - DWORD old_seed; + assert (pPlanetDesc->data_index != HIERARCHY_STARBASE); - if (pPlanetDesc->data_index == HIERARCHY_STARBASE) - return (0); + RandomContext_SeedRandom (SysGenRNG, pPlanetDesc->rand_seed); - old_seed = TFB_SeedRandom (pPlanetDesc->rand_seed); - CalcSysInfo (SysInfoPtr); #ifdef DEBUG_PLANET_CALC @@ -303,18 +419,18 @@ } SysInfoPtr->PlanetInfo.PlanetDensity += (SysInfoPtr->PlanetInfo.PlanetDensity / 20) - - ((COUNT)TFB_Random () + - (LOWORD (RandomContext_Random (SysGenRNG)) % (SysInfoPtr->PlanetInfo.PlanetDensity / 10)); switch (PLANSIZE (SysInfoPtr->PlanetInfo.PlanDataPtr->Type)) { case SMALL_ROCKY_WORLD: #define SMALL_RADIUS 25 - SysInfoPtr->PlanetInfo.PlanetRadius = CalcRadius (SMALL_RADIUS); + SysInfoPtr->PlanetInfo.PlanetRadius = CalcHalfBaseVariance (SMALL_RADIUS); break; case LARGE_ROCKY_WORLD: #define LARGE_RADIUS 75 - SysInfoPtr->PlanetInfo.PlanetRadius = CalcRadius (LARGE_RADIUS); + SysInfoPtr->PlanetInfo.PlanetRadius = CalcHalfBaseVariance (LARGE_RADIUS); break; case GAS_GIANT: #define MIN_GAS_RADIUS 300 @@ -325,9 +441,7 @@ } SysInfoPtr->PlanetInfo.RotationPeriod = CalcRotation (&SysInfoPtr->PlanetInfo); - SysInfoPtr->PlanetInfo.SurfaceGravity = - CalcGravity (SysInfoPtr->PlanetInfo.PlanetDensity, - SysInfoPtr->PlanetInfo.PlanetRadius); + SysInfoPtr->PlanetInfo.SurfaceGravity = CalcGravity (&SysInfoPtr->PlanetInfo); SysInfoPtr->PlanetInfo.AxialTilt = CalcTilt (); if ((SysInfoPtr->PlanetInfo.Tectonics = CalcTectonics (SysInfoPtr->PlanetInfo.PlanDataPtr->BaseTectonics, @@ -341,6 +455,8 @@ SysInfoPtr->PlanetInfo.Tectonics >>= 5; SysInfoPtr->PlanetInfo.Weather >>= 5; + SysInfoPtr->PlanetInfo.LifeChance = CalcLifeChance (&SysInfoPtr->PlanetInfo); + #ifdef DEBUG_PLANET_CALC radius = (SIZE)((DWORD)UNSCALE_RADIUS (radius) * 100 / UNSCALE_RADIUS (EARTH_RADIUS)); log_add (log_Debug, "\tOrbital Distance : %d.%02d AU", radius / 100, radius % 100); @@ -404,7 +520,5 @@ } #endif /* DEBUG_PLANET_CALC */ } - - return (TFB_SeedRandom (old_seed)); } Modified: trunk/sc2/src/uqm/planets/devices.c =================================================================== --- trunk/sc2/src/uqm/planets/devices.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/devices.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -18,6 +18,8 @@ #include "../build.h" #include "../colors.h" +#include "../gendef.h" +#include "../starmap.h" #include "../encount.h" #include "../gamestr.h" #include "../controls.h" Modified: trunk/sc2/src/uqm/planets/generate/genburv.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genburv.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/genburv.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -85,7 +85,7 @@ solarSys->MoonDesc[0].data_index = SELENIC_WORLD; solarSys->MoonDesc[0].radius = MIN_MOON_RADIUS + (MAX_MOONS - 1) * MOON_DELTA; - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); angle = NORMALIZE_ANGLE (LOWORD (rand_val)); solarSys->MoonDesc[0].location.x = COSINE (angle, solarSys->MoonDesc[0].radius); @@ -98,18 +98,17 @@ static bool GenerateBurvixese_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world) { - COUNT i; DWORD rand_val; - rand_val = DoPlanetaryAnalysis (&solarSys->SysInfo, world); + DoPlanetaryAnalysis (&solarSys->SysInfo, world); + rand_val = RandomContext_GetSeed (SysGenRNG); solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN] = rand_val; - i = (COUNT)~0; - rand_val = GenerateLifeForms (&solarSys->SysInfo, &i); + GenerateLifeForms (&solarSys->SysInfo, GENERATE_ALL); + rand_val = RandomContext_GetSeed (SysGenRNG); solarSys->SysInfo.PlanetInfo.ScanSeed[MINERAL_SCAN] = rand_val; - i = (COUNT)~0; - GenerateMineralDeposits (&solarSys->SysInfo, &i); + GenerateMineralDeposits (&solarSys->SysInfo, GENERATE_ALL); solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN] = rand_val; Modified: trunk/sc2/src/uqm/planets/generate/genchmmr.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genchmmr.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/genchmmr.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -77,7 +77,7 @@ solarSys->MoonDesc[0].data_index = HIERARCHY_STARBASE; solarSys->MoonDesc[0].radius = MIN_MOON_RADIUS; - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); angle = NORMALIZE_ANGLE (LOWORD (rand_val)); solarSys->MoonDesc[0].location.x = COSINE (angle, solarSys->MoonDesc[0].radius); Modified: trunk/sc2/src/uqm/planets/generate/gendefault.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/gendefault.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/gendefault.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -126,7 +126,6 @@ bool GenerateDefault_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world) { - COUNT i; DWORD rand_val; SYSTEM_INFO *sysInfo; @@ -146,15 +145,15 @@ sysInfo = &solarSys->SysInfo; - rand_val = DoPlanetaryAnalysis (sysInfo, world); + DoPlanetaryAnalysis (sysInfo, world); + rand_val = RandomContext_GetSeed (SysGenRNG); sysInfo->PlanetInfo.ScanSeed[BIOLOGICAL_SCAN] = rand_val; - i = (COUNT)~0; - rand_val = GenerateLifeForms (sysInfo, &i); + GenerateLifeForms (sysInfo, GENERATE_ALL); + rand_val = RandomContext_GetSeed (SysGenRNG); sysInfo->PlanetInfo.ScanSeed[MINERAL_SCAN] = rand_val; - i = (COUNT)~0; - GenerateMineralDeposits (sysInfo, &i); + GenerateMineralDeposits (sysInfo, GENERATE_ALL); sysInfo->PlanetInfo.ScanSeed[ENERGY_SCAN] = rand_val; LoadPlanet (NULL); @@ -166,9 +165,8 @@ GenerateDefault_generateMinerals (SOLARSYS_STATE *solarSys, PLANET_DESC *world, COUNT whichNode) { - GenerateMineralDeposits (&solarSys->SysInfo, &whichNode); + return GenerateMineralDeposits (&solarSys->SysInfo, whichNode); (void) world; - return whichNode; } bool @@ -209,9 +207,8 @@ GenerateDefault_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world, COUNT whichNode) { - GenerateLifeForms (&solarSys->SysInfo, &whichNode); + return GenerateLifeForms (&solarSys->SysInfo, whichNode); (void) world; - return whichNode; } bool @@ -229,17 +226,15 @@ GenerateDefault_generateArtifact (SOLARSYS_STATE *solarSys, COUNT whichNode) { // Generate an energy node at a random location - GenerateRandomNodes (&solarSys->SysInfo, ENERGY_SCAN, 1, 0, &whichNode); - return whichNode; + return GenerateRandomNodes (&solarSys->SysInfo, ENERGY_SCAN, 1, 0, whichNode); } COUNT GenerateDefault_generateRuins (SOLARSYS_STATE *solarSys, COUNT whichNode) { // Generate a standard spread of city ruins of a destroyed civilization - GenerateRandomNodes (&solarSys->SysInfo, ENERGY_SCAN, NUM_RACE_RUINS, - 0, &whichNode); - return whichNode; + return GenerateRandomNodes (&solarSys->SysInfo, ENERGY_SCAN, NUM_RACE_RUINS, + 0, whichNode); } static inline void @@ -309,7 +304,7 @@ BYTE num_moons; BYTE type; - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); byte_val = LOBYTE (rand_val); num_moons = 0; Modified: trunk/sc2/src/uqm/planets/generate/genmel.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genmel.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/genmel.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -18,7 +18,8 @@ #include "genall.h" #include "../../build.h" -#include "../../encount.h" +#include "../../gendef.h" +#include "../../starmap.h" #include "../../globdata.h" #include "../../state.h" #include "libs/log.h" Modified: trunk/sc2/src/uqm/planets/generate/genmyc.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genmyc.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/genmyc.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -22,7 +22,8 @@ #include "../scan.h" #include "../../build.h" #include "../../comm.h" -#include "../../encount.h" +#include "../../gendef.h" +#include "../../starmap.h" #include "../../globdata.h" #include "../../ipdisp.h" #include "../../nameref.h" Modified: trunk/sc2/src/uqm/planets/generate/genorz.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genorz.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/genorz.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -21,7 +21,8 @@ #include "../planets.h" #include "../../build.h" #include "../../comm.h" -#include "../../encount.h" +#include "../../gendef.h" +#include "../../starmap.h" #include "../../globdata.h" #include "../../ipdisp.h" #include "../../nameref.h" Modified: trunk/sc2/src/uqm/planets/generate/genpet.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genpet.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/genpet.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -21,6 +21,7 @@ #include "../../build.h" #include "../../comm.h" #include "../../encount.h" +#include "../../starmap.h" #include "../../globdata.h" #include "../../ipdisp.h" #include "../../nameref.h" Modified: trunk/sc2/src/uqm/planets/generate/genrain.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genrain.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/genrain.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -18,7 +18,8 @@ #include "genall.h" #include "../planets.h" -#include "../../encount.h" +#include "../../gendef.h" +#include "../../starmap.h" #include "../../globdata.h" #include "libs/mathlib.h" Modified: trunk/sc2/src/uqm/planets/generate/gensam.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/gensam.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/gensam.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -150,7 +150,7 @@ solarSys->MoonDesc[0].data_index = SA_MATRA; solarSys->MoonDesc[0].radius = MIN_MOON_RADIUS + (2 * MOON_DELTA); - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); angle = NORMALIZE_ANGLE (LOWORD (rand_val)); solarSys->MoonDesc[0].location.x = COSINE (angle, solarSys->MoonDesc[0].radius); Modified: trunk/sc2/src/uqm/planets/generate/gensol.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/gensol.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/gensol.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -108,7 +108,7 @@ COUNT planetI; #define SOL_SEED 334241042L - TFB_SeedRandom (SOL_SEED); + RandomContext_SeedRandom (SysGenRNG, SOL_SEED); solarSys->SunDesc[0].NumPlanets = 9; for (planetI = 0; planetI < 9; ++planetI) @@ -118,7 +118,8 @@ UWORD word_val; PLANET_DESC *pCurDesc = &solarSys->PlanetDesc[planetI]; - pCurDesc->rand_seed = rand_val = TFB_Random (); + pCurDesc->rand_seed = RandomContext_Random (SysGenRNG); + rand_val = pCurDesc->rand_seed; word_val = LOWORD (rand_val); angle = NORMALIZE_ANGLE ((COUNT)HIBYTE (word_val)); @@ -208,7 +209,7 @@ solarSys->MoonDesc[1].data_index = SELENIC_WORLD; solarSys->MoonDesc[1].radius = MIN_MOON_RADIUS + (MAX_MOONS - 1) * MOON_DELTA; - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); angle = NORMALIZE_ANGLE (LOWORD (rand_val)); solarSys->MoonDesc[1].location.x = COSINE (angle, solarSys->MoonDesc[1].radius); @@ -269,15 +270,12 @@ return true; } - rand_val = DoPlanetaryAnalysis (&solarSys->SysInfo, world); - if (rand_val) - { - COUNT i; + DoPlanetaryAnalysis (&solarSys->SysInfo, world); + rand_val = RandomContext_GetSeed (SysGenRNG); - solarSys->SysInfo.PlanetInfo.ScanSeed[MINERAL_SCAN] = rand_val; - i = (COUNT)~0; - rand_val = GenerateMineralDeposits (&solarSys->SysInfo, &i); - } + solarSys->SysInfo.PlanetInfo.ScanSeed[MINERAL_SCAN] = rand_val; + GenerateMineralDeposits (&solarSys->SysInfo, GENERATE_ALL); + rand_val = RandomContext_GetSeed (SysGenRNG); planetNr = planetIndex (solarSys, world); if (worldIsPlanet (solarSys, world)) @@ -405,8 +403,7 @@ } solarSys->SysInfo.PlanetInfo.SurfaceGravity = - CalcGravity (solarSys->SysInfo.PlanetInfo.PlanetDensity, - solarSys->SysInfo.PlanetInfo.PlanetRadius); + CalcGravity (&solarSys->SysInfo.PlanetInfo); LoadPlanet (planetNr == 2 ? CaptureDrawable (LoadGraphic (EARTH_MASK_ANIM)) : NULL); } @@ -421,6 +418,10 @@ switch (planetNr) { case 2: /* moons of EARTH */ + // NOTE: Even though we save the seed here, it is irrelevant. + // The seed will be used to randomly place the tractors, but + // since they are mobile, they will be moved to different + // locations not governed by this seed. solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN] = rand_val; @@ -505,8 +506,7 @@ } solarSys->SysInfo.PlanetInfo.SurfaceGravity = - CalcGravity (solarSys->SysInfo.PlanetInfo.PlanetDensity, - solarSys->SysInfo.PlanetInfo.PlanetRadius); + CalcGravity (&solarSys->SysInfo.PlanetInfo); LoadPlanet (NULL); } @@ -601,9 +601,8 @@ if (matchWorld (solarSys, world, 2, 1)) { /* Earth Moon */ - GenerateRandomNodes (&solarSys->SysInfo, BIOLOGICAL_SCAN, 10, - NUM_CREATURE_TYPES + 1, &whichNode); - return whichNode; + return GenerateRandomNodes (&solarSys->SysInfo, BIOLOGICAL_SCAN, 10, + NUM_CREATURE_TYPES + 1, whichNode); } return 0; Modified: trunk/sc2/src/uqm/planets/generate/genspa.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genspa.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/genspa.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -102,7 +102,7 @@ solarSys->MoonDesc[0].data_index = PELLUCID_WORLD; solarSys->MoonDesc[0].radius = MIN_MOON_RADIUS + MOON_DELTA; - angle = NORMALIZE_ANGLE (LOWORD (TFB_Random ())); + angle = NORMALIZE_ANGLE (LOWORD (RandomContext_Random (SysGenRNG))); solarSys->MoonDesc[0].location.x = COSINE (angle, solarSys->MoonDesc[0].radius); solarSys->MoonDesc[0].location.y = @@ -116,7 +116,6 @@ GenerateSpathi_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world) { DWORD rand_val; - COUNT i; if (matchWorld (solarSys, world, 0, 0)) { @@ -144,15 +143,16 @@ } return true; } - rand_val = DoPlanetaryAnalysis (&solarSys->SysInfo, world); + + DoPlanetaryAnalysis (&solarSys->SysInfo, world); + rand_val = RandomContext_GetSeed (SysGenRNG); solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN] = rand_val; - i = (COUNT)~0; - rand_val = GenerateLifeForms (&solarSys->SysInfo, &i); + GenerateLifeForms (&solarSys->SysInfo, GENERATE_ALL); + rand_val = RandomContext_GetSeed (SysGenRNG); solarSys->SysInfo.PlanetInfo.ScanSeed[MINERAL_SCAN] = rand_val; - i = (COUNT)~0; - GenerateMineralDeposits (&solarSys->SysInfo, &i); + GenerateMineralDeposits (&solarSys->SysInfo, GENERATE_ALL); solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN] = rand_val; @@ -181,18 +181,18 @@ else if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { /* visiting Spathiwa */ - rand_val = DoPlanetaryAnalysis (&solarSys->SysInfo, world); + DoPlanetaryAnalysis (&solarSys->SysInfo, world); + rand_val = RandomContext_GetSeed (SysGenRNG); solarSys->SysInfo.PlanetInfo.ScanSeed[MINERAL_SCAN] = rand_val; - i = (COUNT)~0; - rand_val = GenerateMineralDeposits (&solarSys->SysInfo, &i); + GenerateMineralDeposits (&solarSys->SysInfo, GENERATE_ALL); + rand_val = RandomContext_GetSeed (SysGenRNG); solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN] = rand_val; solarSys->SysInfo.PlanetInfo.PlanetRadius = 120; solarSys->SysInfo.PlanetInfo.SurfaceGravity = - CalcGravity (solarSys->SysInfo.PlanetInfo.PlanetDensity, - solarSys->SysInfo.PlanetInfo.PlanetRadius); + CalcGravity (&solarSys->SysInfo.PlanetInfo); solarSys->SysInfo.PlanetInfo.Weather = 0; solarSys->SysInfo.PlanetInfo.Tectonics = 0; solarSys->SysInfo.PlanetInfo.SurfaceTemperature = 31; @@ -253,9 +253,8 @@ if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { #define NUM_EVIL_ONES 32 - GenerateRandomNodes (&solarSys->SysInfo, BIOLOGICAL_SCAN, NUM_EVIL_ONES, - NUM_CREATURE_TYPES, &whichNode); - return whichNode; + return GenerateRandomNodes (&solarSys->SysInfo, BIOLOGICAL_SCAN, NUM_EVIL_ONES, + NUM_CREATURE_TYPES, whichNode); } return 0; Modified: trunk/sc2/src/uqm/planets/generate/genthrad.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genthrad.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/genthrad.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -21,7 +21,8 @@ #include "../planets.h" #include "../../build.h" #include "../../comm.h" -#include "../../encount.h" +#include "../../gendef.h" +#include "../../starmap.h" #include "../../globdata.h" #include "../../ipdisp.h" #include "../../nameref.h" Modified: trunk/sc2/src/uqm/planets/generate/genutw.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genutw.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/genutw.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -21,7 +21,8 @@ #include "../planets.h" #include "../../build.h" #include "../../comm.h" -#include "../../encount.h" +#include "../../gendef.h" +#include "../../starmap.h" #include "../../globdata.h" #include "../../ipdisp.h" #include "../../nameref.h" Modified: trunk/sc2/src/uqm/planets/generate/genvux.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genvux.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/generate/genvux.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -22,7 +22,8 @@ #include "../planets.h" #include "../../build.h" #include "../../comm.h" -#include "../../encount.h" +#include "../../gendef.h" +#include "../../starmap.h" #include "../../globdata.h" #include "../../ipdisp.h" #include "../../nameref.h" @@ -276,9 +277,8 @@ && matchWorld (solarSys, world, 0, MATCH_PLANET)) { COUNT i; - DWORD old_rand; - old_rand = TFB_SeedRandom ( + RandomContext_SeedRandom (SysGenRNG, solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN]); for (i = 0; i <= whichNode && i < 12; ++i) @@ -292,8 +292,6 @@ solarSys->SysInfo.PlanetInfo.CurType = 18; } - TFB_SeedRandom (old_rand); - return 12; // only matters when count is requested } @@ -301,9 +299,8 @@ && matchWorld (solarSys, world, 0, MATCH_PLANET)) { COUNT i; - DWORD old_rand; - old_rand = TFB_SeedRandom ( + RandomContext_SeedRandom (SysGenRNG, solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN]); for (i = 0; i <= whichNode && i < 11; ++i) @@ -319,8 +316,6 @@ solarSys->SysInfo.PlanetInfo.CurType = 8; } - TFB_SeedRandom (old_rand); - return 11; // only matters when count is requested } Modified: trunk/sc2/src/uqm/planets/gentopo.c =================================================================== --- trunk/sc2/src/uqm/planets/gentopo.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/gentopo.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -43,9 +43,10 @@ DWORD rand_val; SBYTE *lpDst; - depth_delta = ((((SIZE)TFB_Random () & 1) << 1) - 1) * depth_delta; + if ((RandomContext_Random (SysGenRNG) & 1) == 0) + depth_delta = -depth_delta; - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); w1 = LOWORD (rand_val); w2 = HIWORD (rand_val); Modified: trunk/sc2/src/uqm/planets/lander.c =================================================================== --- trunk/sc2/src/uqm/planets/lander.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/lander.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -23,8 +23,6 @@ #include "../cons_res.h" #include "../controls.h" #include "../colors.h" -// XXX: for CurStarDescPtr and XXX_DEFINED -#include "../encount.h" #include "../process.h" #include "../units.h" #include "../gamestr.h" Modified: trunk/sc2/src/uqm/planets/orbits.c =================================================================== --- trunk/sc2/src/uqm/planets/orbits.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/orbits.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -17,8 +17,7 @@ */ #include "planets.h" -// XXX: for CurStarDescPtr -#include "../encount.h" +#include "../starmap.h" #include "libs/compiler.h" #include "libs/mathlib.h" #include "libs/log.h" @@ -499,10 +498,15 @@ if (NumPlanets == (BYTE)~0) { -#define MAX_GENERATED_PLANETS 10 - while ((NumPlanets = (BYTE)(LOWORD (TFB_Random()) - % MAX_GENERATED_PLANETS)) == 0) - ; +#define MAX_GENERATED_PLANETS 9 + // XXX: This is pretty funny. Instead of calling RNG once, like so: + // 1 + Random % MAX_GENERATED_PLANETS + // we spin in a loop until the result > 0. + // Note that this behavior must be kept to preserve the universe. + do + NumPlanets = LOWORD (RandomContext_Random (SysGenRNG)) + % (MAX_GENERATED_PLANETS + 1); + while (NumPlanets == 0); system->SunDesc[0].NumPlanets = NumPlanets; } @@ -528,7 +532,7 @@ do { - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); if (TypesDefined) rand_val = 0; else @@ -564,7 +568,7 @@ else min_radius = Suns[StarSize].MinGasGDist; RelocatePlanet: - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); if (GeneratingMoons) { pPD->radius = MIN_MOON_RADIUS @@ -592,7 +596,7 @@ } } - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); angle = NORMALIZE_ANGLE (LOWORD (rand_val)); pPD->location.x = COSINE (angle, pPD->radius); pPD->location.y = SINE (angle, pPD->radius); Modified: trunk/sc2/src/uqm/planets/plandata.h =================================================================== --- trunk/sc2/src/uqm/planets/plandata.h 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/plandata.h 2011-09-09 01:59:12 UTC (rev 3694) @@ -313,8 +313,7 @@ SUPER_DENSITY }; -#define CalcGravity(d,r) (UWORD)((DWORD)(d) * (r) / 100) -#define CalcFromBase(b,v) ((UWORD)(b) + ((UWORD)TFB_Random () % (v))) +extern UWORD CalcGravity (const PLANET_INFO*); #define EARTH_ATMOSPHERE 50 Modified: trunk/sc2/src/uqm/planets/planets.h =================================================================== --- trunk/sc2/src/uqm/planets/planets.h 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/planets.h 2011-09-09 01:59:12 UTC (rev 3694) @@ -19,6 +19,8 @@ #ifndef _PLANETS_H #define _PLANETS_H +#include "libs/mathlib.h" + #define END_INTERPLANETARY START_INTERPLANETARY enum PlanetScanTypes @@ -233,6 +235,9 @@ extern MUSIC_REF SpaceMusic; extern CONTEXT PlanetContext; +// Random context used for all solar system, planets and surfaces generation +extern RandomContext *SysGenRNG; + bool playerInSolarSystem (void); bool playerInPlanetOrbit (void); bool playerInInnerSystem (void); @@ -244,6 +249,8 @@ bool matchWorld (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world, BYTE planetI, BYTE moonI); +DWORD GetRandomSeedForStar (const STAR_DESC *star); + POINT locationToDisplay (POINT pt, SIZE scaleRadius); POINT displayToLocation (POINT pt, SIZE scaleRadius); POINT planetOuterLocation (COUNT planetI); Modified: trunk/sc2/src/uqm/planets/plangen.c =================================================================== --- trunk/sc2/src/uqm/planets/plangen.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/plangen.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -842,7 +842,7 @@ { // Use up the random value byte by byte if ((i & 3) == 0) - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); else rand_val >>= 8; @@ -1066,7 +1066,7 @@ intersect = FALSE; - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); loword = LOWORD (rand_val); hiword = HIWORD (rand_val); switch (HIBYTE (hiword) & 31) @@ -1094,7 +1094,7 @@ if (pstorm_r->extent.height <= 4) pstorm_r->extent.height += 4; - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); loword = LOWORD (rand_val); hiword = HIWORD (rand_val); @@ -1183,7 +1183,7 @@ band_error = num_bands >> 1; lpDst = DepthArray; - band_delta = ((LOWORD (TFB_Random ()) + band_delta = ((LOWORD (RandomContext_Random (SysGenRNG)) & (NUM_BAND_COLORS - 1)) << RANGE_SHIFT) + (1 << (RANGE_SHIFT - 1)); last_y = next_y = 0; @@ -1191,7 +1191,7 @@ { COORD cur_y; - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); loword = LOWORD (rand_val); hiword = HIWORD (rand_val); @@ -1232,7 +1232,7 @@ & (((1 << RANGE_SHIFT) * NUM_BAND_COLORS) - 1); } - MakeStorms (4 + (TFB_Random () & 3) + 1, DepthArray); + MakeStorms (4 + (RandomContext_Random (SysGenRNG) & 3) + 1, DepthArray); DitherMap (DepthArray); } @@ -1718,11 +1718,11 @@ } } +// Sets the SysGenRNG to the required state first. void GeneratePlanetSurface (PLANET_DESC *pPlanetDesc, FRAME SurfDefFrame) { RECT r; - DWORD old_seed; const PlanetFrame *PlanDataPtr; PLANET_INFO *PlanetInfo = &pSolarSysState->SysInfo.PlanetInfo; COUNT i, y; @@ -1732,7 +1732,7 @@ PLANET_ORBIT *Orbit = &pSolarSysState->Orbit; BOOLEAN shielded = (pPlanetDesc->data_index & PLANET_SHIELDED) != 0; - old_seed = TFB_SeedRandom (pPlanetDesc->rand_seed); + RandomContext_SeedRandom (SysGenRNG, pPlanetDesc->rand_seed); TopoContext = CreateContext ("Plangen.TopoContext"); LockMutex (GraphicsLock); @@ -1818,7 +1818,7 @@ RECT crater_r; UWORD loword; - loword = LOWORD (TFB_Random ()); + loword = LOWORD (RandomContext_Random (SysGenRNG)); switch (HIBYTE (loword) & 31) { case 0: @@ -1841,7 +1841,7 @@ break; } - loword = LOWORD (TFB_Random ()); + loword = LOWORD (RandomContext_Random (SysGenRNG)); crater_r.extent.height = crater_r.extent.width; crater_r.corner.x = HIBYTE (loword) % (MAP_WIDTH - crater_r.extent.width); @@ -1952,7 +1952,5 @@ SetContext (OldContext); UnlockMutex (GraphicsLock); DestroyContext (TopoContext); - - TFB_SeedRandom (old_seed); } Modified: trunk/sc2/src/uqm/planets/pstarmap.c =================================================================== --- trunk/sc2/src/uqm/planets/pstarmap.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/pstarmap.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -20,8 +20,7 @@ #include "../colors.h" #include "../controls.h" #include "../menustat.h" -// XXX: for stuff that does not belong there -#include "../encount.h" +#include "../starmap.h" #include "../races.h" #include "../gameopt.h" #include "../gamestr.h" Modified: trunk/sc2/src/uqm/planets/scan.c =================================================================== --- trunk/sc2/src/uqm/planets/scan.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/scan.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -1300,6 +1300,8 @@ creatureType = system->SysInfo.PlanetInfo.CurType; + // NOTE: TFB_Random() calls here are NOT part of the deterministic planet + // generation PRNG flow. if (CreatureData[creatureType].Attributes & SPEED_MASK) { // Place moving creatures at a random location. Modified: trunk/sc2/src/uqm/planets/solarsys.c =================================================================== --- trunk/sc2/src/uqm/planets/solarsys.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/solarsys.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -22,7 +22,7 @@ #include "../controls.h" #include "../menustat.h" // for DrawMenuStateStrings() -#include "../encount.h" +#include "../starmap.h" #include "../races.h" #include "../gamestr.h" #include "../gendef.h" @@ -95,6 +95,7 @@ static RECT scaleRect; // system zooms in when the flagship enters this rect +RandomContext *SysGenRNG; #define DISPLAY_TO_LOC (DISPLAY_FACTOR >> 1) @@ -211,15 +212,15 @@ return pSolarSysState->pBaseDesc != pSolarSysState->PlanetDesc; } +// Sets the SysGenRNG to the required state first. static void GenerateMoons (SOLARSYS_STATE *system, PLANET_DESC *planet) { COUNT i; COUNT facing; PLANET_DESC *pMoonDesc; - DWORD old_seed; - old_seed = TFB_SeedRandom (planet->rand_seed); + RandomContext_SeedRandom (SysGenRNG, planet->rand_seed); (*system->genFuncs->generateName) (system, planet); (*system->genFuncs->generateMoons) (system, planet); @@ -235,8 +236,6 @@ pMoonDesc->temp_color = planet->temp_color; } - - TFB_SeedRandom (old_seed); } void @@ -256,6 +255,9 @@ SpaceJunkFrame = 0; DestroyMusic (SpaceMusic); SpaceMusic = 0; + + RandomContext_Delete (SysGenRNG); + SysGenRNG = NULL; } void @@ -275,6 +277,11 @@ SpaceMusic = LoadMusic (IP_MUSIC); } + + if (!SysGenRNG) + { + SysGenRNG = RandomContext_New (); + } } @@ -350,11 +357,10 @@ } } -static DWORD -seedRandomForSolarSys (void) +DWORD +GetRandomSeedForStar (const STAR_DESC *star) { - return TFB_SeedRandom (MAKE_DWORD (CurStarDescPtr->star_pt.x, - CurStarDescPtr->star_pt.y)); + return MAKE_DWORD (star->star_pt.x, star->star_pt.y); } // Returns an orbital PLANET_DESC when player is in orbit @@ -364,7 +370,6 @@ COUNT i; PLANET_DESC *orbital = NULL; PLANET_DESC *pCurDesc; - DWORD old_seed; #define NUM_TEMP_RANGES 5 static const Color temp_color_array[NUM_TEMP_RANGES] = { @@ -375,13 +380,13 @@ BUILD_COLOR (MAKE_RGB15_INIT (0x0F, 0x08, 0x00), 0x75), }; - old_seed = seedRandomForSolarSys (); + RandomContext_SeedRandom (SysGenRNG, GetRandomSeedForStar (CurStarDescPtr)); SunFrame = SetAbsFrameIndex (SunFrame, STAR_TYPE (CurStarDescPtr->Type)); pCurDesc = &pSolarSysState->SunDesc[0]; pCurDesc->pPrevDesc = 0; - pCurDesc->rand_seed = TFB_Random (); + pCurDesc->rand_seed = RandomContext_Random (SysGenRNG); pCurDesc->data_index = STAR_TYPE (CurStarDescPtr->Type); pCurDesc->location.x = 0; @@ -467,9 +472,6 @@ GLOBAL (ShipStamp.frame) = SetAbsFrameIndex (SISIPFrame, i - 1); } - // Restore RNG state: - TFB_SeedRandom (old_seed); - return orbital; } @@ -1656,7 +1658,6 @@ COUNT i, j; DWORD rand_val; STAMP s; - DWORD old_seed; CONTEXT oldContext; RECT clipRect; FRAME frame; @@ -1675,7 +1676,7 @@ ClearDrawable (); - old_seed = seedRandomForSolarSys (); + RandomContext_SeedRandom (SysGenRNG, GetRandomSeedForStar (CurStarDescPtr)); #define NUM_DIM_PIECES 8 s.frame = SpaceJunkFrame; @@ -1684,7 +1685,7 @@ #define NUM_DIM_DRAWN 5 for (j = 0; j < NUM_DIM_DRAWN; ++j) { - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); s.origin.x = LOWORD (rand_val) % SIS_SCREEN_WIDTH; s.origin.y = HIWORD (rand_val) % SIS_SCREEN_HEIGHT; @@ -1698,7 +1699,7 @@ #define NUM_BRT_DRAWN 30 for (j = 0; j < NUM_BRT_DRAWN; ++j) { - rand_val = TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); s.origin.x = LOWORD (rand_val) % SIS_SCREEN_WIDTH; s.origin.y = HIWORD (rand_val) % SIS_SCREEN_HEIGHT; @@ -1707,8 +1708,6 @@ s.frame = IncFrameIndex (s.frame); } - TFB_SeedRandom (old_seed); - SetContext (oldContext); return frame; Modified: trunk/sc2/src/uqm/planets/sundata.h =================================================================== --- trunk/sc2/src/uqm/planets/sundata.h 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/sundata.h 2011-09-09 01:59:12 UTC (rev 3694) @@ -42,13 +42,15 @@ PLANET_INFO PlanetInfo; } SYSTEM_INFO; + +#define GENERATE_ALL ((COUNT)~0) -extern DWORD GenerateMineralDeposits (SYSTEM_INFO *SysInfoPtr, - COUNT *pwhich_deposit); -extern DWORD GenerateLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT *pwhich_life); +extern COUNT GenerateMineralDeposits (SYSTEM_INFO *SysInfoPtr, + COUNT whichDeposit); +extern COUNT GenerateLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT whichLife); extern void GenerateRandomLocation (SYSTEM_INFO *); -extern DWORD GenerateRandomNodes (SYSTEM_INFO *, COUNT scan, COUNT numNodes, - COUNT type, COUNT *whichNode); +extern COUNT GenerateRandomNodes (SYSTEM_INFO *, COUNT scan, COUNT numNodes, + COUNT type, COUNT whichNode); #define DWARF_ELEMENT_DENSITY 1 #define GIANT_ELEMENT_DENSITY 3 @@ -56,11 +58,9 @@ #define MAX_ELEMENT_DENSITY ((MAX_ELEMENT_UNITS * SUPERGIANT_ELEMENT_DENSITY) << 1) -extern DWORD DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr, +extern void DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr, PLANET_DESC *pPlanetDesc); -extern SYSTEM_INFO CurSysInfo; - #if defined(__cplusplus) } #endif Modified: trunk/sc2/src/uqm/planets/surface.c =================================================================== --- trunk/sc2/src/uqm/planets/surface.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/planets/surface.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -41,16 +41,16 @@ { BYTE num_possible; - num_possible = (BYTE)((BYTE)TFB_Random () - % (DEPOSIT_QUANTITY (eptr->Density) + 1)); + num_possible = LOBYTE (RandomContext_Random (SysGenRNG)) + % (DEPOSIT_QUANTITY (eptr->Density) + 1); while (num_possible--) { #define MEDIUM_DEPOSIT_THRESHOLD 150 #define LARGE_DEPOSIT_THRESHOLD 225 - COUNT deposit_quality_fine, - deposit_quality_gross; + COUNT deposit_quality_fine; + COUNT deposit_quality_gross; - deposit_quality_fine = ((COUNT)TFB_Random () % 100) + deposit_quality_fine = (LOWORD (RandomContext_Random (SysGenRNG)) % 100) + ( DEPOSIT_QUALITY (eptr->Density) + SysInfoPtr->StarSize @@ -85,14 +85,16 @@ return (num_deposits); } -DWORD -GenerateMineralDeposits (SYSTEM_INFO *SysInfoPtr, COUNT *pwhich_deposit) +// Returns: +// for whichLife==~0 : the number of nodes generated +// for whichLife<32 : the index of the last node (no known usage exists) +// Sets the SysGenRNG to the required state first. +COUNT +GenerateMineralDeposits (SYSTEM_INFO *SysInfoPtr, COUNT whichDeposit) { - DWORD old_rand; - - old_rand = TFB_SeedRandom (SysInfoPtr->PlanetInfo.ScanSeed[MINERAL_SCAN]); - *pwhich_deposit = CalcMineralDeposits (SysInfoPtr, *pwhich_deposit); - return (TFB_SeedRandom (old_rand)); + RandomContext_SeedRandom (SysGenRNG, + SysInfoPtr->PlanetInfo.ScanSeed[MINERAL_SCAN]); + return CalcMineralDeposits (SysInfoPtr, whichDeposit); } static COUNT @@ -101,114 +103,28 @@ COUNT num_life_forms; num_life_forms = 0; - if (PLANSIZE (SysInfoPtr->PlanetInfo.PlanDataPtr->Type) == GAS_GIANT) - SysInfoPtr->PlanetInfo.LifeChance = -1; - else + if (PLANSIZE (SysInfoPtr->PlanetInfo.PlanDataPtr->Type) != GAS_GIANT) { #define MIN_LIFE_CHANCE 10 SIZE life_var; - life_var = 0; - - if (SysInfoPtr->PlanetInfo.SurfaceTemperature < -151) - life_var -= 300; - else if (SysInfoPtr->PlanetInfo.SurfaceTemperature < -51) - life_var -= 100; - else if (SysInfoPtr->PlanetInfo.SurfaceTemperature < 0) - life_var += 100; - else if (SysInfoPtr->PlanetInfo.SurfaceTemperature < 50) - life_var += 300; - else if (SysInfoPtr->PlanetInfo.SurfaceTemperature < 150) - life_var += 50; - else if (SysInfoPtr->PlanetInfo.SurfaceTemperature < 250) - life_var -= 100; - else if (SysInfoPtr->PlanetInfo.SurfaceTemperature < 500) - life_var -= 400; - else - life_var -= 800; - - if (SysInfoPtr->PlanetInfo.AtmoDensity == 0) - life_var -= 1000; - else if (SysInfoPtr->PlanetInfo.AtmoDensity < 15) - life_var += 100; - else if (SysInfoPtr->PlanetInfo.AtmoDensity < 30) - life_var += 200; - else if (SysInfoPtr->PlanetInfo.AtmoDensity < 100) - life_var += 300; - else if (SysInfoPtr->PlanetInfo.AtmoDensity < 1000) - life_var += 150; - else if (SysInfoPtr->PlanetInfo.AtmoDensity < 2500) - ; - else - life_var -= 100; - -#ifndef NOTYET - life_var += 200 + 80 + 80; -#else /* NOTYET */ - if (SysInfoPtr->PlanetInfo.SurfaceGravity < 10) - ; - else if (SysInfoPtr->PlanetInfo.SurfaceGravity < 35) - life_var += 50; - else if (SysInfoPtr->PlanetInfo.SurfaceGravity < 75) - life_var += 100; - else if (SysInfoPtr->PlanetInfo.SurfaceGravity < 150) - life_var += 200; - else if (SysInfoPtr->PlanetInfo.SurfaceGravity < 400) - life_var += 50; - else if (SysInfoPtr->PlanetInfo.SurfaceGravity < 800) - ; - else - life_var -= 100; - - if (SysInfoPtr->PlanetInfo.Tectonics < 1) - life_var += 80; - else if (SysInfoPtr->PlanetInfo.Tectonics < 2) - life_var += 70; - else if (SysInfoPtr->PlanetInfo.Tectonics < 3) - life_var += 60; - else if (SysInfoPtr->PlanetInfo.Tectonics < 4) - life_var += 50; - else if (SysInfoPtr->PlanetInfo.Tectonics < 5) - life_var += 25; - else if (SysInfoPtr->PlanetInfo.Tectonics < 6) - ; - else - life_var -= 100; - - if (SysInfoPtr->PlanetInfo.Weather < 1) - life_var += 80; - else if (SysInfoPtr->PlanetInfo.Weather < 2) - life_var += 70; - else if (SysInfoPtr->PlanetInfo.Weather < 3) - life_var += 60; - else if (SysInfoPtr->PlanetInfo.Weather < 4) - life_var += 50; - else if (SysInfoPtr->PlanetInfo.Weather < 5) - life_var += 25; - else if (SysInfoPtr->PlanetInfo.Weather < 6) - ; - else - life_var -= 100; -#endif /* NOTYET */ - - SysInfoPtr->PlanetInfo.LifeChance = life_var; - - life_var = (COUNT)TFB_Random () & 1023; + life_var = RandomContext_Random (SysGenRNG) & 1023; if (life_var < SysInfoPtr->PlanetInfo.LifeChance || (SysInfoPtr->PlanetInfo.LifeChance < MIN_LIFE_CHANCE && life_var < MIN_LIFE_CHANCE)) { BYTE num_types; - num_types = (BYTE)(((BYTE)TFB_Random () % MAX_LIFE_VARIATION) + 1); + num_types = 1 + LOBYTE (RandomContext_Random (SysGenRNG)) + % MAX_LIFE_VARIATION; do { BYTE index, num_creatures; UWORD rand_val; - rand_val = (UWORD)TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); index = LOBYTE (rand_val) % NUM_CREATURE_TYPES; - num_creatures = (BYTE)((HIBYTE (rand_val) % 10) + 1); + num_creatures = 1 + HIBYTE (rand_val) % 10; do { GenerateRandomLocation (SysInfoPtr); @@ -233,15 +149,16 @@ return (num_life_forms); } -DWORD -GenerateLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT *pwhich_life) +// Returns: +// for whichLife==~0 : the number of lifeforms generated +// for whichLife<32 : the index of the last lifeform (no known usage exists) +// Sets the SysGenRNG to the required state first. +COUNT +GenerateLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT whichLife) { - DWORD old_rand; - - old_rand = TFB_SeedRandom ( + RandomContext_SeedRandom (SysGenRNG, SysInfoPtr->PlanetInfo.ScanSeed[BIOLOGICAL_SCAN]); - *pwhich_life = CalcLifeForms (SysInfoPtr, *pwhich_life); - return (TFB_SeedRandom (old_rand)); + return CalcLifeForms (SysInfoPtr, whichLife); } void @@ -249,21 +166,24 @@ { UWORD rand_val; - rand_val = (UWORD)TFB_Random (); + rand_val = RandomContext_Random (SysGenRNG); SysInfoPtr->PlanetInfo.CurPt.x = (LOBYTE (rand_val) % (MAP_WIDTH - (8 << 1))) + 8; SysInfoPtr->PlanetInfo.CurPt.y = (HIBYTE (rand_val) % (MAP_HEIGHT - (8 << 1))) + 8; } -DWORD +// Returns: +// for whichNode==~0 : the number of nodes generated +// for whichNode<32 : the index of the last node (no known usage exists) +// Sets the SysGenRNG to the required state first. +COUNT GenerateRandomNodes (SYSTEM_INFO *SysInfoPtr, COUNT scan, COUNT numNodes, - COUNT type, COUNT *whichNode) + COUNT type, COUNT whichNode) { - DWORD old_rand; COUNT i; - old_rand = TFB_SeedRandom (SysInfoPtr->PlanetInfo.ScanSeed[scan]); + RandomContext_SeedRandom (SysGenRNG, SysInfoPtr->PlanetInfo.ScanSeed[scan]); for (i = 0; i < numNodes; ++i) { @@ -273,11 +193,9 @@ // CurDensity is irrelevant for energy and bio nodes SysInfoPtr->PlanetInfo.CurDensity = 0; - if (i >= *whichNode) + if (i >= whichNode) break; } - *whichNode = i; // only matters when count is requested - - return (TFB_SeedRandom (old_rand)); + return i; } Modified: trunk/sc2/src/uqm/restart.c =================================================================== --- trunk/sc2/src/uqm/restart.c 2011-09-08 15:25:32 UTC (rev 3693) +++ trunk/sc2/src/uqm/restart.c 2011-09-09 01:59:12 UTC (rev 3694) @@ -21,8 +21,7 @@ #include "colors.h" #include "controls.h" #include "credits.h" -// XXX: for star_array[] -#include "encount.h" +#include "starmap.h" #include "fmv.h" #include "menustat.h" #include "gamestr.h" Modified: trunk/sc2/src/uqm/save.c ========================================================... [truncated message content] |
From: <Mee...@us...> - 2011-10-01 14:15:42
|
Revision: 3696 http://sc2.svn.sourceforge.net/sc2/?rev=3696&view=rev Author: Meep-Eep Date: 2011-10-01 14:15:35 +0000 (Sat, 01 Oct 2011) Log Message: ----------- Fixed unconst() types. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/libs/misc.h trunk/sc2/src/libs/uio/uioutils.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-09-09 21:36:34 UTC (rev 3695) +++ trunk/sc2/ChangeLog 2011-10-01 14:15:35 UTC (rev 3696) @@ -1,4 +1,5 @@ Changes towards version 0.8: +- Fixed unconst(), from Scott A. Colcord - Fixes to a few small bugs in UIO which shouldn't have had an impact on UQM, but would in the future, from Alex - Allow F6 as a default alternate search key, from related projects. Modified: trunk/sc2/src/libs/misc.h =================================================================== --- trunk/sc2/src/libs/misc.h 2011-09-09 21:36:34 UTC (rev 3695) +++ trunk/sc2/src/libs/misc.h 2011-10-01 14:15:35 UTC (rev 3696) @@ -51,8 +51,8 @@ static inline void * unconst(const void *arg) { union { - char *c; - const char *cc; + void *c; + const void *cc; } u; u.cc = arg; return u.c; Modified: trunk/sc2/src/libs/uio/uioutils.h =================================================================== --- trunk/sc2/src/libs/uio/uioutils.h 2011-09-09 21:36:34 UTC (rev 3695) +++ trunk/sc2/src/libs/uio/uioutils.h 2011-10-01 14:15:35 UTC (rev 3696) @@ -44,8 +44,8 @@ static inline void * unconst(const void *arg) { union { - char *c; - const char *cc; + void *c; + const void *cc; } u; u.cc = arg; return u.c; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-10-01 14:54:24
|
Revision: 3697 http://sc2.svn.sourceforge.net/sc2/?rev=3697&view=rev Author: Meep-Eep Date: 2011-10-01 14:54:18 +0000 (Sat, 01 Oct 2011) Log Message: ----------- Make use of GAME_STATE_FILE consistently. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/uqm/grpinfo.c trunk/sc2/src/uqm/state.c trunk/sc2/src/uqm/state.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-10-01 14:15:35 UTC (rev 3696) +++ trunk/sc2/ChangeLog 2011-10-01 14:54:18 UTC (rev 3697) @@ -1,4 +1,5 @@ Changes towards version 0.8: +- Make use of GAME_STATE_FILE consistently, from Scott A. Colcord - Fixed unconst(), from Scott A. Colcord - Fixes to a few small bugs in UIO which shouldn't have had an impact on UQM, but would in the future, from Alex Modified: trunk/sc2/src/uqm/grpinfo.c =================================================================== --- trunk/sc2/src/uqm/grpinfo.c 2011-10-01 14:15:35 UTC (rev 3696) +++ trunk/sc2/src/uqm/grpinfo.c 2011-10-01 14:54:18 UTC (rev 3697) @@ -71,7 +71,7 @@ } GROUP_HEADER; static void -ReadGroupHeader (void *fp, GROUP_HEADER *pGH) +ReadGroupHeader (GAME_STATE_FILE *fp, GROUP_HEADER *pGH) { sread_8 (fp, &pGH->NumGroups); sread_8 (fp, &pGH->day_index); @@ -83,7 +83,7 @@ } static void -WriteGroupHeader (void *fp, const GROUP_HEADER *pGH) +WriteGroupHeader (GAME_STATE_FILE *fp, const GROUP_HEADER *pGH) { swrite_8 (fp, pGH->NumGroups); swrite_8 (fp, pGH->day_index); @@ -95,7 +95,7 @@ } static void -ReadShipFragment (void *fp, SHIP_FRAGMENT *FragPtr) +ReadShipFragment (GAME_STATE_FILE *fp, SHIP_FRAGMENT *FragPtr) { BYTE tmpb; @@ -117,7 +117,7 @@ } static void -WriteShipFragment (void *fp, const SHIP_FRAGMENT *FragPtr) +WriteShipFragment (GAME_STATE_FILE *fp, const SHIP_FRAGMENT *FragPtr) { swrite_16 (fp, 0); /* unused: was which_side */ swrite_8 (fp, FragPtr->captains_name_index); @@ -135,7 +135,7 @@ } static void -ReadIpGroup (void *fp, IP_GROUP *GroupPtr) +ReadIpGroup (GAME_STATE_FILE *fp, IP_GROUP *GroupPtr) { BYTE tmpb; @@ -158,7 +158,7 @@ } static void -WriteIpGroup (void *fp, const IP_GROUP *GroupPtr) +WriteIpGroup (GAME_STATE_FILE *fp, const IP_GROUP *GroupPtr) { swrite_16 (fp, 0); /* unused; was which_side */ swrite_8 (fp, 0); /* unused; was captains_name_index */ @@ -181,7 +181,7 @@ void InitGroupInfo (BOOLEAN FirstTime) { - void *fp; + GAME_STATE_FILE *fp; assert (NUM_SAVED_BATTLE_GROUPS >= MAX_BATTLE_GROUPS); @@ -413,7 +413,7 @@ } static void -FlushGroupInfo (GROUP_HEADER* pGH, DWORD offset, BYTE which_group, void *fp) +FlushGroupInfo (GROUP_HEADER* pGH, DWORD offset, BYTE which_group, GAME_STATE_FILE *fp) { if (which_group == GROUP_LIST) { @@ -549,7 +549,7 @@ BOOLEAN GetGroupInfo (DWORD offset, BYTE which_group) { - void *fp; + GAME_STATE_FILE *fp; GROUP_HEADER GH; if (offset != GROUPS_RANDOM && which_group != GROUP_LIST) @@ -828,7 +828,7 @@ DWORD PutGroupInfo (DWORD offset, BYTE which_group) { - void *fp; + GAME_STATE_FILE *fp; GROUP_HEADER GH; if (offset != GROUPS_RANDOM && which_group != GROUP_LIST) Modified: trunk/sc2/src/uqm/state.c =================================================================== --- trunk/sc2/src/uqm/state.c 2011-10-01 14:15:35 UTC (rev 3696) +++ trunk/sc2/src/uqm/state.c 2011-10-01 14:54:18 UTC (rev 3697) @@ -239,7 +239,7 @@ void GetPlanetInfo (void) { - void *fp; + GAME_STATE_FILE *fp; pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask[BIOLOGICAL_SCAN] = 0; pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask[MINERAL_SCAN] = 0; @@ -287,7 +287,7 @@ void PutPlanetInfo (void) { - void *fp; + GAME_STATE_FILE *fp; fp = OpenStateFile (STARINFO_FILE, "r+b"); if (fp) Modified: trunk/sc2/src/uqm/state.h =================================================================== --- trunk/sc2/src/uqm/state.h 2011-10-01 14:15:35 UTC (rev 3696) +++ trunk/sc2/src/uqm/state.h 2011-10-01 14:54:18 UTC (rev 3697) @@ -79,7 +79,7 @@ int SeekStateFile (GAME_STATE_FILE *fp, long offset, int whence); static inline COUNT -sread_8 (void *fp, BYTE *v) +sread_8 (GAME_STATE_FILE *fp, BYTE *v) { BYTE t; if (!v) /* read value ignored */ @@ -88,7 +88,7 @@ } static inline COUNT -sread_16 (void *fp, UWORD *v) +sread_16 (GAME_STATE_FILE *fp, UWORD *v) { UWORD t; if (!v) /* read value ignored */ @@ -97,7 +97,7 @@ } static inline COUNT -sread_16s (void *fp, SWORD *v) +sread_16s (GAME_STATE_FILE *fp, SWORD *v) { UWORD t; COUNT ret; @@ -109,7 +109,7 @@ } static inline COUNT -sread_32 (void *fp, DWORD *v) +sread_32 (GAME_STATE_FILE *fp, DWORD *v) { DWORD t; if (!v) /* read value ignored */ @@ -118,7 +118,7 @@ } static inline COUNT -sread_a32 (void *fp, DWORD *ar, COUNT count) +sread_a32 (GAME_STATE_FILE *fp, DWORD *ar, COUNT count) { assert (ar != NULL); @@ -131,25 +131,25 @@ } static inline COUNT -swrite_8 (void *fp, BYTE v) +swrite_8 (GAME_STATE_FILE *fp, BYTE v) { return WriteStateFile (&v, 1, 1, fp); } static inline COUNT -swrite_16 (void *fp, UWORD v) +swrite_16 (GAME_STATE_FILE *fp, UWORD v) { return WriteStateFile (&v, 2, 1, fp); } static inline COUNT -swrite_32 (void *fp, DWORD v) +swrite_32 (GAME_STATE_FILE *fp, DWORD v) { return WriteStateFile (&v, 4, 1, fp); } static inline COUNT -swrite_a32 (void *fp, const DWORD *ar, COUNT count) +swrite_a32 (GAME_STATE_FILE *fp, const DWORD *ar, COUNT count) { for ( ; count > 0; --count, ++ar) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-10-01 15:55:19
|
Revision: 3700 http://sc2.svn.sourceforge.net/sc2/?rev=3700&view=rev Author: Meep-Eep Date: 2011-10-01 15:55:13 +0000 (Sat, 01 Oct 2011) Log Message: ----------- Don't require the 'shadow' dir in addon packs, from Alex. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/libs/uio/io.c trunk/sc2/src/libs/uio/io.h trunk/sc2/src/options.c Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-10-01 15:40:10 UTC (rev 3699) +++ trunk/sc2/ChangeLog 2011-10-01 15:55:13 UTC (rev 3700) @@ -1,4 +1,5 @@ Changes towards version 0.8: +- Don't require the 'shadow' dir in addon packs, from Alex - Make use of GAME_STATE_FILE consistently, from Scott A. Colcord - Fixed unconst(), from Scott A. Colcord - Fixes to a few small bugs in UIO which shouldn't have had an impact on Modified: trunk/sc2/src/libs/uio/io.c =================================================================== --- trunk/sc2/src/libs/uio/io.c 2011-10-01 15:40:10 UTC (rev 3699) +++ trunk/sc2/src/libs/uio/io.c 2011-10-01 15:55:13 UTC (rev 3700) @@ -287,6 +287,103 @@ } } +// Mount a repository directory into same repository at a different location +// From fossil. +uio_MountHandle * +uio_transplantDir(const char *mountPoint, uio_DirHandle *sourceDir, int flags, + uio_MountHandle *relative) { + uio_MountInfo *relativeInfo; + int numPDirHandles; + uio_PDirHandle **pDirHandles; + uio_MountTreeItem **treeItems; + int i; + uio_MountHandle *handle = NULL; + + if ((flags & uio_MOUNT_RDONLY) != uio_MOUNT_RDONLY) { + // Only read-only transplants supported atm + errno = ENOSYS; + return NULL; + } + + switch (flags & uio_MOUNT_LOCATION_MASK) { + case uio_MOUNT_TOP: + case uio_MOUNT_BOTTOM: + if (relative != NULL) { + errno = EINVAL; + return NULL; + } + relativeInfo = NULL; + break; + case uio_MOUNT_BELOW: + case uio_MOUNT_ABOVE: + if (relative == NULL) { + errno = EINVAL; + return NULL; + } + relativeInfo = relative->mountInfo; + break; + default: + abort(); + } + + if (mountPoint[0] == '/') + mountPoint++; + if (!validPathName(mountPoint, strlen(mountPoint))) { + errno = EINVAL; + return NULL; + } + + if (uio_getPathPhysicalDirs(sourceDir, "", 0, + &pDirHandles, &numPDirHandles, &treeItems) == -1) { + // errno is set + return NULL; + } + if (numPDirHandles == 0) { + errno = ENOENT; + return NULL; + } + + // TODO: We only transplant the first read-only physical dir that we find + // Maybe transplant all of them? We would then have several + // uio_MountHandles to return. + for (i = 0; i < numPDirHandles; ++i) { + uio_PDirHandle *pDirHandle = pDirHandles[i]; + uio_MountInfo *oldMountInfo = treeItems[i]->mountInfo; + uio_Repository *rep = oldMountInfo->mountHandle->repository; + uio_MountInfo *mountInfo; + uio_MountTree *mountTree; + + // Only interested in read-only dirs in this incarnation + if (!uio_mountInfoIsReadOnly(oldMountInfo)) + continue; + + mountInfo = uio_MountInfo_new(oldMountInfo->fsID, NULL, pDirHandle, + uio_strdup(""), oldMountInfo->autoMount, NULL, flags); + // New mount references the same handles + uio_PDirHandle_ref(pDirHandle); + uio_PRoot_refMount(pDirHandle->pRoot); + + uio_repositoryAddMount(rep, mountInfo, + flags & uio_MOUNT_LOCATION_MASK, relativeInfo); + mountTree = uio_mountTreeAddMountInfo(rep, rep->mountTree, + mountInfo, mountPoint, flags & uio_MOUNT_LOCATION_MASK, + relativeInfo); + // mountTree is the node in rep->mountTree where mountInfo leads to + mountInfo->mountTree = mountTree; + mountInfo->mountHandle = uio_MountHandle_new(rep, mountInfo); + handle = mountInfo->mountHandle; + break; + } + + uio_PDirHandles_delete(pDirHandles, numPDirHandles); + uio_free(treeItems); + + if (handle == NULL) + errno = ENOENT; + + return handle; +} + int uio_unmountDir(uio_MountHandle *mountHandle) { uio_PRoot *pRoot; Modified: trunk/sc2/src/libs/uio/io.h =================================================================== --- trunk/sc2/src/libs/uio/io.h 2011-10-01 15:40:10 UTC (rev 3699) +++ trunk/sc2/src/libs/uio/io.h 2011-10-01 15:55:13 UTC (rev 3700) @@ -82,6 +82,12 @@ const char *inPath, uio_AutoMount **autoMount, int flags, uio_MountHandle *relative); +// Mount a repository directory into same repository at a different +// location. +// From fossil. +uio_MountHandle *uio_transplantDir(const char *mountPoint, + uio_DirHandle *sourceDir, int flags, uio_MountHandle *relative); + // Unmount a previously mounted dir. int uio_unmountDir(uio_MountHandle *mountHandle); Modified: trunk/sc2/src/options.c =================================================================== --- trunk/sc2/src/options.c 2011-10-01 15:40:10 UTC (rev 3699) +++ trunk/sc2/src/options.c 2011-10-01 15:55:13 UTC (rev 3700) @@ -571,6 +571,14 @@ { log_add (log_Debug, "Mounting shadow content of '%s' addon", addon); mountDirZips (shadowDir, "/", uio_MOUNT_ABOVE, contentMountHandle); + // Mount non-zipped shadow content + if (uio_transplantDir ("/", shadowDir, uio_MOUNT_RDONLY | + uio_MOUNT_ABOVE, contentMountHandle) == NULL) + { + log_add (log_Warning, "Warning: Could not mount shadow content" + " of '%s': %s.", addon, strerror (errno)); + } + uio_closeDir (shadowDir); } uio_closeDir (addonDir); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-16 17:30:38
|
Revision: 3701 http://sc2.svn.sourceforge.net/sc2/?rev=3701&view=rev Author: Meep-Eep Date: 2011-12-16 17:30:27 +0000 (Fri, 16 Dec 2011) Log Message: ----------- Removed obsolete RESPONSE_TO_REF. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/uqm/comm/mycon/myconc.c trunk/sc2/src/uqm/commglue.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-10-01 15:55:13 UTC (rev 3700) +++ trunk/sc2/ChangeLog 2011-12-16 17:30:27 UTC (rev 3701) @@ -1,4 +1,5 @@ Changes towards version 0.8: +- Removed obsolete RESPONSE_TO_REF - SvdB - Don't require the 'shadow' dir in addon packs, from Alex - Make use of GAME_STATE_FILE consistently, from Scott A. Colcord - Fixed unconst(), from Scott A. Colcord Modified: trunk/sc2/src/uqm/comm/mycon/myconc.c =================================================================== --- trunk/sc2/src/uqm/comm/mycon/myconc.c 2011-10-01 15:55:13 UTC (rev 3700) +++ trunk/sc2/src/uqm/comm/mycon/myconc.c 2011-12-16 17:30:27 UTC (rev 3701) @@ -371,7 +371,7 @@ DoRamble (R); NPCPhrase (RAMBLE_TAIL); - DISABLE_PHRASE (RESPONSE_TO_REF (R)); + DISABLE_PHRASE (R); } if ((BYTE)TFB_Random () < 256 * 30 / 100) Modified: trunk/sc2/src/uqm/commglue.h =================================================================== --- trunk/sc2/src/uqm/commglue.h 2011-10-01 15:55:13 UTC (rev 3700) +++ trunk/sc2/src/uqm/commglue.h 2011-12-16 17:30:27 UTC (rev 3701) @@ -69,7 +69,6 @@ (*(UNICODE *)GetStringAddress ( \ SetAbsStringTableIndex (CommData.ConversationPhrases, (p)-1) \ ) = '\0') -#define RESPONSE_TO_REF(R) (R) #define Response(i,a) \ DoResponsePhrase(i,(RESPONSE_FUNC)a,0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-16 21:02:03
|
Revision: 3702 http://sc2.svn.sourceforge.net/sc2/?rev=3702&view=rev Author: Meep-Eep Date: 2011-12-16 21:01:55 +0000 (Fri, 16 Dec 2011) Log Message: ----------- Annihigate ActivateStarShip(). Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/uqm/build.c trunk/sc2/src/uqm/build.h trunk/sc2/src/uqm/comm/chmmr/chmmrc.c trunk/sc2/src/uqm/comm/druuge/druugec.c trunk/sc2/src/uqm/comm/orz/orzc.c trunk/sc2/src/uqm/comm/pkunk/pkunkc.c trunk/sc2/src/uqm/comm/rebel/rebel.c trunk/sc2/src/uqm/comm/spahome/spahome.c trunk/sc2/src/uqm/comm/spathi/spathic.c trunk/sc2/src/uqm/comm/starbas/starbas.c trunk/sc2/src/uqm/comm/supox/supoxc.c trunk/sc2/src/uqm/comm/syreen/syreenc.c trunk/sc2/src/uqm/comm/talkpet/talkpet.c trunk/sc2/src/uqm/comm/thradd/thraddc.c trunk/sc2/src/uqm/comm/umgah/umgahc.c trunk/sc2/src/uqm/comm/utwig/utwigc.c trunk/sc2/src/uqm/comm/yehat/yehatc.c trunk/sc2/src/uqm/comm/zoqfot/zoqfotc.c trunk/sc2/src/uqm/comm.c trunk/sc2/src/uqm/gameev.c trunk/sc2/src/uqm/globdata.c trunk/sc2/src/uqm/planets/devices.c trunk/sc2/src/uqm/planets/generate/genchmmr.c trunk/sc2/src/uqm/planets/generate/gendru.c trunk/sc2/src/uqm/planets/generate/genilw.c trunk/sc2/src/uqm/planets/generate/genmyc.c trunk/sc2/src/uqm/planets/generate/genorz.c trunk/sc2/src/uqm/planets/generate/genpet.c trunk/sc2/src/uqm/planets/generate/genpku.c trunk/sc2/src/uqm/planets/generate/gensam.c trunk/sc2/src/uqm/planets/generate/genspa.c trunk/sc2/src/uqm/planets/generate/gensup.c trunk/sc2/src/uqm/planets/generate/genthrad.c trunk/sc2/src/uqm/planets/generate/genutw.c trunk/sc2/src/uqm/planets/generate/genvux.c trunk/sc2/src/uqm/planets/generate/genyeh.c trunk/sc2/src/uqm/planets/generate/genzoq.c trunk/sc2/src/uqm/races.h trunk/sc2/src/uqm/shipyard.c trunk/sc2/src/uqm/uqmdebug.c Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/ChangeLog 2011-12-16 21:01:55 UTC (rev 3702) @@ -1,5 +1,6 @@ Changes towards version 0.8: -- Removed obsolete RESPONSE_TO_REF - SvdB +- Annigilate ActivateStarShip() - SvdB +- Removed obsolete RESPONSE_TO_REF() - SvdB - Don't require the 'shadow' dir in addon packs, from Alex - Make use of GAME_STATE_FILE consistently, from Scott A. Colcord - Fixed unconst(), from Scott A. Colcord Modified: trunk/sc2/src/uqm/build.c =================================================================== --- trunk/sc2/src/uqm/build.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/build.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -69,232 +69,287 @@ } /* - * What this function does depends on the value of the 'state' argument: - * SPHERE_TRACKING: - * The sphere of influence for the race for 'which_ship' will be shown - * on the starmap in the future. - * The value returned is 'which_ship', unless the type of ship is only - * available in SuperMelee, in which case 0 is returned. - * SPHERE_KNOWN: - * The size of the fleet of the race of 'which_ship' when the starmap was - * last checked is returned. - * ESCORT_WORTH: - * The total value of all the ships escorting the SIS is returned. - * 'which_ship' is ignored. - * ESCORTING_FLAGSHIP: - * Test if a ship of type 'which_ship' is among the escorts of the SIS - * 0 is returned if false, 1 if true. - * FEASIBILITY_STUDY: - * Test if the SIS can have an escort of type 'which_ship'. - * 0 is returned if 'which_ship' is not available. - * Otherwise, the number of ships that can be added is returned. - * CHECK_ALLIANCE: - * Test the alliance status of the race of 'which_ship'. - * Either GOOD_GUY (allied) or BAD_GUY (not allied) is returned. - * SET_ALLIED (0): - * Ally with the race of 'which_ship'. This makes their ship available - * for building in the shipyard. - * SET_NOT_ALLIED: - * End an alliance with the race of 'which_ship'. This ends the possibility - * of building their ships in the shipyard. - * REMOVE_BUILT: - * Make the already built escorts of the race of 'which_ship' disappear. - * (as for the Orz when the alliance with them ends) - * any other positive number: - * Give the player this many ships of type 'which_ship'. + * Give the player 'count' ships of the specified race, + * limited by the number of free slots. + * Returns the number of ships added. */ COUNT -ActivateStarShip (COUNT which_ship, SIZE state) +AddEscortShips (COUNT race, SIZE count) { HFLEETINFO hFleet; + BYTE which_window; + COUNT i; - hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), which_ship); + hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), race); if (!hFleet) return 0; - switch (state) + assert (count > 0); + + which_window = 0; + for (i = 0; i < (COUNT) count; i++) { - case SPHERE_TRACKING: - case SPHERE_KNOWN: + HSHIPFRAG hStarShip; + HSHIPFRAG hOldShip; + SHIP_FRAGMENT *StarShipPtr; + + hStarShip = CloneShipFragment (race, &GLOBAL (built_ship_q), 0); + if (!hStarShip) + break; + + RemoveQueue (&GLOBAL (built_ship_q), hStarShip); + + /* Find first available escort window */ + while ((hOldShip = GetStarShipFromIndex ( + &GLOBAL (built_ship_q), which_window++))) { - FLEET_INFO *FleetPtr; + BYTE win_loc; - FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hFleet); - if (state == SPHERE_KNOWN) - which_ship = FleetPtr->known_strength; - else if (FleetPtr->actual_strength == 0) - { - if (FleetPtr->allied_state == DEAD_GUY) - which_ship = 0; - } - else if (FleetPtr->known_strength == 0 - && FleetPtr->actual_strength != INFINITE_RADIUS) - { - FleetPtr->known_strength = 1; - FleetPtr->known_loc = FleetPtr->loc; - } - UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet); - return (which_ship); + StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hOldShip); + win_loc = StarShipPtr->index; + UnlockShipFrag (&GLOBAL (built_ship_q), hOldShip); + if (which_window <= win_loc) + break; } - case ESCORT_WORTH: - { - COUNT ShipCost[] = - { - RACE_SHIP_COST - }; - COUNT total = 0; - HSHIPFRAG hStarShip, hNextShip; - for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)); - hStarShip; hStarShip = hNextShip) - { - SHIP_FRAGMENT *StarShipPtr; + StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); + StarShipPtr->index = which_window - 1; + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); - StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); - hNextShip = _GetSuccLink (StarShipPtr); - total += ShipCost[StarShipPtr->race_id]; - UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); - } - return total; - } - case ESCORTING_FLAGSHIP: - { - HSHIPFRAG hStarShip, hNextShip; + InsertQueue (&GLOBAL (built_ship_q), hStarShip, hOldShip); + } - for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)); - hStarShip; hStarShip = hNextShip) - { - BYTE ship_type; - SHIP_FRAGMENT *StarShipPtr; + LockMutex (GraphicsLock); + DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA); + UnlockMutex (GraphicsLock); + return i; +} - StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); - hNextShip = _GetSuccLink (StarShipPtr); - ship_type = StarShipPtr->race_id; - UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); +/* + * Returns the total value of all the ships escorting the SIS. + */ +COUNT +CalculateEscortsWorth (void) +{ + COUNT ShipCost[] = + { + RACE_SHIP_COST + }; + COUNT total = 0; + HSHIPFRAG hStarShip, hNextShip; - if (ship_type == which_ship) - return 1; - } - return 0; - } - case FEASIBILITY_STUDY: + for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)); + hStarShip; hStarShip = hNextShip) + { + SHIP_FRAGMENT *StarShipPtr; + + StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); + hNextShip = _GetSuccLink (StarShipPtr); + total += ShipCost[StarShipPtr->race_id]; + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + } + return total; +} + +#if 0 +/* + * Returns the size of the fleet of the specified race when the starmap was + * last checked. If the race has no SoI, 0 is returned. + */ +COUNT +GetRaceKnownSize (COUNT race) +{ + HFLEETINFO hFleet; + FLEET_INFO *FleetPtr; + COUNT result; + + hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), race); + if (!hFleet) + return 0; + + FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hFleet); + + result = FleetPtr->known_strength; + + UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet); + return result; +} +#endif + +/* + * Start or end an alliance with the specified race. + * Being in an alliance with a race makes their ships available for building + * in the shipyard. + * flag == TRUE: start an alliance + * flag == TRUE: end an alliance + */ +COUNT +SetRaceAllied (COUNT race, BOOLEAN flag) { + HFLEETINFO hFleet; + FLEET_INFO *FleetPtr; + + hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), race); + if (!hFleet) + return 0; + + FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hFleet); + + if (FleetPtr->allied_state == DEAD_GUY) + { + /* Strange request, silently ignore it */ + } + else + { + FleetPtr->allied_state = (flag ? GOOD_GUY : BAD_GUY); + } + + UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet); + return 1; +} + +/* + * Make the sphere of influence for the specified race shown on the starmap + * in the future. + * The value returned is 'race', unless the type of ship is only available + * in SuperMelee, in which case 0 is returned. + */ +COUNT +StartSphereTracking (COUNT race) +{ + HFLEETINFO hFleet; + FLEET_INFO *FleetPtr; + + hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), race); + if (!hFleet) + return 0; + + FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hFleet); + + if (FleetPtr->actual_strength == 0) + { + if (FleetPtr->allied_state == DEAD_GUY) { - return (MAX_BUILT_SHIPS - CountLinks (&GLOBAL (built_ship_q))); - } - case CHECK_ALLIANCE: - { - UWORD flags; - FLEET_INFO *FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), - hFleet); - flags = FleetPtr->allied_state; + // Race is extinct. UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet); - return flags; + return 0; } - case SET_ALLIED: - case SET_NOT_ALLIED: - { - FLEET_INFO *FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), - hFleet); + } + else if (FleetPtr->known_strength == 0 + && FleetPtr->actual_strength != INFINITE_RADIUS) + { + FleetPtr->known_strength = 1; + FleetPtr->known_loc = FleetPtr->loc; + } - if (FleetPtr->allied_state == DEAD_GUY) - { /* Strange request, silently ignore it */ - UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet); - break; - } + UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet); + return race; +} - if (state == SET_ALLIED) - FleetPtr->allied_state = GOOD_GUY; - else - FleetPtr->allied_state = BAD_GUY; - - UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet); - break; - } - case REMOVE_BUILT: - { - HSHIPFRAG hStarShip, hNextShip; - BOOLEAN ShipRemoved = FALSE; +/* + * Returns true if and only if a ship of the specified race is among the + * escort ships. + */ +BOOLEAN +HaveEscortShip (COUNT race) +{ + HFLEETINFO hFleet; + HSHIPFRAG hStarShip, hNextShip; - for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)); - hStarShip; hStarShip = hNextShip) - { - BOOLEAN RemoveShip; - SHIP_FRAGMENT *StarShipPtr; + hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), race); + if (!hFleet) + return FALSE; - StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); - hNextShip = _GetSuccLink (StarShipPtr); - RemoveShip = (StarShipPtr->race_id == which_ship); - UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)); hStarShip; + hStarShip = hNextShip) + { + BYTE ship_type; + SHIP_FRAGMENT *StarShipPtr; - if (RemoveShip) - { - ShipRemoved = TRUE; + StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); + hNextShip = _GetSuccLink (StarShipPtr); + ship_type = StarShipPtr->race_id; + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); - RemoveQueue (&GLOBAL (built_ship_q), hStarShip); - FreeShipFrag (&GLOBAL (built_ship_q), hStarShip); - } - } - - if (ShipRemoved) - { - LockMutex (GraphicsLock); - DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, - UNDEFINED_DELTA); - UnlockMutex (GraphicsLock); - } - break; - } - default: - { - BYTE which_window; - COUNT i; + if (ship_type == race) + return TRUE; + } + return FALSE; +} - assert (state > 0); - /* Add ships to the escorts */ - which_window = 0; - for (i = 0; i < (COUNT)state; i++) - { - HSHIPFRAG hStarShip; - HSHIPFRAG hOldShip; - SHIP_FRAGMENT *StarShipPtr; +/* + * Test if the SIS can have an escort of the specified race. + * Returns 0 if 'race' is not available. + * Otherwise, returns the number of ships that can be added. + */ +COUNT +EscortFeasibilityStudy (COUNT race) +{ + HFLEETINFO hFleet; - hStarShip = CloneShipFragment (which_ship, - &GLOBAL (built_ship_q), 0); - if (!hStarShip) - break; + hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), race); + if (!hFleet) + return 0; - RemoveQueue (&GLOBAL (built_ship_q), hStarShip); + return (MAX_BUILT_SHIPS - CountLinks (&GLOBAL (built_ship_q))); +} - /* Find first available escort window */ - while ((hOldShip = GetStarShipFromIndex ( - &GLOBAL (built_ship_q), which_window++))) - { - BYTE win_loc; +/* + * Test the alliance status of the specified race. + * Either DEAD_GUY (extinct), GOOD_GUY (allied), or BAD_GUY (not allied) is + * returned. + */ +COUNT +CheckAlliance (COUNT race) +{ + HFLEETINFO hFleet; + UWORD flags; + FLEET_INFO *FleetPtr; - StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), - hOldShip); - win_loc = StarShipPtr->index; - UnlockShipFrag (&GLOBAL (built_ship_q), hOldShip); - if (which_window <= win_loc) - break; - } + hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), race); + if (!hFleet) + return 0; - StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); - StarShipPtr->index = which_window - 1; - UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hFleet); + flags = FleetPtr->allied_state; + UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet); - InsertQueue (&GLOBAL (built_ship_q), hStarShip, hOldShip); - } + return flags; +} - LockMutex (GraphicsLock); - DeltaSISGauges (UNDEFINED_DELTA, - UNDEFINED_DELTA, UNDEFINED_DELTA); - UnlockMutex (GraphicsLock); - return i; +/* + * Remove all escort ships of the specified race. + */ +void +RemoveEscortShips (COUNT race) +{ + HSHIPFRAG hStarShip, hNextShip; + BOOLEAN ShipRemoved = FALSE; + + for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)); hStarShip; + hStarShip = hNextShip) + { + BOOLEAN RemoveShip; + SHIP_FRAGMENT *StarShipPtr; + + StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); + hNextShip = _GetSuccLink (StarShipPtr); + RemoveShip = (StarShipPtr->race_id == race); + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + if (RemoveShip) + { + ShipRemoved = TRUE; + RemoveQueue (&GLOBAL (built_ship_q), hStarShip); + FreeShipFrag (&GLOBAL (built_ship_q), hStarShip); } } - - return 1; + + if (ShipRemoved) + { + LockMutex (GraphicsLock); + DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA); + UnlockMutex (GraphicsLock); + } } COUNT Modified: trunk/sc2/src/uqm/build.h =================================================================== --- trunk/sc2/src/uqm/build.h 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/build.h 2011-12-16 21:01:55 UTC (rev 3702) @@ -60,6 +60,16 @@ extern int SetEscortCrewComplement (COUNT which_ship, COUNT crew_level, BYTE captain); +COUNT AddEscortShips (COUNT race, SIZE count); +extern COUNT CalculateEscortsWorth (void); +//extern COUNT GetRaceKnownSize (COUNT race); +extern COUNT SetRaceAllied (COUNT race, BOOLEAN flag); +extern COUNT StartSphereTracking (COUNT race); +BOOLEAN HaveEscortShip (COUNT race); +extern COUNT EscortFeasibilityStudy (COUNT race); +extern COUNT CheckAlliance (COUNT race); +extern void RemoveEscortShips (COUNT race); + extern RACE_DESC *load_ship (SPECIES_ID SpeciesID, BOOLEAN LoadBattleData); extern void free_ship (RACE_DESC *RaceDescPtr, BOOLEAN FreeIconData, BOOLEAN FreeBattleData); Modified: trunk/sc2/src/uqm/comm/chmmr/chmmrc.c =================================================================== --- trunk/sc2/src/uqm/comm/chmmr/chmmrc.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/chmmr/chmmrc.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -134,7 +134,7 @@ NPCPhrase (TAKE_2_WEEKS); - ActivateStarShip (CHMMR_SHIP, SET_ALLIED); + SetRaceAllied (CHMMR_SHIP, TRUE); SET_GAME_STATE (CHMMR_HOME_VISITS, 0); SET_GAME_STATE (CHMMR_STACK, 0); @@ -248,7 +248,7 @@ { NPCPhrase (USE_OUR_SHIPS_BEFORE); - ActivateStarShip (CHMMR_SHIP, SET_ALLIED); + SetRaceAllied (CHMMR_SHIP, TRUE); } else if (PLAYER_SAID (R, where_weapon)) { @@ -263,7 +263,7 @@ DISABLE_PHRASE (where_distraction); } - if (ActivateStarShip (CHMMR_SHIP, CHECK_ALLIANCE) != GOOD_GUY) + if (CheckAlliance (CHMMR_SHIP) != GOOD_GUY) Response (tech_help, NotReady); else if (PHRASE_ENABLED (further_assistance)) Response (further_assistance, NotReady); @@ -301,7 +301,7 @@ { NPCPhrase (USE_OUR_SHIPS_AFTER); - ActivateStarShip (CHMMR_SHIP, SET_ALLIED); + SetRaceAllied (CHMMR_SHIP, TRUE); } if (PHRASE_ENABLED (what_now)) @@ -310,7 +310,7 @@ Response (wont_hurt_my_ship, ImproveBomb); else if (PHRASE_ENABLED (bummer_about_my_ship)) Response (bummer_about_my_ship, ImproveBomb); - if (ActivateStarShip (CHMMR_SHIP, CHECK_ALLIANCE) != GOOD_GUY) + if (CheckAlliance (CHMMR_SHIP) != GOOD_GUY) Response (other_assistance, ImproveBomb); Response (proceed, ExitConversation); } Modified: trunk/sc2/src/uqm/comm/druuge/druugec.c =================================================================== --- trunk/sc2/src/uqm/comm/druuge/druugec.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/druuge/druugec.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -240,7 +240,7 @@ #define SHIP_CREW_COST 100 if (GLOBAL_SIS (CrewEnlisted) < SHIP_CREW_COST) NPCPhrase (NOT_ENOUGH_CREW); - else if (ActivateStarShip (DRUUGE_SHIP, FEASIBILITY_STUDY) == 0) + else if (EscortFeasibilityStudy (DRUUGE_SHIP) == 0) NPCPhrase (NOT_ENOUGH_ROOM); else { @@ -248,7 +248,7 @@ DeltaSISGauges (-SHIP_CREW_COST, 0, 0); UnlockMutex (GraphicsLock); SlaveryCount += SHIP_CREW_COST; - ActivateStarShip (DRUUGE_SHIP, 1); + AddEscortShips (DRUUGE_SHIP, 1); NPCPhrase (BOUGHT_SHIP); } @@ -403,7 +403,7 @@ trade_gas = 0; ships_to_trade = 0; - ship_slots = ActivateStarShip (DRUUGE_SHIP, FEASIBILITY_STUDY); + ship_slots = EscortFeasibilityStudy (DRUUGE_SHIP); if (PLAYER_SAID (R, sell_maidens)) { NPCPhrase (BOUGHT_MAIDENS); @@ -430,7 +430,7 @@ NPCPhrase (YOU_GET); if (ships_to_trade) { - ActivateStarShip (DRUUGE_SHIP, ships_to_trade); + AddEscortShips (DRUUGE_SHIP, ships_to_trade); if (ship_slots >= ships_to_trade) NPCPhrase (DEAL_FOR_STATED_SHIPS); Modified: trunk/sc2/src/uqm/comm/orz/orzc.c =================================================================== --- trunk/sc2/src/uqm/comm/orz/orzc.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/orz/orzc.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -213,7 +213,7 @@ SET_GAME_STATE (ORZ_GENERAL_INFO, 0); SET_GAME_STATE (ORZ_PERSONAL_INFO, 0); SET_GAME_STATE (ORZ_MANNER, 3); - ActivateStarShip (ORZ_SHIP, SET_ALLIED); + SetRaceAllied (ORZ_SHIP, TRUE); } else if (PLAYER_SAID (R, demand_to_land)) { @@ -234,8 +234,8 @@ SET_GAME_STATE (BATTLE_SEGUE, 1); if (PLAYER_SAID (R, about_andro_3)) { - ActivateStarShip (ORZ_SHIP, SET_NOT_ALLIED); - ActivateStarShip (ORZ_SHIP, REMOVE_BUILT); + SetRaceAllied (ORZ_SHIP, FALSE); + RemoveEscortShips (ORZ_SHIP); } XFormColorMap (GetColorMapAddress ( @@ -322,8 +322,7 @@ if (PHRASE_ENABLED (may_we_land)) { - if (Manner == 3 && - ActivateStarShip (ORZ_SHIP, CHECK_ALLIANCE) == GOOD_GUY) + if (Manner == 3 && CheckAlliance (ORZ_SHIP) == GOOD_GUY) Response (may_we_land, ExitConversation); else Response (may_we_land, TaaloWorld); @@ -705,8 +704,7 @@ TaaloWorld ((RESPONSE_REF)0); } - else if (Manner == 3 && - ActivateStarShip (ORZ_SHIP, CHECK_ALLIANCE) == GOOD_GUY) + else if (Manner == 3 && CheckAlliance (ORZ_SHIP) == GOOD_GUY) { if (GET_GAME_STATE (GLOBAL_FLAGS_AND_DATA) & (1 << 7)) { Modified: trunk/sc2/src/uqm/comm/pkunk/pkunkc.c =================================================================== --- trunk/sc2/src/uqm/comm/pkunk/pkunkc.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/pkunk/pkunkc.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -110,7 +110,7 @@ PrepareShip (void) { #define MAX_PKUNK_SHIPS 4 - if (ActivateStarShip (PKUNK_SHIP, MAX_PKUNK_SHIPS)) + if (AddEscortShips (PKUNK_SHIP, MAX_PKUNK_SHIPS)) { BYTE mi, di, yi; @@ -157,7 +157,7 @@ SET_GAME_STATE (PKUNK_INFO, 0); AddEvent (RELATIVE_EVENT, 6, 0, 0, ADVANCE_PKUNK_MISSION); - if (ActivateStarShip (PKUNK_SHIP, FEASIBILITY_STUDY) == 0) + if (EscortFeasibilityStudy (PKUNK_SHIP) == 0) NPCPhrase (INIT_NO_ROOM); else { @@ -949,7 +949,7 @@ { if (NumVisits && ShipsReady ()) { - if (ActivateStarShip (PKUNK_SHIP, FEASIBILITY_STUDY) == 0) + if (EscortFeasibilityStudy (PKUNK_SHIP) == 0) NPCPhrase (NO_ROOM); else { Modified: trunk/sc2/src/uqm/comm/rebel/rebel.c =================================================================== --- trunk/sc2/src/uqm/comm/rebel/rebel.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/rebel/rebel.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -324,7 +324,7 @@ || ((NumVisits == 0 && (NumVisits = GLOBAL (GameClock.month_index) - GET_GAME_STATE (YEHAT_SHIP_MONTH)) < 0) || (NumVisits == 0 && GLOBAL (GameClock.day_index) < GET_GAME_STATE (YEHAT_SHIP_DAY))))) NPCPhrase (NO_SHIPS_YET); - else if ((NumVisits = ActivateStarShip (YEHAT_SHIP, FEASIBILITY_STUDY)) == 0) + else if ((NumVisits = EscortFeasibilityStudy (YEHAT_SHIP)) == 0) NPCPhrase (NO_ROOM); else { @@ -338,7 +338,7 @@ } AlienTalkSegue ((COUNT)~0); - ActivateStarShip (YEHAT_SHIP, NumVisits); + AddEscortShips (YEHAT_SHIP, NumVisits); PrepareShip (); } @@ -382,12 +382,11 @@ NPCPhrase (YEHAT_CAVALRY); AlienTalkSegue ((COUNT)~0); - if ((NumVisits = (BYTE)ActivateStarShip ( - YEHAT_REBEL_SHIP, FEASIBILITY_STUDY - )) > 8) + NumVisits = (BYTE) EscortFeasibilityStudy (YEHAT_REBEL_SHIP); + if (NumVisits > 8) NumVisits = 8; - ActivateStarShip (YEHAT_REBEL_SHIP, NumVisits - (NumVisits >> 1)); - ActivateStarShip (PKUNK_SHIP, NumVisits >> 1); + AddEscortShips (YEHAT_REBEL_SHIP, NumVisits - (NumVisits >> 1)); + AddEscortShips (PKUNK_SHIP, NumVisits >> 1); } else { Modified: trunk/sc2/src/uqm/comm/spahome/spahome.c =================================================================== --- trunk/sc2/src/uqm/comm/spahome/spahome.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/spahome/spahome.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -251,7 +251,7 @@ { NPCPhrase (DEPART_FOR_EARTH); - ActivateStarShip (SPATHI_SHIP, SET_ALLIED); + SetRaceAllied (SPATHI_SHIP, TRUE); AddEvent (RELATIVE_EVENT, 6, 0, 0, SPATHI_SHIELD_EVENT); SET_GAME_STATE (SPATHI_HOME_VISITS, 0); SET_GAME_STATE (SPATHI_VISITS, 0); @@ -821,7 +821,7 @@ { if (PHRASE_ENABLED (spathi_on_pluto)) Response (spathi_on_pluto, SpathiCouncil); - else if (ActivateStarShip (SPATHI_SHIP, ESCORTING_FLAGSHIP)) + else if (HaveEscortShip (SPATHI_SHIP)) { if (PHRASE_ENABLED (hostage)) Response (hostage, SpathiCouncil); @@ -915,7 +915,7 @@ { SpathiAngry ((RESPONSE_REF)0); } - else if (ActivateStarShip (SPATHI_SHIP, CHECK_ALLIANCE) == GOOD_GUY) + else if (CheckAlliance (SPATHI_SHIP) == GOOD_GUY) { CommData.AlienColorMap = SetAbsColorMapIndex (CommData.AlienColorMap, 1); Modified: trunk/sc2/src/uqm/comm/spathi/spathic.c =================================================================== --- trunk/sc2/src/uqm/comm/spathi/spathic.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/spathi/spathic.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -188,14 +188,14 @@ } else if (PLAYER_SAID (Response, join_us)) { - if (ActivateStarShip (SPATHI_SHIP, FEASIBILITY_STUDY) == 0) + if (EscortFeasibilityStudy (SPATHI_SHIP) == 0) NPCPhrase (TOO_SCARY); else { NPCPhrase (WILL_JOIN); AlienTalkSegue ((COUNT)~0); - ActivateStarShip (SPATHI_SHIP, 1); + AddEscortShips (SPATHI_SHIP, 1); /* Make the Eluder escort captained by Fwiffo alone */ SetEscortCrewComplement (SPATHI_SHIP, 1, NAME_OFFSET + NUM_CAPTAINS_NAMES); @@ -750,7 +750,7 @@ Response (we_fight_again_space, ExitConversation); Response (bye_angry_space, ExitConversation); } - else if (ActivateStarShip (SPATHI_SHIP, CHECK_ALLIANCE) == GOOD_GUY) + else if (CheckAlliance (SPATHI_SHIP) == GOOD_GUY) { SpathiAllies ((RESPONSE_REF)0); } Modified: trunk/sc2/src/uqm/comm/starbas/starbas.c =================================================================== --- trunk/sc2/src/uqm/comm/starbas/starbas.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/starbas/starbas.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -700,11 +700,10 @@ COUNT FleetStrength; BOOLEAN HasMaximum; - FleetStrength = ActivateStarShip (0, ESCORT_WORTH); + FleetStrength = CalculateEscortsWorth (); for (i = 0; i < NUM_AVAILABLE_RACES; ++i) { - if (i != HUMAN_SHIP - && ActivateStarShip (i, CHECK_ALLIANCE) == GOOD_GUY) + if (i != HUMAN_SHIP && CheckAlliance (i) == GOOD_GUY) ++num_aliens; } @@ -1377,36 +1376,31 @@ switch (b0) { case 0: - if (ActivateStarShip (SPATHI_SHIP, CHECK_ALLIANCE) - == GOOD_GUY) + if (CheckAlliance (SPATHI_SHIP) == GOOD_GUY) { pStr = STARBASE_BULLETIN_1; } break; case 1: - if (ActivateStarShip (ZOQFOTPIK_SHIP, CHECK_ALLIANCE) - == GOOD_GUY) + if (CheckAlliance (ZOQFOTPIK_SHIP) == GOOD_GUY) { pStr = STARBASE_BULLETIN_2; } break; case 2: - if (ActivateStarShip (SUPOX_SHIP, CHECK_ALLIANCE) - == GOOD_GUY) + if (CheckAlliance (SUPOX_SHIP) == GOOD_GUY) { pStr = STARBASE_BULLETIN_3; } break; case 3: - if (ActivateStarShip (UTWIG_SHIP, CHECK_ALLIANCE) - == GOOD_GUY) + if (CheckAlliance (UTWIG_SHIP) == GOOD_GUY) { pStr = STARBASE_BULLETIN_4; } break; case 4: - if (ActivateStarShip (ORZ_SHIP, CHECK_ALLIANCE) - == GOOD_GUY) + if (CheckAlliance (ORZ_SHIP) == GOOD_GUY) { pStr = STARBASE_BULLETIN_5; } @@ -1415,14 +1409,13 @@ if (GET_GAME_STATE (ARILOU_MANNER) == 2) BulletinMask |= 1L << b0; else if (GET_GAME_STATE (PORTAL_SPAWNER) - && (Repeat || ActivateStarShip ( - ARILOU_SHIP, FEASIBILITY_STUDY - ))) + && (Repeat || EscortFeasibilityStudy ( + ARILOU_SHIP))) { #define NUM_GIFT_ARILOUS 3 pStr = STARBASE_BULLETIN_6; if (!Repeat) - ActivateStarShip (ARILOU_SHIP, NUM_GIFT_ARILOUS); + AddEscortShips (ARILOU_SHIP, NUM_GIFT_ARILOUS); } break; case 6: @@ -1471,15 +1464,13 @@ } break; case 12: - if (ActivateStarShip (CHMMR_SHIP, CHECK_ALLIANCE) - == GOOD_GUY) + if (CheckAlliance (CHMMR_SHIP) == GOOD_GUY) { pStr = STARBASE_BULLETIN_13; } break; case 13: - if (ActivateStarShip (SHOFIXTI_SHIP, CHECK_ALLIANCE) - == GOOD_GUY) + if (CheckAlliance (SHOFIXTI_SHIP) == GOOD_GUY) { pStr = STARBASE_BULLETIN_14; } Modified: trunk/sc2/src/uqm/comm/supox/supoxc.c =================================================================== --- trunk/sc2/src/uqm/comm/supox/supoxc.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/supox/supoxc.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -126,14 +126,14 @@ else if (PLAYER_SAID (R, can_you_help)) { NPCPhrase (HOW_HELP); - if (ActivateStarShip (SUPOX_SHIP, FEASIBILITY_STUDY) == 0) + if (EscortFeasibilityStudy (SUPOX_SHIP) == 0) NPCPhrase (DONT_NEED); else { NPCPhrase (HAVE_4_SHIPS); AlienTalkSegue ((COUNT)~0); - ActivateStarShip (SUPOX_SHIP, 4); + AddEscortShips (SUPOX_SHIP, 4); } } } @@ -357,7 +357,7 @@ LastStack = 2; SET_GAME_STATE (SUPOX_WAR_NEWS, 1); - ActivateStarShip (UTWIG_SHIP, SPHERE_TRACKING); + StartSphereTracking (UTWIG_SHIP); } else if (PLAYER_SAID (R, what_relation_to_utwig)) { @@ -552,7 +552,7 @@ SET_GAME_STATE (BATTLE_SEGUE, 0); } - else if (ActivateStarShip (SUPOX_SHIP, CHECK_ALLIANCE) == GOOD_GUY) + else if (CheckAlliance (SUPOX_SHIP) == GOOD_GUY) { if (GET_GAME_STATE (GLOBAL_FLAGS_AND_DATA) & (1 << 7)) { Modified: trunk/sc2/src/uqm/comm/syreen/syreenc.c =================================================================== --- trunk/sc2/src/uqm/comm/syreen/syreenc.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/syreen/syreenc.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -740,7 +740,7 @@ { case 0: NPCPhrase (HELLO_AFTER_AMBUSH_1); - ActivateStarShip (SYREEN_SHIP, SET_ALLIED); + SetRaceAllied (SYREEN_SHIP, TRUE); break; case 1: NPCPhrase (HELLO_AFTER_AMBUSH_2); Modified: trunk/sc2/src/uqm/comm/talkpet/talkpet.c =================================================================== --- trunk/sc2/src/uqm/comm/talkpet/talkpet.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/talkpet/talkpet.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -780,7 +780,7 @@ } else { - if (ActivateStarShip (UMGAH_SHIP, SPHERE_TRACKING)) + if (StartSphereTracking (UMGAH_SHIP)) { NPCPhrase (LETS_MAKE_A_DEAL); } Modified: trunk/sc2/src/uqm/comm/thradd/thraddc.c =================================================================== --- trunk/sc2/src/uqm/comm/thradd/thraddc.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/thradd/thraddc.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -505,7 +505,7 @@ SET_GAME_STATE (THRADD_VISITS, 0); SET_GAME_STATE (THRADD_MANNER, 1); SET_GAME_STATE (THRADD_STACK_1, 0); - ActivateStarShip (THRADDASH_SHIP, SET_ALLIED); + SetRaceAllied (THRADDASH_SHIP, TRUE); Response (be_polite, ThraddCulture); Response (speak_pig_latin, ThraddCulture); Modified: trunk/sc2/src/uqm/comm/umgah/umgahc.c =================================================================== --- trunk/sc2/src/uqm/comm/umgah/umgahc.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/umgah/umgahc.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -242,7 +242,7 @@ NPCPhrase (FUNNY_IDEA); AlienTalkSegue ((COUNT)~0); - ActivateStarShip (UMGAH_SHIP, 4); + AddEscortShips (UMGAH_SHIP, 4); SET_GAME_STATE (UMGAH_HOSTILE, 1); } } Modified: trunk/sc2/src/uqm/comm/utwig/utwigc.c =================================================================== --- trunk/sc2/src/uqm/comm/utwig/utwigc.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/utwig/utwigc.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -288,22 +288,22 @@ SET_GAME_STATE (SUPOX_HOSTILE, 0); SET_GAME_STATE (UTWIG_HOSTILE, 0); - ActivateStarShip (UTWIG_SHIP, SET_ALLIED); - ActivateStarShip (SUPOX_SHIP, SET_ALLIED); + SetRaceAllied (UTWIG_SHIP, TRUE); + SetRaceAllied (SUPOX_SHIP, TRUE); } } } else if (PLAYER_SAID (R, can_you_help)) { NPCPhrase (HOW_HELP); - if (ActivateStarShip (UTWIG_SHIP, FEASIBILITY_STUDY) == 0) + if (EscortFeasibilityStudy (UTWIG_SHIP) == 0) NPCPhrase (DONT_NEED); else { NPCPhrase (HAVE_4_SHIPS); AlienTalkSegue ((COUNT)~0); - ActivateStarShip (UTWIG_SHIP, 4); + AddEscortShips (UTWIG_SHIP, 4); } } } @@ -390,7 +390,7 @@ Response (what_now_homeworld, AlliedHome); if (PHRASE_ENABLED (how_is_ultron)) Response (how_is_ultron, AlliedHome); - if (NumVisits == 0 && ActivateStarShip (UTWIG_SHIP, FEASIBILITY_STUDY) != 0) + if (NumVisits == 0 && EscortFeasibilityStudy (UTWIG_SHIP) != 0) Response (can_you_help, ExitConversation); Response (bye_allied_homeworld, ExitConversation); } @@ -525,7 +525,7 @@ NPCPhrase (ABOUT_US_2); LastStack = 2; - ActivateStarShip (SUPOX_SHIP, SPHERE_TRACKING); + StartSphereTracking (SUPOX_SHIP); SET_GAME_STATE (UTWIG_WAR_NEWS, 2); } else if (PLAYER_SAID (R, what_about_you_3)) @@ -807,7 +807,7 @@ Response (hey_wait_got_ultron, ExitConversation); } } - else if (ActivateStarShip (UTWIG_SHIP, CHECK_ALLIANCE) == GOOD_GUY) + else if (CheckAlliance (UTWIG_SHIP) == GOOD_GUY) { if (GET_GAME_STATE (GLOBAL_FLAGS_AND_DATA) & (1 << 7)) { Modified: trunk/sc2/src/uqm/comm/yehat/yehatc.c =================================================================== --- trunk/sc2/src/uqm/comm/yehat/yehatc.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/yehat/yehatc.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -309,7 +309,7 @@ else if (PLAYER_SAID (R, shofixti_alive_2)) NPCPhrase (SEND_HIM_OVER_2); - if (ActivateStarShip (SHOFIXTI_SHIP, ESCORTING_FLAGSHIP)) + if (HaveEscortShip (SHOFIXTI_SHIP)) Response (ok_send, ExitConversation); else Response (not_here, ExitConversation); Modified: trunk/sc2/src/uqm/comm/zoqfot/zoqfotc.c =================================================================== --- trunk/sc2/src/uqm/comm/zoqfot/zoqfotc.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm/zoqfot/zoqfotc.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -224,7 +224,7 @@ NPCPhrase_cb (WE_ALLY4, &SelectAlienZOQ); NPCPhrase_cb (WE_ALLY5, &SelectAlienPIK); ZFPTalkSegue ((COUNT)~0); - ActivateStarShip (ZOQFOTPIK_SHIP, SET_ALLIED); + SetRaceAllied (ZOQFOTPIK_SHIP, TRUE); AddEvent (RELATIVE_EVENT, 3, 0, 0, ZOQFOT_DISTRESS_EVENT); SET_GAME_STATE (ZOQFOT_HOME_VISITS, 0); } @@ -735,7 +735,7 @@ NPCPhrase_cb (GOOD9, &SelectAlienPIK); ZFPTalkSegue ((COUNT)~0); - ActivateStarShip (ZOQFOTPIK_SHIP, SET_ALLIED); + SetRaceAllied (ZOQFOTPIK_SHIP, TRUE); AddEvent (RELATIVE_EVENT, 3, 0, 0, ZOQFOT_DISTRESS_EVENT); } else if (PLAYER_SAID (R, enough_info)) @@ -748,7 +748,7 @@ Response (whats_up_homeworld, ZoqFotHome); if (PHRASE_ENABLED (any_war_news)) Response (any_war_news, ZoqFotHome); - if (ActivateStarShip (ZOQFOTPIK_SHIP, CHECK_ALLIANCE) != GOOD_GUY) + if (CheckAlliance (ZOQFOTPIK_SHIP) != GOOD_GUY) Response (i_want_alliance, ZoqFotHome); else if (PHRASE_ENABLED (want_specific_info)) { @@ -870,12 +870,12 @@ ZFPTalkSegue ((COUNT)~0); SET_GAME_STATE (ZOQFOT_DISTRESS, 0); - ActivateStarShip (ZOQFOTPIK_SHIP, MAX_ZFP_SHIPS); + AddEscortShips (ZOQFOTPIK_SHIP, MAX_ZFP_SHIPS); } else { NumVisits = GET_GAME_STATE (ZOQFOT_HOME_VISITS); - if (ActivateStarShip (ZOQFOTPIK_SHIP, CHECK_ALLIANCE) != GOOD_GUY) + if (CheckAlliance (ZOQFOTPIK_SHIP) != GOOD_GUY) { switch (NumVisits++) { @@ -960,7 +960,7 @@ zoqfot_desc.AlienTextWidth = (SIS_TEXT_WIDTH >> 1) - TEXT_X_OFFS; - if (ActivateStarShip (ZOQFOTPIK_SHIP, CHECK_ALLIANCE) == GOOD_GUY + if (CheckAlliance (ZOQFOTPIK_SHIP) == GOOD_GUY || LOBYTE (GLOBAL (CurrentActivity)) == WON_LAST_BATTLE) { SET_GAME_STATE (BATTLE_SEGUE, 0); Modified: trunk/sc2/src/uqm/comm.c =================================================================== --- trunk/sc2/src/uqm/comm.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/comm.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -1394,7 +1394,7 @@ status = HUMAN_SHIP; } } - ActivateStarShip (status, SPHERE_TRACKING); + StartSphereTracking (status); if (which_comm == ORZ_CONVERSATION || (which_comm == TALKING_PET_CONVERSATION @@ -1402,7 +1402,7 @@ || LOBYTE (GLOBAL (CurrentActivity)) == IN_LAST_BATTLE)) || (which_comm != CHMMR_CONVERSATION && which_comm != SYREEN_CONVERSATION - ))//&& ActivateStarShip (status, CHECK_ALLIANCE) == BAD_GUY)) + ))//&& CheckAlliance (status) == BAD_GUY)) BuildBattle (NPC_PLAYER_NUM); } Modified: trunk/sc2/src/uqm/gameev.c =================================================================== --- trunk/sc2/src/uqm/gameev.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/gameev.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -120,7 +120,7 @@ } break; case SHOFIXTI_RETURN_EVENT: - ActivateStarShip (SHOFIXTI_SHIP, SET_ALLIED); + SetRaceAllied (SHOFIXTI_SHIP, TRUE); GLOBAL (CrewCost) -= 2; /* crew is not an issue anymore */ SET_GAME_STATE (CREW_PURCHASED0, 0); @@ -145,7 +145,7 @@ if (SpathiPtr->actual_strength) { - ActivateStarShip (SPATHI_SHIP, SET_NOT_ALLIED); + SetRaceAllied (SPATHI_SHIP, FALSE); SET_GAME_STATE (SPATHI_SHIELDED_SELVES, 1); SpathiPtr->actual_strength = 0; } @@ -181,7 +181,7 @@ RebelPtr->loc.y = 0; UnlockFleetInfo (&GLOBAL (avail_race_q), hRoyalist); UnlockFleetInfo (&GLOBAL (avail_race_q), hRebel); - ActivateStarShip (YEHAT_REBEL_SHIP, SPHERE_TRACKING); + StartSphereTracking (YEHAT_REBEL_SHIP); break; } case SLYLANDRO_RAMP_UP: @@ -439,7 +439,7 @@ { SET_GAME_STATE (YEHAT_ABSORBED_PKUNK, 1); PkunkPtr->allied_state = DEAD_GUY; - ActivateStarShip (YEHAT_SHIP, SPHERE_TRACKING); + StartSphereTracking (YEHAT_SHIP); } else { @@ -577,7 +577,7 @@ SET_GAME_STATE (THRADD_VISITS, 0); if (ThraddPtr->allied_state == GOOD_GUY) - ActivateStarShip (THRADDASH_SHIP, SET_NOT_ALLIED); + SetRaceAllied (THRADDASH_SHIP, FALSE); } ThraddState = GET_GAME_STATE (THRADD_MISSION); Modified: trunk/sc2/src/uqm/globdata.c =================================================================== --- trunk/sc2/src/uqm/globdata.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/globdata.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -337,7 +337,7 @@ sizeof (GLOBAL_SIS (CommanderName)), GAME_STRING (NAMING_STRING_BASE + 3)); - ActivateStarShip (HUMAN_SHIP, SET_ALLIED); + SetRaceAllied (HUMAN_SHIP, TRUE); CloneShipFragment (HUMAN_SHIP, &GLOBAL (built_ship_q), 0); GLOBAL_SIS (log_x) = UNIVERSE_TO_LOGX (SOL_X); Modified: trunk/sc2/src/uqm/planets/devices.c =================================================================== --- trunk/sc2/src/uqm/planets/devices.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/devices.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -258,7 +258,7 @@ HIPGROUP hGroup; FoundIlwrath = (CurStarDescPtr->Index == ILWRATH_DEFINED) - && ActivateStarShip (ILWRATH_SHIP, SPHERE_TRACKING); + && StartSphereTracking (ILWRATH_SHIP); // In the Ilwrath home system and they are alive? if (!FoundIlwrath && Modified: trunk/sc2/src/uqm/planets/generate/genchmmr.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genchmmr.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/genchmmr.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -107,7 +107,7 @@ } else if (GET_GAME_STATE (SUN_DEVICE_ON_SHIP) && !GET_GAME_STATE (ILWRATH_DECEIVED) - && ActivateStarShip (ILWRATH_SHIP, SPHERE_TRACKING)) + && StartSphereTracking (ILWRATH_SHIP)) { PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); ReinitQueue (&GLOBAL (ip_group_q)); Modified: trunk/sc2/src/uqm/planets/generate/gendru.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/gendru.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/gendru.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -88,7 +88,7 @@ { if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - if (ActivateStarShip (DRUUGE_SHIP, SPHERE_TRACKING)) + if (StartSphereTracking (DRUUGE_SHIP)) { NotifyOthers (DRUUGE_SHIP, IPNL_ALL_CLEAR); PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); Modified: trunk/sc2/src/uqm/planets/generate/genilw.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genilw.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/genilw.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -78,7 +78,7 @@ { if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - if (ActivateStarShip (ILWRATH_SHIP, SPHERE_TRACKING)) + if (StartSphereTracking (ILWRATH_SHIP)) { NotifyOthers (ILWRATH_SHIP, IPNL_ALL_CLEAR); PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); Modified: trunk/sc2/src/uqm/planets/generate/genmyc.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genmyc.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/genmyc.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -89,7 +89,7 @@ { if ((CurStarDescPtr->Index == MYCON_DEFINED || CurStarDescPtr->Index == SUN_DEVICE_DEFINED) - && ActivateStarShip (MYCON_SHIP, SPHERE_TRACKING)) + && StartSphereTracking (MYCON_SHIP)) { if (CurStarDescPtr->Index == MYCON_DEFINED || !GET_GAME_STATE (SUN_DEVICE_UNGUARDED)) Modified: trunk/sc2/src/uqm/planets/generate/genorz.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genorz.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/genorz.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -93,7 +93,7 @@ if ((CurStarDescPtr->Index == ORZ_DEFINED || !GET_GAME_STATE (TAALO_UNPROTECTED)) - && ActivateStarShip (ORZ_SHIP, SPHERE_TRACKING)) + && StartSphereTracking (ORZ_SHIP)) { NotifyOthers (ORZ_SHIP, IPNL_ALL_CLEAR); PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); Modified: trunk/sc2/src/uqm/planets/generate/genpet.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genpet.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/genpet.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -83,14 +83,14 @@ if (matchWorld (solarSys, world, 0, MATCH_PLANET) && (GET_GAME_STATE (UMGAH_ZOMBIE_BLOBBIES) || !GET_GAME_STATE (TALKING_PET) - || ActivateStarShip (UMGAH_SHIP, SPHERE_TRACKING))) + || StartSphereTracking (UMGAH_SHIP))) { NotifyOthers (UMGAH_SHIP, IPNL_ALL_CLEAR); PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); ReinitQueue (&GLOBAL (ip_group_q)); assert (CountLinks (&GLOBAL (npc_built_ship_q)) == 0); - if (ActivateStarShip (UMGAH_SHIP, SPHERE_TRACKING)) + if (StartSphereTracking (UMGAH_SHIP)) { GLOBAL (CurrentActivity) |= START_INTERPLANETARY; SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 7); @@ -129,7 +129,7 @@ // Defeated the zombie fleet. InitCommunication (TALKING_PET_CONVERSATION); } - else if (!(ActivateStarShip (UMGAH_SHIP, SPHERE_TRACKING))) + else if (!(StartSphereTracking (UMGAH_SHIP))) { // The Kohr-Ah have destroyed the Umgah, but the // talking pet survived. Modified: trunk/sc2/src/uqm/planets/generate/genpku.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genpku.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/genpku.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -79,7 +79,7 @@ { if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - if (ActivateStarShip (PKUNK_SHIP, SPHERE_TRACKING)) + if (StartSphereTracking (PKUNK_SHIP)) { NotifyOthers (PKUNK_SHIP, IPNL_ALL_CLEAR); PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); Modified: trunk/sc2/src/uqm/planets/generate/gensam.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/gensam.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/gensam.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -215,9 +215,8 @@ EncounterRace = -1; GLOBAL (CurrentActivity) = IN_LAST_BATTLE | START_ENCOUNTER; if (GET_GAME_STATE (YEHAT_CIVIL_WAR) - && ActivateStarShip (YEHAT_SHIP, SPHERE_TRACKING) - && ActivateStarShip (YEHAT_REBEL_SHIP, - FEASIBILITY_STUDY)) + && StartSphereTracking (YEHAT_SHIP) + && EscortFeasibilityStudy (YEHAT_REBEL_SHIP)) InitCommunication (YEHAT_REBEL_CONVERSATION); } } Modified: trunk/sc2/src/uqm/planets/generate/genspa.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genspa.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/genspa.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -121,7 +121,7 @@ { /* Spathiwa's moon */ if (!GET_GAME_STATE (SPATHI_SHIELDED_SELVES) - && ActivateStarShip (SPATHI_SHIP, SPHERE_TRACKING)) + && StartSphereTracking (SPATHI_SHIP)) { NotifyOthers (SPATHI_SHIP, IPNL_ALL_CLEAR); PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); Modified: trunk/sc2/src/uqm/planets/generate/gensup.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/gensup.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/gensup.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -79,7 +79,7 @@ { if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - if (ActivateStarShip (SUPOX_SHIP, SPHERE_TRACKING)) + if (StartSphereTracking (SUPOX_SHIP)) { NotifyOthers (SUPOX_SHIP, IPNL_ALL_CLEAR); PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); Modified: trunk/sc2/src/uqm/planets/generate/genthrad.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genthrad.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/genthrad.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -96,7 +96,7 @@ { if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - if (ActivateStarShip (THRADDASH_SHIP, SPHERE_TRACKING) + if (StartSphereTracking (THRADDASH_SHIP) && (CurStarDescPtr->Index == THRADD_DEFINED || (!GET_GAME_STATE (HELIX_UNPROTECTED) && (BYTE)(GET_GAME_STATE (THRADD_MISSION) - 1) >= 3))) Modified: trunk/sc2/src/uqm/planets/generate/genutw.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genutw.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/genutw.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -109,7 +109,7 @@ { if ((CurStarDescPtr->Index == UTWIG_DEFINED || !GET_GAME_STATE (UTWIG_HAVE_ULTRON)) - && ActivateStarShip (UTWIG_SHIP, SPHERE_TRACKING)) + && StartSphereTracking (UTWIG_SHIP)) { NotifyOthers (UTWIG_SHIP, IPNL_ALL_CLEAR); PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); @@ -141,7 +141,7 @@ if (CurStarDescPtr->Index == BOMB_DEFINED && !GET_GAME_STATE (BOMB_UNPROTECTED) - && ActivateStarShip (DRUUGE_SHIP, SPHERE_TRACKING)) + && StartSphereTracking (DRUUGE_SHIP)) { COUNT i; Modified: trunk/sc2/src/uqm/planets/generate/genvux.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genvux.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/genvux.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -125,7 +125,7 @@ && (CurStarDescPtr->Index == VUX_DEFINED || (CurStarDescPtr->Index == MAIDENS_DEFINED && !GET_GAME_STATE (ZEX_IS_DEAD)))) - && ActivateStarShip (VUX_SHIP, SPHERE_TRACKING)) + && StartSphereTracking (VUX_SHIP)) { NotifyOthers (VUX_SHIP, IPNL_ALL_CLEAR); PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); Modified: trunk/sc2/src/uqm/planets/generate/genyeh.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genyeh.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/genyeh.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -77,7 +77,7 @@ { if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - if (ActivateStarShip (YEHAT_SHIP, SPHERE_TRACKING)) + if (StartSphereTracking (YEHAT_SHIP)) { NotifyOthers (YEHAT_SHIP, IPNL_ALL_CLEAR); PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); Modified: trunk/sc2/src/uqm/planets/generate/genzoq.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/genzoq.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/planets/generate/genzoq.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -87,7 +87,7 @@ { if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - if (ActivateStarShip (ZOQFOTPIK_SHIP, SPHERE_TRACKING)) + if (StartSphereTracking (ZOQFOTPIK_SHIP)) { PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); ReinitQueue (&GLOBAL (ip_group_q)); Modified: trunk/sc2/src/uqm/races.h =================================================================== --- trunk/sc2/src/uqm/races.h 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/races.h 2011-12-16 21:01:55 UTC (rev 3702) @@ -384,9 +384,9 @@ // Values for FLEET_INFO.allied_state enum { - DEAD_GUY = 0, - GOOD_GUY, - BAD_GUY, + DEAD_GUY = 0, // Race is extinct + GOOD_GUY, // Race is allied with the player + BAD_GUY, // Race is not allied with the player }; static inline FLEET_INFO * Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/shipyard.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -525,7 +525,7 @@ LockMutex (GraphicsLock); } } - if (ActivateStarShip (SHOFIXTI_SHIP, CHECK_ALLIANCE) != GOOD_GUY) + if (CheckAlliance (SHOFIXTI_SHIP) != GOOD_GUY) { SET_GAME_STATE (CREW_PURCHASED0, LOBYTE (crew_bought)); SET_GAME_STATE (CREW_PURCHASED1, HIBYTE (crew_bought)); Modified: trunk/sc2/src/uqm/uqmdebug.c =================================================================== --- trunk/sc2/src/uqm/uqmdebug.c 2011-12-16 17:30:27 UTC (rev 3701) +++ trunk/sc2/src/uqm/uqmdebug.c 2011-12-16 21:01:55 UTC (rev 3702) @@ -85,18 +85,18 @@ // Give the player the ships you can't ally with under normal // conditions. clearEscorts (); - ActivateStarShip (ARILOU_SHIP, 1); - ActivateStarShip (PKUNK_SHIP, 1); - ActivateStarShip (VUX_SHIP, 1); - ActivateStarShip (YEHAT_SHIP, 1); - ActivateStarShip (MELNORME_SHIP, 1); - ActivateStarShip (DRUUGE_SHIP, 1); - ActivateStarShip (ILWRATH_SHIP, 1); - ActivateStarShip (MYCON_SHIP, 1); - ActivateStarShip (SLYLANDRO_SHIP, 1); - ActivateStarShip (UMGAH_SHIP, 1); - ActivateStarShip (URQUAN_SHIP, 1); - ActivateStarShip (BLACK_URQUAN_SHIP, 1); + AddEscortShips (ARILOU_SHIP, 1); + AddEscortShips (PKUNK_SHIP, 1); + AddEscortShips (VUX_SHIP, 1); + AddEscortShips (YEHAT_SHIP, 1); + AddEscortShips (MELNORME_SHIP, 1); + AddEscortShips (DRUUGE_SHIP, 1); + AddEscortShips (ILWRATH_SHIP, 1); + AddEscortShips (MYCON_SHIP, 1); + AddEscortShips (SLYLANDRO_SHIP, 1); + AddEscortShips (UMGAH_SHIP, 1); + AddEscortShips (URQUAN_SHIP, 1); + AddEscortShips (BLACK_URQUAN_SHIP, 1); resetCrewBattle (); resetEnergyBattle (); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-20 20:16:23
|
Revision: 3703 http://sc2.svn.sourceforge.net/sc2/?rev=3703&view=rev Author: Meep-Eep Date: 2011-12-20 20:16:17 +0000 (Tue, 20 Dec 2011) Log Message: ----------- Added a callback function for keys. Also some more comments. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/libs/file/files.c trunk/sc2/src/libs/resource/resinit.c trunk/sc2/src/libs/uio/charhashtable.c trunk/sc2/src/libs/uio/charhashtable.h trunk/sc2/src/libs/uio/gphys.h trunk/sc2/src/libs/uio/hashtable.c trunk/sc2/src/libs/uio/hashtable.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-12-16 21:01:55 UTC (rev 3702) +++ trunk/sc2/ChangeLog 2011-12-20 20:16:17 UTC (rev 3703) @@ -1,4 +1,6 @@ Changes towards version 0.8: +- Added a free callback function for the values of the key-value pairs + in hash tables - SvdB - Annigilate ActivateStarShip() - SvdB - Removed obsolete RESPONSE_TO_REF() - SvdB - Don't require the 'shadow' dir in addon packs, from Alex Modified: trunk/sc2/src/libs/file/files.c =================================================================== --- trunk/sc2/src/libs/file/files.c 2011-12-16 21:01:55 UTC (rev 3702) +++ trunk/sc2/src/libs/file/files.c 2011-12-20 20:16:17 UTC (rev 3703) @@ -94,7 +94,7 @@ buf = HMalloc(BUFSIZE); // This was originally a statically allocated buffer, // but as this function might be run from a thread with - // a small Stack, this is better. + // a small stack, this is better. while (1) { numInBuf = uio_read (src, buf, BUFSIZE); Modified: trunk/sc2/src/libs/resource/resinit.c =================================================================== --- trunk/sc2/src/libs/resource/resinit.c 2011-12-16 21:01:55 UTC (rev 3702) +++ trunk/sc2/src/libs/resource/resinit.c 2011-12-20 20:16:17 UTC (rev 3703) @@ -34,7 +34,8 @@ static RESOURCE_INDEX allocResourceIndex (void) { RESOURCE_INDEX ndx = HMalloc (sizeof (RESOURCE_INDEX_DESC)); - ndx->map = CharHashTable_newHashTable (NULL, NULL, NULL, NULL, 0, 0.85, 0.9); + ndx->map = CharHashTable_newHashTable (NULL, NULL, NULL, NULL, NULL, + 0, 0.85, 0.9); return ndx; } Modified: trunk/sc2/src/libs/uio/charhashtable.c =================================================================== --- trunk/sc2/src/libs/uio/charhashtable.c 2011-12-16 21:01:55 UTC (rev 3702) +++ trunk/sc2/src/libs/uio/charhashtable.c 2011-12-20 20:16:17 UTC (rev 3703) @@ -30,7 +30,7 @@ const char *key1, const char *key2); static inline char *CharHashTable_copy(CharHashTable_HashTable *hashTable, const char *key); -static inline void CharHashTable_free(CharHashTable_HashTable *hashTable, +static inline void CharHashTable_freeKey(CharHashTable_HashTable *hashTable, char *key); #include "hashtable.c" @@ -68,7 +68,7 @@ } static inline void -CharHashTable_free(CharHashTable_HashTable *hashTable, +CharHashTable_freeKey(CharHashTable_HashTable *hashTable, char *key) { (void) *hashTable; uio_free(key); Modified: trunk/sc2/src/libs/uio/charhashtable.h =================================================================== --- trunk/sc2/src/libs/uio/charhashtable.h 2011-12-16 21:01:55 UTC (rev 3702) +++ trunk/sc2/src/libs/uio/charhashtable.h 2011-12-20 20:16:17 UTC (rev 3703) @@ -28,7 +28,9 @@ #define CharHashTable_HASH CharHashTable_hash #define CharHashTable_EQUAL CharHashTable_equal #define CharHashTable_COPY CharHashTable_copy -#define CharHashTable_FREE CharHashTable_free +#define CharHashTable_FREEKEY CharHashTable_freeKey +#define CharHashTable_FREEVALUE(hashTable, key) \ + ((void) (hashTable), (void) (key)) #include "hashtable.h" Modified: trunk/sc2/src/libs/uio/gphys.h =================================================================== --- trunk/sc2/src/libs/uio/gphys.h 2011-12-16 21:01:55 UTC (rev 3702) +++ trunk/sc2/src/libs/uio/gphys.h 2011-12-20 20:16:17 UTC (rev 3703) @@ -33,7 +33,7 @@ #define uio_GPDirEntries_new() \ ((uio_GPDirEntries *) CharHashTable_newHashTable(NULL, NULL, NULL, \ - NULL, 0, 0.85, 0.9)) + NULL, NULL, 0, 0.85, 0.9)) #define uio_GPDirEntries_add(hashTable, name, item) \ CharHashTable_add((CharHashTable_HashTable *) hashTable, name, \ (void *) item) Modified: trunk/sc2/src/libs/uio/hashtable.c =================================================================== --- trunk/sc2/src/libs/uio/hashtable.c 2011-12-16 21:01:55 UTC (rev 3702) +++ trunk/sc2/src/libs/uio/hashtable.c 2011-12-20 20:16:17 UTC (rev 3703) @@ -46,12 +46,14 @@ static inline void HASHTABLE_(freeHashEntry)( HASHTABLE_(HashEntry) *entry); +// Create a new HashTable. HASHTABLE_(HashTable) * HASHTABLE_(newHashTable)( HASHTABLE_(HashFunction) hashFunction, HASHTABLE_(EqualFunction) equalFunction, HASHTABLE_(CopyFunction) copyFunction, - HASHTABLE_(FreeFunction) freeFunction, + HASHTABLE_(FreeKeyFunction) freeKeyFunction, + HASHTABLE_(FreeValueFunction) freeValueFunction, uio_uint32 initialSize, double minFillQuotient, double maxFillQuotient) { @@ -63,7 +65,8 @@ hashTable->hashFunction = hashFunction; hashTable->equalFunction = equalFunction; hashTable->copyFunction = copyFunction; - hashTable->freeFunction = freeFunction; + hashTable->freeKeyFunction = freeKeyFunction; + hashTable->freeValueFunction = freeValueFunction; hashTable->minFillQuotient = minFillQuotient; hashTable->maxFillQuotient = maxFillQuotient; @@ -72,6 +75,7 @@ return hashTable; } +// Add an entry to the HashTable. uio_bool HASHTABLE_(add)(HASHTABLE_(HashTable) *hashTable, const HASHTABLE_(Key) *key, HASHTABLE_(Value) *value) { @@ -104,6 +108,7 @@ return true; } +// Remove an entry with a specified Key from the HashTable. uio_bool HASHTABLE_(remove)(HASHTABLE_(HashTable) *hashTable, const HASHTABLE_(Key) *key) { @@ -122,7 +127,8 @@ entry = &(*entry)->next; } next = (*entry)->next; - HASHTABLE_(FREE)(hashTable, (*entry)->key); + HASHTABLE_(FREEKEY)(hashTable, (*entry)->key); + HASHTABLE_(FREEVALUE)(hashTable, (*entry)->value); HASHTABLE_(freeHashEntry)(*entry); *entry = next; @@ -133,6 +139,7 @@ return true; } +// Find the Value stored for some Key. HASHTABLE_(Value) * HASHTABLE_(find)(HASHTABLE_(HashTable) *hashTable, const HASHTABLE_(Key) *key) { @@ -151,11 +158,13 @@ return NULL; } +// Returns the number of entries in the HashTable. uio_uint32 HASHTABLE_(count)(const HASHTABLE_(HashTable) *hashTable) { return hashTable->numEntries; } +// Auxiliary function to (re)initialise the buckets in the HashTable. static void HASHTABLE_(setup)(HASHTABLE_(HashTable) *hashTable, uio_uint32 initialSize) { if (initialSize < 4) @@ -175,6 +184,7 @@ #endif } +// Resize the buckets in the HashTable. static void HASHTABLE_(resize)(HASHTABLE_(HashTable) *hashTable) { HASHTABLE_(HashEntry) **oldEntries; @@ -224,6 +234,7 @@ return x + 1; } +// Get an iterator to iterate through all the entries in the HashTable. // NB: Iterator should be considered invalid if the HashTable is changed. // TODO: change this (make it thread-safe) // this can be done by only marking items as deleted when @@ -252,21 +263,26 @@ return iterator; } +// Returns true if and only if there are no more entries in the hash table +// for the Iterator to find. int HASHTABLE_(iteratorDone)(const HASHTABLE_(Iterator) *iterator) { return iterator->bucketNr >= iterator->hashTable->size; } +// Get the Key of the entry pointed to by an Iterator. HASHTABLE_(Key) * HASHTABLE_(iteratorKey)(HASHTABLE_(Iterator) *iterator) { return iterator->entry->key; } +// Get the Value of the entry pointed to by an Iterator. HASHTABLE_(Value) * HASHTABLE_(iteratorValue)(HASHTABLE_(Iterator) *iterator) { return iterator->entry->value; } +// Move the Iterator to the next entry in the HashTable. // Should not be called if the iterator is already past the last entry. HASHTABLE_(Iterator) * HASHTABLE_(iteratorNext)(HASHTABLE_(Iterator) *iterator) { @@ -293,16 +309,19 @@ return iterator; } +// Free the Iterator. void HASHTABLE_(freeIterator)(HASHTABLE_(Iterator) *iterator) { uio_free(iterator); } +// Auxiliary function to allocate a HashTable. static inline HASHTABLE_(HashTable) * HASHTABLE_(allocHashTable)(void) { return uio_malloc(sizeof (HASHTABLE_(HashTable))); } +// Auxiliary function to create a HashEntry. static inline HASHTABLE_(HashEntry) * HASHTABLE_(newHashEntry)(uio_uint32 hash, HASHTABLE_(Key) *key, HASHTABLE_(Value) *value, HASHTABLE_(HashEntry) *next) { @@ -316,11 +335,13 @@ return result; } +// Allocate a new HashEntry. static inline HASHTABLE_(HashEntry) * HASHTABLE_(allocHashEntry)(void) { return uio_malloc(sizeof (HASHTABLE_(HashEntry))); } +// Delete the HashTable. void HASHTABLE_(deleteHashTable)(HASHTABLE_(HashTable) *hashTable) { uio_uint32 i; @@ -333,7 +354,8 @@ entry = *bucketPtr; while (entry != NULL) { next = entry->next; - HASHTABLE_(FREE)(hashTable, entry->key); + HASHTABLE_(FREEKEY)(hashTable, entry->key); + HASHTABLE_(FREEVALUE)(hashTable, entry->value); HASHTABLE_(freeHashEntry)(entry); entry = next; i--; @@ -344,6 +366,7 @@ uio_free(hashTable); } +// Auxiliary function to deallocate a HashEntry. static inline void HASHTABLE_(freeHashEntry)(HASHTABLE_(HashEntry) *entry) { uio_free(entry); Modified: trunk/sc2/src/libs/uio/hashtable.h =================================================================== --- trunk/sc2/src/libs/uio/hashtable.h 2011-12-16 21:01:55 UTC (rev 3702) +++ trunk/sc2/src/libs/uio/hashtable.h 2011-12-20 20:16:17 UTC (rev 3703) @@ -39,6 +39,8 @@ // (and typedefs) from the HASHTABLE_ block below. // In the .c file, #define HASHTABLE_INTERNAL, #include the .h file // and hashtable.c (in this order), and add the necessary functions. +// If you do not need to free the Value, you can define HashTable_FREEVALUE +// as a no-op. #ifndef HASHTABLE_ # define HASHTABLE_(identifier) HashTable ## _ ## identifier typedef void HashTable_Key; @@ -49,8 +51,10 @@ (hashTable)->equalFunction(hashKey1, hashKey2) # define HashTable_COPY(hashTable, hashKey) \ (hashTable)->copyFunction(hashKey) -# define HashTable_FREE(hashTable, hashKey) \ - (hashTable)->freeFunction(hashKey) +# define HashTable_FREEKEY(hashTable, hashKey) \ + (hashTable)->freeKeyFunction(hashKey) +# define HashTable_FREEVALUE(hashTable, hashValue) \ + (hashTable)->freeValueFunction(hashKey) #endif @@ -59,8 +63,9 @@ typedef uio_bool (*HASHTABLE_(EqualFunction))(const HASHTABLE_(Key) *, const HASHTABLE_(Key) *); typedef HASHTABLE_(Value) *(*HASHTABLE_(CopyFunction))( - const HASHTABLE_(Value) *); -typedef void (*HASHTABLE_(FreeFunction))(HASHTABLE_(Value) *); + const HASHTABLE_(Key) *); +typedef void (*HASHTABLE_(FreeKeyFunction))(HASHTABLE_(Key) *); +typedef void (*HASHTABLE_(FreeValueFunction))(HASHTABLE_(Value) *); typedef struct HASHTABLE_(HashTable) HASHTABLE_(HashTable); typedef struct HASHTABLE_(HashEntry) HASHTABLE_(HashEntry); @@ -68,9 +73,17 @@ struct HASHTABLE_(HashTable) { HASHTABLE_(HashFunction) hashFunction; + // Function creating a uio_uint32 hash of a key. HASHTABLE_(EqualFunction) equalFunction; + // Function used to compare two keys. HASHTABLE_(CopyFunction) copyFunction; - HASHTABLE_(FreeFunction) freeFunction; + // Function used to copy a key. + HASHTABLE_(FreeKeyFunction) freeKeyFunction; + // Function used to free a key. + HASHTABLE_(FreeValueFunction) freeValueFunction; + // Function used to free a value. Called when an entry is + // removed using the remove function, or for entries + // still in the HashTable when the HashTable is deleted. double minFillQuotient; // How much of half of the hashtable needs to be filled @@ -114,7 +127,9 @@ HASHTABLE_(HashFunction) hashFunction, HASHTABLE_(EqualFunction) equalFunction, HASHTABLE_(CopyFunction) copyFunction, - HASHTABLE_(FreeFunction) freeFunction, uio_uint32 initialSize, + HASHTABLE_(FreeKeyFunction) freeKeyFunction, + HASHTABLE_(FreeValueFunction) freeValueFunction, + uio_uint32 initialSize, double minFillQuotient, double maxFillQuotient); uio_bool HASHTABLE_(add)(HASHTABLE_(HashTable) *hashTable, const HASHTABLE_(Key) *key, HASHTABLE_(Value) *value); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-21 17:43:51
|
Revision: 3706 http://sc2.svn.sourceforge.net/sc2/?rev=3706&view=rev Author: Meep-Eep Date: 2011-12-21 17:43:44 +0000 (Wed, 21 Dec 2011) Log Message: ----------- Remove superfluous semicolons, from Louis Delacroix. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/libs/network/connect/connect.c trunk/sc2/src/libs/network/connect/listen.c trunk/sc2/src/libs/network/connect/resolve.c trunk/sc2/src/uqm/supermelee/netplay/packethandlers.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-12-20 22:15:43 UTC (rev 3705) +++ trunk/sc2/ChangeLog 2011-12-21 17:43:44 UTC (rev 3706) @@ -1,4 +1,5 @@ Changes towards version 0.8: +- Remove superfluous semicolons, from Louis Delacroix - Added a free callback function for the values of the key-value pairs in hash tables - SvdB - Annigilate ActivateStarShip() - SvdB Modified: trunk/sc2/src/libs/network/connect/connect.c =================================================================== --- trunk/sc2/src/libs/network/connect/connect.c 2011-12-20 22:15:43 UTC (rev 3705) +++ trunk/sc2/src/libs/network/connect/connect.c 2011-12-21 17:43:44 UTC (rev 3706) @@ -57,7 +57,7 @@ static ConnectState * ConnectState_alloc(void) { return (ConnectState *) malloc(sizeof (ConnectState)); -}; +} static void ConnectState_free(ConnectState *connectState) { Modified: trunk/sc2/src/libs/network/connect/listen.c =================================================================== --- trunk/sc2/src/libs/network/connect/listen.c 2011-12-20 22:15:43 UTC (rev 3705) +++ trunk/sc2/src/libs/network/connect/listen.c 2011-12-21 17:43:44 UTC (rev 3706) @@ -56,7 +56,7 @@ static ListenState * ListenState_alloc(void) { return (ListenState *) malloc(sizeof (ListenState)); -}; +} static void ListenState_free(ListenState *listenState) { Modified: trunk/sc2/src/libs/network/connect/resolve.c =================================================================== --- trunk/sc2/src/libs/network/connect/resolve.c 2011-12-20 22:15:43 UTC (rev 3705) +++ trunk/sc2/src/libs/network/connect/resolve.c 2011-12-21 17:43:44 UTC (rev 3706) @@ -33,7 +33,7 @@ static ResolveState * ResolveState_new(void) { return (ResolveState *) malloc(sizeof (ResolveState)); -}; +} static void ResolveState_free(ResolveState *resolveState) { Modified: trunk/sc2/src/uqm/supermelee/netplay/packethandlers.h =================================================================== --- trunk/sc2/src/uqm/supermelee/netplay/packethandlers.h 2011-12-20 22:15:43 UTC (rev 3705) +++ trunk/sc2/src/uqm/supermelee/netplay/packethandlers.h 2011-12-21 17:43:44 UTC (rev 3706) @@ -27,7 +27,7 @@ #define DECLARE_PACKETHANDLER(type) \ int PacketHandler_##type(NetConnection *conn, \ - const Packet_##type *packet); + const Packet_##type *packet) DECLARE_PACKETHANDLER(Init); DECLARE_PACKETHANDLER(Ping); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-21 17:59:55
|
Revision: 3708 http://sc2.svn.sourceforge.net/sc2/?rev=3708&view=rev Author: Meep-Eep Date: 2011-12-21 17:59:49 +0000 (Wed, 21 Dec 2011) Log Message: ----------- Fix for a few warnings. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/libs/graphics/tfb_prim.c Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-12-21 17:58:57 UTC (rev 3707) +++ trunk/sc2/ChangeLog 2011-12-21 17:59:49 UTC (rev 3708) @@ -1,5 +1,5 @@ Changes towards version 0.8: -- Remove superfluous semicolons, from Louis Delacroix +- Some cleanups / warnings fixes, from Louis Delacroix - Added a free callback function for the values of the key-value pairs in hash tables - SvdB - Annigilate ActivateStarShip() - SvdB Modified: trunk/sc2/src/libs/graphics/tfb_prim.c =================================================================== --- trunk/sc2/src/libs/graphics/tfb_prim.c 2011-12-21 17:58:57 UTC (rev 3707) +++ trunk/sc2/src/libs/graphics/tfb_prim.c 2011-12-21 17:59:49 UTC (rev 3708) @@ -131,7 +131,7 @@ if (!SrcFramePtr) { log_add (log_Warning, "TFB_Prim_Stamp: Tried to draw a NULL frame" - " (Stamp address = %p)", stmp); + " (Stamp address = %p)", (void *) stmp); return; } img = SrcFramePtr->image; @@ -180,7 +180,7 @@ if (!SrcFramePtr) { log_add (log_Warning, "TFB_Prim_StampFill: Tried to draw a NULL frame" - " (Stamp address = %p)", stmp); + " (Stamp address = %p)", (void *) stmp); return; } img = SrcFramePtr->image; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-21 18:03:51
|
Revision: 3709 http://sc2.svn.sourceforge.net/sc2/?rev=3709&view=rev Author: Meep-Eep Date: 2011-12-21 18:03:45 +0000 (Wed, 21 Dec 2011) Log Message: ----------- Fix memory leak, from louisdx. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/libs/file/dirs.c Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-12-21 17:59:49 UTC (rev 3708) +++ trunk/sc2/ChangeLog 2011-12-21 18:03:45 UTC (rev 3709) @@ -1,4 +1,5 @@ Changes towards version 0.8: +- Fix memory leak in mkdirhier(), from Loius Delacroix - Some cleanups / warnings fixes, from Louis Delacroix - Added a free callback function for the values of the key-value pairs in hash tables - SvdB Modified: trunk/sc2/src/libs/file/dirs.c =================================================================== --- trunk/sc2/src/libs/file/dirs.c 2011-12-21 17:59:49 UTC (rev 3708) +++ trunk/sc2/src/libs/file/dirs.c 2011-12-21 18:03:45 UTC (rev 3709) @@ -142,7 +142,7 @@ if (*pathstart == '\0') { // path exists completely, nothing more to do - return 0; + goto success; } // walk through the path as long as the components exist @@ -177,7 +177,7 @@ } if (*pathend == '\0') - return 0; + goto success; *ptr = '/'; ptr++; @@ -187,7 +187,7 @@ // pathstart is the next non-slash character if (*pathstart == '\0') - return 0; + goto success; } // create all components left @@ -221,6 +221,9 @@ ptr += pathend - pathstart; *ptr = '\0'; } + +success: + HFree (buf); return 0; err: @@ -641,6 +644,7 @@ *destptr = '\0'; } + HFree (buf); return 0; err: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-28 17:52:05
|
Revision: 3711 http://sc2.svn.sourceforge.net/sc2/?rev=3711&view=rev Author: Meep-Eep Date: 2011-12-28 17:51:58 +0000 (Wed, 28 Dec 2011) Log Message: ----------- Fix a few memory leaks, from Louis Delacroix. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/uqm/flash.c trunk/sc2/src/uqm.c Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-12-26 01:35:07 UTC (rev 3710) +++ trunk/sc2/ChangeLog 2011-12-28 17:51:58 UTC (rev 3711) @@ -1,5 +1,5 @@ Changes towards version 0.8: -- Fix memory leak in mkdirhier(), from Loius Delacroix +- Fix several memory leaks, from Loius Delacroix - Some cleanups / warnings fixes, from Louis Delacroix - Added a free callback function for the values of the key-value pairs in hash tables - SvdB Modified: trunk/sc2/src/uqm/flash.c =================================================================== --- trunk/sc2/src/uqm/flash.c 2011-12-26 01:35:07 UTC (rev 3710) +++ trunk/sc2/src/uqm/flash.c 2011-12-28 17:51:58 UTC (rev 3711) @@ -211,6 +211,7 @@ Flash_drawFrame (context, context->original); Flash_clearCache (context); + HFree (context->cache); DestroyDrawable (ReleaseDrawable (context->original)); } Modified: trunk/sc2/src/uqm.c =================================================================== --- trunk/sc2/src/uqm.c 2011-12-26 01:35:07 UTC (rev 3710) +++ trunk/sc2/src/uqm.c 2011-12-28 17:51:58 UTC (rev 3711) @@ -487,6 +487,8 @@ UnInitThreadSystem (); mem_uninit (); } + + HFree (options.addons); return EXIT_SUCCESS; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-29 23:38:44
|
Revision: 3722 http://sc2.svn.sourceforge.net/sc2/?rev=3722&view=rev Author: Meep-Eep Date: 2011-12-29 23:38:38 +0000 (Thu, 29 Dec 2011) Log Message: ----------- Changed SetFlashRect to use the new flash code. This is an intermediate step towards getting rid of the flash thread altogether. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/uqm/menu.c trunk/sc2/src/uqm/sis.c trunk/sc2/src/uqm/sis.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-12-29 22:30:42 UTC (rev 3721) +++ trunk/sc2/ChangeLog 2011-12-29 23:38:38 UTC (rev 3722) @@ -1,4 +1,5 @@ Changes towards version 0.8: +- Changed SetFlashRect() to use the new flash code - SvdB - Added Valgrind suppression file, from Louis Delacroix - Fix several memory leaks, from Loius Delacroix - Some cleanups / warnings fixes, from Louis Delacroix Modified: trunk/sc2/src/uqm/menu.c =================================================================== --- trunk/sc2/src/uqm/menu.c 2011-12-29 22:30:42 UTC (rev 3721) +++ trunk/sc2/src/uqm/menu.c 2011-12-29 23:38:38 UTC (rev 3722) @@ -28,9 +28,6 @@ #include "libs/tasklib.h" #include "libs/log.h" -extern Task flash_task; -extern RECT flash_rect; - static BYTE GetEndMenuState (BYTE BaseState); static BYTE GetBeginMenuState (BYTE BaseState); static BYTE FixMenuState (BYTE BadState); @@ -500,6 +497,7 @@ if (NewState <= end_index - beg_index) s.frame = SetAbsFrameIndex (PlayFrame, beg_index + NewState); + PreUpdateRadarRect (); LockMutex (GraphicsLock); OldContext = SetContext (StatusContext); GetContextClipRect (&r); @@ -600,13 +598,8 @@ } } UnbatchGraphics (); - if (flash_task - && flash_rect.corner.x == RADAR_X - && flash_rect.corner.y == RADAR_Y - && flash_rect.extent.width == RADAR_WIDTH - && flash_rect.extent.height == RADAR_HEIGHT) - SetFlashRect (SFR_MENU_3DO); SetContext (OldContext); UnlockMutex (GraphicsLock); + PostUpdateRadarRect (); } Modified: trunk/sc2/src/uqm/sis.c =================================================================== --- trunk/sc2/src/uqm/sis.c 2011-12-29 22:30:42 UTC (rev 3721) +++ trunk/sc2/src/uqm/sis.c 2011-12-29 23:38:38 UTC (rev 3722) @@ -31,6 +31,7 @@ #include "element.h" #include "setup.h" #include "state.h" +#include "flash.h" #include "libs/graphics/gfx_common.h" #include "libs/tasklib.h" #include "libs/log.h" @@ -1589,248 +1590,118 @@ } -Task flash_task = 0; -RECT flash_rect; -static FRAME flash_screen_frame = 0; - // The original contents of the flash rectangle. -static int flash_changed; -Mutex flash_mutex = 0; +static Task flash_task = 0; +static FlashContext *flashContext = NULL; +static RECT flash_rect; static int flash_rect_func (void *data) { -#define NORMAL_STRENGTH 4 -#define NORMAL_F_STRENGTH 0 -#define CACHE_SIZE 10 - DWORD TimeIn; - const DWORD WaitTime = ONE_SECOND / 16; - SIZE strength; - RECT cached_rect = {{0, 0}, {0, 0}}; - FRAME cached_screen_frame = 0; Task task = (Task)data; - bool cached[CACHE_SIZE]; - STAMP cached_stamp[CACHE_SIZE]; - int i; - // Init cache - for (i = 0; i < CACHE_SIZE; i++) - { - cached[i] = false; - cached_stamp[i].frame = 0; - } - - strength = NORMAL_STRENGTH; - TimeIn = GetTimeCounter (); while (!Task_ReadState(task, TASK_EXIT)) { - CONTEXT OldContext; - - LockMutex (flash_mutex); - if (flash_changed) - { - cached_rect = flash_rect; - if (cached_screen_frame) - DestroyDrawable (ReleaseDrawable (cached_screen_frame)); - flash_changed = 0; - // Wait for the flash_screen_frame to get initialized - FlushGraphics (); - cached_screen_frame = CaptureDrawable ( - CloneFrame (flash_screen_frame)); - UnlockMutex (flash_mutex); - - // Clear the cache. - for (i = 0; i < CACHE_SIZE; i++) - { - cached[i] = false; - if (cached_stamp[i].frame) - DestroyDrawable (ReleaseDrawable (cached_stamp[i].frame)); - cached_stamp[i].frame = 0; - } - } - else - UnlockMutex (flash_mutex); - - if (cached_rect.extent.width) - { - STAMP *pStamp; - -#define MIN_STRENGTH 4 -#define MAX_STRENGTH 6 - strength += 2; - if (strength > MAX_STRENGTH) - strength = MIN_STRENGTH; - if (cached[strength - MIN_STRENGTH]) - pStamp = &cached_stamp[strength - MIN_STRENGTH]; - else - { - pStamp = &cached_stamp[strength - MIN_STRENGTH]; - cached[strength - MIN_STRENGTH] = true; - pStamp->frame = CaptureDrawable ( - CloneFrame (cached_screen_frame)); - pStamp->origin.x = 0; - pStamp->origin.y = 0; - - if (strength != 4) - { // brighten the frame with an additive - DrawMode oldMode; - STAMP s; - int factor; - - s.origin.x = 0; - s.origin.y = 0; - s.frame = cached_screen_frame; - - factor = (strength - MIN_STRENGTH) * DRAW_FACTOR_1 / 4; - - LockMutex (GraphicsLock); - OldContext = SetContext (OffScreenContext); - SetContextFGFrame (pStamp->frame); - SetContextClipRect (NULL); - oldMode = SetContextDrawMode (MAKE_DRAW_MODE ( - DRAW_ADDITIVE, factor)); - DrawStamp (&s); - SetContextDrawMode (oldMode); - SetContext (OldContext); - UnlockMutex (GraphicsLock); - } - } - - LockMutex (GraphicsLock); - OldContext = SetContext (ScreenContext); - SetContextClipRect (&cached_rect); - // flash changed_can't be modified while GraphicSem is held - if (!flash_changed) - DrawStamp (pStamp); - // XXX: Shouldn't we save and restore the original cliprect? - SetContextClipRect (NULL); - SetContext (OldContext); - UnlockMutex (GraphicsLock); - } - FlushGraphics (); - SleepThreadUntil (TimeIn + WaitTime); - TimeIn = GetTimeCounter (); + Flash_process (flashContext); + TimeCount nextTime = Flash_nextTime (flashContext); + SleepThreadUntil (nextTime); } - // Clear cache - { - if (cached_screen_frame) - DestroyDrawable (ReleaseDrawable (cached_screen_frame)); - - for (i = 0; i < CACHE_SIZE; i++) - { - if(cached_stamp[i].frame) - DestroyDrawable (ReleaseDrawable (cached_stamp[i].frame)); - } - } - LockMutex (flash_mutex); - flash_task = 0; - UnlockMutex (flash_mutex); - FinishTask (task); return 0; } +// Pre: the caller holds the GraphicsLock void SetFlashRect (RECT *pRect) { RECT clip_r = {{0, 0}, {0, 0}}; - RECT temp_r, flash_rect1, old_r; - CONTEXT OldContext; - int create_flash = 0; + RECT temp_r; - if (!flash_mutex) - flash_mutex = CreateMutex ("FlashRect Lock", - SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO); - - old_r = flash_rect; - flash_rect1 = flash_rect; - if (pRect != SFR_MENU_3DO && pRect != SFR_MENU_ANY) { + // The caller specified their own flash area, or NULL (stop flashing). GetContextClipRect (&clip_r); - OldContext = SetContext (ScreenContext); } else { - //Don't flash when using the PC menu if (optWhichMenu == OPT_PC && pRect != SFR_MENU_ANY) { - OldContext = SetContext (ScreenContext); + // The player wants PC menus and this flash is not used + // for a PC menu. + // Don't flash. pRect = 0; } else { - OldContext = SetContext (StatusContext); + // The player wants 3DO menus, or the flash is used in both + // 3DO and PC mode. + CONTEXT OldContext = SetContext (StatusContext); GetContextClipRect (&clip_r); pRect = &temp_r; temp_r.corner.x = RADAR_X - clip_r.corner.x; temp_r.corner.y = RADAR_Y - clip_r.corner.y; temp_r.extent.width = RADAR_WIDTH; temp_r.extent.height = RADAR_HEIGHT; - SetContext (ScreenContext); + SetContext (OldContext); } } - if (pRect == 0 || pRect->extent.width == 0) + // Conclude an old flash task. + if (flashContext != NULL) { - // End the flashing. - flash_rect1.extent.width = 0; - if (flash_task) - { - UnlockMutex (GraphicsLock); - ConcludeTask (flash_task); - LockMutex (GraphicsLock); - } + UnlockMutex (GraphicsLock); + ConcludeTask (flash_task); + LockMutex (GraphicsLock); + flash_task = 0; + + Flash_terminate (flashContext); + flashContext = 0; } - else + + // Start a new flash task. + if (pRect != 0 && pRect->extent.width != 0) { - flash_rect1 = *pRect; - flash_rect1.corner.x += clip_r.corner.x; - flash_rect1.corner.y += clip_r.corner.y; - create_flash = 1; + flash_rect = *pRect; + flash_rect.corner.x += clip_r.corner.x; + flash_rect.corner.y += clip_r.corner.y; + + flashContext = Flash_createHighlight (ScreenContext, &flash_rect); + Flash_setMergeFactors(flashContext, 3, 2, 2); + Flash_setSpeed (flashContext, 0, ONE_SECOND / 16, 0, ONE_SECOND / 16); + Flash_setFrameTime (flashContext, ONE_SECOND / 16); + Flash_start (flashContext); + + flash_task = AssignTask (flash_rect_func, 2048, "flash rectangle"); } - - LockMutex (flash_mutex); - flash_rect = flash_rect1; +} - if (old_r.extent.width && !rectsEqual (old_r, flash_rect)) +void +PreUpdateRadarRect (void) { + // XXX: this check doesn't take the ContextClipRect into account, + // as the code above in SetFlashRect does. One is wrong. + // Note that this code came from menu.c originally. + if (flash_task + && flash_rect.corner.x == RADAR_X + && flash_rect.corner.y == RADAR_Y + && flash_rect.extent.width == RADAR_WIDTH + && flash_rect.extent.height == RADAR_HEIGHT) { - // We had a flash rectangle, and now a different one is set. - if (flash_screen_frame) - { - // The screen contents may have changed; we grab a new copy. - STAMP old_s; - old_s.origin.x = old_r.corner.x; - old_s.origin.y = old_r.corner.y; - old_s.frame = flash_screen_frame; - DrawStamp (&old_s); - DestroyDrawable (ReleaseDrawable (flash_screen_frame)); - flash_screen_frame = 0; - } - else - log_add (log_Debug, "Couldn't locate flash_screen_rect"); + Flash_preUpdate(flashContext); } - - if (flash_rect.extent.width) +} + +void +PostUpdateRadarRect (void) { + // XXX: this check doesn't take the ContextClipRect into account, + // as the code above in SetFlashRect does. One is wrong. + // Note that this code came from menu.c originally. + if (flash_task + && flash_rect.corner.x == RADAR_X + && flash_rect.corner.y == RADAR_Y + && flash_rect.extent.width == RADAR_WIDTH + && flash_rect.extent.height == RADAR_HEIGHT) { - // A new flash rectangle is set. - // Copy the original contents of the rectangle from the screen. - if (flash_screen_frame) - DestroyDrawable (ReleaseDrawable (flash_screen_frame)); - flash_screen_frame = - CaptureDrawable (LoadDisplayPixmap (&flash_rect, (FRAME)0)); + Flash_postUpdate(flashContext); } - flash_changed = 1; - UnlockMutex (flash_mutex); - // we create the thread after the LoadDisplayPixmap() - // so there is no race between the FlushGraphics in flash_task - // and the Enqueue in LoadDisplayPixmap() - if (create_flash && flash_task == 0) - { - flash_task = AssignTask (flash_rect_func, 2048, - "flash rectangle"); - } - - SetContext (OldContext); } Modified: trunk/sc2/src/uqm/sis.h =================================================================== --- trunk/sc2/src/uqm/sis.h 2011-12-29 22:30:42 UTC (rev 3721) +++ trunk/sc2/src/uqm/sis.h 2011-12-29 23:38:38 UTC (rev 3722) @@ -182,6 +182,8 @@ extern void DrawSISFrame (void); extern void ClearSISRect (BYTE ClearFlags); extern void SetFlashRect (RECT *pRect); +extern void PreUpdateRadarRect (void); +extern void PostUpdateRadarRect (void); #define SFR_MENU_3DO ((RECT*)~0L) #define SFR_MENU_ANY ((RECT*)~1L) extern void DrawHyperCoords (POINT puniverse); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-30 01:37:28
|
Revision: 3723 http://sc2.svn.sourceforge.net/sc2/?rev=3723&view=rev Author: Meep-Eep Date: 2011-12-30 01:37:21 +0000 (Fri, 30 Dec 2011) Log Message: ----------- Reverting. This one is not ready yet. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/uqm/menu.c trunk/sc2/src/uqm/sis.c trunk/sc2/src/uqm/sis.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-12-29 23:38:38 UTC (rev 3722) +++ trunk/sc2/ChangeLog 2011-12-30 01:37:21 UTC (rev 3723) @@ -1,5 +1,4 @@ Changes towards version 0.8: -- Changed SetFlashRect() to use the new flash code - SvdB - Added Valgrind suppression file, from Louis Delacroix - Fix several memory leaks, from Loius Delacroix - Some cleanups / warnings fixes, from Louis Delacroix Modified: trunk/sc2/src/uqm/menu.c =================================================================== --- trunk/sc2/src/uqm/menu.c 2011-12-29 23:38:38 UTC (rev 3722) +++ trunk/sc2/src/uqm/menu.c 2011-12-30 01:37:21 UTC (rev 3723) @@ -28,6 +28,9 @@ #include "libs/tasklib.h" #include "libs/log.h" +extern Task flash_task; +extern RECT flash_rect; + static BYTE GetEndMenuState (BYTE BaseState); static BYTE GetBeginMenuState (BYTE BaseState); static BYTE FixMenuState (BYTE BadState); @@ -497,7 +500,6 @@ if (NewState <= end_index - beg_index) s.frame = SetAbsFrameIndex (PlayFrame, beg_index + NewState); - PreUpdateRadarRect (); LockMutex (GraphicsLock); OldContext = SetContext (StatusContext); GetContextClipRect (&r); @@ -598,8 +600,13 @@ } } UnbatchGraphics (); + if (flash_task + && flash_rect.corner.x == RADAR_X + && flash_rect.corner.y == RADAR_Y + && flash_rect.extent.width == RADAR_WIDTH + && flash_rect.extent.height == RADAR_HEIGHT) + SetFlashRect (SFR_MENU_3DO); SetContext (OldContext); UnlockMutex (GraphicsLock); - PostUpdateRadarRect (); } Modified: trunk/sc2/src/uqm/sis.c =================================================================== --- trunk/sc2/src/uqm/sis.c 2011-12-29 23:38:38 UTC (rev 3722) +++ trunk/sc2/src/uqm/sis.c 2011-12-30 01:37:21 UTC (rev 3723) @@ -31,7 +31,6 @@ #include "element.h" #include "setup.h" #include "state.h" -#include "flash.h" #include "libs/graphics/gfx_common.h" #include "libs/tasklib.h" #include "libs/log.h" @@ -1590,118 +1589,248 @@ } -static Task flash_task = 0; -static FlashContext *flashContext = NULL; -static RECT flash_rect; +Task flash_task = 0; +RECT flash_rect; +static FRAME flash_screen_frame = 0; + // The original contents of the flash rectangle. +static int flash_changed; +Mutex flash_mutex = 0; static int flash_rect_func (void *data) { +#define NORMAL_STRENGTH 4 +#define NORMAL_F_STRENGTH 0 +#define CACHE_SIZE 10 + DWORD TimeIn; + const DWORD WaitTime = ONE_SECOND / 16; + SIZE strength; + RECT cached_rect = {{0, 0}, {0, 0}}; + FRAME cached_screen_frame = 0; Task task = (Task)data; + bool cached[CACHE_SIZE]; + STAMP cached_stamp[CACHE_SIZE]; + int i; + // Init cache + for (i = 0; i < CACHE_SIZE; i++) + { + cached[i] = false; + cached_stamp[i].frame = 0; + } + + strength = NORMAL_STRENGTH; + TimeIn = GetTimeCounter (); while (!Task_ReadState(task, TASK_EXIT)) { - Flash_process (flashContext); - TimeCount nextTime = Flash_nextTime (flashContext); - SleepThreadUntil (nextTime); + CONTEXT OldContext; + + LockMutex (flash_mutex); + if (flash_changed) + { + cached_rect = flash_rect; + if (cached_screen_frame) + DestroyDrawable (ReleaseDrawable (cached_screen_frame)); + flash_changed = 0; + // Wait for the flash_screen_frame to get initialized + FlushGraphics (); + cached_screen_frame = CaptureDrawable ( + CloneFrame (flash_screen_frame)); + UnlockMutex (flash_mutex); + + // Clear the cache. + for (i = 0; i < CACHE_SIZE; i++) + { + cached[i] = false; + if (cached_stamp[i].frame) + DestroyDrawable (ReleaseDrawable (cached_stamp[i].frame)); + cached_stamp[i].frame = 0; + } + } + else + UnlockMutex (flash_mutex); + + if (cached_rect.extent.width) + { + STAMP *pStamp; + +#define MIN_STRENGTH 4 +#define MAX_STRENGTH 6 + strength += 2; + if (strength > MAX_STRENGTH) + strength = MIN_STRENGTH; + if (cached[strength - MIN_STRENGTH]) + pStamp = &cached_stamp[strength - MIN_STRENGTH]; + else + { + pStamp = &cached_stamp[strength - MIN_STRENGTH]; + cached[strength - MIN_STRENGTH] = true; + pStamp->frame = CaptureDrawable ( + CloneFrame (cached_screen_frame)); + pStamp->origin.x = 0; + pStamp->origin.y = 0; + + if (strength != 4) + { // brighten the frame with an additive + DrawMode oldMode; + STAMP s; + int factor; + + s.origin.x = 0; + s.origin.y = 0; + s.frame = cached_screen_frame; + + factor = (strength - MIN_STRENGTH) * DRAW_FACTOR_1 / 4; + + LockMutex (GraphicsLock); + OldContext = SetContext (OffScreenContext); + SetContextFGFrame (pStamp->frame); + SetContextClipRect (NULL); + oldMode = SetContextDrawMode (MAKE_DRAW_MODE ( + DRAW_ADDITIVE, factor)); + DrawStamp (&s); + SetContextDrawMode (oldMode); + SetContext (OldContext); + UnlockMutex (GraphicsLock); + } + } + + LockMutex (GraphicsLock); + OldContext = SetContext (ScreenContext); + SetContextClipRect (&cached_rect); + // flash changed_can't be modified while GraphicSem is held + if (!flash_changed) + DrawStamp (pStamp); + // XXX: Shouldn't we save and restore the original cliprect? + SetContextClipRect (NULL); + SetContext (OldContext); + UnlockMutex (GraphicsLock); + } + FlushGraphics (); + SleepThreadUntil (TimeIn + WaitTime); + TimeIn = GetTimeCounter (); } + // Clear cache + { + if (cached_screen_frame) + DestroyDrawable (ReleaseDrawable (cached_screen_frame)); + + for (i = 0; i < CACHE_SIZE; i++) + { + if(cached_stamp[i].frame) + DestroyDrawable (ReleaseDrawable (cached_stamp[i].frame)); + } + } + LockMutex (flash_mutex); + flash_task = 0; + UnlockMutex (flash_mutex); + FinishTask (task); return 0; } -// Pre: the caller holds the GraphicsLock void SetFlashRect (RECT *pRect) { RECT clip_r = {{0, 0}, {0, 0}}; - RECT temp_r; + RECT temp_r, flash_rect1, old_r; + CONTEXT OldContext; + int create_flash = 0; + if (!flash_mutex) + flash_mutex = CreateMutex ("FlashRect Lock", + SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO); + + old_r = flash_rect; + flash_rect1 = flash_rect; + if (pRect != SFR_MENU_3DO && pRect != SFR_MENU_ANY) { - // The caller specified their own flash area, or NULL (stop flashing). GetContextClipRect (&clip_r); + OldContext = SetContext (ScreenContext); } else { + //Don't flash when using the PC menu if (optWhichMenu == OPT_PC && pRect != SFR_MENU_ANY) { - // The player wants PC menus and this flash is not used - // for a PC menu. - // Don't flash. + OldContext = SetContext (ScreenContext); pRect = 0; } else { - // The player wants 3DO menus, or the flash is used in both - // 3DO and PC mode. - CONTEXT OldContext = SetContext (StatusContext); + OldContext = SetContext (StatusContext); GetContextClipRect (&clip_r); pRect = &temp_r; temp_r.corner.x = RADAR_X - clip_r.corner.x; temp_r.corner.y = RADAR_Y - clip_r.corner.y; temp_r.extent.width = RADAR_WIDTH; temp_r.extent.height = RADAR_HEIGHT; - SetContext (OldContext); + SetContext (ScreenContext); } } - // Conclude an old flash task. - if (flashContext != NULL) + if (pRect == 0 || pRect->extent.width == 0) { - UnlockMutex (GraphicsLock); - ConcludeTask (flash_task); - LockMutex (GraphicsLock); - flash_task = 0; - - Flash_terminate (flashContext); - flashContext = 0; + // End the flashing. + flash_rect1.extent.width = 0; + if (flash_task) + { + UnlockMutex (GraphicsLock); + ConcludeTask (flash_task); + LockMutex (GraphicsLock); + } } - - // Start a new flash task. - if (pRect != 0 && pRect->extent.width != 0) + else { - flash_rect = *pRect; - flash_rect.corner.x += clip_r.corner.x; - flash_rect.corner.y += clip_r.corner.y; - - flashContext = Flash_createHighlight (ScreenContext, &flash_rect); - Flash_setMergeFactors(flashContext, 3, 2, 2); - Flash_setSpeed (flashContext, 0, ONE_SECOND / 16, 0, ONE_SECOND / 16); - Flash_setFrameTime (flashContext, ONE_SECOND / 16); - Flash_start (flashContext); - - flash_task = AssignTask (flash_rect_func, 2048, "flash rectangle"); + flash_rect1 = *pRect; + flash_rect1.corner.x += clip_r.corner.x; + flash_rect1.corner.y += clip_r.corner.y; + create_flash = 1; } -} + + LockMutex (flash_mutex); + flash_rect = flash_rect1; -void -PreUpdateRadarRect (void) { - // XXX: this check doesn't take the ContextClipRect into account, - // as the code above in SetFlashRect does. One is wrong. - // Note that this code came from menu.c originally. - if (flash_task - && flash_rect.corner.x == RADAR_X - && flash_rect.corner.y == RADAR_Y - && flash_rect.extent.width == RADAR_WIDTH - && flash_rect.extent.height == RADAR_HEIGHT) + if (old_r.extent.width && !rectsEqual (old_r, flash_rect)) { - Flash_preUpdate(flashContext); + // We had a flash rectangle, and now a different one is set. + if (flash_screen_frame) + { + // The screen contents may have changed; we grab a new copy. + STAMP old_s; + old_s.origin.x = old_r.corner.x; + old_s.origin.y = old_r.corner.y; + old_s.frame = flash_screen_frame; + DrawStamp (&old_s); + DestroyDrawable (ReleaseDrawable (flash_screen_frame)); + flash_screen_frame = 0; + } + else + log_add (log_Debug, "Couldn't locate flash_screen_rect"); } -} - -void -PostUpdateRadarRect (void) { - // XXX: this check doesn't take the ContextClipRect into account, - // as the code above in SetFlashRect does. One is wrong. - // Note that this code came from menu.c originally. - if (flash_task - && flash_rect.corner.x == RADAR_X - && flash_rect.corner.y == RADAR_Y - && flash_rect.extent.width == RADAR_WIDTH - && flash_rect.extent.height == RADAR_HEIGHT) + + if (flash_rect.extent.width) { - Flash_postUpdate(flashContext); + // A new flash rectangle is set. + // Copy the original contents of the rectangle from the screen. + if (flash_screen_frame) + DestroyDrawable (ReleaseDrawable (flash_screen_frame)); + flash_screen_frame = + CaptureDrawable (LoadDisplayPixmap (&flash_rect, (FRAME)0)); } + flash_changed = 1; + UnlockMutex (flash_mutex); + // we create the thread after the LoadDisplayPixmap() + // so there is no race between the FlushGraphics in flash_task + // and the Enqueue in LoadDisplayPixmap() + if (create_flash && flash_task == 0) + { + flash_task = AssignTask (flash_rect_func, 2048, + "flash rectangle"); + } + + SetContext (OldContext); } Modified: trunk/sc2/src/uqm/sis.h =================================================================== --- trunk/sc2/src/uqm/sis.h 2011-12-29 23:38:38 UTC (rev 3722) +++ trunk/sc2/src/uqm/sis.h 2011-12-30 01:37:21 UTC (rev 3723) @@ -182,8 +182,6 @@ extern void DrawSISFrame (void); extern void ClearSISRect (BYTE ClearFlags); extern void SetFlashRect (RECT *pRect); -extern void PreUpdateRadarRect (void); -extern void PostUpdateRadarRect (void); #define SFR_MENU_3DO ((RECT*)~0L) #define SFR_MENU_ANY ((RECT*)~1L) extern void DrawHyperCoords (POINT puniverse); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-31 01:39:09
|
Revision: 3724 http://sc2.svn.sourceforge.net/sc2/?rev=3724&view=rev Author: Meep-Eep Date: 2011-12-31 01:39:02 +0000 (Sat, 31 Dec 2011) Log Message: ----------- Some cleaning up of DoModifyShips(). More to come. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/uqm/build.c trunk/sc2/src/uqm/build.h trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-12-30 01:37:21 UTC (rev 3723) +++ trunk/sc2/ChangeLog 2011-12-31 01:39:02 UTC (rev 3724) @@ -1,4 +1,5 @@ Changes towards version 0.8: +- Cleaning up DoModifyShips() - SvdB - Added Valgrind suppression file, from Louis Delacroix - Fix several memory leaks, from Loius Delacroix - Some cleanups / warnings fixes, from Louis Delacroix Modified: trunk/sc2/src/uqm/build.c =================================================================== --- trunk/sc2/src/uqm/build.c 2011-12-30 01:37:21 UTC (rev 3723) +++ trunk/sc2/src/uqm/build.c 2011-12-31 01:39:02 UTC (rev 3724) @@ -68,6 +68,31 @@ return (hStarShip); } +HSHIPFRAG +GetEscortByStarShipIndex (COUNT index) +{ + HSHIPFRAG hStarShip; + HSHIPFRAG hNextShip; + SHIP_FRAGMENT *StarShipPtr; + + for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)); + hStarShip; hStarShip = hNextShip) + { + StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + if (StarShipPtr->index == index) + { + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + break; + } + + hNextShip = _GetSuccLink (StarShipPtr); + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + } + + return hStarShip; +} + /* * Give the player 'count' ships of the specified race, * limited by the number of free slots. Modified: trunk/sc2/src/uqm/build.h =================================================================== --- trunk/sc2/src/uqm/build.h 2011-12-30 01:37:21 UTC (rev 3723) +++ trunk/sc2/src/uqm/build.h 2011-12-31 01:39:02 UTC (rev 3724) @@ -38,6 +38,7 @@ extern HSHIPFRAG CloneShipFragment (COUNT shipIndex, QUEUE *pDstQueue, COUNT crew_level); extern HLINK GetStarShipFromIndex (QUEUE *pShipQ, COUNT Index); +HSHIPFRAG GetEscortByStarShipIndex (COUNT index); extern BYTE NameCaptain (QUEUE *pQueue, SPECIES_ID SpeciesID); /* Possible values for the 'state' argument of Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2011-12-30 01:37:21 UTC (rev 3723) +++ trunk/sc2/src/uqm/shipyard.c 2011-12-31 01:39:02 UTC (rev 3724) @@ -533,6 +533,64 @@ } } +#define MODIFY_CREW_FLAG (1 << 8) +#ifdef WANT_SHIP_SPINS +// Helper function for DoModifyShips(), called when the player presses the +// special button. +// It works both when the cursor is over an escort ship, while not editing +// the crew, and when a new ship is added. +// hStarShip is the ship in the slot under the cursor (or 0 if no such ship). +static BOOLEAN +DMS_SpinShip (MENU_STATE *pMS, HSHIPFRAG hStarShip) +{ + HFLEETINFO hSpinShip = 0; + CONTEXT OldContext; + RECT OldClipRect; + + // No spinning the flagship. + if (HINIBBLE (pMS->CurState) != 0) + return FALSE; + + // We must either be hovering over a used ship slot, or adding a new + // ship to the fleet. + if ((hStarShip == 0) == !(pMS->delta_item & MODIFY_CREW_FLAG)) + return FALSE; + + if (!hStarShip) + { + // Selecting a ship to build. + hSpinShip = GetAvailableRaceFromIndex (LOBYTE (pMS->delta_item)); + if (!hSpinShip) + return FALSE; + } + else + { + // Hovering over an escort ship. + SHIP_FRAGMENT *FragPtr = LockShipFrag ( + &GLOBAL (built_ship_q), hStarShip); + hSpinShip = GetStarShipFromIndex ( + &GLOBAL (avail_race_q), FragPtr->race_id); + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + } + + SetFlashRect (NULL); + + OldContext = SetContext (ScreenContext); + GetContextClipRect (&OldClipRect); + + SpinStarShip (pMS, hSpinShip); + + SetContextClipRect (&OldClipRect); + SetContext (OldContext); + + if (hStarShip) + return TRUE; + + SetFlashRect (SFR_MENU_3DO); + return FALSE; +} +#endif /* WANT_SHIP_SPINS */ + /* in this routine, the least significant byte of pMS->CurState is used * to store the current selected ship index * a special case for the row is hi-nibble == -1 (0xf), which specifies @@ -543,7 +601,6 @@ static BOOLEAN DoModifyShips (MENU_STATE *pMS) { -#define MODIFY_CREW_FLAG (1 << 8) BOOLEAN select, cancel; #ifdef WANT_SHIP_SPINS BOOLEAN special; @@ -611,7 +668,8 @@ else if (dx && !HINIBBLE (NewState)) { NewState = NewState % HANGAR_SHIPS_ROW; - if ((dx += NewState) < 0) + dx += NewState; + if (dx < 0) NewState = (BYTE)(pMS->CurState + (HANGAR_SHIPS_ROW - 1)); else if (dx > HANGAR_SHIPS_ROW - 1) NewState = (BYTE)(pMS->CurState - (HANGAR_SHIPS_ROW - 1)); @@ -626,24 +684,11 @@ || NewState != pMS->CurState || ((pMS->delta_item & MODIFY_CREW_FLAG) && (dx || dy))) { - HSHIPFRAG hStarShip, hNextShip; - SHIP_FRAGMENT *StarShipPtr; + HSHIPFRAG hStarShip; RECT r; - for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)); - hStarShip; hStarShip = hNextShip) - { - StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); + hStarShip = GetEscortByStarShipIndex (pMS->CurState); - if (StarShipPtr->index == pMS->CurState) - { - UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); - break; - } - - hNextShip = _GetSuccLink (StarShipPtr); - UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); - } if ((pMS->delta_item & MODIFY_CREW_FLAG) && (hStarShip)) { SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, @@ -659,49 +704,11 @@ #ifdef WANT_SHIP_SPINS if (special) { - HFLEETINFO hSpinShip = 0; - - if ((special && (((hStarShip == 0 - && HINIBBLE (pMS->CurState) == 0) - && (pMS->delta_item & MODIFY_CREW_FLAG)) - || ((hStarShip != 0 && - HINIBBLE (pMS->CurState) == 0) - && !(pMS->delta_item & MODIFY_CREW_FLAG)))) - && (hStarShip - || (HINIBBLE (pMS->CurState) == 0 - && (hSpinShip = GetAvailableRaceFromIndex ( - LOBYTE (pMS->delta_item)))))) - { - CONTEXT OldContext; - RECT OldClipRect; - - if (!hSpinShip) - { /* Get fleet info from selected escort */ - SHIP_FRAGMENT *FragPtr = LockShipFrag ( - &GLOBAL (built_ship_q), hStarShip); - hSpinShip = GetStarShipFromIndex ( - &GLOBAL (avail_race_q), FragPtr->race_id); - UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); - } - - SetFlashRect (NULL); - - OldContext = SetContext (ScreenContext); - GetContextClipRect (&OldClipRect); - - SpinStarShip (pMS, hSpinShip); - - SetContextClipRect (&OldClipRect); - SetContext (OldContext); - - if (hStarShip) - goto ChangeFlashRect; - - SetFlashRect (SFR_MENU_3DO); - } + if (DMS_SpinShip (pMS, hStarShip)) + goto ChangeFlashRect; } else -#endif +#endif /* WANT_SHIP_SPINS */ if (select || ((pMS->delta_item & MODIFY_CREW_FLAG) && (dx || dy || cancel))) { @@ -800,8 +807,8 @@ if ((pMS->delta_item & MODIFY_CREW_FLAG) && hStarShip != 0) { - StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), - hStarShip); + SHIP_FRAGMENT *StarShipPtr = LockShipFrag ( + &GLOBAL (built_ship_q), hStarShip); if (StarShipPtr->crew_level == 0) { SetFlashRect (NULL); @@ -858,6 +865,7 @@ else if (pMS->delta_item & MODIFY_CREW_FLAG) { SIZE crew_delta, crew_bought; + SHIP_FRAGMENT *StarShipPtr; if (hStarShip) StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-15 20:01:27
|
Revision: 3747 http://sc2.svn.sourceforge.net/sc2/?rev=3747&view=rev Author: Meep-Eep Date: 2012-01-15 20:01:20 +0000 (Sun, 15 Jan 2012) Log Message: ----------- Add C++ support to the build system, from Scott A. Colcord. Modified Paths: -------------- trunk/sc2/Makefile.build trunk/sc2/Makeproject trunk/sc2/build/unix/build.config trunk/sc2/build/unix/build.sh trunk/sc2/build/unix/build_functions trunk/sc2/build/unix/config_proginfo_build trunk/sc2/build/unix/make/buildtools-armv5 trunk/sc2/build/unix/make/buildtools-generic trunk/sc2/build/unix/make/buildtools-winscw trunk/sc2/build.vars.in Modified: trunk/sc2/Makefile.build =================================================================== --- trunk/sc2/Makefile.build 2012-01-14 20:10:11 UTC (rev 3746) +++ trunk/sc2/Makefile.build 2012-01-15 20:01:20 UTC (rev 3747) @@ -42,6 +42,13 @@ fi $(call act,act_mkdep_c,MKDEP ,$@) +$(OBJDIR)%.cpp.d: $(BUILD_ROOT)%.cpp + @DIR=$(dir $@); \ + if [ ! -d $$DIR ]; then \ + mkdir -p "$$DIR"; \ + fi + $(call act,act_mkdep_cxx,MKDEP ,$@) + $(OBJDIR)%.m.d: $(BUILD_ROOT)%.m @DIR=$(dir $@); \ if [ ! -d $$DIR ]; then \ @@ -63,6 +70,13 @@ fi $(call act,act_cc,CC ,$@) +%.cpp.o: + @DIR=$(dir $@); \ + if [ ! -d $$DIR ]; then \ + mkdir -p "$$DIR"; \ + fi + $(call act,act_cxx,CXX ,$@) + %.m.o: @DIR=$(dir $@); \ if [ ! -d $$DIR ]; then \ Modified: trunk/sc2/Makeproject =================================================================== --- trunk/sc2/Makeproject 2012-01-14 20:10:11 UTC (rev 3746) +++ trunk/sc2/Makeproject 2012-01-15 20:01:20 UTC (rev 3747) @@ -17,8 +17,10 @@ ;; esac uqm_CFLAGS="$uqm_CFLAGS -Isrc" +uqm_CXXFLAGS="$uqm_CXXFLAGS -Isrc" if [ "$uqm_HAVE_REGEX" = 0 ]; then uqm_CFLAGS="$uqm_CFLAGS -Isrc/regex" + uqm_CXXFLAGS="$uqm_CXXFLAGS -Isrc/regex" fi # Stuff to install under the directory for libraries, as specified during Modified: trunk/sc2/build/unix/build.config =================================================================== --- trunk/sc2/build/unix/build.config 2012-01-14 20:10:11 UTC (rev 3746) +++ trunk/sc2/build/unix/build.config 2012-01-15 20:01:20 UTC (rev 3747) @@ -10,6 +10,7 @@ { # Some requirements: have_build_tools_language C || exit 1 + have_build_tools_language CXX || exit 1 have_build_tool LINK || exit 1 case "$HOST_SYSTEM" in MINGW32*|cegcc) @@ -108,16 +109,16 @@ nodebug_action() { case "$HOST_SYSTEM" in WINSCW) - CFLAGS="$CFLAGS -O2 -d NDEBUG" + CCOMMONFLAGS="$CCOMMONFLAGS -O2 -d NDEBUG" ;; ARMV5) - CFLAGS="$CFLAGS -O3 -Otime -DNDEBUG" + CCOMMONFLAGS="$CCOMMONFLAGS -O3 -Otime -DNDEBUG" ;; GCCE) - CFLAGS="$CFLAGS -O3 -DNDEBUG" + CCOMMONFLAGS="$CCOMMONFLAGS -O3 -DNDEBUG" ;; *) - CFLAGS="$CFLAGS -O3 -DNDEBUG" + CCOMMONFLAGS="$CCOMMONFLAGS -O3 -DNDEBUG" ;; esac DEBUG=0 @@ -127,13 +128,13 @@ debug_action() { case "$HOST_SYSTEM" in WINSCW) - CFLAGS="$CFLAGS -g -O0 -W all -d DEBUG -d _DEBUG" + CCOMMONFLAGS="$CCOMMONFLAGS -g -O0 -W all -d DEBUG -d _DEBUG" ;; ARMV5|GCCE) - CFLAGS="$CFLAGS -g -O0 -DDEBUG -D_DEBUG" + CCOMMONFLAGS="$CCOMMONFLAGS -g -O0 -DDEBUG -D_DEBUG" ;; *) - CFLAGS="$CFLAGS -g -O0 -W -Wall -DDEBUG" + CCOMMONFLAGS="$CCOMMONFLAGS -g -O0 -W -Wall -DDEBUG" LDFLAGS="$LDFLAGS -O0" ;; esac @@ -144,43 +145,46 @@ strictdebug_action() { case "$HOST_SYSTEM" in WINSCW) - CFLAGS="$CFLAGS -g -O0 -W all -d DEBUG -d _DEBUG" + CCOMMONFLAGS="$CCOMMONFLAGS -g -O0 -W all -d DEBUG -d _DEBUG" ;; ARMV5|GCCE) - CFLAGS="$CFLAGS -g -O0 -DDEBUG -D_DEBUG" + CCOMMONFLAGS="$CCOMMONFLAGS -g -O0 -DDEBUG -D_DEBUG" ;; *) - CFLAGS="$CFLAGS -g -O0 -DDEBUG -W -Wall" -# CFLAGS="$CFLAGS -O1" + CCOMMONFLAGS="$CCOMMONFLAGS -g -O0 -DDEBUG -W -Wall" +# CCOMMONFLAGS="$CCOMMONFLAGS -O1" # This is needed for -Wunitialized with gcc 3.4 - CFLAGS="$CFLAGS -Wbad-function-cast -Wcast-qual -Wmissing-prototypes \ - -Wstrict-prototypes -Wmissing-declarations \ + CCOMMONFLAGS="$CCOMMONFLAGS -Wcast-qual -Wmissing-declarations \ -Wwrite-strings -Wimplicit -Wreturn-type -Wformat \ -Wswitch -Wcomment -Wchar-subscripts \ - -Wparentheses -Wcast-align \ - -Wuninitialized" + -Wparentheses -Wcast-align -Wuninitialized" + CFLAGS="$CFLAGS -Wbad-function-cast -Wmissing-prototypes \ + -Wstrict-prototypes" + # CFLAGS is for flags not valid in C++. CFLAGS="$CFLAGS -Wdeclaration-after-statement" # Until we abandon MSVC 6 -# CFLAGS="$CFLAGS -Waggregate-return" +# CCOMMONFLAGS="$CCOMMONFLAGS -Waggregate-return" # It's not unreasonable to return structs at times. -# CFLAGS="$CFLAGS "-Wpointer-arith" +# CCOMMONFLAGS="$CCOMMONFLAGS "-Wpointer-arith" # Some standard header won't even compile with this on -# CFLAGS="$CFLAGS -Wshadow" +# CCOMMONFLAGS="$CCOMMONFLAGS -Wshadow" # This gives absurd conflicts with standard files, # like from 'y0 and y1' -# CFLAGS="$CFLAGS -Werror" +# CCOMMONFLAGS="$CCOMMONFLAGS -Werror" # We shouldn't do this until we actually nail them # all in the original code. Then we can enforce them # on ourselves. -# CFLAGS="$CFLAGS -pedantic-errors -ansi -trigraphs" # ANSI -# CFLAGS="$CFLAGS -Wnested-externs" +# CCOMMONFLAGS="$CCOMMONFLAGS -pedantic-errors -ansi -trigraphs" # ANSI +# CCOMMONFLAGS="$CCOMMONFLAGS -Wnested-externs" # We know they're in the code, and though we'd like to # get rid of them, they're not bugs. -# CFLAGS="$CFLAGS -Winline" +# CCOMMONFLAGS="$CCOMMONFLAGS -Winline" # This gives too many warnings which we can do nothing # about, obscuring legitimate warnings. CFLAGS=`echo $CFLAGS` - # Remove all the unnecessary spaces from $CFLAGS, + CXXFLAGS=`echo $CXXFLAGS` + CCOMMONFLAGS=`echo $CCOMMONFLAGS` + # Remove all the unnecessary spaces from the flags vars # for more readable messages. LDFLAGS="$LDFLAGS -O0" ;; @@ -202,7 +206,7 @@ CHOICE_graphics_OPTION_pure_TITLE="Don't include OpenGL graphics support" CHOICE_graphics_OPTION_pure_ACTION='graphics_pure_action' graphics_pure_action() { - CFLAGS="$CFLAGS -DGFXMODULE_SDL" + CCOMMONFLAGS="$CCOMMONFLAGS -DGFXMODULE_SDL" GFXMODULE=sdl HAVE_OPENGL=0 } @@ -210,7 +214,7 @@ CHOICE_graphics_OPTION_opengl_ACTION='graphics_opengl_action' CHOICE_graphics_OPTION_opengl_PRECOND="have_library opengl" graphics_opengl_action() { - CFLAGS="$CFLAGS -DGFXMODULE_SDL -DHAVE_OPENGL" + CCOMMONFLAGS="$CCOMMONFLAGS -DGFXMODULE_SDL -DHAVE_OPENGL" GFXMODULE=sdl HAVE_OPENGL=1 use_library opengl @@ -228,7 +232,7 @@ CHOICE_sound_OPTION_openal_PRECOND="have_library openal" CHOICE_sound_OPTION_openal_ACTION=sound_openal_action sound_openal_action() { - CFLAGS="$CFLAGS -DHAVE_OPENAL" + CCOMMONFLAGS="$CCOMMONFLAGS -DHAVE_OPENAL" SOUNDMODULE=openal use_library openal } @@ -249,14 +253,14 @@ CHOICE_ovcodec_OPTION_tremor_PRECOND="have_library tremor" CHOICE_ovcodec_OPTION_tremor_ACTION=ovcodec_tremor_action ovcodec_tremor_action() { - CFLAGS="$CFLAGS -DOVCODEC_TREMOR" + CCOMMONFLAGS="$CCOMMONFLAGS -DOVCODEC_TREMOR" OGGVORBIS=tremor use_library tremor } CHOICE_ovcodec_OPTION_none_TITLE="No Ogg Vorbis support" CHOICE_ovcodec_OPTION_none_ACTION=ovcodec_none_action ovcodec_none_action() { - CFLAGS="$CFLAGS -DOVCODEC_NONE" + CCOMMONFLAGS="$CCOMMONFLAGS -DOVCODEC_NONE" OGGVORBIS=none } CHOICE_ovcodec_DEFAULT=standard @@ -266,7 +270,7 @@ CHOICE_mikmod_OPTION_internal_TITLE="Included libmikmod" CHOICE_mikmod_OPTION_internal_ACTION=mikmod_internal_action mikmod_internal_action() { - CFLAGS="$CFLAGS -DUSE_INTERNAL_MIKMOD" + CCOMMONFLAGS="$CCOMMONFLAGS -DUSE_INTERNAL_MIKMOD" USE_INTERNAL_MIKMOD=1 } CHOICE_mikmod_OPTION_external_TITLE="System libmikmod" @@ -285,7 +289,7 @@ # TODO: Check whether SDL has joystick support. CHOICE_joystick_OPTION_enabled_ACTION=joystick_enabled_action joystick_enabled_action() { - CFLAGS="$CFLAGS -DHAVE_JOYSTICK" + CCOMMONFLAGS="$CCOMMONFLAGS -DHAVE_JOYSTICK" } CHOICE_joystick_OPTION_disabled_TITLE="disabled" case "$HOST_SYSTEM" in @@ -309,7 +313,7 @@ CHOICE_netplay_OPTION_full_PRECOND="have_library netlibs" CHOICE_netplay_OPTION_full_ACTION=netplay_full_action netplay_full_action() { - CFLAGS="$CFLAGS -DNETPLAY=NETPLAY_FULL" + CCOMMONFLAGS="$CCOMMONFLAGS -DNETPLAY=NETPLAY_FULL" if [ -n "$MACRO_WIN32" ]; then LDFLAGS="$LDFLAGS -lws2_32" fi @@ -320,7 +324,7 @@ CHOICE_netplay_OPTION_ipv4_PRECOND="have_library netlibs" CHOICE_netplay_OPTION_ipv4_ACTION=netplay_ipv4_action netplay_ipv4_action() { - CFLAGS="$CFLAGS -DNETPLAY=NETPLAY_IPV4" + CCOMMONFLAGS="$CCOMMONFLAGS -DNETPLAY=NETPLAY_IPV4" NETPLAY="IPV4" use_library netlibs } @@ -333,7 +337,7 @@ CHOICE_ioformat_OPTION_stdio_zip_PRECOND="have_library zlib" CHOICE_ioformat_OPTION_stdio_zip_ACTION="ioformat_stdio_zip_action" ioformat_stdio_zip_action() { - CFLAGS="$CFLAGS -DHAVE_ZIP=1" + CCOMMONFLAGS="$CCOMMONFLAGS -DHAVE_ZIP=1" USE_ZIP_IO=1 use_library zlib } @@ -344,7 +348,7 @@ CHOICE_accel_OPTION_asm_TITLE="Platform acceleration (asm, etc.)" CHOICE_accel_OPTION_asm_ACTION="accel_asm_action" accel_asm_action() { - CFLAGS="$CFLAGS -DUSE_PLATFORM_ACCEL" + CCOMMONFLAGS="$CCOMMONFLAGS -DUSE_PLATFORM_ACCEL" USE_PLATFORM_ACCEL=1 } CHOICE_accel_OPTION_plainc_TITLE="Only plain C code" @@ -359,14 +363,14 @@ CHOICE_threadlib_OPTION_sdl_TITLE="SDL-controlled thread library" CHOICE_threadlib_OPTION_sdl_ACTION="threadlib_sdl_action" threadlib_sdl_action() { - CFLAGS="$CFLAGS -DTHREADLIB_SDL" + CCOMMONFLAGS="$CCOMMONFLAGS -DTHREADLIB_SDL" THREADLIB="SDL" } CHOICE_threadlib_OPTION_pthread_TITLE="Pthread thread library" CHOICE_threadlib_OPTION_pthread_PRECOND="have_library pthread" CHOICE_threadlib_OPTION_pthread_ACTION="threadlib_pthread_action" threadlib_pthread_action() { - CFLAGS="$CFLAGS -DTHREADLIB_PTHREAD" + CCOMMONFLAGS="$CCOMMONFLAGS -DTHREADLIB_PTHREAD" THREADLIB="PTHREAD" use_library pthread } @@ -419,8 +423,17 @@ # Set the content dir CONTENTDIR="${INSTALL_SHAREDIR}uqm/content" - CFLAGS="$CFLAGS -I\"$BUILD_WORK\"" + CCOMMONFLAGS="$CCOMMONFLAGS -I\"$BUILD_WORK\"" + # Set C++ only flags + # These allow use of C++ without the standard library + CXXFLAGS="$CXXFLAGS -fno-rtti -fno-exceptions -nostdinc++" + + # At this point, all the compiler flags must be set. + CFLAGS="$CFLAGS $CCOMMONFLAGS" + CXXFLAGS="$CXXFLAGS $CCOMMONFLAGS" + CCOMMONFLAGS="" + # Export the HAVE_ symbols to config_unix.h, using config_unix.h.in # as template (or config_win.h/config_win.h.in). SUBSTITUTE_VARS="$HAVE_SYMBOLS CONTENTDIR" @@ -435,8 +448,9 @@ substitute_vars SUBSTITUTE_VARS SUBSTITUTE_FILES src "$BUILD_WORK" # Make build.vars from build.vars.in, substituting variables. - SUBSTITUTE_VARS="BUILD_SYSTEM HOST_SYSTEM CFLAGS LDFLAGS LINK \ + SUBSTITUTE_VARS="BUILD_SYSTEM HOST_SYSTEM CFLAGS CXXFLAGS LDFLAGS LINK \ PREPROC_C MKDEP_C COMPILE_C \ + PREPROC_CXX MKDEP_CXX COMPILE_CXX \ PREPROC_OBJC MKDEP_OBJC COMPILE_OBJC \ MAKE ECHON SED DEBUG JOYSTICK NETPLAY \ OGGVORBIS SOUNDMODULE USE_INTERNAL_MIKMOD \ Modified: trunk/sc2/build/unix/build.sh =================================================================== --- trunk/sc2/build/unix/build.sh 2012-01-14 20:10:11 UTC (rev 3746) +++ trunk/sc2/build/unix/build.sh 2012-01-15 20:01:20 UTC (rev 3747) @@ -83,8 +83,8 @@ fi BUILD_PROJECT="$TARGET" export TARGET BUILD_PROJECT ECHON -export PREPROC_C MKDEP_C COMPILE_C PREPROC_OBJC MKDEP_OBJC COMPILE_OBJC LINK -export "${BUILD_PROJECT}_CFLAGS" "${BUILD_PROJECT}_LDFLAGS" +export PREPROC_C MKDEP_C COMPILE_C PREPROC_CXX MKDEP_CXX COMPILE_CXX PREPROC_OBJC MKDEP_OBJC COMPILE_OBJC LINK +export "${BUILD_PROJECT}_CFLAGS" "${BUILD_PROJECT}_CXXFLAGS" "${BUILD_PROJECT}_LDFLAGS" # Add trailing / from objs dir eval ${BUILD_PROJECT}_OBJS=\${${BUILD_PROJECT}_OBJS%/}/ Modified: trunk/sc2/build/unix/build_functions =================================================================== --- trunk/sc2/build/unix/build_functions 2012-01-14 20:10:11 UTC (rev 3746) +++ trunk/sc2/build/unix/build_functions 2012-01-15 20:01:20 UTC (rev 3747) @@ -104,9 +104,10 @@ # Compile the lot. # With the depend info set up, we can leave everything to make. build_compile() { - local CFLAGS LDFLAGS TARGET_FILE DEPEND_FILE OBJDIR + local CFLAGS CXXFLAGS LDFLAGS TARGET_FILE DEPEND_FILE OBJDIR eval CFLAGS="\${${BUILD_PROJECT}_CFLAGS}" + eval CXXFLAGS="\${${BUILD_PROJECT}_CXXFLAGS}" eval LDFLAGS="\${${BUILD_PROJECT}_LDFLAGS}" eval OBJDIR=\""\$BUILD_WORK/\${${BUILD_PROJECT}_OBJS}"\" eval TARGET_FILE=\""\$BUILD_WORK/\${${BUILD_PROJECT}_NAME}"\" @@ -114,7 +115,7 @@ eval "${TARGET}_pre_build" - CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS \ + CFLAGS=$CFLAGS CXXFLAGS=$CXXFLAGS LDFLAGS=$LDFLAGS \ OBJDIR=$OBJDIR \ BUILD_ROOT= \ TARGET_FILE=$TARGET_FILE DEPEND_FILE=$DEPEND_FILE \ Modified: trunk/sc2/build/unix/config_proginfo_build =================================================================== --- trunk/sc2/build/unix/config_proginfo_build 2012-01-14 20:10:11 UTC (rev 3746) +++ trunk/sc2/build/unix/config_proginfo_build 2012-01-15 20:01:20 UTC (rev 3747) @@ -26,6 +26,9 @@ # CFLAGS SYSTEM_BUILD_CFLAGS="" +# CXXFLAGS +SYSTEM_BUILD_CXXFLAGS="" + # LDFLAGS SYSTEM_BUILD_LDFLAGS="" @@ -33,6 +36,9 @@ BUILDTOOL_PREPROC_C_NAME="C preprocessor" BUILDTOOL_MKDEP_C_NAME="C dependency generator" BUILDTOOL_COMPILE_C_NAME="C compiler" +BUILDTOOL_PREPROC_CXX_NAME="C++ preprocessor" +BUILDTOOL_MKDEP_CXX_NAME="C++ dependency generator" +BUILDTOOL_COMPILE_CXX_NAME="C++ compiler" BUILDTOOL_PREPROC_OBJC_NAME="Objective-C preprocessor" BUILDTOOL_MKDEP_OBJC_NAME="Objective-C dependency generator" BUILDTOOL_COMPILE_OBJC_NAME="Objective-C compiler" @@ -48,6 +54,15 @@ BUILDTOOL_COMPILE_C_COMMAND="\$PROG_gcc_FILE -c $EXTRA_PLATFORM_GCC_FLAGS_COMPILE_C" BUILDTOOL_COMPILE_C_DEPEND='gcc' + BUILDTOOL_PREPROC_CXX_COMMAND="\$PROG_gcc_FILE -E $EXTRA_PLATFORM_GCC_FLAGS_PREPROC_CXX" + BUILDTOOL_PREPROC_CXX_DEPEND='gcc' + + BUILDTOOL_MKDEP_CXX_COMMAND="\$PROG_gcc_FILE -MM $EXTRA_PLATFORM_GCC_FLAGS_MKDEP_CXX" + BUILDTOOL_MKDEP_CXX_DEPEND='gcc' + + BUILDTOOL_COMPILE_CXX_COMMAND="\$PROG_gcc_FILE -c $EXTRA_PLATFORM_GCC_FLAGS_COMPILE_CXX" + BUILDTOOL_COMPILE_CXX_DEPEND='gcc' + BUILDTOOL_PREPROC_OBJC_COMMAND="\$PROG_gcc_FILE -E $EXTRA_PLATFORM_GCC_FLAGS_PREPROC_OBJC" BUILDTOOL_PREPROC_OBJC_DEPEND='gcc' @@ -63,6 +78,7 @@ case "$HOST_SYSTEM" in Darwin) EXTRA_PLATFORM_GCC_FLAGS_COMPILE_C='-mmacosx-version-min=10.4 -arch i386' + EXTRA_PLATFORM_GCC_FLAGS_COMPILE_CXX='-mmacosx-version-min=10.4 -arch i386' EXTRA_PLATFORM_GCC_FLAGS_COMPILE_OBJC='-mmacosx-version-min=10.4 -arch i386' EXTRA_PLATFORM_GCC_FLAGS_LINK='-mmacosx-version-min=10.4 -arch i386' useGccBuildTools @@ -80,6 +96,15 @@ BUILDTOOL_COMPILE_C_COMMAND="\$PROG_mwccsym2_FILE -c $EXTRA_WINSCW_FLAGS_COMPILE" BUILDTOOL_COMPILE_C_DEPEND='mwccsym2' + BUILDTOOL_PREPROC_CXX_COMMAND="\$PROG_mwccsym2_FILE -E $EXTRA_WINSCW_FLAGS_COMPILE" + BUILDTOOL_PREPROC_CXX_DEPEND='mwccsym2' + + BUILDTOOL_MKDEP_CXX_COMMAND="\$PROG_mwccsym2_FILE -MM -ext .o -gccdep $EXTRA_WINSCW_FLAGS_COMPILE" + BUILDTOOL_MKDEP_CXX_DEPEND='mwccsym2' + + BUILDTOOL_COMPILE_CXX_COMMAND="\$PROG_mwccsym2_FILE -c $EXTRA_WINSCW_FLAGS_COMPILE" + BUILDTOOL_COMPILE_CXX_DEPEND='mwccsym2' + BUILDTOOL_PREPROC_OBJC_COMMAND="\$PROG_mwccsym2_FILE -E" BUILDTOOL_PREPROC_OBJC_DEPEND='mwccsym2' @@ -99,12 +124,21 @@ BUILDTOOL_PREPROC_C_COMMAND="\$PROG_armcc_FILE -E $EXTRA_ARMV5_FLAGS_COMPILE" BUILDTOOL_PREPROC_C_DEPEND='armcc' - BUILDTOOL_MKDEP_C_COMMAND="\$PROG_armcc_FILE -MM --unix_depend_format $EXTRA_ARMV5_FLAGS_COMPILE" + BUILDTOOL_MKDEP_C_COMMAND="\$PROG_armcc_FILE -MM $EXTRA_ARMV5_FLAGS_COMPILE" BUILDTOOL_MKDEP_C_DEPEND='armcc' BUILDTOOL_COMPILE_C_COMMAND="\$PROG_armcc_FILE -c $EXTRA_ARMV5_FLAGS_COMPILE" BUILDTOOL_COMPILE_C_DEPEND='armcc' + BUILDTOOL_PREPROC_CXX_COMMAND="\$PROG_armcc_FILE -E $EXTRA_ARMV5_FLAGS_COMPILE" + BUILDTOOL_PREPROC_CXX_DEPEND='armcc' + + BUILDTOOL_MKDEP_CXX_COMMAND="\$PROG_armcc_FILE -MM $EXTRA_ARMV5_FLAGS_COMPILE" + BUILDTOOL_MKDEP_CXX_DEPEND='armcc' + + BUILDTOOL_COMPILE_CXX_COMMAND="\$PROG_armcc_FILE -c $EXTRA_ARMV5_FLAGS_COMPILE" + BUILDTOOL_COMPILE_CXX_DEPEND='armcc' + BUILDTOOL_PREPROC_OBJC_COMMAND="\$PROG_armcc_FILE -E" BUILDTOOL_PREPROC_OBJC_DEPEND='armcc' @@ -130,6 +164,15 @@ BUILDTOOL_COMPILE_C_COMMAND="\$PROG_gcce_FILE -c $EXTRA_GCCE_FLAGS_COMPILE" BUILDTOOL_COMPILE_C_DEPEND='gcce' + BUILDTOOL_PREPROC_CXX_COMMAND="\$PROG_gcce_FILE -E $EXTRA_GCCE_FLAGS_COMPILE" + BUILDTOOL_PREPROC_CXX_DEPEND='gcce' + + BUILDTOOL_MKDEP_CXX_COMMAND="\$PROG_gcce_FILE -MM $EXTRA_GCCE_FLAGS_COMPILE" + BUILDTOOL_MKDEP_CXX_DEPEND='gcce' + + BUILDTOOL_COMPILE_CXX_COMMAND="\$PROG_gcce_FILE -c $EXTRA_GCCE_FLAGS_COMPILE" + BUILDTOOL_COMPILE_CXX_DEPEND='gcce' + BUILDTOOL_PREPROC_OBJC_COMMAND="\$PROG_gcce_FILE -E" BUILDTOOL_PREPROC_OBJC_DEPEND='gcce' @@ -155,6 +198,15 @@ BUILDTOOL_COMPILE_C_COMMAND="\$PROG_mingw_gcc_FILE -c $EXTRA_CYGWIN_FLAGS_COMPILE" BUILDTOOL_COMPILE_C_DEPEND='mingw_gcc' + BUILDTOOL_PREPROC_CXX_COMMAND="\$PROG_mingw_gcc_FILE -E $EXTRA_CYGWIN_FLAGS_COMPILE" + BUILDTOOL_PREPROC_CXX_DEPEND='mingw_gcc' + + BUILDTOOL_MKDEP_CXX_COMMAND="\$PROG_mingw_gcc_FILE -MM $EXTRA_CYGWIN_FLAGS_COMPILE" + BUILDTOOL_MKDEP_CXX_DEPEND='mingw_gcc' + + BUILDTOOL_COMPILE_CXX_COMMAND="\$PROG_mingw_gcc_FILE -c $EXTRA_CYGWIN_FLAGS_COMPILE" + BUILDTOOL_COMPILE_CXX_DEPEND='mingw_gcc' + BUILDTOOL_PREPROC_OBJC_COMMAND="\$PROG_mingw_gcc_FILE -E" BUILDTOOL_PREPROC_OBJC_DEPEND='mingw_gcc' Modified: trunk/sc2/build/unix/make/buildtools-armv5 =================================================================== --- trunk/sc2/build/unix/make/buildtools-armv5 2012-01-14 20:10:11 UTC (rev 3746) +++ trunk/sc2/build/unix/make/buildtools-armv5 2012-01-15 20:01:20 UTC (rev 3747) @@ -7,6 +7,10 @@ $(MKDEP_C) $(CFLAGS) -o "$(@D)/$(<F).o" "$<" --depend "$@" endef +define act_mkdep_cxx + $(MKDEP_CXX) $(CXXFLAGS) -o "$(@D)/$(<F).o" "$<" --depend "$@" +endef + define act_link $(LINK) --create "$@" $^ $(LDFLAGS) endef Modified: trunk/sc2/build/unix/make/buildtools-generic =================================================================== --- trunk/sc2/build/unix/make/buildtools-generic 2012-01-14 20:10:11 UTC (rev 3746) +++ trunk/sc2/build/unix/make/buildtools-generic 2012-01-15 20:01:20 UTC (rev 3747) @@ -6,6 +6,10 @@ $(MKDEP_C) $(CFLAGS) "$<" -MT "$(@D)/$(<F).o" -MF "$@" endef +define act_mkdep_cxx + $(MKDEP_CXX) $(CXXFLAGS) "$<" -MT "$(@D)/$(<F).o" -MF "$@" +endef + define act_mkdep_m $(MKDEP_OBJC) $(CFLAGS) "$<" -MT "$(@D)/$(<F).o" -MF "$@" endef @@ -18,6 +22,10 @@ $(COMPILE_C) -o "$@" $(CFLAGS) "$<" endef +define act_cxx + $(COMPILE_CXX) -o "$@" $(CXXFLAGS) "$<" +endef + define act_objcc $(COMPILE_OBJC) -o "$@" $(CFLAGS) "$<" endef Modified: trunk/sc2/build/unix/make/buildtools-winscw =================================================================== --- trunk/sc2/build/unix/make/buildtools-winscw 2012-01-14 20:10:11 UTC (rev 3746) +++ trunk/sc2/build/unix/make/buildtools-winscw 2012-01-15 20:01:20 UTC (rev 3747) @@ -10,3 +10,10 @@ @rm -f "$@.tmp" endef +define act_mkdep_cxx + $(MKDEP_C) $(CXXFLAGS) "$<" -o "$@.tmp" + @echo -n "$(@D)/" > $@ + @cat "$@.tmp" >> $@ + @rm -f "$@.tmp" +endef + Modified: trunk/sc2/build.vars.in =================================================================== --- trunk/sc2/build.vars.in 2012-01-14 20:10:11 UTC (rev 3746) +++ trunk/sc2/build.vars.in 2012-01-15 20:01:20 UTC (rev 3747) @@ -20,6 +20,9 @@ PREPROC_C='@PREPROC_C@' MKDEP_C='@MKDEP_C@' COMPILE_C='@COMPILE_C@' +PREPROC_CXX='@PREPROC_CXX@' +MKDEP_CXX='@MKDEP_CXX@' +COMPILE_CXX='@COMPILE_CXX@' PREPROC_OBJC='@PREPROC_OBJC@' MKDEP_OBJC='@MKDEP_OBJC@' COMPILE_OBJC='@COMPILE_OBJC@' @@ -30,6 +33,7 @@ REZ='@REZ@' WINDRES='@WINDRES@' uqm_CFLAGS='@CFLAGS@' +uqm_CXXFLAGS='@CXXFLAGS@' uqm_LDFLAGS='@LDFLAGS@' uqm_INSTALL_BINDIR='@INSTALL_BINDIR@' uqm_INSTALL_LIBDIR='@INSTALL_LIBDIR@' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-23 20:14:52
|
Revision: 3749 http://sc2.svn.sourceforge.net/sc2/?rev=3749&view=rev Author: Meep-Eep Date: 2012-01-23 20:14:45 +0000 (Mon, 23 Jan 2012) Log Message: ----------- Switch SetFlashRect() to the new flash code, as the next step towards getting rid of threads. Also some small cleanups. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/uqm/flash.c trunk/sc2/src/uqm/gameopt.c trunk/sc2/src/uqm/menu.c trunk/sc2/src/uqm/outfit.c trunk/sc2/src/uqm/planets/roster.c trunk/sc2/src/uqm/shipyard.c trunk/sc2/src/uqm/sis.c trunk/sc2/src/uqm/sis.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2012-01-15 20:37:31 UTC (rev 3748) +++ trunk/sc2/ChangeLog 2012-01-23 20:14:45 UTC (rev 3749) @@ -1,4 +1,6 @@ Changes towards version 0.8: +- Switch SetFlashRect() to the new flash code -- SvdB +- Add C++ support to the build system, from Scott A. Colcord - Cleaning up DoModifyShips() - SvdB - Added Valgrind suppression file, from Louis Delacroix - Fix several memory leaks, from Loius Delacroix Modified: trunk/sc2/src/uqm/flash.c =================================================================== --- trunk/sc2/src/uqm/flash.c 2012-01-15 20:37:31 UTC (rev 3748) +++ trunk/sc2/src/uqm/flash.c 2012-01-23 20:14:45 UTC (rev 3749) @@ -18,6 +18,12 @@ // areas, drawing directly to the screen, using a cache, are // currently in use. +// NOTE: +// - If you change the properties of the original CONTEXT, specifically the +// dimensions and origin, you'll need to call Flash_preUpdate() before and +// Flash_postUpdate() after that change. Note that this may change which +// part of the screen is flashing. + // TODO: // - During a few frames during the sequence, the frame to be displayed // is equal to a frame which was supplied as a parameter to the flash @@ -472,7 +478,8 @@ } } -// Call before you update the graphics in the currently flashing area. +// Call before you update the graphics in the currently flashing area, +// or before you change the dimensions or origin of the graphics context. void Flash_preUpdate (FlashContext *context) { @@ -483,7 +490,8 @@ } } -// Call after you update the graphics in the currently flashing area. +// Call after you update the graphics in the currently flashing area, +// or after you change the dimensions or origin of the graphics context. void Flash_postUpdate (FlashContext *context) { @@ -803,5 +811,3 @@ Flash_drawCachedFrame (context, numer, denom); } - - Modified: trunk/sc2/src/uqm/gameopt.c =================================================================== --- trunk/sc2/src/uqm/gameopt.c 2012-01-15 20:37:31 UTC (rev 3748) +++ trunk/sc2/src/uqm/gameopt.c 2012-01-23 20:14:45 UTC (rev 3749) @@ -176,6 +176,26 @@ #define DDSHS_EDIT 1 #define DDSHS_BLOCKCUR 2 +static const RECT captainNameRect = { + /* .corner = */ { + /* .x = */ 3, + /* .y = */ 10 + }, /* .extent = */ { + /* .width = */ SHIP_NAME_WIDTH - 2, + /* .height = */ SHIP_NAME_HEIGHT + } +}; +static const RECT shipNameRect = { + /* .corner = */ { + /* .x = */ 2, + /* .y = */ 20 + }, /* .extent = */ { + /* .width = */ SHIP_NAME_WIDTH, + /* .height = */ SHIP_NAME_HEIGHT + } +}; + + static BOOLEAN DrawNameString (bool nameCaptain, UNICODE *Str, COUNT CursorPos, COUNT state) @@ -185,20 +205,11 @@ Color BackGround, ForeGround; FONT Font; - LockMutex (GraphicsLock); - { - r.corner.x = 2; - r.extent.width = SHIP_NAME_WIDTH; - r.extent.height = SHIP_NAME_HEIGHT; - - SetContext (StatusContext); if (nameCaptain) { // Naming the captain Font = TinyFont; - r.corner.y = 10; - ++r.corner.x; - r.extent.width -= 2; + r = captainNameRect; lf.baseline.x = r.corner.x + (r.extent.width >> 1) - 1; BackGround = BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09); @@ -207,7 +218,7 @@ else { // Naming the flagship Font = StarConFont; - r.corner.y = 20; + r = shipNameRect; lf.baseline.x = r.corner.x + (r.extent.width >> 1); BackGround = BUILD_COLOR (MAKE_RGB15 (0x0F, 0x00, 0x00), 0x2D); @@ -218,6 +229,8 @@ lf.align = ALIGN_CENTER; } + LockMutex (GraphicsLock); + SetContext (StatusContext); SetContextFont (Font); lf.pStr = Str; lf.CharCount = (COUNT)~0; @@ -244,6 +257,10 @@ // disallow the change return (FALSE); } + + UnlockMutex (GraphicsLock); + PreUpdateFlashRect (); + LockMutex (GraphicsLock); SetContextForeGroundColor (BackGround); DrawFilledRectangle (&r); @@ -281,8 +298,8 @@ SetContextForeGroundColor (ForeGround); font_DrawText (&lf); - - SetFlashRect (&r); + + PostUpdateFlashRectLocked (); } UnlockMutex (GraphicsLock); @@ -309,7 +326,7 @@ UNICODE *Setting; LockMutex (GraphicsLock); - SetFlashRect (NULL); + SetFlashRect (nameCaptain ? &captainNameRect : &shipNameRect); UnlockMutex (GraphicsLock); DrawNameString (nameCaptain, buf, 0, DDSHS_EDIT); Modified: trunk/sc2/src/uqm/menu.c =================================================================== --- trunk/sc2/src/uqm/menu.c 2012-01-15 20:37:31 UTC (rev 3748) +++ trunk/sc2/src/uqm/menu.c 2012-01-23 20:14:45 UTC (rev 3749) @@ -28,9 +28,6 @@ #include "libs/tasklib.h" #include "libs/log.h" -extern Task flash_task; -extern RECT flash_rect; - static BYTE GetEndMenuState (BYTE BaseState); static BYTE GetBeginMenuState (BYTE BaseState); static BYTE FixMenuState (BYTE BadState); @@ -500,6 +497,7 @@ if (NewState <= end_index - beg_index) s.frame = SetAbsFrameIndex (PlayFrame, beg_index + NewState); + PreUpdateFlashRect (); LockMutex (GraphicsLock); OldContext = SetContext (StatusContext); GetContextClipRect (&r); @@ -600,13 +598,8 @@ } } UnbatchGraphics (); - if (flash_task - && flash_rect.corner.x == RADAR_X - && flash_rect.corner.y == RADAR_Y - && flash_rect.extent.width == RADAR_WIDTH - && flash_rect.extent.height == RADAR_HEIGHT) - SetFlashRect (SFR_MENU_3DO); SetContext (OldContext); UnlockMutex (GraphicsLock); + PostUpdateFlashRect (); } Modified: trunk/sc2/src/uqm/outfit.c =================================================================== --- trunk/sc2/src/uqm/outfit.c 2012-01-15 20:37:31 UTC (rev 3748) +++ trunk/sc2/src/uqm/outfit.c 2012-01-23 20:14:45 UTC (rev 3749) @@ -448,9 +448,9 @@ if (NewItem != pMS->CurState) { pMS->CurState = NewItem; + PreUpdateFlashRect (); DrawModuleStrings (pMS, NewItem); - // flash with PC menus too - SetFlashRect (SFR_MENU_ANY); + PostUpdateFlashRect (); } } else if (NewItem != pMS->delta_item || NewState != pMS->CurState) @@ -573,7 +573,9 @@ SetContextBackGroundColor (BLACK_COLOR)); DrawFilledRectangle (&r); } + PreUpdateFlashRect (); DeltaSISGauges (0, FUEL_TANK_SCALE, -GLOBAL (FuelCost)); + PostUpdateFlashRect (); SetContext (StatusContext); GetGaugeRect (&r, FALSE); SetFlashRect (&r); @@ -590,7 +592,9 @@ SetContext (SpaceContext); if (GLOBAL_SIS (FuelOnBoard)) { + PreUpdateFlashRect (); DeltaSISGauges (0, -FUEL_TANK_SCALE, GLOBAL (FuelCost)); + PostUpdateFlashRect (); if (GLOBAL_SIS (FuelOnBoard) % FUEL_VOLUME_PER_ROW == 0 && GLOBAL_SIS (FuelOnBoard) >= FUEL_RESERVE) { Modified: trunk/sc2/src/uqm/planets/roster.c =================================================================== --- trunk/sc2/src/uqm/planets/roster.c 2012-01-15 20:37:31 UTC (rev 3748) +++ trunk/sc2/src/uqm/planets/roster.c 2012-01-23 20:14:45 UTC (rev 3749) @@ -198,7 +198,9 @@ StarShipPtr->crew_level, TemplatePtr->crew_level); + PreUpdateFlashRect (); DrawStatusMessage (buf); + PostUpdateFlashRect (); DeltaSISGauges (-crew_delta, 0, 0); if (crew_delta) { Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2012-01-15 20:37:31 UTC (rev 3748) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-23 20:14:45 UTC (rev 3749) @@ -219,8 +219,7 @@ r.corner = s.origin; r.extent.width = RADAR_WIDTH; r.extent.height = RADAR_HEIGHT; - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x00), 0x00)); + SetContextForeGroundColor (BLACK_COLOR); DrawFilledRectangle (&r); if (NewRaceItem != (BYTE)~0) { @@ -232,19 +231,22 @@ hStarShip = GetAvailableRaceFromIndex (NewRaceItem); NewRaceItem = GetIndexFromStarShip (&GLOBAL (avail_race_q), hStarShip); + + // Draw the ship name, above the ship image. s.frame = SetAbsFrameIndex (pMS->ModuleFrame, 3 + NewRaceItem); - // Ship name, above the ship image. DrawStamp (&s); + + // Draw the ship image. FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip); s.frame = FleetPtr->melee_icon; - // Ship image. UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip); - t.baseline.x = s.origin.x + RADAR_WIDTH - 2; t.baseline.y = s.origin.y + RADAR_HEIGHT - 2; s.origin.x += (RADAR_WIDTH >> 1); s.origin.y += (RADAR_HEIGHT >> 1); DrawStamp (&s); + + // Print the ship cost. t.align = ALIGN_RIGHT; t.CharCount = (COUNT)~0; t.pStr = buf; @@ -257,8 +259,6 @@ UnbatchGraphics (); SetContext (OldContext); - // Flash the ship purchase menu even when optMenu == OPT_PC - SetFlashRect (SFR_MENU_ANY); UnlockMutex (GraphicsLock); } @@ -266,6 +266,10 @@ #define SHIP_WIN_HEIGHT (SHIP_WIN_WIDTH + 6) #define SHIP_WIN_FRAMES ((SHIP_WIN_WIDTH >> 1) + 1) +// Print the crew count of an escort ship on top of its (already drawn) +// image, either as '30' (full), '28/30' (partially full), or 'SCRAP' +// (empty). +// pRect is the rectangle of the ship image. static void ShowShipCrew (SHIP_FRAGMENT *StarShipPtr, const RECT *pRect) { @@ -274,20 +278,21 @@ UNICODE buf[80]; HFLEETINFO hTemplate; FLEET_INFO *TemplatePtr; + COUNT maxCrewLevel; hTemplate = GetStarShipFromIndex (&GLOBAL (avail_race_q), StarShipPtr->race_id); TemplatePtr = LockFleetInfo (&GLOBAL (avail_race_q), hTemplate); - if (StarShipPtr->crew_level >= TemplatePtr->crew_level) + maxCrewLevel = TemplatePtr->crew_level; + UnlockFleetInfo (&GLOBAL (avail_race_q), hTemplate); + + if (StarShipPtr->crew_level >= maxCrewLevel) sprintf (buf, "%u", StarShipPtr->crew_level); else if (StarShipPtr->crew_level == 0) // XXX: "SCRAP" needs to be moved to starcon.txt utf8StringCopy (buf, sizeof (buf), "SCRAP"); else - sprintf (buf, "%u/%u", - StarShipPtr->crew_level, - TemplatePtr->crew_level); - UnlockFleetInfo (&GLOBAL (avail_race_q), hTemplate); + sprintf (buf, "%u/%u", StarShipPtr->crew_level, maxCrewLevel); r = *pRect; t.baseline.x = r.corner.x + (r.extent.width >> 1); @@ -313,14 +318,17 @@ ShowCombatShip (MENU_STATE *pMS, COUNT which_window, SHIP_FRAGMENT *YankedStarShipPtr) { - COUNT i, num_ships; + COUNT i; + COUNT num_ships; HSHIPFRAG hStarShip, hNextShip; SHIP_FRAGMENT *StarShipPtr; struct { SHIP_FRAGMENT *StarShipPtr; POINT finished_s; - STAMP ship_s, lfdoor_s, rtdoor_s; + STAMP ship_s; + STAMP lfdoor_s; + STAMP rtdoor_s; } ship_win_info[MAX_BUILT_SHIPS], *pship_win_info; num_ships = 1; @@ -388,6 +396,10 @@ hNextShip = _GetSuccLink (StarShipPtr); pship_win_info->StarShipPtr = StarShipPtr; + // XXX BUG: this looks wrong according to the original + // semantics of LockShipFrag(): StarShipPtr is not valid + // anymore after UnlockShipFrag() is called, but it is + // used thereafter. pship_win_info->lfdoor_s.origin.x = -1; pship_win_info->rtdoor_s.origin.x = 1; @@ -496,6 +508,7 @@ } } +// Pre: GraphicsLock is unlocked. static void CrewTransaction (SIZE crew_delta) { @@ -519,10 +532,7 @@ && crew_bought - crew_delta < CREW_EXPENSE_THRESHOLD) { GLOBAL (CrewCost) += 2; - - UnlockMutex (GraphicsLock); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); - LockMutex (GraphicsLock); } } else @@ -531,10 +541,7 @@ && crew_bought - crew_delta >= CREW_EXPENSE_THRESHOLD) { GLOBAL (CrewCost) -= 2; - - UnlockMutex (GraphicsLock); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); - LockMutex (GraphicsLock); } } if (CheckAlliance (SHOFIXTI_SHIP) != GOOD_GUY) @@ -739,8 +746,14 @@ return 0; } + // Draw a crew member. DrawPoint (&r.corner); + + // Update the crew counter and RU. Note that the crew counter is + // flashing. + PreUpdateFlashRectLocked (); DeltaSISGauges (1, 0, -GLOBAL (CrewCost)); + PostUpdateFlashRectLocked (); return 1; } @@ -765,9 +778,14 @@ GET_GAME_STATE (CREW_PURCHASED0), GET_GAME_STATE (CREW_PURCHASED1)); + // Update the crew counter and RU. Note that the crew counter is + // flashing. + PreUpdateFlashRectLocked (); DeltaSISGauges (-1, 0, GLOBAL (CrewCost) - (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); + PostUpdateFlashRectLocked (); + // Remove the pixel representing the crew member. GetCPodCapacity (&r.corner); SetContextForeGroundColor (BLACK_COLOR); DrawPoint (&r.corner); @@ -824,8 +842,11 @@ } ++StarShipPtr->crew_level; + + PreUpdateFlashRectLocked (); DMS_GetEscortShipRect (&r, StarShipPtr->index); ShowShipCrew (StarShipPtr, &r); + PostUpdateFlashRectLocked (); return 1; } @@ -867,8 +888,10 @@ PlayMenuSound (MENU_SOUND_FAILURE); } + PreUpdateFlashRectLocked (); DMS_GetEscortShipRect (&r, StarShipPtr->index); ShowShipCrew (StarShipPtr, &r); + PostUpdateFlashRectLocked (); return crew_delta; } @@ -880,6 +903,7 @@ // selected. // 'dy' is -1 if the 'up' button was pressed, or '1' if the down button was // pressed. +// Pre: caller holds the GraphicsLock static void DMS_ModifyCrew (MENU_STATE *pMS, HSHIPFRAG hStarShip, SBYTE dy) { @@ -936,12 +960,15 @@ pMS->delta_item &= MODIFY_CREW_FLAG; } + UnlockMutex (GraphicsLock); CrewTransaction (crew_delta); + LockMutex (GraphicsLock); } // Helper function for DoModifyShips(), called when the player presses the // select button when the cursor is over an empty escort ship slot. // Try to add the currently selected ship as an escort ship. +// Pre: caller does not hold the GraphicsLock static void DMS_TryAddEscortShip (MENU_STATE *pMS) { @@ -1000,7 +1027,7 @@ // Cancel selecting an escort ship. pMS->delta_item &= ~MODIFY_CREW_FLAG; LockMutex (GraphicsLock); - SetFlashRect (SFR_MENU_3DO); + SetFlashRect (NULL); UnlockMutex (GraphicsLock); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); LockMutex (GraphicsLock); @@ -1032,7 +1059,9 @@ if (currentShip != LOBYTE (pMS->delta_item)) { + PreUpdateFlashRect (); DrawRaceStrings (pMS, currentShip); + PostUpdateFlashRect (); pMS->delta_item = currentShip | MODIFY_CREW_FLAG; } } @@ -1041,6 +1070,7 @@ // Helper function for DoModifyShips(), called when the player presses // 'select' or 'cancel' after selling all the crew. +// Pre: caller holds the GraphicsLock static void DMS_ScrapEscortShip (MENU_STATE *pMS, HSHIPFRAG hStarShip) { @@ -1108,6 +1138,7 @@ // Helper function for DoModifyShips(), called every time DoModifyShip() is // called when we are in crew editing mode. +// Pre: Caller holds the GraphicsLock static void DMS_EditCrewMode (MENU_STATE *pMS, HSHIPFRAG hStarShip, BOOLEAN select, BOOLEAN cancel, SBYTE dy) @@ -1132,9 +1163,7 @@ } pMS->delta_item &= ~MODIFY_CREW_FLAG; - LockMutex (GraphicsLock); DMS_SetMode (pMS, DMS_Mode_navigate); - UnlockMutex (GraphicsLock); } else if (dy) { @@ -1146,7 +1175,7 @@ // Helper function for DoModifyShips(), called every time DoModifyShip() is // called when we are in the mode where you can select a ship or empty slot. -void +static void DMS_NavigateShipSlots (MENU_STATE *pMS, BOOLEAN special, BOOLEAN select, BOOLEAN cancel, SBYTE dx, SBYTE dy) { Modified: trunk/sc2/src/uqm/sis.c =================================================================== --- trunk/sc2/src/uqm/sis.c 2012-01-15 20:37:31 UTC (rev 3748) +++ trunk/sc2/src/uqm/sis.c 2012-01-23 20:14:45 UTC (rev 3749) @@ -31,6 +31,7 @@ #include "element.h" #include "setup.h" #include "state.h" +#include "flash.h" #include "libs/graphics/gfx_common.h" #include "libs/tasklib.h" #include "libs/log.h" @@ -1589,248 +1590,173 @@ } -Task flash_task = 0; -RECT flash_rect; -static FRAME flash_screen_frame = 0; - // The original contents of the flash rectangle. -static int flash_changed; -Mutex flash_mutex = 0; +static Task flash_task = 0; +static FlashContext *flashContext = NULL; +static RECT flash_rect; +static Mutex flash_mutex = 0; static int flash_rect_func (void *data) { -#define NORMAL_STRENGTH 4 -#define NORMAL_F_STRENGTH 0 -#define CACHE_SIZE 10 - DWORD TimeIn; - const DWORD WaitTime = ONE_SECOND / 16; - SIZE strength; - RECT cached_rect = {{0, 0}, {0, 0}}; - FRAME cached_screen_frame = 0; Task task = (Task)data; - bool cached[CACHE_SIZE]; - STAMP cached_stamp[CACHE_SIZE]; - int i; - // Init cache - for (i = 0; i < CACHE_SIZE; i++) - { - cached[i] = false; - cached_stamp[i].frame = 0; - } - - strength = NORMAL_STRENGTH; - TimeIn = GetTimeCounter (); while (!Task_ReadState(task, TASK_EXIT)) { - CONTEXT OldContext; - + TimeCount nextTime; LockMutex (flash_mutex); - if (flash_changed) - { - cached_rect = flash_rect; - if (cached_screen_frame) - DestroyDrawable (ReleaseDrawable (cached_screen_frame)); - flash_changed = 0; - // Wait for the flash_screen_frame to get initialized - FlushGraphics (); - cached_screen_frame = CaptureDrawable ( - CloneFrame (flash_screen_frame)); - UnlockMutex (flash_mutex); - - // Clear the cache. - for (i = 0; i < CACHE_SIZE; i++) - { - cached[i] = false; - if (cached_stamp[i].frame) - DestroyDrawable (ReleaseDrawable (cached_stamp[i].frame)); - cached_stamp[i].frame = 0; - } - } - else - UnlockMutex (flash_mutex); - - if (cached_rect.extent.width) - { - STAMP *pStamp; - -#define MIN_STRENGTH 4 -#define MAX_STRENGTH 6 - strength += 2; - if (strength > MAX_STRENGTH) - strength = MIN_STRENGTH; - if (cached[strength - MIN_STRENGTH]) - pStamp = &cached_stamp[strength - MIN_STRENGTH]; - else - { - pStamp = &cached_stamp[strength - MIN_STRENGTH]; - cached[strength - MIN_STRENGTH] = true; - pStamp->frame = CaptureDrawable ( - CloneFrame (cached_screen_frame)); - pStamp->origin.x = 0; - pStamp->origin.y = 0; - - if (strength != 4) - { // brighten the frame with an additive - DrawMode oldMode; - STAMP s; - int factor; - - s.origin.x = 0; - s.origin.y = 0; - s.frame = cached_screen_frame; - - factor = (strength - MIN_STRENGTH) * DRAW_FACTOR_1 / 4; - - LockMutex (GraphicsLock); - OldContext = SetContext (OffScreenContext); - SetContextFGFrame (pStamp->frame); - SetContextClipRect (NULL); - oldMode = SetContextDrawMode (MAKE_DRAW_MODE ( - DRAW_ADDITIVE, factor)); - DrawStamp (&s); - SetContextDrawMode (oldMode); - SetContext (OldContext); - UnlockMutex (GraphicsLock); - } - } - - LockMutex (GraphicsLock); - OldContext = SetContext (ScreenContext); - SetContextClipRect (&cached_rect); - // flash changed_can't be modified while GraphicSem is held - if (!flash_changed) - DrawStamp (pStamp); - // XXX: Shouldn't we save and restore the original cliprect? - SetContextClipRect (NULL); - SetContext (OldContext); - UnlockMutex (GraphicsLock); - } - FlushGraphics (); - SleepThreadUntil (TimeIn + WaitTime); - TimeIn = GetTimeCounter (); + Flash_process (flashContext); + nextTime = Flash_nextTime (flashContext); + UnlockMutex (flash_mutex); + SleepThreadUntil (nextTime); } - // Clear cache - { - if (cached_screen_frame) - DestroyDrawable (ReleaseDrawable (cached_screen_frame)); - - for (i = 0; i < CACHE_SIZE; i++) - { - if(cached_stamp[i].frame) - DestroyDrawable (ReleaseDrawable (cached_stamp[i].frame)); - } - } - LockMutex (flash_mutex); - flash_task = 0; - UnlockMutex (flash_mutex); - FinishTask (task); return 0; } +// Pre: the caller holds the GraphicsLock void -SetFlashRect (RECT *pRect) +SetFlashRect (const RECT *pRect) { RECT clip_r = {{0, 0}, {0, 0}}; - RECT temp_r, flash_rect1, old_r; - CONTEXT OldContext; - int create_flash = 0; - + RECT temp_r; + if (!flash_mutex) flash_mutex = CreateMutex ("FlashRect Lock", SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO); - old_r = flash_rect; - flash_rect1 = flash_rect; - if (pRect != SFR_MENU_3DO && pRect != SFR_MENU_ANY) { + // The caller specified their own flash area, or NULL (stop flashing). GetContextClipRect (&clip_r); - OldContext = SetContext (ScreenContext); } else { - //Don't flash when using the PC menu if (optWhichMenu == OPT_PC && pRect != SFR_MENU_ANY) { - OldContext = SetContext (ScreenContext); + // The player wants PC menus and this flash is not used + // for a PC menu. + // Don't flash. pRect = 0; } else { - OldContext = SetContext (StatusContext); + // The player wants 3DO menus, or the flash is used in both + // 3DO and PC mode. + CONTEXT OldContext = SetContext (StatusContext); GetContextClipRect (&clip_r); pRect = &temp_r; temp_r.corner.x = RADAR_X - clip_r.corner.x; temp_r.corner.y = RADAR_Y - clip_r.corner.y; temp_r.extent.width = RADAR_WIDTH; temp_r.extent.height = RADAR_HEIGHT; - SetContext (ScreenContext); + SetContext (OldContext); } } - if (pRect == 0 || pRect->extent.width == 0) + // Conclude an old flash task. + if (flashContext != NULL) { - // End the flashing. - flash_rect1.extent.width = 0; - if (flash_task) - { - UnlockMutex (GraphicsLock); - ConcludeTask (flash_task); - LockMutex (GraphicsLock); - } + UnlockMutex (GraphicsLock); + ConcludeTask (flash_task); + LockMutex (GraphicsLock); + flash_task = 0; + + Flash_terminate (flashContext); + flashContext = 0; } - else + + // Start a new flash task. + if (pRect != 0 && pRect->extent.width != 0) { - flash_rect1 = *pRect; - flash_rect1.corner.x += clip_r.corner.x; - flash_rect1.corner.y += clip_r.corner.y; - create_flash = 1; + flash_rect = *pRect; + flash_rect.corner.x += clip_r.corner.x; + flash_rect.corner.y += clip_r.corner.y; + + flashContext = Flash_createHighlight (ScreenContext, &flash_rect); + Flash_setMergeFactors(flashContext, 3, 2, 2); + Flash_setSpeed (flashContext, 0, ONE_SECOND / 16, 0, ONE_SECOND / 16); + Flash_setFrameTime (flashContext, ONE_SECOND / 16); + Flash_start (flashContext); + + flash_task = AssignTask (flash_rect_func, 2048, "flash rectangle"); } - - LockMutex (flash_mutex); - flash_rect = flash_rect1; +} - if (old_r.extent.width && !rectsEqual (old_r, flash_rect)) +// Sleep while calling the flash rectangle update when necessary. +void +FlashRectSleepUntil (TimeCount wakeTime) +{ + while (GetTimeCounter() < wakeTime) { - // We had a flash rectangle, and now a different one is set. - if (flash_screen_frame) - { - // The screen contents may have changed; we grab a new copy. - STAMP old_s; - old_s.origin.x = old_r.corner.x; - old_s.origin.y = old_r.corner.y; - old_s.frame = flash_screen_frame; - DrawStamp (&old_s); - DestroyDrawable (ReleaseDrawable (flash_screen_frame)); - flash_screen_frame = 0; - } - else - log_add (log_Debug, "Couldn't locate flash_screen_rect"); + TimeCount flashNextTime = Flash_nextTime (flashContext); + TimeCount nextTime = (flashNextTime < wakeTime) ? + flashNextTime : wakeTime; + SleepThreadUntil (nextTime); + if (nextTime == flashNextTime) + Flash_process (flashContext); } - - if (flash_rect.extent.width) +} + +COUNT updateFlashRectRecursion = 0; +// XXX This is necessary at least because DMS_AddEscortShip() calls +// DrawRaceStrings() in an UpdateFlashRect block, which calls +// ClearSISRect(), which calls DrawMenuStateStrings(), which starts its own +// UpdateFlashRect block. This should probably be cleaned up. + +// GraphicsLock must be unlocked. +void +PreUpdateFlashRect (void) +{ + if (flash_task) { - // A new flash rectangle is set. - // Copy the original contents of the rectangle from the screen. - if (flash_screen_frame) - DestroyDrawable (ReleaseDrawable (flash_screen_frame)); - flash_screen_frame = - CaptureDrawable (LoadDisplayPixmap (&flash_rect, (FRAME)0)); + updateFlashRectRecursion++; + if (updateFlashRectRecursion > 1) + return; + + LockMutex (flash_mutex); + Flash_pause (flashContext); + // We need to actually pause, as the flash update function + // is called from another thread. + Flash_preUpdate (flashContext); + UnlockMutex (flash_mutex); } - flash_changed = 1; - UnlockMutex (flash_mutex); - // we create the thread after the LoadDisplayPixmap() - // so there is no race between the FlushGraphics in flash_task - // and the Enqueue in LoadDisplayPixmap() - if (create_flash && flash_task == 0) +} + +// GraphicsLock must be unlocked. +void +PostUpdateFlashRect (void) +{ + if (flash_task) { - flash_task = AssignTask (flash_rect_func, 2048, - "flash rectangle"); + updateFlashRectRecursion--; + if (updateFlashRectRecursion > 0) + return; + + LockMutex (flash_mutex); + Flash_postUpdate (flashContext); + Flash_continue (flashContext); + UnlockMutex (flash_mutex); } +} - SetContext (OldContext); +// Because the situation occurs a lot where the GraphicsLock is already +// locked, we add this function. +void +PreUpdateFlashRectLocked (void) +{ + UnlockMutex (GraphicsLock); + PreUpdateFlashRect (); + LockMutex (GraphicsLock); } +// Because the situation occurs a lot where the GraphicsLock is already +// locked, we add this function. +void +PostUpdateFlashRectLocked (void) +{ + UnlockMutex (GraphicsLock); + PostUpdateFlashRect (); + LockMutex (GraphicsLock); +} + Modified: trunk/sc2/src/uqm/sis.h =================================================================== --- trunk/sc2/src/uqm/sis.h 2012-01-15 20:37:31 UTC (rev 3748) +++ trunk/sc2/src/uqm/sis.h 2012-01-23 20:14:45 UTC (rev 3749) @@ -181,7 +181,11 @@ extern void InitSISContexts (void); extern void DrawSISFrame (void); extern void ClearSISRect (BYTE ClearFlags); -extern void SetFlashRect (RECT *pRect); +extern void SetFlashRect (const RECT *pRect); +extern void PreUpdateFlashRect (void); +extern void PostUpdateFlashRect (void); +extern void PreUpdateFlashRectLocked (void); +extern void PostUpdateFlashRectLocked (void); #define SFR_MENU_3DO ((RECT*)~0L) #define SFR_MENU_ANY ((RECT*)~1L) extern void DrawHyperCoords (POINT puniverse); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-27 23:29:11
|
Revision: 3750 http://sc2.svn.sourceforge.net/sc2/?rev=3750&view=rev Author: Meep-Eep Date: 2012-01-27 23:29:03 +0000 (Fri, 27 Jan 2012) Log Message: ----------- Annihigate flash thread. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/build/msvc6/UrQuanMasters.dsp trunk/sc2/src/libs/Makeinfo trunk/sc2/src/libs/callback/Makeinfo trunk/sc2/src/libs/callback/alarm.c trunk/sc2/src/libs/callback/alarm.h trunk/sc2/src/libs/callback/callback.c trunk/sc2/src/libs/callback/callback.h trunk/sc2/src/libs/sound/mixer/nosound/audiodrv_nosound.c trunk/sc2/src/libs/sound/stream.c trunk/sc2/src/libs/threadlib.h trunk/sc2/src/libs/threads/thrcommon.c trunk/sc2/src/uqm/battle.c trunk/sc2/src/uqm/confirm.c trunk/sc2/src/uqm/gameinp.c trunk/sc2/src/uqm/sis.c trunk/sc2/src/uqm/sis.h trunk/sc2/src/uqm/starcon.c trunk/sc2/src/uqm/supermelee/netplay/netmelee.c trunk/sc2/src/uqm/supermelee/pickmele.c Added Paths: ----------- trunk/sc2/src/libs/async.h trunk/sc2/src/libs/callback/async.c trunk/sc2/src/libs/callback/async.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/ChangeLog 2012-01-27 23:29:03 UTC (rev 3750) @@ -1,5 +1,6 @@ Changes towards version 0.8: -- Switch SetFlashRect() to the new flash code -- SvdB +- Annihigate flash thread - SvdB +- Switch SetFlashRect() to the new flash code - SvdB - Add C++ support to the build system, from Scott A. Colcord - Cleaning up DoModifyShips() - SvdB - Added Valgrind suppression file, from Louis Delacroix Modified: trunk/sc2/build/msvc6/UrQuanMasters.dsp =================================================================== --- trunk/sc2/build/msvc6/UrQuanMasters.dsp 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/build/msvc6/UrQuanMasters.dsp 2012-01-27 23:29:03 UTC (rev 3750) @@ -215,6 +215,14 @@ # End Source File # Begin Source File +SOURCE=..\..\src\libs\callback\async.c +# End Source File +# Begin Source File + +SOURCE=..\..\src\libs\callback\async.h +# End Source File +# Begin Source File + SOURCE=..\..\src\libs\callback\callback.c # End Source File # Begin Source File @@ -1470,6 +1478,10 @@ # End Source File # Begin Source File +SOURCE=..\..\src\libs\async.h +# End Source File +# Begin Source File + SOURCE=..\..\src\libs\callback.h # End Source File # Begin Source File Modified: trunk/sc2/src/libs/Makeinfo =================================================================== --- trunk/sc2/src/libs/Makeinfo 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/libs/Makeinfo 2012-01-27 23:29:03 UTC (rev 3750) @@ -12,8 +12,8 @@ # uqm_SUBDIRS="$UQM_SUBDIRS debug" #fi -uqm_HFILES="alarm.h callback.h cdplib.h compiler.h declib.h file.h gfxlib.h - heap.h inplib.h list.h log.h mathlib.h md5.h memlib.h misc.h net.h - platform.h reslib.h sndlib.h strlib.h tasklib.h threadlib.h - timelib.h uio.h uioutils.h unicode.h vidlib.h" +uqm_HFILES="alarm.h async.h callback.h cdplib.h compiler.h declib.h file.h + gfxlib.h heap.h inplib.h list.h log.h mathlib.h md5.h memlib.h + misc.h net.h platform.h reslib.h sndlib.h strlib.h tasklib.h + threadlib.h timelib.h uio.h uioutils.h unicode.h vidlib.h" Added: trunk/sc2/src/libs/async.h =================================================================== --- trunk/sc2/src/libs/async.h (rev 0) +++ trunk/sc2/src/libs/async.h 2012-01-27 23:29:03 UTC (rev 3750) @@ -0,0 +1,10 @@ +#if defined(__cplusplus) +extern "C" { +#endif + +#include "callback/async.h" + +#if defined(__cplusplus) +} +#endif + Modified: trunk/sc2/src/libs/callback/Makeinfo =================================================================== --- trunk/sc2/src/libs/callback/Makeinfo 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/libs/callback/Makeinfo 2012-01-27 23:29:03 UTC (rev 3750) @@ -1,2 +1,2 @@ -uqm_CFILES="alarm.c callback.c" -uqm_HFILES="alarm.h callback.h" +uqm_CFILES="alarm.c async.c callback.c" +uqm_HFILES="alarm.h async.h callback.h" Modified: trunk/sc2/src/libs/callback/alarm.c =================================================================== --- trunk/sc2/src/libs/callback/alarm.c 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/libs/callback/alarm.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -18,6 +18,7 @@ #include "alarm.h" +#include SDL_INCLUDE(SDL.h) #include "libs/heap.h" #include <assert.h> @@ -71,19 +72,19 @@ } static inline AlarmTime -AlarmTime_nowMS(void) { +AlarmTime_nowMs(void) { return SDL_GetTicks(); } Alarm * -Alarm_addRelativeMs(Uint32 ms, AlarmCallback callback, +Alarm_addAbsoluteMs(uint32 ms, AlarmCallback callback, AlarmCallbackArg arg) { Alarm *alarm; assert(alarmHeap != NULL); alarm = Alarm_alloc(); - alarm->time = AlarmTime_nowMS() + ms; + alarm->time = ms; alarm->callback = callback; alarm->arg = arg; @@ -92,6 +93,23 @@ return alarm; } +Alarm * +Alarm_addRelativeMs(uint32 ms, AlarmCallback callback, + AlarmCallbackArg arg) { + Alarm *alarm; + + assert(alarmHeap != NULL); + + alarm = Alarm_alloc(); + alarm->time = AlarmTime_nowMs() + ms; + alarm->callback = callback; + alarm->arg = arg; + + Heap_add(alarmHeap, (HeapValue *) alarm); + + return alarm; +} + void Alarm_remove(Alarm *alarm) { assert(alarmHeap != NULL); @@ -99,15 +117,40 @@ Alarm_free(alarm); } +// Process at most one alarm, if its time has come. // It is safe to call this function again from inside a callback function // that it called. It should not be called from multiple threads at once. +bool +Alarm_processOne(void) +{ + AlarmTime now; + Alarm *alarm; + + assert(alarmHeap != NULL); + if (!Heap_hasMore(alarmHeap)) + return false; + + now = AlarmTime_nowMs(); + alarm = (Alarm *) Heap_first(alarmHeap); + if (now < alarm->time) + return false; + + Heap_pop(alarmHeap); + alarm->callback(alarm->arg); + Alarm_free(alarm); + return true; +} + +#if 0 +// It is safe to call this function again from inside a callback function +// that it called. It should not be called from multiple threads at once. void -Alarm_process(void) { +Alarm_processAll(void) { AlarmTime now; assert(alarmHeap != NULL); - now = AlarmTime_nowMS(); + now = AlarmTime_nowMs(); while (Heap_hasMore(alarmHeap)) { Alarm *alarm = (Alarm *) Heap_first(alarmHeap); @@ -119,8 +162,9 @@ Alarm_free(alarm); } } +#endif -Uint32 +uint32 Alarm_timeBeforeNextMs(void) { Alarm *alarm; @@ -131,4 +175,3 @@ return alarmTimeToMsUint32(alarm->time); } - Modified: trunk/sc2/src/libs/callback/alarm.h =================================================================== --- trunk/sc2/src/libs/callback/alarm.h 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/libs/callback/alarm.h 2012-01-27 23:29:03 UTC (rev 3750) @@ -22,11 +22,10 @@ #include "port.h" #include "types.h" -#include SDL_INCLUDE(SDL.h) -typedef Uint32 AlarmTime; -static inline Uint32 +typedef uint32 AlarmTime; +static inline uint32 alarmTimeToMsUint32(AlarmTime time) { - return (Uint32) time; + return (uint32) time; } typedef struct Alarm Alarm; @@ -44,11 +43,14 @@ void Alarm_init(void); void Alarm_uninit(void); -Alarm *Alarm_addRelativeMs(Uint32 ms, AlarmCallback callback, +Alarm *Alarm_addAbsoluteMs(uint32 ms, AlarmCallback callback, AlarmCallbackArg arg); +Alarm *Alarm_addRelativeMs(uint32 ms, AlarmCallback callback, + AlarmCallbackArg arg); void Alarm_remove(Alarm *alarm); -void Alarm_process(void); -Uint32 Alarm_timeBeforeNextMs(void); +bool Alarm_processOne(void); +void Alarm_processAll(void); +uint32 Alarm_timeBeforeNextMs(void); #endif /* _ALARM_H */ Added: trunk/sc2/src/libs/callback/async.c =================================================================== --- trunk/sc2/src/libs/callback/async.c (rev 0) +++ trunk/sc2/src/libs/callback/async.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -0,0 +1,56 @@ +/* + * Copyright 2012 Serge van den Boom <sv...@st...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "async.h" + +#include "libs/alarm.h" +#include "libs/callback.h" + + +// Process all alarms and callbacks. +// First, all scheduled callbacks are called. +// Then each alarm due is called, and after each of these alarms, the +// callbacks scheduled by this alarm are called. +void +Async_process(void) +{ + // Call pending callbacks. + Callback_process(); + + for (;;) { + if (!Alarm_processOne()) + return; + + // Call callbacks scheduled from the last alarm. + Callback_process(); + } +} + +// Returns the next time that some asynchronous callback is +// to be called. Note that all values lower than the current time +// should be considered as 'somewhere in the past'. +uint32 +Async_timeBeforeNextMs(void) { + if (Callback_haveMore()) { + // Any time before the current time is ok, though we reserve 0 so + // that the caller may use it as a special value in its own code. + return 1; + } + return Alarm_timeBeforeNextMs(); +} + Added: trunk/sc2/src/libs/callback/async.h =================================================================== --- trunk/sc2/src/libs/callback/async.h (rev 0) +++ trunk/sc2/src/libs/callback/async.h 2012-01-27 23:29:03 UTC (rev 3750) @@ -0,0 +1,28 @@ +/* + * Copyright 2012 Serge van den Boom <sv...@st...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _ASYNC_H +#define _ASYNC_H + +#include "types.h" + +void Async_process(void); +uint32 Async_timeBeforeNextMs(void); + +#endif /* _ASYNC_H */ + Modified: trunk/sc2/src/libs/callback/callback.c =================================================================== --- trunk/sc2/src/libs/callback/callback.c 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/libs/callback/callback.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -170,4 +170,14 @@ } } +bool +Callback_haveMore(void) { + bool result; + CallbackList_lock(); + result = (callbacks != NULL); + CallbackList_unlock(); + + return result; +} + Modified: trunk/sc2/src/libs/callback/callback.h =================================================================== --- trunk/sc2/src/libs/callback/callback.h 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/libs/callback/callback.h 2012-01-27 23:29:03 UTC (rev 3750) @@ -36,6 +36,7 @@ CallbackID Callback_add(CallbackFunction callback, CallbackArg arg); bool Callback_remove(CallbackID id); void Callback_process(void); +bool Callback_haveMore(void); #endif /* _CALLBACK_H */ Modified: trunk/sc2/src/libs/sound/mixer/nosound/audiodrv_nosound.c =================================================================== --- trunk/sc2/src/libs/sound/mixer/nosound/audiodrv_nosound.c 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/libs/sound/mixer/nosound/audiodrv_nosound.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -211,7 +211,7 @@ mixer_MixFake (NULL, stream, len); delay = period - (GetTimeCounter () - entryTime); if (delay > 0) - SleepThread (delay); + HibernateThread (delay); } HFree (stream); Modified: trunk/sc2/src/libs/sound/stream.c =================================================================== --- trunk/sc2/src/libs/sound/stream.c 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/libs/sound/stream.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -568,7 +568,7 @@ if (active_streams == 0) { // Throttle down the thread when there are no active streams - SleepThread (ONE_SECOND / 10); + HibernateThread (ONE_SECOND / 10); } else TaskSwitch (); Modified: trunk/sc2/src/libs/threadlib.h =================================================================== --- trunk/sc2/src/libs/threadlib.h 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/libs/threadlib.h 2012-01-27 23:29:03 UTC (rev 3750) @@ -145,6 +145,8 @@ void DestroyThreadLocal (ThreadLocal *tl); ThreadLocal *GetMyThreadLocal (void); +void HibernateThread (TimePeriod timePeriod); +void HibernateThreadUntil (TimeCount wakeTime); void SleepThread (TimePeriod timePeriod); void SleepThreadUntil (TimeCount wakeTime); void DestroyThread (Thread); Modified: trunk/sc2/src/libs/threads/thrcommon.c =================================================================== --- trunk/sc2/src/libs/threads/thrcommon.c 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/libs/threads/thrcommon.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -19,6 +19,7 @@ #include "libs/threadlib.h" #include "libs/timelib.h" #include "libs/log.h" +#include "libs/async.h" #include "libs/memlib.h" #include "thrcommon.h" @@ -284,19 +285,82 @@ NativeWaitThread (thread, status); } +#ifdef DEBUG_SLEEP +extern uint32 mainThreadId; +extern uint32 SDL_ThreadID(void); +#endif /* DEBUG_SLEEP */ + void -SleepThread (TimePeriod timePeriod) +HibernateThread (TimePeriod timePeriod) { +#ifdef DEBUG_SLEEP + if (SDL_ThreadID() == mainThreadId) + log_add (log_Debug, "HibernateThread called from main thread.\n"); +#endif /* DEBUG_SLEEP */ + NativeSleepThread (timePeriod); } void -SleepThreadUntil (TimeCount wakeTime) +HibernateThreadUntil (TimeCount wakeTime) { +#ifdef DEBUG_SLEEP + if (SDL_ThreadID() == mainThreadId) + log_add (log_Debug, "HibernateThreadUntil called from main " + "thread.\n"); +#endif /* DEBUG_SLEEP */ + NativeSleepThreadUntil (wakeTime); } void +SleepThread (TimePeriod timePeriod) +{ + TimeCount now; + +#ifdef DEBUG_SLEEP + if (SDL_ThreadID() != mainThreadId) + log_add (log_Debug, "SleepThread called from non-main " + "thread.\n"); +#endif /* DEBUG_SLEEP */ + + now = GetTimeCounter (); + SleepThreadUntil (now + timePeriod); +} + +// Sleep until wakeTime, but call asynchrounous operations until then. +void +SleepThreadUntil (TimeCount wakeTime) +{ +#ifdef DEBUG_SLEEP + if (SDL_ThreadID() != mainThreadId) + log_add (log_Debug, "SleepThreadUntil called from non-main " + "thread.\n"); +#endif /* DEBUG_SLEEP */ + + for (;;) { + uint32 nextTimeMs; + TimeCount nextTime; + TimeCount now; + + Async_process (); + + now = GetTimeCounter (); + if (wakeTime <= now) + return; + + nextTimeMs = Async_timeBeforeNextMs (); + nextTime = (nextTimeMs / 1000) * ONE_SECOND + + ((nextTimeMs % 1000) * ONE_SECOND / 1000); + // Overflow-safe conversion. + if (wakeTime < nextTime) + nextTime = wakeTime; + + NativeSleepThreadUntil (nextTime); + } +} + +void TaskSwitch (void) { NativeTaskSwitch (); Modified: trunk/sc2/src/uqm/battle.c =================================================================== --- trunk/sc2/src/uqm/battle.c 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/uqm/battle.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -40,6 +40,7 @@ #include "setup.h" #include "settings.h" #include "sounds.h" +#include "libs/async.h" #include "libs/graphics/gfx_common.h" #include "libs/log.h" #include "libs/mathlib.h" @@ -334,6 +335,7 @@ battle_speed = HIBYTE (nth_frame); if (battle_speed == (BYTE)~0) { // maximum speed, nothing rendered at all + Async_process (); TaskSwitch (); } else Modified: trunk/sc2/src/uqm/confirm.c =================================================================== --- trunk/sc2/src/uqm/confirm.c 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/uqm/confirm.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -83,6 +83,8 @@ if (PlayingTrack ()) PauseTrack (); + PauseFlash (); + LockMutex (GraphicsLock); { RECT r; @@ -160,6 +162,8 @@ } UnlockMutex (GraphicsLock); + ContinueFlash (); + if (PlayingTrack ()) ResumeTrack (); @@ -212,6 +216,7 @@ label.line_count = SplitString (msg, '\n', 30, lines, bank); label.lines = lines; + PauseFlash (); LockMutex (GraphicsLock); oldContext = SetContext (ScreenContext); @@ -242,6 +247,8 @@ SetContextClipRect (&oldRect); SetContext (oldContext); UnlockMutex (GraphicsLock); + ContinueFlash (); SetMenuSounds (s0, s1); StringBank_Free (bank); } + Modified: trunk/sc2/src/uqm/gameinp.c =================================================================== --- trunk/sc2/src/uqm/gameinp.c 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/uqm/gameinp.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -28,6 +28,7 @@ #include "sounds.h" #include "tactrans.h" #include "uqmdebug.h" +#include "libs/async.h" #include "libs/inplib.h" #include "libs/timelib.h" #include "libs/threadlib.h" @@ -359,6 +360,7 @@ do { MENU_SOUND_FLAGS soundFlags; + Async_process (); TaskSwitch (); UpdateInputState (); Modified: trunk/sc2/src/uqm/sis.c =================================================================== --- trunk/sc2/src/uqm/sis.c 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/uqm/sis.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -34,6 +34,7 @@ #include "flash.h" #include "libs/graphics/gfx_common.h" #include "libs/tasklib.h" +#include "libs/alarm.h" #include "libs/log.h" #include <stdio.h> @@ -1590,28 +1591,32 @@ } -static Task flash_task = 0; static FlashContext *flashContext = NULL; static RECT flash_rect; -static Mutex flash_mutex = 0; +static Alarm *flashAlarm = NULL; +static BOOLEAN flashPaused = FALSE; -static int -flash_rect_func (void *data) +static void scheduleFlashAlarm (void); + +static void +updateFlashRect (void *arg) { - Task task = (Task)data; + if (flashContext == NULL) + return; - while (!Task_ReadState(task, TASK_EXIT)) - { - TimeCount nextTime; - LockMutex (flash_mutex); - Flash_process (flashContext); - nextTime = Flash_nextTime (flashContext); - UnlockMutex (flash_mutex); - SleepThreadUntil (nextTime); - } + Flash_process (flashContext); + scheduleFlashAlarm (); + (void) arg; +} - FinishTask (task); - return 0; +static void +scheduleFlashAlarm (void) +{ + TimeCount nextTime = Flash_nextTime (flashContext); + DWORD nextTimeMs = (nextTime / ONE_SECOND) * 1000 + + ((nextTime % ONE_SECOND) * 1000 / ONE_SECOND); + // Overflow-safe conversion. + flashAlarm = Alarm_addAbsoluteMs (nextTimeMs, updateFlashRect, NULL); } // Pre: the caller holds the GraphicsLock @@ -1621,10 +1626,6 @@ RECT clip_r = {{0, 0}, {0, 0}}; RECT temp_r; - if (!flash_mutex) - flash_mutex = CreateMutex ("FlashRect Lock", - SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO); - if (pRect != SFR_MENU_3DO && pRect != SFR_MENU_ANY) { // The caller specified their own flash area, or NULL (stop flashing). @@ -1654,47 +1655,42 @@ } } - // Conclude an old flash task. - if (flashContext != NULL) - { - UnlockMutex (GraphicsLock); - ConcludeTask (flash_task); - LockMutex (GraphicsLock); - flash_task = 0; - - Flash_terminate (flashContext); - flashContext = 0; - } - - // Start a new flash task. if (pRect != 0 && pRect->extent.width != 0) { + // Flash rectangle is not empty, start or continue flashing. flash_rect = *pRect; flash_rect.corner.x += clip_r.corner.x; flash_rect.corner.y += clip_r.corner.y; - flashContext = Flash_createHighlight (ScreenContext, &flash_rect); - Flash_setMergeFactors(flashContext, 3, 2, 2); - Flash_setSpeed (flashContext, 0, ONE_SECOND / 16, 0, ONE_SECOND / 16); - Flash_setFrameTime (flashContext, ONE_SECOND / 16); - Flash_start (flashContext); - - flash_task = AssignTask (flash_rect_func, 2048, "flash rectangle"); + if (flashContext == NULL) + { + // Create a new flash context. + flashContext = Flash_createHighlight (ScreenContext, &flash_rect); + Flash_setMergeFactors(flashContext, 3, 2, 2); + Flash_setSpeed (flashContext, 0, ONE_SECOND / 16, 0, ONE_SECOND / 16); + Flash_setFrameTime (flashContext, ONE_SECOND / 16); + Flash_start (flashContext); + scheduleFlashAlarm (); + } + else + { + // Reuse an existing flash context + Flash_setRect (flashContext, &flash_rect); + } } -} - -// Sleep while calling the flash rectangle update when necessary. -void -FlashRectSleepUntil (TimeCount wakeTime) -{ - while (GetTimeCounter() < wakeTime) + else { - TimeCount flashNextTime = Flash_nextTime (flashContext); - TimeCount nextTime = (flashNextTime < wakeTime) ? - flashNextTime : wakeTime; - SleepThreadUntil (nextTime); - if (nextTime == flashNextTime) - Flash_process (flashContext); + // Flash rectangle is empty. Stop flashing. + if (flashContext != NULL) + { + UnlockMutex (GraphicsLock); + Alarm_remove(flashAlarm); + LockMutex (GraphicsLock); + flashAlarm = 0; + + Flash_terminate (flashContext); + flashContext = NULL; + } } } @@ -1708,18 +1704,12 @@ void PreUpdateFlashRect (void) { - if (flash_task) + if (flashAlarm) { updateFlashRectRecursion++; if (updateFlashRectRecursion > 1) return; - - LockMutex (flash_mutex); - Flash_pause (flashContext); - // We need to actually pause, as the flash update function - // is called from another thread. Flash_preUpdate (flashContext); - UnlockMutex (flash_mutex); } } @@ -1727,16 +1717,13 @@ void PostUpdateFlashRect (void) { - if (flash_task) + if (flashAlarm) { updateFlashRectRecursion--; if (updateFlashRectRecursion > 0) return; - LockMutex (flash_mutex); Flash_postUpdate (flashContext); - Flash_continue (flashContext); - UnlockMutex (flash_mutex); } } @@ -1760,3 +1747,27 @@ LockMutex (GraphicsLock); } +// Stop flashing if flashing is active. +void +PauseFlash (void) +{ + if (flashContext != NULL) + { + Alarm_remove(flashAlarm); + flashAlarm = 0; + flashPaused = TRUE; + } +} + +// Continue flashing after PauseFlash (), if flashing was active. +void +ContinueFlash (void) +{ + if (flashPaused) + { + scheduleFlashAlarm (); + flashPaused = FALSE; + } +} + + Modified: trunk/sc2/src/uqm/sis.h =================================================================== --- trunk/sc2/src/uqm/sis.h 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/uqm/sis.h 2012-01-27 23:29:03 UTC (rev 3750) @@ -186,6 +186,9 @@ extern void PostUpdateFlashRect (void); extern void PreUpdateFlashRectLocked (void); extern void PostUpdateFlashRectLocked (void); +extern void PauseFlash (void); +extern void ContinueFlash (void); + #define SFR_MENU_3DO ((RECT*)~0L) #define SFR_MENU_ANY ((RECT*)~1L) extern void DrawHyperCoords (POINT puniverse); Modified: trunk/sc2/src/uqm/starcon.c =================================================================== --- trunk/sc2/src/uqm/starcon.c 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/uqm/starcon.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -50,6 +50,10 @@ #include "options.h" volatile int MainExited = FALSE; +#ifdef DEBUG_SLEEP +uint32 mainThreadId; +extern uint32 SDL_ThreadID(void); +#endif // Open or close the periodically occuring QuasiSpace portal. // It changes the appearant portal size when necessary. @@ -143,6 +147,10 @@ int Starcon2Main (void *threadArg) { +#ifdef DEBUG_SLEEP + mainThreadId = SDL_ThreadID(); +#endif + #if CREATE_JOURNAL { int ac = argc; Modified: trunk/sc2/src/uqm/supermelee/netplay/netmelee.c =================================================================== --- trunk/sc2/src/uqm/supermelee/netplay/netmelee.c 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/uqm/supermelee/netplay/netmelee.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -17,7 +17,7 @@ */ #include "netmelee.h" -#include "libs/alarm.h" +#include "libs/async.h" #include "libs/callback.h" #include "libs/log.h" #include "libs/net.h" @@ -146,8 +146,7 @@ NetManager_process(&timeoutMs); // This may cause more packets to be queued, hence the // flushPacketQueues(). - Alarm_process(); - Callback_process(); + Async_process(); flushPacketQueues(); // During the flush, a disconnect may be noticed, which triggers // another callback. It must be handled immediately, before @@ -166,11 +165,11 @@ void netInputBlocking(uint32 timeoutMs) { - uint32 nextAlarmMs; + uint32 nextAsyncMs; - nextAlarmMs = Alarm_timeBeforeNextMs(); - if (nextAlarmMs < timeoutMs) - timeoutMs = nextAlarmMs; + nextAsyncMs = Async_timeBeforeNextMs(); + if (nextAsyncMs < timeoutMs) + timeoutMs = nextAsyncMs; netInputAux(timeoutMs); } Modified: trunk/sc2/src/uqm/supermelee/pickmele.c =================================================================== --- trunk/sc2/src/uqm/supermelee/pickmele.c 2012-01-23 20:14:45 UTC (rev 3749) +++ trunk/sc2/src/uqm/supermelee/pickmele.c 2012-01-27 23:29:03 UTC (rev 3750) @@ -37,6 +37,7 @@ #include "../races.h" #include "../setup.h" #include "../sounds.h" +#include "libs/async.h" #include "libs/log.h" #include "libs/mathlib.h" @@ -676,6 +677,7 @@ ButtonState = FALSE; } + Async_process (); TaskSwitch (); } while (!(GLOBAL (CurrentActivity) & CHECK_ABORT) && (!ButtonState && (!(PlayerControl[0] & PlayerControl[1] & PSYTRON_CONTROL) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-28 19:02:39
|
Revision: 3752 http://sc2.svn.sourceforge.net/sc2/?rev=3752&view=rev Author: Meep-Eep Date: 2012-01-28 19:02:33 +0000 (Sat, 28 Jan 2012) Log Message: ----------- Add/Remove fuel 10 at a time with PageUp/PageDown, from from Scott A. Colcord, Nic. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/uqm/outfit.c Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2012-01-28 17:07:35 UTC (rev 3751) +++ trunk/sc2/ChangeLog 2012-01-28 19:02:33 UTC (rev 3752) @@ -1,4 +1,6 @@ Changes towards version 0.8: +- PageUp/PageDown now add/remove 10 fuel in the shipyard, from + Scott A. Colcord, Nic - Annihigate flash thread - SvdB - Switch SetFlashRect() to the new flash code - SvdB - Add C++ support to the build system, from Scott A. Colcord Modified: trunk/sc2/src/uqm/outfit.c =================================================================== --- trunk/sc2/src/uqm/outfit.c 2012-01-28 17:07:35 UTC (rev 3751) +++ trunk/sc2/src/uqm/outfit.c 2012-01-28 19:02:33 UTC (rev 3752) @@ -85,7 +85,8 @@ t.align = ALIGN_RIGHT; t.CharCount = (COUNT)~0; t.pStr = buf; - sprintf (buf, "%u", GLOBAL (ModuleCost[NewModule]) * MODULE_COST_SCALE); + sprintf (buf, "%u", + GLOBAL (ModuleCost[NewModule]) * MODULE_COST_SCALE); SetContextFont (TinyFont); SetContextForeGroundColor ( BUILD_COLOR (MAKE_RGB15 (0x00, 0x1F, 0x00), 0x02)); @@ -98,43 +99,38 @@ static void RedistributeFuel (void) { - COUNT m; - DWORD FuelVolume; + const DWORD FuelVolume = GLOBAL_SIS (FuelOnBoard); + const CONTEXT OldContext = SetContext (SpaceContext); RECT r; - - FuelVolume = GLOBAL_SIS (FuelOnBoard); - if (FuelVolume <= FUEL_RESERVE) - return; - - GLOBAL_SIS (FuelOnBoard) = 0; - m = FUEL_VOLUME_PER_ROW; - - r.extent.width = 3; r.extent.height = 1; - while (FuelVolume -= m) - { - GLOBAL_SIS (FuelOnBoard) += FUEL_VOLUME_PER_ROW; - GetFTankCapacity (&r.corner); - DrawPoint (&r.corner); - r.corner.x += r.extent.width + 1; - DrawPoint (&r.corner); - r.corner.x -= r.extent.width; - SetContextForeGroundColor (SetContextBackGroundColor (BLACK_COLOR)); - DrawFilledRectangle (&r); - if (FuelVolume < FUEL_VOLUME_PER_ROW) - m = (COUNT)FuelVolume; - } - FuelVolume = GLOBAL_SIS (FuelOnBoard) + m; - - r.extent.width = 5; - while ((GLOBAL_SIS (FuelOnBoard) += FUEL_VOLUME_PER_ROW) < - GetFTankCapacity (&r.corner)) + // Loop through all the rows to draw + BatchGraphics (); + for (GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; + GLOBAL_SIS (FuelOnBoard) < GetFTankCapacity (&r.corner); + GLOBAL_SIS (FuelOnBoard) += FUEL_VOLUME_PER_ROW) { - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x0B, 0x00, 0x00), 0x2E)); + // If we're less than the fuel level, draw fuel. + if (GLOBAL_SIS (FuelOnBoard) < FuelVolume) + { + r.extent.width = 3; + DrawPoint (&r.corner); + r.corner.x += r.extent.width + 1; + DrawPoint (&r.corner); + r.corner.x -= r.extent.width; + SetContextForeGroundColor ( + SetContextBackGroundColor (BLACK_COLOR)); + } + else // Otherwise, draw an empty bar. + { + r.extent.width = 5; + SetContextForeGroundColor ( + BUILD_COLOR (MAKE_RGB15 (0x0B, 0x00, 0x00), 0x2E)); + } DrawFilledRectangle (&r); } + UnbatchGraphics (); + SetContext (OldContext); GLOBAL_SIS (FuelOnBoard) = FuelVolume; } @@ -348,7 +344,8 @@ GLOBAL (ModuleCost[old_slot_piece]) * MODULE_COST_SCALE); - if (pMS->CurState == PLANET_LANDER || pMS->CurState == EMPTY_SLOT + 3) + if (pMS->CurState == PLANET_LANDER || + pMS->CurState == EMPTY_SLOT + 3) DisplayLanders (pMS); else { @@ -402,7 +399,8 @@ NewItem = NewState < EMPTY_SLOT ? pMS->CurState : pMS->delta_item; do { - if (NewState >= EMPTY_SLOT && (PulsedInputState.menu[KEY_MENU_UP] || PulsedInputState.menu[KEY_MENU_DOWN])) + if (NewState >= EMPTY_SLOT && (PulsedInputState.menu[KEY_MENU_UP] + || PulsedInputState.menu[KEY_MENU_DOWN])) { if (PulsedInputState.menu[KEY_MENU_UP]) { @@ -551,69 +549,58 @@ static void ChangeFuelQuantity (void) { - RECT r; + int incr = 0; // Fuel increment in fuel points (not units). - r.extent.height = 1; - - if (PulsedInputState.menu[KEY_MENU_UP]) + if (PulsedInputState.menu[KEY_MENU_UP]) + incr = FUEL_TANK_SCALE; // +1 Unit + else if (PulsedInputState.menu[KEY_MENU_DOWN]) + incr = -FUEL_TANK_SCALE; // -1 Unit + else if (PulsedInputState.menu[KEY_MENU_PAGE_UP]) + incr = FUEL_VOLUME_PER_ROW; // +1 Bar + else if (PulsedInputState.menu[KEY_MENU_PAGE_DOWN]) + incr = -FUEL_VOLUME_PER_ROW; // -1 Bar + else + return; + + // Clamp incr to what we can afford/hold/have. { - LockMutex (GraphicsLock); - SetContext (SpaceContext); - if (GetFTankCapacity (&r.corner) > GLOBAL_SIS (FuelOnBoard) - && GLOBAL_SIS (ResUnits) >= (DWORD)GLOBAL (FuelCost)) - { - if (GLOBAL_SIS (FuelOnBoard) >= FUEL_RESERVE) - { - r.extent.width = 3; - DrawPoint (&r.corner); - r.corner.x += r.extent.width + 1; - DrawPoint (&r.corner); - r.corner.x -= r.extent.width; - SetContextForeGroundColor ( - SetContextBackGroundColor (BLACK_COLOR)); - DrawFilledRectangle (&r); - } - PreUpdateFlashRect (); - DeltaSISGauges (0, FUEL_TANK_SCALE, -GLOBAL (FuelCost)); - PostUpdateFlashRect (); - SetContext (StatusContext); - GetGaugeRect (&r, FALSE); - SetFlashRect (&r); - } - else - { // no more room for fuel or not enough RUs - PlayMenuSound (MENU_SOUND_FAILURE); - } - UnlockMutex (GraphicsLock); + const int maxFit = GetFuelTankCapacity () - GLOBAL_SIS (FuelOnBoard); + const int maxAfford = GLOBAL_SIS (ResUnits) / GLOBAL (FuelCost); + const int minFit = -GLOBAL_SIS (FuelOnBoard); + + if (incr > maxFit) + incr = maxFit; // All we can hold. + + if (incr > maxAfford * FUEL_TANK_SCALE) + incr = maxAfford * FUEL_TANK_SCALE; // All we can afford. + + if (incr < minFit) + incr = minFit; // All we have. } - else if (PulsedInputState.menu[KEY_MENU_DOWN]) + + LockMutex (GraphicsLock); + if (!incr) { - LockMutex (GraphicsLock); - SetContext (SpaceContext); - if (GLOBAL_SIS (FuelOnBoard)) - { - PreUpdateFlashRect (); - DeltaSISGauges (0, -FUEL_TANK_SCALE, GLOBAL (FuelCost)); - PostUpdateFlashRect (); - if (GLOBAL_SIS (FuelOnBoard) % FUEL_VOLUME_PER_ROW == 0 && - GLOBAL_SIS (FuelOnBoard) >= FUEL_RESERVE) - { - GetFTankCapacity (&r.corner); - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x0B, 0x00, 0x00), 0x2E)); - r.extent.width = 5; - DrawFilledRectangle (&r); - } - } - else - { // no fuel left to drain - PlayMenuSound (MENU_SOUND_FAILURE); - } - SetContext (StatusContext); + // No more room, not enough RUs, or no fuel left to drain. + PlayMenuSound (MENU_SOUND_FAILURE); + } + else + { + const int cost = (incr / FUEL_TANK_SCALE) * GLOBAL (FuelCost); + PreUpdateFlashRect (); + DeltaSISGauges (0, incr, -cost); + PostUpdateFlashRect (); + RedistributeFuel (); + } + + { // Make fuel gauge flash. + RECT r; + CONTEXT oldContext = SetContext (StatusContext); GetGaugeRect (&r, FALSE); SetFlashRect (&r); - UnlockMutex (GraphicsLock); + SetContext (oldContext); } + UnlockMutex (GraphicsLock); } static void @@ -810,7 +797,9 @@ switch (pMS->CurState) { case OUTFIT_DOFUEL: - SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, MENU_SOUND_SELECT | MENU_SOUND_CANCEL); + SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN | + MENU_SOUND_PAGEUP | MENU_SOUND_PAGEDOWN, + MENU_SOUND_SELECT | MENU_SOUND_CANCEL); break; default: SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <av...@us...> - 2012-01-29 20:18:57
|
Revision: 3759 http://sc2.svn.sourceforge.net/sc2/?rev=3759&view=rev Author: avolkov Date: 2012-01-29 20:18:50 +0000 (Sun, 29 Jan 2012) Log Message: ----------- Split debug key function into sync and async parts (wrt the game logic thread), paving the way for GraphicsLock and GameClock lock removal Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/uqm/clock.c trunk/sc2/src/uqm/gameinp.c trunk/sc2/src/uqm/planets/calc.c trunk/sc2/src/uqm/starcon.c trunk/sc2/src/uqm/uqmdebug.c trunk/sc2/src/uqm/uqmdebug.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2012-01-29 18:35:35 UTC (rev 3758) +++ trunk/sc2/ChangeLog 2012-01-29 20:18:50 UTC (rev 3759) @@ -1,4 +1,6 @@ Changes towards version 0.8: +- Split debug key function into sync and async parts, paving the way + for GraphicsLock removal - Alex - PageUp/PageDown now add/remove 10 fuel in the shipyard, from Scott A. Colcord, Nic - Annihigate flash thread - SvdB Modified: trunk/sc2/src/uqm/clock.c =================================================================== --- trunk/sc2/src/uqm/clock.c 2012-01-29 18:35:35 UTC (rev 3758) +++ trunk/sc2/src/uqm/clock.c 2012-01-29 20:18:50 UTC (rev 3759) @@ -157,22 +157,16 @@ BOOLEAN GameClockRunning (void) { - SIZE prev_tick, cur_tick; + SIZE day_in_ticks; if (!clock_mutex) return FALSE; LockMutex (clock_mutex); - prev_tick = GLOBAL (GameClock.tick_count); + day_in_ticks = GLOBAL (GameClock.day_in_ticks); UnlockMutex (clock_mutex); - SleepThread (ONE_SECOND / 5); - - LockMutex (clock_mutex); - cur_tick = GLOBAL (GameClock.tick_count); - UnlockMutex (clock_mutex); - - return cur_tick != prev_tick; + return day_in_ticks != 0; } void Modified: trunk/sc2/src/uqm/gameinp.c =================================================================== --- trunk/sc2/src/uqm/gameinp.c 2012-01-29 18:35:35 UTC (rev 3758) +++ trunk/sc2/src/uqm/gameinp.c 2012-01-29 20:18:50 UTC (rev 3759) @@ -275,6 +275,11 @@ if (CurrentInputState.menu[KEY_EXIT]) ExitRequested = TRUE; + +#if defined(DEBUG) || defined(USE_DEBUG_KEY) + if (PulsedInputState.menu[KEY_DEBUG]) + debugKeyPressedSynchronous (); +#endif } InputFrameCallback * @@ -365,19 +370,6 @@ UpdateInputState (); -#ifdef DEBUG - if (doInputDebugHook != NULL) - { - void (*saveDebugHook) (void); - saveDebugHook = doInputDebugHook; - doInputDebugHook = NULL; - // No further debugHook calls unless the called - // function resets doInputDebugHook. - (*saveDebugHook) (); - continue; - } -#endif - #if DEMO_MODE || CREATE_JOURNAL if (ArrowInput != DemoInput) #endif Modified: trunk/sc2/src/uqm/planets/calc.c =================================================================== --- trunk/sc2/src/uqm/planets/calc.c 2012-01-29 18:35:35 UTC (rev 3758) +++ trunk/sc2/src/uqm/planets/calc.c 2012-01-29 20:18:50 UTC (rev 3759) @@ -352,7 +352,8 @@ void DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr, PLANET_DESC *pPlanetDesc) { - assert (pPlanetDesc->data_index != HIERARCHY_STARBASE); + assert ((pPlanetDesc->data_index & ~WORLD_TYPE_SPECIAL) + < NUMBER_OF_PLANET_TYPES); RandomContext_SeedRandom (SysGenRNG, pPlanetDesc->rand_seed); Modified: trunk/sc2/src/uqm/starcon.c =================================================================== --- trunk/sc2/src/uqm/starcon.c 2012-01-29 18:35:35 UTC (rev 3758) +++ trunk/sc2/src/uqm/starcon.c 2012-01-29 20:18:50 UTC (rev 3759) @@ -105,6 +105,7 @@ } } +// Executes on the main() thread void SignalStopMainThread (void) { @@ -113,6 +114,7 @@ TaskSwitch (); } +// Executes on the main() thread void ProcessUtilityKeys (void) { @@ -132,11 +134,17 @@ } #if defined(DEBUG) || defined(USE_DEBUG_KEY) - if (ImmediateInputState.menu[KEY_DEBUG]) - { - // clear ImmediateInputState so we don't repeat this next frame - FlushInput (); - debugKeyPressed (); + { // Only call the debug func on the rising edge of + // ImmediateInputState[KEY_DEBUG] so it does not execute repeatedly. + // This duplicates the PulsedInputState somewhat, but we cannot + // use PulsedInputState here because it is meant for another thread. + static int debugKeyState; + + if (ImmediateInputState.menu[KEY_DEBUG] && debugKeyState == 0) + { + debugKeyPressed (); + } + debugKeyState = ImmediateInputState.menu[KEY_DEBUG]; } #endif /* DEBUG */ } Modified: trunk/sc2/src/uqm/uqmdebug.c =================================================================== --- trunk/sc2/src/uqm/uqmdebug.c 2012-01-29 18:35:35 UTC (rev 3758) +++ trunk/sc2/src/uqm/uqmdebug.c 2012-01-29 20:18:50 UTC (rev 3759) @@ -72,11 +72,12 @@ BOOLEAN instantMove = FALSE; BOOLEAN disableInteractivity = FALSE; void (* volatile debugHook) (void) = NULL; -void (* volatile doInputDebugHook) (void) = NULL; +// Must be called on the Starcon2Main thread. +// This function is called synchronously wrt the game logic thread. void -debugKeyPressed (void) +debugKeyPressedSynchronous (void) { // State modifying: equipShip (); @@ -107,28 +108,36 @@ // SET_GAME_STATE (MELNORME_CREDIT1, 100); // GLOBAL_SIS (ResUnits) = 100000; + // Informational: +// dumpEvents (stderr); + + // Graphical and textual: +// debugContexts(); +} + +// Can be called on any thread, but usually on main() +// This function is called asynchronously wrt the game logic thread, +// which means locking applies. Use carefully. +// TODO: Once game logic thread is purged of graphics and clock locks, +// this function may not call graphics and game clock functions at all. +void +debugKeyPressed (void) +{ // Tests // Scale_PerfTest (); // Informational: // dumpStrings (stdout); -// dumpEvents (stderr); // dumpPlanetTypes(stderr); // debugHook = dumpUniverseToFile; // This will cause dumpUniverseToFile to be called from the - // main loop. Calling it from here would give threading + // Starcon2Main loop. Calling it from here would give threading // problems. // debugHook = tallyResourcesToFile; // This will cause tallyResourcesToFile to be called from the - // main loop. Calling it from here would give threading + // Starcon2Main loop. Calling it from here would give threading // problems. - // Graphical and textual: - //doInputDebugHook = debugContexts; - // This will cause debugContexts to be called from the - // Starcon2Main thread, from DoInput(). Calling it from here - // would give threading problems. - // Interactive: // uio_debugInteractive(stdin, stdout, stderr); } @@ -137,6 +146,9 @@ // Fast forwards to the next event. // If skipHEE is set, HYPERSPACE_ENCOUNTER_EVENTs are skipped. +// Must be called from the Starcon2Main thread. +// TODO: GraphicsLock and LockGameClock may be removed since it is only +// supposed to be called synchronously wrt the game logic thread. void forwardToNextEvent (BOOLEAN skipHEE) { @@ -596,6 +608,8 @@ //////////////////////////////////////////////////////////////////////////// +// Must be called from the Starcon2Main thread. +// TODO: LockGameClock may be removed void UniverseRecurse (UniverseRecurseArg *universeRecurseArg) { @@ -728,10 +742,13 @@ if (universeRecurseArg->moonFunc != NULL) { system->pOrbitalDesc = moon; - DoPlanetaryAnalysis (&system->SysInfo, moon); + if (moon->data_index != HIERARCHY_STARBASE && moon->data_index != SA_MATRA) + { + DoPlanetaryAnalysis (&system->SysInfo, moon); // When GenerateDefaultFunctions is used as genFuncs, // generateOrbital will also call DoPlanetaryAnalysis, // but with other GenerateFunctions this is not guaranteed. + } (*system->genFuncs->generateOrbital) (system, moon); (*universeRecurseArg->moonFunc) ( moon, universeRecurseArg->arg); @@ -745,6 +762,7 @@ FILE *out; } DumpUniverseArg; +// Must be called from the Starcon2Main thread. void dumpUniverse (FILE *out) { @@ -763,7 +781,7 @@ UniverseRecurse (&universeRecurseArg); } -// Must be called from the main thread. +// Must be called from the Starcon2Main thread. void dumpUniverseToFile (void) { @@ -1146,6 +1164,7 @@ COUNT bioCount; }; +// Must be called from the Starcon2Main thread. void tallyResources (FILE *out) { @@ -1164,7 +1183,7 @@ UniverseRecurse (&universeRecurseArg); } -// Must be called from the main thread. +// Must be called from the Starcon2Main thread. void tallyResourcesToFile (void) { Modified: trunk/sc2/src/uqm/uqmdebug.h =================================================================== --- trunk/sc2/src/uqm/uqmdebug.h 2012-01-29 18:35:35 UTC (rev 3758) +++ trunk/sc2/src/uqm/uqmdebug.h 2012-01-29 20:18:50 UTC (rev 3759) @@ -33,19 +33,19 @@ // Starcon2Main thread, in the main game loop. extern void (* volatile debugHook) (void); -// If a function is assigned to this, it will be called from the -// Starcon2Main thread, in doInput(). -extern void (* volatile doInputDebugHook) (void); - - -// Called when the debug key (symbol 'Debug' in the keys.cfg) is pressed. +// Called on the main() thread when the debug key (symbol 'Debug' in the +// keys.cfg) is pressed void debugKeyPressed (void); +// Called on the Starcon2Main() thread when the debug key (symbol 'Debug' +// in the keys.cfg) is pressed. +void debugKeyPressedSynchronous (void); // Forward time to the next event. If skipHEE is set, the event named // HYPERSPACE_ENCOUNTER_EVENT, which normally occurs every game day, -// is skipped. +// is skipped. Must be called on the Starcon2Main thread. void forwardToNextEvent (BOOLEAN skipHEE); // Generate a list of all events in the event queue. +// Must be called on the Starcon2Main thread. void dumpEvents (FILE *out); // Describe one event. void dumpEvent (FILE *out, const EVENT *eventPtr); @@ -102,11 +102,13 @@ // User data. } UniverseRecurseArg; // Recurse through all systems, planets, and moons in the universe. +// Must be called on the Starcon2Main thread. void UniverseRecurse (UniverseRecurseArg *universeRecurseArg); -// Describe the entire universe. +// Describe the entire universe. Must be called on the Starcon2Main thread. void dumpUniverse (FILE *out); // Describe the entire universe, output to a file "./PlanetInfo". +// Must be called on the Starcon2Main thread. void dumpUniverseToFile (void); // Describe one star system. void dumpSystem (FILE *out, const STAR_DESC *star, @@ -137,9 +139,10 @@ const PLANET_DESC *world, COUNT bio[]); // Tally the resources for each star system. +// Must be called on the Starcon2Main thread. void tallyResources (FILE *out); // Tally the resources for each star system, output to a file -// "./ResourceTally". +// "./ResourceTally". Must be called on the Starcon2Main thread. void tallyResourcesToFile (void); @@ -186,7 +189,7 @@ // Graphically and textually show all the contexts. -// Should be called from debugHook. +// Must be called on the Starcon2Main thread. void debugContexts (void); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <av...@us...> - 2012-02-11 23:41:16
|
Revision: 3761 http://sc2.svn.sourceforge.net/sc2/?rev=3761&view=rev Author: avolkov Date: 2012-02-11 23:41:06 +0000 (Sat, 11 Feb 2012) Log Message: ----------- Quantum-erase GraphicsLock; Some changes needed to accomplish this: * comm/trackplayer Callbacks are now queued instead of asynchronously called on the stream decoder thread * libs/callback now guards the list with a mutex (called from different threads) * only one thread (Starcon2Main) is allowed to queue draw commands right now; a sanity check is in place (define DEBUG_DCQ_THREADS) Fixes: Alarms and Callbacks are used for more than just Netplay, reflect this. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/build/msvc6/UrQuanMasters.dsp trunk/sc2/doc/devel/threads trunk/sc2/src/libs/callback/callback.c trunk/sc2/src/libs/callback/callback.h trunk/sc2/src/libs/graphics/dcqueue.c trunk/sc2/src/libs/sound/trackint.h trunk/sc2/src/libs/sound/trackplayer.c trunk/sc2/src/libs/sound/trackplayer.h trunk/sc2/src/libs/video/video.c trunk/sc2/src/libs/video/vidintrn.h trunk/sc2/src/libs/video/vidplayer.c trunk/sc2/src/uqm/battle.c trunk/sc2/src/uqm/battle.h trunk/sc2/src/uqm/build.c trunk/sc2/src/uqm/clock.c trunk/sc2/src/uqm/cnctdlg.c trunk/sc2/src/uqm/comm/comandr/comandr.c trunk/sc2/src/uqm/comm/druuge/druugec.c trunk/sc2/src/uqm/comm/melnorm/melnorm.c trunk/sc2/src/uqm/comm/starbas/starbas.c trunk/sc2/src/uqm/comm/zoqfot/zoqfotc.c trunk/sc2/src/uqm/comm.c trunk/sc2/src/uqm/commglue.c trunk/sc2/src/uqm/commglue.h trunk/sc2/src/uqm/confirm.c trunk/sc2/src/uqm/controls.h trunk/sc2/src/uqm/credits.c trunk/sc2/src/uqm/encount.c trunk/sc2/src/uqm/flash.c trunk/sc2/src/uqm/fmv.c trunk/sc2/src/uqm/gameopt.c trunk/sc2/src/uqm/hyper.c trunk/sc2/src/uqm/intro.c trunk/sc2/src/uqm/menu.c trunk/sc2/src/uqm/outfit.c trunk/sc2/src/uqm/pickship.c trunk/sc2/src/uqm/planets/cargo.c trunk/sc2/src/uqm/planets/devices.c trunk/sc2/src/uqm/planets/generate/genchmmr.c trunk/sc2/src/uqm/planets/generate/genmyc.c trunk/sc2/src/uqm/planets/generate/genorz.c trunk/sc2/src/uqm/planets/generate/genpet.c trunk/sc2/src/uqm/planets/generate/genthrad.c trunk/sc2/src/uqm/planets/generate/genutw.c trunk/sc2/src/uqm/planets/generate/genvux.c trunk/sc2/src/uqm/planets/lander.c trunk/sc2/src/uqm/planets/pl_stuff.c trunk/sc2/src/uqm/planets/planets.c trunk/sc2/src/uqm/planets/plangen.c trunk/sc2/src/uqm/planets/pstarmap.c trunk/sc2/src/uqm/planets/report.c trunk/sc2/src/uqm/planets/roster.c trunk/sc2/src/uqm/planets/scan.c trunk/sc2/src/uqm/planets/solarsys.c trunk/sc2/src/uqm/restart.c trunk/sc2/src/uqm/save.c trunk/sc2/src/uqm/setup.c trunk/sc2/src/uqm/setup.h trunk/sc2/src/uqm/shipyard.c trunk/sc2/src/uqm/sis.c trunk/sc2/src/uqm/sis.h trunk/sc2/src/uqm/starbase.c trunk/sc2/src/uqm/starcon.c trunk/sc2/src/uqm/supermelee/buildpick.c trunk/sc2/src/uqm/supermelee/loadmele.c trunk/sc2/src/uqm/supermelee/melee.c trunk/sc2/src/uqm/supermelee/pickmele.c trunk/sc2/src/uqm/uqmdebug.c trunk/sc2/src/uqm/util.c trunk/sc2/src/uqm.c Removed Paths: ------------- trunk/sc2/doc/devel/graphicslock Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/ChangeLog 2012-02-11 23:41:06 UTC (rev 3761) @@ -1,4 +1,5 @@ Changes towards version 0.8: +- Removed GraphicsLock and made comm callbacks queued - Alex - Split debug key function into sync and async parts, paving the way for GraphicsLock removal - Alex - PageUp/PageDown now add/remove 10 fuel in the shipyard, from Modified: trunk/sc2/build/msvc6/UrQuanMasters.dsp =================================================================== --- trunk/sc2/build/msvc6/UrQuanMasters.dsp 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/build/msvc6/UrQuanMasters.dsp 2012-02-11 23:41:06 UTC (rev 3761) @@ -3654,10 +3654,6 @@ # End Source File # Begin Source File -SOURCE=..\..\doc\devel\graphicslock -# End Source File -# Begin Source File - SOURCE=..\..\doc\devel\input # End Source File # Begin Source File Deleted: trunk/sc2/doc/devel/graphicslock =================================================================== --- trunk/sc2/doc/devel/graphicslock 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/doc/devel/graphicslock 2012-02-11 23:41:06 UTC (rev 3761) @@ -1,104 +0,0 @@ -HOW TO NOT GET HOSED BY DOUBLE-LOCK/UNLOCKS WITH GraphicsLock - -For the kinds of modifications you're likely to be doing, there only a -few functions that you must take care to ensure that you hold -GraphicsLock before calling. There are also some general guidelines. - -GENERAL GUIDELINES - -- Don't hold the GraphicsLock in Generate* functions. - -- Always hold it while doing ship operations - they're all only called - by RedrawQueue. (preprocess, postprocess, etc.) - -- On ConcludeTask, you must not be holding *anything* or you could - cause a deadlock if the thread you're waiting to conclude needs - whatever lock you hold before it can safely exit. It is - acceptable to hold the GraphicsLock when merely calling - Task_SetState. - -Specific Guidelines: - -Always hold the GraphicsLock when calling... - -- SetFlashRect in sis.c; this changes which part of the screen is - flashing. Very common. - -- RedrawQueue in process.c; this is for updating all the the graphics - for ship animations. - -- GetMeleeStarShip in pickmele.c. That this is extern at all is - probably a sign of lousy code organization. - -- DoMenuOptions in hyper.c; this is a consequence of being called from - a ship operation when in hyperspace, which means that it must assume - that it's called with the GraphicsLock held. - -- DoDiscoveryReport in planets/report.c; this is called by the - Generate* functions, which always start out not holding the Lock. - -- ClearSISRect and DeltaSISGauges in sis.c; you might call these if - working on code that modifies fuel or crew somehow. - -THE GORY DETAILS - -[functionname] means that the function is static and demands lockedness. -<functionname> means that the function is static and demands unlockedness. -*functionname* means that the function is extern and demands lockedness -(functionname) means that the function is extern and demands unlockedness. - -This information is incomplete, and the result of a fairly informal -hand-analysis of the code. In the case of extern-requires-lock, -context and calling sites have been tracked so that all such functions -are reached. - -battle.c: (Battle) -border.c: (DrawSISFrame) -build.c: (ActivateStarShip) -clock.c: (clock_task_func) -comm.c: (ambient_anim_task) [SpewPhrases] (AlienTalkSegue) - <DoCommunication> [HailAlien] (InitCommunication) -confirm.c: (DoConfirmExit) -credits.c: (Credits) (OutTakes) -encount.c: <DoSelectAction> (InitEncounter) [DrawFadeText] - (UninitEncounter) (EncounterBattle) -fmv.c: (Introduction) -gameopt.c: <FeedbackSetting> <FeedbackQuit> <DrawDescriptionString> - <DoNaming> <DoSettings> <DoQuitMenu> [ShowSummary] - <DoPickGame> <PickGame> -hyper.c: *LoadHyperspace* *FreeHyperspace* *DoMenuOptions* -init.c: *InitShips* *UninitShips* -melee.c: [DrawPickFrame] (flash_selection_func) <DrawMeleeShipStrings> - <DoLoadTeam> <DoSaveTeam> <DoEdit> <DoPickShip> - <FreeMeleeInfo> <DoMelee> -menu.c: (DrawMenuStateStrings) -outfit.c: <DoInstallModule> (ChangeFuelQuantity) (DoOutfit) -pickmele.c: *GetMeleeStarShip* -pickship.c: <DoPickBattleShip> [GetArmadaStarShip] -process.c: *RedrawQueue* -restart.c: <DrawRestartMenu> <DoRestart> (StartGame) -save.c: (SaveProblem) -ship.c: *ship_preprocess* -shipyard.c: (hangar_anim_func) <DrawRaceStrings> <ShowCombatShip> - [CrewTransaction] <DoModifyShips> <DrawBluePrint> - (DoShipyard) -sis.c: *ClearSISRect* *DeltaSISGauges* (flash_rect_func) - *SetFlashRect* -starbase.c: (rotate_starbase) (DoStarBase) -starcon.c: (arilou_gate_task) (Starcon2Main) -utils.c: (PauseGame) -cargo.c: (DrawCargoStrings) <DoDiscardCargo> (Cargo) -devices.c: <DrawDevices> <DoManipulateDevices> (Devices) -lander.c: <ScrollPlanetSide> [AnimateLaunch] <InitPlanetSide> - <ReturnToOrbit> (PlanetSide) (InitLander) -planets.c: (LoadPlanet) (FreePlanet) -plangen.c: (rotate_planet_task) -pstarmap.c: (flash_cursor_func) (DrawStarMap) [EraseCursor] - <DoMoveCursor> [DoStarMap] (DoFlagshipCommands) -report.c: [MakeReport] *DoDiscoveryReport* -roster.c: (flash_ship_task) <DoModifyRoster> -scan.c: <EraseCoarseScan> <PrintCoarseScanPC> <PrintCoarseScan3DO> - <SetPlanetLoc> (flash_planet_loc_func) <PickPlanetSide> - <DoScan> (ScanSystem) -solarsys.c: <FreeSolarSys> (IPtask_func) <DrawInnerSystem> - (ChangeSolarSys) <InitSolarSys> Modified: trunk/sc2/doc/devel/threads =================================================================== --- trunk/sc2/doc/devel/threads 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/doc/devel/threads 2012-02-11 23:41:06 UTC (rev 3761) @@ -97,10 +97,7 @@ sleep if the mutex is already locked, and awaken once the mutex becomes available. A Mutex must be unlocked by the same thread that locked it, and a thread must never lock a mutex it has already locked -(without unlocking it first). The most important Mutex in the program -the GraphicsLock. Code in UQM that does things like change the -screen's clipping rectangle always grabs the GraphicsLock first, to -ensure that the screen doesn't go crazy. +(without unlocking it first). API: Mutex CreateMutex (const char *name, DWORD syncClass); Modified: trunk/sc2/src/libs/callback/callback.c =================================================================== --- trunk/sc2/src/libs/callback/callback.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/libs/callback/callback.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -23,6 +23,8 @@ #include <stdlib.h> #include <sys/types.h> +#include "libs/threadlib.h" + typedef struct CallbackLink CallbackLink; #define CALLBACK_INTERNAL @@ -38,16 +40,16 @@ static CallbackLink **callbacksEnd; static CallbackLink *const *callbacksProcessEnd; +static Mutex callbackListLock; + static inline void CallbackList_lock(void) { - // TODO - // Necessary for reentrant operation + LockMutex(callbackListLock); } static inline void CallbackList_unlock(void) { - // TODO - // Necessary for reentrant operation + UnlockMutex(callbackListLock); } #if 0 @@ -62,8 +64,16 @@ callbacks = NULL; callbacksEnd = &callbacks; callbacksProcessEnd = &callbacks; + callbackListLock = CreateMutex("Callback List Lock", SYNC_CLASS_TOPLEVEL); } +void +Callback_uninit(void) { + // TODO: cleanup the queue? + DestroyMutex (callbackListLock); + callbackListLock = 0; +} + // Callbacks are guaranteed to be called in the order that they are queued. CallbackID Callback_add(CallbackFunction callback, CallbackArg arg) { Modified: trunk/sc2/src/libs/callback/callback.h =================================================================== --- trunk/sc2/src/libs/callback/callback.h 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/libs/callback/callback.h 2012-02-11 23:41:06 UTC (rev 3761) @@ -33,6 +33,7 @@ typedef void (*CallbackFunction)(CallbackArg arg); void Callback_init(void); +void Callback_uninit(void); CallbackID Callback_add(CallbackFunction callback, CallbackArg arg); bool Callback_remove(CallbackID id); void Callback_process(void); Modified: trunk/sc2/src/libs/graphics/dcqueue.c =================================================================== --- trunk/sc2/src/libs/graphics/dcqueue.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/libs/graphics/dcqueue.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -216,6 +216,22 @@ UnlockRecursiveMutex (DCQ_Mutex); } +static void +checkExclusiveThread (void) +{ +#ifdef DEBUG_DCQ_THREADS + static uint32 exclusiveThreadId; + extern uint32 SDL_ThreadID(void); + + // Only one thread is currently allowed to enqueue commands + // This is not a technical limitation but rather a semantical one atm. + if (!exclusiveThreadId) + exclusiveThreadId = SDL_ThreadID(); + else + assert (SDL_ThreadID() == exclusiveThreadId); +#endif +} + void TFB_EnqueueDrawCommand (TFB_DrawCommand* DrawCommand) { @@ -224,6 +240,8 @@ return; } + checkExclusiveThread (); + if (DrawCommand->Type <= TFB_DRAWCOMMANDTYPE_COPYTOIMAGE && _CurFramePtr->Type == SCREEN_DRAWABLE) { Modified: trunk/sc2/src/libs/sound/trackint.h =================================================================== --- trunk/sc2/src/libs/sound/trackint.h 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/libs/sound/trackint.h 2012-02-11 23:41:06 UTC (rev 3761) @@ -17,6 +17,8 @@ #ifndef TRACKINT_H #define TRACKINT_H +#include "libs/callback.h" + struct tfb_soundchunk { TFB_SoundDecoder *decoder; // decoder for this chunk @@ -24,7 +26,7 @@ int tag_me; // set for chunks with subtitles uint32 track_num; // logical track #, comm code needs this UNICODE *text; // subtitle text - TFB_TrackCB callback; // comm callback, executed on chunk start + CallbackFunction callback; // comm callback, executed on chunk start struct tfb_soundchunk *next; }; Modified: trunk/sc2/src/libs/sound/trackplayer.c =================================================================== --- trunk/sc2/src/libs/sound/trackplayer.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/libs/sound/trackplayer.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -199,7 +199,8 @@ DoTrackTag (TFB_SoundChunk *chunk) { if (chunk->callback) - chunk->callback (); + Callback_add(chunk->callback, 0); + cur_sub_chunk = chunk; } @@ -421,7 +422,7 @@ // XXX: This code and the entire trackplayer are begging to be overhauled void -SpliceTrack (UNICODE *TrackName, UNICODE *TrackText, UNICODE *TimeStamp, TFB_TrackCB cb) +SpliceTrack (UNICODE *TrackName, UNICODE *TrackText, UNICODE *TimeStamp, CallbackFunction cb) { static UNICODE last_track_name[128] = ""; static unsigned long dec_offset = 0; Modified: trunk/sc2/src/libs/sound/trackplayer.h =================================================================== --- trunk/sc2/src/libs/sound/trackplayer.h 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/libs/sound/trackplayer.h 2012-02-11 23:41:06 UTC (rev 3761) @@ -20,9 +20,8 @@ #define TRACKPLAYER_H #include "libs/compiler.h" +#include "libs/callback.h" -typedef void (*TFB_TrackCB) (void); - #define ACCEL_SCROLL_SPEED 300 extern void PlayTrack (void); @@ -37,7 +36,7 @@ extern void FastReverse_Page (void); extern void FastForward_Page (void); -extern void SpliceTrack (UNICODE *filespec, UNICODE *textspec, UNICODE *TimeStamp, TFB_TrackCB cb); +extern void SpliceTrack (UNICODE *filespec, UNICODE *textspec, UNICODE *TimeStamp, CallbackFunction cb); extern void SpliceMultiTrack (UNICODE *TrackNames[], UNICODE *TrackText); extern int GetTrackPosition (int in_units); Modified: trunk/sc2/src/libs/video/video.c =================================================================== --- trunk/sc2/src/libs/video/video.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/libs/video/video.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -127,7 +127,6 @@ _cur_speech = 0; _cur_video = NULL_VIDEO_REF; - LockMutex (GraphicsLock); // play video in the center of the screen if (TFB_PlayVideo (vid, (ScreenWidth - vid->w) / 2, (ScreenHeight - vid->h) / 2)) @@ -144,7 +143,6 @@ { ret = NO_FMV; } - UnlockMutex (GraphicsLock); return ret; } Modified: trunk/sc2/src/libs/video/vidintrn.h =================================================================== --- trunk/sc2/src/libs/video/vidintrn.h 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/libs/video/vidintrn.h 2012-02-11 23:41:06 UTC (rev 3761) @@ -38,10 +38,4 @@ MUSIC_REF speechref; }; -// XXX: There has to be a better way to synchronize gfx calls with the rest -// of the game. The only thing we need to sync is the current context, and -// even there only the cliprect. Perhaps a DCQ command that takes an -// explicit cliprect would be better. -extern Mutex GraphicsLock; - #endif Modified: trunk/sc2/src/libs/video/vidplayer.c =================================================================== --- trunk/sc2/src/libs/video/vidplayer.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/libs/video/vidplayer.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -143,14 +143,12 @@ vid->cur_frame = vid->decoder->cur_frame; // draw the frame - LockMutex (GraphicsLock); // We have the cliprect precalculated and don't need the rest oldContext = SetContext (NULL); TFB_DrawScreen_Image (vid->frame, vid->dst_rect.corner.x, vid->dst_rect.corner.y, 0, 0, NULL, DRAW_REPLACE_MODE, TFB_SCREEN_MAIN); SetContext (oldContext); - UnlockMutex (GraphicsLock); FlushGraphics (); // needed to prevent half-frame updates // increase interframe with positive lag-count to allow audio to catch up @@ -195,14 +193,12 @@ vid->cur_frame = vid->decoder->cur_frame; - LockMutex (GraphicsLock); // We have the cliprect precalculated and don't need the rest oldContext = SetContext (NULL); TFB_DrawScreen_Image (vid->frame, vid->dst_rect.corner.x, vid->dst_rect.corner.y, 0, 0, NULL, DRAW_REPLACE_MODE, TFB_SCREEN_MAIN); SetContext (oldContext); - UnlockMutex (GraphicsLock); FlushGraphics (); // needed to prevent half-frame updates if (vid->cur_frame == vid->loop_frame) Modified: trunk/sc2/src/uqm/battle.c =================================================================== --- trunk/sc2/src/uqm/battle.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/battle.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -302,7 +302,6 @@ } #endif - LockMutex (GraphicsLock); if (bs->first_time) { r.corner.x = SIS_ORG_X; @@ -325,7 +324,6 @@ ScreenTransition (3, &r); } UnbatchGraphics (); - UnlockMutex (GraphicsLock); if ((!(GLOBAL (CurrentActivity) & IN_BATTLE)) || (GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))) { @@ -399,7 +397,6 @@ { SIZE num_ships; - LockMutex (GraphicsLock); #if !(DEMO_MODE || CREATE_JOURNAL) if (LOBYTE (GLOBAL (CurrentActivity)) != SUPER_MELEE) { @@ -469,9 +466,7 @@ bs.first_time = (BOOLEAN)(LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE); - UnlockMutex (GraphicsLock); DoInput (&bs, FALSE); - LockMutex (GraphicsLock); AbortBattle: if (LOBYTE (GLOBAL (CurrentActivity)) == SUPER_MELEE) @@ -481,12 +476,10 @@ // Do not return to the main menu when a game is aborted, // (just to the supermelee menu). #ifdef NETPLAY - UnlockMutex (GraphicsLock); waitResetConnections(NetState_inSetup); // A connection may already be in inSetup (set from // GetMeleeStarship). This is not a problem, although // it will generate a warning in debug mode. - LockMutex (GraphicsLock); #endif GLOBAL (CurrentActivity) &= ~CHECK_ABORT; @@ -514,7 +507,6 @@ UninitShips (); FreeBattleSong (); - UnlockMutex (GraphicsLock); return (BOOLEAN) (num_ships < 0); } Modified: trunk/sc2/src/uqm/battle.h =================================================================== --- trunk/sc2/src/uqm/battle.h 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/battle.h 2012-02-11 23:41:06 UTC (rev 3761) @@ -31,8 +31,7 @@ #endif // The callback function is called on every battle frame -// with GraphicsLock held, just before the display queue -// is drawn +// just before the display queue is drawn typedef void (BattleFrameCallback) (void); typedef struct battlestate_struct { Modified: trunk/sc2/src/uqm/build.c =================================================================== --- trunk/sc2/src/uqm/build.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/build.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -144,9 +144,7 @@ InsertQueue (&GLOBAL (built_ship_q), hStarShip, hOldShip); } - LockMutex (GraphicsLock); DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA); - UnlockMutex (GraphicsLock); return i; } @@ -389,9 +387,7 @@ if (count > 0) { // Update the display. - LockMutex (GraphicsLock); DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA); - UnlockMutex (GraphicsLock); } return count; Modified: trunk/sc2/src/uqm/clock.c =================================================================== --- trunk/sc2/src/uqm/clock.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/clock.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -276,7 +276,6 @@ return (0); } -// This function must be called with GraphicsLock held. void GameClockTick (void) { @@ -299,7 +298,6 @@ UnlockMutex (clock_mutex); } -// This function must be called with GraphicsLock held. void MoveGameClockDays (COUNT days) { Modified: trunk/sc2/src/uqm/cnctdlg.c =================================================================== --- trunk/sc2/src/uqm/cnctdlg.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/cnctdlg.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -531,14 +531,12 @@ r.corner.x = (SCREEN_WIDTH - r.extent.width) >> 1; r.corner.y = (SCREEN_HEIGHT - r.extent.height) >> 1; - LockMutex (GraphicsLock); DrawShadowedBox (&r, SHADOWBOX_BACKGROUND_COLOR, SHADOWBOX_DARK_COLOR, SHADOWBOX_MEDIUM_COLOR); menu.draw ((WIDGET *)&menu, r.corner.x + 10, r.corner.y + 10); - UnlockMutex (GraphicsLock); } static BOOLEAN Modified: trunk/sc2/src/uqm/comm/comandr/comandr.c =================================================================== --- trunk/sc2/src/uqm/comm/comandr/comandr.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/comm/comandr/comandr.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -227,10 +227,8 @@ { NPCPhrase (HERE_IS_A_NEW_LANDER); ++GLOBAL_SIS (NumLanders); - LockMutex (GraphicsLock); DrawLanders (); DeltaSISGauges (4, 0, 0); - UnlockMutex (GraphicsLock); SET_GAME_STATE (LANDERS_LOST, 1); } @@ -238,27 +236,21 @@ { NPCPhrase (HERE_IS_ANOTHER_LANDER); ++GLOBAL_SIS (NumLanders); - LockMutex (GraphicsLock); DrawLanders (); DeltaSISGauges (4, 0, 0); - UnlockMutex (GraphicsLock); } else if (PLAYER_SAID (R, need_fuel_mercury) || PLAYER_SAID (R, need_fuel_luna)) { NPCPhrase (GIVE_FUEL); - LockMutex (GraphicsLock); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); - UnlockMutex (GraphicsLock); SET_GAME_STATE (GIVEN_FUEL_BEFORE, 1); } else if (PLAYER_SAID (R, need_fuel_again)) { NPCPhrase (GIVE_FUEL_AGAIN); - LockMutex (GraphicsLock); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); - UnlockMutex (GraphicsLock); } if (GLOBAL_SIS (ElementAmounts[RADIOACTIVE])) @@ -297,10 +289,8 @@ { NPCPhrase (HERE_IS_A_NEW_LANDER); ++GLOBAL_SIS (NumLanders); - LockMutex (GraphicsLock); DrawLanders (); DeltaSISGauges (4, 0, 0); - UnlockMutex (GraphicsLock); SET_GAME_STATE (LANDERS_LOST, 1); } @@ -308,27 +298,21 @@ { NPCPhrase (HERE_IS_ANOTHER_LANDER); ++GLOBAL_SIS (NumLanders); - LockMutex (GraphicsLock); DrawLanders (); DeltaSISGauges (4, 0, 0); - UnlockMutex (GraphicsLock); } else if (PLAYER_SAID (R, need_fuel_mercury) || PLAYER_SAID (R, need_fuel_luna)) { NPCPhrase (GIVE_FUEL); - LockMutex (GraphicsLock); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); - UnlockMutex (GraphicsLock); SET_GAME_STATE (GIVEN_FUEL_BEFORE, 1); } else if (PLAYER_SAID (R, need_fuel_again)) { NPCPhrase (GIVE_FUEL_AGAIN); - LockMutex (GraphicsLock); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); - UnlockMutex (GraphicsLock); } else if (PLAYER_SAID (R, where_get_radios)) { @@ -399,10 +383,8 @@ { NPCPhrase (HERE_IS_A_NEW_LANDER); ++GLOBAL_SIS (NumLanders); - LockMutex (GraphicsLock); DrawLanders (); DeltaSISGauges (4, 0, 0); - UnlockMutex (GraphicsLock); SET_GAME_STATE (LANDERS_LOST, 1); } @@ -410,27 +392,21 @@ { NPCPhrase (HERE_IS_ANOTHER_LANDER); ++GLOBAL_SIS (NumLanders); - LockMutex (GraphicsLock); DrawLanders (); DeltaSISGauges (4, 0, 0); - UnlockMutex (GraphicsLock); } else if (PLAYER_SAID (R, need_fuel_mercury) || PLAYER_SAID (R, need_fuel_luna)) { NPCPhrase (GIVE_FUEL); - LockMutex (GraphicsLock); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); - UnlockMutex (GraphicsLock); SET_GAME_STATE (GIVEN_FUEL_BEFORE, 1); } else if (PLAYER_SAID (R, need_fuel_again)) { NPCPhrase (GIVE_FUEL_AGAIN); - LockMutex (GraphicsLock); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); - UnlockMutex (GraphicsLock); } else if (PLAYER_SAID (R, we_are_here_to_help)) { @@ -593,9 +569,7 @@ NPCPhrase (FUEL_UP1); AlienTalkSegue (1); - LockMutex (GraphicsLock); CommData.AlienAmbientArray[2].AnimFlags |= ANIM_DISABLED; - UnlockMutex (GraphicsLock); XFormColorMap (GetColorMapAddress ( SetAbsColorMapIndex (CommData.AlienColorMap, 0) Modified: trunk/sc2/src/uqm/comm/druuge/druugec.c =================================================================== --- trunk/sc2/src/uqm/comm/druuge/druugec.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/comm/druuge/druugec.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -244,9 +244,7 @@ NPCPhrase (NOT_ENOUGH_ROOM); else { - LockMutex (GraphicsLock); DeltaSISGauges (-SHIP_CREW_COST, 0, 0); - UnlockMutex (GraphicsLock); SlaveryCount += SHIP_CREW_COST; AddEscortShips (DRUUGE_SHIP, 1); @@ -260,9 +258,7 @@ NPCPhrase (NOT_ENOUGH_CREW); else { - LockMutex (GraphicsLock); DeltaSISGauges (-ARTIFACT_CREW_COST, 0, 0); - UnlockMutex (GraphicsLock); SlaveryCount += ARTIFACT_CREW_COST; SET_GAME_STATE (ROSY_SPHERE_ON_SHIP, 1); SET_GAME_STATE (ROSY_SPHERE, 1); @@ -276,9 +272,7 @@ NPCPhrase (NOT_ENOUGH_CREW); else { - LockMutex (GraphicsLock); DeltaSISGauges (-ARTIFACT_CREW_COST, 0, 0); - UnlockMutex (GraphicsLock); SlaveryCount += ARTIFACT_CREW_COST; SET_GAME_STATE (ARTIFACT_2_ON_SHIP, 1); @@ -291,9 +285,7 @@ NPCPhrase (NOT_ENOUGH_CREW); else { - LockMutex (GraphicsLock); DeltaSISGauges (-ARTIFACT_CREW_COST, 0, 0); - UnlockMutex (GraphicsLock); SlaveryCount += ARTIFACT_CREW_COST; SET_GAME_STATE (ARTIFACT_3_ON_SHIP, 1); @@ -307,10 +299,8 @@ NPCPhrase (NOT_ENOUGH_CREW); else { - LockMutex (GraphicsLock); DeltaSISGauges (-FUEL_CREW_COST, FUEL_CREW_COST * FUEL_TANK_SCALE, 0); - UnlockMutex (GraphicsLock); SlaveryCount += FUEL_CREW_COST; NPCPhrase (BOUGHT_FUEL); @@ -466,14 +456,12 @@ capacity -= GLOBAL_SIS (FuelOnBoard); f = (COUNT)((capacity + (FUEL_TANK_SCALE >> 1)) / FUEL_TANK_SCALE); - LockMutex (GraphicsLock); while (capacity > 0x3FFFL) { DeltaSISGauges (0, 0x3FFF, 0); capacity -= 0x3FFF; } DeltaSISGauges (0, (SIZE)capacity, 0); - UnlockMutex (GraphicsLock); NPCPhrase (FUEL0); NPCNumber (f, NULL); Modified: trunk/sc2/src/uqm/comm/melnorm/melnorm.c =================================================================== --- trunk/sc2/src/uqm/comm/melnorm/melnorm.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/comm/melnorm/melnorm.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -21,8 +21,6 @@ #include "strings.h" #include "uqm/gameev.h" -#include "uqm/setup.h" - // for GraphicsLock #include "uqm/shipcont.h" #include "libs/inplib.h" #include "libs/mathlib.h" @@ -590,9 +588,7 @@ if (fuel_required == 0) { GlobData.SIS_state = SIS_copy; - LockMutex (GraphicsLock); DeltaSISGauges (UNDEFINED_DELTA, rescue_fuel, UNDEFINED_DELTA); - UnlockMutex (GraphicsLock); } else if (fuel_required == (COUNT)~0) { @@ -616,9 +612,7 @@ GLOBAL_SIS (ModuleSlots[i]) = EMPTY_SLOT + 2; } - LockMutex (GraphicsLock); DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA); - UnlockMutex (GraphicsLock); } else if (fuel_required) { @@ -735,9 +729,7 @@ if (total == 0) { NPCPhrase (CHARITY); - LockMutex (GraphicsLock); DeltaSISGauges (0, fuel_required, 0); - UnlockMutex (GraphicsLock); return (FALSE); } else @@ -891,9 +883,7 @@ { Credit += delta_credit; SetAvailableCredits (Credit); - LockMutex (GraphicsLock); DrawStatusMessage (NULL); - UnlockMutex (GraphicsLock); return true; } @@ -1045,14 +1035,12 @@ NPCPhrase (GOT_FUEL); f = (DWORD)needed_credit * FUEL_TANK_SCALE; - LockMutex (GraphicsLock); while (f > 0x3FFFL) { DeltaSISGauges (0, 0x3FFF, 0); f -= 0x3FFF; } DeltaSISGauges (0, (SIZE)f, 0); - UnlockMutex (GraphicsLock); } needed_credit *= (BIO_CREDIT_VALUE / 2); } @@ -1251,9 +1239,7 @@ } while (GLOBAL_SIS (TotalBioMass)); SleepThread (ONE_SECOND / 2); - LockMutex (GraphicsLock); ClearSISRect (DRAW_SIS_DISPLAY); - UnlockMutex (GraphicsLock); } else /* if (R == sell_rainbow_locations) */ { @@ -1838,11 +1824,9 @@ static void post_melnorme_enc (void) { - LockMutex (GraphicsLock); if (prevMsgMode != SMM_UNDEFINED) SetStatusMessageMode (prevMsgMode); DrawStatusMessage (NULL); - UnlockMutex (GraphicsLock); } LOCDATA* Modified: trunk/sc2/src/uqm/comm/starbas/starbas.c =================================================================== --- trunk/sc2/src/uqm/comm/starbas/starbas.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/comm/starbas/starbas.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -1656,9 +1656,7 @@ else NPCPhrase (GLOBAL_SHIP_NAME); NPCPhrase (STARBASE_IS_READY_C); - LockMutex (GraphicsLock); DeltaSISGauges (0, 0, 2500); - UnlockMutex (GraphicsLock); SET_GAME_STATE (STARBASE_MONTH, GLOBAL (GameClock.month_index)); SET_GAME_STATE (STARBASE_DAY, @@ -1770,9 +1768,7 @@ Sleepy = FALSE; GLOBAL_SIS (ElementAmounts[i]) = 0; GLOBAL_SIS (TotalElementMass) -= amount; - LockMutex (GraphicsLock); DeltaSISGauges (0, 0, amount * GLOBAL (ElementWorth[i])); - UnlockMutex (GraphicsLock); break; } @@ -1781,10 +1777,8 @@ TaskSwitch (); TimeIn = GetTimeCounter (); DrawCargoStrings ((BYTE)i, (BYTE)i); - LockMutex (GraphicsLock); ShowRemainingCapacity (); DeltaSISGauges (0, 0, GLOBAL (ElementWorth[i])); - UnlockMutex (GraphicsLock); } while (--amount); } if (Sleepy) { @@ -1794,9 +1788,7 @@ } SleepThread (ONE_SECOND / 2); - LockMutex (GraphicsLock); ClearSISRect (DRAW_SIS_DISPLAY); - UnlockMutex (GraphicsLock); // DrawStorageBays (FALSE); if (total < 1000) Modified: trunk/sc2/src/uqm/comm/zoqfot/zoqfotc.c =================================================================== --- trunk/sc2/src/uqm/comm/zoqfot/zoqfotc.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/comm/zoqfot/zoqfotc.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -118,15 +118,12 @@ static int LastAlien; +// Queued and executes synchronously on the Starcon2Main thread static void -SelectAlienZOQ (void) +SelectAlienZOQ (CallbackArg arg) { if (LastAlien != ZOQ_ALIEN) { - // XXX: This should hold the GraphicsLock to block comm anims and - // prevent CommData half-updates, but if we do so, the stream - // decoder will deadlock with the drawing thread. - // Transition to neutral state first if Pik was talking if (LastAlien != FOT_ALIEN) CommData.AlienTransitionDesc.AnimFlags |= TALK_DONE; @@ -142,17 +139,16 @@ CommData.AlienTextFColor = ZOQ_FG_COLOR; CommData.AlienTextBColor = ZOQ_BG_COLOR; } + + (void)arg; // ignored } +// Queued and executes synchronously on the Starcon2Main thread static void -SelectAlienPIK (void) +SelectAlienPIK (CallbackArg arg) { if (LastAlien != PIK_ALIEN) { - // XXX: This should hold the GraphicsLock to block comm anims and - // prevent CommData half-updates, but if we do so, the stream - // decoder will deadlock with the drawing thread. - // Transition to neutral state first if Zoq was talking if (LastAlien != FOT_ALIEN) CommData.AlienTransitionDesc.AnimFlags |= TALK_DONE; @@ -168,13 +164,15 @@ CommData.AlienTextFColor = PIK_FG_COLOR; CommData.AlienTextBColor = PIK_BG_COLOR; } + + (void)arg; // ignored } static void ZFPTalkSegue (COUNT wait_track) { LastAlien = FOT_ALIEN; - SelectAlienZOQ (); + SelectAlienZOQ (0); AlienTalkSegue (wait_track); } Modified: trunk/sc2/src/uqm/comm.c =================================================================== --- trunk/sc2/src/uqm/comm.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/comm.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -632,13 +632,11 @@ CheckSubtitles (); } - LockMutex (GraphicsLock); // XXX: When seeking, all animations (talking and ambient) stop // progressing. This is an original 3DO behavior, and I see no // reason why the animations cannot continue while seeking. UpdateAnimations (pTS->seeking); UpdateSpeechGraphics (); - UnlockMutex (GraphicsLock); curTrack = PlayingTrack (); pTS->ended = !pTS->seeking && !curTrack; @@ -653,9 +651,7 @@ static void runCommAnimFrame (void) { - LockMutex (GraphicsLock); UpdateCommGraphics (); - UnlockMutex (GraphicsLock); SleepThread (COMM_ANIM_RATE); } @@ -764,13 +760,11 @@ if (!pCurInputState->Initialized) { InitSpeechGraphics (); - LockMutex (GraphicsLock); SetColorMap (GetColorMapAddress (CommData.AlienColorMap)); SetContext (AnimContext); DrawAlienFrame (NULL, 0, TRUE); UpdateSpeechGraphics (); CommIntroTransition (); - UnlockMutex (GraphicsLock); pCurInputState->Initialized = TRUE; @@ -845,7 +839,6 @@ r.extent.width = SIS_SCREEN_WIDTH; r.extent.height = SIS_SCREEN_HEIGHT - SLIDER_Y - SLIDER_HEIGHT + 2; - LockMutex (GraphicsLock); SetContext (AnimContext); SetContextForeGroundColor (COMM_HISTORY_BACKGROUND_COLOR); DrawFilledRectangle (&r); @@ -914,7 +907,6 @@ font_DrawText (&mt); } - UnlockMutex (GraphicsLock); pSS->PrintNext = FALSE; } @@ -934,9 +926,7 @@ &pES->response_list[pES->cur_response].response_text; utf8StringCopy (pES->phrase_buf, sizeof pES->phrase_buf, response_text->pStr); - LockMutex (GraphicsLock); FeedbackPlayerPhrase (pES->phrase_buf); - UnlockMutex (GraphicsLock); StopTrack (); ClearSubtitles (); SetSliderImage (SetAbsFrameIndex (ActivityFrame, 2)); @@ -955,29 +945,23 @@ { SUMMARY_STATE SummaryState; - LockMutex (GraphicsLock); if (pES) FeedbackPlayerPhrase (pES->phrase_buf); - UnlockMutex (GraphicsLock); SummaryState.Initialized = FALSE; DoConvSummary (&SummaryState); - LockMutex (GraphicsLock); if (pES) RefreshResponses (pES); clear_subtitles = TRUE; - UnlockMutex (GraphicsLock); } static void SelectReplay (ENCOUNTER_STATE *pES) { FadeMusic (BACKGROUND_VOL, ONE_SECOND); - LockMutex (GraphicsLock); if (pES) FeedbackPlayerPhrase (pES->phrase_buf); - UnlockMutex (GraphicsLock); TalkSegue (0); } @@ -990,9 +974,7 @@ if (pES->top_response == (BYTE)~0) { pES->top_response = 0; - LockMutex (GraphicsLock); RefreshResponses (pES); - UnlockMutex (GraphicsLock); } if (PulsedInputState.menu[KEY_MENU_SELECT]) @@ -1013,9 +995,7 @@ if (!(GLOBAL (CurrentActivity) & CHECK_ABORT)) { - LockMutex (GraphicsLock); RefreshResponses (pES); - UnlockMutex (GraphicsLock); FadeMusic (FOREGROUND_VOL, ONE_SECOND); } } @@ -1029,7 +1009,6 @@ { COORD y; - LockMutex (GraphicsLock); BatchGraphics (); add_text (-2, &pES->response_list[pES->cur_response].response_text); @@ -1049,12 +1028,9 @@ RefreshResponses (pES); } UnbatchGraphics (); - UnlockMutex (GraphicsLock); } - LockMutex (GraphicsLock); UpdateCommGraphics (); - UnlockMutex (GraphicsLock); SleepThreadUntil (pES->NextTime); pES->NextTime = GetTimeCounter () + COMM_ANIM_RATE; @@ -1094,9 +1070,7 @@ pLRS->TimeOut = FadeMusic (0, ONE_SECOND * 2) + ONE_SECOND / 60; } - LockMutex (GraphicsLock); UpdateCommGraphics (); - UnlockMutex (GraphicsLock); SleepThreadUntil (pLRS->NextTime); pLRS->NextTime = GetTimeCounter () + COMM_ANIM_RATE; @@ -1135,11 +1109,9 @@ return TRUE; } - LockMutex (GraphicsLock); SetContext (SpaceContext); DestroyContext (AnimContext); AnimContext = NULL; - UnlockMutex (GraphicsLock); FlushColorXForms (); ClearSubtitles (); @@ -1228,7 +1200,6 @@ SubtitleText.baseline = CommData.AlienTextBaseline; SubtitleText.align = CommData.AlienTextAlign; - LockMutex (GraphicsLock); // init subtitle cache context TextCacheContext = CreateContext ("TextCacheContext"); @@ -1293,7 +1264,6 @@ DrawSISComWindow (); } - UnlockMutex (GraphicsLock); LastActivity |= CHECK_LOAD; /* prevent spurious input */ (*CommData.init_encounter_func) (); @@ -1302,10 +1272,8 @@ (*CommData.post_encounter_func) (); (*CommData.uninit_encounter_func) (); - LockMutex (GraphicsLock); SetContext (SpaceContext); SetContextFont (OldFont); - UnlockMutex (GraphicsLock); DestroyStringTable (ReleaseStringTable (CommData.ConversationPhrases)); DestroyMusic (CommData.AlienSong); @@ -1343,7 +1311,6 @@ return 0; #endif - LockMutex (GraphicsLock); if (LastActivity & CHECK_LOAD) { @@ -1369,7 +1336,6 @@ } } - UnlockMutex (GraphicsLock); if (which_comm == URQUAN_DRONE_CONVERSATION) { Modified: trunk/sc2/src/uqm/commglue.c =================================================================== --- trunk/sc2/src/uqm/commglue.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/commglue.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -28,8 +28,10 @@ static int NPCNumberPhrase (int number, const char *fmt, UNICODE **ptrack); +// The CallbackFunction is queued and executes synchronously +// on the Starcon2Main thread void -NPCPhrase_cb (int index, TFB_TrackCB cb) +NPCPhrase_cb (int index, CallbackFunction cb) { UNICODE *pStr, buf[400]; void *pClip, *pTimeStamp; Modified: trunk/sc2/src/uqm/commglue.h =================================================================== --- trunk/sc2/src/uqm/commglue.h 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/commglue.h 2012-02-11 23:41:06 UTC (rev 3761) @@ -22,6 +22,7 @@ #include "globdata.h" #include "resinst.h" #include "libs/sound/trackplayer.h" +#include "libs/callback.h" #if defined(__cplusplus) extern "C" { @@ -88,7 +89,9 @@ response_func, UNICODE *ContstructStr); extern void DoNPCPhrase (UNICODE *pStr); -extern void NPCPhrase_cb (int index, TFB_TrackCB cb); +// The CallbackFunction is queued and executes synchronously +// on the Starcon2Main thread +extern void NPCPhrase_cb (int index, CallbackFunction cb); #define NPCPhrase(index) NPCPhrase_cb ((index), NULL) extern void NPCPhrase_splice (int index); extern void NPCNumber (int number, const char *fmt); Modified: trunk/sc2/src/uqm/confirm.c =================================================================== --- trunk/sc2/src/uqm/confirm.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/confirm.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -85,7 +85,6 @@ PauseFlash (); - LockMutex (GraphicsLock); { RECT r; STAMP s; @@ -160,7 +159,6 @@ SetContextClipRect (&oldRect); SetContext (oldContext); } - UnlockMutex (GraphicsLock); ContinueFlash (); @@ -217,7 +215,6 @@ label.lines = lines; PauseFlash (); - LockMutex (GraphicsLock); oldContext = SetContext (ScreenContext); GetContextClipRect (&oldRect); @@ -246,7 +243,6 @@ DestroyDrawable (ReleaseDrawable (s.frame)); SetContextClipRect (&oldRect); SetContext (oldContext); - UnlockMutex (GraphicsLock); ContinueFlash (); SetMenuSounds (s0, s1); StringBank_Free (bank); Modified: trunk/sc2/src/uqm/controls.h =================================================================== --- trunk/sc2/src/uqm/controls.h 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/controls.h 2012-02-11 23:41:06 UTC (rev 3761) @@ -119,9 +119,6 @@ void DoPopupWindow(const char *msg); typedef void (InputFrameCallback) (void); -// Anything using input callbacks MUST NOT keep GraphicsLock across -// InputFunc executions. This also means NOT holding GraphicsLock -// when calling DoInput(). InputFrameCallback* SetInputCallback (InputFrameCallback *); // pInputState must point to a struct derived from INPUT_STATE_DESC void DoInput (void *pInputState, BOOLEAN resetInput); Modified: trunk/sc2/src/uqm/credits.c =================================================================== --- trunk/sc2/src/uqm/credits.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/credits.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -240,7 +240,6 @@ t.pStr = " "; t.CharCount = 1; - LockMutex (GraphicsLock); OldContext = SetContext (TempContext); // get font dimensions @@ -312,7 +311,6 @@ SetContextFGFrame (OldFrame); SetContext (OldContext); - UnlockMutex (GraphicsLock); return f; } @@ -331,7 +329,6 @@ STAMP s; int i; - LockMutex (GraphicsLock); oldContext = SetContext (targetContext); // draw background s.origin.x = 0; @@ -358,7 +355,6 @@ } SetContext (oldContext); - UnlockMutex (GraphicsLock); } static void @@ -373,7 +369,6 @@ LocalContext = CreateContext ("Credits.LocalContext"); DrawContext = CreateContext ("Credits.DrawContext"); - LockMutex (GraphicsLock); targetFrame = GetContextFGFrame (); GetContextClipRect (&ctxRect); CreditsExtent = ctxRect.extent; @@ -402,7 +397,6 @@ SetContextFGFrame (targetFrame); SetContext (oldContext); - UnlockMutex (GraphicsLock); // Prepare the first screen frame RenderCreditsScreen (LocalContext); @@ -493,12 +487,10 @@ s.origin.y = 0; s.frame = CreditsFrame; - LockMutex (GraphicsLock); OldContext = SetContext (DrawContext); DrawStamp (&s); SetContext (OldContext); FlushGraphics (); - UnlockMutex (GraphicsLock); // prepare next screen frame deficitHeight = calcDeficitHeight (); @@ -782,13 +774,11 @@ hMusic = LoadMusic (CREDITS_MUSIC); - LockMutex (GraphicsLock); SetContext (ScreenContext); SetContextClipRect (NULL); GetContextClipRect (&screenRect); SetContextBackGroundColor (BLACK_COLOR); ClearDrawable (); - UnlockMutex (GraphicsLock); if (!LoadCredits ()) return; @@ -797,10 +787,8 @@ s.origin.x = 0; s.origin.y = 0; s.frame = CreditsBack; - LockMutex (GraphicsLock); DrawStamp (&s); FadeScreen (FadeAllToColor, ONE_SECOND / 2); - UnlockMutex (GraphicsLock); // set the position of outtakes comm CommWndRect.corner.x = (screenRect.extent.width - CommWndRect.extent.width) @@ -836,11 +824,9 @@ FadeMusic (0, ONE_SECOND / 2); UninitCredits (); - LockMutex (GraphicsLock); SetContext (ScreenContext); SleepThreadUntil (FadeScreen (FadeAllToBlack, ONE_SECOND / 2)); FlushColorXForms (); - UnlockMutex (GraphicsLock); if (hMusic) { Modified: trunk/sc2/src/uqm/encount.c =================================================================== --- trunk/sc2/src/uqm/encount.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/encount.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -78,9 +78,7 @@ if (!GameOptions ()) return FALSE; DrawMenuStateStrings (PM_CONVERSE, pMS->CurState); - LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); break; default: printf ("Unknown option: %d\n", pMS->CurState); @@ -270,7 +268,6 @@ extern FRAME planet[]; MUSIC_REF MR; - LockMutex (GraphicsLock); SetContext (SpaceContext); SetContextFont (TinyFont); @@ -278,11 +275,9 @@ MR = LoadMusic (REDALERT_MUSIC); PlayMusic (MR, FALSE, 1); SegueFrame = CaptureDrawable (LoadGraphic (SEGUE_PMAP_ANIM)); - UnlockMutex (GraphicsLock); WaitForSoundEnd (TFBSOUND_WAIT_ALL); StopMusic (); DestroyMusic (MR); - LockMutex (GraphicsLock); s.origin.x = s.origin.y = 0; SetTransitionSource (NULL); @@ -394,7 +389,6 @@ DestroyDrawable (ReleaseDrawable (SegueFrame)); ScreenTransition (3, NULL); - UnlockMutex (GraphicsLock); { MENU_STATE MenuState; @@ -403,15 +397,11 @@ MenuState.Initialized = FALSE; DrawMenuStateStrings (PM_CONVERSE, MenuState.CurState = HAIL); - LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); DoInput (&MenuState, TRUE); - LockMutex (GraphicsLock); SetFlashRect (NULL); - UnlockMutex (GraphicsLock); return (MenuState.CurState); } @@ -451,10 +441,8 @@ { for (i = 0; i < (SIZE) NUM_FADES; ++i) { - UnlockMutex (GraphicsLock); if (AnyButtonPress (TRUE)) i = NUM_FADES - 1; - LockMutex (GraphicsLock); SetContextForeGroundColor (fade_cycle[i]); font_DrawText (&t1); @@ -467,10 +455,8 @@ { for (i = NUM_FADES - 1; i >= 0; --i) { - UnlockMutex (GraphicsLock); if (AnyButtonPress (TRUE)) i = 0; - LockMutex (GraphicsLock); SetContextForeGroundColor (fade_cycle[i]); font_DrawText (&t1); @@ -492,7 +478,6 @@ ships_killed = 0; - LockMutex (GraphicsLock); free_gravity_well (); if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) @@ -702,10 +687,8 @@ TimeCount Time = GetTimeCounter (); for (j = 0; j < NUM_SHIP_FADES; ++j) { - UnlockMutex (GraphicsLock); Sleepy = (BOOLEAN)!AnyButtonPress (TRUE) && !(GLOBAL (CurrentActivity) & CHECK_ABORT); - LockMutex (GraphicsLock); if (!Sleepy) break; @@ -738,9 +721,7 @@ DestroyDrawable (ReleaseDrawable (s.frame)); #endif /* NEVER */ - UnlockMutex (GraphicsLock); WaitForAnyButton (TRUE, ONE_SECOND * 3, FALSE); - LockMutex (GraphicsLock); if (!CurrentInputState.key[PlayerControls[0]][KEY_ESCAPE]) { DrawFadeText (str1, str2, FALSE, &scavenge_r); @@ -766,9 +747,7 @@ str2 = GAME_STRING (ENCOUNTER_STRING_BASE + 7); // "Scavenged" DrawFadeText (str1, str2, TRUE, &scavenge_r); - UnlockMutex (GraphicsLock); WaitForAnyButton (TRUE, ONE_SECOND * 2, FALSE); - LockMutex (GraphicsLock); if (!CurrentInputState.key[PlayerControls[0]][KEY_ESCAPE]) DrawFadeText (str1, str2, FALSE, &scavenge_r); } @@ -787,7 +766,6 @@ } } ExitUninitEncounter: - UnlockMutex (GraphicsLock); return (ships_killed); } @@ -799,7 +777,6 @@ extern UWORD nth_frame; InputContext *savedPlayerInput = NULL; - LockMutex (GraphicsLock); SET_GAME_STATE (BATTLE_SEGUE, 1); @@ -838,9 +815,7 @@ GameSounds = CaptureSound (LoadSound (GAME_SOUNDS)); - UnlockMutex (GraphicsLock); Battle (NULL); - LockMutex (GraphicsLock); DestroySound (ReleaseSound (GameSounds)); GameSounds = 0; @@ -864,6 +839,5 @@ GLOBAL (CurrentActivity) = OldActivity; - UnlockMutex (GraphicsLock); } Modified: trunk/sc2/src/uqm/flash.c =================================================================== --- trunk/sc2/src/uqm/flash.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/flash.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -36,8 +36,6 @@ #define FLASH_INTERNAL #include "flash.h" -#include "setup.h" - // For GraphicsLock. #include "libs/log.h" #include "libs/memlib.h" #include "libs/threadlib.h" @@ -545,7 +543,6 @@ if (context->original != (FRAME) 0) DestroyDrawable (ReleaseDrawable (context->original)); - LockMutex (GraphicsLock); oldGfxContext = SetContext (context->gfxContext); context->original = CaptureDrawable (CopyContextRect (&context->rect)); SetContext (oldGfxContext); @@ -553,7 +550,6 @@ // CopyContextRect() may have queued the command to read // a rectangle from the screen; a FlushGraphics() // is necessary to ensure that it can actually be used. - UnlockMutex (GraphicsLock); } static inline void @@ -589,7 +585,6 @@ Flash_blendFraction (context, numer, denom, &blendedNumer, &blendedDenom); - LockMutex (GraphicsLock); oldGfxContext = SetContext (workGfxContext); SetContextFGFrame (dest); @@ -650,7 +645,6 @@ } SetContext (oldGfxContext); - UnlockMutex (GraphicsLock); } // Prepare an entry in the cache. @@ -686,7 +680,6 @@ CONTEXT oldGfxContext; STAMP stamp; - LockMutex (GraphicsLock); oldGfxContext = SetContext (context->gfxContext); stamp.origin = context->rect.corner; @@ -694,7 +687,6 @@ DrawStamp(&stamp); SetContext (oldGfxContext); - UnlockMutex (GraphicsLock); } static void Modified: trunk/sc2/src/uqm/fmv.c =================================================================== --- trunk/sc2/src/uqm/fmv.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/fmv.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -79,13 +79,11 @@ DWORD TimeOut; SleepThreadUntil (FadeScreen (FadeAllToBlack, ONE_SECOND / 120)); - LockMutex (GraphicsLock); SetContext (ScreenContext); s.origin.x = s.origin.y = 0; s.frame = CaptureDrawable (LoadGraphic (TITLE_ANIM)); DrawStamp (&s); DestroyDrawable (ReleaseDrawable (s.frame)); - UnlockMutex (GraphicsLock); TimeOut = FadeScreen (FadeAllToColor, ONE_SECOND / 2); Modified: trunk/sc2/src/uqm/gameopt.c =================================================================== --- trunk/sc2/src/uqm/gameopt.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/gameopt.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -167,9 +167,7 @@ break; } - LockMutex (GraphicsLock); DrawStatusMessage (buf); - UnlockMutex (GraphicsLock); } #define DDSHS_NORMAL 0 @@ -229,7 +227,6 @@ lf.align = ALIGN_CENTER; } - LockMutex (GraphicsLock); SetContext (StatusContext); SetContextFont (Font); lf.pStr = Str; @@ -253,14 +250,11 @@ if ((text_r.extent.width + 2) >= r.extent.width) { // the text does not fit the input box size and so // will not fit when displayed later - UnlockMutex (GraphicsLock); // disallow the change return (FALSE); } - UnlockMutex (GraphicsLock); PreUpdateFlashRect (); - LockMutex (GraphicsLock); SetContextForeGroundColor (BackGround); DrawFilledRectangle (&r); @@ -299,10 +293,9 @@ SetContextForeGroundColor (ForeGround); font_DrawText (&lf); - PostUpdateFlashRectLocked (); + PostUpdateFlashRect (); } - UnlockMutex (GraphicsLock); return (TRUE); } @@ -325,15 +318,11 @@ TEXTENTRY_STATE tes; UNICODE *Setting; - LockMutex (GraphicsLock); SetFlashRect (nameCaptain ? &captainNameRect : &shipNameRect); - UnlockMutex (GraphicsLock); DrawNameString (nameCaptain, buf, 0, DDSHS_EDIT); - LockMutex (GraphicsLock); DrawStatusMessage (GAME_STRING (NAMING_STRING_BASE + 0)); - UnlockMutex (GraphicsLock); if (nameCaptain) { @@ -359,9 +348,7 @@ else utf8StringCopy (buf, sizeof (buf), Setting); - LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); DrawNameString (nameCaptain, buf, 0, DDSHS_NORMAL); @@ -450,9 +437,7 @@ MenuState.InputFunc = DoSettings; DoInput (&MenuState, FALSE); - LockMutex (GraphicsLock); DrawStatusMessage (NULL); - UnlockMutex (GraphicsLock); } typedef struct @@ -677,10 +662,8 @@ r.corner.y = SIS_ORG_Y + 84; r.extent = OldRect.extent; SetContextClipRect (&r); - UnlockMutex (GraphicsLock); // draw the lander with upgrades InitLander (pSD->Flags | OVERRIDE_LANDER_FLAGS); - LockMutex (GraphicsLock); SetContextClipRect (&OldRect); SetContext (SpaceContext); @@ -941,11 +924,9 @@ if (NewState != pMS->CurState) { - LockMutex (GraphicsLock); pMS->CurState = NewState; SetContext (SpaceContext); RedrawPickDisplay (pickState, pMS->CurState); - UnlockMutex (GraphicsLock); } SleepThreadUntil (TimeIn + ONE_SECOND / 30); @@ -965,9 +946,7 @@ // TODO: fix ConfirmSaveLoad() interface so it does not rely on // MsgStamp != NULL parameter. - LockMutex (GraphicsLock); ConfirmSaveLoad (pickState->saving ? &saveStamp : NULL); - UnlockMutex (GraphicsLock); if (pickState->saving) success = SaveGame (gameIndex, desc); @@ -978,9 +957,7 @@ // display a load problem message if (pickState->saving) { // restore the screen under "SAVING..." message - LockMutex (GraphicsLock); DrawStamp (&saveStamp); - UnlockMutex (GraphicsLock); } DestroyDrawable (ReleaseDrawable (saveStamp.frame)); @@ -1015,12 +992,10 @@ LoadGameDescriptions (pickState.summary); - LockMutex (GraphicsLock); OldContext = SetContext (SpaceContext); // Save the current state of the screen for later restoration DlgStamp = SaveContextFrame (NULL); GetContextClipRect (&DlgRect); - UnlockMutex (GraphicsLock); SleepThreadUntil (TimeOut); PauseMusic (); @@ -1028,7 +1003,6 @@ FadeMusic (NORMAL_VOLUME, 0); // draw the current savegame and fade in - LockMutex (GraphicsLock); SetTransitionSource (NULL); BatchGraphics (); @@ -1050,7 +1024,6 @@ ScreenTransition (3, &ctxRect); UnbatchGraphics (); } - UnlockMutex (GraphicsLock); SetMenuSounds (MENU_SOUND_ARROWS | MENU_SOUND_PAGEUP | MENU_SOUND_PAGEDOWN, 0); @@ -1076,9 +1049,7 @@ // reload and redraw everything LoadGameDescriptions (pickState.summary); - LockMutex (GraphicsLock); RedrawPickDisplay (&pickState, MenuState.CurState); - UnlockMutex (GraphicsLock); } SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); @@ -1091,20 +1062,16 @@ if (!(GLOBAL (CurrentActivity) & CHECK_ABORT) && (saving || (!pickState.success && !fromMainMenu))) { // Restore previous screen - LockMutex (GraphicsLock); SetTransitionSource (&DlgRect); BatchGraphics (); DrawStamp (&DlgStamp); ScreenTransition (3, &DlgRect); UnbatchGraphics (); - UnlockMutex (GraphicsLock); } DestroyDrawable (ReleaseDrawable (DlgStamp.frame)); - LockMutex (GraphicsLock); SetContext (OldContext); - UnlockMutex (GraphicsLock); ResumeMusic (); @@ -1132,14 +1099,10 @@ { case SAVE_GAME: case LOAD_GAME: - LockMutex (GraphicsLock); SetFlashRect (NULL); - UnlockMutex (GraphicsLock); if (PickGame (pMS->CurState == SAVE_GAME, FALSE)) return FALSE; - LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); break; case QUIT_GAME: if (ConfirmExit ()) @@ -1181,17 +1144,13 @@ MenuState.CurState = SAVE_GAME; DrawMenuStateStrings (PM_SAVE_GAME, MenuState.CurState); - LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); MenuState.InputFunc = DoGameOptions; DoInput (&MenuState, TRUE); - LockMutex (GraphicsLock); SetFlashRect (NULL); - UnlockMutex (GraphicsLock); return !(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)); } Modified: trunk/sc2/src/uqm/hyper.c =================================================================== --- trunk/sc2/src/uqm/hyper.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/hyper.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -1633,9 +1633,7 @@ if (!select) return TRUE; - LockMutex (GraphicsLock); SetFlashRect (NULL); - UnlockMutex (GraphicsLock); switch (pMS->CurState) { @@ -1675,9 +1673,7 @@ pMS->CurState = NAVIGATION; DrawMenuStateStrings (PM_STARMAP, pMS->CurState); } - LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); } return TRUE; @@ -1695,7 +1691,6 @@ OldContext = SetContext (SpaceContext); OldColor = SetContextBackGroundColor (BLACK_COLOR); - UnlockMutex (GraphicsLock); memset (&MenuState, 0, sizeof (MenuState)); MenuState.InputFunc = DoHyperspaceMenu; @@ -1703,14 +1698,11 @@ MenuState.CurState = STARMAP; DrawMenuStateStrings (PM_STARMAP, STARMAP); - LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); DoInput (&MenuState, TRUE); - LockMutex (GraphicsLock); SetFlashRect (NULL); SetContext (SpaceContext); @@ -1718,9 +1710,7 @@ if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))) { ClearSISRect (CLEAR_SIS_RADAR); - UnlockMutex (GraphicsLock); WaitForNoInput (ONE_SECOND / 2, FALSE); - LockMutex (GraphicsLock); } SetContextBackGroundColor (OldColor); Modified: trunk/sc2/src/uqm/intro.c =================================================================== --- trunk/sc2/src/uqm/intro.c 2012-02-06 17:43:46 UTC (rev 3760) +++ trunk/sc2/src/uqm/intro.c 2012-02-11 23:41:06 UTC (rev 3761) @@ -160,7 +160,6 @@ if (!pPIS->Batched) { pPIS->Batched = TRUE; - LockMutex (GraphicsLock); BatchGraphics (); } } @@ -171,7 +170,6 @@ if (pPIS->Batched) { UnbatchGraphics (); - UnlockMutex (GraphicsLock); pPIS->Batched = FALSE; if (bYield) TaskSwitch (); @@ -196,7 +194,6 @@ COUNT piece; Color SisBack; - LockMutex (GraphicsLock); OldContext = SetContext (OffScreenContext); SkelFrame = CaptureDrawable (LoadGraphic (SISSKEL_MASK_PMAP_ANIM)); @@ -264,7 +261,6 @@ SetContext (OldContext); FlushGraphics (); - UnlockMutex (GraphicsLock); pPIS->SisFrame = SisFrame; } @@ -277,9 +273,7 @@ s.origin.x = 0; s.origin.y = 0; s.frame = SetAbsFrameIndex (pPIS->Frame, pPIS->MovieFrame); - LockMutex (GraphicsLock); DrawStamp (&s); - UnlockMutex (GraphicsLock); } static BOOLEAN @@ -362,9 +356,7 @@ /* center on screen */ pPIS->clip_r.corner.x = (SCREEN_WIDTH - w) / 2; pPIS->clip_r.corner.y = (SCREEN_HEIGHT - h) / 2; - LockMutex (GraphicsLock); SetContextClipRect (&pPIS->clip_r); - UnlockMutex (GraphicsLock); } } else if (strcmp (Opcode, "FONT") == 0) @@ -390,11 +382,7 @@ *pFont = LoadFontFile (pPIS->Buffer); } - if (!pPIS->Batched) - LockMutex (GraphicsLock); SetContextFont (*pFont); - if (!pPIS->Batched) - UnlockMutex (GraphicsLock); } else if (strcmp (Opcode, "ANI") == 0) { /* set ani */ @@ -490,12 +478,8 @@ t.CharCount = (COUNT)~0; t.baseline.x = x; t.baseline.y = y; - if (!pPIS->Batched) - LockMutex (GraphicsLock); DrawTextEffect (&t, pPIS->TextColor, pPIS->TextBackColor, pPIS->TextEffect); - if (!pPIS->Batched) - UnlockMutex (GraphicsLock); } } else if (strcmp (Opcode, "TFI") == 0) @@ -510,9 +494,7 @@ Present_UnbatchGraphics (pPIS, TRUE); - LockMutex (GraphicsLock); GetContextFontLeading (&leading); - UnlockMutex (GraphicsLock); switch (pPIS->TextVPos) { @@ -536,7 +518,6 @@ pPIS->TextLines[i].baseline.y = y; } - LockMutex (GraphicsLock); for (i = 0; i < pPIS->LinesCount; ++i) DrawTextEffect (pPIS->TextLines + i, pPIS->TextFadeColor, pPIS->TextFadeColor, pPIS->TextEffect); @@ -550,7 +531,6 @@ ScreenTransition (3, &pPIS->tfade_r); UnbatchGraphics (); - UnlockMutex (GraphicsLock); } else if (strcmp (Opcode, "TFO") == 0) { /* text fade-out */ @@ -558,7 +538,6 @@ Present_UnbatchGraphics (pPIS, TRUE); - LockMutex (GraphicsLock); /* do transition */ SetTransitionSource (&pPIS->tfade_r); BatchGraphics (); @@ -567,7 +546,6 @@ pPIS->TextFadeColor, pPIS->TextEffect); ScreenTransition (3, &pPIS->tfade_r); UnbatchGraphics (); - UnlockMutex (GraphicsLock); } else if (strcmp (Opcode, "SAVEBG") == 0) { /* save background */ @@ -652,15 +630,11 @@ } s.origin.x = x; s.origin.y = y; - if (!pPIS->Batched) - LockMutex (GraphicsLock); old_mode = SetGraphicScaleMode (scale_mode); old_scale = SetGraphicScale (scale); DrawStamp (&s); SetGraphicScale (old_scale); SetGraphicScaleMode (old_mode); - if (!pPIS->Batched) - UnlockMutex (GraphicsLock); } else if (strcmp (Opcode, "BATCH") == 0) { /* batch graphics */ @@ -689,9 +663,7 @@ { /* clear screen */ Present_UnbatchGraphics (pPIS, TRUE); - LockMutex (GraphicsLock); ClearDrawable (); - UnlockMutex (GraphicsLock); } else if (strcmp (Opcode, "CALL") == 0) { /* call another script */ @@ -712,12 +684,8 @@ l.second.x = x2; l.second.y = y2; - if (!pPIS->Batched) - LockMutex (GraphicsLock); SetContextForeGroundColor (pPIS->TextColor); DrawLine (&l); - if (!pPIS->Batched) - UnlockMutex (GraphicsLock); } else { @@ -771,12 +739,10 @@ pis.SlideShow = SetAbsStringTableIndex (pis.SlideShow, 0); pis.OperIndex = 0; - LockMutex ... [truncated message content] |
From: <Mee...@us...> - 2013-01-05 17:36:04
|
Revision: 3779 http://sc2.svn.sourceforge.net/sc2/?rev=3779&view=rev Author: Meep-Eep Date: 2013-01-05 17:35:49 +0000 (Sat, 05 Jan 2013) Log Message: ----------- Update; convert AUTHORS to UTF-8. Modified Paths: -------------- trunk/sc2/AUTHORS trunk/sc2/content/base/cutscene/credits/credits.txt Modified: trunk/sc2/AUTHORS =================================================================== --- trunk/sc2/AUTHORS 2012-02-26 21:05:46 UTC (rev 3778) +++ trunk/sc2/AUTHORS 2013-01-05 17:35:49 UTC (rev 3779) @@ -7,7 +7,7 @@ ------------------------- Core team (in alphabetical order): - Serge van den Boom <sv...@st...> + Serge van den Boom <se...@vd...> Mika Kolehmainen <mk...@ka...> Michael Chapman Martin <mcm...@gm...> Chris Nelson <ch...@to...> @@ -19,13 +19,18 @@ Music remixers (in alphabetical order): Jouni Airaksinen <mar...@sp...> - Tore Aune Fjellstad - Espen G\xE4tzschmann + András Barják <for...@fr...> + Matt Bentley + Tore Aune Fjellstad <vo...@me...> + Espen Gätzschmann <ti...@me...> Aaron J. Grier <ag...@po...> + A. Keren + Casey Monroe Dan Nicholson <da...@ko...> George Nowik <no...@at...> - Riku Nuottaj\xE4rvi <rik...@pp...> + Riku Nuottajärvi <rik...@pp...> Erol Otus <er...@to...> + Greg Szymanski Other contributions (in alphabetical order): Jouni Airaksinen <mar...@sp...> (Startup Menu) @@ -138,7 +143,7 @@ Music: Burke Treischmann Dan Nicholson - Riku Nuottaj\xE4rvi + Riku Nuottajärvi Eric Berge Erol Otus Marc Brown Modified: trunk/sc2/content/base/cutscene/credits/credits.txt =================================================================== --- trunk/sc2/content/base/cutscene/credits/credits.txt 2012-02-26 21:05:46 UTC (rev 3778) +++ trunk/sc2/content/base/cutscene/credits/credits.txt 2013-01-05 17:35:49 UTC (rev 3779) @@ -61,13 +61,18 @@ #(Music remixers) 13 C Jouni Airaksinen +András Barják +Matt Bentley Tore Aune Fjellstad Espen Gätzschmann Aaron J. Grier +A. Keren +Casey Monroe Dan Nicholson George Nowik Riku Nuottajärvi Erol Otus +Greg Szymanski #(Other contrib caption) 13 C This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mcm...@us...> - 2013-02-19 03:23:29
|
Revision: 3780 http://sourceforge.net/p/sc2/code/3780 Author: mcmartin Date: 2013-02-19 03:23:27 +0000 (Tue, 19 Feb 2013) Log Message: ----------- Update the Win32 installer to fit the new site design and to make Remix Pack 4 available. Juggle some file locations to make it easier to run the NSI script directly out of the win32_install directory. The installer code is still kind of a mess, but this makes it more reliable than the old 0.7 installer from a user experience standpoint. Modified Paths: -------------- trunk/sc2/build/win32_install/packages.nsh trunk/sc2/build/win32_install/uqm-installer.nsi trunk/sc2/doc/users/manual.txt Added Paths: ----------- trunk/sc2/build/win32_install/uqm-3do.cfg trunk/sc2/build/win32_install/uqm-pc.cfg Modified: trunk/sc2/build/win32_install/packages.nsh =================================================================== --- trunk/sc2/build/win32_install/packages.nsh 2013-01-05 17:35:49 UTC (rev 3779) +++ trunk/sc2/build/win32_install/packages.nsh 2013-02-19 03:23:27 UTC (rev 3780) @@ -18,3 +18,6 @@ !define PKG_REMIX3_FILE "uqm-remix-disc3.uqm" !define PKG_REMIX3_MD5SUM "5ccc6d4ac301ae98e172ac6835dcdead" !define PKG_REMIX3_SIZE 38989 +!define PKG_REMIX4_FILE "uqm-remix-disc4.uqm" +!define PKG_REMIX4_MD5SUM "d3dc6036588662391a3820ca6b222dd6" +!define PKG_REMIX4_SIZE 84517 \ No newline at end of file Added: trunk/sc2/build/win32_install/uqm-3do.cfg =================================================================== --- trunk/sc2/build/win32_install/uqm-3do.cfg (rev 0) +++ trunk/sc2/build/win32_install/uqm-3do.cfg 2013-02-19 03:23:27 UTC (rev 3780) @@ -0,0 +1,11 @@ +3domusic = BOOLEAN:true +textmenu = BOOLEAN:false +textgradients = BOOLEAN:false +subtitles = BOOLEAN:false +iconicscan = BOOLEAN:true +3domovies = BOOLEAN:true +speechvol = INT32:100 +pulseshield = BOOLEAN:true +smoothmelee = BOOLEAN:true +smoothscroll = BOOLEAN:true +remixmusic = BOOLEAN:false Modified: trunk/sc2/build/win32_install/uqm-installer.nsi =================================================================== --- trunk/sc2/build/win32_install/uqm-installer.nsi 2013-01-05 17:35:49 UTC (rev 3779) +++ trunk/sc2/build/win32_install/uqm-installer.nsi 2013-02-19 03:23:27 UTC (rev 3780) @@ -14,6 +14,10 @@ !define PRODUCT_UNINST_ROOT_KEY "HKLM" !define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir" +; The INSTALLER_VERSION is a suffix to the version number for installer patches or to mark +; alpha/beta/release candidate status. In normal releases it is the empty string. +!define INSTALLER_VERSION "-1" + ; UQM Package definitions !include "packages.nsh" @@ -80,7 +84,7 @@ ; MUI end ------ Name "${PRODUCT_NAME} ${PRODUCT_VERSION}" -OutFile "uqm-${PRODUCT_VERSION}-installer.exe" +OutFile "uqm-${PRODUCT_VERSION}${INSTALLER_VERSION}-installer.exe" InstallDir "$PROGRAMFILES\The Ur-Quan Masters\" InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" "" ShowInstDetails show @@ -125,115 +129,75 @@ Function RandomServer Push $0 - Push 27 + Push 17 Call Random Pop $0 IntCmp $0 0 0 +4 +4 - StrCpy $0 "ovh" + StrCpy $0 "aarnet" Exch $0 Return IntCmp $0 1 0 +4 +4 - StrCpy $0 "mesh" + StrCpy $0 "citylan" Exch $0 Return IntCmp $0 2 0 +4 +4 - StrCpy $0 "aarnet" + StrCpy $0 "freefr" Exch $0 Return IntCmp $0 3 0 +4 +4 - StrCpy $0 "switch" + StrCpy $0 "garr" Exch $0 Return IntCmp $0 4 0 +4 +4 - StrCpy $0 "superb-sea2" + StrCpy $0 "heanet" Exch $0 Return IntCmp $0 5 0 +4 +4 - StrCpy $0 "jaist" + StrCpy $0 "hivelocity" Exch $0 Return IntCmp $0 6 0 +4 +4 - StrCpy $0 "voxel" + StrCpy $0 "ignum" Exch $0 Return IntCmp $0 7 0 +4 +4 - StrCpy $0 "heanet" + StrCpy $0 "internode" Exch $0 Return IntCmp $0 8 0 +4 +4 - StrCpy $0 "cdnetworks-us-1" + StrCpy $0 "iweb" Exch $0 Return IntCmp $0 9 0 +4 +4 - StrCpy $0 "cdnetworks-us-2" + StrCpy $0 "jaist" Exch $0 Return IntCmp $0 10 0 +4 +4 - StrCpy $0 "cdnetworks-kr-1" + StrCpy $0 "nchc" Exch $0 Return IntCmp $0 11 0 +4 +4 - StrCpy $0 "surfnet" + StrCpy $0 "netcologne" Exch $0 Return IntCmp $0 12 0 +4 +4 - StrCpy $0 "cdnetworks-kr-2" + StrCpy $0 "switch" Exch $0 Return IntCmp $0 13 0 +4 +4 - StrCpy $0 "kent" + StrCpy $0 "tenet" Exch $0 Return IntCmp $0 14 0 +4 +4 - StrCpy $0 "nchc" + StrCpy $0 "ufpr" Exch $0 Return IntCmp $0 15 0 +4 +4 - StrCpy $0 "dfn" + StrCpy $0 "voxel" Exch $0 Return - IntCmp $0 16 0 +4 +4 - StrCpy $0 "freefr" + StrCpy $0 "waix" Exch $0 - Return - IntCmp $0 17 0 +4 +4 - StrCpy $0 "garr" - Exch $0 - Return - IntCmp $0 18 0 +4 +4 - StrCpy $0 "ignum" - Exch $0 - Return - IntCmp $0 19 0 +4 +4 - StrCpy $0 "internode" - Exch $0 - Return - IntCmp $0 20 0 +4 +4 - StrCpy $0 "iweb" - Exch $0 - Return - IntCmp $0 21 0 +4 +4 - StrCpy $0 "netcologne" - Exch $0 - Return - IntCmp $0 22 0 +4 +4 - StrCpy $0 "leaseweb" - Exch $0 - Return - IntCmp $0 23 0 +4 +4 - StrCpy $0 "ncu" - Exch $0 - Return - IntCmp $0 24 0 +4 +4 - StrCpy $0 "tenet" - Exch $0 - Return - IntCmp $0 25 0 +4 +4 - StrCpy $0 "transact" - Exch $0 - Return - StrCpy $0 "citylan" - Exch $0 FunctionEnd # To use: @@ -251,6 +215,7 @@ Exch $1 # File name Push $2 Push $3 + StrCpy $R9 0 # failure count # Check to make sure the file wasn't already installed IfFileExists "$0\$1" 0 NotThere md5dll::GetFileMD5 "$0\$1" @@ -289,6 +254,12 @@ StrCmp $2 "success" DownloadSuccessful StrCmp $2 "cancel" DownloadCanceled StrCpy $2 "Could not install the package $1 due to the following error: $\"$2$\"." + # Only actually display the error every third try, unless it's a user cancellation. We can't + # really rely on SF.net to have everything at every mirror. + IntOp $R9 $R9 + 1 + IntCmp $R9 3 0 AttemptDownload + # If we fell through, reset the count. + StrCpy $R9 0 Goto CheckMandatory DownloadCanceled: StrCpy $2 "Download was canceled by user." @@ -411,7 +382,7 @@ AddSize ${PKG_CONTENT_SIZE} StrCpy $MANDATORY 1 StrCpy $MD5SUM "${PKG_CONTENT_MD5SUM}" - File "content\version" + File "..\..\content\version" StrCpy $DOWNLOADPATH "UQM/0.7/" Push "${PKG_CONTENT_FILE}" Push "$INSTDIR\content\packages" @@ -504,20 +475,20 @@ !insertmacro MUI_STARTMENU_WRITE_END SectionEnd -# Section "Pack 4" SEC08 -# SectionIn 6 -# AddSize ${PKG_REMIX4_SIZE} -# StrCpy $MANDATORY 0 -# StrCpy $MD5SUM "${PKG_REMIX4_MD5SUM}" -# StrCpy $DOWNLOADPATH "UQM%20Remix%20Packs/UQM%20Remix%20Pack%204/" -# Push "${PKG_REMIX4_FILE}" -# Push "$INSTDIR\content\addons" -# Call HandlePackage -# Call EnableRemixes -# ; Shortcuts -# !insertmacro MUI_STARTMENU_WRITE_BEGIN Application -# !insertmacro MUI_STARTMENU_WRITE_END -# SectionEnd + Section "Pack 4" SEC08 + SectionIn 6 + AddSize ${PKG_REMIX4_SIZE} + StrCpy $MANDATORY 0 + StrCpy $MD5SUM "${PKG_REMIX4_MD5SUM}" + StrCpy $DOWNLOADPATH "UQM%20Remix%20Packs/UQM%20Remix%20Pack%204/" + Push "${PKG_REMIX4_FILE}" + Push "$INSTDIR\content\addons" + Call HandlePackage + Call EnableRemixes + ; Shortcuts + !insertmacro MUI_STARTMENU_WRITE_BEGIN Application + !insertmacro MUI_STARTMENU_WRITE_END + SectionEnd SectionGroupEnd Section -ShortcutsAndIcons @@ -588,7 +559,7 @@ !insertmacro MUI_DESCRIPTION_TEXT ${SEC05} `Ur-Quan Masters Remix Pack 1 - 'Super Melee!' Optional add-on music package. If this package is selected and not present in the packages directory, the installer will attempt to download it.` !insertmacro MUI_DESCRIPTION_TEXT ${SEC06} `Ur-Quan Masters Remix Pack 2 - 'Neutral Aliens - Don't Shoot!' Optional add-on music package. If this package is selected and not present in the packages directory, the installer will attempt to download it.` !insertmacro MUI_DESCRIPTION_TEXT ${SEC07} `Ur-Quan Masters Remix Pack 3 - 'The Ur-Quan Hierarchy.' Optional add-on music package. If this package is selected and not present in the packages directory, the installer will attempt to download it.` -# !insertmacro MUI_DESCRIPTION_TEXT ${SEC08} `Ur-Quan Masters Remix Pack 4 - 'The New Alliance of Free Stars.' Optional add-on music package. If this package is selected and not present in the packages directory, the installer will attempt to download it.` + !insertmacro MUI_DESCRIPTION_TEXT ${SEC08} `Ur-Quan Masters Remix Pack 4 - 'The New Alliance of Free Stars.' Optional add-on music package. If this package is selected and not present in the packages directory, the installer will attempt to download it.` !insertmacro MUI_FUNCTION_DESCRIPTION_END Added: trunk/sc2/build/win32_install/uqm-pc.cfg =================================================================== --- trunk/sc2/build/win32_install/uqm-pc.cfg (rev 0) +++ trunk/sc2/build/win32_install/uqm-pc.cfg 2013-02-19 03:23:27 UTC (rev 3780) @@ -0,0 +1,11 @@ +3domusic = BOOLEAN:false +textmenu = BOOLEAN:true +textgradients = BOOLEAN:true +subtitles = BOOLEAN:true +iconicscan = BOOLEAN:false +3domovies = BOOLEAN:false +positionalsfx = BOOLEAN:false +pulseshield = BOOLEAN:false +smoothmelee = BOOLEAN:false +smoothscroll = BOOLEAN:false +remixmusic = BOOLEAN:false Modified: trunk/sc2/doc/users/manual.txt =================================================================== --- trunk/sc2/doc/users/manual.txt 2013-01-05 17:35:49 UTC (rev 3779) +++ trunk/sc2/doc/users/manual.txt 2013-02-19 03:23:27 UTC (rev 3780) @@ -1,6 +1,6 @@ THE UR-QUAN MASTERS v0.7 -- homepage: http://sc2.sf.net/ -Welcome to the sixth release of the Ur-Quan Masters port. This +Welcome to this beta release of the Ur-Quan Masters port. This document will tell you everything you need to play, even if you've never played the original. @@ -134,6 +134,15 @@ Set speech volume (0-100). If set to 0, the game runs in 'no speech' mode and the oscilloscope reacts to the music. + -m 3do (or --music 3do) + +Use the 3DO remixed soundtrack for songs that were in fact remixed. +The default. + + -m pc (or --music pc) + +Use the .MOD based PC soundtrack everywhere. + -q (or --audioquality) Can be "high", "medium", or "low". Specifies how nice the audio @@ -782,7 +791,7 @@ in the game. '--addon' may be specified more than once to enable multiple add-ons. -Formerly standard packages, 3domusic and 3dovoice are now standard add-ons, +Unlike previous releases, 3domusic and 3dovoice are now standard add-ons, and can be turned on and off from the in-game setup menu. The Precursors UQM Remix project is intended to be used as an add-on. If you install UQM 0.7 from the Windows installer, the remix packs This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |