2011-03-13 20:22:05 +01:00
|
|
|
/* Copyright (C) 2011 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
|
|
|
/*
|
|
|
|
* Describes ground via heightmap and array of CPatch.
|
2007-05-07 18:33:24 +02:00
|
|
|
*/
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_TERRAIN
|
|
|
|
#define INCLUDED_TERRAIN
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "maths/Vector3D.h"
|
2010-04-06 19:31:38 +02:00
|
|
|
#include "maths/Fixed.h"
|
2006-09-26 03:44:20 +02:00
|
|
|
#include "graphics/SColor.h"
|
2012-04-18 22:39:00 +02:00
|
|
|
#include "graphics/HeightMipmap.h"
|
2006-06-09 18:44:16 +02:00
|
|
|
|
|
|
|
class CPatch;
|
|
|
|
class CMiniPatch;
|
2010-01-09 20:20:14 +01:00
|
|
|
class CFixedVector3D;
|
2010-05-28 01:31:03 +02:00
|
|
|
class CStr8;
|
2011-11-25 07:36:13 +01:00
|
|
|
class CBoundingBoxAligned;
|
2006-06-09 18:44:16 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Terrain Constants:
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
/// metres [world space units] per tile in x and z
|
2012-01-12 13:51:10 +01:00
|
|
|
const ssize_t TERRAIN_TILE_SIZE = 4;
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
/// number of u16 height units per metre
|
2010-05-02 22:32:37 +02:00
|
|
|
const ssize_t HEIGHT_UNITS_PER_METRE = 732; // == approx int(256.0f/0.35f)
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
/// metres per u16 height unit
|
|
|
|
const float HEIGHT_SCALE = 1.f / HEIGHT_UNITS_PER_METRE;
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CTerrain: main terrain class; contains the heightmap describing elevation
|
|
|
|
// data, and the smaller subpatches that form the terrain
|
|
|
|
class CTerrain
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTerrain();
|
|
|
|
~CTerrain();
|
|
|
|
|
2006-04-17 22:02:51 +02:00
|
|
|
// Coordinate naming convention: world-space coordinates are float x,z;
|
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
|
|
|
// tile-space coordinates are ssize_t i,j. rationale: signed types can
|
|
|
|
// more efficiently be converted to/from floating point. use ssize_t
|
|
|
|
// instead of int/long because these are sizes.
|
2006-04-17 22:02:51 +02:00
|
|
|
|
2009-11-08 17:49:52 +01:00
|
|
|
bool Initialize(ssize_t patchesPerSide, const u16* ptr);
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
// return number of vertices along edge of the terrain
|
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 GetVerticesPerSide() const { return m_MapSize; }
|
2006-04-17 22:02:51 +02:00
|
|
|
// return number of tiles along edge of the terrain
|
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 GetTilesPerSide() const { return GetVerticesPerSide()-1; }
|
2004-05-29 22:56:24 +02:00
|
|
|
// return number of patches along edge of the terrain
|
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 GetPatchesPerSide() const { return m_MapSizePatches; }
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2010-09-04 14:50:27 +02:00
|
|
|
float GetMinX() const { return 0.0f; }
|
|
|
|
float GetMinZ() const { return 0.0f; }
|
2012-01-12 13:51:10 +01:00
|
|
|
float GetMaxX() const { return (float)((m_MapSize-1) * TERRAIN_TILE_SIZE); }
|
|
|
|
float GetMaxZ() const { return (float)((m_MapSize-1) * TERRAIN_TILE_SIZE); }
|
2010-09-04 14:50:27 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
bool IsOnMap(float x, float z) const
|
2004-07-23 12:56:52 +02:00
|
|
|
{
|
2010-09-04 14:50:27 +02:00
|
|
|
return ((x >= GetMinX()) && (x < GetMaxX())
|
|
|
|
&& (z >= GetMinZ()) && (z < GetMaxZ()));
|
2004-07-23 12:56:52 +02:00
|
|
|
}
|
2006-10-08 19:39:46 +02:00
|
|
|
|
2010-05-28 01:31:03 +02:00
|
|
|
CStr8 GetMovementClass(ssize_t i, ssize_t j) const;
|
2006-10-08 19:39:46 +02: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
|
|
|
float GetVertexGroundLevel(ssize_t i, ssize_t j) const;
|
2010-05-28 01:31:03 +02:00
|
|
|
fixed GetVertexGroundLevelFixed(ssize_t i, ssize_t j) const;
|
2007-05-02 14:07:08 +02:00
|
|
|
float GetExactGroundLevel(float x, float z) const;
|
2010-05-02 22:32:37 +02:00
|
|
|
fixed GetExactGroundLevelFixed(fixed x, fixed z) const;
|
2012-04-18 22:39:00 +02:00
|
|
|
float GetFilteredGroundLevel(float x, float z, float radius) const;
|
2004-07-23 12:56:52 +02:00
|
|
|
|
2010-05-28 01:31:03 +02:00
|
|
|
// get the approximate slope (0 = horizontal, 0.5 = 30 degrees, 1.0 = 45 degrees, etc)
|
|
|
|
fixed GetSlopeFixed(ssize_t i, ssize_t j) const;
|
2011-03-13 20:10:38 +01:00
|
|
|
|
|
|
|
// Returns true if the triangulation diagonal for tile (i, j)
|
|
|
|
// should be in the direction (1,-1); false if it should be (1,1)
|
|
|
|
bool GetTriangulationDir(ssize_t i, ssize_t j) const;
|
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
// resize this terrain such that each side has given number of patches
|
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 Resize(ssize_t size);
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
// set up a new heightmap from 16 bit data; assumes heightmap matches current terrain size
|
|
|
|
void SetHeightMap(u16* heightmap);
|
|
|
|
// return a pointer to the heightmap
|
|
|
|
u16* GetHeightMap() const { return m_Heightmap; }
|
|
|
|
|
|
|
|
// get patch at given coordinates, expressed in patch-space; return 0 if
|
|
|
|
// coordinates represent patch off the edge of the map
|
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
|
|
|
CPatch* GetPatch(ssize_t i, ssize_t j) const;
|
2004-05-29 22:56:24 +02:00
|
|
|
// get tile at given coordinates, expressed in tile-space; return 0 if
|
|
|
|
// coordinates represent tile off the edge of the map
|
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
|
|
|
CMiniPatch* GetTile(ssize_t i, ssize_t j) const;
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
// calculate the position of a given vertex
|
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 CalcPosition(ssize_t i, ssize_t j, CVector3D& pos) const;
|
2010-01-09 20:20:14 +01:00
|
|
|
void CalcPositionFixed(ssize_t i, ssize_t j, CFixedVector3D& pos) const;
|
2005-09-12 22:04:26 +02:00
|
|
|
// calculate the vertex under a given position (rounding down 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
|
|
|
static void CalcFromPosition(const CVector3D& pos, ssize_t& i, ssize_t& j)
|
2005-11-06 02:33:16 +01:00
|
|
|
{
|
2012-01-12 13:51:10 +01:00
|
|
|
i = (ssize_t)(pos.X/TERRAIN_TILE_SIZE);
|
|
|
|
j = (ssize_t)(pos.Z/TERRAIN_TILE_SIZE);
|
2005-11-06 02:33:16 +01:00
|
|
|
}
|
|
|
|
// calculate the vertex under a given position (rounding down 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
|
|
|
static void CalcFromPosition(float x, float z, ssize_t& i, ssize_t& j)
|
2005-11-06 02:33:16 +01:00
|
|
|
{
|
2012-01-12 13:51:10 +01:00
|
|
|
i = (ssize_t)(x/TERRAIN_TILE_SIZE);
|
|
|
|
j = (ssize_t)(z/TERRAIN_TILE_SIZE);
|
2005-11-06 02:33:16 +01:00
|
|
|
}
|
2004-05-29 22:56:24 +02:00
|
|
|
// calculate the normal at a given vertex
|
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 CalcNormal(ssize_t i, ssize_t j, CVector3D& normal) const;
|
2010-01-09 20:20:14 +01:00
|
|
|
void CalcNormalFixed(ssize_t i, ssize_t j, CFixedVector3D& normal) const;
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2011-07-30 02:56:45 +02:00
|
|
|
CVector3D CalcExactNormal(float x, float z) const;
|
|
|
|
|
2012-04-18 00:35:34 +02:00
|
|
|
// Mark a specific square of tiles (inclusive lower bound, exclusive upper bound)
|
|
|
|
// as dirty - use this after modifying the heightmap.
|
|
|
|
// If you modify a vertex (i,j), you should dirty tiles
|
|
|
|
// from (i-1, j-1) [inclusive] to (i+1, j+1) [exclusive]
|
|
|
|
// since their geometry depends on that vertex.
|
|
|
|
// If you modify a tile (i,j), you should dirty tiles
|
|
|
|
// from (i-1, j-1) [inclusive] to (i+2, j+2) [exclusive]
|
|
|
|
// since their texture blends depend on that tile.
|
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 MakeDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dirtyFlags);
|
2005-11-05 05:59:54 +01:00
|
|
|
// mark the entire map as dirty
|
2005-11-06 06:05:07 +01:00
|
|
|
void MakeDirty(int dirtyFlags);
|
2005-07-03 18:25:48 +02:00
|
|
|
|
2011-03-13 20:22:05 +01:00
|
|
|
/**
|
|
|
|
* Returns a 3D bounding box encompassing the given vertex range (inclusive)
|
|
|
|
*/
|
2011-11-25 07:36:13 +01:00
|
|
|
CBoundingBoxAligned GetVertexesBound(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1);
|
2011-03-13 20:22:05 +01:00
|
|
|
|
2006-09-26 03:44:20 +02:00
|
|
|
// get the base colour for the terrain (typically pure white - other colours
|
|
|
|
// will interact badly with LOS - but used by the Actor Viewer tool)
|
|
|
|
SColor4ub GetBaseColour() const { return m_BaseColour; }
|
|
|
|
// set the base colour for the terrain
|
|
|
|
void SetBaseColour(SColor4ub colour) { m_BaseColour = colour; }
|
|
|
|
|
2012-04-18 22:39:00 +02:00
|
|
|
const CHeightMipmap& GetHeightMipmap() const { return m_HeightMipmap; }
|
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
private:
|
|
|
|
// delete any data allocated by this terrain
|
|
|
|
void ReleaseData();
|
|
|
|
// setup patch pointers etc
|
|
|
|
void InitialisePatches();
|
|
|
|
|
|
|
|
// size of this map in each direction, in vertices; ie. total tiles = sqr(m_MapSize-1)
|
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_MapSize;
|
2004-05-29 22:56:24 +02:00
|
|
|
// size of this map in each direction, in patches; total patches = sqr(m_MapSizePatches)
|
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_MapSizePatches;
|
2004-05-29 22:56:24 +02:00
|
|
|
// the patches comprising this terrain
|
|
|
|
CPatch* m_Patches;
|
|
|
|
// 16-bit heightmap data
|
2006-09-26 03:44:20 +02:00
|
|
|
u16* m_Heightmap;
|
|
|
|
// base colour (usually white)
|
|
|
|
SColor4ub m_BaseColour;
|
2012-04-18 22:39:00 +02:00
|
|
|
// heightmap mipmap
|
|
|
|
CHeightMipmap m_HeightMipmap;
|
2004-05-29 22:56:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|