You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(147) |
Oct
(219) |
Nov
(189) |
Dec
(380) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(301) |
Feb
(369) |
Mar
(155) |
Apr
(61) |
May
(77) |
Jun
(101) |
Jul
(191) |
Aug
(107) |
Sep
(180) |
Oct
(37) |
Nov
(7) |
Dec
(28) |
2004 |
Jan
(34) |
Feb
(45) |
Mar
(7) |
Apr
(17) |
May
(6) |
Jun
(59) |
Jul
(4) |
Aug
(8) |
Sep
(6) |
Oct
(18) |
Nov
(11) |
Dec
(15) |
2005 |
Jan
(148) |
Feb
(146) |
Mar
(73) |
Apr
(154) |
May
(192) |
Jun
(11) |
Jul
(23) |
Aug
(23) |
Sep
(26) |
Oct
(68) |
Nov
(109) |
Dec
(294) |
2006 |
Jan
(172) |
Feb
(22) |
Mar
(81) |
Apr
(79) |
May
(83) |
Jun
(23) |
Jul
(35) |
Aug
(66) |
Sep
(39) |
Oct
(133) |
Nov
(125) |
Dec
(90) |
2007 |
Jan
(49) |
Feb
(21) |
Mar
(3) |
Apr
(33) |
May
(19) |
Jun
(26) |
Jul
(32) |
Aug
(18) |
Sep
(14) |
Oct
(2) |
Nov
(8) |
Dec
(22) |
2008 |
Jan
(23) |
Feb
(14) |
Mar
(28) |
Apr
(11) |
May
(55) |
Jun
(8) |
Jul
(1) |
Aug
(36) |
Sep
(8) |
Oct
(20) |
Nov
(6) |
Dec
|
2009 |
Jan
(2) |
Feb
(7) |
Mar
|
Apr
(1) |
May
(2) |
Jun
(46) |
Jul
(15) |
Aug
(1) |
Sep
(3) |
Oct
(88) |
Nov
(108) |
Dec
(119) |
2010 |
Jan
(31) |
Feb
(3) |
Mar
(5) |
Apr
(1) |
May
(5) |
Jun
(5) |
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
(23) |
Mar
(1) |
Apr
(20) |
May
(27) |
Jun
(2) |
Jul
(40) |
Aug
(14) |
Sep
(17) |
Oct
(5) |
Nov
|
Dec
(28) |
2012 |
Jan
(31) |
Feb
(19) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
(1) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
From: <Mee...@us...> - 2012-01-01 17:36:56
|
Revision: 3732 http://sc2.svn.sourceforge.net/sc2/?rev=3732&view=rev Author: Meep-Eep Date: 2012-01-01 17:36:50 +0000 (Sun, 01 Jan 2012) Log Message: ----------- More cleanups. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2012-01-01 16:47:49 UTC (rev 3731) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-01 17:36:50 UTC (rev 3732) @@ -961,6 +961,47 @@ SetFlashRect (&r); } +// Helper function for DoModifyShips(), called when the player presses +// one of the motion keys when not in crew modification mode. +static BYTE +DMS_MoveCursor (BYTE curState, SBYTE dx, SBYTE dy) +{ + BYTE row = LONIBBLE(curState) / HANGAR_SHIPS_ROW; + BYTE col = LONIBBLE(curState) % HANGAR_SHIPS_ROW; + BOOLEAN isFlagShipSelected = (HINIBBLE(curState) != 0); + + if (dy) + { + // Vertical motion. + + // We consider the flagship an extra row (on the bottom), + // to ease operations. + if (isFlagShipSelected) + row = HANGAR_ROWS; + + // Move up/down, wrapping around: + row = (row + (HANGAR_ROWS + 1) + dy) % (HANGAR_ROWS + 1); + + // If we moved to the 'extra row', this means the flag ship. + isFlagShipSelected = (row == HANGAR_ROWS); + if (isFlagShipSelected) + row = 0; + } + else if (dx) + { + // Horizontal motion. + if (!isFlagShipSelected) + { + // Moving horizontally through the escort ship slots, + // wrapping around if necessary. + col = (col + HANGAR_SHIPS_ROW + dx) % HANGAR_SHIPS_ROW; + } + } + + return MAKE_BYTE(row * HANGAR_SHIPS_ROW + col, + isFlagShipSelected ? 0xf : 0); +} + /* 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 @@ -1017,36 +1058,11 @@ if (pMS->delta_item & MODIFY_CREW_FLAG) { } - else if (dy) + else if (dx || dy) { - if (HINIBBLE (NewState)) - NewState = pMS->CurState % HANGAR_SHIPS_ROW; - else - NewState = (unsigned char)(pMS->CurState + HANGAR_SHIPS_ROW); - - NewState += dy * HANGAR_SHIPS_ROW; - if (NewState / HANGAR_SHIPS_ROW > 0 - && NewState / HANGAR_SHIPS_ROW <= HANGAR_ROWS) - NewState -= HANGAR_SHIPS_ROW; - else if (NewState / HANGAR_SHIPS_ROW > HANGAR_ROWS + 1) - /* negative number - select last row */ - NewState = pMS->CurState % HANGAR_SHIPS_ROW - + HANGAR_SHIPS_ROW * (HANGAR_ROWS - 1); - else - // select SIS - NewState = MAKE_BYTE (pMS->CurState, 0xF); + NewState = DMS_MoveCursor (NewState, dx, dy); } - else if (dx && !HINIBBLE (NewState)) - { - // Moving horizontally through the escort ship slots, - // wrapping around if necessary. - BYTE row = pMS->CurState / HANGAR_SHIPS_ROW; - BYTE col = pMS->CurState % HANGAR_SHIPS_ROW; - col = (col + HANGAR_SHIPS_ROW + dx) % HANGAR_SHIPS_ROW; - NewState = row * HANGAR_SHIPS_ROW + col; - } - if (select || cancel #ifdef WANT_SHIP_SPINS || special This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-01 16:47:55
|
Revision: 3731 http://sc2.svn.sourceforge.net/sc2/?rev=3731&view=rev Author: Meep-Eep Date: 2012-01-01 16:47:49 +0000 (Sun, 01 Jan 2012) Log Message: ----------- Fix for my earlier cleanup... Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2012-01-01 16:41:38 UTC (rev 3730) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-01 16:47:49 UTC (rev 3731) @@ -1040,8 +1040,11 @@ { // Moving horizontally through the escort ship slots, // wrapping around if necessary. - NewState = (pMS->CurState + HANGAR_SHIPS_ROW + dx) % - HANGAR_SHIPS_ROW; + BYTE row = pMS->CurState / HANGAR_SHIPS_ROW; + BYTE col = pMS->CurState % HANGAR_SHIPS_ROW; + + col = (col + HANGAR_SHIPS_ROW + dx) % HANGAR_SHIPS_ROW; + NewState = row * HANGAR_SHIPS_ROW + col; } if (select || cancel This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-01 16:41:44
|
Revision: 3730 http://sc2.svn.sourceforge.net/sc2/?rev=3730&view=rev Author: Meep-Eep Date: 2012-01-01 16:41:38 +0000 (Sun, 01 Jan 2012) Log Message: ----------- More DoModifyShips() cleanups. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2012-01-01 01:59:12 UTC (rev 3729) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-01 16:41:38 UTC (rev 3730) @@ -931,6 +931,36 @@ } } +// Helper function for DoModifyShips(), called when the player presses +// 'select' or 'cancel' after selling all the crew. +static void +DMS_ScrapEscortShip (MENU_STATE *pMS, HSHIPFRAG hStarShip) +{ + RECT r; + SHIP_FRAGMENT *StarShipPtr = + LockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + SetFlashRect (NULL); + UnlockMutex (GraphicsLock); + ShowCombatShip (pMS, pMS->CurState, StarShipPtr); + LockMutex (GraphicsLock); + + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + RemoveQueue (&GLOBAL (built_ship_q), hStarShip); + FreeShipFrag (&GLOBAL (built_ship_q), hStarShip); + // refresh SIS display + DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA); + + r.corner.x = pMS->flash_rect0.corner.x; + r.corner.y = pMS->flash_rect0.corner.y; + r.extent.width = SHIP_WIN_WIDTH; + r.extent.height = SHIP_WIN_HEIGHT; + + SetContext (SpaceContext); + SetFlashRect (&r); +} + /* 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 @@ -1076,32 +1106,22 @@ if ((pMS->delta_item & MODIFY_CREW_FLAG) && hStarShip != 0) { + // Pressing the select or cancel button in crew edit + // mode for an escort ship. SHIP_FRAGMENT *StarShipPtr = LockShipFrag ( &GLOBAL (built_ship_q), hStarShip); - if (StarShipPtr->crew_level == 0) + COUNT crew_level = StarShipPtr->crew_level; + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + if (crew_level == 0) { - SetFlashRect (NULL); - UnlockMutex (GraphicsLock); - ShowCombatShip (pMS, pMS->CurState, StarShipPtr); - LockMutex (GraphicsLock); - UnlockShipFrag (&GLOBAL (built_ship_q), - hStarShip); - RemoveQueue (&GLOBAL (built_ship_q), hStarShip); - FreeShipFrag (&GLOBAL (built_ship_q), hStarShip); - // refresh SIS display - DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, - UNDEFINED_DELTA); - r.corner.x = pMS->flash_rect0.corner.x; - r.corner.y = pMS->flash_rect0.corner.y; - r.extent.width = SHIP_WIN_WIDTH; - r.extent.height = SHIP_WIN_HEIGHT; - SetContext (SpaceContext); - SetFlashRect (&r); + // Scrap escort ship, then exiting crew edit + // mode. + DMS_ScrapEscortShip (pMS, hStarShip); } else { - UnlockShipFrag (&GLOBAL (built_ship_q), - hStarShip); + // Just exiting escort ship crew edit mode. } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-01 01:59:19
|
Revision: 3729 http://sc2.svn.sourceforge.net/sc2/?rev=3729&view=rev Author: Meep-Eep Date: 2012-01-01 01:59:12 +0000 (Sun, 01 Jan 2012) Log Message: ----------- More cleanups of DoModifyShips. We'll get to something comprehendible eventually. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2011-12-31 02:54:57 UTC (rev 3728) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-01 01:59:12 UTC (rev 3729) @@ -593,8 +593,247 @@ } #endif /* WANT_SHIP_SPINS */ -// Try to add the currently selected ship +// Helper function for DoModifyShips(), called when the player presses the +// up button when modifying the crew of the flagship. +// Buy crew for the flagship. +// Returns the change in crew (1 on success, 0 on failure). +static SIZE +DMS_HireFlagShipCrew (void) +{ + RECT r; + + if (GetCPodCapacity (&r.corner) <= GetCrewCount ()) + { + // At capacity. + return 0; + } + + if (GLOBAL_SIS (ResUnits) < (DWORD)GLOBAL (CrewCost)) + { + // Not enough RUs. + return 0; + } + + DrawPoint (&r.corner); + DeltaSISGauges (1, 0, -GLOBAL (CrewCost)); + + return 1; +} + +// Helper function for DoModifyShips(), called when the player presses the +// down button when modifying the crew of the flagship. +// Dismiss crew from the flagship. +// Returns the change in crew (-1 on success, 0 on failure). +static SIZE +DMS_DismissFlagShipCrew (void) +{ + SIZE crew_bought; + RECT r; + + if (GetCrewCount () == 0) + { + // No crew to dismiss. + return 0; + } + + crew_bought = (SIZE)MAKE_WORD ( + GET_GAME_STATE (CREW_PURCHASED0), + GET_GAME_STATE (CREW_PURCHASED1)); + + DeltaSISGauges (-1, 0, GLOBAL (CrewCost) - + (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); + + GetCPodCapacity (&r.corner); + SetContextForeGroundColor (BLACK_COLOR); + DrawPoint (&r.corner); + + return -1; +} + +// Helper function for DoModifyShips(), called when the player presses the +// up button when modifying the crew of an escort ship. +// Buy crew for an escort ship +// Returns the change in crew (1 on success, 0 on failure). +static SIZE +DMS_HireEscortShipCrew (MENU_STATE *pMS, SHIP_FRAGMENT *StarShipPtr) +{ + COUNT templateMaxCrew; + + { + // XXX Split this off into a separate function? + HFLEETINFO hTemplate = GetStarShipFromIndex (&GLOBAL (avail_race_q), + StarShipPtr->race_id); + FLEET_INFO *TemplatePtr = + LockFleetInfo (&GLOBAL (avail_race_q), hTemplate); + templateMaxCrew = TemplatePtr->crew_level; + UnlockFleetInfo (&GLOBAL (avail_race_q), hTemplate); + } + + if (GLOBAL_SIS (ResUnits) < (DWORD)GLOBAL (CrewCost)) + { + // Not enough money to hire a crew member. + return 0; + } + + if (StarShipPtr->crew_level >= StarShipPtr->max_crew) + { + // This ship cannot handle more crew. + return 0; + } + + if (StarShipPtr->crew_level >= templateMaxCrew) + { + // A ship of this type cannot handle more crew. + return 0; + } + + if (StarShipPtr->crew_level > 0) + { + DeltaSISGauges (0, 0, -GLOBAL (CrewCost)); + } + else + { + // Buy a ship. + DeltaSISGauges (0, 0, -(COUNT)ShipCost[StarShipPtr->race_id]); + } + + ++StarShipPtr->crew_level; + ShowShipCrew (StarShipPtr, &pMS->flash_rect0); + + return 1; +} + +// Helper function for DoModifyShips(), called when the player presses the +// down button when modifying the crew of an escort ship. +// Dismiss crew from an escort ship +// Returns the change in crew (-1 on success, 0 on failure). +static SIZE +DMS_DismissEscortShipCrew (MENU_STATE *pMS, SHIP_FRAGMENT *StarShipPtr) +{ + SIZE crew_delta = 0; + + if (StarShipPtr->crew_level > 0) + { + if (StarShipPtr->crew_level > 1) + { + // The ship was not at 'scrap'. + // Give one crew member worth of RU. + SIZE crew_bought = (SIZE)MAKE_WORD ( + GET_GAME_STATE (CREW_PURCHASED0), + GET_GAME_STATE (CREW_PURCHASED1)); + + DeltaSISGauges (0, 0, GLOBAL (CrewCost) + - (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); + } + else + { + // With the last crew member, the ship + // will be scrapped. + // Give RU for the ship. + DeltaSISGauges (0, 0, (COUNT)ShipCost[StarShipPtr->race_id]); + } + crew_delta = -1; + --StarShipPtr->crew_level; + } + else + { // no crew to dismiss + PlayMenuSound (MENU_SOUND_FAILURE); + } + + ShowShipCrew (StarShipPtr, &pMS->flash_rect0); + + return crew_delta; +} + +// Helper function for DoModifyShips(), called when the player presses the +// up or down button when modifying the crew of the flagship or of an escort +// ship. +// 'hStarShip' is the currently escort ship, or 0 if no ship is +// selected. +// 'dy' is -1 if the 'up' button was pressed, or '1' if the down button was +// pressed. static void +DMS_ModifyCrew (MENU_STATE *pMS, HSHIPFRAG hStarShip, SBYTE dy) +{ + SIZE crew_delta = 0; + SHIP_FRAGMENT *StarShipPtr = NULL; + + if (hStarShip) + StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, + MENU_SOUND_SELECT | MENU_SOUND_CANCEL); + + if (hStarShip == 0) + { + // Add/Dismiss crew for the flagship. + if (dy < 0) + { + // Add crew for the flagship. + crew_delta = DMS_HireFlagShipCrew (); + } + else + { + // Dismiss crew from the flagship. + crew_delta = DMS_DismissFlagShipCrew (); + } + + if (crew_delta != 0) + { + RECT r; + SetContext (StatusContext); + GetGaugeRect (&r, TRUE); + SetFlashRect (&r); + SetContext (SpaceContext); + } + } + else + { + // Add/Dismiss crew for an escort ship. + if (dy < 0) + { + // Add crew for an escort ship. + crew_delta = DMS_HireEscortShipCrew (pMS, StarShipPtr); + } + else + { + // Dismiss crew from an escort ship. + crew_delta = DMS_DismissEscortShipCrew (pMS, StarShipPtr); + } + + if (crew_delta != 0) + { + RECT r; + r.corner.x = pMS->flash_rect0.corner.x; + r.corner.y = pMS->flash_rect0.corner.y + + pMS->flash_rect0.extent.height - 6; + r.extent.width = SHIP_WIN_WIDTH; + r.extent.height = 5; + + SetContext (SpaceContext); + SetFlashRect (&r); + } + } + + if (crew_delta == 0) + PlayMenuSound (MENU_SOUND_FAILURE); + + if (hStarShip) + { + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + // Clear out the bought ship index so that flash rects work + // correctly. + pMS->delta_item &= MODIFY_CREW_FLAG; + } + + CrewTransaction (crew_delta); +} + +// 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. +static void DMS_TryAddEscortShip (MENU_STATE *pMS) { HFLEETINFO shipInfo = GetAvailableRaceFromIndex ( @@ -634,6 +873,64 @@ MENU_SOUND_SELECT | MENU_SOUND_CANCEL); } +// Helper function for DoModifyShips(), called when the player is in the +// mode to add a new escort ship to the fleet (after pressing select on an +// empty slot). +static BOOLEAN +DMS_AddEscortShip (MENU_STATE *pMS, BOOLEAN select, BOOLEAN cancel, + SBYTE dx, SBYTE dy, BYTE *newStateOut) +{ + BYTE NewState; + assert (select || cancel || dx || dy); + assert (pMS->delta_item & MODIFY_CREW_FLAG); + + if (cancel) + { + // Cancel selecting an escort ship. + pMS->delta_item &= ~MODIFY_CREW_FLAG; + LockMutex (GraphicsLock); + SetFlashRect (SFR_MENU_3DO); + UnlockMutex (GraphicsLock); + DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); + SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); + return FALSE; + } + + if (select) + { + // Selected a ship to be inserted in an empty escort + // ship slot. + DMS_TryAddEscortShip (pMS); + return TRUE; + } + + { + // Motion key pressed while selecting a ship to be + // inserted in an empty escort ship slot. + COUNT Index = GetAvailableRaceCount (); + NewState = LOBYTE (pMS->delta_item); + if (dx < 0 || dy < 0) + { + if (NewState-- == 0) + NewState = Index - 1; + } + else if (dx > 0 || dy > 0) + { + if (++NewState == Index) + NewState = 0; + } + + if (NewState != LOBYTE (pMS->delta_item)) + { + DrawRaceStrings (pMS, NewState); + pMS->delta_item = NewState | MODIFY_CREW_FLAG; + } + + *newStateOut = NewState; + return TRUE; + } +} + /* 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 @@ -644,14 +941,11 @@ static BOOLEAN DoModifyShips (MENU_STATE *pMS) { - BOOLEAN select, cancel; #ifdef WANT_SHIP_SPINS - BOOLEAN special; - - special = PulsedInputState.menu[KEY_MENU_SPECIAL]; + BOOLEAN special = PulsedInputState.menu[KEY_MENU_SPECIAL]; #endif /* WANT_SHIP_SPINS */ - select = PulsedInputState.menu[KEY_MENU_SELECT]; - cancel = PulsedInputState.menu[KEY_MENU_CANCEL]; + BOOLEAN select = PulsedInputState.menu[KEY_MENU_SELECT]; + BOOLEAN cancel = PulsedInputState.menu[KEY_MENU_CANCEL]; if (GLOBAL (CurrentActivity) & CHECK_ABORT) { @@ -674,18 +968,22 @@ { SBYTE dx = 0; SBYTE dy = 0; - BYTE NewState; + BYTE NewState = pMS->CurState; if (!(pMS->delta_item & MODIFY_CREW_FLAG)) { SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); } - if (PulsedInputState.menu[KEY_MENU_RIGHT]) dx = 1; - if (PulsedInputState.menu[KEY_MENU_LEFT]) dx = -1; - if (PulsedInputState.menu[KEY_MENU_UP]) dy = -1; - if (PulsedInputState.menu[KEY_MENU_DOWN]) dy = 1; - NewState = pMS->CurState; + if (PulsedInputState.menu[KEY_MENU_RIGHT]) + dx = 1; + if (PulsedInputState.menu[KEY_MENU_LEFT]) + dx = -1; + if (PulsedInputState.menu[KEY_MENU_UP]) + dy = -1; + if (PulsedInputState.menu[KEY_MENU_DOWN]) + dy = 1; + if (pMS->delta_item & MODIFY_CREW_FLAG) { } @@ -748,71 +1046,32 @@ } else #endif /* WANT_SHIP_SPINS */ - if (select || ((pMS->delta_item & MODIFY_CREW_FLAG) + if (hStarShip == 0 && HINIBBLE (pMS->CurState) == 0 && + !(pMS->delta_item & MODIFY_CREW_FLAG) && select) + { + // Select button was pressed over an empty escort + // ship slot. Switch to 'add escort ship' mode. + UnlockMutex (GraphicsLock); + pMS->delta_item = MODIFY_CREW_FLAG; + DrawRaceStrings (pMS, 0); + return TRUE; + } + else if (select || ((pMS->delta_item & MODIFY_CREW_FLAG) && (dx || dy || cancel))) { if (hStarShip == 0 && HINIBBLE (pMS->CurState) == 0) { - // Cursor is over an empty escort ship slot. - COUNT Index; - -// SetFlashRect (NULL); + // Cursor is over an empty escort ship slot, while we're + // in 'add escort ship' mode. UnlockMutex (GraphicsLock); - if (!(pMS->delta_item & MODIFY_CREW_FLAG)) - { - // Select button was pressed over an empty escort - // ship slot. Switch to 'add ship' mode. - pMS->delta_item = MODIFY_CREW_FLAG; - DrawRaceStrings (pMS, 0); + if (DMS_AddEscortShip (pMS, select, cancel, dx, dy, &NewState)) return TRUE; - } - else if (cancel) - { - // We were selecting a ship to be inserted in an - // empty escort ship slot, but cancelled. - pMS->delta_item ^= MODIFY_CREW_FLAG; - LockMutex (GraphicsLock); - SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); - DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); - SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); - } - else if (select) - { - // Selected a ship to be inserted in an empty escort - // ship slot. - DMS_TryAddEscortShip (pMS); - return TRUE; - } - else - { - // Motion key pressed while selecting a ship to be - // inserted in an empty escort ship slot. - Index = GetAvailableRaceCount (); - NewState = LOBYTE (pMS->delta_item); - if (dx < 0 || dy < 0) - { - if (NewState-- == 0) - NewState = Index - 1; - } - else if (dx > 0 || dy > 0) - { - if (++NewState == Index) - NewState = 0; - } - - if (NewState != LOBYTE (pMS->delta_item)) - { - DrawRaceStrings (pMS, NewState); - pMS->delta_item = NewState | MODIFY_CREW_FLAG; - } - - return TRUE; - } + LockMutex (GraphicsLock); goto ChangeFlashRect; } - else if (select || cancel) + + if (select || cancel) { if ((pMS->delta_item & MODIFY_CREW_FLAG) && hStarShip != 0) @@ -875,162 +1134,9 @@ } else if (pMS->delta_item & MODIFY_CREW_FLAG) { - SIZE crew_delta, crew_bought; - SHIP_FRAGMENT *StarShipPtr; - - if (hStarShip) - StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), - hStarShip); - else - StarShipPtr = NULL; // Keeping compiler quiet. - - SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, - MENU_SOUND_SELECT | MENU_SOUND_CANCEL); - crew_delta = 0; - if (dy < 0) - { - // Buy crew - if (hStarShip == 0) - { - // Buy crew for the flagship. - if (GetCPodCapacity (&r.corner) > GetCrewCount () - && GLOBAL_SIS (ResUnits) >= - (DWORD)GLOBAL (CrewCost)) - { - DrawPoint (&r.corner); - DeltaSISGauges (1, 0, -GLOBAL (CrewCost)); - crew_delta = 1; - - SetContext (StatusContext); - GetGaugeRect (&r, TRUE); - SetFlashRect (&r); - SetContext (SpaceContext); - } - else - { // at capacity or not enough RUs - PlayMenuSound (MENU_SOUND_FAILURE); - } - } - else - { - // Buy crew for an escort ship. - HFLEETINFO hTemplate; - FLEET_INFO *TemplatePtr; - - hTemplate = GetStarShipFromIndex ( - &GLOBAL (avail_race_q), - StarShipPtr->race_id); - TemplatePtr = LockFleetInfo ( - &GLOBAL (avail_race_q), hTemplate); - if (GLOBAL_SIS (ResUnits) >= - (DWORD)GLOBAL (CrewCost) - && StarShipPtr->crew_level < - StarShipPtr->max_crew && - StarShipPtr->crew_level < - TemplatePtr->crew_level) - { - if (StarShipPtr->crew_level > 0) - DeltaSISGauges (0, 0, -GLOBAL (CrewCost)); - else - DeltaSISGauges (0, 0, -(COUNT)ShipCost[ - StarShipPtr->race_id]); - ++StarShipPtr->crew_level; - crew_delta = 1; - ShowShipCrew (StarShipPtr, &pMS->flash_rect0); - r.corner.x = pMS->flash_rect0.corner.x; - r.corner.y = pMS->flash_rect0.corner.y - + pMS->flash_rect0.extent.height - 6; - r.extent.width = SHIP_WIN_WIDTH; - r.extent.height = 5; - SetContext (SpaceContext); - SetFlashRect (&r); - } - else - { // at capacity or not enough RUs - PlayMenuSound (MENU_SOUND_FAILURE); - } - UnlockFleetInfo (&GLOBAL (avail_race_q), - hTemplate); - } - } - else if (dy > 0) - { - // Dismiss crew. - crew_bought = (SIZE)MAKE_WORD ( - GET_GAME_STATE (CREW_PURCHASED0), - GET_GAME_STATE (CREW_PURCHASED1)); - if (hStarShip == 0) - { - // Dismiss crew from the flagship. - if (GetCrewCount ()) - { - DeltaSISGauges (-1, 0, GLOBAL (CrewCost) - - (crew_bought == - CREW_EXPENSE_THRESHOLD ? 2 : 0)); - crew_delta = -1; - - GetCPodCapacity (&r.corner); - SetContextForeGroundColor (BLACK_COLOR); - DrawPoint (&r.corner); - - SetContext (StatusContext); - GetGaugeRect (&r, TRUE); - SetFlashRect (&r); - SetContext (SpaceContext); - } - else - { // no crew to dismiss - PlayMenuSound (MENU_SOUND_FAILURE); - } - } - else - { - // Dismiss crew from an escort ship. - if (StarShipPtr->crew_level > 0) - { - if (StarShipPtr->crew_level > 1) - { - // The ship was not at 'scrap'. - // Give one crew member worth of RU. - DeltaSISGauges (0, 0, GLOBAL (CrewCost) - - (crew_bought == - CREW_EXPENSE_THRESHOLD ? 2 : 0)); - } - else - { - // With the last crew member, the ship - // will be scrapped. - // Give RU for the ship. - DeltaSISGauges (0, 0, (COUNT)ShipCost[ - StarShipPtr->race_id]); - } - crew_delta = -1; - --StarShipPtr->crew_level; - } - else - { // no crew to dismiss - PlayMenuSound (MENU_SOUND_FAILURE); - } - ShowShipCrew (StarShipPtr, &pMS->flash_rect0); - r.corner.x = pMS->flash_rect0.corner.x; - r.corner.y = pMS->flash_rect0.corner.y - + pMS->flash_rect0.extent.height - 6; - r.extent.width = SHIP_WIN_WIDTH; - r.extent.height = 5; - SetContext (SpaceContext); - SetFlashRect (&r); - } - } - - if (hStarShip) - { - UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); - - // clear out the bought ship index - // so that flash rects work correctly - pMS->delta_item &= MODIFY_CREW_FLAG; - } - CrewTransaction (crew_delta); + // Hire or dismiss crew for the flagship or an escort + // ship. + DMS_ModifyCrew (pMS, hStarShip, dy); } } else if (cancel) @@ -1053,6 +1159,7 @@ ChangeFlashRect: if (HINIBBLE (pMS->CurState)) { + // Flash the flag ship. pMS->flash_rect0.corner.x = 0; pMS->flash_rect0.corner.y = 0; pMS->flash_rect0.extent.width = SIS_SCREEN_WIDTH; @@ -1060,10 +1167,13 @@ } else { - pMS->flash_rect0.corner.x = hangar_x_coords[ - pMS->CurState % HANGAR_SHIPS_ROW]; - pMS->flash_rect0.corner.y = HANGAR_Y + (HANGAR_DY * - (pMS->CurState / HANGAR_SHIPS_ROW)); + // Flash the current escort ship slot. + BYTE row = pMS->CurState / HANGAR_SHIPS_ROW; + BYTE col = pMS->CurState % HANGAR_SHIPS_ROW; + + pMS->flash_rect0.corner.x = hangar_x_coords[col]; + pMS->flash_rect0.corner.y = + HANGAR_Y + (HANGAR_DY * row); pMS->flash_rect0.extent.width = SHIP_WIN_WIDTH; pMS->flash_rect0.extent.height = SHIP_WIN_HEIGHT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-31 02:55:03
|
Revision: 3728 http://sc2.svn.sourceforge.net/sc2/?rev=3728&view=rev Author: Meep-Eep Date: 2011-12-31 02:54:57 +0000 (Sat, 31 Dec 2011) Log Message: ----------- A few more comments. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2011-12-31 02:40:15 UTC (rev 3727) +++ trunk/sc2/src/uqm/shipyard.c 2011-12-31 02:54:57 UTC (rev 3728) @@ -889,8 +889,10 @@ crew_delta = 0; if (dy < 0) { + // Buy crew if (hStarShip == 0) { + // Buy crew for the flagship. if (GetCPodCapacity (&r.corner) > GetCrewCount () && GLOBAL_SIS (ResUnits) >= (DWORD)GLOBAL (CrewCost)) @@ -911,6 +913,7 @@ } else { + // Buy crew for an escort ship. HFLEETINFO hTemplate; FLEET_INFO *TemplatePtr; @@ -952,11 +955,13 @@ } else if (dy > 0) { + // Dismiss crew. crew_bought = (SIZE)MAKE_WORD ( GET_GAME_STATE (CREW_PURCHASED0), GET_GAME_STATE (CREW_PURCHASED1)); if (hStarShip == 0) { + // Dismiss crew from the flagship. if (GetCrewCount ()) { DeltaSISGauges (-1, 0, GLOBAL (CrewCost) @@ -980,15 +985,25 @@ } else { + // Dismiss crew from an escort ship. if (StarShipPtr->crew_level > 0) { if (StarShipPtr->crew_level > 1) + { + // The ship was not at 'scrap'. + // Give one crew member worth of RU. DeltaSISGauges (0, 0, GLOBAL (CrewCost) - (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); + } else + { + // With the last crew member, the ship + // will be scrapped. + // Give RU for the ship. DeltaSISGauges (0, 0, (COUNT)ShipCost[ StarShipPtr->race_id]); + } crew_delta = -1; --StarShipPtr->crew_level; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-31 02:40:22
|
Revision: 3727 http://sc2.svn.sourceforge.net/sc2/?rev=3727&view=rev Author: Meep-Eep Date: 2011-12-31 02:40:15 +0000 (Sat, 31 Dec 2011) Log Message: ----------- Clean up DoModifyShips a bit more. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2011-12-31 01:58:11 UTC (rev 3726) +++ trunk/sc2/src/uqm/shipyard.c 2011-12-31 02:40:15 UTC (rev 3727) @@ -73,6 +73,12 @@ SHIPYARD_EXIT }; +static COUNT ShipCost[] = +{ + RACE_SHIP_COST +}; + + static void animatePowerLines (MENU_STATE *pMS) { @@ -214,10 +220,6 @@ HFLEETINFO hStarShip; FLEET_INFO *FleetPtr; UNICODE buf[30]; - COUNT ShipCost[] = - { - RACE_SHIP_COST - }; hStarShip = GetAvailableRaceFromIndex (NewRaceItem); NewRaceItem = GetIndexFromStarShip (&GLOBAL (avail_race_q), @@ -591,6 +593,47 @@ } #endif /* WANT_SHIP_SPINS */ +// Try to add the currently selected ship +static void +DMS_TryAddEscortShip (MENU_STATE *pMS) +{ + HFLEETINFO shipInfo = GetAvailableRaceFromIndex ( + LOBYTE (pMS->delta_item)); + COUNT Index = GetIndexFromStarShip (&GLOBAL (avail_race_q), shipInfo); + + if (GLOBAL_SIS (ResUnits) >= (DWORD)ShipCost[Index] + && CloneShipFragment (Index, &GLOBAL (built_ship_q), 1)) + { + RECT r; + ShowCombatShip (pMS, pMS->CurState, NULL); + //Reset flash rectangle + LockMutex (GraphicsLock); + SetFlashRect (SFR_MENU_3DO); + UnlockMutex (GraphicsLock); + DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); + + LockMutex (GraphicsLock); + DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, + -((int)ShipCost[Index])); + r.corner.x = pMS->flash_rect0.corner.x; + r.corner.y = pMS->flash_rect0.corner.y + + pMS->flash_rect0.extent.height - 6; + r.extent.width = SHIP_WIN_WIDTH; + r.extent.height = 5; + SetContext (SpaceContext); + SetFlashRect (&r); + UnlockMutex (GraphicsLock); + } + else + { + // not enough RUs to build, or cloning the ship failed. + PlayMenuSound (MENU_SOUND_FAILURE); + } + + SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, + MENU_SOUND_SELECT | MENU_SOUND_CANCEL); +} + /* 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 @@ -708,25 +751,25 @@ if (select || ((pMS->delta_item & MODIFY_CREW_FLAG) && (dx || dy || cancel))) { - COUNT ShipCost[] = - { - RACE_SHIP_COST - }; - if (hStarShip == 0 && HINIBBLE (pMS->CurState) == 0) { + // Cursor is over an empty escort ship slot. COUNT Index; // SetFlashRect (NULL); UnlockMutex (GraphicsLock); if (!(pMS->delta_item & MODIFY_CREW_FLAG)) { + // Select button was pressed over an empty escort + // ship slot. Switch to 'add ship' mode. pMS->delta_item = MODIFY_CREW_FLAG; DrawRaceStrings (pMS, 0); return TRUE; } else if (cancel) { + // We were selecting a ship to be inserted in an + // empty escort ship slot, but cancelled. pMS->delta_item ^= MODIFY_CREW_FLAG; LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); @@ -736,44 +779,15 @@ } else if (select) { - Index = GetIndexFromStarShip (&GLOBAL (avail_race_q), - GetAvailableRaceFromIndex ( - LOBYTE (pMS->delta_item))); - - if (GLOBAL_SIS (ResUnits) >= (DWORD)ShipCost[Index] - && CloneShipFragment (Index, - &GLOBAL (built_ship_q), 1)) - { - ShowCombatShip (pMS, pMS->CurState, NULL); - //Reset flash rectangle - LockMutex (GraphicsLock); - SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); - DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); - - LockMutex (GraphicsLock); - DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, - -((int)ShipCost[Index])); - r.corner.x = pMS->flash_rect0.corner.x; - r.corner.y = pMS->flash_rect0.corner.y - + pMS->flash_rect0.extent.height - 6; - r.extent.width = SHIP_WIN_WIDTH; - r.extent.height = 5; - SetContext (SpaceContext); - SetFlashRect (&r); - UnlockMutex (GraphicsLock); - } - else - { // not enough RUs to build - PlayMenuSound (MENU_SOUND_FAILURE); - } - SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, - MENU_SOUND_SELECT | MENU_SOUND_CANCEL); - + // Selected a ship to be inserted in an empty escort + // ship slot. + DMS_TryAddEscortShip (pMS); return TRUE; } else { + // Motion key pressed while selecting a ship to be + // inserted in an empty escort ship slot. Index = GetAvailableRaceCount (); NewState = LOBYTE (pMS->delta_item); if (dx < 0 || dy < 0) @@ -832,7 +846,8 @@ } } - if (!(pMS->delta_item ^= MODIFY_CREW_FLAG)) + pMS->delta_item ^= MODIFY_CREW_FLAG; + if (!pMS->delta_item) { goto ChangeFlashRect; } @@ -1023,8 +1038,8 @@ ChangeFlashRect: if (HINIBBLE (pMS->CurState)) { - pMS->flash_rect0.corner.x = - pMS->flash_rect0.corner.y = 0; + pMS->flash_rect0.corner.x = 0; + pMS->flash_rect0.corner.y = 0; pMS->flash_rect0.extent.width = SIS_SCREEN_WIDTH; pMS->flash_rect0.extent.height = 61; } 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:58:17
|
Revision: 3726 http://sc2.svn.sourceforge.net/sc2/?rev=3726&view=rev Author: Meep-Eep Date: 2011-12-31 01:58:11 +0000 (Sat, 31 Dec 2011) Log Message: ----------- Remove dead code; consistent use of 'extern'. Modified Paths: -------------- trunk/sc2/src/uqm/build.h Modified: trunk/sc2/src/uqm/build.h =================================================================== --- trunk/sc2/src/uqm/build.h 2011-12-31 01:46:56 UTC (rev 3725) +++ trunk/sc2/src/uqm/build.h 2011-12-31 01:58:11 UTC (rev 3726) @@ -38,35 +38,20 @@ extern HSHIPFRAG CloneShipFragment (COUNT shipIndex, QUEUE *pDstQueue, COUNT crew_level); extern HLINK GetStarShipFromIndex (QUEUE *pShipQ, COUNT Index); -HSHIPFRAG GetEscortByStarShipIndex (COUNT index); +extern HSHIPFRAG GetEscortByStarShipIndex (COUNT index); extern BYTE NameCaptain (QUEUE *pQueue, SPECIES_ID SpeciesID); -/* Possible values for the 'state' argument of - * COUNT ActivateStarShip (COUNT which_ship, SIZE state) - * See that function for more information. - */ -#define SET_ALLIED 0 -#define SET_NOT_ALLIED -1 -#define CHECK_ALLIANCE -2 -#define REMOVE_BUILT -3 -#define ESCORT_WORTH -4 -#define SPHERE_KNOWN -5 -#define SPHERE_TRACKING -6 -#define ESCORTING_FLAGSHIP -7 -#define FEASIBILITY_STUDY -8 - /* Check for how many escort ships there's still space */ - extern COUNT ActivateStarShip (COUNT which_ship, SIZE state); extern COUNT GetIndexFromStarShip (QUEUE *pShipQ, HLINK hStarShip); extern int SetEscortCrewComplement (COUNT which_ship, COUNT crew_level, BYTE captain); -COUNT AddEscortShips (COUNT race, SIZE count); +extern 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 BOOLEAN HaveEscortShip (COUNT race); extern COUNT EscortFeasibilityStudy (COUNT race); extern COUNT CheckAlliance (COUNT race); extern void RemoveEscortShips (COUNT race); 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:47:05
|
Revision: 3725 http://sc2.svn.sourceforge.net/sc2/?rev=3725&view=rev Author: Meep-Eep Date: 2011-12-31 01:46:56 +0000 (Sat, 31 Dec 2011) Log Message: ----------- Simplify. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2011-12-31 01:39:02 UTC (rev 3724) +++ trunk/sc2/src/uqm/shipyard.c 2011-12-31 01:46:56 UTC (rev 3725) @@ -667,14 +667,10 @@ } else if (dx && !HINIBBLE (NewState)) { - NewState = NewState % HANGAR_SHIPS_ROW; - 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)); - else - NewState = (BYTE)(pMS->CurState - NewState + dx); + // Moving horizontally through the escort ship slots, + // wrapping around if necessary. + NewState = (pMS->CurState + HANGAR_SHIPS_ROW + dx) % + HANGAR_SHIPS_ROW; } if (select || cancel 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...> - 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-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-29 22:30:48
|
Revision: 3721 http://sc2.svn.sourceforge.net/sc2/?rev=3721&view=rev Author: Meep-Eep Date: 2011-12-29 22:30:42 +0000 (Thu, 29 Dec 2011) Log Message: ----------- More comment fixes. Modified Paths: -------------- trunk/sc2/src/uqm/flash.h Modified: trunk/sc2/src/uqm/flash.h =================================================================== --- trunk/sc2/src/uqm/flash.h 2011-12-29 21:29:16 UTC (rev 3720) +++ trunk/sc2/src/uqm/flash.h 2011-12-29 22:30:42 UTC (rev 3721) @@ -38,7 +38,7 @@ * Flash_setMergeFactors(fc, 2, 3, 2); * * // We change the flashing speed from the defaults. - * Flash_setSpeed (ONE_SECOND, ONE_SECOND, ONE_SECOND, ONE_SECOND); + * Flash_setSpeed (fc, ONE_SECOND, ONE_SECOND, ONE_SECOND, ONE_SECOND); * * // During cross-fades, update 8 times per second. * Flash_setFrameTime (fc, ONE_SECOND / 8); @@ -62,7 +62,7 @@ * ... * // Modifying the graphics of the area that is flashing: * void Flash_preUpdate (fc); - * ... // do Drawing + * ... // do drawing * void Flash_postUpdate (fc); * ... * // We're done. Terminating the flash restores the flash area to its @@ -77,13 +77,15 @@ * * Limitations: * - * 2) Functions that draw to the gfxContext or read the original gfxContext - * contents, which is most of them, must be called with gfxContext having - * the same clip-rect as it did when other drawing functions were called. - * Otherwise, original contents restoration may draw to the wrong area, or - * the wrong area may be read. - * There may be cases where one would *want* that to happen, and such - * cases are not covered by this limitation. + * * Functions that draw to the gfxContext or read the original gfxContext + * contents, which is most of them, must be called with gfxContext having + * the same clip-rect as it did when other drawing functions were called. + * Otherwise, original contents restoration may draw to the wrong area, or + * the wrong area may be read. + * There may be cases where one would *want* that to happen, and such + * cases are not covered by this limitation. + * * Multiple flashes may be used simultaneously, but don't let them + * overlap; artifacts would occur. */ #include "libs/gfxlib.h" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-29 21:29:22
|
Revision: 3720 http://sc2.svn.sourceforge.net/sc2/?rev=3720&view=rev Author: Meep-Eep Date: 2011-12-29 21:29:16 +0000 (Thu, 29 Dec 2011) Log Message: ----------- Change 'if' chain to switch. Now why didn't I use a switch in the first place? Modified Paths: -------------- trunk/sc2/src/uqm/flash.c Modified: trunk/sc2/src/uqm/flash.c =================================================================== --- trunk/sc2/src/uqm/flash.c 2011-12-29 21:18:08 UTC (rev 3719) +++ trunk/sc2/src/uqm/flash.c 2011-12-29 21:29:16 UTC (rev 3720) @@ -275,38 +275,37 @@ now = GetTimeCounter (); - if (context->state == FlashState_fadeIn) + switch (context->state) { - if (now >= context->lastStateTime + context->fadeInTime) - { + case FlashState_fadeIn: + if (now >= context->lastStateTime + context->fadeInTime) + { + Flash_nextState (context); + context->lastStateTime = now; + } + context->lastFrameTime = now; + break; + case FlashState_on: + if (now < context->lastStateTime + context->onTime) + return; Flash_nextState (context); context->lastStateTime = now; - } - context->lastFrameTime = now; - } - else if (context->state == FlashState_on) - { - if (now < context->lastStateTime + context->onTime) - return; - Flash_nextState (context); - context->lastStateTime = now; - } - else if (context->state == FlashState_fadeOut) - { - if (now >= context->lastStateTime + context->fadeOutTime) - { + break; + case FlashState_fadeOut: + if (now >= context->lastStateTime + context->fadeOutTime) + { + Flash_nextState (context); + context->lastStateTime = now; + } + context->lastFrameTime = now; + break; + case FlashState_off: + if (now < context->lastStateTime + context->offTime) + return; Flash_nextState (context); context->lastStateTime = now; - } - context->lastFrameTime = now; + break; } - else /* context->state == FlashState_off */ - { - if (now < context->lastStateTime + context->offTime) - return; - Flash_nextState (context); - context->lastStateTime = now; - } Flash_drawCurrentFrame (context); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-29 21:18:14
|
Revision: 3719 http://sc2.svn.sourceforge.net/sc2/?rev=3719&view=rev Author: Meep-Eep Date: 2011-12-29 21:18:08 +0000 (Thu, 29 Dec 2011) Log Message: ----------- Fix comments. Modified Paths: -------------- trunk/sc2/src/uqm/flash.h Modified: trunk/sc2/src/uqm/flash.h =================================================================== --- trunk/sc2/src/uqm/flash.h 2011-12-29 15:00:32 UTC (rev 3718) +++ trunk/sc2/src/uqm/flash.h 2011-12-29 21:18:08 UTC (rev 3719) @@ -31,18 +31,17 @@ * * // We create the flash context; it is used to manipulate the flash * // rectangle while it exists. - * FlashContext *fc = Flash_createHighlight (context, (FRAME) 0, rect); + * FlashContext *fc = Flash_createHighlight (gfxContext, rect); * * // Specify how bright the flash is at the beginning and ending of the * // sequence. - * Flash_setMergeFactors(context, 2, 3, 2); + * Flash_setMergeFactors(fc, 2, 3, 2); * * // We change the flashing speed from the defaults. * Flash_setSpeed (ONE_SECOND, ONE_SECOND, ONE_SECOND, ONE_SECOND); * * // During cross-fades, update 8 times per second. - * Flash_setFrameTime (gmstate.player[playerI].flashContext, - * ONE_SECOND / 8); + * Flash_setFrameTime (fc, ONE_SECOND / 8); * * // We start the flashing. The default is to start from the "off" state. * Flash_start (fc); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <av...@us...> - 2011-12-29 15:00:42
|
Revision: 3718 http://sc2.svn.sourceforge.net/sc2/?rev=3718&view=rev Author: avolkov Date: 2011-12-29 15:00:32 +0000 (Thu, 29 Dec 2011) Log Message: ----------- Still no mid-block variable declaration in VC6. No matter how hard you try, VC6 just won't accept it! :P Modified Paths: -------------- trunk/sc2/src/libs/graphics/context.c Modified: trunk/sc2/src/libs/graphics/context.c =================================================================== --- trunk/sc2/src/libs/graphics/context.c 2011-12-28 20:24:21 UTC (rev 3717) +++ trunk/sc2/src/libs/graphics/context.c 2011-12-29 15:00:32 UTC (rev 3718) @@ -123,6 +123,8 @@ BOOLEAN DestroyContext (CONTEXT ContextRef) { + TFB_Image *img; + if (ContextRef == 0) return (FALSE); @@ -139,7 +141,7 @@ } #endif /* DEBUG */ - TFB_Image *img = ContextRef->FontBacking; + img = ContextRef->FontBacking; if (img) TFB_DrawImage_Delete (img); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-28 20:24:27
|
Revision: 3717 http://sc2.svn.sourceforge.net/sc2/?rev=3717&view=rev Author: Meep-Eep Date: 2011-12-28 20:24:21 +0000 (Wed, 28 Dec 2011) Log Message: ----------- Added Valgrind suppression file, from Louis Delacroix Modified Paths: -------------- trunk/sc2/ChangeLog Added Paths: ----------- trunk/tools/valgrind/ trunk/tools/valgrind/sc2-valgrind.supp Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-12-28 19:40:24 UTC (rev 3716) +++ trunk/sc2/ChangeLog 2011-12-28 20:24:21 UTC (rev 3717) @@ -1,4 +1,5 @@ Changes towards version 0.8: +- Added Valgrind suppression file, from Louis 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 Added: trunk/tools/valgrind/sc2-valgrind.supp =================================================================== --- trunk/tools/valgrind/sc2-valgrind.supp (rev 0) +++ trunk/tools/valgrind/sc2-valgrind.supp 2011-12-28 20:24:21 UTC (rev 3717) @@ -0,0 +1,47 @@ +# Valgrind suppression file. +# Usage: +# valgrind --suppressions=sc2-valgrind.supp --log-file=sc2.vglog ./uqm-debug +{ + memory leaks in SDL + Memcheck:Leak + ... + obj:*/lib/libSDL* +} +{ + memory leaks in PulseAudio + Memcheck:Leak + ... + obj:*/lib/libpulse* +} +{ + memory leaks in libasound + Memcheck:Leak + ... + obj:*/lib/libasound* +} +{ + ioctl param in libasound + Memcheck:Param + ioctl(arg) + ... + obj:*/lib/libasound* +} +{ + semctl param in libasound + Memcheck:Param + semctl(IPC_SET, arg.buf) + ... + obj:*/lib/libasound* +} +{ + memory leaks in libX11 + Memcheck:Leak + ... + obj:*/lib/libX11* +} +{ + memory leaks in libmikmod + Memcheck:Leak + ... + obj:*/lib/libmikmod* +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-28 19:40:31
|
Revision: 3716 http://sc2.svn.sourceforge.net/sc2/?rev=3716&view=rev Author: Meep-Eep Date: 2011-12-28 19:40:24 +0000 (Wed, 28 Dec 2011) Log Message: ----------- Cleanup, simplify, from Louis Delacroix. Modified Paths: -------------- trunk/sc2/src/libs/memlib.h trunk/sc2/src/libs/memory/w_memlib.c Modified: trunk/sc2/src/libs/memlib.h =================================================================== --- trunk/sc2/src/libs/memlib.h 2011-12-28 18:43:45 UTC (rev 3715) +++ trunk/sc2/src/libs/memlib.h 2011-12-28 19:40:24 UTC (rev 3716) @@ -19,6 +19,8 @@ #ifndef _MEMLIB_H #define _MEMLIB_H +#include <stddef.h> + #include "types.h" #if defined(__cplusplus) @@ -28,10 +30,10 @@ extern bool mem_init (void); extern bool mem_uninit (void); -extern void *HMalloc (int size); +extern void *HMalloc (size_t size); extern void HFree (void *p); -extern void *HCalloc (int size); -extern void *HRealloc (void *p, int size); +extern void *HCalloc (size_t size); +extern void *HRealloc (void *p, size_t size); #if defined(__cplusplus) } Modified: trunk/sc2/src/libs/memory/w_memlib.c =================================================================== --- trunk/sc2/src/libs/memory/w_memlib.c 2011-12-28 18:43:45 UTC (rev 3715) +++ trunk/sc2/src/libs/memory/w_memlib.c 2011-12-28 19:40:24 UTC (rev 3716) @@ -38,68 +38,47 @@ } void * -HMalloc (int size) +HMalloc (size_t size) { - void *p; - - if (size == 0) - return NULL; - - if (size < 0) + void *p = malloc (size); + if (p == NULL && size > 0) { - log_add (log_Fatal, "HMalloc() FATAL: " - "request for negative amount of memory %d!", size); - fflush (stderr); - explode (); - } - - p = malloc (size); - if (p == NULL) - { log_add (log_Fatal, "HMalloc() FATAL: out of memory."); fflush (stderr); explode (); } - return (p); + + return p; } void HFree (void *p) { - if (p) - { - free (p); - } + free (p); } void * -HCalloc (int size) +HCalloc (size_t size) { void *p; p = HMalloc (size); memset (p, 0, size); - return (p); + return p; } void * -HRealloc (void *p, int size) +HRealloc (void *p, size_t size) { - if (size < 0) - { - log_add (log_Fatal, "HRealloc() FATAL: " - "request for negative amount of memory %d!", size); - fflush (stderr); - explode (); - } - p = realloc (p, size); - if (!p && size > 0) + if (p == NULL && size > 0) { log_add (log_Fatal, "HRealloc() FATAL: out of memory."); fflush (stderr); explode (); } + return p; } + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-28 18:43:51
|
Revision: 3715 http://sc2.svn.sourceforge.net/sc2/?rev=3715&view=rev Author: Meep-Eep Date: 2011-12-28 18:43:45 +0000 (Wed, 28 Dec 2011) Log Message: ----------- Reapply. Old SDL versions could return -1 (probably as a bug). We might as well handle this case. Modified Paths: -------------- trunk/sc2/src/libs/graphics/sdl/sdl_common.c Modified: trunk/sc2/src/libs/graphics/sdl/sdl_common.c =================================================================== --- trunk/sc2/src/libs/graphics/sdl/sdl_common.c 2011-12-28 18:31:23 UTC (rev 3714) +++ trunk/sc2/src/libs/graphics/sdl/sdl_common.c 2011-12-28 18:43:45 UTC (rev 3715) @@ -186,7 +186,7 @@ { SDL_Event Event; - while (SDL_PollEvent (&Event)) + while (SDL_PollEvent (&Event) > 0) { /* Run through the InputEvent filter. */ ProcessInputEvent (&Event); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-28 18:31:29
|
Revision: 3714 http://sc2.svn.sourceforge.net/sc2/?rev=3714&view=rev Author: Meep-Eep Date: 2011-12-28 18:31:23 +0000 (Wed, 28 Dec 2011) Log Message: ----------- Revert; SDL_PollEvent() never returns -1. Modified Paths: -------------- trunk/sc2/src/libs/graphics/sdl/sdl_common.c Modified: trunk/sc2/src/libs/graphics/sdl/sdl_common.c =================================================================== --- trunk/sc2/src/libs/graphics/sdl/sdl_common.c 2011-12-28 18:26:00 UTC (rev 3713) +++ trunk/sc2/src/libs/graphics/sdl/sdl_common.c 2011-12-28 18:31:23 UTC (rev 3714) @@ -186,7 +186,7 @@ { SDL_Event Event; - while (SDL_PollEvent (&Event) > 0) + while (SDL_PollEvent (&Event)) { /* Run through the InputEvent filter. */ ProcessInputEvent (&Event); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-28 18:26:07
|
Revision: 3713 http://sc2.svn.sourceforge.net/sc2/?rev=3713&view=rev Author: Meep-Eep Date: 2011-12-28 18:26:00 +0000 (Wed, 28 Dec 2011) Log Message: ----------- SDL_PollEvent may return -1. Handle this. Modified Paths: -------------- trunk/sc2/src/libs/graphics/sdl/sdl_common.c Modified: trunk/sc2/src/libs/graphics/sdl/sdl_common.c =================================================================== --- trunk/sc2/src/libs/graphics/sdl/sdl_common.c 2011-12-28 18:00:11 UTC (rev 3712) +++ trunk/sc2/src/libs/graphics/sdl/sdl_common.c 2011-12-28 18:26:00 UTC (rev 3713) @@ -186,7 +186,7 @@ { SDL_Event Event; - while (SDL_PollEvent (&Event)) + while (SDL_PollEvent (&Event) > 0) { /* Run through the InputEvent filter. */ ProcessInputEvent (&Event); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-28 18:00:20
|
Revision: 3712 http://sc2.svn.sourceforge.net/sc2/?rev=3712&view=rev Author: Meep-Eep Date: 2011-12-28 18:00:11 +0000 (Wed, 28 Dec 2011) Log Message: ----------- Fix memory leak, from Louis Delacroix. Modified Paths: -------------- trunk/sc2/src/libs/graphics/context.c Modified: trunk/sc2/src/libs/graphics/context.c =================================================================== --- trunk/sc2/src/libs/graphics/context.c 2011-12-28 17:51:58 UTC (rev 3711) +++ trunk/sc2/src/libs/graphics/context.c 2011-12-28 18:00:11 UTC (rev 3712) @@ -139,6 +139,10 @@ } #endif /* DEBUG */ + TFB_Image *img = ContextRef->FontBacking; + if (img) + TFB_DrawImage_Delete (img); + FreeContext (ContextRef); return TRUE; } 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-26 01:35:13
|
Revision: 3710 http://sc2.svn.sourceforge.net/sc2/?rev=3710&view=rev Author: Meep-Eep Date: 2011-12-26 01:35:07 +0000 (Mon, 26 Dec 2011) Log Message: ----------- Small step towards cleaning up this mess. Modified Paths: -------------- trunk/sc2/src/libs/strings/getstr.c Modified: trunk/sc2/src/libs/strings/getstr.c =================================================================== --- trunk/sc2/src/libs/strings/getstr.c 2011-12-21 18:03:45 UTC (rev 3709) +++ trunk/sc2/src/libs/strings/getstr.c 2011-12-26 01:35:07 UTC (rev 3710) @@ -67,14 +67,33 @@ uio_Stream *fp; unsigned long dataLen; void *result; - int n, path_len, num_data_sets; - DWORD opos, - slen[MAX_STRINGS], StringOffs, tot_string_size, - clen[MAX_STRINGS], ClipOffs, tot_clip_size, - tslen[MAX_STRINGS], TSOffs; + int n; + int path_len; + int num_data_sets; + DWORD opos; + DWORD slen[MAX_STRINGS]; + // Length of each of the dialog strings. + DWORD StringOffs; + DWORD tot_string_size; + DWORD clen[MAX_STRINGS]; + // Length of each of the speech file names. + DWORD ClipOffs; + DWORD tot_clip_size; + DWORD tslen[MAX_STRINGS]; + // Length of each of the timestamp strings. + DWORD TSOffs; DWORD tot_ts_size = 0; - char CurrentLine[1024], paths[1024], *clip_path, *ts_path, - *strdata, *clipdata, *ts_data; + char CurrentLine[1024]; + char paths[1024]; + char *clip_path; + char *ts_path; + char *strdata = NULL; + // Contains the dialog strings. + char *clipdata = NULL; + // Contains the file names of the speech files. + char *ts_data = NULL; + // Contains the timestamp data for synching the text with the + // speech. uio_Stream *timestamp_fp = NULL; /* Parse out the conversation components. */ @@ -107,7 +126,8 @@ } dataLen = LengthResFile (fp); - log_add (log_Info, "\t'%s' -- conversation phrases -- %lu bytes", paths, dataLen); + log_add (log_Info, "\t'%s' -- conversation phrases -- %lu bytes", paths, + dataLen); if (clip_path) log_add (log_Info, "\t'%s' -- voice clip directory", clip_path); else @@ -117,41 +137,51 @@ else log_add (log_Info, "\tNo associated timestamp file"); - if (dataLen == 0) { - log_add (log_Warning, "Warning: Trying to load empty file '%s'.", path); + log_add (log_Warning, "Warning: Trying to load empty file '%s'.", + path); goto err; } - if ((strdata = HMalloc (tot_string_size = POOL_SIZE)) == 0) + tot_string_size = POOL_SIZE; + strdata = HMalloc (tot_string_size); + if (strdata == 0) goto err; - if ((clipdata = HMalloc (tot_clip_size = POOL_SIZE)) == 0) - { - HFree (strdata); + tot_clip_size = POOL_SIZE; + clipdata = HMalloc (tot_clip_size); + if (clipdata == 0) goto err; - } ts_data = NULL; path_len = clip_path ? strlen (clip_path) : 0; - if (ts_path && (timestamp_fp = uio_fopen (contentDir, ts_path, - "rb"))) + if (ts_path) { - if ((ts_data = HMalloc (tot_ts_size = POOL_SIZE)) == 0) - goto err; + timestamp_fp = uio_fopen (contentDir, ts_path, "rb"); + if (timestamp_fp != NULL) + { + tot_ts_size = POOL_SIZE; + ts_data = HMalloc (tot_ts_size); + if (ts_data == 0) + goto err; + } } opos = uio_ftell (fp); n = -1; - StringOffs = ClipOffs = TSOffs = 0; + StringOffs = 0; + ClipOffs = 0; + TSOffs = 0; while (uio_fgets (CurrentLine, sizeof (CurrentLine), fp) && n < MAX_STRINGS - 1) { int l; if (CurrentLine[0] == '#') { + // String header, of the following form: + // #(GLAD_WHEN_YOU_COME_BACK) commander-000.ogg char CopyLine[1024]; char *s; @@ -161,7 +191,7 @@ { if (n >= 0) { - while (slen[n] > 1 && + while (slen[n] > 1 && (strdata[StringOffs - 2] == '\n' || strdata[StringOffs - 2] == '\r')) { @@ -172,32 +202,38 @@ } slen[++n] = 0; + // now lets check for timestamp data if (timestamp_fp) { - char TimeStampLine[1024], *tsptr; + // We have a time stamp file. + char TimeStampLine[1024]; + char *tsptr; BOOLEAN ts_ok = FALSE; uio_fgets (TimeStampLine, sizeof (TimeStampLine), timestamp_fp); if (TimeStampLine[0] == '#') { + // Line is of the following form: + // #(GIVE_FUEL_AGAIN) 3304,3255 tslen[n] = 0; - if ((tsptr = strstr (TimeStampLine,s)) - && (tsptr += strlen(s)) - && (++tsptr)) + tsptr = strstr (TimeStampLine, s); + if (tsptr) { + tsptr += strlen(s) + 1; ts_ok = TRUE; while (! strcspn(tsptr," \t\r\n") && *tsptr) tsptr++; if (*tsptr) { - l = strlen (tsptr) + 1; - if (TSOffs + l > tot_ts_size - && (ts_data = HRealloc (ts_data, - tot_ts_size += POOL_SIZE)) == 0) + l = strlen (tsptr) + 1; + if (TSOffs + l > tot_ts_size) { - HFree (strdata); - goto err; + tot_ts_size += POOL_SIZE; + ts_data = HRealloc (ts_data, tot_ts_size); + if (ts_data == 0) + goto err; // BUG: old ts_data leaks } + strcpy (&ts_data[TSOffs], tsptr); TSOffs += l; tslen[n] = l; @@ -221,12 +257,12 @@ if (s) { l = path_len + strlen (s) + 1; - if (ClipOffs + l > tot_clip_size - && (clipdata = HRealloc (clipdata, - tot_clip_size += POOL_SIZE)) == 0) + if (ClipOffs + l > tot_clip_size) { - HFree (strdata); - goto err; + tot_clip_size += POOL_SIZE; + clipdata = HRealloc (clipdata, tot_clip_size); + if (clipdata == 0) + goto err; // BUG: old clipdata leaks } if (clip_path) @@ -241,12 +277,12 @@ { char *s; l = strlen (CurrentLine) + 1; - if (StringOffs + l > tot_string_size - && (strdata = HRealloc (strdata, - tot_string_size += POOL_SIZE)) == 0) + if (StringOffs + l > tot_string_size) { - HFree (clipdata); - goto err; + tot_string_size += POOL_SIZE; + strdata = HRealloc (strdata, tot_string_size); + if (strdata == 0) + goto err; // BUG: old strdata leaks } if (slen[n]) @@ -287,10 +323,13 @@ flags |= HAS_SOUND_CLIPS; if (TSOffs) flags |= HAS_TIMESTAMP; + result = AllocStringTable (n, flags); if (result) { - int StringIndex, ClipIndex, TSIndex; + int StringIndex; + int ClipIndex; + int TSIndex; STRING_TABLE_DESC *lpST; lpST = (STRING_TABLE) result; @@ -299,7 +338,9 @@ ClipIndex = n; TSIndex = n * ((flags & HAS_SOUND_CLIPS) ? 2 : 1); - StringOffs = ClipOffs = TSOffs = 0; + StringOffs = 0; + ClipOffs = 0; + TSOffs = 0; for (n = 0; n < (int)lpST->size; ++n, ++StringIndex, ++ClipIndex, ++TSIndex) @@ -328,9 +369,14 @@ return; err: + if (ts_data != NULL) + HFree (ts_data); + if (clipdata != NULL) + HFree (clipdata); + if (strdata != NULL) + HFree (strdata); res_CloseResFile (fp); resdata->ptr = NULL; - } void * @@ -342,8 +388,10 @@ DWORD opos, slen[MAX_STRINGS], StringOffs, tot_string_size; char CurrentLine[1024], *strdata; - if ((strdata = HMalloc (tot_string_size = POOL_SIZE)) == 0) - return (0); + tot_string_size = POOL_SIZE; + strdata = HMalloc (tot_string_size); + if (strdata == 0) + return 0; opos = uio_ftell (fp); n = -1; @@ -380,11 +428,12 @@ { char *s; l = strlen (CurrentLine) + 1; - if (StringOffs + l > tot_string_size - && (strdata = HRealloc (strdata, - tot_string_size += POOL_SIZE)) == 0) + if (StringOffs + l > tot_string_size) { - return (0); + tot_string_size += POOL_SIZE; + strdata = HRealloc (strdata, tot_string_size); + if (strdata == 0) + return 0; // BUG: old strdata leaks } if (slen[n]) @@ -439,7 +488,7 @@ } HFree (strdata); - return (result); + return result; } @@ -478,6 +527,6 @@ result = lpST; } - return (result); + return result; } 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-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. |