Rationalise terrain dirty-rect coordinates.
Clean up some whitespace. This was SVN commit r11543.
This commit is contained in:
parent
41f50e6b4c
commit
3027ce1a04
@ -536,10 +536,12 @@ void CTerrain::Resize(ssize_t size)
|
||||
// InitialisePatches: initialise patch data
|
||||
void CTerrain::InitialisePatches()
|
||||
{
|
||||
for (ssize_t j=0;j<m_MapSizePatches;j++) {
|
||||
for (ssize_t i=0;i<m_MapSizePatches;i++) {
|
||||
CPatch* patch=GetPatch(i,j); // can't fail
|
||||
patch->Initialize(this,i,j);
|
||||
for (ssize_t j = 0; j < m_MapSizePatches; j++)
|
||||
{
|
||||
for (ssize_t i = 0; i < m_MapSizePatches; i++)
|
||||
{
|
||||
CPatch* patch = GetPatch(i, j); // can't fail
|
||||
patch->Initialize(this, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -550,12 +552,14 @@ void CTerrain::InitialisePatches()
|
||||
void CTerrain::SetHeightMap(u16* heightmap)
|
||||
{
|
||||
// keep a copy of the given heightmap
|
||||
memcpy(m_Heightmap,heightmap,m_MapSize*m_MapSize*sizeof(u16));
|
||||
memcpy(m_Heightmap, heightmap, m_MapSize*m_MapSize*sizeof(u16));
|
||||
|
||||
// recalculate patch bounds, invalidate vertices
|
||||
for (ssize_t j=0;j<m_MapSizePatches;j++) {
|
||||
for (ssize_t i=0;i<m_MapSizePatches;i++) {
|
||||
CPatch* patch=GetPatch(i,j); // can't fail
|
||||
for (ssize_t j = 0; j < m_MapSizePatches; j++)
|
||||
{
|
||||
for (ssize_t i = 0; i < m_MapSizePatches; i++)
|
||||
{
|
||||
CPatch* patch = GetPatch(i, j); // can't fail
|
||||
patch->InvalidateBounds();
|
||||
patch->SetDirty(RENDERDATA_UPDATE_VERTICES);
|
||||
}
|
||||
@ -567,14 +571,17 @@ void CTerrain::SetHeightMap(u16* heightmap)
|
||||
|
||||
void CTerrain::MakeDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dirtyFlags)
|
||||
{
|
||||
// flag vertex data as dirty for affected patches, and rebuild bounds of these patches
|
||||
ssize_t pi0 = clamp((i0/PATCH_SIZE)-1, (ssize_t)0, m_MapSizePatches);
|
||||
ssize_t pi1 = clamp((i1/PATCH_SIZE)+1, (ssize_t)0, m_MapSizePatches);
|
||||
ssize_t pj0 = clamp((j0/PATCH_SIZE)-1, (ssize_t)0, m_MapSizePatches);
|
||||
ssize_t pj1 = clamp((j1/PATCH_SIZE)+1, (ssize_t)0, m_MapSizePatches);
|
||||
for (ssize_t j = pj0; j < pj1; j++) {
|
||||
for (ssize_t i = pi0; i < pi1; i++) {
|
||||
CPatch* patch = GetPatch(i,j); // can't fail (i,j were clamped)
|
||||
// Finds the inclusive limits of the patches that include the specified range of tiles
|
||||
ssize_t pi0 = clamp( i0 /PATCH_SIZE, (ssize_t)0, m_MapSizePatches-1);
|
||||
ssize_t pi1 = clamp((i1-1)/PATCH_SIZE, (ssize_t)0, m_MapSizePatches-1);
|
||||
ssize_t pj0 = clamp( j0 /PATCH_SIZE, (ssize_t)0, m_MapSizePatches-1);
|
||||
ssize_t pj1 = clamp((j1-1)/PATCH_SIZE, (ssize_t)0, m_MapSizePatches-1);
|
||||
|
||||
for (ssize_t j = pj0; j <= pj1; j++)
|
||||
{
|
||||
for (ssize_t i = pi0; i <= pi1; i++)
|
||||
{
|
||||
CPatch* patch = GetPatch(i, j); // can't fail (i,j were clamped)
|
||||
if (dirtyFlags & RENDERDATA_UPDATE_VERTICES)
|
||||
patch->CalcBounds();
|
||||
patch->SetDirty(dirtyFlags);
|
||||
@ -584,9 +591,11 @@ void CTerrain::MakeDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dir
|
||||
|
||||
void CTerrain::MakeDirty(int dirtyFlags)
|
||||
{
|
||||
for (ssize_t j = 0; j < m_MapSizePatches; j++) {
|
||||
for (ssize_t i = 0; i < m_MapSizePatches; i++) {
|
||||
CPatch* patch = GetPatch(i,j); // can't fail
|
||||
for (ssize_t j = 0; j < m_MapSizePatches; j++)
|
||||
{
|
||||
for (ssize_t i = 0; i < m_MapSizePatches; i++)
|
||||
{
|
||||
CPatch* patch = GetPatch(i, j); // can't fail
|
||||
if (dirtyFlags & RENDERDATA_UPDATE_VERTICES)
|
||||
patch->CalcBounds();
|
||||
patch->SetDirty(dirtyFlags);
|
||||
|
@ -128,7 +128,14 @@ public:
|
||||
|
||||
CVector3D CalcExactNormal(float x, float z) const;
|
||||
|
||||
// mark a specific square of tiles as dirty - use this after modifying the heightmap
|
||||
// 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.
|
||||
void MakeDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dirtyFlags);
|
||||
// mark the entire map as dirty
|
||||
void MakeDirty(int dirtyFlags);
|
||||
|
@ -101,7 +101,7 @@ protected:
|
||||
BEGIN_COMMAND(AlterElevation)
|
||||
{
|
||||
TerrainArray m_TerrainDelta;
|
||||
ssize_t m_i0, m_j0, m_i1, m_j1;
|
||||
ssize_t m_i0, m_j0, m_i1, m_j1; // dirtied tiles (inclusive lower bound, exclusive upper)
|
||||
|
||||
cAlterElevation()
|
||||
{
|
||||
@ -148,8 +148,8 @@ BEGIN_COMMAND(AlterElevation)
|
||||
}
|
||||
}
|
||||
|
||||
m_i0 = x0;
|
||||
m_j0 = y0;
|
||||
m_i0 = x0 - 1;
|
||||
m_j0 = y0 - 1;
|
||||
m_i1 = x0 + g_CurrentBrush.m_W;
|
||||
m_j1 = y0 + g_CurrentBrush.m_H;
|
||||
MakeDirty();
|
||||
@ -183,7 +183,7 @@ END_COMMAND(AlterElevation)
|
||||
BEGIN_COMMAND(SmoothElevation)
|
||||
{
|
||||
TerrainArray m_TerrainDelta;
|
||||
ssize_t m_i0, m_j0, m_i1, m_j1;
|
||||
ssize_t m_i0, m_j0, m_i1, m_j1; // dirtied tiles (inclusive lower bound, exclusive upper)
|
||||
|
||||
cSmoothElevation()
|
||||
{
|
||||
@ -262,8 +262,8 @@ BEGIN_COMMAND(SmoothElevation)
|
||||
|
||||
m_i0 = x0;
|
||||
m_j0 = y0;
|
||||
m_i1 = x0 + g_CurrentBrush.m_W;
|
||||
m_j1 = y0 + g_CurrentBrush.m_H;
|
||||
m_i1 = x0 + g_CurrentBrush.m_W - 1;
|
||||
m_j1 = y0 + g_CurrentBrush.m_H - 1;
|
||||
MakeDirty();
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ END_COMMAND(SmoothElevation)
|
||||
BEGIN_COMMAND(FlattenElevation)
|
||||
{
|
||||
TerrainArray m_TerrainDelta;
|
||||
ssize_t m_i0, m_j0, m_i1, m_j1;
|
||||
ssize_t m_i0, m_j0, m_i1, m_j1; // dirtied tiles (inclusive lower bound, exclusive upper)
|
||||
|
||||
cFlattenElevation()
|
||||
{
|
||||
@ -326,15 +326,17 @@ BEGIN_COMMAND(FlattenElevation)
|
||||
g_CurrentBrush.GetBottomLeft(x0, y0);
|
||||
|
||||
for (ssize_t dy = 0; dy < g_CurrentBrush.m_H; ++dy)
|
||||
{
|
||||
for (ssize_t dx = 0; dx < g_CurrentBrush.m_W; ++dx)
|
||||
{
|
||||
float b = g_CurrentBrush.Get(dx, dy);
|
||||
if (b)
|
||||
m_TerrainDelta.MoveVertexTowards(x0+dx, y0+dy, height, 1 + (int)(b*amount));
|
||||
}
|
||||
}
|
||||
|
||||
m_i0 = x0;
|
||||
m_j0 = y0;
|
||||
m_i0 = x0 - 1;
|
||||
m_j0 = y0 - 1;
|
||||
m_i1 = x0 + g_CurrentBrush.m_W;
|
||||
m_j1 = y0 + g_CurrentBrush.m_H;
|
||||
MakeDirty();
|
||||
|
@ -270,7 +270,7 @@ protected:
|
||||
BEGIN_COMMAND(PaintTerrain)
|
||||
{
|
||||
TerrainArray m_TerrainDelta;
|
||||
ssize_t m_i0, m_j0, m_i1, m_j1;
|
||||
ssize_t m_i0, m_j0, m_i1, m_j1; // dirtied tiles (inclusive lower bound, exclusive upper)
|
||||
|
||||
cPaintTerrain()
|
||||
{
|
||||
@ -324,10 +324,10 @@ BEGIN_COMMAND(PaintTerrain)
|
||||
}
|
||||
}
|
||||
|
||||
m_i0 = x0;
|
||||
m_j0 = y0;
|
||||
m_i1 = x0 + g_CurrentBrush.m_W;
|
||||
m_j1 = y0 + g_CurrentBrush.m_H;
|
||||
m_i0 = x0 - 1;
|
||||
m_j0 = y0 - 1;
|
||||
m_i1 = x0 + g_CurrentBrush.m_W + 1;
|
||||
m_j1 = y0 + g_CurrentBrush.m_H + 1;
|
||||
MakeDirty();
|
||||
}
|
||||
|
||||
@ -359,7 +359,7 @@ END_COMMAND(PaintTerrain)
|
||||
BEGIN_COMMAND(ReplaceTerrain)
|
||||
{
|
||||
TerrainArray m_TerrainDelta;
|
||||
ssize_t m_i0, m_j0, m_i1, m_j1;
|
||||
ssize_t m_i0, m_j0, m_i1, m_j1; // dirtied tiles (inclusive lower bound, exclusive upper)
|
||||
|
||||
cReplaceTerrain()
|
||||
{
|
||||
@ -407,10 +407,10 @@ BEGIN_COMMAND(ReplaceTerrain)
|
||||
{
|
||||
if (m_TerrainDelta.GetTexEntry(i, j) == replacedTex)
|
||||
{
|
||||
m_i0 = std::min(m_i0, i);
|
||||
m_j0 = std::min(m_j0, j);
|
||||
m_i1 = std::max(m_i1, i+1);
|
||||
m_j1 = std::max(m_j1, j+1);
|
||||
m_i0 = std::min(m_i0, i-1);
|
||||
m_j0 = std::min(m_j0, j-1);
|
||||
m_i1 = std::max(m_i1, i+2);
|
||||
m_j1 = std::max(m_j1, j+2);
|
||||
m_TerrainDelta.PaintTile(i, j, texentry, m_TerrainDelta.GetPriority(i, j));
|
||||
}
|
||||
}
|
||||
@ -438,7 +438,7 @@ END_COMMAND(ReplaceTerrain)
|
||||
BEGIN_COMMAND(FillTerrain)
|
||||
{
|
||||
TerrainArray m_TerrainDelta;
|
||||
ssize_t m_i0, m_j0, m_i1, m_j1;
|
||||
ssize_t m_i0, m_j0, m_i1, m_j1; // dirtied tiles (inclusive lower bound, exclusive upper)
|
||||
|
||||
cFillTerrain()
|
||||
{
|
||||
@ -500,10 +500,10 @@ BEGIN_COMMAND(FillTerrain)
|
||||
if (m_TerrainDelta.GetTexEntry(i, j) == replacedTex)
|
||||
{
|
||||
// Found a tile to replace: adjust bounds and paint it
|
||||
m_i0 = std::min(m_i0, (ssize_t)i);
|
||||
m_j0 = std::min(m_j0, (ssize_t)j);
|
||||
m_i1 = std::max(m_i1, (ssize_t)i+1);
|
||||
m_j1 = std::max(m_j1, (ssize_t)j+1);
|
||||
m_i0 = std::min(m_i0, (ssize_t)i-1);
|
||||
m_j0 = std::min(m_j0, (ssize_t)j-1);
|
||||
m_i1 = std::max(m_i1, (ssize_t)i+2);
|
||||
m_j1 = std::max(m_j1, (ssize_t)j+2);
|
||||
m_TerrainDelta.PaintTile(i, j, texentry, m_TerrainDelta.GetPriority(i, j));
|
||||
|
||||
// Visit 4 adjacent tiles (could visit 8 if we want to count diagonal adjacency)
|
||||
|
Loading…
Reference in New Issue
Block a user