janwas
c0ed950657
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.
68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
/**
|
|
* =========================================================================
|
|
* File : UnitManager.h
|
|
* Project : 0 A.D.
|
|
* Description : Container that owns all units
|
|
* =========================================================================
|
|
*/
|
|
|
|
#ifndef INCLUDED_UNITMANAGER
|
|
#define INCLUDED_UNITMANAGER
|
|
|
|
#include <vector>
|
|
#include <set>
|
|
|
|
class CUnit;
|
|
class CModel;
|
|
class CVector3D;
|
|
class CEntity;
|
|
class CStr;
|
|
class CObjectManager;
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// CUnitManager: simple container class holding all units within the world
|
|
class CUnitManager
|
|
{
|
|
public:
|
|
// constructor, destructor
|
|
CUnitManager();
|
|
~CUnitManager();
|
|
|
|
// add given unit to world
|
|
void AddUnit(CUnit* unit);
|
|
// remove given unit from world, but don't delete it
|
|
void RemoveUnit(CUnit* unit);
|
|
// remove given unit from world and delete it
|
|
void DeleteUnit(CUnit* unit);
|
|
// remove and delete all units
|
|
void DeleteAll();
|
|
|
|
// creates a new unit and adds it to the world
|
|
CUnit* CreateUnit(const CStr& actorName, CEntity* entity, const std::set<CStr>& selections);
|
|
|
|
// return the units
|
|
const std::vector<CUnit*>& GetUnits() const { return m_Units; }
|
|
|
|
// iterate through units testing given ray against bounds of each unit;
|
|
// return the closest unit, or null if everything missed
|
|
CUnit* PickUnit(const CVector3D& origin, const CVector3D& dir, bool entitiesOnly) const;
|
|
|
|
CUnit* FindByID(size_t id) const;
|
|
|
|
size_t GetNewID() { return m_NextID++; }
|
|
|
|
void SetNextID(size_t n) { m_NextID = n; }
|
|
|
|
void SetObjectManager(CObjectManager& objectManager) { m_ObjectManager = &objectManager; }
|
|
|
|
private:
|
|
// list of all known units
|
|
std::vector<CUnit*> m_Units;
|
|
// next ID number to be assigned to a unit created in the editor
|
|
size_t m_NextID;
|
|
// graphical object manager; may be NULL if not set up
|
|
CObjectManager* m_ObjectManager;
|
|
};
|
|
|
|
#endif
|