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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameclient): show each ally's cursor on the map
Olcay Seygan30d66ffb661a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1f546e14d..2cee284ce 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -478,6 +478,15 @@ found and fixed — EA's own, not port damage.**- Your screen only. Nobody else in the match sees your choice, nothing about the game itself changes, and two people in the same game can run different settings. Original is the default and nothing changes until you pick something else.- Switch it mid-match and the map repaints itself. So does the picture when an alliance is made or broken by a map script.+## You can see where your ally is pointing++- Your ally's mouse is on your map: a soft pool of their own player colour on the ground where it rests, with their name across the middle of it. No second arrow on your screen - one is confusing enough, and the name is the part that says whose it is.+- Two people playing together spend half the match describing places to each other. "Behind the oil derrick, no, the other one" is a sentence nobody has to type when you can watch where they are pointing while they say it.+- It moves the way a hand moves. Ten positions a second go over the wire and the marker glides between them, so what you see is somebody working rather than a marker teleporting around the map.+- Allies only, and only mutual ones. Your position is sent to the players you are actually allied with and to nobody else; an enemy is never sent it at all, and a machine that has been made to send it anyway is ignored by everyone who is not your ally.+- An ally who alt-tabs away fades out over a couple of seconds instead of freezing on the map, so a marker that is still there is a marker somebody is still behind.+- Off in one place. `ShowAllyCursors = no` in `Options.ini` stops both halves: nothing is sent from your machine and nothing is drawn on it.+## The options screen has pages- Display, audio, controls, gameplay and network, behind five buttons across the top. The original screen was one panel with everything on it at once, and it was already full the day it shipped: the language filter, the keyboard button and four camera checkboxes are all still in there, parked off the right edge where nobody can reach them, because there was nowhere left to put them.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 7551afc04..2e54e43a6 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -360,6 +360,7 @@ public:Bool m_buildPlacementShadows; ///< whether that structure casts a shadow while it rides the cursorBool m_zoomToCursor; ///< the mouse wheel zooms toward whatever the cursor is overBool m_formationDrag; ///< dragging the right button spreads the selection along the line drawn+ Bool m_showAllyCursors; ///< in a network game, draw where each ally's mouse is pointingInt m_menuTransitionSpeed; ///< percent of the authored speed the menus slide and fade at; 100 = as drawnInt m_textureFilterMode; ///< 0 bilinear, 1 trilinear, 2 anisotropicInt m_anisotropyLevel; ///< samples anisotropic filtering may take; 0 = whatever the card offersdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 2b5539dfb..b39ce5d5f 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -447,6 +447,20 @@ public: // ********************************************************************};const std::vector<OrderHint>& getOrderHints( void ) const { return m_orderHints; }+ // Where each ally's mouse is pointing. A network game only: the position arrives about ten+ // times a second on a side channel of its own, carries nothing the simulation reads, and is+ // never acked or resent, so a lost one costs a tenth of a second of staleness and nothing else.+ struct AllyCursor+ {+ Coord3D position; ///< the last spot that ally reported+ Coord3D shown; ///< eased towards it, so ten updates a second do not read as ten steps+ UnsignedInt heardMs; ///< wall clock of that report, for the fade when an ally stops sending+ Bool known; ///< FALSE until the first report of the match arrives+ };+ void noteAllyCursor( Int playerIndex, Real x, Real y ); ///< an ally said where their mouse is+ const AllyCursor& getAllyCursor( Int playerIndex ) const { return m_allyCursors[ playerIndex ]; }+ Real getAllyCursorFade( Int playerIndex ) const; ///< 0 when there is nothing to draw, 1 for a live cursor+// A circle dragged out with the left button while the attack key is armed. Everything hostile// and visible inside it joins the shift queue below, and the selection works down that list one// target at a time: the next one is ordered the moment the current one stops existing.@@ -999,6 +1013,10 @@ public:/** The wash inside the attack circle, on the ground for the same reason: the units being swept* up stand on top of it instead of being painted over. */virtual void drawAttackCircleFill( void ) { }++ /** The patch of an ally's own colour lying under their cursor. On the ground so that it reads+ * as light falling on the map rather than as a disc floating over it. */+ virtual void drawAllyCursorLights( void ) { }protected:void clearWorldAnimations( void ); ///< delete all world animations@@ -1028,6 +1046,17 @@ protected:Int m_formationDragSpacing; ///< pixels a new point has to earn, doubled each time the curve fills upstd::vector<OrderHint> m_orderHints; ///< who is going where, for drawing+ AllyCursor m_allyCursors[ MAX_PLAYER_COUNT ]; ///< where every ally's mouse was last seen (fork)+ UnsignedInt m_allyCursorSentMs; ///< wall clock of the last position this machine sent+ Coord3D m_allyCursorSentPosition; ///< and what it said, so a still mouse sends nothing+ UnsignedInt m_allyCursorEasedMs; ///< wall clock of the last easing pass, which sets its step++ void clearAllyCursors( void ); ///< forget every ally's marker, for the start of a match+ void updateAllyCursors( void ); ///< ease every ally's marker towards where they said it was+ void sendLocalAllyCursor( void ); ///< tell the allies where this machine's mouse is, at most ten times a second+ Int allyPlayerMask( void ) const; ///< the slots this machine is allied with+ Bool isAllyOfLocalPlayer( Int playerIndex ) const; ///< is this player mutually allied with the one at this machine+Bool m_isAttackCircling; ///< TRUE while an attack circle is being dragged (fork)ICoord2D m_attackCircleAnchor; ///< where the circle was started, in pixelsICoord2D m_attackCircleCursor; ///< where the cursor is now, which is the rimdiff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/ConnectionManager.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/ConnectionManager.hindex 19c49504a..879308226 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/ConnectionManager.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/ConnectionManager.h@@ -66,6 +66,7 @@ public:void parseUserList(const GameInfo *game);void sendChat(UnicodeString text, Int playerMask, UnsignedInt executionFrame);void sendDisconnectChat(UnicodeString text);+ void sendAllyCursor(Real x, Real y, Int playerMask); ///< Tell the players in the mask where the local mouse is pointing.void sendLocalCommand(NetCommandMsg *msg, UnsignedByte relay = 0xff); ///< Send command to the players specified in the relay, goes through packet router.void sendLocalCommandDirect(NetCommandMsg *msg, UnsignedByte relay); ///< Send command directly to the players specified, doesn't go through packet router.void sendLocalGameMessage(GameMessage *msg, UnsignedInt frame);@@ -168,6 +169,7 @@ private:void processFrameInfo(NetFrameCommandMsg *msg);void processRunAheadMetrics(NetRunAheadMetricsCommandMsg *msg);void processDisconnectChat(NetDisconnectChatCommandMsg *msg);+ void processAllyCursor(NetAllyCursorCommandMsg *msg);void processProgress( NetProgressCommandMsg *msg );void processLoadComplete( NetCommandMsg *msg );void processTimeOutGameStart( NetCommandMsg *msg );diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetCommandMsg.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetCommandMsg.hindex 3d6b09e08..f54ef8a6b 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetCommandMsg.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetCommandMsg.h@@ -340,7 +340,28 @@ protected:};//------------------------------------------------------------------------------class NetDisconnectVoteCommandMsg : public NetCommandMsg+/**+ * Where one player's mouse is pointing on the ground, so the players allied with them can see it.+ * Two coordinates and nothing else: the height comes off the receiver's own terrain, which both+ * machines already agree about, and the name and colour come from the player the slot belongs to.+ */+class NetAllyCursorCommandMsg : public NetCommandMsg+{+ MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetAllyCursorCommandMsg, "NetAllyCursorCommandMsg")+public:+ NetAllyCursorCommandMsg();++ Real getX();+ Real getY();+ void setPosition( Real x, Real y );++protected:+ Real m_x;+ Real m_y;+};++//-----------------------------------------------------------------------------+class NetDisconnectVoteCommandMsg : public NetCommandMsg{MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectVoteCommandMsg, "NetDisconnectVoteCommandMsg")public:diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetPacket.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetPacket.hindex 3c3307279..c0a35b730 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetPacket.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetPacket.h@@ -104,6 +104,7 @@ protected:static UnsignedInt GetDisconnectFrameCommandSize(NetCommandMsg *msg);static UnsignedInt GetDisconnectScreenOffCommandSize(NetCommandMsg *msg);static UnsignedInt GetFrameResendRequestCommandSize(NetCommandMsg *msg);+ static UnsignedInt GetAllyCursorCommandSize(NetCommandMsg *msg);static void FillBufferWithGameCommand(UnsignedByte *buffer, NetCommandRef *msg);static void FillBufferWithAckCommand(UnsignedByte *buffer, NetCommandRef *msg);@@ -129,6 +130,7 @@ protected:static void FillBufferWithDisconnectFrameMessage(UnsignedByte *buffer, NetCommandRef *msg);static void FillBufferWithDisconnectScreenOffMessage(UnsignedByte *buffer, NetCommandRef *msg);static void FillBufferWithFrameResendRequestMessage(UnsignedByte *buffer, NetCommandRef *msg);+ static void FillBufferWithAllyCursorMessage(UnsignedByte *buffer, NetCommandRef *msg);Bool addFrameCommand(NetCommandRef *msg);Bool isRoomForFrameMessage(NetCommandRef *msg);@@ -183,6 +185,8 @@ protected:Bool isRoomForDisconnectScreenOffMessage(NetCommandRef *msg);Bool addFrameResendRequestCommand(NetCommandRef *msg);Bool isRoomForFrameResendRequestMessage(NetCommandRef *msg);+ Bool addAllyCursorCommand(NetCommandRef *msg);+ Bool isRoomForAllyCursorMessage(NetCommandRef *msg);Bool isAckRepeat(NetCommandRef *msg);Bool isAckBothRepeat(NetCommandRef *msg);@@ -217,6 +221,7 @@ protected:static NetCommandMsg * readDisconnectFrameMessage(UnsignedByte *data, Int &i);static NetCommandMsg * readDisconnectScreenOffMessage(UnsignedByte *data, Int &i);static NetCommandMsg * readFrameResendRequestMessage(UnsignedByte *data, Int &i);+ static NetCommandMsg * readAllyCursorMessage(UnsignedByte *data, Int &i);void writeGameMessageArgumentToPacket(GameMessageArgumentDataType type, GameMessageArgumentType arg);static void readGameMessageArgumentFromPacket(GameMessageArgumentDataType type, NetGameCommandMsg *msg, UnsignedByte *data, Int &i);diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetworkDefs.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetworkDefs.hindex 2939a7a9c..1299fc123 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetworkDefs.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetworkDefs.h@@ -162,6 +162,8 @@ enum NetCommandType {NETCOMMANDTYPE_FILEANNOUNCE,NETCOMMANDTYPE_FILEPROGRESS,NETCOMMANDTYPE_FRAMERESENDREQUEST,+ NETCOMMANDTYPE_ALLYCURSOR, // Where an ally's mouse is pointing. Carries no game state and+ // is never acked or resent - a lost one is replaced 100ms later.// Disconnect menu command section.NETCOMMANDTYPE_DISCONNECTSTART,diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetworkInterface.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetworkInterface.hindex 48a6b6a9a..b6e86a42a 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetworkInterface.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetworkInterface.h@@ -79,6 +79,10 @@ public:virtual void sendChat(UnicodeString text, Int playerMask) = 0; ///< Send a chat line using the normal system.virtual void sendDisconnectChat(UnicodeString text) = 0; ///< Send a chat line using the disconnect manager.+ /// Tell the players in the mask where the local mouse is pointing. Unacked and unresent - a+ /// lost one is replaced by the next.+ virtual void sendAllyCursor(Real x, Real y, Int playerMask) = 0;+virtual void sendFile(AsciiString path, UnsignedByte playerMask, UnsignedShort commandID) = 0;virtual UnsignedShort sendFileAnnounce(AsciiString path, UnsignedByte playerMask) = 0;virtual Int getFileTransferProgress(Int playerID, AsciiString path) = 0;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex 0676b313c..e01ae4a1e 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -200,6 +200,7 @@ GlobalData* GlobalData::m_theOriginal = NULL;{ "BuildPlacementShadows", INI::parseBool, NULL, offsetof( GlobalData, m_buildPlacementShadows ) },{ "ZoomToCursor", INI::parseBool, NULL, offsetof( GlobalData, m_zoomToCursor ) },{ "FormationDrag", INI::parseBool, NULL, offsetof( GlobalData, m_formationDrag ) },+ { "ShowAllyCursors", INI::parseBool, NULL, offsetof( GlobalData, m_showAllyCursors ) },{ "ShowHudOverlay", INI::parseBool, NULL, offsetof( GlobalData, m_showHudOverlay ) },{ "ShowPlacementRangeRing", INI::parseBool, NULL, offsetof( GlobalData, m_showPlacementRangeRing ) },{ "WorkersReturnToSupply", INI::parseBool, NULL, offsetof( GlobalData, m_workersReturnToSupply ) },@@ -1092,6 +1093,7 @@ GlobalData::GlobalData()m_zoomToCursor = TRUE;// the right button no longer scrolls, so a right-drag is free to mean somethingm_formationDrag = TRUE;+ m_showAllyCursors = TRUE;m_menuTransitionSpeed = 100;m_textureFilterMode = 2; // anisotropic; retail shipped bilinear on a 2003 fill-rate budgetm_anisotropyLevel = 0; // whatever the card offers, capped at 16 in _Init_Filtersdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cppindex 80962e0a7..cb792c1a6 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp@@ -45,6 +45,7 @@ OPTION_BOOL_ACCESSORS( m_edgeScrollInWindowedMode )OPTION_BOOL_ACCESSORS( m_snapCameraRotateTo45 )OPTION_BOOL_ACCESSORS( m_zoomToCursor )OPTION_BOOL_ACCESSORS( m_formationDrag )+OPTION_BOOL_ACCESSORS( m_showAllyCursors )OPTION_INT_ACCESSORS( m_bloomIntensity )OPTION_INT_ACCESSORS( m_bloomThreshold )OPTION_INT_ACCESSORS( m_menuTransitionSpeed )@@ -181,6 +182,13 @@ const OptionDef TheOptionCatalog[] =OPTION_BOOL, APPLY_LIVE, 0, 1,get_m_formationDrag, set_m_formationDrag },+ // In a network game, each ally's mouse is drawn on the map with their name over it and a patch+ // of their colour under it. Off and neither end of it happens: nothing is sent and nothing is+ // drawn, so a player who does not want to be watched turns it off on their own machine.+ { "ShowAllyCursors", "", "",+ OPTION_BOOL, APPLY_LIVE, 0, 1,+ get_m_showAllyCursors, set_m_showAllyCursors },+// Percent of the speed the menu slides and fades were authored at. 100 is what the artists// drew; higher gets you through the shell faster, and nothing about a menu animation is worth// waiting for on the four hundredth launch.diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cppindex acc720cd4..b062486a7 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cpp@@ -612,6 +612,7 @@ static PoolSizeRec sizes[] ={ "NetPacketRouterAckCommandMsg", 32, 32 },{ "NetDisconnectChatCommandMsg", 32, 32 },{ "NetChatCommandMsg", 32, 32 },+ { "NetAllyCursorCommandMsg", 32, 32 },{ "NetDisconnectVoteCommandMsg", 32, 32 },{ "NetProgressCommandMsg", 32, 32 },{ "NetWrapperCommandMsg", 32, 32 },diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 90da6f349..938741d24 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -80,6 +80,8 @@#include "GameClient/Shadow.h"#include "GameClient/GlobalLanguage.h"+#include "GameNetwork/NetworkInterface.h"+#include "GameLogic/AIGuard.h"#include "GameLogic/AIStateMachine.h"#include "GameLogic/Module/AIUpdate.h"@@ -1221,6 +1223,7 @@ InGameUI::InGameUI()m_shiftAttackQueueEngagedFrame = 0;m_shiftAttackQueueWaitingForRearm = FALSE;m_shiftAttackQueueWaitingForSelection = FALSE;+ clearAllyCursors();m_curRcType = RADIUSCURSOR_NONE;@@ -2330,6 +2333,15 @@ void InGameUI::update( void )TheTacticalView->zoomOut( cameraSteps );}+ //+ // Where this machine's mouse is, for the allies, and where theirs were, for this screen. Here+ // rather than in preDraw because an ally's cursor is drawn twice: the patch of light goes down+ // in the terrain pass and the pointer over the top of it afterwards, and preDraw runs between+ // the two - so easing there moved the pointer a frame ahead of its own light, which on a fast+ // drag is a smear trailing the marker by an inch.+ //+ sendLocalAllyCursor();+ updateAllyCursors();} // end update@@ -2431,6 +2443,7 @@ void InGameUI::reset( void )m_shiftAttackQueueEngagedFrame = 0;m_shiftAttackQueueWaitingForRearm = FALSE;m_shiftAttackQueueWaitingForSelection = FALSE;+ clearAllyCursors();m_clientQuiet = false;// TheSuperHackers @bugfix A key or button still held when the game ended left its camera@@ -2688,6 +2701,211 @@ void InGameUI::addFormationDragPoint( const ICoord2D& pt )updateFormationHints();}+//-------------------------------------------------------------------------------------------------+// Ally cursors. Ten reports a second, on a network command of their own that carries two floats+// and is never acked, resent or written to a replay - the simulation cannot see any of this, so+// none of it can change what a match does.+//+// A cursor that has not been heard from for ALLY_CURSOR_HOLD_MS starts fading and is gone by+// ALLY_CURSOR_GONE_MS, which is what an ally alt-tabbing away or dropping out looks like.+//-------------------------------------------------------------------------------------------------+static const UnsignedInt ALLY_CURSOR_SEND_INTERVAL_MS = 100; ///< ten a second, which reads as continuous once eased+static const UnsignedInt ALLY_CURSOR_IDLE_RESEND_MS = 1000; ///< a still mouse still says so, or it would fade out+static const UnsignedInt ALLY_CURSOR_HOLD_MS = 2500; ///< heard from this recently, drawn at full strength+static const UnsignedInt ALLY_CURSOR_GONE_MS = 3500; ///< and faded out entirely by here+static const Real ALLY_CURSOR_MOVED_DIST = 1.0f; ///< world units a cursor has to have moved to be worth a packet+static const Real ALLY_CURSOR_EASE_MS = 110.0f; ///< how long the marker takes to catch up with a new report+static const Real ALLY_CURSOR_JUMP_DIST = 400.0f; ///< further than this and it snaps instead: a camera jump is not a mouse move++//-------------------------------------------------------------------------------------------------+void InGameUI::clearAllyCursors( void )+{+ for( Int i = 0; i < MAX_PLAYER_COUNT; ++i )+ {+ m_allyCursors[ i ].position.zero();+ m_allyCursors[ i ].shown.zero();+ m_allyCursors[ i ].heardMs = 0;+ m_allyCursors[ i ].known = FALSE;+ }+ m_allyCursorSentMs = 0;+ m_allyCursorSentPosition.zero();+ m_allyCursorEasedMs = 0;+}++//-------------------------------------------------------------------------------------------------+/** One ally's mouse, as they last reported it. The height is not on the wire: the terrain both+ * machines loaded answers that, and reading it here means a cursor over a hill sits on the hill+ * rather than at whatever height the sender's own camera happened to make of it. */+//-------------------------------------------------------------------------------------------------+void InGameUI::noteAllyCursor( Int playerIndex, Real x, Real y )+{+ if( !isValidPlayerIndex( playerIndex ) )+ return;++ //+ // The sender addresses these to its allies, but the relay mask is not what decides who reads+ // one: the packet router processes every command that passes through it on its way to somebody+ // else, so without this the player holding that seat would watch the enemy's mouse. The check+ // belongs here anyway - a machine that has been made to send its cursor to everyone gets the+ // same answer, because whether two players are allied is not the sender's to assert.+ //+ if( !isAllyOfLocalPlayer( playerIndex ) )+ return;++ AllyCursor& cursor = m_allyCursors[ playerIndex ];++ cursor.position.x = x;+ cursor.position.y = y;+ cursor.position.z = TheTerrainLogic->getGroundHeight( x, y );+ cursor.heardMs = timeGetTime();++ // the first report of a match arrives wherever that ally is looking, which is nowhere near the+ // origin the marker starts at - easing in from there would draw a line across the whole map+ if( cursor.known == FALSE )+ {+ cursor.shown = cursor.position;+ cursor.known = TRUE;+ DEBUG_LOG(("ALLYCURSOR: first report from player %d at %.1f,%.1f\n", playerIndex, x, y));+ }+}++//-------------------------------------------------------------------------------------------------+/** Is this player mutually allied with the one sitting at this machine. One-sided alliances are+ * not a partnership: a player who has declared for somebody who has not declared back does not get+ * to watch them work. */+//-------------------------------------------------------------------------------------------------+Bool InGameUI::isAllyOfLocalPlayer( Int playerIndex ) const+{+ const Player *localPlayer = ThePlayerList->getLocalPlayer();+ const Player *player = ThePlayerList->getNthPlayer( playerIndex );+ if( localPlayer == NULL || player == NULL || player == localPlayer )+ return FALSE;++ if( !localPlayer->isPlayerActive() || !player->isPlayerActive() )+ return FALSE;++ return player->getRelationship( localPlayer->getDefaultTeam() ) == ALLIES &&+ localPlayer->getRelationship( player->getDefaultTeam() ) == ALLIES;+}++//-------------------------------------------------------------------------------------------------+/** How strongly an ally's cursor should be drawn, 0 for one that should not be drawn at all. */+//-------------------------------------------------------------------------------------------------+Real InGameUI::getAllyCursorFade( Int playerIndex ) const+{+ if( !isValidPlayerIndex( playerIndex ) )+ return 0.0f;++ const AllyCursor& cursor = m_allyCursors[ playerIndex ];+ if( cursor.known == FALSE )+ return 0.0f;++ const UnsignedInt ageMs = timeGetTime() - cursor.heardMs;+ if( ageMs >= ALLY_CURSOR_GONE_MS )+ return 0.0f;+ if( ageMs <= ALLY_CURSOR_HOLD_MS )+ return 1.0f;++ return 1.0f - (Real)( ageMs - ALLY_CURSOR_HOLD_MS ) / (Real)( ALLY_CURSOR_GONE_MS - ALLY_CURSOR_HOLD_MS );+}++//-------------------------------------------------------------------------------------------------+/** Walk every marker towards the spot its owner last reported. Ten reports a second drawn raw+ * would step; eased over about a tenth of a second they read as one hand moving. Wall clock+ * rather than frames, because the picture is uncapped. */+//-------------------------------------------------------------------------------------------------+void InGameUI::updateAllyCursors( void )+{+ const UnsignedInt nowMs = timeGetTime();+ const UnsignedInt elapsedMs = ( m_allyCursorEasedMs == 0 ) ? 0 : ( nowMs - m_allyCursorEasedMs );+ m_allyCursorEasedMs = nowMs;++ Real step = (Real)elapsedMs / ALLY_CURSOR_EASE_MS;+ if( step > 1.0f )+ step = 1.0f;++ for( Int i = 0; i < MAX_PLAYER_COUNT; ++i )+ {+ AllyCursor& cursor = m_allyCursors[ i ];+ if( cursor.known == FALSE )+ continue;++ Coord3D delta = cursor.position;+ delta.sub( &cursor.shown );++ if( delta.length() > ALLY_CURSOR_JUMP_DIST )+ {+ cursor.shown = cursor.position;+ continue;+ }++ delta.scale( step );+ cursor.shown.add( &delta );+ }+}++//-------------------------------------------------------------------------------------------------+/** The slots this machine is mutually allied with, its own left out. An observer is allied with+ * nobody, so the mask comes back empty and nothing is sent. */+//-------------------------------------------------------------------------------------------------+Int InGameUI::allyPlayerMask( void ) const+{+ Int mask = 0;+ for( Int slot = 0; slot < MAX_SLOTS; ++slot )+ {+ // the network's slot numbers and the player list's indices are two different numberings, and+ // "player<slot>" is the name that joins them - the same lookup in-game chat uses+ AsciiString playerName;+ playerName.format( "player%d", slot );+ const Player *player = ThePlayerList->findPlayerWithNameKey( TheNameKeyGenerator->nameToKey( playerName ) );+ if( player != NULL && isAllyOfLocalPlayer( player->getPlayerIndex() ) )+ mask |= ( 1 << slot );+ }++ return mask;+}++//-------------------------------------------------------------------------------------------------+/** Tell the allies where this machine's mouse is pointing, at most ten times a second, and only+ * while it is over the map. A mouse that has not moved still reports once a second, or the+ * marker on the other screens would fade out while its owner sat thinking. */+//-------------------------------------------------------------------------------------------------+void InGameUI::sendLocalAllyCursor( void )+{+ if( !TheGlobalData->m_showAllyCursors )+ return;++ // TheNetwork is the whole test for "is this a game with other people in it"+ if( TheNetwork == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )+ return;++ const UnsignedInt nowMs = timeGetTime();+ if( m_allyCursorSentMs != 0 && ( nowMs - m_allyCursorSentMs ) < ALLY_CURSOR_SEND_INTERVAL_MS )+ return;++ // a pointer over the command bar or off the top of the map has no map position, and a marker+ // parked on the last piece of ground it crossed on the way there would be a lie+ const MouseIO *mouse = TheMouse->getMouseStatus();+ Coord3D world;+ if( !TheTacticalView->screenToTerrain( &mouse->pos, &world ) )+ return;++ Coord3D moved = world;+ moved.sub( &m_allyCursorSentPosition );+ if( m_allyCursorSentMs != 0 && moved.length() < ALLY_CURSOR_MOVED_DIST &&+ ( nowMs - m_allyCursorSentMs ) < ALLY_CURSOR_IDLE_RESEND_MS )+ return;++ const Int mask = allyPlayerMask();+ if( mask == 0 )+ return;++ TheNetwork->sendAllyCursor( world.x, world.y, mask );++ m_allyCursorSentMs = nowMs;+ m_allyCursorSentPosition = world;+}+//-------------------------------------------------------------------------------------------------/** Work out who is going where, from the curve as it stands. This is the same arithmetic the logic* runs when the button comes up - same curve, same filter, same total order - so what the playerdiff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cppindex bfe4b0fe9..39a3279f8 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp@@ -547,10 +547,15 @@ Bool ConnectionManager::processNetCommand(NetCommandRef *ref) {return FALSE;}+ if (msg->getNetCommandType() == NETCOMMANDTYPE_ALLYCURSOR) {+ processAllyCursor((NetAllyCursorCommandMsg *)msg);+ return FALSE;+ }+if (msg->getNetCommandType() == NETCOMMANDTYPE_CHAT) {processChat((NetChatCommandMsg *)msg);return FALSE;- }+ }if (msg->getNetCommandType() == NETCOMMANDTYPE_FILE) {processFile((NetFileCommandMsg *)msg);@@ -2217,6 +2222,45 @@ void ConnectionManager::sendChat(UnicodeString text, Int playerMask, UnsignedIntmsg->detach();}+/**+ * Tell the players in the mask where the local mouse is pointing. Nothing acks this and nothing+ * resends it: a lost one is replaced by the next, a tenth of a second later. The mask is built by+ * the caller from the local player's own alliances, so an enemy is never sent one at all.+ */+void ConnectionManager::sendAllyCursor(Real x, Real y, Int playerMask)+{+ NetAllyCursorCommandMsg *msg = newInstance(NetAllyCursorCommandMsg);+ msg->setPosition(x, y);+ msg->setPlayerID(m_localSlot);+ msg->setID(0);+ msg->setExecutionFrame(0);++ sendLocalCommand(msg, (UnsignedByte)(playerMask & (0xff ^ (1 << m_localSlot))));++ msg->detach();+}++/**+ * Remember where an ally says their cursor is. The height is not on the wire - the terrain both+ * machines loaded answers that - and the name and colour come from the player the slot belongs to.+ */+void ConnectionManager::processAllyCursor(NetAllyCursorCommandMsg *msg)+{+ const UnsignedByte playerID = msg->getPlayerID();+ if (playerID >= MAX_SLOTS) {+ return;+ }++ AsciiString playerName;+ playerName.format("player%d", playerID);+ const Player *player = ThePlayerList->findPlayerWithNameKey( TheNameKeyGenerator->nameToKey( playerName ) );+ if (player == NULL) {+ return;+ }++ TheInGameUI->noteAllyCursor( player->getPlayerIndex(), msg->getX(), msg->getY() );+}+void ConnectionManager::sendDisconnectChat(UnicodeString text) {NetDisconnectChatCommandMsg *msg = newInstance(NetDisconnectChatCommandMsg);msg->setPlayerID(m_localSlot);diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cppindex fbd9043cd..de8e2b40a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp@@ -762,6 +762,36 @@ void NetChatCommandMsg::setPlayerMask( Int playerMask )m_playerMask = playerMask;}+//-------------------------+// NetAllyCursorCommandMsg+//-------------------------+NetAllyCursorCommandMsg::NetAllyCursorCommandMsg() : NetCommandMsg()+{+ m_commandType = NETCOMMANDTYPE_ALLYCURSOR;+ m_x = 0.0f;+ m_y = 0.0f;+}++NetAllyCursorCommandMsg::~NetAllyCursorCommandMsg()+{+}++Real NetAllyCursorCommandMsg::getX()+{+ return m_x;+}++Real NetAllyCursorCommandMsg::getY()+{+ return m_y;+}++void NetAllyCursorCommandMsg::setPosition( Real x, Real y )+{+ m_x = x;+ m_y = y;+}+//-------------------------// NetDisconnectVoteCommandMsg//-------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetPacket.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetPacket.cppindex ff36da0e4..9ed49daa4 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetPacket.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetPacket.cpp@@ -144,6 +144,8 @@ NetCommandRef * NetPacket::ConstructNetCommandMsgFromRawData(UnsignedByte *data,msg = readDisconnectScreenOffMessage(data, offset);} else if (commandType == NETCOMMANDTYPE_FRAMERESENDREQUEST) {msg = readFrameResendRequestMessage(data, offset);+ } else if (commandType == NETCOMMANDTYPE_ALLYCURSOR) {+ msg = readAllyCursorMessage(data, offset);}msg->setExecutionFrame(frame);@@ -308,6 +310,8 @@ UnsignedInt NetPacket::GetBufferSizeNeededForCommand(NetCommandMsg *msg) {return GetDisconnectScreenOffCommandSize(msg);case NETCOMMANDTYPE_FRAMERESENDREQUEST:return GetFrameResendRequestCommandSize(msg);+ case NETCOMMANDTYPE_ALLYCURSOR:+ return GetAllyCursorCommandSize(msg);default:DEBUG_CRASH(("Unknown NETCOMMANDTYPE %d", msg->getNetCommandType()));break;@@ -758,6 +762,19 @@ UnsignedInt NetPacket::GetFrameResendRequestCommandSize(NetCommandMsg *msg) {return msglen;}+UnsignedInt NetPacket::GetAllyCursorCommandSize(NetCommandMsg *msg) {+ UnsignedInt msglen = 0;+ msglen += sizeof(UnsignedByte) + sizeof(UnsignedByte); // 'T' and command type+ msglen += sizeof(UnsignedByte) + sizeof(UnsignedByte); // 'P' and player ID+ msglen += sizeof(UnsignedByte) + sizeof(UnsignedShort); // 'C' and command ID+ msglen += sizeof(UnsignedByte) + sizeof(UnsignedByte); // 'R' and relay++ ++msglen; // 'D'+ msglen += sizeof(Real) + sizeof(Real); // where on the map the cursor is++ return msglen;+}+// this function assumes that buffer is already the correct size.void NetPacket::FillBufferWithCommand(UnsignedByte *buffer, NetCommandRef *ref) {NetCommandMsg *msg = ref->getCommand();@@ -838,6 +855,9 @@ void NetPacket::FillBufferWithCommand(UnsignedByte *buffer, NetCommandRef *ref)case NETCOMMANDTYPE_FRAMERESENDREQUEST:FillBufferWithFrameResendRequestMessage(buffer, ref);break;+ case NETCOMMANDTYPE_ALLYCURSOR:+ FillBufferWithAllyCursorMessage(buffer, ref);+ break;default:DEBUG_CRASH(("Unknown NETCOMMANDTYPE %d", msg->getNetCommandType()));break;@@ -1919,6 +1939,48 @@ void NetPacket::FillBufferWithFrameResendRequestMessage(UnsignedByte *buffer, Neoffset += sizeof(frameToResend);}+void NetPacket::FillBufferWithAllyCursorMessage(UnsignedByte *buffer, NetCommandRef *msg) {+ NetAllyCursorCommandMsg *cmdMsg = (NetAllyCursorCommandMsg *)(msg->getCommand());+ UnsignedInt offset = 0;++ // command type+ buffer[offset] = 'T';+ ++offset;+ buffer[offset] = cmdMsg->getNetCommandType();+ offset += sizeof(UnsignedByte);++ // relay+ buffer[offset] = 'R';+ ++offset;+ buffer[offset] = msg->getRelay();+ offset += sizeof(UnsignedByte);++ // player ID+ buffer[offset] = 'P';+ ++offset;+ buffer[offset] = cmdMsg->getPlayerID();+ offset += sizeof(UnsignedByte);++ // command ID+ buffer[offset] = 'C';+ ++offset;+ UnsignedShort newID = cmdMsg->getID();+ memcpy(buffer + offset, &newID, sizeof(newID));+ offset += sizeof(newID);++ // data+ buffer[offset] = 'D';+ ++offset;++ Real x = cmdMsg->getX();+ memcpy(buffer + offset, &x, sizeof(x));+ offset += sizeof(x);++ Real y = cmdMsg->getY();+ memcpy(buffer + offset, &y, sizeof(y));+ offset += sizeof(y);+}+/*** Constructor@@ -2055,6 +2117,8 @@ Bool NetPacket::addCommand(NetCommandRef *msg) {return addDisconnectScreenOffCommand(msg);case NETCOMMANDTYPE_FRAMERESENDREQUEST:return addFrameResendRequestCommand(msg);+ case NETCOMMANDTYPE_ALLYCURSOR:+ return addAllyCursorCommand(msg);default:DEBUG_CRASH(("Unknown NETCOMMANDTYPE %d", cmdMsg->getNetCommandType()));break;@@ -2183,6 +2247,109 @@ Bool NetPacket::isRoomForFrameResendRequestMessage(NetCommandRef *msg) {return TRUE;}+/**+ * Add an ally cursor position to the packet. No execution frame goes with it: nothing waits for+ * this command, it is drawn the moment it lands and replaced by the next one.+ */+Bool NetPacket::addAllyCursorCommand(NetCommandRef *msg) {+ Bool needNewCommandID = FALSE;+ if (isRoomForAllyCursorMessage(msg)) {+ NetAllyCursorCommandMsg *cmdMsg = (NetAllyCursorCommandMsg *)(msg->getCommand());++ // If necessary, put the NetCommandType into the packet.+ if (m_lastCommandType != cmdMsg->getNetCommandType()) {+ m_packet[m_packetLen] = 'T';+ ++m_packetLen;+ m_packet[m_packetLen] = cmdMsg->getNetCommandType();+ m_packetLen += sizeof(UnsignedByte);++ m_lastCommandType = cmdMsg->getNetCommandType();+ }++ // If necessary, put the relay into the packet.+ if (m_lastRelay != msg->getRelay()) {+ m_packet[m_packetLen] = 'R';+ ++m_packetLen;+ UnsignedByte newRelay = msg->getRelay();+ memcpy(m_packet + m_packetLen, &newRelay, sizeof(UnsignedByte));+ m_packetLen += sizeof(UnsignedByte);++ m_lastRelay = newRelay;+ }++ // If necessary put the player ID into the packet.+ if (m_lastPlayerID != cmdMsg->getPlayerID()) {+ m_packet[m_packetLen] = 'P';+ ++m_packetLen;+ m_packet[m_packetLen] = cmdMsg->getPlayerID();+ m_packetLen += sizeof(UnsignedByte);++ m_lastPlayerID = cmdMsg->getPlayerID();+ needNewCommandID = TRUE;+ }++ // If necessary, specify the command ID of this command.+ if (((m_lastCommandID + 1) != (UnsignedShort)(cmdMsg->getID())) || (needNewCommandID == TRUE)) {+ m_packet[m_packetLen] = 'C';+ ++m_packetLen;+ UnsignedShort newID = cmdMsg->getID();+ memcpy(m_packet + m_packetLen, &newID, sizeof(UnsignedShort));+ m_packetLen += sizeof(UnsignedShort);+ }+ m_lastCommandID = cmdMsg->getID();++ m_packet[m_packetLen] = 'D';+ ++m_packetLen;++ Real x = cmdMsg->getX();+ memcpy(m_packet + m_packetLen, &x, sizeof(x));+ m_packetLen += sizeof(x);++ Real y = cmdMsg->getY();+ memcpy(m_packet + m_packetLen, &y, sizeof(y));+ m_packetLen += sizeof(y);++ ++m_numCommands;+ if (m_lastCommand != NULL) {+ m_lastCommand->deleteInstance();+ m_lastCommand = NULL;+ }+ m_lastCommand = NEW_NETCOMMANDREF(msg->getCommand());+ m_lastCommand->setRelay(msg->getRelay());++ return TRUE;+ }+ return FALSE;+}++Bool NetPacket::isRoomForAllyCursorMessage(NetCommandRef *msg) {+ Int len = 0;+ Bool needNewCommandID = FALSE;+ NetAllyCursorCommandMsg *cmdMsg = (NetAllyCursorCommandMsg *)(msg->getCommand());+ if (m_lastCommandType != cmdMsg->getNetCommandType()) {+ ++len;+ len += sizeof(UnsignedByte);+ }+ if (m_lastRelay != msg->getRelay()) {+ len += sizeof(UnsignedByte) + sizeof(UnsignedByte);+ }+ if (m_lastPlayerID != cmdMsg->getPlayerID()) {+ ++len;+ len += sizeof(UnsignedByte);+ needNewCommandID = TRUE;+ }+ if (((m_lastCommandID + 1) != (UnsignedShort)(cmdMsg->getID())) || (needNewCommandID == TRUE)) {+ len += sizeof(UnsignedShort) + sizeof(UnsignedByte);+ }++ ++len; // for 'D'+ len += sizeof(Real) + sizeof(Real); // for the position+ if ((len + m_packetLen) > MAX_PACKET_SIZE) {+ return FALSE;+ }+ return TRUE;+}+Bool NetPacket::addDisconnectScreenOffCommand(NetCommandRef *msg) {Bool needNewCommandID = FALSE;if (isRoomForDisconnectScreenOffMessage(msg)) {@@ -5108,6 +5275,9 @@ NetCommandList * NetPacket::getCommandList() {DEBUG_LOG(("read frame resend request message from player %d\n", playerID));msg = readFrameResendRequestMessage(m_packet, i);break;+ case NETCOMMANDTYPE_ALLYCURSOR:+ msg = readAllyCursorMessage(m_packet, i);+ break;}if (msg == NULL) {@@ -5834,6 +6004,25 @@ NetCommandMsg * NetPacket::readFrameResendRequestMessage(UnsignedByte *data, Intreturn msg;}+/**+ * Reads the ally cursor message at this position in the packet.+ */+NetCommandMsg * NetPacket::readAllyCursorMessage(UnsignedByte *data, Int &i) {+ NetAllyCursorCommandMsg *msg = newInstance(NetAllyCursorCommandMsg);++ Real x = 0.0f;+ memcpy(&x, data + i, sizeof(x));+ i += sizeof(x);++ Real y = 0.0f;+ memcpy(&y, data + i, sizeof(y));+ i += sizeof(y);++ msg->setPosition(x, y);++ return msg;+}+/*** Returns the number of commands in this packet. Only valid if the packet is locally constructed.*/diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cppindex 63e002bce..c60f43c59 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp@@ -128,6 +128,7 @@ public:void sendChat(UnicodeString text, Int playerMask);void sendDisconnectChat(UnicodeString text);+ void sendAllyCursor(Real x, Real y, Int playerMask);void sendFile(AsciiString path, UnsignedByte playerMask, UnsignedShort commandID);UnsignedShort sendFileAnnounce(AsciiString path, UnsignedByte playerMask);@@ -913,6 +914,13 @@ void Network::sendDisconnectChat(UnicodeString text) {m_conMgr->sendDisconnectChat(text);}+/**+ * Tells the players in the mask where the local mouse is pointing.+ */+void Network::sendAllyCursor(Real x, Real y, Int playerMask) {+ m_conMgr->sendAllyCursor(x, y, playerMask);+}+// send a file. woohoo.void Network::sendFile(AsciiString path, UnsignedByte playerMask, UnsignedShort commandID){diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetworkUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetworkUtil.cppindex 2e8e0ae8a..dc4b0ba59 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetworkUtil.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/NetworkUtil.cpp@@ -294,6 +294,8 @@ AsciiString GetAsciiNetCommandType(NetCommandType type) {s.set("NETCOMMANDTYPE_DISCONNECTSCREENOFF");} else if (type == NETCOMMANDTYPE_FRAMERESENDREQUEST) {s.set("NETCOMMANDTYPE_FRAMERESENDREQUEST");+ } else if (type == NETCOMMANDTYPE_ALLYCURSOR) {+ s.set("NETCOMMANDTYPE_ALLYCURSOR");} else {s.set("UNKNOWN");}diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.hindex 2d00b39bb..91dd48627 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h@@ -82,10 +82,16 @@ protected:virtual void drawFormationLine( void ); ///< the line a right drag is spreading the selection alongvirtual void drawOrderHints( void ); ///< a line from each selected unit to where its order sends itvirtual void drawAttackCircle( void ); ///< the circle a left drag is sweeping targets out of+ virtual void drawAllyCursorLights( void ); ///< the patch of an ally's colour lying under their cursor+ void drawAllyCursors( void ); ///< each ally's pointer and name, over the worldRenderObjClass *m_buildingPlacementAnchor;RenderObjClass *m_buildingPlacementArrow;+ /// One name plate per player, built the first time that ally's cursor is drawn and kept, because+ /// laying out the same string every frame for every ally is work nobody sees.+ DisplayString *m_allyCursorNames[ MAX_PLAYER_COUNT ];+}; // end class W3DInGameUI#endif // end __W3DINGAMEUI_H_diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cppindex 06a5c902c..0c230822b 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp@@ -2163,6 +2163,9 @@ void HeightMapRenderObjClass::Render(RenderInfoClass & rinfo)// and the wash inside an attack circle, for the same reason: the units it is sweeping up// have to stand on top of itTheInGameUI->drawAttackCircleFill();++ // and the patch of colour under each ally's cursor, which is light falling on the map+ TheInGameUI->drawAllyCursorLights();}// We do some custom blending, so tell the shader class to reset everything.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cppindex 15b7c261c..544a4dea4 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -30,6 +30,8 @@#include <stdlib.h>#include "Common/GlobalData.h"+#include "Common/Player.h"+#include "Common/PlayerList.h"#include "Common/ThingTemplate.h"#include "Common/ThingFactory.h"#include "GameLogic/AI.h"@@ -37,8 +39,11 @@#include "GameLogic/TerrainLogic.h"#include "GameLogic/GameLogic.h"#include "GameLogic/Object.h"+#include "GameClient/DisplayStringManager.h"#include "GameClient/Drawable.h"#include "GameClient/GadgetListBox.h"+#include "GameClient/GlobalLanguage.h"+#include "GameClient/PlayerColorScheme.h"#include "GameClient/GameClient.h"#include "GameClient/GameWindowManager.h"#include "GameClient/GadgetSlider.h"@@ -283,6 +288,9 @@ W3DInGameUI::W3DInGameUI()m_buildingPlacementAnchor = NULL;m_buildingPlacementArrow = NULL;+ for( Int i = 0; i < MAX_PLAYER_COUNT; ++i )+ m_allyCursorNames[ i ] = NULL;+} // end W3DInGameUI//-------------------------------------------------------------------------------------------------@@ -292,6 +300,13 @@ W3DInGameUI::~W3DInGameUI()REF_PTR_RELEASE( m_buildingPlacementAnchor );REF_PTR_RELEASE( m_buildingPlacementArrow );+ for( Int i = 0; i < MAX_PLAYER_COUNT; ++i )+ if( m_allyCursorNames[ i ] )+ {+ TheDisplayStringManager->freeDisplayString( m_allyCursorNames[ i ] );+ m_allyCursorNames[ i ] = NULL;+ }+} // end ~W3DInGameUI// loadText ===================================================================@@ -394,6 +409,9 @@ void W3DInGameUI::draw( void )// and where everything selected is headed, drag or no dragdrawOrderHints();+ // where the allies are pointing, which is the one thing on this screen somebody else is doing+ drawAllyCursors();+// the attack circle, while the left button is still sweeping it outif( isAttackCircling() )drawAttackCircle();@@ -1142,6 +1160,152 @@ void W3DInGameUI::drawOrderHints( void )} // end drawOrderHints+//-------------------------------------------------------------------------------------------------+/** A patch of the ally's own colour on the ground under their cursor. It is a fan of rings whose+ * alpha falls to nothing at the rim, drawn in the terrain pass like the attack circle's wash, so+ * units and buildings stand on top of it and it reads as light on the map rather than as a disc+ * hanging over it.+ *+ * Faint on purpose: seven of these at full strength would be seven holes in the map. */+//-------------------------------------------------------------------------------------------------+void W3DInGameUI::drawAllyCursorLights( void )+{+ if( !TheGlobalData->m_showAllyCursors )+ return;++ enum { LIGHT_SEGMENTS = 20, LIGHT_RINGS = 5 };+ const Real LIGHT_RADIUS = 55.0f; // about three tanks across, so it reads at the zoom people play at+ const Real LIGHT_LIFT = 0.35f; // the same hair off the dirt the attack circle's wash takes+ const Real LIGHT_CENTRE_ALPHA = 0x78;++ Bool stateSet = FALSE;++ for( Int playerIndex = 0; playerIndex < MAX_PLAYER_COUNT; ++playerIndex )+ {+ const Real fade = getAllyCursorFade( playerIndex );+ if( fade <= 0.0f )+ continue;++ // a cursor is only ever known for a player who was found and vouched for on the way in+ Player *player = ThePlayerList->getNthPlayer( playerIndex );++ const Coord3D& centre = getAllyCursor( playerIndex ).shown;+ const UnsignedInt rgb = (UnsignedInt)clientPlayerColor( player ) & 0x00FFFFFF;++ Vector3 ring[ LIGHT_RINGS + 1 ][ LIGHT_SEGMENTS + 1 ];+ Int r, s;+ for( r = 0; r <= LIGHT_RINGS; ++r )+ {+ const Real ringRadius = LIGHT_RADIUS * (Real)r / (Real)LIGHT_RINGS;+ for( s = 0; s <= LIGHT_SEGMENTS; ++s )+ {+ const Real angle = 2.0f * PI * (Real)s / (Real)LIGHT_SEGMENTS;+ const Real x = centre.x + ringRadius * (Real)cos( angle );+ const Real y = centre.y + ringRadius * (Real)sin( angle );+ ring[ r ][ s ].Set( x, y, TheTerrainLogic->getGroundHeight( x, y ) + LIGHT_LIFT );+ }+ }++ // the alpha of ring r, so the patch is brightest under the pointer and gone at the rim. The+ // falloff holds its strength through the middle and then drops, which is what a pool of light+ // looks like; a straight ramp reads as a flat disc with a hard edge+ UnsignedInt ringColor[ LIGHT_RINGS + 1 ];+ for( r = 0; r <= LIGHT_RINGS; ++r )+ {+ const Real across = (Real)r / (Real)LIGHT_RINGS;+ const Real remaining = 1.0f - across;+ ringColor[ r ] = overlayColor( rgb, LIGHT_CENTRE_ALPHA * fade * remaining * remaining * ( 3.0f - 2.0f * remaining ) );+ }++ // one render state for all of them, and only if there turned out to be something to draw+ if( stateSet == FALSE )+ {+ setGroundOverlayState();+ stateSet = TRUE;+ }++ GroundOverlayQuads &quads = theGroundOverlayQuads;++ // the innermost band is a fan around the centre point, two segments to a quad - running it+ // through the ring loop below would give every second triangle no area at all+ for( s = 0; s < LIGHT_SEGMENTS; s += 2 )+ {+ quads.add( ring[ 0 ][ 0 ], ring[ 1 ][ s ], ring[ 1 ][ s + 1 ], ring[ 1 ][ s + 2 ],+ ringColor[ 0 ], ringColor[ 1 ], ringColor[ 1 ], ringColor[ 1 ] );+ }++ for( r = 1; r < LIGHT_RINGS; ++r )+ {+ for( s = 0; s < LIGHT_SEGMENTS; ++s )+ {+ quads.add( ring[ r ][ s ], ring[ r + 1 ][ s ], ring[ r + 1 ][ s + 1 ], ring[ r ][ s + 1 ],+ ringColor[ r ], ringColor[ r + 1 ], ringColor[ r + 1 ], ringColor[ r ] );+ }+ }+ }++ if( stateSet )+ theGroundOverlayQuads.flush();++} // end drawAllyCursorLights++//-------------------------------------------------------------------------------------------------+/** Each ally's mouse, drawn as their name in their own colour sitting in the middle of the pool of+ * light on the ground under it. No pointer: a second arrow on screen is read as your own for the+ * half second it takes to notice it is not, and the name is the part that says whose it is.+ *+ * An ally who stops sending - alt-tabbed, or dropped - fades out rather than vanishing, which is+ * the difference between "they went away" and "the network hiccuped". */+//-------------------------------------------------------------------------------------------------+void W3DInGameUI::drawAllyCursors( void )+{+ if( !TheGlobalData->m_showAllyCursors )+ return;++ const Int NAME_POINT_SIZE = 10;++ for( Int playerIndex = 0; playerIndex < MAX_PLAYER_COUNT; ++playerIndex )+ {+ const Real fade = getAllyCursorFade( playerIndex );+ if( fade <= 0.0f )+ continue;++ // a cursor is only ever known for a player who was found and vouched for on the way in+ Player *player = ThePlayerList->getNthPlayer( playerIndex );++ // a cursor off the side of the screen still has a usable pixel; only one behind the camera+ // has not, which is the one case worldToScreenTriReturn calls invalid+ ICoord2D screen;+ if( TheTacticalView->worldToScreenTriReturn( &getAllyCursor( playerIndex ).shown, &screen ) == View::WTS_INVALID )+ continue;++ const UnsignedInt alpha = (UnsignedInt)REAL_TO_INT( 255.0f * fade );+ const UnsignedInt rgb = (UnsignedInt)clientPlayerColor( player ) & 0x00FFFFFF;+ const Color tint = (Color)( rgb | ( alpha << 24 ) );+ const Color dropColor = GameMakeColor( 0, 0, 0, (UnsignedByte)alpha );++ if( m_allyCursorNames[ playerIndex ] == NULL )+ {+ m_allyCursorNames[ playerIndex ] = TheDisplayStringManager->newDisplayString();+ m_allyCursorNames[ playerIndex ]->setFont( TheWindowManager->winFindFont(+ AsciiString( "Arial" ),+ TheGlobalLanguageData->adjustFontSize( NAME_POINT_SIZE ), TRUE ) );+ }++ // set every frame: a player who is destroyed or renamed mid-match should not keep a stale plate+ m_allyCursorNames[ playerIndex ]->setText( player->getPlayerDisplayName() );++ // centred on the reported spot in both directions, so the name sits in the middle of its own+ // pool of light and the two together are the marker+ Int nameWidth = 0, nameHeight = 0;+ m_allyCursorNames[ playerIndex ]->getSize( &nameWidth, &nameHeight );+ m_allyCursorNames[ playerIndex ]->draw( screen.x - nameWidth / 2,+ screen.y - nameHeight / 2,+ tint, dropColor );+ }++} // end drawAllyCursors+//-------------------------------------------------------------------------------------------------/** Draw visual back for clicking to attack a unit in the world *///-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 251e87011..2e4e5b0d7 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -4962,6 +4962,61 @@ TEST(an_overlong_chat_line_keeps_its_length_instead_of_wrapping_to_a_short_one)ref->deleteInstance();}+/* An ally cursor is two floats on a command of its own, and the packet writer and the packet+ reader are two separate hand-written walks over the same bytes - a field added to one and not+ the other reads the next command's header as position data. So the round trip is pinned: what+ goes in comes out, on the right slot, as the right command type. */+TEST(an_ally_cursor_survives_the_round_trip_through_a_packet)+{+ const Real sentX = 1234.5f;+ const Real sentY = -678.25f;++ NetAllyCursorCommandMsg *cursor = newInstance( NetAllyCursorCommandMsg );+ cursor->setPosition( sentX, sentY );+ cursor->setPlayerID( 3 );+ cursor->setID( 0 );+ cursor->setExecutionFrame( 0 );++ NetCommandRef *ref = newInstance( NetCommandRef )( cursor );+ ref->setRelay( 0x0F );+ cursor->detach(); // the ref holds it now++ NetPacket *packet = newInstance( NetPacket );+ packet->init();+ CHECK( packet->addCommand( ref ) );+ CHECK_EQ( packet->getNumCommands(), 1 );++ NetCommandList *list = packet->getCommandList();+ NetCommandRef *read = list->getFirstMessage();+ CHECK( read != NULL );+ if( read )+ {+ NetCommandMsg *msg = read->getCommand();+ CHECK_EQ( (Int)msg->getNetCommandType(), (Int)NETCOMMANDTYPE_ALLYCURSOR );+ CHECK_EQ( (Int)msg->getPlayerID(), 3 );+ CHECK_EQ( ((NetAllyCursorCommandMsg *)msg)->getX(), sentX );+ CHECK_EQ( ((NetAllyCursorCommandMsg *)msg)->getY(), sentY );+ }++ list->deleteInstance();+ packet->deleteInstance();+ ref->deleteInstance();+}++/* Nothing about an ally cursor may reach the simulation: it is not acked, not resent, not held for+ a frame and not written to a replay. The three predicates the network layer sorts commands by+ are where that is decided, so they are the thing to pin. */+TEST(an_ally_cursor_is_never_acked_resent_or_frame_synchronised)+{+ NetAllyCursorCommandMsg *cursor = newInstance( NetAllyCursorCommandMsg );++ CHECK( !DoesCommandRequireACommandID( NETCOMMANDTYPE_ALLYCURSOR ) );+ CHECK( !IsCommandSynchronized( NETCOMMANDTYPE_ALLYCURSOR ) );+ CHECK( !CommandRequiresAck( cursor ) );++ cursor->detach(); // the constructor's own reference is the only one+}+/* addCommand's own guard against a null reference sat below the line that followed it, so the onecall it exists to survive was the one call that crashed. */TEST(adding_a_null_command_to_a_packet_is_refused_not_followed)