From: <av...@us...> - 2009-06-30 10:06:56
|
Revision: 3163 http://sc2.svn.sourceforge.net/sc2/?rev=3163&view=rev Author: avolkov Date: 2009-06-30 10:06:23 +0000 (Tue, 30 Jun 2009) Log Message: ----------- Starmap unit conversion corrections and lazy-cursor fix; fixes bug #970 Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/sc2code/planets/pstarmap.c Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2009-06-30 05:32:24 UTC (rev 3162) +++ trunk/sc2/ChangeLog 2009-06-30 10:06:23 UTC (rev 3163) @@ -1,4 +1,5 @@ Changes towards version 0.7: +- Starmap unit conversion corrections; fixes bug #970 - Alex - Rounding-error correction in log(x|y)ToUniverse (bug #1046), from Nic - Change hardcoded Starbase and Sa-Matra values to pretty enum values (bug #1047), from Nic Modified: trunk/sc2/src/sc2code/planets/pstarmap.c =================================================================== --- trunk/sc2/src/sc2code/planets/pstarmap.c 2009-06-30 05:32:24 UTC (rev 3162) +++ trunk/sc2/src/sc2code/planets/pstarmap.c 2009-06-30 10:06:23 UTC (rev 3163) @@ -36,24 +36,59 @@ #include "libs/mathlib.h" +static inline long +signedDivWithError (long val, long divisor) +{ + int invert = 0; + if (val < 0) + { + invert = 1; + val = -val; + } + val = (val + ROUNDING_ERROR (divisor)) / divisor; + return invert ? -val : val; +} -#define UNIVERSE_TO_DISPX(ux) \ - (COORD)(((((long)(ux) - pMenuState->flash_rect1.corner.x) \ - << LOBYTE (pMenuState->delta_item)) \ - * SIS_SCREEN_WIDTH / (MAX_X_UNIVERSE + 1)) + ((SIS_SCREEN_WIDTH - 1) >> 1)) -#define UNIVERSE_TO_DISPY(uy) \ - (COORD)(((((long)pMenuState->flash_rect1.corner.y - (uy)) \ - << LOBYTE (pMenuState->delta_item)) \ - * SIS_SCREEN_HEIGHT / (MAX_Y_UNIVERSE + 1)) + ((SIS_SCREEN_HEIGHT - 1) >> 1)) -#define DISP_TO_UNIVERSEX(dx) \ - ((COORD)((((long)((dx) - ((SIS_SCREEN_WIDTH - 1) >> 1)) \ - * (MAX_X_UNIVERSE + 1)) >> LOBYTE (pMenuState->delta_item)) \ - / SIS_SCREEN_WIDTH) + pMenuState->flash_rect1.corner.x) -#define DISP_TO_UNIVERSEY(dy) \ - ((COORD)((((long)(((SIS_SCREEN_HEIGHT - 1) >> 1) - (dy)) \ - * (MAX_Y_UNIVERSE + 1)) >> LOBYTE (pMenuState->delta_item)) \ - / SIS_SCREEN_HEIGHT) + pMenuState->flash_rect1.corner.y) +#define MAP_FIT_X ((MAX_X_UNIVERSE + 1) / SIS_SCREEN_WIDTH + 1) +static inline COORD +universeToDispx (COORD ux) +{ + return signedDivWithError ((((long)ux - pMenuState->flash_rect1.corner.x) + << LOBYTE (pMenuState->delta_item)) + * SIS_SCREEN_WIDTH, MAX_X_UNIVERSE + MAP_FIT_X) + + ((SIS_SCREEN_WIDTH - 1) >> 1); +} +#define UNIVERSE_TO_DISPX(ux) universeToDispx(ux) + +static inline COORD +universeToDispy (COORD uy) +{ + return signedDivWithError ((((long)pMenuState->flash_rect1.corner.y - uy) + << LOBYTE (pMenuState->delta_item)) + * SIS_SCREEN_HEIGHT, MAX_Y_UNIVERSE + 2) + + ((SIS_SCREEN_HEIGHT - 1) >> 1); +} +#define UNIVERSE_TO_DISPY(uy) universeToDispy(uy) + +static inline COORD +dispxToUniverse (COORD dx) +{ + return (((long)(dx - ((SIS_SCREEN_WIDTH - 1) >> 1)) + * (MAX_X_UNIVERSE + MAP_FIT_X)) >> LOBYTE (pMenuState->delta_item)) + / SIS_SCREEN_WIDTH + pMenuState->flash_rect1.corner.x; +} +#define DISP_TO_UNIVERSEX(dx) dispxToUniverse(dx) + +static inline COORD +dispyToUniverse (COORD dy) +{ + return (((long)(((SIS_SCREEN_HEIGHT - 1) >> 1) - dy) + * (MAX_Y_UNIVERSE + 2)) >> LOBYTE (pMenuState->delta_item)) + / SIS_SCREEN_HEIGHT + pMenuState->flash_rect1.corner.y; +} +#define DISP_TO_UNIVERSEY(dy) dispyToUniverse(dy) + static BOOLEAN transition_pending; static int @@ -619,43 +654,29 @@ if (sx) { - pMS->first_item.x = - DISP_TO_UNIVERSEX (s.origin.x) - sx; + pMS->first_item.x = DISP_TO_UNIVERSEX (s.origin.x) - sx; while (UNIVERSE_TO_DISPX (pMS->first_item.x) == pt.x) - { pMS->first_item.x += sx; - if (pMS->first_item.x < 0) - { - pMS->first_item.x = 0; - break; - } - else if (pMS->first_item.x > MAX_X_UNIVERSE) - { - pMS->first_item.x = MAX_X_UNIVERSE; - break; - } - } + + if (pMS->first_item.x < 0) + pMS->first_item.x = 0; + else if (pMS->first_item.x > MAX_X_UNIVERSE) + pMS->first_item.x = MAX_X_UNIVERSE; + s.origin.x = UNIVERSE_TO_DISPX (pMS->first_item.x); } if (sy) { - pMS->first_item.y = - DISP_TO_UNIVERSEY (s.origin.y) + sy; + pMS->first_item.y = DISP_TO_UNIVERSEY (s.origin.y) + sy; while (UNIVERSE_TO_DISPY (pMS->first_item.y) == pt.y) - { pMS->first_item.y -= sy; - if (pMS->first_item.y < 0) - { - pMS->first_item.y = 0; - break; - } - else if (pMS->first_item.y > MAX_Y_UNIVERSE) - { - pMS->first_item.y = MAX_Y_UNIVERSE; - break; - } - } + + if (pMS->first_item.y < 0) + pMS->first_item.y = 0; + else if (pMS->first_item.y > MAX_Y_UNIVERSE) + pMS->first_item.y = MAX_Y_UNIVERSE; + s.origin.y = UNIVERSE_TO_DISPY (pMS->first_item.y); } @@ -707,6 +728,19 @@ pMS->first_item = BestSDPtr->star_pt; GetClusterName (BestSDPtr, buf); } + else + { // No star found. Reset the coordinates to the cursor's location + pMS->first_item.x = DISP_TO_UNIVERSEX (pt.x); + if (pMS->first_item.x < 0) + pMS->first_item.x = 0; + else if (pMS->first_item.x > MAX_X_UNIVERSE) + pMS->first_item.x = MAX_X_UNIVERSE; + pMS->first_item.y = DISP_TO_UNIVERSEY (pt.y); + if (pMS->first_item.y < 0) + pMS->first_item.y = 0; + else if (pMS->first_item.y > MAX_Y_UNIVERSE) + pMS->first_item.y = MAX_Y_UNIVERSE; + } if (GET_GAME_STATE (ARILOU_SPACE)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |