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/>.
|
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* Container that owns all units
|
2007-05-07 18:33:24 +02:00
|
|
|
*/
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_UNITMANAGER
|
|
|
|
#define INCLUDED_UNITMANAGER
|
2004-05-30 02:46:58 +02:00
|
|
|
|
|
|
|
#include <vector>
|
2006-04-19 07:30:02 +02:00
|
|
|
#include <set>
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2004-12-12 20:43:55 +01:00
|
|
|
class CUnit;
|
2004-05-30 02:46:58 +02:00
|
|
|
class CVector3D;
|
2005-03-19 12:55:27 +01:00
|
|
|
class CEntity;
|
2007-01-08 02:56:46 +01:00
|
|
|
class CObjectManager;
|
2010-03-28 20:21:48 +02:00
|
|
|
class CStr8;
|
2004-05-30 02:46:58 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CUnitManager: simple container class holding all units within the world
|
2007-01-08 02:56:46 +01:00
|
|
|
class CUnitManager
|
2004-05-30 02:46:58 +02:00
|
|
|
{
|
|
|
|
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);
|
2004-10-06 20:45:59 +02:00
|
|
|
// remove given unit from world and delete it
|
|
|
|
void DeleteUnit(CUnit* unit);
|
2004-05-30 02:46:58 +02:00
|
|
|
// remove and delete all units
|
|
|
|
void DeleteAll();
|
|
|
|
|
2005-03-19 12:55:27 +01:00
|
|
|
// creates a new unit and adds it to the world
|
2010-03-28 20:21:48 +02:00
|
|
|
CUnit* CreateUnit(const CStr8& actorName, CEntity* entity, const std::set<CStr8>& selections);
|
2005-03-19 12:55:27 +01:00
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
// 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
|
2006-12-20 06:41:54 +01:00
|
|
|
CUnit* PickUnit(const CVector3D& origin, const CVector3D& dir, bool entitiesOnly) const;
|
2005-12-09 04:15:00 +01: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
|
|
|
CUnit* FindByID(size_t id) const;
|
2005-12-09 04:15:00 +01: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
|
|
|
size_t GetNewID() { return m_NextID++; }
|
2005-12-09 04:15:00 +01: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
|
|
|
void SetNextID(size_t n) { m_NextID = n; }
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2007-01-08 02:56:46 +01:00
|
|
|
void SetObjectManager(CObjectManager& objectManager) { m_ObjectManager = &objectManager; }
|
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
private:
|
|
|
|
// list of all known units
|
|
|
|
std::vector<CUnit*> m_Units;
|
2005-12-09 04:15:00 +01:00
|
|
|
// next ID number to be assigned to a unit created in the editor
|
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
|
|
|
size_t m_NextID;
|
2007-01-08 02:56:46 +01:00
|
|
|
// graphical object manager; may be NULL if not set up
|
|
|
|
CObjectManager* m_ObjectManager;
|
2004-05-30 02:46:58 +02:00
|
|
|
};
|
|
|
|
|
2004-06-02 17:03:17 +02:00
|
|
|
#endif
|