From: <av...@us...> - 2009-12-03 21:36:39
|
Revision: 3385 http://sc2.svn.sourceforge.net/sc2/?rev=3385&view=rev Author: avolkov Date: 2009-12-03 21:36:32 +0000 (Thu, 03 Dec 2009) Log Message: ----------- Cleanup: use IP location<->display conversion functions; some ipdisp clarifications Modified Paths: -------------- trunk/sc2/src/uqm/element.h trunk/sc2/src/uqm/grpinfo.c trunk/sc2/src/uqm/ipdisp.c trunk/sc2/src/uqm/planets/generate/gensam.c trunk/sc2/src/uqm/planets/planets.h trunk/sc2/src/uqm/planets/solarsys.c Modified: trunk/sc2/src/uqm/element.h =================================================================== --- trunk/sc2/src/uqm/element.h 2009-12-03 03:54:12 UTC (rev 3384) +++ trunk/sc2/src/uqm/element.h 2009-12-03 21:36:32 UTC (rev 3385) @@ -134,11 +134,16 @@ * with CREATURE_AWARE * - for canned bio: value of creature */ - BYTE sys_loc; /* IP: location in system */ + // TODO: Use a different name for Planetside bio, like + // BYTE bio_state; }; - BYTE turn_wait; union { + BYTE turn_wait; + BYTE sys_loc; /* IP flagship: location in system */ + }; + union + { BYTE thrust_wait; BYTE blast_offset; BYTE next_turn; /* Battle: animation interframe for some elements */ Modified: trunk/sc2/src/uqm/grpinfo.c =================================================================== --- trunk/sc2/src/uqm/grpinfo.c 2009-12-03 03:54:12 UTC (rev 3384) +++ trunk/sc2/src/uqm/grpinfo.c 2009-12-03 21:36:32 UTC (rev 3385) @@ -656,8 +656,7 @@ COUNT angle; POINT org; - XFormIPLoc (&pSolarSysState->PlanetDesc[group_loc - 1] - .image.origin, &org, FALSE); + org = planetOuterLocation (group_loc - 1); angle = FACING_TO_ANGLE (GroupPtr->orbit_pos + 1); GroupPtr->loc.x = org.x + COSINE (angle, STATION_RADIUS); GroupPtr->loc.y = org.y + SINE (angle, STATION_RADIUS); Modified: trunk/sc2/src/uqm/ipdisp.c =================================================================== --- trunk/sc2/src/uqm/ipdisp.c 2009-12-03 03:54:12 UTC (rev 3384) +++ trunk/sc2/src/uqm/ipdisp.c 2009-12-03 21:36:32 UTC (rev 3385) @@ -97,6 +97,43 @@ } } +static SIZE +zoomRadiusForLocation (BYTE location) +{ + if (location == 0) + { // In outer system view; use current zoom radius + return pSolarSysState->SunDesc[0].radius; + } + else + { // In inner system view; always max zoom + return MAX_ZOOM_RADIUS; + } +} + +static inline void +adjustDeltaVforZoom (SIZE zoom, SIZE *dx, SIZE *dy) +{ + if (zoom == MIN_ZOOM_RADIUS) + { + *dx >>= 2; + *dy >>= 2; + } + else if (zoom < MAX_ZOOM_RADIUS) + { + *dx >>= 1; + *dy >>= 1; + } +} + +static BYTE +getFlagshipLocation (void) +{ + if (!playerInInnerSystem ()) + return 0; + else + return 1 + planetIndex (pSolarSysState, pSolarSysState->pOrbitalDesc); +} + static void ip_group_preprocess (ELEMENT *ElementPtr) { @@ -117,17 +154,8 @@ group_loc = GroupPtr->sys_loc; // save old location DisplayArray[EPtr->PrimIndex].Object.Point = GroupPtr->loc; - if (group_loc != 0) - radius = MAX_ZOOM_RADIUS; - else - radius = pSolarSysState->SunDesc[0].radius; - - dest_pt.x = (SIS_SCREEN_WIDTH >> 1) - + (SIZE)((long)GroupPtr->loc.x - * (DISPLAY_FACTOR >> 1) / radius); - dest_pt.y = (SIS_SCREEN_HEIGHT >> 1) - + (SIZE)((long)GroupPtr->loc.y - * (DISPLAY_FACTOR >> 1) / radius); + radius = zoomRadiusForLocation (group_loc); + dest_pt = locationToDisplay (GroupPtr->loc, radius); EPtr->current.location.x = DISPLAY_TO_WORLD (dest_pt.x) + (COORD)(LOG_SPACE_WIDTH >> 1) - (LOG_SPACE_WIDTH >> (MAX_REDUCTION + 1)); @@ -137,11 +165,7 @@ InitIntersectStartPoint (EPtr); - if (!playerInInnerSystem ()) - flagship_loc = 0; - else - flagship_loc = (BYTE)(pSolarSysState->pBaseDesc->pPrevDesc - - pSolarSysState->PlanetDesc + 1); + flagship_loc = getFlagshipLocation (); task = GroupPtr->task; @@ -246,13 +270,7 @@ else { orbit_dist = STATION_RADIUS; - XFormIPLoc ( - &pSolarSysState->PlanetDesc[ - target_loc - 1 - ].image.origin, - &org, - FALSE - ); + org = planetOuterLocation (target_loc - 1); } angle = FACING_TO_ANGLE (GroupPtr->orbit_pos + 1); @@ -289,8 +307,7 @@ if (GroupPtr->dest_loc == 0) dest_pt = pSolarSysState->SunDesc[0].location; else - XFormIPLoc (&pSolarSysState->PlanetDesc[ - target_loc - 1].image.origin, &dest_pt, FALSE); + dest_pt = planetOuterLocation (target_loc - 1); } else { @@ -331,12 +348,13 @@ EPtr->thrust_wait = TRACK_WAIT; } - SetVelocityComponents (&EPtr->velocity, - vdx = COSINE (angle, speed), - vdy = SINE (angle, speed)); + vdx = COSINE (angle, speed); + vdy = SINE (angle, speed); + SetVelocityComponents (&EPtr->velocity, vdx, vdy); } - dx = vdx, dy = vdy; + dx = vdx; + dy = vdy; if (group_loc == target_loc) { if (target_loc == 0) @@ -351,7 +369,8 @@ >= (long)delta_x * delta_x + (long)delta_y * delta_y) { GroupPtr->loc = dest_pt; - vdx = vdy = 0; + vdx = 0; + vdy = 0; ZeroVelocityComponents (&EPtr->velocity); } } @@ -359,17 +378,8 @@ else { if (group_loc == 0) - { - if (pSolarSysState->SunDesc[0].radius < MAX_ZOOM_RADIUS) - { - dx >>= 1; - dy >>= 1; - if (pSolarSysState->SunDesc[0].radius == MIN_ZOOM_RADIUS) - { - dx >>= 1; - dy >>= 1; - } - } + { // In outer system + adjustDeltaVforZoom (radius, &dx, &dy); if (task == ON_STATION && GroupPtr->dest_loc) goto PartialRevolution; @@ -378,14 +388,9 @@ Transition = TRUE; } else - { + { // In inner system; also leaving outer CheckGetAway hack CheckGetAway: - dest_pt.x = (SIS_SCREEN_WIDTH >> 1) - + (SIZE)((long)GroupPtr->loc.x - * (DISPLAY_FACTOR >> 1) / MAX_ZOOM_RADIUS); - dest_pt.y = (SIS_SCREEN_HEIGHT >> 1) - + (SIZE)((long)GroupPtr->loc.y - * (DISPLAY_FACTOR >> 1) / MAX_ZOOM_RADIUS); + dest_pt = locationToDisplay (GroupPtr->loc, radius); if (dest_pt.x < 0 || dest_pt.x >= SIS_SCREEN_WIDTH || dest_pt.y < 0 @@ -398,15 +403,12 @@ /* no collisions during transition */ EPtr->state_flags |= NONSOLID; - vdx = vdy = 0; + vdx = 0; + vdy = 0; ZeroVelocityComponents (&EPtr->velocity); if (group_loc != 0) { - PLANET_DESC *pCurDesc; - - pCurDesc = &pSolarSysState->PlanetDesc[group_loc - 1]; - XFormIPLoc (&pCurDesc->image.origin, &GroupPtr->loc, - FALSE); + GroupPtr->loc = planetOuterLocation (group_loc - 1); group_loc = 0; GroupPtr->sys_loc = 0; } @@ -420,6 +422,8 @@ } else { + POINT entryPt; + if (target_loc == GroupPtr->dest_loc) { GroupPtr->orbit_pos = NORMALIZE_FACING ( @@ -428,14 +432,17 @@ ((COUNT)TFB_Random () % MAX_REVOLUTIONS) << FACING_SHIFT; } - - GroupPtr->loc.x = -(SIZE)((long)COSINE ( - angle, SIS_SCREEN_WIDTH * 9 / 16 - ) * MAX_ZOOM_RADIUS / (DISPLAY_FACTOR >> 1)); - GroupPtr->loc.y = -(SIZE)((long)SINE ( - angle, SIS_SCREEN_WIDTH * 9 / 16 - ) * MAX_ZOOM_RADIUS / (DISPLAY_FACTOR >> 1)); - + // The group enters inner system exactly on the edge of a + // circle with radius = 9/16 * window-dim, which is + // different from how the flagship enters, but similar + // in the way that the group will never show up in any + // of the corners. + entryPt.x = (SIS_SCREEN_WIDTH >> 1) - COSINE (angle, + SIS_SCREEN_WIDTH * 9 / 16); + entryPt.y = (SIS_SCREEN_HEIGHT >> 1) - SINE (angle, + SIS_SCREEN_HEIGHT * 9 / 16); + GroupPtr->loc = displayToLocation (entryPt, + MAX_ZOOM_RADIUS); group_loc = target_loc; GroupPtr->sys_loc = target_loc; } @@ -443,32 +450,12 @@ } } - if (group_loc != 0) - radius = MAX_ZOOM_RADIUS; - else - { - radius = pSolarSysState->SunDesc[0].radius; - if (radius < MAX_ZOOM_RADIUS) - { - vdx >>= 1; - vdy >>= 1; - if (radius == MIN_ZOOM_RADIUS) - { - vdx >>= 1; - vdy >>= 1; - } - } - } + radius = zoomRadiusForLocation (group_loc); + adjustDeltaVforZoom (radius, &vdx, &vdy); GroupPtr->loc.x += vdx; GroupPtr->loc.y += vdy; - dest_pt.x = (SIS_SCREEN_WIDTH >> 1) - + (SIZE)((long)GroupPtr->loc.x - * (DISPLAY_FACTOR >> 1) / radius); - dest_pt.y = (SIS_SCREEN_HEIGHT >> 1) - + (SIZE)((long)GroupPtr->loc.y - * (DISPLAY_FACTOR >> 1) / radius); - + dest_pt = locationToDisplay (GroupPtr->loc, radius); EPtr->next.location.x = DISPLAY_TO_WORLD (dest_pt.x) + (COORD)(LOG_SPACE_WIDTH >> 1) - (LOG_SPACE_WIDTH >> (MAX_REDUCTION + 1)); @@ -583,9 +570,8 @@ ELEMENT *IPSHIPElementPtr; LockElement (hIPSHIPElement, &IPSHIPElementPtr); - // XXX: turn_wait hack is not actually used anywhere - //IPSHIPElementPtr->turn_wait = GroupPtr->group_id; - IPSHIPElementPtr->sys_loc = 1; + // Must have mass_points for collisions to work + IPSHIPElementPtr->mass_points = 1; IPSHIPElementPtr->hit_points = 1; IPSHIPElementPtr->state_flags = CHANGING | FINITE_LIFE | IGNORE_VELOCITY; @@ -608,18 +594,9 @@ SIZE radius; POINT pt; - if (GroupPtr->sys_loc != 0) - radius = MAX_ZOOM_RADIUS; - else - radius = pSolarSysState->SunDesc[0].radius; + radius = zoomRadiusForLocation (GroupPtr->sys_loc); + pt = locationToDisplay (GroupPtr->loc, radius); - pt.x = (SIS_SCREEN_WIDTH >> 1) - + (SIZE)((long)GroupPtr->loc.x - * DISPLAY_FACTOR / radius); - pt.y = (SIS_SCREEN_HEIGHT >> 1) - + (SIZE)((long)GroupPtr->loc.y - * (DISPLAY_FACTOR >> 1) / radius); - IPSHIPElementPtr->current.location.x = DISPLAY_TO_WORLD (pt.x) + (COORD)(LOG_SPACE_WIDTH >> 1) @@ -676,34 +653,11 @@ GetCurrentVelocityComponents (&GLOBAL (velocity), &vdx, &vdy); - if (playerInInnerSystem ()) - { - flagship_loc = (BYTE)(pSolarSysState->pBaseDesc->pPrevDesc - - pSolarSysState->PlanetDesc + 2); - radius = MAX_ZOOM_RADIUS; - } - else - { - flagship_loc = 1; - radius = pSolarSysState->SunDesc[0].radius; - if (radius < MAX_ZOOM_RADIUS) - { - vdx >>= 1; - vdy >>= 1; - if (radius == MIN_ZOOM_RADIUS) - { - vdx >>= 1; - vdy >>= 1; - } - } - } + flagship_loc = getFlagshipLocation (); + radius = zoomRadiusForLocation (flagship_loc); + adjustDeltaVforZoom (radius, &vdx, &vdy); - pt.x = (SIS_SCREEN_WIDTH >> 1) - + (SIZE)((long)GLOBAL (ip_location.x) - * (DISPLAY_FACTOR >> 1) / radius); - pt.y = (SIS_SCREEN_HEIGHT >> 1) - + (SIZE)((long)GLOBAL (ip_location.y) - * (DISPLAY_FACTOR >> 1) / radius); + pt = locationToDisplay (GLOBAL (ip_location), radius); ElementPtr->current.location.x = DISPLAY_TO_WORLD (pt.x) + (COORD)(LOG_SPACE_WIDTH >> 1) - (LOG_SPACE_WIDTH >> (MAX_REDUCTION + 1)); @@ -715,12 +669,7 @@ GLOBAL (ip_location.x) += vdx; GLOBAL (ip_location.y) += vdy; - pt.x = (SIS_SCREEN_WIDTH >> 1) - + (SIZE)((long)GLOBAL (ip_location.x) - * (DISPLAY_FACTOR >> 1) / radius); - pt.y = (SIS_SCREEN_HEIGHT >> 1) - + (SIZE)((long)GLOBAL (ip_location.y) - * (DISPLAY_FACTOR >> 1) / radius); + pt = locationToDisplay (GLOBAL (ip_location), radius); ElementPtr->next.location.x = DISPLAY_TO_WORLD (pt.x) + (COORD)(LOG_SPACE_WIDTH >> 1) - (LOG_SPACE_WIDTH >> (MAX_REDUCTION + 1)); @@ -767,12 +716,9 @@ LockElement (hFlagShipElement, &FlagShipElementPtr); FlagShipElementPtr->hit_points = 1; - if (!playerInInnerSystem ()) - FlagShipElementPtr->sys_loc = 1; - else - FlagShipElementPtr->sys_loc = - (BYTE)(pSolarSysState->pBaseDesc->pPrevDesc - - pSolarSysState->PlanetDesc + 2); + // Must have mass_points for collisions to work + FlagShipElementPtr->mass_points = 1; + FlagShipElementPtr->sys_loc = getFlagshipLocation (); FlagShipElementPtr->state_flags = APPEARING | IGNORE_VELOCITY; if (GET_GAME_STATE (ESCAPE_COUNTER)) FlagShipElementPtr->state_flags |= NONSOLID; Modified: trunk/sc2/src/uqm/planets/generate/gensam.c =================================================================== --- trunk/sc2/src/uqm/planets/generate/gensam.c 2009-12-03 03:54:12 UTC (rev 3384) +++ trunk/sc2/src/uqm/planets/generate/gensam.c 2009-12-03 21:36:32 UTC (rev 3385) @@ -114,7 +114,7 @@ COUNT angle; POINT org; - XFormIPLoc (&solarSys->PlanetDesc[4].image.origin, &org, FALSE); + org = planetOuterLocation (4); angle = ARCTAN (GLOBAL (ip_location.x) - org.x, GLOBAL (ip_location.y) - org.y); GLOBAL (ip_location.x) = org.x + COSINE (angle, 3000); @@ -275,7 +275,7 @@ GetGroupInfo (GLOBAL (BattleGroupRef), GROUP_INIT_IP); - XFormIPLoc (&solarSys->PlanetDesc[4].image.origin, &org, FALSE); + org = planetOuterLocation (4); hGroup = GetHeadLink (&GLOBAL (ip_group_q)); for (b0 = 0, b1 = 0; b0 < NUM_URQUAN_GUARDS0; Modified: trunk/sc2/src/uqm/planets/planets.h =================================================================== --- trunk/sc2/src/uqm/planets/planets.h 2009-12-03 03:54:12 UTC (rev 3384) +++ trunk/sc2/src/uqm/planets/planets.h 2009-12-03 21:36:32 UTC (rev 3385) @@ -236,6 +236,10 @@ bool matchWorld (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world, BYTE planetI, BYTE moonI); +POINT locationToDisplay (POINT pt, SIZE scaleRadius); +POINT displayToLocation (POINT pt, SIZE scaleRadius); +POINT planetOuterLocation (COUNT planetI); + extern void LoadPlanet (FRAME SurfDefFrame); extern void DrawPlanet (int x, int y, int dy, Color rgb); extern void FreePlanet (void); Modified: trunk/sc2/src/uqm/planets/solarsys.c =================================================================== --- trunk/sc2/src/uqm/planets/solarsys.c 2009-12-03 03:54:12 UTC (rev 3384) +++ trunk/sc2/src/uqm/planets/solarsys.c 2009-12-03 21:36:32 UTC (rev 3385) @@ -85,7 +85,7 @@ #define DISPLAY_TO_LOC (DISPLAY_FACTOR >> 1) -static POINT +POINT locationToDisplay (POINT pt, SIZE scaleRadius) { POINT out; @@ -98,7 +98,7 @@ return out; } -static POINT +POINT displayToLocation (POINT pt, SIZE scaleRadius) { POINT out; @@ -111,6 +111,14 @@ return out; } +POINT +planetOuterLocation (COUNT planetI) +{ + SIZE scaleRadius = pSolarSysState->SunDesc[0].radius; + return displayToLocation (pSolarSysState->PlanetDesc[planetI].image.origin, + scaleRadius); +} + bool worldIsPlanet (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world) { @@ -892,8 +900,8 @@ GLOBAL (ip_location) = displayToLocation ( GLOBAL (ShipStamp.origin), MAX_ZOOM_RADIUS); - XFormIPLoc (&planet->image.origin, &pSolarSysState->SunDesc[0].location, - FALSE); + pSolarSysState->SunDesc[0].location = + planetOuterLocation (planetIndex (pSolarSysState, planet)); ZeroVelocityComponents (&GLOBAL (velocity)); GenerateMoons (pSolarSysState, planet); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |