Cleanup: use IP location<->display conversion functions; some ipdisp clarifications

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3385 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-12-03 21:36:32 +00:00
parent b0bdc9e7b3
commit 2cba7e4942
6 changed files with 110 additions and 148 deletions
+6 -1
View File
@@ -134,9 +134,14 @@ struct element
* with CREATURE_AWARE * with CREATURE_AWARE
* - for canned bio: value of creature * - 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;
}; };
union
{
BYTE turn_wait; BYTE turn_wait;
BYTE sys_loc; /* IP flagship: location in system */
};
union union
{ {
BYTE thrust_wait; BYTE thrust_wait;
+1 -2
View File
@@ -656,8 +656,7 @@ GetGroupInfo (DWORD offset, BYTE which_group)
COUNT angle; COUNT angle;
POINT org; POINT org;
XFormIPLoc (&pSolarSysState->PlanetDesc[group_loc - 1] org = planetOuterLocation (group_loc - 1);
.image.origin, &org, FALSE);
angle = FACING_TO_ANGLE (GroupPtr->orbit_pos + 1); angle = FACING_TO_ANGLE (GroupPtr->orbit_pos + 1);
GroupPtr->loc.x = org.x + COSINE (angle, STATION_RADIUS); GroupPtr->loc.x = org.x + COSINE (angle, STATION_RADIUS);
GroupPtr->loc.y = org.y + SINE (angle, STATION_RADIUS); GroupPtr->loc.y = org.y + SINE (angle, STATION_RADIUS);
+84 -138
View File
@@ -97,6 +97,43 @@ NotifyOthers (COUNT which_race, BYTE target_loc)
} }
} }
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 static void
ip_group_preprocess (ELEMENT *ElementPtr) ip_group_preprocess (ELEMENT *ElementPtr)
{ {
@@ -117,17 +154,8 @@ ip_group_preprocess (ELEMENT *ElementPtr)
group_loc = GroupPtr->sys_loc; // save old location group_loc = GroupPtr->sys_loc; // save old location
DisplayArray[EPtr->PrimIndex].Object.Point = GroupPtr->loc; DisplayArray[EPtr->PrimIndex].Object.Point = GroupPtr->loc;
if (group_loc != 0) radius = zoomRadiusForLocation (group_loc);
radius = MAX_ZOOM_RADIUS; dest_pt = locationToDisplay (GroupPtr->loc, 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);
EPtr->current.location.x = DISPLAY_TO_WORLD (dest_pt.x) EPtr->current.location.x = DISPLAY_TO_WORLD (dest_pt.x)
+ (COORD)(LOG_SPACE_WIDTH >> 1) + (COORD)(LOG_SPACE_WIDTH >> 1)
- (LOG_SPACE_WIDTH >> (MAX_REDUCTION + 1)); - (LOG_SPACE_WIDTH >> (MAX_REDUCTION + 1));
@@ -137,11 +165,7 @@ ip_group_preprocess (ELEMENT *ElementPtr)
InitIntersectStartPoint (EPtr); InitIntersectStartPoint (EPtr);
if (!playerInInnerSystem ()) flagship_loc = getFlagshipLocation ();
flagship_loc = 0;
else
flagship_loc = (BYTE)(pSolarSysState->pBaseDesc->pPrevDesc
- pSolarSysState->PlanetDesc + 1);
task = GroupPtr->task; task = GroupPtr->task;
@@ -246,13 +270,7 @@ ip_group_preprocess (ELEMENT *ElementPtr)
else else
{ {
orbit_dist = STATION_RADIUS; orbit_dist = STATION_RADIUS;
XFormIPLoc ( org = planetOuterLocation (target_loc - 1);
&pSolarSysState->PlanetDesc[
target_loc - 1
].image.origin,
&org,
FALSE
);
} }
angle = FACING_TO_ANGLE (GroupPtr->orbit_pos + 1); angle = FACING_TO_ANGLE (GroupPtr->orbit_pos + 1);
@@ -289,8 +307,7 @@ ip_group_preprocess (ELEMENT *ElementPtr)
if (GroupPtr->dest_loc == 0) if (GroupPtr->dest_loc == 0)
dest_pt = pSolarSysState->SunDesc[0].location; dest_pt = pSolarSysState->SunDesc[0].location;
else else
XFormIPLoc (&pSolarSysState->PlanetDesc[ dest_pt = planetOuterLocation (target_loc - 1);
target_loc - 1].image.origin, &dest_pt, FALSE);
} }
else else
{ {
@@ -331,12 +348,13 @@ ip_group_preprocess (ELEMENT *ElementPtr)
EPtr->thrust_wait = TRACK_WAIT; EPtr->thrust_wait = TRACK_WAIT;
} }
SetVelocityComponents (&EPtr->velocity, vdx = COSINE (angle, speed);
vdx = COSINE (angle, speed), vdy = SINE (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 (group_loc == target_loc)
{ {
if (target_loc == 0) if (target_loc == 0)
@@ -351,7 +369,8 @@ PartialRevolution:
>= (long)delta_x * delta_x + (long)delta_y * delta_y) >= (long)delta_x * delta_x + (long)delta_y * delta_y)
{ {
GroupPtr->loc = dest_pt; GroupPtr->loc = dest_pt;
vdx = vdy = 0; vdx = 0;
vdy = 0;
ZeroVelocityComponents (&EPtr->velocity); ZeroVelocityComponents (&EPtr->velocity);
} }
} }
@@ -359,17 +378,8 @@ PartialRevolution:
else else
{ {
if (group_loc == 0) if (group_loc == 0)
{ { // In outer system
if (pSolarSysState->SunDesc[0].radius < MAX_ZOOM_RADIUS) adjustDeltaVforZoom (radius, &dx, &dy);
{
dx >>= 1;
dy >>= 1;
if (pSolarSysState->SunDesc[0].radius == MIN_ZOOM_RADIUS)
{
dx >>= 1;
dy >>= 1;
}
}
if (task == ON_STATION && GroupPtr->dest_loc) if (task == ON_STATION && GroupPtr->dest_loc)
goto PartialRevolution; goto PartialRevolution;
@@ -378,14 +388,9 @@ PartialRevolution:
Transition = TRUE; Transition = TRUE;
} }
else else
{ { // In inner system; also leaving outer CheckGetAway hack
CheckGetAway: CheckGetAway:
dest_pt.x = (SIS_SCREEN_WIDTH >> 1) dest_pt = locationToDisplay (GroupPtr->loc, radius);
+ (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);
if (dest_pt.x < 0 if (dest_pt.x < 0
|| dest_pt.x >= SIS_SCREEN_WIDTH || dest_pt.x >= SIS_SCREEN_WIDTH
|| dest_pt.y < 0 || dest_pt.y < 0
@@ -398,15 +403,12 @@ CheckGetAway:
/* no collisions during transition */ /* no collisions during transition */
EPtr->state_flags |= NONSOLID; EPtr->state_flags |= NONSOLID;
vdx = vdy = 0; vdx = 0;
vdy = 0;
ZeroVelocityComponents (&EPtr->velocity); ZeroVelocityComponents (&EPtr->velocity);
if (group_loc != 0) if (group_loc != 0)
{ {
PLANET_DESC *pCurDesc; GroupPtr->loc = planetOuterLocation (group_loc - 1);
pCurDesc = &pSolarSysState->PlanetDesc[group_loc - 1];
XFormIPLoc (&pCurDesc->image.origin, &GroupPtr->loc,
FALSE);
group_loc = 0; group_loc = 0;
GroupPtr->sys_loc = 0; GroupPtr->sys_loc = 0;
} }
@@ -420,6 +422,8 @@ CheckGetAway:
} }
else else
{ {
POINT entryPt;
if (target_loc == GroupPtr->dest_loc) if (target_loc == GroupPtr->dest_loc)
{ {
GroupPtr->orbit_pos = NORMALIZE_FACING ( GroupPtr->orbit_pos = NORMALIZE_FACING (
@@ -428,14 +432,17 @@ CheckGetAway:
((COUNT)TFB_Random () % MAX_REVOLUTIONS) ((COUNT)TFB_Random () % MAX_REVOLUTIONS)
<< FACING_SHIFT; << FACING_SHIFT;
} }
// The group enters inner system exactly on the edge of a
GroupPtr->loc.x = -(SIZE)((long)COSINE ( // circle with radius = 9/16 * window-dim, which is
angle, SIS_SCREEN_WIDTH * 9 / 16 // different from how the flagship enters, but similar
) * MAX_ZOOM_RADIUS / (DISPLAY_FACTOR >> 1)); // in the way that the group will never show up in any
GroupPtr->loc.y = -(SIZE)((long)SINE ( // of the corners.
angle, SIS_SCREEN_WIDTH * 9 / 16 entryPt.x = (SIS_SCREEN_WIDTH >> 1) - COSINE (angle,
) * MAX_ZOOM_RADIUS / (DISPLAY_FACTOR >> 1)); 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; group_loc = target_loc;
GroupPtr->sys_loc = target_loc; GroupPtr->sys_loc = target_loc;
} }
@@ -443,32 +450,12 @@ CheckGetAway:
} }
} }
if (group_loc != 0) radius = zoomRadiusForLocation (group_loc);
radius = MAX_ZOOM_RADIUS; adjustDeltaVforZoom (radius, &vdx, &vdy);
else
{
radius = pSolarSysState->SunDesc[0].radius;
if (radius < MAX_ZOOM_RADIUS)
{
vdx >>= 1;
vdy >>= 1;
if (radius == MIN_ZOOM_RADIUS)
{
vdx >>= 1;
vdy >>= 1;
}
}
}
GroupPtr->loc.x += vdx; GroupPtr->loc.x += vdx;
GroupPtr->loc.y += vdy; GroupPtr->loc.y += vdy;
dest_pt.x = (SIS_SCREEN_WIDTH >> 1) dest_pt = locationToDisplay (GroupPtr->loc, radius);
+ (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);
EPtr->next.location.x = DISPLAY_TO_WORLD (dest_pt.x) EPtr->next.location.x = DISPLAY_TO_WORLD (dest_pt.x)
+ (COORD)(LOG_SPACE_WIDTH >> 1) + (COORD)(LOG_SPACE_WIDTH >> 1)
- (LOG_SPACE_WIDTH >> (MAX_REDUCTION + 1)); - (LOG_SPACE_WIDTH >> (MAX_REDUCTION + 1));
@@ -583,9 +570,8 @@ spawn_ip_group (IP_GROUP *GroupPtr)
ELEMENT *IPSHIPElementPtr; ELEMENT *IPSHIPElementPtr;
LockElement (hIPSHIPElement, &IPSHIPElementPtr); LockElement (hIPSHIPElement, &IPSHIPElementPtr);
// XXX: turn_wait hack is not actually used anywhere // Must have mass_points for collisions to work
//IPSHIPElementPtr->turn_wait = GroupPtr->group_id; IPSHIPElementPtr->mass_points = 1;
IPSHIPElementPtr->sys_loc = 1;
IPSHIPElementPtr->hit_points = 1; IPSHIPElementPtr->hit_points = 1;
IPSHIPElementPtr->state_flags = IPSHIPElementPtr->state_flags =
CHANGING | FINITE_LIFE | IGNORE_VELOCITY; CHANGING | FINITE_LIFE | IGNORE_VELOCITY;
@@ -608,17 +594,8 @@ spawn_ip_group (IP_GROUP *GroupPtr)
SIZE radius; SIZE radius;
POINT pt; POINT pt;
if (GroupPtr->sys_loc != 0) radius = zoomRadiusForLocation (GroupPtr->sys_loc);
radius = MAX_ZOOM_RADIUS; pt = locationToDisplay (GroupPtr->loc, radius);
else
radius = pSolarSysState->SunDesc[0].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 = IPSHIPElementPtr->current.location.x =
DISPLAY_TO_WORLD (pt.x) DISPLAY_TO_WORLD (pt.x)
@@ -676,34 +653,11 @@ flag_ship_preprocess (ELEMENT *ElementPtr)
GetCurrentVelocityComponents (&GLOBAL (velocity), &vdx, &vdy); GetCurrentVelocityComponents (&GLOBAL (velocity), &vdx, &vdy);
if (playerInInnerSystem ()) flagship_loc = getFlagshipLocation ();
{ radius = zoomRadiusForLocation (flagship_loc);
flagship_loc = (BYTE)(pSolarSysState->pBaseDesc->pPrevDesc adjustDeltaVforZoom (radius, &vdx, &vdy);
- 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;
}
}
}
pt.x = (SIS_SCREEN_WIDTH >> 1) pt = locationToDisplay (GLOBAL (ip_location), radius);
+ (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);
ElementPtr->current.location.x = DISPLAY_TO_WORLD (pt.x) ElementPtr->current.location.x = DISPLAY_TO_WORLD (pt.x)
+ (COORD)(LOG_SPACE_WIDTH >> 1) + (COORD)(LOG_SPACE_WIDTH >> 1)
- (LOG_SPACE_WIDTH >> (MAX_REDUCTION + 1)); - (LOG_SPACE_WIDTH >> (MAX_REDUCTION + 1));
@@ -715,12 +669,7 @@ flag_ship_preprocess (ELEMENT *ElementPtr)
GLOBAL (ip_location.x) += vdx; GLOBAL (ip_location.x) += vdx;
GLOBAL (ip_location.y) += vdy; GLOBAL (ip_location.y) += vdy;
pt.x = (SIS_SCREEN_WIDTH >> 1) pt = locationToDisplay (GLOBAL (ip_location), radius);
+ (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);
ElementPtr->next.location.x = DISPLAY_TO_WORLD (pt.x) ElementPtr->next.location.x = DISPLAY_TO_WORLD (pt.x)
+ (COORD)(LOG_SPACE_WIDTH >> 1) + (COORD)(LOG_SPACE_WIDTH >> 1)
- (LOG_SPACE_WIDTH >> (MAX_REDUCTION + 1)); - (LOG_SPACE_WIDTH >> (MAX_REDUCTION + 1));
@@ -767,12 +716,9 @@ spawn_flag_ship (void)
LockElement (hFlagShipElement, &FlagShipElementPtr); LockElement (hFlagShipElement, &FlagShipElementPtr);
FlagShipElementPtr->hit_points = 1; FlagShipElementPtr->hit_points = 1;
if (!playerInInnerSystem ()) // Must have mass_points for collisions to work
FlagShipElementPtr->sys_loc = 1; FlagShipElementPtr->mass_points = 1;
else FlagShipElementPtr->sys_loc = getFlagshipLocation ();
FlagShipElementPtr->sys_loc =
(BYTE)(pSolarSysState->pBaseDesc->pPrevDesc
- pSolarSysState->PlanetDesc + 2);
FlagShipElementPtr->state_flags = APPEARING | IGNORE_VELOCITY; FlagShipElementPtr->state_flags = APPEARING | IGNORE_VELOCITY;
if (GET_GAME_STATE (ESCAPE_COUNTER)) if (GET_GAME_STATE (ESCAPE_COUNTER))
FlagShipElementPtr->state_flags |= NONSOLID; FlagShipElementPtr->state_flags |= NONSOLID;
+2 -2
View File
@@ -114,7 +114,7 @@ GenerateSaMatra_reinitNpcs (SOLARSYS_STATE *solarSys)
COUNT angle; COUNT angle;
POINT org; POINT org;
XFormIPLoc (&solarSys->PlanetDesc[4].image.origin, &org, FALSE); org = planetOuterLocation (4);
angle = ARCTAN (GLOBAL (ip_location.x) - org.x, angle = ARCTAN (GLOBAL (ip_location.x) - org.x,
GLOBAL (ip_location.y) - org.y); GLOBAL (ip_location.y) - org.y);
GLOBAL (ip_location.x) = org.x + COSINE (angle, 3000); GLOBAL (ip_location.x) = org.x + COSINE (angle, 3000);
@@ -275,7 +275,7 @@ BuildUrquanGuard (SOLARSYS_STATE *solarSys)
GetGroupInfo (GLOBAL (BattleGroupRef), GROUP_INIT_IP); GetGroupInfo (GLOBAL (BattleGroupRef), GROUP_INIT_IP);
XFormIPLoc (&solarSys->PlanetDesc[4].image.origin, &org, FALSE); org = planetOuterLocation (4);
hGroup = GetHeadLink (&GLOBAL (ip_group_q)); hGroup = GetHeadLink (&GLOBAL (ip_group_q));
for (b0 = 0, b1 = 0; for (b0 = 0, b1 = 0;
b0 < NUM_URQUAN_GUARDS0; b0 < NUM_URQUAN_GUARDS0;
+4
View File
@@ -236,6 +236,10 @@ COUNT moonIndex (const SOLARSYS_STATE *solarSys, const PLANET_DESC *moon);
bool matchWorld (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world, bool matchWorld (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world,
BYTE planetI, BYTE moonI); 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 LoadPlanet (FRAME SurfDefFrame);
extern void DrawPlanet (int x, int y, int dy, Color rgb); extern void DrawPlanet (int x, int y, int dy, Color rgb);
extern void FreePlanet (void); extern void FreePlanet (void);
+12 -4
View File
@@ -85,7 +85,7 @@ static RECT scaleRect;
#define DISPLAY_TO_LOC (DISPLAY_FACTOR >> 1) #define DISPLAY_TO_LOC (DISPLAY_FACTOR >> 1)
static POINT POINT
locationToDisplay (POINT pt, SIZE scaleRadius) locationToDisplay (POINT pt, SIZE scaleRadius)
{ {
POINT out; POINT out;
@@ -98,7 +98,7 @@ locationToDisplay (POINT pt, SIZE scaleRadius)
return out; return out;
} }
static POINT POINT
displayToLocation (POINT pt, SIZE scaleRadius) displayToLocation (POINT pt, SIZE scaleRadius)
{ {
POINT out; POINT out;
@@ -111,6 +111,14 @@ displayToLocation (POINT pt, SIZE scaleRadius)
return out; return out;
} }
POINT
planetOuterLocation (COUNT planetI)
{
SIZE scaleRadius = pSolarSysState->SunDesc[0].radius;
return displayToLocation (pSolarSysState->PlanetDesc[planetI].image.origin,
scaleRadius);
}
bool bool
worldIsPlanet (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world) worldIsPlanet (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world)
{ {
@@ -892,8 +900,8 @@ enterInnerSystem (PLANET_DESC *planet)
GLOBAL (ip_location) = displayToLocation ( GLOBAL (ip_location) = displayToLocation (
GLOBAL (ShipStamp.origin), MAX_ZOOM_RADIUS); GLOBAL (ShipStamp.origin), MAX_ZOOM_RADIUS);
XFormIPLoc (&planet->image.origin, &pSolarSysState->SunDesc[0].location, pSolarSysState->SunDesc[0].location =
FALSE); planetOuterLocation (planetIndex (pSolarSysState, planet));
ZeroVelocityComponents (&GLOBAL (velocity)); ZeroVelocityComponents (&GLOBAL (velocity));
GenerateMoons (pSolarSysState, planet); GenerateMoons (pSolarSysState, planet);