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.

fix(gameengine): tell callers when a screen pick reaches no ground

Olcay Seygan6ef0da224eb9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cbbbe7747..516a9de54 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -429,6 +429,8 @@ found and fixed — EA's own, not port damage.**
- One tree in ten stood dead still in the breeze. The number that picks which way a tree sways was drawn from a range one short at the bottom, and the bottom of that range is the slot meaning "no sway at all".
- Police car lights flash at their own speed instead of your monitor's. On a fast screen with the frame cap off they were cycling five and a half times too quickly.
- Ten more places that wrote terrain, roads, bridges, trees, foundations and scorch marks into a buffer the graphics card had refused to hand over. Every one of them wrote to address zero instead, and a graphics device pulled out from under the game is all it takes; the frame is simply skipped now.
+- The building outline and the target circle stay where they are when the cursor crosses the skyline. There is no ground above the horizon, and the game took the miss for an answer: the corner of the map. Every time the mouse went over the horizon the ghost you were placing shot across the world and back.
+- The radar stops reading a hero who has just died. It kept the unit's own position rather than a copy of it, and only rebuilt that list every sixth frame, so the five frames after a hero fell were spent looking at a unit that was no longer there.
- A mission that asks to see more of the ground gets more of it. The script action for widening the drawn terrain was written when the game drew a square of map around the camera and pushed that square out; this one already draws the whole map, so the same arithmetic handed back a patch a few hundred feet across and the ground ended in mid air - in exactly the cutscenes that asked to see further.
- Tank tracks no longer crash the game. The renderer has to borrow the buffer it writes them into, and when that request failed, which is what a graphics device pulled out from under the game does, the tracks were written to address zero anyway. Two more of the same shape went with it: the screenshot path and the texture size lookup both used a pointer that the failing call had never filled in. Three of those texture lookups also leaked the surface they asked about, once per procedural texture, for the life of the process.
- Double-clicking a menu button opens the screen once. The button stays live while the old screen animates out, so the second click started the same transition again and the screen opened twice, one copy left drawn over whatever came next and doing nothing sensible when clicked.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
index 9b522fd83..6b4ae4854 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
@@ -201,7 +201,10 @@ public:
Bool worldToScreen( const Coord3D *w, ICoord2D *s ) { return worldToScreenTriReturn( w, s ) == WTS_INSIDE_FRUSTUM; } ///< Transform world coordinate "w" into screen coordinate "s"
virtual WorldToScreenReturn worldToScreenTriReturn(const Coord3D *w, ICoord2D *s ) = 0; ///< Like worldToScreen(), but with a more informative return value
virtual void screenToWorld( const ICoord2D *s, Coord3D *w ) = 0; ///< Transform screen coordinate "s" into world coordinate "w"
- virtual void screenToTerrain( const ICoord2D *screen, Coord3D *world ) = 0; ///< transform screen coord to a point on the 3D terrain
+ /// Transform a screen coord to a point on the 3D terrain. FALSE when the ray reaches no ground,
+ /// which happens whenever the pixel is above the horizon; world is still filled in, with the
+ /// map corner, so a caller that ignores this reads what it always read.
+ virtual Bool screenToTerrain( const ICoord2D *screen, Coord3D *world ) = 0;
virtual void screenToWorldAtZ( const ICoord2D *s, Coord3D *w, Real z ) = 0; ///< transform screen point to world point at the specified world Z value
virtual void getLocation ( ViewLocation *location ); ///< write the view's current location in to the view location object
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 238df2d49..ad9dc39ee 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1528,8 +1528,9 @@ void InGameUI::handleRadiusCursor()
&& ThePlayerList->getLocalPlayer()->hasRadar()
);
- if( !radarOn || (TheRadar->screenPixelToWorld( &mouseIO->pos, &pos ) == FALSE) )// if radar off, or point not on radar
- TheTacticalView->screenToTerrain( &mouseIO->pos, &pos );
+ Bool hasPos = radarOn && TheRadar->screenPixelToWorld( &mouseIO->pos, &pos );
+ if( !hasPos )// if radar off, or point not on radar
+ hasPos = TheTacticalView->screenToTerrain( &mouseIO->pos, &pos );
if ( TheGlobalData->m_doubleClickAttackMove && m_duringDoubleClickAttackMoveGuardHintTimer > 0 )
@@ -1538,7 +1539,7 @@ void InGameUI::handleRadiusCursor()
m_curRadiusCursor.setPosition( m_duringDoubleClickAttackMoveGuardHintStashedPosition ); //world space position of center of decal
}
- else
+ else if ( hasPos )
{
m_curRadiusCursor.setPosition(pos); //world space position of center of decal
m_curRadiusCursor.update();
@@ -1550,9 +1551,11 @@ void InGameUI::handleRadiusCursor()
void InGameUI::triggerDoubleClickAttackMoveGuardHint( void )
{
- m_duringDoubleClickAttackMoveGuardHintTimer = 11;
const MouseIO* mouseIO = TheMouse->getMouseStatus();
- TheTacticalView->screenToTerrain( &mouseIO->pos, &m_duringDoubleClickAttackMoveGuardHintStashedPosition );
+ // No ground under the cursor means there is nothing to stash and nothing to hint at, so the
+ // timer stays down rather than parking the hint on the corner of the map for eleven frames.
+ if( TheTacticalView->screenToTerrain( &mouseIO->pos, &m_duringDoubleClickAttackMoveGuardHintStashedPosition ) )
+ m_duringDoubleClickAttackMoveGuardHintTimer = 11;
}
@@ -1733,7 +1736,10 @@ void InGameUI::handleBuildPlacements( void )
// set the location and angle of the place icon
/**@todo this whole orientation vector thing is LAME! Must replace, all I want to
to do is set a simple angle and have it automatically change, ug! */
- TheTacticalView->screenToTerrain( &loc, &world );
+ // Above the horizon the ray reaches no ground and the answer is the corner of the map, which
+ // threw the ghost across the world and back. Hold it where it was instead.
+ if( !TheTacticalView->screenToTerrain( &loc, &world ) )
+ world = *m_placeIcon[ 0 ]->getPosition();
snapPlacementToGrid( &world, m_pendingPlaceType, angle );
//
@@ -1852,8 +1858,12 @@ void InGameUI::handleBuildPlacements( void )
// project the start and the end points of the line anchor into the 3D world
Coord3D worldStart, worldEnd;
- TheTacticalView->screenToTerrain( &screenStart, &worldStart );
- TheTacticalView->screenToTerrain( &screenEnd, &worldEnd );
+ // An end that leaves the ground - the cursor dragged above the horizon - has no place on
+ // the map, and the corner is not it. Leave the line as it was last drawn. This block is
+ // the last thing handleBuildPlacements does.
+ if( !TheTacticalView->screenToTerrain( &screenStart, &worldStart ) ||
+ !TheTacticalView->screenToTerrain( &screenEnd, &worldEnd ) )
+ return;
// both ends, so a wall lands on the grid and tiles from a grid square
snapPlacementToGrid( &worldStart, m_pendingPlaceType, angle );
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
index 83c776154..a9ad75717 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
@@ -206,7 +206,7 @@ public:
virtual WorldToScreenReturn worldToScreenTriReturn( const Coord3D *w, ICoord2D *s ); ///< Transform world coordinate "w" into screen coordinate "s"
virtual void screenToWorld( const ICoord2D *s, Coord3D *w ); ///< Transform screen coordinate "s" into world coordinate "w"
- virtual void screenToTerrain( const ICoord2D *screen, Coord3D *world ); ///< transform screen coord to a point on the 3D terrain
+ virtual Bool screenToTerrain( const ICoord2D *screen, Coord3D *world ); ///< transform screen coord to a point on the 3D terrain
virtual void screenToWorldAtZ( const ICoord2D *s, Coord3D *w, Real z ); ///< transform screen point to world point at the specified world Z value
CameraClass *get3DCamera() const { return m_3DCamera; }
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
index e0b0e891e..31e820250 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
@@ -1552,9 +1552,11 @@ void W3DDisplay::gatherDebugStats( void )
//display the x and y mouse coordinates
const MouseIO *mouseIO = TheMouse->getMouseStatus();
Coord3D worldPos;
- TheTacticalView->screenToTerrain(&mouseIO->pos, &worldPos);
- unibuffer.format( L"Mouse position: screen: (%d, %d), world: (%g, %g, %g)", mouseIO->pos.x, mouseIO->pos.y,
- worldPos.x, worldPos.y, worldPos.z);
+ if( TheTacticalView->screenToTerrain(&mouseIO->pos, &worldPos) )
+ unibuffer.format( L"Mouse position: screen: (%d, %d), world: (%g, %g, %g)", mouseIO->pos.x, mouseIO->pos.y,
+ worldPos.x, worldPos.y, worldPos.z);
+ else
+ unibuffer.format( L"Mouse position: screen: (%d, %d), world: none", mouseIO->pos.x, mouseIO->pos.y);
m_displayStrings[MousePosition]->setText( unibuffer );
//display the number of particles in the world and being displayed on screen
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index 034c22e61..d7d6d6b35 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -2557,11 +2557,11 @@ Drawable *W3DView::pickDrawable( const ICoord2D *screen, Bool forceAttack, PickT
/** convert a pixel (x,y) to a location in the world on the terrain.
Screen coordinates assumed in absolute values relative to full display resolution. */
//-------------------------------------------------------------------------------------------------
-void W3DView::screenToTerrain( const ICoord2D *screen, Coord3D *world )
+Bool W3DView::screenToTerrain( const ICoord2D *screen, Coord3D *world )
{
// sanity
if( screen == NULL || world == NULL || TheTerrainRenderObject == NULL )
- return;
+ return FALSE;
if (m_cameraHasMovedSinceRequest) {
m_locationRequests.clear();
@@ -2578,7 +2578,7 @@ void W3DView::screenToTerrain( const ICoord2D *screen, Coord3D *world )
for (int i = m_locationRequests.size() - 1; i >= 0; --i) {
if (m_locationRequests[i].first.x == screen->x && m_locationRequests[i].first.y == screen->y) {
(*world) = m_locationRequests[i].second;
- return;
+ return TRUE;
}
}
@@ -2593,29 +2593,45 @@ void W3DView::screenToTerrain( const ICoord2D *screen, Coord3D *world )
RayCollisionTestClass raytest(lineseg,&result);
+ Bool hit = FALSE;
+
if( TheTerrainRenderObject->Cast_Ray(raytest) )
{
// get the point of intersection according to W3D
intersection = result.ContactPoint;
-
+ hit = TRUE;
+
} // end if
- // Pick bridges.
+ // Pick bridges.
Vector3 bridgePt;
Drawable *bridge = TheTerrainLogic->pickBridge(rayStart, rayEnd, &bridgePt);
if (bridge && bridgePt.Z > intersection.Z) {
intersection = bridgePt;
+ hit = TRUE;
}
+ //
+ // A ray aimed above the horizon reaches no ground at all, and this used to hand the caller
+ // (0,0,0) without a word - a real place, the corner of the map, which is why the radius cursor
+ // and the building ghost jumped there. The out parameter still gets that value so the callers
+ // that ignore the answer behave exactly as before; the answer is now available to the ones that
+ // should not draw anything at all.
+ //
world->x = intersection.X;
world->y = intersection.Y;
world->z = intersection.Z;
+ if (!hit)
+ return FALSE;
+
PosRequest req;
req.first = (*screen);
req.second = (*world);
m_locationRequests.push_back(req); // Insert this request at the end, requires no extra copies
+ return TRUE;
+
} // end screenToTerrain
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp
index 8c7e1b5de..58c273155 100644
--- a/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp
+++ b/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp
@@ -180,7 +180,7 @@ public:
void *userData ) {return 0;};
virtual WorldToScreenReturn worldToScreenTriReturn( const Coord3D *w, ICoord2D *s ) { return WTS_INVALID; }; ///< Transform world coordinate "w" into screen coordinate "s"
virtual void screenToWorld( const ICoord2D *s, Coord3D *w ) {}; ///< Transform screen coordinate "s" into world coordinate "w"
- virtual void screenToTerrain( const ICoord2D *screen, Coord3D *world ) {}; ///< transform screen coord to a point on the 3D terrain
+ virtual Bool screenToTerrain( const ICoord2D *screen, Coord3D *world ) { return false; } ///< transform screen coord to a point on the 3D terrain
virtual void screenToWorldAtZ( const ICoord2D *s, Coord3D *w, Real z ) {}; ///< transform screen point to world point at the specified world Z value
virtual void getScreenCornerWorldPointsAtZ( Coord3D *topLeft, Coord3D *topRight,
Coord3D *bottomLeft, Coord3D *bottomRight,