mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-10-14 07:17:44 +00:00
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of mostly equivalent types we had in use (int, uint, unsigned, unsigned int, i32, u32, ulong, uintN). it is more efficient to use 64-bit types in 64-bit mode, so the preferred default is size_t (for anything remotely resembling a size or index). tile coordinates are ssize_t to allow more efficient conversion to/from floating point. flags are int because we almost never need more than 15 distinct bits, bit test/set is not slower and int is fastest to type. finally, some data that is pretty much directly passed to OpenGL is now typed accordingly. after several hours, the code now requires fewer casts and less guesswork. other changes: - unit and player IDs now have an "invalid id" constant in the respective class to avoid casting and -1 - fix some endian/64-bit bugs in the map (un)packing. added a convenience function to write/read a size_t. - ia32: change CPUID interface to allow passing in ecx (required for cache topology detection, which I need at work). remove some unneeded functions from asm, replace with intrinsics where possible. This was SVN commit r5942.
This commit is contained in:
@@ -24,23 +24,23 @@ CEntityFormation::CEntityFormation( CFormation*& base, size_t index )
|
||||
m_duplication=false;
|
||||
m_entities.resize(m_base->m_numSlots);
|
||||
|
||||
m_index = (int)index;
|
||||
m_index = index;
|
||||
}
|
||||
|
||||
CEntityFormation::~CEntityFormation()
|
||||
{
|
||||
for ( int i=0; i<m_base->m_numSlots; ++i )
|
||||
for ( size_t i=0; i<m_base->m_numSlots; ++i )
|
||||
{
|
||||
if ( m_entities[i] )
|
||||
{
|
||||
m_entities[i]->m_formation = -1;
|
||||
m_entities[i]->m_formationSlot = -1;
|
||||
m_entities[i]->m_formationSlot = (size_t)-1;
|
||||
m_entities[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CEntityFormation::GetSlotCount()
|
||||
size_t CEntityFormation::GetSlotCount()
|
||||
{
|
||||
return m_base->m_numSlots;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ void CEntityFormation::SwitchBase( CFormation*& base )
|
||||
{
|
||||
std::vector<CEntity*> copy;
|
||||
copy.resize( m_base->m_numSlots );
|
||||
for ( int i=0; i < m_base->m_numSlots; ++i )
|
||||
for ( size_t i=0; i < m_base->m_numSlots; ++i )
|
||||
{
|
||||
if ( !m_entities[i] )
|
||||
continue;
|
||||
@@ -68,7 +68,7 @@ bool CEntityFormation::AddUnit( CEntity* entity )
|
||||
{
|
||||
debug_assert( entity );
|
||||
//Add the unit to the most appropriate slot
|
||||
for (int i=0; i<m_base->m_numSlots; ++i)
|
||||
for (size_t i=0; i<m_base->m_numSlots; ++i)
|
||||
{
|
||||
if ( IsBetterUnit( i, entity ) )
|
||||
{
|
||||
@@ -82,8 +82,8 @@ bool CEntityFormation::AddUnit( CEntity* entity )
|
||||
|
||||
m_entities[i] = entity;
|
||||
++m_numEntities;
|
||||
entity->m_formation = m_index;
|
||||
entity->m_formationSlot = i;
|
||||
entity->m_formation = (ssize_t)m_index;
|
||||
entity->m_formationSlot = (ssize_t)i;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -98,13 +98,13 @@ void CEntityFormation::RemoveUnit( CEntity* entity )
|
||||
|
||||
m_entities[entity->m_formationSlot] = NULL;
|
||||
entity->m_formation = -1;
|
||||
entity->m_formationSlot = -1;
|
||||
entity->m_formationSlot = (size_t)-1;
|
||||
|
||||
--m_numEntities;
|
||||
//UpdateFormation();
|
||||
}
|
||||
|
||||
bool CEntityFormation::IsSlotAppropriate( int order, CEntity* entity )
|
||||
bool CEntityFormation::IsSlotAppropriate( size_t order, CEntity* entity )
|
||||
{
|
||||
debug_assert( entity );
|
||||
if ( !IsValidOrder(order) )
|
||||
@@ -119,7 +119,7 @@ bool CEntityFormation::IsSlotAppropriate( int order, CEntity* entity )
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CEntityFormation::IsBetterUnit( int order, CEntity* entity )
|
||||
bool CEntityFormation::IsBetterUnit( size_t order, CEntity* entity )
|
||||
{
|
||||
if ( !( IsValidOrder(order) && entity ) )
|
||||
return false;
|
||||
@@ -147,13 +147,13 @@ bool CEntityFormation::IsBetterUnit( int order, CEntity* entity )
|
||||
void CEntityFormation::UpdateFormation()
|
||||
{
|
||||
//Get the entities in the right order (as in, ordered correctly and in the right order/slot)
|
||||
for ( int i=1; i<m_base->m_numSlots; ++i )
|
||||
for ( size_t i=1; i<m_base->m_numSlots; ++i )
|
||||
{
|
||||
if ( !m_entities[i] )
|
||||
continue;
|
||||
|
||||
//Go through slots with higher order
|
||||
for ( int j=i-1; j > 0; --j )
|
||||
for ( size_t j=i-1; j != 0; --j )
|
||||
{
|
||||
if ( IsBetterUnit( j, m_entities[i] ) )
|
||||
{
|
||||
@@ -161,7 +161,7 @@ void CEntityFormation::UpdateFormation()
|
||||
m_entities[j] = m_entities[i];
|
||||
m_entities[i] = temp;
|
||||
|
||||
int tmpSlot = m_entities[i]->m_formationSlot;
|
||||
ssize_t tmpSlot = m_entities[i]->m_formationSlot;
|
||||
m_entities[i]->m_formationSlot = m_entities[j]->m_formationSlot;
|
||||
m_entities[j]->m_formationSlot = tmpSlot;
|
||||
--i;
|
||||
@@ -176,7 +176,7 @@ void CEntityFormation::UpdateFormation()
|
||||
|
||||
void CEntityFormation::ResetAllEntities()
|
||||
{
|
||||
for ( int i=0; i<m_base->m_numSlots; ++i )
|
||||
for ( size_t i=0; i<m_base->m_numSlots; ++i )
|
||||
m_entities[i] = NULL;
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ void CEntityFormation::ResetAngleDivs()
|
||||
|
||||
void CEntityFormation::SelectAllUnits()
|
||||
{
|
||||
for ( int i=0; i<m_base->m_numSlots; ++i )
|
||||
for ( size_t i=0; i<m_base->m_numSlots; ++i )
|
||||
{
|
||||
if ( m_entities[i] && !g_Selection.IsSelected(m_entities[i]->me) )
|
||||
g_Selection.AddSelection( m_entities[i]->me );
|
||||
@@ -198,7 +198,7 @@ void CEntityFormation::SelectAllUnits()
|
||||
CEntityList CEntityFormation::GetEntityList()
|
||||
{
|
||||
CEntityList ret;
|
||||
for ( int i=0; i<m_base->m_numSlots; i++ )
|
||||
for ( size_t i=0; i<m_base->m_numSlots; i++ )
|
||||
{
|
||||
if ( m_entities[i] )
|
||||
ret.push_back( m_entities[i]->me);
|
||||
@@ -206,7 +206,7 @@ CEntityList CEntityFormation::GetEntityList()
|
||||
return ret;
|
||||
}
|
||||
|
||||
CVector2D CEntityFormation::GetSlotPosition( int order )
|
||||
CVector2D CEntityFormation::GetSlotPosition( size_t order )
|
||||
{
|
||||
if ( IsValidOrder(order) )
|
||||
return CVector2D ( m_base->m_slots[order].rankOff, m_base->m_slots[order].fileOff );
|
||||
@@ -226,12 +226,12 @@ void CEntityFormation::BaseToMovement()
|
||||
|
||||
void CEntityFormation::ResetIndex( size_t index )
|
||||
{
|
||||
m_index = (int)index;
|
||||
m_index = index;
|
||||
|
||||
for ( size_t i=0; i< m_entities.size(); ++i )
|
||||
{
|
||||
if ( m_entities[i] )
|
||||
m_entities[i]->m_formation = m_index;
|
||||
m_entities[i]->m_formation = (ssize_t)m_index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user