Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ WindowMsgHandledType BeaconWindowInput( GameWindow *window, UnsignedInt msg,
{
if (msg == GWM_CHAR && mData1 == KEY_ESC)
{
TheInGameUI->deselectAllDrawables(TRUE); // there should only be one beacon and nothing else selected
TheInGameUI->deselectAllDrawables(); // there should only be one beacon and nothing else selected
return MSG_HANDLED;
}

Expand Down
19 changes: 10 additions & 9 deletions Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2590,9 +2590,8 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
// create a new group.
GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );

//New group or add to group? Passed in value is true if we are creating a new group.
//New group so pass in value true
teamMsg->appendBooleanArgument( TRUE );

teamMsg->appendObjectIDArgument( newDrawable->getObject()->getID() );

// select the unit
Expand Down Expand Up @@ -2702,16 +2701,15 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
{
//deselect other units
TheInGameUI->deselectAllDrawables();
// select the unit

// create a new group.
GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );

//New group or add to group? Passed in value is true if we are creating a new group.
//New group so pass in value true
teamMsg->appendBooleanArgument( TRUE );

teamMsg->appendObjectIDArgument( newDrawable->getObject()->getID() );

// select the unit
TheInGameUI->selectDrawable( newDrawable );

// center on the unit
Expand Down Expand Up @@ -2816,13 +2814,14 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
//deselect other units
TheInGameUI->deselectAllDrawables();

// select the unit
// create a new group.
GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );

//New group so pass in value true
teamMsg->appendBooleanArgument( TRUE );
teamMsg->appendObjectIDArgument( newDrawable->getObject()->getID() );

// select the unit
TheInGameUI->selectDrawable( newDrawable );

// center on the unit
Expand Down Expand Up @@ -2930,16 +2929,15 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
{
//deselect other units
TheInGameUI->deselectAllDrawables();
// select the unit

// create a new group.
GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );

//New group so passed in value true
//New group so pass in value true
teamMsg->appendBooleanArgument( TRUE );

teamMsg->appendObjectIDArgument( newDrawable->getObject()->getID() );

// select the unit
TheInGameUI->selectDrawable( newDrawable );

// center on the unit
Expand Down Expand Up @@ -2982,6 +2980,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
if ( heroDraw == nullptr )
break;

//deselect other units
TheInGameUI->deselectAllDrawables();

// create a new group.
Expand All @@ -2990,6 +2989,8 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
//New group so pass in value true
teamMsg->appendBooleanArgument( TRUE );
teamMsg->appendObjectIDArgument( hero->getID() );

// select the unit
TheInGameUI->selectDrawable( heroDraw );

// center on the unit
Expand Down
32 changes: 10 additions & 22 deletions Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,6 @@ static Bool canSelectWrapper( Drawable *draw, void *userData )
return CanSelectDrawable( draw, dragSelecting );
}

//-----------------------------------------------------------------------------
/**
* Deselect all drawables, and emit a "TEAM_DESTROY" message, since
* the "team" was the group of currently selected units.
*/
static void deselectAll()
{

// deselect it all
TheInGameUI->deselectAllDrawables();
}

