2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "precompiled.h"
|
2006-06-09 20:32:00 +02:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "EntityFormation.h"
|
2006-06-09 20:32:00 +02:00
|
|
|
|
|
|
|
#include "Entity.h"
|
2006-06-10 01:07:11 +02:00
|
|
|
#include "FormationCollection.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "FormationManager.h"
|
|
|
|
#include "Simulation.h"
|
|
|
|
#include "ps/Game.h"
|
2006-08-26 22:25:37 +02:00
|
|
|
#include "network/NetMessage.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-06-10 01:07:11 +02:00
|
|
|
CEntityFormation::CEntityFormation( CFormation*& base, size_t index )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
if (!base)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_self = m_base = base;
|
|
|
|
m_numEntities=0;
|
|
|
|
m_speed=0.0f;
|
|
|
|
m_orientation = 0.0f;
|
|
|
|
|
|
|
|
m_position.x = m_position.y = -1.0f;
|
|
|
|
m_duplication=false;
|
|
|
|
m_entities.resize(m_base->m_numSlots);
|
|
|
|
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
m_index = index;
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
2007-01-24 21:17:28 +01:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
CEntityFormation::~CEntityFormation()
|
|
|
|
{
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
for ( size_t i=0; i<m_base->m_numSlots; ++i )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
if ( m_entities[i] )
|
|
|
|
{
|
|
|
|
m_entities[i]->m_formation = -1;
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
m_entities[i]->m_formationSlot = (size_t)-1;
|
2006-04-24 01:14:18 +02:00
|
|
|
m_entities[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-01-24 21:17:28 +01:00
|
|
|
|
2006-06-10 01:07:11 +02:00
|
|
|
void CEntityFormation::SwitchBase( CFormation*& base )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
std::vector<CEntity*> copy;
|
|
|
|
copy.resize( m_base->m_numSlots );
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
for ( size_t i=0; i < m_base->m_numSlots; ++i )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
if ( !m_entities[i] )
|
|
|
|
continue;
|
|
|
|
copy.push_back( m_entities[i] );
|
|
|
|
RemoveUnit( m_entities[i] );
|
|
|
|
}
|
|
|
|
m_self = m_base = base;
|
|
|
|
m_entities.resize(m_base->m_numSlots);
|
|
|
|
ResetAllEntities();
|
|
|
|
|
|
|
|
for ( std::vector<CEntity*>::iterator it=copy.begin(); it != copy.end(); it++ )
|
|
|
|
g_FormationManager.AddUnit(*it, m_index);
|
|
|
|
}
|
2007-05-02 14:07:08 +02:00
|
|
|
|
2007-01-25 08:00:31 +01:00
|
|
|
bool CEntityFormation::AddUnit( CEntity* entity )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
debug_assert( entity );
|
|
|
|
//Add the unit to the most appropriate slot
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
for (size_t i=0; i<m_base->m_numSlots; ++i)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
if ( IsBetterUnit( i, entity ) )
|
|
|
|
{
|
|
|
|
if ( m_entities[i] )
|
|
|
|
{
|
|
|
|
CEntity* prev = m_entities[i];
|
|
|
|
RemoveUnit( m_entities[i] );
|
|
|
|
m_entities[i] = entity;
|
|
|
|
AddUnit( prev );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_entities[i] = entity;
|
|
|
|
++m_numEntities;
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
entity->m_formation = (ssize_t)m_index;
|
|
|
|
entity->m_formationSlot = (ssize_t)i;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-05-02 14:07:08 +02:00
|
|
|
|
2007-01-25 08:00:31 +01:00
|
|
|
void CEntityFormation::RemoveUnit( CEntity* entity )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2006-07-06 05:17:44 +02:00
|
|
|
if ( !(IsValidOrder(entity->m_formationSlot) && entity) )
|
2006-04-24 01:14:18 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_entities[entity->m_formationSlot] = NULL;
|
|
|
|
entity->m_formation = -1;
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
entity->m_formationSlot = (size_t)-1;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
--m_numEntities;
|
|
|
|
//UpdateFormation();
|
|
|
|
}
|
2007-05-02 14:07:08 +02: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.
2008-05-11 20:48:32 +02:00
|
|
|
bool CEntityFormation::IsSlotAppropriate( size_t order, CEntity* entity )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
debug_assert( entity );
|
|
|
|
if ( !IsValidOrder(order) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for ( size_t idx=0; idx < m_base->m_slots[order].category.size(); ++idx )
|
|
|
|
{
|
|
|
|
CStr tmp( m_base->m_slots[order].category[idx] );
|
|
|
|
if ( entity->m_classes.IsMember( tmp ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-05-02 14:07:08 +02: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.
2008-05-11 20:48:32 +02:00
|
|
|
bool CEntityFormation::IsBetterUnit( size_t order, CEntity* entity )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2006-07-06 05:17:44 +02:00
|
|
|
if ( !( IsValidOrder(order) && entity ) )
|
2006-04-24 01:14:18 +02:00
|
|
|
return false;
|
|
|
|
//Adding to an empty slot, check if we're elligible
|
|
|
|
if ( !m_entities[order] )
|
|
|
|
return IsSlotAppropriate(order, entity);
|
|
|
|
|
|
|
|
//Go through each category and check both units' classes. Must be done in order
|
|
|
|
//because categories are listed in order of importance
|
|
|
|
for ( size_t idx=0; idx < m_base->m_slots[order].category.size(); ++idx )
|
|
|
|
{
|
|
|
|
CStr cat = m_base->m_slots[order].category[idx];
|
|
|
|
bool current=false;
|
|
|
|
bool newEnt=false;
|
|
|
|
|
|
|
|
current = m_entities[order]->m_classes.IsMember( cat );
|
|
|
|
newEnt = entity->m_classes.IsMember( cat );
|
|
|
|
|
|
|
|
if ( current != newEnt )
|
|
|
|
return newEnt;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEntityFormation::UpdateFormation()
|
|
|
|
{
|
|
|
|
//Get the entities in the right order (as in, ordered correctly and in the right order/slot)
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
for ( size_t i=1; i<m_base->m_numSlots; ++i )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
if ( !m_entities[i] )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//Go through slots with higher order
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
for ( size_t j=i-1; j != 0; --j )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
if ( IsBetterUnit( j, m_entities[i] ) )
|
|
|
|
{
|
|
|
|
CEntity* temp = m_entities[j];
|
|
|
|
m_entities[j] = m_entities[i];
|
|
|
|
m_entities[i] = temp;
|
|
|
|
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
ssize_t tmpSlot = m_entities[i]->m_formationSlot;
|
2006-04-24 01:14:18 +02:00
|
|
|
m_entities[i]->m_formationSlot = m_entities[j]->m_formationSlot;
|
|
|
|
m_entities[j]->m_formationSlot = tmpSlot;
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CEntityList entities = GetEntityList();
|
2010-05-20 19:58:37 +02:00
|
|
|
/*
|
2008-06-16 20:19:35 +02:00
|
|
|
CNetMessage* msg = CNetMessage::CreatePositionMessage( entities, NMT_FORMATION_GOTO, m_position );
|
2006-04-24 01:14:18 +02:00
|
|
|
g_Game->GetSimulation()->QueueLocalCommand(msg);
|
2010-05-20 19:58:37 +02:00
|
|
|
*/
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEntityFormation::ResetAllEntities()
|
|
|
|
{
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
for ( size_t i=0; i<m_base->m_numSlots; ++i )
|
2006-04-24 01:14:18 +02:00
|
|
|
m_entities[i] = NULL;
|
|
|
|
}
|
2007-05-02 14:07:08 +02:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
void CEntityFormation::ResetAngleDivs()
|
|
|
|
{
|
|
|
|
for ( int i=0; i<m_base->m_anglePenaltyDivs; ++i )
|
|
|
|
m_angleDivs[i] = false;
|
|
|
|
}
|
2007-05-02 14:07:08 +02:00
|
|
|
|
2008-11-22 17:50:03 +01:00
|
|
|
void CEntityFormation::SelectAllUnits() const
|
2006-04-24 01:14:18 +02: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.
2008-05-11 20:48:32 +02:00
|
|
|
for ( size_t i=0; i<m_base->m_numSlots; ++i )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2010-05-20 20:09:23 +02:00
|
|
|
/*
|
2007-05-02 14:07:08 +02:00
|
|
|
if ( m_entities[i] && !g_Selection.IsSelected(m_entities[i]->me) )
|
|
|
|
g_Selection.AddSelection( m_entities[i]->me );
|
2010-05-20 20:09:23 +02:00
|
|
|
*/
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-22 17:50:03 +01:00
|
|
|
// (cannot be declared inline in the header due to use of CFormation (m_base)
|
|
|
|
size_t CEntityFormation::GetSlotCount() const
|
|
|
|
{
|
|
|
|
return m_base->m_numSlots;
|
|
|
|
}
|
|
|
|
|
|
|
|
CEntityList CEntityFormation::GetEntityList() const
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
CEntityList ret;
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
for ( size_t i=0; i<m_base->m_numSlots; i++ )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
if ( m_entities[i] )
|
|
|
|
ret.push_back( m_entities[i]->me);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-22 17:50:03 +01:00
|
|
|
CVector2D CEntityFormation::GetSlotPosition( size_t order ) const
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
if ( IsValidOrder(order) )
|
|
|
|
return CVector2D ( m_base->m_slots[order].rankOff, m_base->m_slots[order].fileOff );
|
|
|
|
return CVector2D(-1, -1);
|
|
|
|
}
|
2007-05-02 14:07:08 +02:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
void CEntityFormation::BaseToMovement()
|
|
|
|
{
|
2006-06-10 01:07:11 +02:00
|
|
|
CFormation* tmp = m_self;
|
2007-05-02 14:07:08 +02:00
|
|
|
CFormation* move = g_EntityFormationCollection.GetTemplate( m_base->m_movement );
|
2006-04-24 01:14:18 +02:00
|
|
|
if (!move)
|
|
|
|
return;
|
|
|
|
SwitchBase( move );
|
|
|
|
//SwitchBase resets m_self, so reset it so we can return to the correct base later
|
|
|
|
m_self = tmp;
|
|
|
|
}
|
2007-05-02 14:07:08 +02:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
void CEntityFormation::ResetIndex( size_t index )
|
|
|
|
{
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
m_index = index;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
for ( size_t i=0; i< m_entities.size(); ++i )
|
|
|
|
{
|
|
|
|
if ( m_entities[i] )
|
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.
2008-05-11 20:48:32 +02:00
|
|
|
m_entities[i]->m_formation = (ssize_t)m_index;
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
}
|
2007-05-02 14:07:08 +02:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
/*
|
|
|
|
inline void CEntityFormation::SetDuplication( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* argv )
|
|
|
|
{
|
|
|
|
m_duplication=ToPrimitive<bool>( argv[0] );
|
|
|
|
}
|
|
|
|
inline bool CEntityFormation::IsDuplication( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
|
|
|
|
{
|
|
|
|
return m_duplication;
|
|
|
|
}*/
|