1
0
forked from 0ad/0ad

Modified semantics of HEntity's validity check to count handles to units that are destroyed but not deleted as still valid handles. This fixes some previous code that assumed these semantics, such as code for dealing with exhausted gather targets. It looks like the meaning was changed long ago when the entity flags were added. Also added an IsAlive method in HEntity for the old check, in case any code needs to be switched over to that.

Also removed some debug output from entity_functions.js.

This was SVN commit r5074.
This commit is contained in:
Matei 2007-05-16 06:58:49 +00:00
parent dcf253714f
commit 2e5c530c03
3 changed files with 25 additions and 20 deletions

View File

@ -1963,7 +1963,6 @@ function InfidelityAura( source, time )
{ {
if( this.count[i] > 0 ) if( this.count[i] > 0 )
{ {
console.write( "Starting convert timer" );
this.convertTimer = setTimeout( this.convert, parseInt( this.time * 1000 ), this ); this.convertTimer = setTimeout( this.convert, parseInt( this.time * 1000 ), this );
return; return;
} }
@ -1974,7 +1973,6 @@ function InfidelityAura( source, time )
// If we had started a convert timer before, cancel it (either we have units from our owner in range, or there are no units from anyone in range) // If we had started a convert timer before, cancel it (either we have units from our owner in range, or there are no units from anyone in range)
if( this.convertTimer ) if( this.convertTimer )
{ {
console.write( "Cancelling convert timer" );
cancelTimer( this.convertTimer ); cancelTimer( this.convertTimer );
this.convertTimer = 0; this.convertTimer = 0;
} }
@ -1982,8 +1980,6 @@ function InfidelityAura( source, time )
this.convert = function() this.convert = function()
{ {
console.write( "Conversion time!" );
// Switch ownership to whichever non-gaia player has the most units near us // Switch ownership to whichever non-gaia player has the most units near us
bestPlayer = 0; bestPlayer = 0;
bestCount = 0; bestCount = 0;

View File

@ -47,22 +47,19 @@ bool HEntity::operator ==( const HEntity& test ) const
return( m_handle == test.m_handle ); return( m_handle == test.m_handle );
} }
HEntity::operator bool() const bool HEntity::IsValid() const
{ {
if( m_handle == INVALID_HANDLE ) if( m_handle == INVALID_HANDLE )
return( false ); return( false );
debug_assert( g_EntityManager.m_entities[m_handle].m_refcount ); debug_assert( g_EntityManager.m_entities[m_handle].m_refcount );
return( !g_EntityManager.m_entities[m_handle].m_entity->entf_get(ENTF_DESTROYED) ); //return( !g_EntityManager.m_entities[m_handle].m_entity->entf_get(ENTF_DESTROYED) );
return( true );
} }
bool HEntity::operator!() const bool HEntity::IsAlive() const
{ {
if( m_handle == INVALID_HANDLE ) return( IsValid() && !g_EntityManager.m_entities[m_handle].m_entity->entf_get(ENTF_DESTROYED) );
return( true );
debug_assert( g_EntityManager.m_entities[m_handle].m_refcount );
return( g_EntityManager.m_entities[m_handle].m_entity->entf_get(ENTF_DESTROYED) );
} }
void HEntity::AddRef() void HEntity::AddRef()

View File

@ -50,19 +50,31 @@ private:
void DecRef(); void DecRef();
HEntity( u16 index ); HEntity( u16 index );
public: public:
CEntity& operator*() const;
CEntity* operator->() const;
HEntity(); HEntity();
HEntity( const HEntity& copy ); HEntity( const HEntity& copy );
~HEntity();
void operator=( const HEntity& copy ); void operator=( const HEntity& copy );
CEntity& operator*() const;
CEntity* operator->() const;
bool operator==( const HEntity& test ) const; bool operator==( const HEntity& test ) const;
bool operator!=( const HEntity& test ) const { return( !operator==( test ) ); } bool operator!=( const HEntity& test ) const { return( !operator==( test ) ); }
operator bool() const;
bool operator!() const;
operator CEntity*() const; operator CEntity*() const;
// Visual C++ 2003 can't handle (bool && HEntity) expressions, so provide another alias for operator bool()
bool IsValid() const {return this->operator bool();} // Returns true iff we are a valid handle, i.e. one to a non-deleted (but possibly destroyed) entity
~HEntity(); bool IsValid() const;
// Returns true iff we are a valid handle to an entity that is not destroyed
bool IsAlive() const;
// Same as IsValid(); maybe this should be removed altogether to prevent confusion?
operator bool() const { return IsValid(); }
// Same as !IsValid()
bool operator!() const { return !IsValid(); };
uint GetSerializedLength() const; uint GetSerializedLength() const;
u8 *Serialize(u8 *buffer) const; u8 *Serialize(u8 *buffer) const;