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
|
|
|
//This keeps track of all the formations exisisting in the game.
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_FORMATIONMANAGER
|
|
|
|
#define INCLUDED_FORMATIONMANAGER
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
#include "ps/Singleton.h"
|
|
|
|
#include "scripting/DOMEvent.h"
|
|
|
|
|
|
|
|
#define g_FormationManager CFormationManager::GetSingleton()
|
|
|
|
|
|
|
|
class CEntity;
|
|
|
|
class CStr;
|
2006-06-10 01:07:11 +02:00
|
|
|
class CFormation;
|
2006-04-24 01:14:18 +02:00
|
|
|
class CVector2D;
|
|
|
|
class CEntityFormation;
|
|
|
|
|
|
|
|
struct CEntityList;
|
|
|
|
|
|
|
|
class CFormationManager : public Singleton<CFormationManager>
|
|
|
|
{
|
|
|
|
#define FormIterator std::vector<CEntityFormation*>::iterator
|
|
|
|
|
|
|
|
public:
|
|
|
|
CFormationManager() {}
|
|
|
|
~CFormationManager();
|
|
|
|
void CreateFormation( CEntityList& entities, CStrW& name );
|
|
|
|
//entity is any unit in the formation
|
|
|
|
void DestroyFormation( size_t form );
|
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
|
|
|
inline bool IsValidFormation( size_t index )
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2009-07-27 20:32:59 +02:00
|
|
|
return (index < m_formations.size());
|
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
|
|
|
bool AddUnit( CEntity* entity, size_t& form );
|
|
|
|
CEntityList AddUnitList( CEntityList& entities, size_t form );
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
//Returns false if the formation is destroyed
|
2007-01-25 08:00:31 +01:00
|
|
|
bool RemoveUnit( CEntity* entity );
|
2006-04-24 01:14:18 +02:00
|
|
|
bool RemoveUnitList( CEntityList& entities );
|
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
|
|
|
CEntityFormation* GetFormation(size_t form);
|
2006-04-24 01:14:18 +02:00
|
|
|
void UpdateIndexes( size_t update );
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<CEntityFormation*> m_formations;
|
|
|
|
};
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif // INCLUDED_FORMATIONMANAGER
|