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
|
|
|
// LOSManager.h
|
|
|
|
//
|
|
|
|
// Maintains and updates line of sight data (including Shroud of Darkness
|
|
|
|
// and Fog of War).
|
|
|
|
//
|
|
|
|
// Usage:
|
|
|
|
// - Initialize() is called when the game is started to allocate the visibility arrays
|
|
|
|
// - Update() is called each frame by CSimulation::Update() to update the visibility arrays
|
|
|
|
// - m_MapRevealed can be set to true to reveal the entire map (remove both LOS and FOW)
|
|
|
|
// - GetStatus can be used to obtain the LOS status of a tile or a world-space point
|
|
|
|
// - GetUnitStatus returns the LOS status of an entity or actor
|
|
|
|
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_LOSMANAGER
|
|
|
|
#define INCLUDED_LOSMANAGER
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
class CUnit;
|
2006-09-01 02:24:26 +02:00
|
|
|
class CEntity;
|
2006-04-24 01:14:18 +02:00
|
|
|
class CPlayer;
|
|
|
|
|
|
|
|
#undef _2_los
|
|
|
|
|
|
|
|
enum ELOSStatus
|
|
|
|
{
|
|
|
|
LOS_VISIBLE = 2, // tile is currently in LOS of one of the player's units
|
|
|
|
LOS_EXPLORED = 1, // tile was explored before but is now in Fog of War
|
|
|
|
LOS_UNEXPLORED = 0 // tile is unexplored and therefore in Shroud of Darkness
|
|
|
|
};
|
|
|
|
|
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
|
|
|
// if changing these values, adapt ScriptGlue!RevealMap
|
|
|
|
enum ELOSSetting
|
|
|
|
{
|
|
|
|
LOS_SETTING_NORMAL,
|
|
|
|
LOS_SETTING_EXPLORED,
|
|
|
|
LOS_SETTING_ALL_VISIBLE
|
|
|
|
};
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
enum EUnitLOSStatus
|
|
|
|
{
|
|
|
|
UNIT_VISIBLE = 2, // unit is in LOS of one of the player's units
|
|
|
|
UNIT_REMEMBERED = 1, // unit was seen before and is permanent but is no longer in LOS
|
|
|
|
UNIT_HIDDEN = 0 // unit is either not permanent or was never seen before
|
|
|
|
};
|
|
|
|
|
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
|
|
|
extern size_t LOS_GetTokenFor(size_t player_id);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
class CLOSManager
|
|
|
|
{
|
|
|
|
#ifdef _2_los
|
|
|
|
int** m_Explored; // (m_Explored[x][z] & (1<<p) says whether player p has explored tile (x,z),
|
|
|
|
// i.e. has removed Shroud of Darkness from it.
|
|
|
|
int** m_Visible; // (m_Visible[x][z] & (1<<p)) says whether player p currently sees tile (x,z).
|
|
|
|
// NOTE: This will have to be changed to a 3D array where each element stores the number of units
|
|
|
|
// of a certain player that can see a certain tile if we want to use incremental LOS.
|
|
|
|
#else
|
|
|
|
u16** m_VisibilityMatrix;
|
|
|
|
#endif
|
|
|
|
|
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_TilesPerSide;
|
|
|
|
size_t m_TilesPerSide_1; // as above, -1
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
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
|
|
|
|
|
|
|
ELOSSetting m_LOSSetting;
|
2006-10-08 19:39:46 +02:00
|
|
|
bool m_FogOfWar;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
CLOSManager();
|
|
|
|
~CLOSManager();
|
|
|
|
|
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 Initialize(ELOSSetting losSetting, bool fogOfWar);
|
2006-04-24 01:14:18 +02:00
|
|
|
void Update();
|
|
|
|
|
|
|
|
// Get LOS status for a tile (in tile coordinates)
|
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
|
|
|
ELOSStatus GetStatus(ssize_t tx, ssize_t tz, CPlayer* player);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// Get LOS status for a point (in game coordinates)
|
|
|
|
ELOSStatus GetStatus(float fx, float fz, CPlayer* player);
|
|
|
|
|
2006-09-01 02:24:26 +02:00
|
|
|
// Returns whether a given actor is visible to the given player
|
2006-04-24 01:14:18 +02:00
|
|
|
EUnitLOSStatus GetUnitStatus(CUnit* unit, CPlayer* player);
|
2006-09-01 02:24:26 +02:00
|
|
|
|
|
|
|
// Returns whether a given entity is visible to the given player
|
|
|
|
EUnitLOSStatus GetUnitStatus(CEntity* entity, CPlayer* player);
|
2006-04-24 01:14:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|