2006-04-24 01:14:18 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : TerrainOverlay.h
|
|
|
|
* Project : Pyrogenesis
|
|
|
|
* Description : System for representing tile-based information on top of
|
|
|
|
* : the terrain.
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_TERRAINOVERLAY
|
|
|
|
#define INCLUDED_TERRAINOVERLAY
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2008-06-26 22:12:42 +02:00
|
|
|
struct CColor;
|
2006-04-24 01:14:18 +02:00
|
|
|
class CTerrain;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for (relatively) simple drawing of
|
2008-06-26 22:12:42 +02:00
|
|
|
* data onto terrain tiles, intended for debugging purposes and for the Atlas
|
2006-04-24 01:14:18 +02:00
|
|
|
* editor (hence not trying to be very efficient).
|
|
|
|
* <p>
|
|
|
|
* To start drawing a terrain overlay, first create a subclass of TerrainOverlay.
|
|
|
|
* Override the method GetTileExtents if you want to change the range over which
|
|
|
|
* it is drawn.
|
|
|
|
* Override ProcessTile to do your processing for each tile, which should call
|
|
|
|
* RenderTile and RenderTileOutline as appropriate.
|
|
|
|
* See the end of TerrainOverlay.h for an example.
|
|
|
|
* <p>
|
|
|
|
* A TerrainOverlay object will be rendered for as long as it exists.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class TerrainOverlay
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~TerrainOverlay();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Construct the object and register it with the global
|
|
|
|
* list of terrain overlays.
|
|
|
|
* <p>
|
|
|
|
* The priority parameter controls the order in which overlays are drawn,
|
|
|
|
* if several exist - they are processed in order of increasing priority,
|
|
|
|
* so later ones draw on top of earlier ones.
|
|
|
|
* Most should use the default of 100. Numbers from 200 are used
|
|
|
|
* by Atlas.
|
|
|
|
*
|
|
|
|
* @param priority controls the order of drawing
|
|
|
|
*/
|
|
|
|
TerrainOverlay(int priority = 100);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override to limit the range over which ProcessTile will
|
|
|
|
* be called. Defaults to the size of the map.
|
|
|
|
*
|
|
|
|
* @param min_i_inclusive [output] smallest <i>i</i> coordinate, in tile-space units
|
|
|
|
* (1 unit per tile, <i>+i</i> is world-space <i>+x</i> and game-space East)
|
|
|
|
* @param min_j_inclusive [output] smallest <i>j</i> coordinate
|
|
|
|
* (<i>+j</i> is world-space <i>+z</i> and game-space North)
|
|
|
|
* @param max_i_inclusive [output] largest <i>i</i> coordinate
|
|
|
|
* @param max_j_inclusive [output] largest <i>j</i> coordinate
|
|
|
|
*/
|
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
|
|
|
virtual void GetTileExtents(ssize_t& min_i_inclusive, ssize_t& min_j_inclusive,
|
|
|
|
ssize_t& max_i_inclusive, ssize_t& max_j_inclusive);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Override to perform processing of each tile. Typically calls
|
|
|
|
* RenderTile and/or RenderTileOutline.
|
|
|
|
*
|
|
|
|
* @param i <i>i</i> coordinate of tile being processed
|
|
|
|
* @param j <i>j</i> coordinate of tile being processed
|
|
|
|
*/
|
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
|
|
|
virtual void ProcessTile(ssize_t i, ssize_t j) = 0;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw a filled quad on top of the current tile.
|
|
|
|
*
|
|
|
|
* @param colour colour to draw. May be transparent (alpha < 1)
|
|
|
|
* @param draw_hidden true if hidden tiles (i.e. those behind other tiles)
|
|
|
|
* should be drawn
|
|
|
|
*/
|
|
|
|
void RenderTile(const CColor& colour, bool draw_hidden);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw an outlined quad on top of the current tile.
|
|
|
|
*
|
|
|
|
* @param colour colour to draw. May be transparent (alpha < 1)
|
|
|
|
* @param line_width width of lines in pixels. 1 is a sensible value
|
|
|
|
* @param draw_hidden true if hidden tiles (i.e. those behind other tiles)
|
|
|
|
* should be drawn
|
|
|
|
*/
|
|
|
|
void RenderTileOutline(const CColor& colour, int line_width, bool draw_hidden);
|
|
|
|
|
2007-10-09 09:27:45 +02:00
|
|
|
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
public:
|
2007-10-09 09:27:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
/// Draw all TerrainOverlay objects that exist.
|
|
|
|
static void RenderOverlays();
|
|
|
|
|
2008-06-25 01:35:46 +02:00
|
|
|
#if 0
|
2007-10-09 09:27:45 +02:00
|
|
|
/**
|
|
|
|
* Kai: added function to draw out line segments for triangulation
|
|
|
|
*/
|
|
|
|
static void RenderEntityEdges();
|
2008-06-25 01:35:46 +02:00
|
|
|
#endif
|
2007-10-09 09:27:45 +02:00
|
|
|
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
private:
|
|
|
|
/// Copying not allowed.
|
|
|
|
TerrainOverlay(const TerrainOverlay&);
|
|
|
|
|
|
|
|
friend struct render1st;
|
|
|
|
|
|
|
|
// Process all tiles
|
|
|
|
void Render();
|
|
|
|
|
|
|
|
// Temporary storage of tile coordinates, so ProcessTile doesn't need to
|
|
|
|
// pass it to RenderTile/etc (and doesn't have a chance to get it wrong)
|
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 m_i, m_j;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
CTerrain* m_Terrain;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Example usage:
|
|
|
|
|
|
|
|
class ExampleTerrainOverlay : public TerrainOverlay
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
char random[1021];
|
|
|
|
|
|
|
|
ExampleTerrainOverlay()
|
|
|
|
{
|
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 < ARRAY_SIZE(random); ++i)
|
2006-04-24 01:14:18 +02:00
|
|
|
random[i] = rand(0, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void GetTileExtents(
|
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& min_i_inclusive, ssize_t& min_j_inclusive,
|
|
|
|
ssize_t& max_i_inclusive, ssize_t& max_j_inclusive)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
min_i_inclusive = 5;
|
|
|
|
min_j_inclusive = 10;
|
|
|
|
max_i_inclusive = 70;
|
|
|
|
max_j_inclusive = 50;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
virtual void ProcessTile(ssize_t i, ssize_t j)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
if (!random[(i*97+j*101) % ARRAY_SIZE(random)])
|
|
|
|
return;
|
|
|
|
RenderTile(CColor(random[(i*79+j*13) % ARRAY_SIZE(random)]/4.f, 1, 0, 0.3f), false);
|
|
|
|
RenderTileOutline(CColor(1, 1, 1, 1), 1, true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ExampleTerrainOverlay test; // or allocate it dynamically somewhere
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif // INCLUDED_TERRAINOVERLAY
|