//-----------------------------------------------------------------------------
/**
* Select the given drawable, without playing its sound.
Expand All @@ -230,14 +218,14 @@ static void deselectAll()
static Bool selectSingleDrawableWithoutSound( Drawable *draw )
{

// since we are single selecting a drawable, unselect everything else
deselectAll();

// do the drawable selection
TheInGameUI->selectDrawable( draw );

Object *obj = draw->getObject();
if (obj != nullptr) {
// since we are single selecting a drawable, unselect everything else
TheInGameUI->deselectAllDrawables();

// do the drawable selection
TheInGameUI->selectDrawable(draw);

GameMessage *msg = TheMessageStream->appendMessage(GameMessage::MSG_CREATE_SELECTED_GROUP_NO_SOUND);
msg->appendBooleanArgument(TRUE);
msg->appendObjectIDArgument(obj->getID());
Expand Down Expand Up @@ -893,7 +881,7 @@ GameMessageDisposition SelectionTranslator::onMouseLeftClick(MAYBE_UNUSED const
{
if (!addToGroup)
{
deselectAll();
TheInGameUI->deselectAllDrawables();
}

GameMessage *newMsg = TheMessageStream->appendMessage(GameMessage::MSG_CREATE_SELECTED_GROUP);
Expand Down Expand Up @@ -1063,7 +1051,7 @@ GameMessageDisposition SelectionTranslator::onRawMouseLeftButtonUp(MAYBE_UNUSED
{
if( !TheInGameUI->getPreventLeftClickDeselectionInAlternateMouseModeForOneClick() )
{
deselectAll();
TheInGameUI->deselectAllDrawables();
m_lastGroupSelGroup = -1;
}
else
Expand Down Expand Up @@ -1127,7 +1115,7 @@ GameMessageDisposition SelectionTranslator::onRawMouseRightButtonUp(MAYBE_UNUSED
else if (!TheGlobalData->m_useAlternateMouse)
{
//No GUI command mode, so deselect everyone if we're in regular mouse mode.
deselectAll();
TheInGameUI->deselectAllDrawables();
}
}
}
Expand Down Expand Up @@ -1200,7 +1188,7 @@ GameMessageDisposition SelectionTranslator::onMetaSelectTeam(MAYBE_UNUSED const

if ( performSelection )
{
TheInGameUI->deselectAllDrawables( false ); //No need to post message because we're just creating a new group!
TheInGameUI->deselectAllDrawables();

// no need to send two messages for selecting the same group.
TheMessageStream->appendMessage((GameMessage::Type)(GameMessage::MSG_SELECT_TEAM0 + group));
Expand Down
8 changes: 6 additions & 2 deletions Generals/Code/GameEngine/Include/Common/MessageStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,10 @@ class GameMessage : public MemoryPoolObject

GameMessage( Type type );

GameMessage *next() { return m_next; } ///< Return next message in the stream
GameMessage *prev() { return m_prev; } ///< Return prev message in the stream
GameMessage *next() { return m_next; } ///< Return next message in the stream
const GameMessage *next() const { return m_next; } ///< Return next message in the stream
GameMessage *prev() { return m_prev; } ///< Return prev message in the stream
const GameMessage *prev() const { return m_prev; } ///< Return prev message in the stream

Type getType() const { return m_type; } ///< Return the message type

Expand Down Expand Up @@ -768,6 +770,8 @@ class MessageStream : public GameMessageList

protected:

Bool isRedundantMessage(const GameMessage *msg) const;

struct TranslatorData
{
TranslatorData *m_next, *m_prev; ///< List links for list of translators
Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Include/GameClient/InGameUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ friend class Drawable; // for selection/deselection transactions
// Drawable selection mechanisms
virtual void selectDrawable( Drawable *draw ); ///< Mark given Drawable as "selected"
virtual void deselectDrawable( Drawable *draw ); ///< Clear "selected" status from Drawable
virtual void deselectAllDrawables( Bool postMsg = true ); ///< Clear the "select" flag from all drawables
virtual void deselectAllDrawables(); ///< Clear the "select" flag from all drawables
virtual Int getSelectCount() { return m_selectCount; } ///< Get count of currently selected drawables
virtual Int getMaxSelectCount() { return m_maxSelectCount; } ///< Get the max number of selected drawables
virtual UnsignedInt getFrameSelectionChanged() { return m_frameSelectionChanged; } ///< Get the max number of selected drawables
Expand Down
62 changes: 56 additions & 6 deletions Generals/Code/GameEngine/Source/Common/MessageStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ void MessageStream::removeTranslator( TranslatorID id )
// ------------------------------------------------------------------------------------------------
#if defined(RTS_DEBUG)

Bool isInvalidDebugCommand( GameMessage::Type t )
static Bool isInvalidDebugCommand( GameMessage::Type t )
{
// see if this is something that should be prevented in multiplayer games
// Don't reject this stuff in skirmish games.
Expand Down Expand Up @@ -1081,23 +1081,32 @@ void MessageStream::propagateMessages()
{
for( msg=m_firstMessage; msg; msg=next )
{
// TheSuperHackers @tweak Delete messages that we know are redundant. This can reduce network traffic.
// @info If there is a need to look back on previous messages, then first invalidate the messages in this loop
// before deleting them later.
if (isRedundantMessage(msg))
{
next = msg->next();
deleteInstance(msg);
continue;
}

if (ss->m_translator
#if defined(RTS_DEBUG)
&& !isInvalidDebugCommand(msg->getType())
#endif
)
{
GameMessageDisposition disp = ss->m_translator->translateGameMessage(msg);
next = msg->next();
if (disp == DESTROY_MESSAGE)
{
next = msg->next();
deleteInstance(msg);
continue;
}
}
else
{
next = msg->next();
}

next = msg->next();
}
}

Expand All @@ -1111,6 +1120,47 @@ void MessageStream::propagateMessages()

}

Bool MessageStream::isRedundantMessage(const GameMessage *msg) const
{
switch (msg->getType())
{
case GameMessage::MSG_DESTROY_SELECTED_GROUP:
{
const GameMessage* msgNext = msg->next();
if (!msgNext)
break;

switch (msgNext->getType())
{
case GameMessage::MSG_CREATE_SELECTED_GROUP:
case GameMessage::MSG_CREATE_SELECTED_GROUP_NO_SOUND:
if (msgNext->getArgumentCount() >= 1)
{
const Bool newGroup = msgNext->getArgument(0)->boolean;
if (newGroup)
return true;
}
break;
case GameMessage::MSG_DESTROY_SELECTED_GROUP:
return true;
case GameMessage::MSG_SELECT_TEAM0:
case GameMessage::MSG_SELECT_TEAM1:
case GameMessage::MSG_SELECT_TEAM2:
case GameMessage::MSG_SELECT_TEAM3:
case GameMessage::MSG_SELECT_TEAM4:
case GameMessage::MSG_SELECT_TEAM5:
case GameMessage::MSG_SELECT_TEAM6:
case GameMessage::MSG_SELECT_TEAM7:
case GameMessage::MSG_SELECT_TEAM8:
case GameMessage::MSG_SELECT_TEAM9:
return true;
}
break;
}
}

return false;
}

//------------------------------------------------------------------------------------------------
// CommandList
Expand Down
14 changes: 5 additions & 9 deletions Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3512,9 +3512,10 @@ void InGameUI::deselectDrawable( Drawable *draw )
//-------------------------------------------------------------------------------------------------
/** Clear all drawables' "select" status */
//-------------------------------------------------------------------------------------------------
void InGameUI::deselectAllDrawables( Bool postMsg )
void InGameUI::deselectAllDrawables()
{
const DrawableList *selected = getAllSelectedDrawables();
const Bool hadSelectedDrawables = !selected->empty();

// loop through all the selected drawables
for ( DrawableListCIt it = selected->begin(); it != selected->end(); )
Expand All @@ -3535,16 +3536,11 @@ void InGameUI::deselectAllDrawables( Bool postMsg )
// our selection can no longer consist of exactly one angry mob
m_soloNexusSelectedDrawableID = INVALID_DRAWABLE_ID;


///@todo don't we want to not emit this message if there wasn't a group at all? (CBD)
/** @todo also, we probably are sending this message too much, we should come up with
some kind of "selections are dirty" status that we can check once per frame and send
the correct group info over the network ... could be tricky tho (or impossible) given
the order of operations of things happening in the code (CBD) */
if( postMsg )
// TheSuperHackers @tweak Only send this message when objects were previously selected.
if (hadSelectedDrawables)
{
// TheSuperHackers @tweak Originally this message had one boolean argument, but it wasn't used for anything.
TheMessageStream->appendMessage( GameMessage::MSG_DESTROY_SELECTED_GROUP );
TheMessageStream->appendMessage(GameMessage::MSG_DESTROY_SELECTED_GROUP);
}
}

