2012-04-24 18:46:32 +02:00
|
|
|
/* Copyright (C) 2012 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* 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
|
|
|
/*
|
|
|
|
* System for representing tile-based information on top of the
|
|
|
|
* terrain.
|
2006-04-24 01:14:18 +02:00
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_TERRAINOVERLAY
|
|
|
|
#define INCLUDED_TERRAINOVERLAY
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2012-04-24 18:46:32 +02:00
|
|
|
#include "lib/ogl.h"
|
|
|
|
|
2008-06-26 22:12:42 +02:00
|
|
|
struct CColor;
|
2006-04-24 01:14:18 +02:00
|
|
|
class CTerrain;
|
2012-01-18 22:22:58 +01:00
|
|
|
class CSimContext;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2012-04-24 18:46:32 +02:00
|
|
|
/**
|
|
|
|
* Common interface for terrain-tile-based and texture-based debug overlays.
|
|
|
|
*
|
|
|
|
* An overlay object will be rendered for as long as it is allocated
|
|
|
|
* (it is automatically registered/deregistered by constructor/destructor).
|
|
|
|
*/
|
|
|
|
class ITerrainOverlay
|
|
|
|
{
|
|
|
|
NONCOPYABLE(ITerrainOverlay);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~ITerrainOverlay();
|
|
|
|
|
|
|
|
virtual void RenderBeforeWater() { }
|
|
|
|
|
|
|
|
virtual void RenderAfterWater() { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw all ITerrainOverlay objects that exist
|
|
|
|
* and that should be drawn before water.
|
|
|
|
*/
|
|
|
|
static void RenderOverlaysBeforeWater();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw all ITerrainOverlay objects that exist
|
|
|
|
* and that should be drawn after water.
|
|
|
|
*/
|
|
|
|
static void RenderOverlaysAfterWater();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ITerrainOverlay(int priority);
|
|
|
|
};
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
/**
|
|
|
|
* 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).
|
2010-01-29 22:13:18 +01:00
|
|
|
*
|
2006-04-24 01:14:18 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
2012-04-24 18:46:32 +02:00
|
|
|
class TerrainOverlay : public ITerrainOverlay
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
|
*/
|
2012-01-18 22:22:58 +01:00
|
|
|
TerrainOverlay(const CSimContext& simContext, int priority = 100);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-01-29 22:13:18 +01:00
|
|
|
/**
|
|
|
|
* Override to perform processing at the start of the overlay rendering,
|
|
|
|
* before the ProcessTile calls
|
|
|
|
*/
|
|
|
|
virtual void StartRender();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override to perform processing at the end of the overlay rendering,
|
|
|
|
* after the ProcessTile calls
|
|
|
|
*/
|
|
|
|
virtual void EndRender();
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2010-01-29 22:13:18 +01:00
|
|
|
/**
|
|
|
|
* Draw a filled quad on top of the given tile.
|
|
|
|
*/
|
|
|
|
void RenderTile(const CColor& colour, bool draw_hidden, ssize_t i, ssize_t j);
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2010-01-29 22:13:18 +01:00
|
|
|
/**
|
|
|
|
* Draw an outlined quad on top of the given tile.
|
|
|
|
*/
|
|
|
|
void RenderTileOutline(const CColor& colour, int line_width, bool draw_hidden, ssize_t i, ssize_t j);
|
2007-10-09 09:27:45 +02:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
private:
|
|
|
|
// Process all tiles
|
2012-04-24 18:46:32 +02:00
|
|
|
virtual void RenderBeforeWater();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
};
|
|
|
|
|
2012-04-24 18:46:32 +02:00
|
|
|
/**
|
|
|
|
* Base class for texture-based terrain overlays, with an arbitrary number of
|
|
|
|
* texels per terrain tile, intended for debugging purposes.
|
|
|
|
* Subclasses must implement BuildTextureRGBA which will be called each frame.
|
|
|
|
*/
|
|
|
|
class TerrainTextureOverlay : public ITerrainOverlay
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
public:
|
2012-04-24 18:46:32 +02:00
|
|
|
TerrainTextureOverlay(float texelsPerTile, int priority = 100);
|
|
|
|
|
|
|
|
virtual ~TerrainTextureOverlay();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Called each frame to generate the texture to render on the terrain.
|
|
|
|
* @p data is w*h*4 bytes, where w and h are the terrain size multiplied
|
|
|
|
* by texelsPerTile. @p data defaults to fully transparent, and should
|
|
|
|
* be filled with data in RGBA order.
|
|
|
|
*/
|
|
|
|
virtual void BuildTextureRGBA(u8* data, size_t w, size_t h) = 0;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2012-04-24 18:46:32 +02:00
|
|
|
private:
|
2014-06-25 03:11:10 +02:00
|
|
|
void RenderAfterWater(int cullGroup);
|
2012-04-24 18:46:32 +02:00
|
|
|
|
|
|
|
float m_TexelsPerTile;
|
|
|
|
GLuint m_Texture;
|
|
|
|
GLsizei m_TextureW, m_TextureH;
|
|
|
|
};
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif // INCLUDED_TERRAINOVERLAY
|