From: <sv...@ww...> - 2005-05-01 15:52:41
|
Author: mkrose Date: 2005-05-01 08:52:35 -0700 (Sun, 01 May 2005) New Revision: 1539 Modified: trunk/CSP/SimCore/Battlefield/GlobalBattlefield.h Log: Fix global battlefield so that it doesn't send add/remove unit messages to the client that owns the unit. This issue arises when a client has multiple local units. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1539 Modified: trunk/CSP/SimCore/Battlefield/GlobalBattlefield.h =================================================================== --- trunk/CSP/SimCore/Battlefield/GlobalBattlefield.h 2005-05-01 15:43:07 UTC (rev 1538) +++ trunk/CSP/SimCore/Battlefield/GlobalBattlefield.h 2005-05-01 15:52:35 UTC (rev 1539) @@ -465,23 +465,28 @@ ContactWrapper *cfrom = static_cast<ContactWrapper*>(from); CSP_LOG(BATTLEFIELD, DEBUG, "INCREMENT: " << *(from->unit()) << " -> " << *(to->unit())); if (cfrom->incrementCount(to->owner())) { - CSP_LOG(BATTLEFIELD, INFO, "sending add unit " << from->unit()->id() << " to client " << to->owner()); - { // tell OWNER[to] to expect updates from OWNER[from] - CommandAddUnit::Ref msg = new CommandAddUnit(); - msg->set_unit_id(from->id()); - msg->set_unit_class(simdata::Path(from->unit()->getObjectPath())); - msg->set_unit_type(static_cast<const simdata::uint8>(from->unit()->type())); - msg->set_owner_id(from->owner()); - msg->set_grid_x(from->point().x()); - msg->set_grid_y(from->point().y()); - sendClientCommand(msg, to->owner()); + // if the units are owned by the same client we still reference count + // but we don't send an update. both units will already be present in + // the client's local battlefield. + if (from->owner() != to->owner()) { + CSP_LOG(BATTLEFIELD, INFO, "sending add unit " << from->unit()->id() << " to client " << to->owner()); + { // tell OWNER[to] to expect updates from OWNER[from] + CommandAddUnit::Ref msg = new CommandAddUnit(); + msg->set_unit_id(from->id()); + msg->set_unit_class(simdata::Path(from->unit()->getObjectPath())); + msg->set_unit_type(static_cast<const simdata::uint8>(from->unit()->type())); + msg->set_owner_id(from->owner()); + msg->set_grid_x(from->point().x()); + msg->set_grid_y(from->point().y()); + sendClientCommand(msg, to->owner()); + } + { // tell OWNER[from] to update OWNER[to] + CommandUpdatePeer::Ref msg = new CommandUpdatePeer(); + msg->set_unit_id(from->id()); + msg->set_peer_id(to->owner()); + sendClientCommand(msg, from->owner()); + } } - { // tell OWNER[from] to update OWNER[to] - CommandUpdatePeer::Ref msg = new CommandUpdatePeer(); - msg->set_unit_id(from->id()); - msg->set_peer_id(to->owner()); - sendClientCommand(msg, from->owner()); - } } } @@ -489,19 +494,24 @@ ContactWrapper *cfrom = static_cast<ContactWrapper*>(from); CSP_LOG(BATTLEFIELD, DEBUG, "DECREMENT: " << *(from->unit()) << " -> " << *(to->unit())); if (cfrom->decrementCount(to->owner())) { - CSP_LOG(BATTLEFIELD, INFO, "sending remove unit " << from->unit()->id() << " to client " << to->owner()); - { - CommandRemoveUnit::Ref msg = new CommandRemoveUnit(); - msg->set_unit_id(from->id()); - sendClientCommand(msg, to->owner()); + // if the units are owned by the same client we still reference count + // but we don't send an update. removal and notification of local units + // has already been done in the client's battlefield. + if (from->owner() != to->owner()) { + CSP_LOG(BATTLEFIELD, INFO, "sending remove unit " << from->unit()->id() << " to client " << to->owner()); + { + CommandRemoveUnit::Ref msg = new CommandRemoveUnit(); + msg->set_unit_id(from->id()); + sendClientCommand(msg, to->owner()); + } + { + CommandUpdatePeer::Ref msg = new CommandUpdatePeer(); + msg->set_unit_id(from->id()); + msg->set_peer_id(to->owner()); + msg->set_stop(true); + sendClientCommand(msg, from->owner()); + } } - { - CommandUpdatePeer::Ref msg = new CommandUpdatePeer(); - msg->set_unit_id(from->id()); - msg->set_peer_id(to->owner()); - msg->set_stop(true); - sendClientCommand(msg, from->owner()); - } } } |