Expand Down
8 changes: 6 additions & 2 deletions GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,10 @@ class GameMessage : public MemoryPoolObject

GameMessage( Type type );

GameMessage *next() { return m_next; } ///< Return next message in the stream
GameMessage *prev() { return m_prev; } ///< Return prev message in the stream
GameMessage *next() { return m_next; } ///< Return next message in the stream
const GameMessage *next() const { return m_next; } ///< Return next message in the stream
GameMessage *prev() { return m_prev; } ///< Return prev message in the stream
const GameMessage *prev() const { return m_prev; } ///< Return prev message in the stream

Type getType() const { return m_type; } ///< Return the message type

Expand Down Expand Up @@ -768,6 +770,8 @@ class MessageStream : public GameMessageList

protected:

Bool isRedundantMessage(const GameMessage *msg) const;

struct TranslatorData
{
TranslatorData *m_next, *m_prev; ///< List links for list of translators
Expand Down
2 changes: 1 addition & 1 deletion GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ friend class Drawable; // for selection/deselection transactions
// Drawable selection mechanisms
virtual void selectDrawable( Drawable *draw ); ///< Mark given Drawable as "selected"
virtual void deselectDrawable( Drawable *draw ); ///< Clear "selected" status from Drawable
virtual void deselectAllDrawables( Bool postMsg = true ); ///< Clear the "select" flag from all drawables
virtual void deselectAllDrawables(); ///< Clear the "select" flag from all drawables
virtual Int getSelectCount() { return m_selectCount; } ///< Get count of currently selected drawables
virtual Int getMaxSelectCount() { return m_maxSelectCount; } ///< Get the max number of selected drawables
virtual UnsignedInt getFrameSelectionChanged() { return m_frameSelectionChanged; } ///< Get the max number of selected drawables
Expand Down
Loading
Loading