2025-08-02 12:24:35 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2009-06-20 09:13:29 -07:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-06-20 09:13:29 -07:00
|
|
|
* 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.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-06-20 09:13:29 -07:00
|
|
|
* 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
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-20 09:13:29 -07:00
|
|
|
*/
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
2022-01-29 00:28:04 -08:00
|
|
|
#include "graphics/RenderableObject.h"
|
2006-04-23 16:14:18 -07:00
|
|
|
#include "graphics/Terrain.h"
|
2022-01-29 00:28:04 -08:00
|
|
|
#include "graphics/UnitManager.h"
|
2025-08-08 12:04:43 -07:00
|
|
|
#include "lib/posix/posix_types.h"
|
|
|
|
|
#include "lib/types.h"
|
|
|
|
|
#include "maths/MathUtil.h"
|
|
|
|
|
#include "maths/Vector3D.h"
|
2006-04-23 16:14:18 -07:00
|
|
|
#include "ps/Game.h"
|
|
|
|
|
#include "ps/World.h"
|
2010-05-27 16:31:03 -07:00
|
|
|
#include "simulation2/components/ICmpTerrain.h"
|
2025-08-02 12:24:35 -07:00
|
|
|
#include "simulation2/system/Component.h"
|
2025-08-08 12:04:43 -07:00
|
|
|
#include "simulation2/system/Entity.h"
|
|
|
|
|
#include "tools/atlas/GameInterface/Brushes.h"
|
|
|
|
|
#include "tools/atlas/GameInterface/CommandProc.h"
|
|
|
|
|
#include "tools/atlas/GameInterface/DeltaArray.h"
|
|
|
|
|
#include "tools/atlas/GameInterface/Messages.h"
|
|
|
|
|
#include "tools/atlas/GameInterface/Shareable.h"
|
|
|
|
|
#include "tools/atlas/GameInterface/SharedTypes.h"
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <vector>
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace AtlasMessage {
|
|
|
|
|
|
|
|
|
|
class TerrainArray : public DeltaArray2D<u16>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
void Init()
|
|
|
|
|
{
|
2023-09-26 13:10:40 -07:00
|
|
|
m_Heightmap = g_Game->GetWorld()->GetTerrain().GetHeightMap();
|
|
|
|
|
m_VertsPerSide = g_Game->GetWorld()->GetTerrain().GetVerticesPerSide();
|
2006-04-23 16:14:18 -07: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 11:48:32 -07:00
|
|
|
void RaiseVertex(ssize_t x, ssize_t y, int amount)
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
// Ignore out-of-bounds vertices
|
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 11:48:32 -07:00
|
|
|
if (size_t(x) >= size_t(m_VertsPerSide) || size_t(y) >= size_t(m_VertsPerSide))
|
2006-04-23 16:14:18 -07:00
|
|
|
return;
|
|
|
|
|
|
2019-09-18 08:02:36 -07:00
|
|
|
set(x, y, static_cast<u16>(Clamp(get(x,y) + amount, 0, 65535)));
|
2006-04-23 16:14:18 -07: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 11:48:32 -07:00
|
|
|
void MoveVertexTowards(ssize_t x, ssize_t y, int target, int amount)
|
2006-04-23 16:14:18 -07: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 11:48:32 -07:00
|
|
|
if (size_t(x) >= size_t(m_VertsPerSide) || size_t(y) >= size_t(m_VertsPerSide))
|
2006-04-23 16:14:18 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int h = get(x,y);
|
|
|
|
|
if (h < target)
|
|
|
|
|
h = std::min(target, h + amount);
|
|
|
|
|
else if (h > target)
|
|
|
|
|
h = std::max(target, h - amount);
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
|
2019-09-18 08:02:36 -07:00
|
|
|
set(x, y, static_cast<u16>(Clamp(h, 0, 65535)));
|
2006-04-23 16:14:18 -07: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 11:48:32 -07:00
|
|
|
void SetVertex(ssize_t x, ssize_t y, u16 value)
|
2006-04-23 16:14:18 -07: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 11:48:32 -07:00
|
|
|
if (size_t(x) >= size_t(m_VertsPerSide) || size_t(y) >= size_t(m_VertsPerSide))
|
2006-04-23 16:14:18 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
set(x,y, value);
|
|
|
|
|
}
|
|
|
|
|
|
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 11:48:32 -07:00
|
|
|
u16 GetVertex(ssize_t x, ssize_t y)
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
2019-09-18 08:02:36 -07:00
|
|
|
return get(Clamp<ssize_t>(x, 0, m_VertsPerSide - 1), Clamp<ssize_t>(y, 0, m_VertsPerSide - 1));
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
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 11:48:32 -07:00
|
|
|
u16 getOld(ssize_t x, ssize_t y)
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
return m_Heightmap[y*m_VertsPerSide + x];
|
|
|
|
|
}
|
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 11:48:32 -07:00
|
|
|
void setNew(ssize_t x, ssize_t y, const u16& val)
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
m_Heightmap[y*m_VertsPerSide + x] = val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u16* m_Heightmap;
|
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 11:48:32 -07:00
|
|
|
ssize_t m_VertsPerSide;
|
2006-04-23 16:14:18 -07:00
|
|
|
};
|
|
|
|
|
|
2010-08-05 13:43:31 -07:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-11-23 06:09:58 -08:00
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
BEGIN_COMMAND(AlterElevation)
|
2006-06-21 15:37:31 -07:00
|
|
|
{
|
2006-04-23 16:14:18 -07:00
|
|
|
TerrainArray m_TerrainDelta;
|
2012-04-17 15:35:34 -07:00
|
|
|
ssize_t m_i0, m_j0, m_i1, m_j1; // dirtied tiles (inclusive lower bound, exclusive upper)
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2006-06-21 15:37:31 -07:00
|
|
|
cAlterElevation()
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
m_TerrainDelta.Init();
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-27 16:31:03 -07:00
|
|
|
void MakeDirty()
|
|
|
|
|
{
|
2023-09-26 13:10:40 -07:00
|
|
|
g_Game->GetWorld()->GetTerrain().MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES);
|
2022-01-29 00:28:04 -08:00
|
|
|
g_Game->GetWorld()->GetUnitManager().MakeTerrainDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES);
|
2010-05-27 16:31:03 -07:00
|
|
|
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
2012-02-07 18:46:15 -08:00
|
|
|
if (cmpTerrain)
|
2010-05-27 16:31:03 -07:00
|
|
|
cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1);
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
void Do()
|
|
|
|
|
{
|
2006-05-03 19:44:03 -07:00
|
|
|
int amount = (int)msg->amount;
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
// If the framerate is very high, 'amount' is often very
|
|
|
|
|
// small (even zero) so the integer truncation is significant
|
|
|
|
|
static float roundingError = 0.0;
|
2006-05-03 19:44:03 -07:00
|
|
|
roundingError += msg->amount - (float)amount;
|
2006-04-23 16:14:18 -07:00
|
|
|
if (roundingError >= 1.f)
|
|
|
|
|
{
|
|
|
|
|
amount += (int)roundingError;
|
|
|
|
|
roundingError -= (float)(int)roundingError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static CVector3D previousPosition;
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 10:36:42 -07:00
|
|
|
g_CurrentBrush.m_Centre = msg->pos->GetWorldSpace(previousPosition);
|
2006-04-23 16:14:18 -07:00
|
|
|
previousPosition = g_CurrentBrush.m_Centre;
|
|
|
|
|
|
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 11:48:32 -07:00
|
|
|
ssize_t x0, y0;
|
2006-04-23 16:14:18 -07:00
|
|
|
g_CurrentBrush.GetBottomLeft(x0, y0);
|
|
|
|
|
|
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 11:48:32 -07:00
|
|
|
for (ssize_t dy = 0; dy < g_CurrentBrush.m_H; ++dy)
|
2010-05-27 16:31:03 -07: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 11:48:32 -07:00
|
|
|
for (ssize_t dx = 0; dx < g_CurrentBrush.m_W; ++dx)
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
// TODO: proper variable raise amount (store floats in terrain delta array?)
|
|
|
|
|
float b = g_CurrentBrush.Get(dx, dy);
|
|
|
|
|
if (b)
|
|
|
|
|
m_TerrainDelta.RaiseVertex(x0+dx, y0+dy, (int)(amount*b));
|
|
|
|
|
}
|
2010-05-27 16:31:03 -07:00
|
|
|
}
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2012-04-17 15:35:34 -07:00
|
|
|
m_i0 = x0 - 1;
|
|
|
|
|
m_j0 = y0 - 1;
|
2010-05-27 16:31:03 -07:00
|
|
|
m_i1 = x0 + g_CurrentBrush.m_W;
|
|
|
|
|
m_j1 = y0 + g_CurrentBrush.m_H;
|
|
|
|
|
MakeDirty();
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Undo()
|
|
|
|
|
{
|
|
|
|
|
m_TerrainDelta.Undo();
|
2010-05-27 16:31:03 -07:00
|
|
|
MakeDirty();
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Redo()
|
|
|
|
|
{
|
|
|
|
|
m_TerrainDelta.Redo();
|
2010-05-27 16:31:03 -07:00
|
|
|
MakeDirty();
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
2006-06-02 22:08:32 -07:00
|
|
|
void MergeIntoPrevious(cAlterElevation* prev)
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
prev->m_TerrainDelta.OverlayWith(m_TerrainDelta);
|
2010-05-27 16:31:03 -07:00
|
|
|
prev->m_i0 = std::min(prev->m_i0, m_i0);
|
|
|
|
|
prev->m_j0 = std::min(prev->m_j0, m_j0);
|
|
|
|
|
prev->m_i1 = std::max(prev->m_i1, m_i1);
|
|
|
|
|
prev->m_j1 = std::max(prev->m_j1, m_j1);
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
2006-06-21 15:37:31 -07:00
|
|
|
};
|
2006-04-23 16:14:18 -07:00
|
|
|
END_COMMAND(AlterElevation)
|
|
|
|
|
|
2010-08-05 13:43:31 -07:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-11-23 06:09:58 -08:00
|
|
|
|
2010-08-05 13:43:31 -07:00
|
|
|
BEGIN_COMMAND(SmoothElevation)
|
|
|
|
|
{
|
|
|
|
|
TerrainArray m_TerrainDelta;
|
2012-04-17 15:35:34 -07:00
|
|
|
ssize_t m_i0, m_j0, m_i1, m_j1; // dirtied tiles (inclusive lower bound, exclusive upper)
|
2010-08-05 13:43:31 -07:00
|
|
|
|
|
|
|
|
cSmoothElevation()
|
|
|
|
|
{
|
|
|
|
|
m_TerrainDelta.Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MakeDirty()
|
|
|
|
|
{
|
2023-09-26 13:10:40 -07:00
|
|
|
g_Game->GetWorld()->GetTerrain().MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES);
|
2022-01-29 00:28:04 -08:00
|
|
|
g_Game->GetWorld()->GetUnitManager().MakeTerrainDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES);
|
2010-08-05 13:43:31 -07:00
|
|
|
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
2012-02-07 18:46:15 -08:00
|
|
|
if (cmpTerrain)
|
2010-08-05 13:43:31 -07:00
|
|
|
cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Do()
|
|
|
|
|
{
|
|
|
|
|
int amount = (int)msg->amount;
|
|
|
|
|
|
|
|
|
|
// If the framerate is very high, 'amount' is often very
|
|
|
|
|
// small (even zero) so the integer truncation is significant
|
|
|
|
|
static float roundingError = 0.0;
|
|
|
|
|
roundingError += msg->amount - (float)amount;
|
|
|
|
|
if (roundingError >= 1.f)
|
|
|
|
|
{
|
|
|
|
|
amount += (int)roundingError;
|
|
|
|
|
roundingError -= (float)(int)roundingError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static CVector3D previousPosition;
|
|
|
|
|
g_CurrentBrush.m_Centre = msg->pos->GetWorldSpace(previousPosition);
|
|
|
|
|
previousPosition = g_CurrentBrush.m_Centre;
|
|
|
|
|
|
|
|
|
|
ssize_t x0, y0;
|
|
|
|
|
g_CurrentBrush.GetBottomLeft(x0, y0);
|
|
|
|
|
|
|
|
|
|
if (g_CurrentBrush.m_H > 2)
|
|
|
|
|
{
|
|
|
|
|
std::vector<float> terrainDeltas;
|
|
|
|
|
ssize_t num = (g_CurrentBrush.m_H - 2) * (g_CurrentBrush.m_W - 2);
|
|
|
|
|
terrainDeltas.resize(num);
|
|
|
|
|
|
|
|
|
|
// For each vertex, compute the average of the 9 adjacent vertices
|
|
|
|
|
for (ssize_t dy = 0; dy < g_CurrentBrush.m_H; ++dy)
|
|
|
|
|
{
|
|
|
|
|
for (ssize_t dx = 0; dx < g_CurrentBrush.m_W; ++dx)
|
|
|
|
|
{
|
|
|
|
|
float delta = m_TerrainDelta.GetVertex(x0+dx, y0+dy) / 9.0f;
|
|
|
|
|
ssize_t x1_min = std::max((ssize_t)1, dx - 1);
|
|
|
|
|
ssize_t x1_max = std::min(dx + 1, g_CurrentBrush.m_W - 2);
|
|
|
|
|
ssize_t y1_min = std::max((ssize_t)1, dy - 1);
|
|
|
|
|
ssize_t y1_max = std::min(dy + 1, g_CurrentBrush.m_H - 2);
|
|
|
|
|
|
|
|
|
|
for (ssize_t yy = y1_min; yy <= y1_max; ++yy)
|
|
|
|
|
{
|
|
|
|
|
for (ssize_t xx = x1_min; xx <= x1_max; ++xx)
|
|
|
|
|
{
|
|
|
|
|
ssize_t index = (yy-1)*(g_CurrentBrush.m_W-2) + (xx-1);
|
|
|
|
|
terrainDeltas[index] += delta;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Move each vertex towards the computed average of its neighbours
|
|
|
|
|
for (ssize_t dy = 1; dy < g_CurrentBrush.m_H - 1; ++dy)
|
|
|
|
|
{
|
|
|
|
|
for (ssize_t dx = 1; dx < g_CurrentBrush.m_W - 1; ++dx)
|
|
|
|
|
{
|
|
|
|
|
ssize_t index = (dy-1)*(g_CurrentBrush.m_W-2) + (dx-1);
|
|
|
|
|
float b = g_CurrentBrush.Get(dx, dy);
|
|
|
|
|
if (b)
|
|
|
|
|
m_TerrainDelta.MoveVertexTowards(x0+dx, y0+dy, (int)terrainDeltas[index], (int)(amount*b));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_i0 = x0;
|
|
|
|
|
m_j0 = y0;
|
2012-04-17 15:35:34 -07:00
|
|
|
m_i1 = x0 + g_CurrentBrush.m_W - 1;
|
|
|
|
|
m_j1 = y0 + g_CurrentBrush.m_H - 1;
|
2010-08-05 13:43:31 -07:00
|
|
|
MakeDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Undo()
|
|
|
|
|
{
|
|
|
|
|
m_TerrainDelta.Undo();
|
|
|
|
|
MakeDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Redo()
|
|
|
|
|
{
|
|
|
|
|
m_TerrainDelta.Redo();
|
|
|
|
|
MakeDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MergeIntoPrevious(cSmoothElevation* prev)
|
|
|
|
|
{
|
|
|
|
|
prev->m_TerrainDelta.OverlayWith(m_TerrainDelta);
|
|
|
|
|
prev->m_i0 = std::min(prev->m_i0, m_i0);
|
|
|
|
|
prev->m_j0 = std::min(prev->m_j0, m_j0);
|
|
|
|
|
prev->m_i1 = std::max(prev->m_i1, m_i1);
|
|
|
|
|
prev->m_j1 = std::max(prev->m_j1, m_j1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
END_COMMAND(SmoothElevation)
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
BEGIN_COMMAND(FlattenElevation)
|
2006-06-21 15:37:31 -07:00
|
|
|
{
|
2006-04-23 16:14:18 -07:00
|
|
|
TerrainArray m_TerrainDelta;
|
2012-04-17 15:35:34 -07:00
|
|
|
ssize_t m_i0, m_j0, m_i1, m_j1; // dirtied tiles (inclusive lower bound, exclusive upper)
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2006-06-21 15:37:31 -07:00
|
|
|
cFlattenElevation()
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
m_TerrainDelta.Init();
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-27 16:31:03 -07:00
|
|
|
void MakeDirty()
|
|
|
|
|
{
|
2023-09-26 13:10:40 -07:00
|
|
|
g_Game->GetWorld()->GetTerrain().MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES);
|
2022-01-29 00:28:04 -08:00
|
|
|
g_Game->GetWorld()->GetUnitManager().MakeTerrainDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES);
|
2010-05-27 16:31:03 -07:00
|
|
|
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
2012-02-07 18:46:15 -08:00
|
|
|
if (cmpTerrain)
|
2010-05-27 16:31:03 -07:00
|
|
|
cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1);
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
void Do()
|
|
|
|
|
{
|
2006-05-03 19:44:03 -07:00
|
|
|
int amount = (int)msg->amount;
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
static CVector3D previousPosition;
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 10:36:42 -07:00
|
|
|
g_CurrentBrush.m_Centre = msg->pos->GetWorldSpace(previousPosition);
|
2006-04-23 16:14:18 -07:00
|
|
|
previousPosition = g_CurrentBrush.m_Centre;
|
|
|
|
|
|
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 11:48:32 -07:00
|
|
|
ssize_t xc, yc;
|
2006-04-23 16:14:18 -07:00
|
|
|
g_CurrentBrush.GetCentre(xc, yc);
|
|
|
|
|
u16 height = m_TerrainDelta.GetVertex(xc, yc);
|
|
|
|
|
|
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 11:48:32 -07:00
|
|
|
ssize_t x0, y0;
|
2006-04-23 16:14:18 -07:00
|
|
|
g_CurrentBrush.GetBottomLeft(x0, y0);
|
|
|
|
|
|
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 11:48:32 -07:00
|
|
|
for (ssize_t dy = 0; dy < g_CurrentBrush.m_H; ++dy)
|
2012-04-17 15:35:34 -07: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 11:48:32 -07:00
|
|
|
for (ssize_t dx = 0; dx < g_CurrentBrush.m_W; ++dx)
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
float b = g_CurrentBrush.Get(dx, dy);
|
|
|
|
|
if (b)
|
|
|
|
|
m_TerrainDelta.MoveVertexTowards(x0+dx, y0+dy, height, 1 + (int)(b*amount));
|
|
|
|
|
}
|
2012-04-17 15:35:34 -07:00
|
|
|
}
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2012-04-17 15:35:34 -07:00
|
|
|
m_i0 = x0 - 1;
|
|
|
|
|
m_j0 = y0 - 1;
|
2010-05-27 16:31:03 -07:00
|
|
|
m_i1 = x0 + g_CurrentBrush.m_W;
|
|
|
|
|
m_j1 = y0 + g_CurrentBrush.m_H;
|
|
|
|
|
MakeDirty();
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Undo()
|
|
|
|
|
{
|
|
|
|
|
m_TerrainDelta.Undo();
|
2010-05-27 16:31:03 -07:00
|
|
|
MakeDirty();
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Redo()
|
|
|
|
|
{
|
|
|
|
|
m_TerrainDelta.Redo();
|
2010-05-27 16:31:03 -07:00
|
|
|
MakeDirty();
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
2006-06-02 22:08:32 -07:00
|
|
|
void MergeIntoPrevious(cFlattenElevation* prev)
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
|
|
|
|
prev->m_TerrainDelta.OverlayWith(m_TerrainDelta);
|
2010-05-27 16:31:03 -07:00
|
|
|
prev->m_i0 = std::min(prev->m_i0, m_i0);
|
|
|
|
|
prev->m_j0 = std::min(prev->m_j0, m_j0);
|
|
|
|
|
prev->m_i1 = std::max(prev->m_i1, m_i1);
|
|
|
|
|
prev->m_j1 = std::max(prev->m_j1, m_j1);
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
2006-06-21 15:37:31 -07:00
|
|
|
};
|
2006-04-23 16:14:18 -07:00
|
|
|
END_COMMAND(FlattenElevation)
|
|
|
|
|
|
2013-08-16 07:46:54 -07:00
|
|
|
|
|
|
|
|
BEGIN_COMMAND(PikeElevation)
|
|
|
|
|
{
|
|
|
|
|
TerrainArray m_TerrainDelta;
|
|
|
|
|
ssize_t m_i0, m_j0, m_i1, m_j1; // dirtied tiles (inclusive lower bound, exclusive upper)
|
|
|
|
|
|
|
|
|
|
cPikeElevation()
|
|
|
|
|
{
|
|
|
|
|
m_TerrainDelta.Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MakeDirty()
|
|
|
|
|
{
|
2023-09-26 13:10:40 -07:00
|
|
|
g_Game->GetWorld()->GetTerrain().MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES);
|
2022-01-29 00:28:04 -08:00
|
|
|
g_Game->GetWorld()->GetUnitManager().MakeTerrainDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES);
|
2013-08-16 07:46:54 -07:00
|
|
|
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
|
|
|
|
if (cmpTerrain)
|
|
|
|
|
cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Do()
|
|
|
|
|
{
|
|
|
|
|
int amount = (int)msg->amount;
|
|
|
|
|
|
|
|
|
|
// If the framerate is very high, 'amount' is often very
|
|
|
|
|
// small (even zero) so the integer truncation is significant
|
|
|
|
|
static float roundingError = 0.0;
|
|
|
|
|
roundingError += msg->amount - (float)amount;
|
|
|
|
|
if (roundingError >= 1.f)
|
|
|
|
|
{
|
|
|
|
|
amount += (int)roundingError;
|
|
|
|
|
roundingError -= (float)(int)roundingError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static CVector3D previousPosition;
|
|
|
|
|
g_CurrentBrush.m_Centre = msg->pos->GetWorldSpace(previousPosition);
|
|
|
|
|
previousPosition = g_CurrentBrush.m_Centre;
|
|
|
|
|
|
|
|
|
|
ssize_t x0, y0;
|
|
|
|
|
g_CurrentBrush.GetBottomLeft(x0, y0);
|
|
|
|
|
float h = ((float) g_CurrentBrush.m_H - 1) / 2.f;
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
float x = (float)dx - ((float)g_CurrentBrush.m_H - 1) / 2.f;
|
|
|
|
|
float y = (float)dy - ((float)g_CurrentBrush.m_W - 1) / 2.f;
|
2019-09-18 08:02:36 -07:00
|
|
|
float distance = Clamp(1 - static_cast<float>(sqrt(x * x + y * y)) / h, 0.01f, 1.0f);
|
2013-08-17 07:02:18 -07:00
|
|
|
distance *= distance;
|
2013-08-16 07:46:54 -07:00
|
|
|
m_TerrainDelta.RaiseVertex(x0 + dx, y0 + dy, (int)(amount * distance));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_i0 = x0 - 1;
|
|
|
|
|
m_j0 = y0 - 1;
|
|
|
|
|
m_i1 = x0 + g_CurrentBrush.m_W;
|
|
|
|
|
m_j1 = y0 + g_CurrentBrush.m_H;
|
|
|
|
|
MakeDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Undo()
|
|
|
|
|
{
|
|
|
|
|
m_TerrainDelta.Undo();
|
|
|
|
|
MakeDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Redo()
|
|
|
|
|
{
|
|
|
|
|
m_TerrainDelta.Redo();
|
|
|
|
|
MakeDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MergeIntoPrevious(cPikeElevation* prev)
|
|
|
|
|
{
|
|
|
|
|
prev->m_TerrainDelta.OverlayWith(m_TerrainDelta);
|
|
|
|
|
prev->m_i0 = std::min(prev->m_i0, m_i0);
|
|
|
|
|
prev->m_j0 = std::min(prev->m_j0, m_j0);
|
|
|
|
|
prev->m_i1 = std::max(prev->m_i1, m_i1);
|
|
|
|
|
prev->m_j1 = std::max(prev->m_j1, m_j1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
END_COMMAND(PikeElevation)
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|