1
0
forked from 0ad/0ad

Fixing some multiplayer issues:

a) Run commands were not being sent accross properly because the JS just
directly set flags on the entity. Note: The current fix has the
side-effect of making it no longer possible to double-rightclick a
target to charge, run-gather, etc. That will be fixed in a later commit.
b) EntityLists were serialized in a format that made it impossible to
deserialize a zero-length list.

This was SVN commit r6221.
This commit is contained in:
Matei 2008-07-13 05:56:27 +00:00
parent 1e64089cdb
commit d5fedc7c76
5 changed files with 22 additions and 55 deletions

View File

@ -25,12 +25,17 @@ function worldClickHandler(event)
// Right button single- or double-clicks
if (event.button == SDL_BUTTON_RIGHT && event.clicks <= 2)
{
if (event.clicks == 1)
if (event.clicks == 1) {
cmd = event.order;
}
else if (event.clicks == 2)
{
//console.write("Issuing secondary order");
cmd = event.secondaryOrder;
// Use the secondary order, or, if the entites didn't vote for any order
// (i.e. we are using the default of NMT_GOTO), use the NMT_RUN
if (event.order == NMT_GOTO )
cmd = NMT_RUN;
else
cmd = event.secondaryOrder;
}
}
else
@ -53,9 +58,7 @@ function worldClickHandler(event)
case NMT_RUN:
case NMT_PATROL:
if (event.queued)
{
cmd = NMT_ADD_WAYPOINT;
}
args[0]=event.x;
args[1]=event.y;
break;
@ -106,11 +109,6 @@ function worldClickHandler(event)
return;
}
if (event.clicks == 2)
triggerSelectionRun();
else
setSelectionRun();
issueCommand (selection, isOrderQueued(), cmd, args[0], args[1]);
}
@ -188,37 +186,6 @@ function makeUnit (x, y, z, MakeUnitName)
// ====================================================================
function selected()
{
// Returns how many units selected.
if( selection.length > 0 )
return( selection[0] );
return( null );
}
// ====================================================================
function triggerSelectionRun()
{
for ( i=0; i< selection.length; i++ )
{
selection[i].triggerRun();
}
}
// ====================================================================
function setSelectionRun()
{
for ( i=0; i< selection.length; i++ )
{
selection[i].setRun( false );
}
}
// ====================================================================
function validProperty (propertyName)
{
// Accepts a string representing an entity property (eg "selection[0].traits.id.generic")

View File

@ -554,6 +554,10 @@ void CEntity::UpdateOrders( int timestep )
return;
case CEntityOrder::ORDER_GOTO:
case CEntityOrder::ORDER_RUN:
// Choose to run only if type == ORDER_RUN
entf_set_to(ENTF_TRIGGER_RUN, current->m_type == CEntityOrder::ORDER_RUN);
if( !entf_get(ENTF_TRIGGER_RUN) )
entf_set_to(ENTF_SHOULD_RUN, false);
if( ProcessGoto( current, timestep ) )
break;
UpdateCollisionPatch();

View File

@ -135,24 +135,26 @@ HEntity::operator CStr() const
size_t CEntityList::GetSerializedLength() const
{
return (size_t)(2*size());
return (size_t)(2*(size()+1));
}
u8 *CEntityList::Serialize(u8 *buffer) const
{
for (size_t i=0;i<(size()-1);i++)
Serialize_int_2(buffer, size());
for (size_t i=0; i<size(); i++)
Serialize_int_2(buffer, at(i).m_handle);
Serialize_int_2(buffer, back().m_handle | HANDLE_SENTINEL_BIT);
return buffer;
}
const u8 *CEntityList::Deserialize(const u8* buffer, const u8* UNUSED(end))
{
u16 n=0, handle;
while (!(n & HANDLE_SENTINEL_BIT))
const int MAX_SIZE = 500; // TODO: Don't allow selecting more than this many entities
u16 size, handle;
Deserialize_int_2(buffer, size);
debug_assert(size > 0 && size < MAX_SIZE && "Inalid size when deserializing CEntityList");
for (int i=0; i<size; i++)
{
Deserialize_int_2(buffer, n);
handle = n & ~HANDLE_SENTINEL_BIT;
Deserialize_int_2(buffer, handle);
// We have to validate the data, or the HEntity constructor will debug_assert
// on us.
// FIXME We should also check that the entity actually exists

View File

@ -19,12 +19,6 @@
#define INCLUDED_ENTITYHANDLES
#define INVALID_HANDLE 65535
// The maximum numerical value of an entity handle sent over the network
#define MAX_HANDLE 0x7fff
// If (handle & PS_ENTITY_SENTINEL_BIT) is non-zero, this is a terminating
// entity id. Reset the sentinel bit to get the original handle.
#define HANDLE_SENTINEL_BIT 0x8000
class CEntity;
class CEntityManager;

View File

@ -31,7 +31,7 @@ class CStr8;
class CVector3D;
const size_t MAX_HANDLES = 16384;
cassert(MAX_HANDLES <= MAX_HANDLE+1);
cassert(MAX_HANDLES < 0x10000);
// collision patch size, in graphics units, not tiles (1 tile = 4 units)
#define COLLISION_PATCH_SIZE 8