Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameclient): calmer director camera that watches special powers

Olcay Seygan403755a384e3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 49799b364..9c0dcc052 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -746,7 +746,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- Every row and every countdown stands in real metal, cut from the same tray the general's powers sit in down in the corner - the side your command bar is showing. Watching a match there is no bar of your own, so the superweapon countdowns used to fall back to a flat black box for the whole match; now they wear the metal of the player you are watching, and follow it when you switch seats.
- Watching, the command bar is down to the radar. The list of players it held is the board on the right and the Tab scoreboard now. Pick a player to follow in the camera panel and you are looking at him, his money and his side's steel, the way his button in the list did; pick nobody for everybody. Picking drops whatever you had selected, so the promotions on screen are that player's and not the owner of the tank you last clicked. The portrait panel in the right corner comes up when you select something and goes when you click empty ground, so an empty match leaves the bottom of the screen to the battle.
- Watching, the bars over the buildings are everyone's too - what each factory is turning out, and how long the superweapons have left. An observer used to see none of it.
-- Watching, the camera can drive itself. Two drop-downs in the camera panel on the right, above the board, say who has it and which player you follow, and you can follow nobody. The Director goes to the fight with the most on the line over the last five seconds, where a dead Overlord counts for more than six riflemen being shot at and anything happening to a superweapon counts three times over. It stays with that fight at least six seconds, and cuts away sooner only for one three times the size; after twenty seconds on the same fight, any bigger one elsewhere takes it. So a 4v4 is watched like a broadcast rather than hunted for. When nobody is shooting it no longer parks on empty ground: it goes round what is worth seeing, an army on the march, a superweapon, a base going up, the rest of a base, the dearest first and eight seconds each, and does not come back to one of the last three while there is anything else to show. With a player picked it keeps to his fights and his own armies and buildings. Player camera shows his screen: a human player's camera comes over the network five times a second, smoothed in between, and a computer player, who has no camera, gets the Director narrowed to his own fights. Scroll with the keys or a drag, turn the view or click the radar and the camera is yours again, still following the same player. The edge of the screen does not scroll while it drives: the panel on the right stands on that edge, and reaching for it used to hand the camera back to you, so the Director stopped following the fighting the first time you went to change a setting. In a replay with the recorded camera switched on in the options, the player you follow still drives the camera the way his button in the old list did.
+- Watching, the camera can drive itself. Two drop-downs in the camera panel on the right, above the board, say who has it and which player you follow, and you can follow nobody. The Director goes to the fight with the most on the line over the last five seconds, where a dead Overlord counts for more than six riflemen being shot at and anything happening to a superweapon counts three times over. It stays with that fight twelve seconds, leaves after six only for one four times the size, and after half a minute on the same fight a third bigger is enough. So a 4v4 is watched like a broadcast rather than hunted for, and it does not hop between spots every few seconds. Any general's power used on the map outranks every fight. A nuke is shown in its silo as it leaves, then the camera waits at the target for it to come down and stays through the blast. The particle cannon's beam is followed along its whole sweep, and a Scud Storm or a carpet bomb is watched until the last explosion has died down. Then it goes back to the fighting. The camera glides between places and slows into each one, and only cuts when the next one is across most of the map. When nobody is shooting it no longer parks on empty ground: it goes round what is worth seeing, an army on the march, a superweapon, a base going up, the rest of a base, the dearest first and fourteen seconds each, and does not come back to one of the last three while there is anything else to show. With a player picked it keeps to his fights and his own armies and buildings. Player camera shows his screen: a human player's camera comes over the network five times a second, smoothed in between, and a computer player, who has no camera, gets the Director narrowed to his own fights. Scroll with the keys or a drag, turn the view or click the radar and the camera is yours again, still following the same player. The edge of the screen does not scroll while it drives: the panel on the right stands on that edge, and reaching for it used to hand the camera back to you, so the Director stopped following the fighting the first time you went to change a setting. In a replay with the recorded camera switched on in the options, the player you follow still drives the camera the way his button in the old list did.
- Watching, tick Fog of war under the camera and you see what the player you follow sees and nothing more: black where he has never been, grey where he has been, none of the enemy he cannot see, and an enemy base as he last saw it. Stealth goes by his eyes too: a Jarmen Kell he has not found is gone from the screen and the radar, and his own stealthed units show the way they show him. It stays on whoever drives the camera, until you switch it off or follow nobody. Switch to another player and his fog comes in whole, shadows included: a building he has never seen casts nothing on his grey ground. An observer used to have no fog at all: the whole map, all match, with no way to see the game the way one of its players was seeing it.
- An ally, and anyone watching, now sees a stealthed unit's muzzle flash, its promotion and the cash it earns - if they can see the unit at all. Those three asked 'is it mine' instead of 'can I see it', so allies and observers got nothing.
- Watching, the match opens on the middle of the map. An observer has no start position, so the game looked for the camera waypoint of "player zero", did not find it, and fell back to the corner of the map: every match watched from the stands began pointed at empty ground in the south west.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
index f5454380c..936c623f1 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
@@ -22,7 +22,10 @@
// The mode and the followed player are picked apart, from two lists. Free is the camera in the
// watcher's own hands. Director goes to the fight of the last few seconds with the most at stake,
// each hit counted by what the thing hit cost and more for a kill or a superweapon, and stays there
-// a while before it looks for a bigger fight. With no fight on it goes round the armies on the
+// a while before it looks for a bigger fight. A special power used anywhere outranks any fight: a
+// superweapon is shown leaving its silo, then where it lands until the dust settles, a laser
+// followed along its sweep. The camera glides between places on a spring and only cuts across
+// most of a map. With no fight on it goes round the armies on the
// move, the bases going up and the superweapons, a few seconds each, so it never sits still; with a
// player picked it counts only that player's fights and things. Player shows what the followed player's own screen
// shows: a player's camera comes over the network a few times a second (MSG_SET_REPLAY_CAMERA), an
@@ -63,6 +66,28 @@ struct DirectorHeat
Real weight;
};
+class Player;
+
+/// a special power used lately: who used it, where it was fired from, where it lands, and until which
+/// logic frame it is worth watching. A superweapon is shown leaving its silo before its target
+struct DirectorEvent
+{
+ UnsignedInt id;
+ const Player *owner;
+ Coord2D source;
+ Coord2D target;
+ UnsignedInt since;
+ UnsignedInt until;
+ Real weight;
+ Bool superweapon;
+};
+
+/// how fast the camera is going on each of its six axes, carried from one frame's step to the next
+struct ObserverCameraVelocity
+{
+ Real x, y, z, angle, pitch, zoom;
+};
+
/// the place the hits crowd most: each hit's weight summed over those within DIRECTOR_GATHER_RADIUS
/// of it, and the best one's neighbours averaged by weight. FALSE when nothing was hit
Bool ObserverCamera_hottestPlace( const std::vector< DirectorHeat > &hits, Coord2D *place, Real *heat );
@@ -78,11 +103,15 @@ Real ObserverCamera_hitWeight( Int cost, Bool killed, Bool superweapon );
Real ObserverCamera_sightWeight( Int cost, Bool structure, Bool busy, Bool superweapon );
/// the best place among the sights away from the ones in seen; FALSE when every sight was seen
Bool ObserverCamera_nextSight( const std::vector< DirectorHeat > &sights, const std::vector< Coord2D > &seen, Coord2D *place );
-/// a step of the camera towards where it is going, easing with timeConstant, or the jump there when
-/// the two are further apart than a pan should cross
-ViewLocation ObserverCamera_approach( const ViewLocation &from, const ViewLocation &to, Real elapsedSeconds, Real timeConstant );
-
-class Player;
+/// where an event is best watched on a frame: a superweapon's silo for its first few seconds, then
+/// where it lands
+Coord2D ObserverCamera_eventPlace( const DirectorEvent &event, UnsignedInt frame );
+/// a step of the camera towards where it is going on a critically damped spring: it gathers speed,
+/// never goes faster than topSpeed across the ground, and slows into place without overshooting.
+/// smoothSeconds is roughly how long it takes to arrive. Further apart than a glide should cross,
+/// it jumps there and stops
+ViewLocation ObserverCamera_approach( const ViewLocation &from, const ViewLocation &to, Real elapsedSeconds, Real smoothSeconds,
+ Real topSpeed, ObserverCameraVelocity *velocity );
class ObserverCamera
{
@@ -113,6 +142,12 @@ public:
/// on is following
Int getShroudPlayerIndex( void ) const;
+ /// a special power was used: logic tells the director, and never asks it anything back
+ void noteSpecialPower( const Player *owner, const Coord3D *from, const Coord3D *at, Bool superweapon );
+ /// a superweapon is hitting the ground here this frame, a beam or a warhead. Keeps the event it
+ /// belongs to going a few seconds more, and with follow the event's target moves with it
+ void noteSuperweaponHit( const Player *owner, const Coord3D *at, Bool follow );
+
enum { NO_PLAYER = -1 };
private:
@@ -122,6 +157,10 @@ private:
Bool isShowingPlayerView( void ) const;
Bool chooseTarget( const ViewLocation &current, ViewLocation *target );
Bool directorPlace( const Player *narrowTo, Coord2D *place );
+ DirectorEvent *findEvent( UnsignedInt id );
+ void dropOldEvents( UnsignedInt frame );
+
+ enum PlaceKind { PLACE_SIGHT, PLACE_FIGHT, PLACE_EVENT };
ObserverCameraMode m_mode;
Int m_followed;
@@ -131,6 +170,7 @@ private:
Bool m_holdingHeight; ///< the view's own height easing is off while a player's zoom is shown
Coord3D m_drivenTo;
UnsignedInt m_lastUpdate;
+ ObserverCameraVelocity m_velocity;
ViewLocation m_playerViews[ MAX_PLAYER_COUNT ];
@@ -139,8 +179,11 @@ private:
UnsignedInt m_placeSince; ///< the logic frame it went there
UnsignedInt m_placeScanned; ///< the logic frame the hits were last counted
const Player *m_placeFor; ///< whose fights the place was picked from, NULL for everybody's
- Bool m_placeIsFight; ///< the place is a fight, not a sight picked while nothing was hit
+ PlaceKind m_placeKind; ///< a fight, a special power, or a sight picked while nothing was hit
+ UnsignedInt m_placeEvent; ///< the id of the event the place is, while it is one
std::vector< Coord2D > m_seen; ///< the last few sights, oldest first, not gone back to while there is another
+ std::vector< DirectorEvent > m_events; ///< the special powers still worth watching, oldest first
+ UnsignedInt m_nextEventId;
};
extern ObserverCamera TheObserverCamera;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
index d5c9bf2c6..298d47e52 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
@@ -49,35 +49,52 @@ static const UnsignedInt DIRECTOR_HEAT_FRAMES = 5 * LOGICFRAMES_PER_SECOND;
/// how often the hits are counted again
static const UnsignedInt DIRECTOR_SCAN_FRAMES = LOGICFRAMES_PER_SECOND / 2;
/// how long the director stays with a fight that is still going before it looks for a better one
-static const UnsignedInt DIRECTOR_HOLD_FRAMES = 6 * LOGICFRAMES_PER_SECOND;
+static const UnsignedInt DIRECTOR_HOLD_FRAMES = 12 * LOGICFRAMES_PER_SECOND;
/// how much hotter somewhere else has to be to be worth leaving a fight that is still going
-static const Real DIRECTOR_SWITCH_MARGIN = 1.5f;
-/// no cut sooner than this after the last one, however big the other fight
-static const UnsignedInt DIRECTOR_SETTLE_FRAMES = 2 * LOGICFRAMES_PER_SECOND;
+static const Real DIRECTOR_SWITCH_MARGIN = 2.0f;
+/// no move sooner than this after the last one, however big the other fight
+static const UnsignedInt DIRECTOR_SETTLE_FRAMES = 6 * LOGICFRAMES_PER_SECOND;
/// this much hotter elsewhere and the director goes before its hold is up
-static const Real DIRECTOR_BIG_MARGIN = 3.0f;
-/// after this long on one fight any hotter one elsewhere will do
-static const UnsignedInt DIRECTOR_TIRED_FRAMES = 20 * LOGICFRAMES_PER_SECOND;
-static const Real DIRECTOR_TIRED_MARGIN = 1.1f;
+static const Real DIRECTOR_BIG_MARGIN = 4.0f;
+/// after this long on one fight any clearly hotter one elsewhere will do
+static const UnsignedInt DIRECTOR_TIRED_FRAMES = 30 * LOGICFRAMES_PER_SECOND;
+static const Real DIRECTOR_TIRED_MARGIN = 1.3f;
+/// a fight's middle drifts as units die and arrive; the camera follows it only once it has gone this far
+static const Real DIRECTOR_FOLLOW_SLACK = 80.0f;
+/// what a special power counts for against another one; any of them outranks every fight
+static const Real EVENT_WEIGHT = 1.0f;
+static const Real EVENT_SUPERWEAPON_WEIGHT = 5.0f;
+/// how long a special power is watched with nothing hitting the ground there yet: a superweapon's
+/// missiles take a while to arrive, a bomber longer to fly in
+static const UnsignedInt EVENT_FRAMES = 12 * LOGICFRAMES_PER_SECOND;
+static const UnsignedInt EVENT_SUPERWEAPON_FRAMES = 20 * LOGICFRAMES_PER_SECOND;
+/// how long a superweapon is shown at its silo before the camera goes to where it will land
+static const UnsignedInt EVENT_LAUNCH_FRAMES = 4 * LOGICFRAMES_PER_SECOND;
+/// the camera stays this long after the last hit at an event's target, for the cloud and the fires
+static const UnsignedInt EVENT_AFTERMATH_FRAMES = 5 * LOGICFRAMES_PER_SECOND;
/// a hit on a thing that cost this much counts twice what a free one does
static const Real DIRECTOR_COST_PER_WEIGHT = 500.0f;
/// a kill counts this many times a hit, and anything on a superweapon this many times again
static const Real DIRECTOR_KILL_FACTOR = 2.0f;
static const Real DIRECTOR_SUPERWEAPON_FACTOR = 3.0f;
/// with no fight on, how long the director looks at one army, base or building site
-static const UnsignedInt DIRECTOR_SIGHT_FRAMES = 8 * LOGICFRAMES_PER_SECOND;
+static const UnsignedInt DIRECTOR_SIGHT_FRAMES = 14 * LOGICFRAMES_PER_SECOND;
/// how many of the last sights the director will not go back to while there is another
static const size_t DIRECTOR_SEEN_COUNT = 3;
-/// further apart than this the camera cuts rather than pans: a pan across the map shows nothing
-static const Real CUT_DISTANCE = 700.0f;
+/// further apart than this the camera cuts rather than glides: a glide across most of a map is too
+/// long to sit through and shows nothing
+static const Real CUT_DISTANCE = 1600.0f;
/// the camera found further than this from where it was put was moved by something else, a click on
/// the production strip or a jump to a group; the edge of the map pulls it back by less. The radar
/// hands the camera over itself, since a click near the camera and a drag both move it by less
static const Real HAND_JUMP_DISTANCE = 400.0f;
-/// how quickly the camera closes on where it is going, in seconds to cover about two thirds of it
-static const Real DIRECTOR_PAN_SECONDS = 0.35f;
+/// roughly how long the director's glide takes to arrive, easing in and out
+static const Real DIRECTOR_PAN_SECONDS = 1.4f;
+/// the director's glide never crosses the ground faster than this, about two screens a second
+static const Real DIRECTOR_TOP_SPEED = 900.0f;
/// a player's camera comes a few times a second, and this smooths the steps between
-static const Real PLAYER_PAN_SECONDS = 0.12f;
+static const Real PLAYER_PAN_SECONDS = 0.15f;
+static const Real PLAYER_TOP_SPEED = 4000.0f;
/// a frame longer than this is a hitch, and is not allowed to throw the camera across the map
static const UnsignedInt LONGEST_STEP_MILLISECONDS = 100;
static const Real MILLISECONDS_PER_SECOND = 1000.0f;
@@ -189,36 +206,81 @@ Bool ObserverCamera_shouldMove( Real heatHere, Real heatThere, UnsignedInt frame
return heatThere > heatHere * margin;
}
+//-------------------------------------------------------------------------------------------------
+Coord2D ObserverCamera_eventPlace( const DirectorEvent &event, UnsignedInt frame )
+{
+ if( event.superweapon && frame < event.since + EVENT_LAUNCH_FRAMES && !sameFight( event.source, event.target ) )
+ return event.source;
+ return event.target;
+}
+
//-------------------------------------------------------------------------------------------------
/** An angle's shortest way round to another, so a camera facing just west of north turns a few
* degrees to just east of it rather than all the way back round. */
//-------------------------------------------------------------------------------------------------
-static Real turnTowards( Real from, Real to, Real share )
+static Real shortestTurn( Real from, Real to )
{
Real turn = to - from;
while( turn > PI )
turn -= 2.0f * PI;
while( turn < -PI )
turn += 2.0f * PI;
- return from + turn * share;
+ return turn;
}
//-------------------------------------------------------------------------------------------------
-ViewLocation ObserverCamera_approach( const ViewLocation &from, const ViewLocation &to, Real elapsedSeconds, Real timeConstant )
+/** One axis of a critically damped spring, in the closed form game cameras use (Game Programming
+ * Gems 4, 1.10): from rest it gathers speed, then slows into the target without passing it. */
+//-------------------------------------------------------------------------------------------------
+static Real springTowards( Real from, Real to, Real *velocity, Real smoothSeconds, Real elapsedSeconds )
+{
+ const Real omega = 2.0f / smoothSeconds;
+ const Real x = omega * elapsedSeconds;
+ const Real decay = 1.0f / ( 1.0f + x + 0.48f * x * x + 0.235f * x * x * x );
+ const Real change = from - to;
+ const Real pull = ( *velocity + omega * change ) * elapsedSeconds;
+ *velocity = ( *velocity - omega * pull ) * decay;
+ Real result = to + ( change + pull ) * decay;
+ if( ( to - from > 0.0f ) == ( result > to ) )
+ {
+ result = to;
+ *velocity = 0.0f;
+ }
+ return result;
+}
+
+//-------------------------------------------------------------------------------------------------
+ViewLocation ObserverCamera_approach( const ViewLocation &from, const ViewLocation &to, Real elapsedSeconds, Real smoothSeconds,
+ Real topSpeed, ObserverCameraVelocity *velocity )
{
const Coord3D &start = from.getPosition();
const Coord3D &end = to.getPosition();
- const Real dx = end.x - start.x;
- const Real dy = end.y - start.y;
- if( dx * dx + dy * dy > CUT_DISTANCE * CUT_DISTANCE )
+ Real dx = end.x - start.x;
+ Real dy = end.y - start.y;
+ const Real distance = sqrtf( dx * dx + dy * dy );
+ if( distance > CUT_DISTANCE )
+ {
+ velocity->x = velocity->y = velocity->z = velocity->angle = velocity->pitch = velocity->zoom = 0.0f;
return to;
+ }
+
+ // a long way is closed on a point that runs at most this far ahead, which holds the middle of the
+ // glide to a steady speed instead of a lunge
+ const Real reach = topSpeed * smoothSeconds;
+ if( distance > reach )
+ {
+ dx *= reach / distance;
+ dy *= reach / distance;
+ }
- const Real share = 1.0f - expf( -elapsedSeconds / timeConstant );
+ const Real angle = from.getAngle();
ViewLocation step;
- step.init( start.x + dx * share, start.y + dy * share, start.z + ( end.z - start.z ) * share,
- turnTowards( from.getAngle(), to.getAngle(), share ),
- from.getPitch() + ( to.getPitch() - from.getPitch() ) * share,
- from.getZoom() + ( to.getZoom() - from.getZoom() ) * share );
+ step.init( springTowards( start.x, start.x + dx, &velocity->x, smoothSeconds, elapsedSeconds ),
+ springTowards( start.y, start.y + dy, &velocity->y, smoothSeconds, elapsedSeconds ),
+ springTowards( start.z, end.z, &velocity->z, smoothSeconds, elapsedSeconds ),
+ springTowards( angle, angle + shortestTurn( angle, to.getAngle() ), &velocity->angle, smoothSeconds, elapsedSeconds ),
+ springTowards( from.getPitch(), to.getPitch(), &velocity->pitch, smoothSeconds, elapsedSeconds ),
+ springTowards( from.getZoom(), to.getZoom(), &velocity->zoom, smoothSeconds, elapsedSeconds ) );
return step;
}
@@ -239,6 +301,7 @@ void ObserverCamera::reset( void )
m_holdingHeight = FALSE;
m_drivenTo.zero();
m_lastUpdate = 0;
+ m_velocity.x = m_velocity.y = m_velocity.z = m_velocity.angle = m_velocity.pitch = m_velocity.zoom = 0.0f;
for( Int index = 0; index < MAX_PLAYER_COUNT; index++ )
m_playerViews[ index ] = ViewLocation();
m_placeValid = FALSE;
@@ -246,8 +309,81 @@ void ObserverCamera::reset( void )
m_placeSince = 0;
m_placeScanned = 0;
m_placeFor = NULL;
- m_placeIsFight = FALSE;
+ m_placeKind = PLACE_SIGHT;
+ m_placeEvent = 0;
m_seen.clear();
+ m_events.clear();
+ m_nextEventId = 1;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Called from the logic on every machine, players' included, so it only ever adds to a list the
+ * director reads; nothing the logic does depends on it. */
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera::noteSpecialPower( const Player *owner, const Coord3D *from, const Coord3D *at, Bool superweapon )
+{
+ const UnsignedInt frame = TheGameLogic->getFrame();
+ dropOldEvents( frame );
+
+ DirectorEvent event;
+ event.id = m_nextEventId++;
+ event.owner = owner;
+ event.source.x = from->x;
+ event.source.y = from->y;
+ event.target.x = at->x;
+ event.target.y = at->y;
+ event.since = frame;
+ event.until = frame + ( superweapon ? EVENT_SUPERWEAPON_FRAMES : EVENT_FRAMES );
+ event.weight = superweapon ? EVENT_SUPERWEAPON_WEIGHT : EVENT_WEIGHT;
+ event.superweapon = superweapon;
+ m_events.push_back( event );
+}
+
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera::noteSuperweaponHit( const Player *owner, const Coord3D *at, Bool follow )
+{
+ const UnsignedInt frame = TheGameLogic->getFrame();
+ Coord2D where;
+ where.x = at->x;
+ where.y = at->y;
+ for( size_t index = 0; index < m_events.size(); index++ )
+ {
+ DirectorEvent &event = m_events[ index ];
+ if( event.owner != owner || !sameFight( event.target, where ) || frame >= event.until )
+ continue;
+
+ if( follow )
+ event.target = where;
+ event.until = max( event.until, frame + EVENT_AFTERMATH_FRAMES );
+ return;
+ }
+
+ // a warhead nobody's special power sent, a script's or a map's, is still worth seeing land
+ noteSpecialPower( owner, at, at, TRUE );
+ m_events.back().until = frame + EVENT_AFTERMATH_FRAMES;
+}
+
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera::dropOldEvents( UnsignedInt frame )
+{
+ size_t kept = 0;
+ for( size_t index = 0; index < m_events.size(); index++ )
+ {
+ if( frame < m_events[ index ].until )
+ m_events[ kept++ ] = m_events[ index ];
+ }
+ m_events.resize( kept );
+}
+
+//-------------------------------------------------------------------------------------------------
+DirectorEvent *ObserverCamera::findEvent( UnsignedInt id )
+{
+ for( size_t index = 0; index < m_events.size(); index++ )
+ {
+ if( m_events[ index ].id == id )
+ return &m_events[ index ];
+ }
+ return NULL;
}
//-------------------------------------------------------------------------------------------------
@@ -333,8 +469,10 @@ Bool ObserverCamera::takenByHand( const ViewLocation &current ) const
/** Where the director looks: the fight with the most at stake, held for a while, followed as it
* moves, and left for a clearly bigger one. With no fight anywhere it goes round what is worth
* seeing instead, an army on the move, a base going up, a superweapon, a few seconds each and not
- * straight back to one it has just shown. Narrowed to one player it counts only the hits on his
- * things, the hits his things made and his own sights. It only reads the logic. */
+ * straight back to one it has just shown. A special power beats all of it and is held until
+ * nothing has hit the ground there for a few seconds. Narrowed to one player it counts only the
+ * hits on his things, the hits his things made, his own sights and the special powers he used or
+ * had used on him. It only reads the logic. */
//-------------------------------------------------------------------------------------------------
Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )
{
@@ -388,17 +526,58 @@ Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )
const UnsignedInt held = frame - m_placeSince;
Coord2D followed = m_place;
- if( m_placeValid && m_placeIsFight )
+
+ // a special power outranks any fight. Narrowed to one player, only his own and the ones that
+ // land on his things count, the way only his fights do
+ dropOldEvents( frame );
+ DirectorEvent *best = NULL;
+ for( size_t index = 0; index < m_events.size(); index++ )
+ {
+ DirectorEvent &event = m_events[ index ];
+ Coord2D middle;
+ if( event.owner != narrowTo && narrowTo != NULL && ObserverCamera_heatAround( sights, event.target, &middle ) <= 0.0f )
+ continue;
+ // hits at the target keep it going: the missiles arriving, the bombs, the fires after
+ if( frame >= event.since + EVENT_LAUNCH_FRAMES && ObserverCamera_heatAround( hits, event.target, &middle ) > 0.0f )
+ event.until = max( event.until, frame + EVENT_AFTERMATH_FRAMES );
+ if( best == NULL || event.weight >= best->weight )
+ best = &event;
+ }
+ DirectorEvent *current = m_placeValid && m_placeKind == PLACE_EVENT ? findEvent( m_placeEvent ) : NULL;
+ if( current != NULL && ( best == current || !ObserverCamera_shouldMove( current->weight, best->weight, held ) ) )
+ {
+ m_place = ObserverCamera_eventPlace( *current, frame );
+ *place = m_place;
+ return TRUE;
+ }
+ // an event that just ended hands straight over to the next; anything else is given its settle first
+ if( best != NULL && ( !m_placeValid || m_placeKind == PLACE_EVENT || held >= DIRECTOR_SETTLE_FRAMES ) )
+ {
+ DEBUG_LOG(( "OBSCAM frame %u director to special power %u at (%.0f,%.0f)%s\n", frame, best->id,
+ best->target.x, best->target.y, best->superweapon ? " superweapon" : "" ));
+ m_place = ObserverCamera_eventPlace( *best, frame );
+ m_placeKind = PLACE_EVENT;
+ m_placeEvent = best->id;
+ m_placeSince = frame;
+ m_placeValid = TRUE;
+ *place = m_place;
+ return TRUE;
+ }
+
+ if( m_placeValid && m_placeKind == PLACE_FIGHT )
{
const Real heatHere = ObserverCamera_heatAround( hits, m_place, &followed );
if( heatHere > 0.0f && ( sameFight( hottest, followed ) || !ObserverCamera_shouldMove( heatHere, hottestHeat, held ) ) )
{
- m_place = followed;
+ const Real dx = followed.x - m_place.x;
+ const Real dy = followed.y - m_place.y;
+ if( dx * dx + dy * dy > DIRECTOR_FOLLOW_SLACK * DIRECTOR_FOLLOW_SLACK )
+ m_place = followed;
*place = m_place;
return TRUE;
}
}
- else if( m_placeValid && hottestHeat <= 0.0f && held < DIRECTOR_SIGHT_FRAMES )
+ else if( m_placeValid && m_placeKind == PLACE_SIGHT && hottestHeat <= 0.0f && held < DIRECTOR_SIGHT_FRAMES )
{
if( ObserverCamera_heatAround( sights, m_place, &followed ) > 0.0f )
m_place = followed;
@@ -410,7 +589,7 @@ Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )
{
DEBUG_LOG(( "OBSCAM frame %u director to fight (%.0f,%.0f) heat %.1f\n", frame, hottest.x, hottest.y, hottestHeat ));
m_place = hottest;
- m_placeIsFight = TRUE;
+ m_placeKind = PLACE_FIGHT;
}
else
{
@@ -426,7 +605,7 @@ Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )
}
DEBUG_LOG(( "OBSCAM frame %u director to sight (%.0f,%.0f)\n", frame, sight.x, sight.y ));
m_place = sight;
- m_placeIsFight = FALSE;
+ m_placeKind = PLACE_SIGHT;
m_seen.push_back( sight );
if( m_seen.size() > DIRECTOR_SEEN_COUNT )
m_seen.erase( m_seen.begin() );
@@ -503,8 +682,11 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )
}
holdHeight( isShowingPlayerView() );
- const Real timeConstant = m_mode == OBSERVER_CAMERA_PLAYER ? PLAYER_PAN_SECONDS : DIRECTOR_PAN_SECONDS;
- const ViewLocation step = ObserverCamera_approach( current, target, elapsed / MILLISECONDS_PER_SECOND, timeConstant );
+ if( !m_driving )
+ m_velocity.x = m_velocity.y = m_velocity.z = m_velocity.angle = m_velocity.pitch = m_velocity.zoom = 0.0f;
+ const Bool player = m_mode == OBSERVER_CAMERA_PLAYER;
+ const ViewLocation step = ObserverCamera_approach( current, target, elapsed / MILLISECONDS_PER_SECOND,
+ player ? PLAYER_PAN_SECONDS : DIRECTOR_PAN_SECONDS, player ? PLAYER_TOP_SPEED : DIRECTOR_TOP_SPEED, &m_velocity );
TheTacticalView->setLocation( &step );
m_drivenTo = step.getPosition();
m_driving = TRUE;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp
index bbb9baf97..ec47accd6 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp
@@ -54,6 +54,7 @@
#include "GameClient/Eva.h"
#include "GameClient/InGameUI.h"
#include "GameClient/ControlBar.h"
+#include "GameClient/ObserverCamera.h"
#ifdef _INTERNAL
@@ -570,6 +571,11 @@ void SpecialPowerModule::aboutToDoSpecialPower( const Coord3D *location )
getSpecialPowerModuleData()->m_specialPowerTemplate->getName(),
getObject()->getID());
+ // the observer's director camera goes to see it; this only tells the client
+ if( location != NULL )
+ TheObserverCamera.noteSpecialPower( getObject()->getControllingPlayer(), getObject()->getPosition(), location,
+ getObject()->isKindOf( KINDOF_FS_SUPERWEAPON ) );
+
// Let EVA do her thing
SpecialPowerType type = getSpecialPowerModuleData()->m_specialPowerTemplate->getSpecialPowerType();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp
index 144bf3c43..0368ec8fd 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp
@@ -46,6 +46,7 @@
#include "GameClient/Drawable.h"
#include "GameClient/FXList.h"
#include "GameClient/InGameUI.h"
+#include "GameClient/ObserverCamera.h"
#include "GameClient/ParticleSys.h"
static const Real STRAIGHT_DOWN_SLOW_FACTOR = 0.5f;
@@ -458,6 +459,8 @@ void NeutronMissileUpdate::detonate()
{
m_deliveryDecal.clear();
Object* obj = getObject();
+ // the observer's director camera stays for the blast; this only tells the client
+ TheObserverCamera.noteSuperweaponHit( obj->getControllingPlayer(), obj->getPosition(), FALSE );
// kill it (vs destroying it) so that its Die modules are called
obj->kill();
m_state = DEAD;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp
index 9838fd3f1..0f048196c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp
@@ -46,6 +46,7 @@
#include "GameClient/Drawable.h"
#include "GameClient/ParticleSys.h"
#include "GameClient/FXList.h"
+#include "GameClient/ObserverCamera.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/PartitionManager.h"
@@ -660,6 +661,9 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update()
beam->setPosition( &audioPos );
}
+ // the observer's director camera follows the beam along its sweep; this only tells the client
+ TheObserverCamera.noteSuperweaponHit( me->getControllingPlayer(), &m_currentTargetPosition, TRUE );
+
//Create scorch marks periodically
if( m_nextScorchMarkFrame <= now )
{
diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.inc
index 3880d9c81..93bf77b42 100644
--- a/GeneralsMD/Code/Tests/test_observer_camera.inc
+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc
@@ -32,23 +32,49 @@ TEST(the_director_goes_to_the_crowded_fight_not_the_lone_hit)
TEST(the_director_holds_a_live_fight_and_leaves_a_dead_one)
{
- const UnsignedInt longHeld = 10 * LOGICFRAMES_PER_SECOND;
+ const UnsignedInt longHeld = 15 * LOGICFRAMES_PER_SECOND;
const UnsignedInt justArrived = LOGICFRAMES_PER_SECOND;
CHECK( ObserverCamera_shouldMove( 0.0f, 1.0f, justArrived ) );
CHECK( !ObserverCamera_shouldMove( 0.0f, 0.0f, longHeld ) );
CHECK( !ObserverCamera_shouldMove( 4.0f, 20.0f, justArrived ) );
- CHECK( !ObserverCamera_shouldMove( 4.0f, 5.0f, longHeld ) );
- CHECK( ObserverCamera_shouldMove( 4.0f, 7.0f, longHeld ) );
+ CHECK( !ObserverCamera_shouldMove( 4.0f, 7.0f, longHeld ) );
+ CHECK( ObserverCamera_shouldMove( 4.0f, 9.0f, longHeld ) );
+ // ten seconds in is still inside the hold
+ CHECK( !ObserverCamera_shouldMove( 4.0f, 9.0f, 10 * LOGICFRAMES_PER_SECOND ) );
}
TEST(the_director_leaves_early_for_a_much_bigger_fight_and_late_for_any_bigger_one)
{
- const UnsignedInt settled = 3 * LOGICFRAMES_PER_SECOND;
- const UnsignedInt tired = 25 * LOGICFRAMES_PER_SECOND;
- CHECK( ObserverCamera_shouldMove( 4.0f, 13.0f, settled ) );
- CHECK( !ObserverCamera_shouldMove( 4.0f, 7.0f, settled ) );
- CHECK( ObserverCamera_shouldMove( 4.0f, 5.0f, tired ) );
- CHECK( !ObserverCamera_shouldMove( 4.0f, 4.2f, tired ) );
+ const UnsignedInt settled = 7 * LOGICFRAMES_PER_SECOND;
+ const UnsignedInt tired = 35 * LOGICFRAMES_PER_SECOND;
+ CHECK( ObserverCamera_shouldMove( 4.0f, 17.0f, settled ) );
+ CHECK( !ObserverCamera_shouldMove( 4.0f, 13.0f, settled ) );
+ // not even a much bigger fight pulls it away in its first seconds
+ CHECK( !ObserverCamera_shouldMove( 4.0f, 40.0f, 3 * LOGICFRAMES_PER_SECOND ) );
+ CHECK( ObserverCamera_shouldMove( 4.0f, 5.4f, tired ) );
+ CHECK( !ObserverCamera_shouldMove( 4.0f, 5.0f, tired ) );
+}
+
+TEST(the_director_shows_a_superweapon_leaving_its_silo_then_where_it_lands)
+{
+ DirectorEvent nuke;
+ nuke.id = 1;
+ nuke.owner = NULL;
+ nuke.source.x = 500.0f;
+ nuke.source.y = 500.0f;
+ nuke.target.x = 3000.0f;
+ nuke.target.y = 2000.0f;
+ nuke.since = 1000;
+ nuke.until = 2000;
+ nuke.weight = 5.0f;
+ nuke.superweapon = TRUE;
+ CHECK_NEAR( ObserverCamera_eventPlace( nuke, 1001 ).x, 500.0f, 0.001f );
+ CHECK_NEAR( ObserverCamera_eventPlace( nuke, 1000 + 10 * LOGICFRAMES_PER_SECOND ).x, 3000.0f, 0.001f );
+
+ // a bomber's strike has nothing worth seeing where it was ordered from
+ DirectorEvent strike = nuke;
+ strike.superweapon = FALSE;
+ CHECK_NEAR( ObserverCamera_eventPlace( strike, 1001 ).x, 3000.0f, 0.001f );
}
TEST(the_director_goes_where_more_is_at_stake_not_where_more_was_hit)
@@ -106,6 +132,13 @@ TEST(the_director_with_no_fight_goes_round_the_sights_and_never_parks)
CHECK_NEAR( place.x, 1000.0f, 0.001f );
}
+static ObserverCameraVelocity atRest( void )
+{
+ ObserverCameraVelocity velocity;
+ velocity.x = velocity.y = velocity.z = velocity.angle = velocity.pitch = velocity.zoom = 0.0f;
+ return velocity;
+}
+
TEST(the_observer_camera_pans_a_short_way_and_cuts_a_long_one)
{
ViewLocation from;
@@ -116,14 +149,51 @@ TEST(the_observer_camera_pans_a_short_way_and_cuts_a_long_one)
ViewLocation across;
across.init( 3000.0f, 1000.0f, 0.0f, 3.0f, 0.5f, 1.0f );
- const ViewLocation still = ObserverCamera_approach( from, beside, 0.0f, 0.2f );
+ ObserverCameraVelocity velocity = atRest();
+ const ViewLocation still = ObserverCamera_approach( from, beside, 0.0f, 0.2f, 900.0f, &velocity );
CHECK_NEAR( still.getPosition().x, 1000.0f, 0.001f );
- const ViewLocation step = ObserverCamera_approach( from, beside, 0.1f, 0.2f );
+ const ViewLocation step = ObserverCamera_approach( from, beside, 0.1f, 0.2f, 900.0f, &velocity );
CHECK( step.getPosition().x > 1000.0f && step.getPosition().x < 1100.0f );
// 3 to -3 is the short way through the back, not six radians round the front
CHECK( fabs( step.getAngle() ) > 3.0f );
- const ViewLocation cut = ObserverCamera_approach( from, across, 0.01f, 0.2f );
+ velocity = atRest();
+ const ViewLocation cut = ObserverCamera_approach( from, across, 0.01f, 0.2f, 900.0f, &velocity );
CHECK_NEAR( cut.getPosition().x, 3000.0f, 0.001f );
+ CHECK_NEAR( velocity.x, 0.0f, 0.001f );
+}
+
+TEST(the_observer_camera_eases_in_holds_its_top_speed_and_settles_without_overshoot)
+{
+ ViewLocation from;
+ from.init( 1000.0f, 1000.0f, 0.0f, 0.0f, 0.5f, 1.0f );
+ ViewLocation to;
+ to.init( 2200.0f, 1000.0f, 0.0f, 0.0f, 0.5f, 1.0f );
+
+ const Real tick = 1.0f / 30.0f;
+ const Real topSpeed = 900.0f;
+ ObserverCameraVelocity velocity = atRest();
+ ViewLocation at = from;
+ Real lastStep = 0.0f;
+ Real firstStep = 0.0f;
+ Bool overshot = FALSE;
+ Bool tooFast = FALSE;
+ for( Int each = 0; each < 30 * 10; each++ )
+ {
+ const ViewLocation next = ObserverCamera_approach( at, to, tick, 1.4f, topSpeed, &velocity );
+ const Real moved = next.getPosition().x - at.getPosition().x;
+ if( each == 0 )
+ firstStep = moved;
+ tooFast = tooFast || moved > topSpeed * tick;
+ overshot = overshot || next.getPosition().x > 2200.0f + 0.01f;
+ lastStep = moved;
+ at = next;
+ }
+ // from rest the first step is a small fraction of the speed it reaches
+ CHECK( firstStep < 0.25f * topSpeed * tick );
+ CHECK( !tooFast );
+ CHECK( !overshot );
+ CHECK_NEAR( at.getPosition().x, 2200.0f, 1.0f );
+ CHECK( lastStep < 1.0f );
}