Changeset View
Standalone View
source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp
Show All 12 Lines | |||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * 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/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "MessageHandler.h" | #include "MessageHandler.h" | ||||
#include "../GameLoop.h" | |||||
#include "../CommandProc.h" | #include "../CommandProc.h" | ||||
vladislavbelov: Use the alphabet order. | |||||
#include "../GameLoop.h" | |||||
#include "../MessagePasser.h" | |||||
#include "graphics/GameView.h" | #include "graphics/GameView.h" | ||||
#include "graphics/LOSTexture.h" | #include "graphics/LOSTexture.h" | ||||
#include "graphics/MapIO.h" | #include "graphics/MapIO.h" | ||||
#include "graphics/MapWriter.h" | #include "graphics/MapWriter.h" | ||||
#include "graphics/Patch.h" | #include "graphics/Patch.h" | ||||
#include "graphics/Terrain.h" | #include "graphics/Terrain.h" | ||||
#include "graphics/TerrainTextureEntry.h" | #include "graphics/TerrainTextureEntry.h" | ||||
#include "graphics/TerrainTextureManager.h" | #include "graphics/TerrainTextureManager.h" | ||||
#include "lib/bits.h" | #include "lib/bits.h" | ||||
#include "lib/file/vfs/vfs_path.h" | #include "lib/file/vfs/vfs_path.h" | ||||
#include "lib/status.h" | #include "lib/status.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/GameSetup/GameSetup.h" | |||||
#include "ps/Loader.h" | #include "ps/Loader.h" | ||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/WaterManager.h" | |||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/components/ICmpOwnership.h" | |||||
#include "simulation2/components/ICmpPlayer.h" | #include "simulation2/components/ICmpPlayer.h" | ||||
#include "simulation2/components/ICmpPlayerManager.h" | #include "simulation2/components/ICmpPlayerManager.h" | ||||
#include "simulation2/components/ICmpPosition.h" | #include "simulation2/components/ICmpPosition.h" | ||||
#include "simulation2/components/ICmpRangeManager.h" | #include "simulation2/components/ICmpRangeManager.h" | ||||
#include "simulation2/components/ICmpTemplateManager.h" | |||||
#include "simulation2/components/ICmpTerrain.h" | #include "simulation2/components/ICmpTerrain.h" | ||||
#include "simulation2/system/ParamNode.h" | |||||
namespace | namespace | ||||
{ | { | ||||
void InitGame() | void InitGame() | ||||
{ | { | ||||
if (g_Game) | if (g_Game) | ||||
{ | { | ||||
delete g_Game; | delete g_Game; | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | if (LoadHeightmapImageOs(*msg->filename, heightmap_source) != INFO::OK) | ||||
LOGERROR("Failed to decode heightmap."); | LOGERROR("Failed to decode heightmap."); | ||||
return; | return; | ||||
} | } | ||||
// resize terrain to heightmap size | // resize terrain to heightmap size | ||||
// Notice that the number of tiles/pixels per side of the heightmap image is | // Notice that the number of tiles/pixels per side of the heightmap image is | ||||
// one less than the number of vertices per side of the heightmap. | // one less than the number of vertices per side of the heightmap. | ||||
CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | ||||
terrain->Resize((sqrt(heightmap_source.size()) - 1) / PATCH_SIZE); | terrain->ResizeRecenter((sqrt(heightmap_source.size()) - 1) / PATCH_SIZE); | ||||
// copy heightmap data into map | // copy heightmap data into map | ||||
u16* heightmap = g_Game->GetWorld()->GetTerrain()->GetHeightMap(); | u16* heightmap = g_Game->GetWorld()->GetTerrain()->GetHeightMap(); | ||||
ENSURE(heightmap_source.size() == (std::size_t) SQR(g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide())); | ENSURE(heightmap_source.size() == (std::size_t) SQR(g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide())); | ||||
std::copy(heightmap_source.begin(), heightmap_source.end(), heightmap); | std::copy(heightmap_source.begin(), heightmap_source.end(), heightmap); | ||||
// update simulation | // update simulation | ||||
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); | CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
g_Game->GetSimulation2()->LoadPlayerSettings(msg->newplayers); | g_Game->GetSimulation2()->LoadPlayerSettings(msg->newplayers); | ||||
} | } | ||||
QUERYHANDLER(GetMapSizes) | QUERYHANDLER(GetMapSizes) | ||||
{ | { | ||||
msg->sizes = g_Game->GetSimulation2()->GetMapSizes(); | msg->sizes = g_Game->GetSimulation2()->GetMapSizes(); | ||||
} | } | ||||
QUERYHANDLER(RasterizeMinimap) | |||||
{ | |||||
const CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | |||||
const ssize_t dimension = terrain->GetVerticesPerSide() - 1; | |||||
const ssize_t bpp = 24; | |||||
const ssize_t buf_size = dimension * dimension * (bpp / 8); | |||||
std::vector<u8> imageBytes = std::vector<u8>(buf_size); | |||||
Done Inline Actionsstd::vector<u8> imageBytes(buf_size);. vladislavbelov: `std::vector<u8> imageBytes(buf_size);`. | |||||
// Stolen from MiniMap.cpp | |||||
Done Inline ActionsThat's bad, we might have a dissynchronization. I suggest to move the original code to a common static function of Minimap and reuse it here. vladislavbelov: That's bad, we might have a dissynchronization. I suggest to move the original code to a common… | |||||
float shallowPassageHeight = 0.0f; | |||||
// Get the maximum height for unit passage in water. | |||||
CParamNode externalParamNode; | |||||
CParamNode::LoadXML(externalParamNode, L"simulation/data/pathfinder.xml", "pathfinder"); | |||||
const CParamNode pathingSettings = externalParamNode.GetChild("Pathfinder").GetChild("PassabilityClasses"); | |||||
if (pathingSettings.GetChild("default").IsOk() && pathingSettings.GetChild("default").GetChild("MaxWaterDepth").IsOk()) | |||||
shallowPassageHeight = pathingSettings.GetChild("default").GetChild("MaxWaterDepth").ToFloat(); | |||||
ssize_t w = dimension; | |||||
ssize_t h = dimension; | |||||
float waterHeight = g_Renderer.GetWaterManager()->m_WaterHeight; | |||||
for (ssize_t j = 0; j < h; ++j) | |||||
{ | |||||
// Work backwards to vertically flip the image. | |||||
ssize_t position = 3 * (h - j - 1) * dimension; | |||||
for (ssize_t i = 0; i < w; ++i) | |||||
{ | |||||
float avgHeight = (terrain->GetVertexGroundLevel(i, j) | |||||
+ terrain->GetVertexGroundLevel(i + 1, j) | |||||
+ terrain->GetVertexGroundLevel(i, j + 1) | |||||
+ terrain->GetVertexGroundLevel(i + 1, j + 1) | |||||
) / 4.0f; | |||||
if (avgHeight < waterHeight && avgHeight > waterHeight - shallowPassageHeight) | |||||
{ | |||||
// shallow water | |||||
imageBytes[position++] = 0x70; | |||||
imageBytes[position++] = 0x98; | |||||
imageBytes[position++] = 0xc0; | |||||
} | |||||
else if (avgHeight < waterHeight) | |||||
{ | |||||
// Set water as constant color for consistency on different maps | |||||
imageBytes[position++] = 0x50; | |||||
imageBytes[position++] = 0x78; | |||||
imageBytes[position++] = 0xa0; | |||||
Done Inline ActionsAs I said below, raw pointers isn't the good practice for threaded applications. I'd prefer to use std::vector<u8> instead of this C-style. vladislavbelov: As I said below, raw pointers isn't the good practice for threaded applications. I'd prefer to… | |||||
} | |||||
else | |||||
{ | |||||
u32 color = std::numeric_limits<u32>::max(); | |||||
u32 hmap = static_cast<u32>(terrain->GetHeightMap()[j * dimension + i]) >> 8; | |||||
float scale = hmap / 3.0f + 170.0f / 255.0f; | |||||
CMiniPatch* mp = terrain->GetTile(i, j); | |||||
if (mp) | |||||
{ | |||||
CTerrainTextureEntry* tex = mp->GetTextureEntry(); | |||||
if (tex) | |||||
color = tex->GetBaseColor(); | |||||
} | |||||
// Convert | |||||
imageBytes[position++] = static_cast<u8>(static_cast<float>(color & 0xff) * scale); | |||||
Done Inline Actionsmsg->imageBytes = std::move(imageBytes); vladislavbelov: ```lang=cpp
msg->imageBytes = std::move(imageBytes);
``` | |||||
imageBytes[position++] = static_cast<u8>(static_cast<float>((color >> 8) & 0xff) * scale); | |||||
imageBytes[position++] = static_cast<u8>(static_cast<float>((color >> 16) & 0xff) * scale); | |||||
} | |||||
} | |||||
} | |||||
msg->imageBytes = imageBytes; | |||||
msg->dimension = dimension; | |||||
} | |||||
Done Inline ActionsMisleading name, it doesn't return display. I'd suggest to call it like DrawMinimap or RasterizeMinimap. vladislavbelov: Misleading name, it doesn't return display. I'd suggest to call it like `DrawMinimap` or… | |||||
QUERYHANDLER(GetRMSData) | QUERYHANDLER(GetRMSData) | ||||
{ | { | ||||
msg->data = g_Game->GetSimulation2()->GetRMSData(); | msg->data = g_Game->GetSimulation2()->GetRMSData(); | ||||
} | } | ||||
QUERYHANDLER(GetCurrentMapSize) | |||||
{ | |||||
msg->size = g_Game->GetWorld()->GetTerrain()->GetTilesPerSide(); | |||||
} | |||||
BEGIN_COMMAND(ResizeMap) | BEGIN_COMMAND(ResizeMap) | ||||
{ | { | ||||
int m_OldTiles, m_NewTiles; | bool Within(const CFixedVector3D& pos, const int centerX, const int centerZ, const int radius) | ||||
{ | |||||
int dx = abs(pos.X.ToInt_RoundToZero() - centerX); | |||||
if (dx > radius) | |||||
return false; | |||||
int dz = abs(pos.Z.ToInt_RoundToZero() - centerZ); | |||||
if (dz > radius) | |||||
return false; | |||||
if (dx + dz <= radius) | |||||
return true; | |||||
return (dx * dx + dz * dz <= radius * radius); | |||||
} | |||||
struct DeletedObject | |||||
{ | |||||
Done Inline ActionsUseless brackets. vladislavbelov: Useless brackets. | |||||
entity_id_t entityId; | |||||
CStr templateName; | |||||
int32_t owner; | |||||
CFixedVector3D pos; | |||||
CFixedVector3D rot; | |||||
}; | |||||
ssize_t m_OldPatches, m_NewPatches; | |||||
int m_OffsetX, m_OffsetY; | |||||
u16* m_Heightmap; | |||||
CPatch* m_Patches; | |||||
std::vector<DeletedObject> m_DeletedObjects; | |||||
Done Inline ActionsWhy void* and not u8? vladislavbelov: Why `void*` and not `u8`? | |||||
Done Inline ActionsBecause previously I was directly passing it into the destination wxImage, so just was working on the exact type I needed. Clockwork-Muse: Because previously I was directly passing it into the destination wxImage, so just was working… | |||||
std::vector<std::pair<entity_id_t, CFixedVector3D>> m_OldPositions; | |||||
std::vector<std::pair<entity_id_t, CFixedVector3D>> m_NewPositions; | |||||
Done Inline ActionsI suggest to rename test to position/pos. vladislavbelov: I suggest to rename `test` to `position`/`pos`. | |||||
cResizeMap() | cResizeMap() | ||||
{ | { | ||||
Done Inline ActionscResizeMap() : m_Heightmap(nullptr), m_Patches(nullptr) { } vladislavbelov: ```lang=cpp
cResizeMap() : m_Heightmap(nullptr), m_Patches(nullptr)
{
}
``` | |||||
} | } | ||||
~cResizeMap() | |||||
{ | |||||
delete m_Heightmap; | |||||
Done Inline ActionsA bit dangerous, these pointers aren't default initialized. vladislavbelov: A bit dangerous, these pointers aren't default initialized. | |||||
Done Inline ActionsHow should I do that ? Like this ? if(m_Heightmap != nullptr) delete m_Heightmap; if(m_Patches!= nullptr) delete m_Patches; Stan: How should I do that ?
Like this ?
```lang=cpp
if(m_Heightmap != nullptr)
delete… | |||||
Done Inline ActionsNo, I mean to initialize them in ctor by nullptr. vladislavbelov: No, I mean to initialize them in ctor by `nullptr`. | |||||
delete m_Patches; | |||||
} | |||||
void MakeDirty() | void MakeDirty() | ||||
{ | { | ||||
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); | CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); | ||||
if (cmpTerrain) | if (cmpTerrain) | ||||
cmpTerrain->ReloadTerrain(); | cmpTerrain->ReloadTerrain(); | ||||
// The LOS texture won't normally get updated when running Atlas | // The LOS texture won't normally get updated when running Atlas | ||||
// (since there's no simulation updates), so explicitly dirty it | // (since there's no simulation updates), so explicitly dirty it | ||||
g_Game->GetView()->GetLOSTexture().MakeDirty(); | g_Game->GetView()->GetLOSTexture().MakeDirty(); | ||||
} | } | ||||
void ResizeTerrain(int tiles) | |||||
void ResizeTerrain(ssize_t patches, int offsetX, int offsetY) | |||||
{ | { | ||||
CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | ||||
terrain->ResizeRecenter(patches, offsetX, offsetY); | |||||
} | |||||
terrain->Resize(tiles / PATCH_SIZE); | void DeleteAll(const std::vector<DeletedObject>& deletedObjects) | ||||
{ | |||||
for (const DeletedObject& deleted : deletedObjects) | |||||
{ | |||||
g_Game->GetSimulation2()->DestroyEntity(deleted.entityId); | |||||
} | |||||
MakeDirty(); | g_Game->GetSimulation2()->FlushDestroyedEntities(); | ||||
} | |||||
void UndeleteAll(const std::vector<DeletedObject>& deletedObjects) | |||||
{ | |||||
CSimulation2& sim = *g_Game->GetSimulation2(); | |||||
Done Inline ActionsRestoreAll? Also suffix All, why it's used for Delete and here, but not for SetPosition? Though there are no all entities in all these cases, only passed as argument. vladislavbelov: `RestoreAll`? Also suffix `All`, why it's used for `Delete` and here, but not for `SetPosition`? | |||||
for (const DeletedObject& deleted : deletedObjects) | |||||
{ | |||||
entity_id_t ent = sim.AddEntity(deleted.templateName.FromUTF8(), deleted.entityId); | |||||
if (ent == INVALID_ENTITY) | |||||
{ | |||||
LOGERROR("Failed to load entity template '%s'", deleted.templateName.c_str()); | |||||
} | |||||
else | |||||
{ | |||||
CmpPtr<ICmpPosition> cmpPosition(sim, deleted.entityId); | |||||
if (cmpPosition) | |||||
{ | |||||
cmpPosition->JumpTo(deleted.pos.X, deleted.pos.Z); | |||||
cmpPosition->SetXZRotation(deleted.rot.X, deleted.rot.Z); | |||||
cmpPosition->SetYRotation(deleted.rot.Y); | |||||
} | |||||
CmpPtr<ICmpOwnership> cmpOwnership(sim, deleted.entityId); | |||||
if (cmpOwnership) | |||||
cmpOwnership->SetOwner(deleted.owner); | |||||
} | |||||
} | |||||
} | |||||
void SetMovedEntitiesPosition(const std::vector<std::pair<entity_id_t, CFixedVector3D>>& movedObjects) | |||||
{ | |||||
for (std::pair<entity_id_t, CFixedVector3D> const& kv : movedObjects) | |||||
{ | |||||
Done Inline ActionsToo common name, maybe SetPositionOfMovedEntities? vladislavbelov: Too common name, maybe `SetPositionOfMovedEntities`? | |||||
entity_id_t id = kv.first; | |||||
CFixedVector3D position = kv.second; | |||||
CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id); | |||||
ENSURE(cmpPosition); | |||||
cmpPosition->JumpTo(position.X, position.Z); | |||||
} | |||||
} | } | ||||
void Do() | void Do() | ||||
{ | { | ||||
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); | CSimulation2& sim = *g_Game->GetSimulation2(); | ||||
CmpPtr<ICmpTemplateManager> cmpTemplateManager(sim, SYSTEM_ENTITY); | |||||
ENSURE(cmpTemplateManager); | |||||
CmpPtr<ICmpTerrain> cmpTerrain(sim, SYSTEM_ENTITY); | |||||
if (!cmpTerrain) | if (!cmpTerrain) | ||||
{ | { | ||||
m_OldTiles = m_NewTiles = 0; | m_OldPatches = m_NewPatches = 0; | ||||
m_OffsetX = m_OffsetY = 0; | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
m_OldTiles = (int)cmpTerrain->GetTilesPerSide(); | m_OldPatches = static_cast<ssize_t>(cmpTerrain->GetTilesPerSide() / PATCH_SIZE); | ||||
m_NewTiles = msg->tiles; | m_NewPatches = msg->tiles / PATCH_SIZE; | ||||
m_OffsetX = msg->offsetX / PATCH_SIZE; | |||||
// Need to flip direction of vertical offset, due to screen mapping order. | |||||
m_OffsetY = -(msg->offsetY / PATCH_SIZE); | |||||
CTerrain* terrain = cmpTerrain->GetCTerrain(); | |||||
m_Heightmap = new u16[(m_OldPatches * PATCH_SIZE + 1) * (m_OldPatches * PATCH_SIZE + 1)]; | |||||
std::copy_n(terrain->GetHeightMap(), (m_OldPatches * PATCH_SIZE + 1) * (m_OldPatches * PATCH_SIZE + 1), m_Heightmap); | |||||
m_Patches = new CPatch[m_OldPatches * m_OldPatches]; | |||||
for (ssize_t j = 0; j < m_OldPatches; ++j) | |||||
{ | |||||
for (ssize_t i = 0; i < m_OldPatches; ++i) | |||||
{ | |||||
CPatch& src = *(terrain->GetPatch(i, j)); | |||||
CPatch& dst = m_Patches[j * m_OldPatches + i]; | |||||
std::copy_n(&src.m_MiniPatches[0][0], PATCH_SIZE * PATCH_SIZE, &dst.m_MiniPatches[0][0]); | |||||
} | |||||
} | } | ||||
} | |||||
const int radiusInTerrainUnits = m_NewPatches * PATCH_SIZE * TERRAIN_TILE_SIZE / 2 * (1.f - 1e-6f); | |||||
// Opposite direction offset, as we move the destination onto the source, not the source into the destination. | |||||
const int mapCenterX = (m_OldPatches / 2 - m_OffsetX) * PATCH_SIZE * TERRAIN_TILE_SIZE; | |||||
const int mapCenterZ = (m_OldPatches / 2 - m_OffsetY) * PATCH_SIZE * TERRAIN_TILE_SIZE; | |||||
// The offset to move units by is opposite the direction the map is moved, and from the corner. | |||||
const int offsetX = ((m_NewPatches - m_OldPatches) / 2 + m_OffsetX) * PATCH_SIZE * TERRAIN_TILE_SIZE; | |||||
const int offsetZ = ((m_NewPatches - m_OldPatches) / 2 + m_OffsetY) * PATCH_SIZE * TERRAIN_TILE_SIZE; | |||||
const CFixedVector3D offset = CFixedVector3D(fixed::FromInt(offsetX), fixed::FromInt(0), fixed::FromInt(offsetZ)); | |||||
const CSimulation2::InterfaceListUnordered& ents = sim.GetEntitiesWithInterfaceUnordered(IID_Selectable); | |||||
for (std::pair<entity_id_t, IComponent*> const& kv : ents) | |||||
{ | |||||
const entity_id_t entityId = kv.first; | |||||
CmpPtr<ICmpPosition> cmpPosition(sim, entityId); | |||||
ResizeTerrain(m_NewTiles); | if (cmpPosition && cmpPosition->IsInWorld() && Within(cmpPosition->GetPosition(), mapCenterX, mapCenterZ, radiusInTerrainUnits)) | ||||
{ | |||||
CFixedVector3D position = cmpPosition->GetPosition(); | |||||
m_NewPositions.emplace_back(entityId, position + offset); | |||||
m_OldPositions.emplace_back(entityId, position); | |||||
} | } | ||||
else | |||||
{ | |||||
DeletedObject deleted; | |||||
deleted.entityId = entityId; | |||||
deleted.templateName = cmpTemplateManager->GetCurrentTemplateName(entityId); | |||||
// If the entity has a position, but the ending position is not valid; | |||||
if (cmpPosition) | |||||
{ | |||||
deleted.pos = cmpPosition->GetPosition(); | |||||
deleted.rot = cmpPosition->GetRotation(); | |||||
} | |||||
CmpPtr<ICmpOwnership> cmpOwnership(sim, entityId); | |||||
if (cmpOwnership) | |||||
deleted.owner = cmpOwnership->GetOwner(); | |||||
m_DeletedObjects.push_back(deleted); | |||||
} | |||||
} | |||||
DeleteAll(m_DeletedObjects); | |||||
ResizeTerrain(m_NewPatches, m_OffsetX, m_OffsetY); | |||||
SetMovedEntitiesPosition(m_NewPositions); | |||||
MakeDirty(); | |||||
} | |||||
void Undo() | void Undo() | ||||
{ | { | ||||
Done Inline ActionsThe auto isn't preferred for this cases, because the name or the type doesn't tell about itself. vladislavbelov: The `auto` isn't preferred for this cases, because the name or the type doesn't tell about… | |||||
ResizeTerrain(m_OldTiles); | if (m_Heightmap == nullptr || m_Patches == nullptr) | ||||
{ | |||||
// If there previously was no data, just resize to old (probably not originally valid). | |||||
ResizeTerrain(m_OldPatches, -m_OffsetX, -m_OffsetY); | |||||
} | |||||
else | |||||
{ | |||||
CSimulation2& sim = *g_Game->GetSimulation2(); | |||||
CmpPtr<ICmpTerrain> cmpTerrain(sim, SYSTEM_ENTITY); | |||||
CTerrain* terrain = cmpTerrain->GetCTerrain(); | |||||
terrain->Initialize(m_OldPatches, m_Heightmap); | |||||
// Copy terrain data back. | |||||
for (ssize_t j = 0; j < m_OldPatches; ++j) | |||||
{ | |||||
for (ssize_t i = 0; i < m_OldPatches; ++i) | |||||
{ | |||||
CPatch& src = m_Patches[j * m_OldPatches + i]; | |||||
CPatch& dst = *(terrain->GetPatch(i, j)); | |||||
std::copy_n(&src.m_MiniPatches[0][0], PATCH_SIZE * PATCH_SIZE, &dst.m_MiniPatches[0][0]); | |||||
} | |||||
} | |||||
} | |||||
UndeleteAll(m_DeletedObjects); | |||||
SetMovedEntitiesPosition(m_OldPositions); | |||||
MakeDirty(); | |||||
} | } | ||||
void Redo() | void Redo() | ||||
{ | { | ||||
ResizeTerrain(m_NewTiles); | DeleteAll(m_DeletedObjects); | ||||
ResizeTerrain(m_NewPatches, m_OffsetX, m_OffsetY); | |||||
SetMovedEntitiesPosition(m_NewPositions); | |||||
MakeDirty(); | |||||
} | } | ||||
}; | }; | ||||
END_COMMAND(ResizeMap) | END_COMMAND(ResizeMap) | ||||
QUERYHANDLER(VFSFileExists) | QUERYHANDLER(VFSFileExists) | ||||
{ | { | ||||
msg->exists = VfsFileExists(*msg->path); | msg->exists = VfsFileExists(*msg->path); | ||||
} | } | ||||
QUERYHANDLER(VFSFileRealPath) | QUERYHANDLER(VFSFileRealPath) | ||||
{ | { | ||||
VfsPath pathname(*msg->path); | VfsPath pathname(*msg->path); | ||||
if (pathname.empty()) | if (pathname.empty()) | ||||
return; | return; | ||||
Done Inline ActionsWon't entities be re-added? vladislavbelov: Won't entities be re-added? | |||||
Done Inline ActionsI don't understand your comment? What are you getting at here? Clockwork-Muse: I don't understand your comment? What are you getting at here? | |||||
OsPath realPathname; | OsPath realPathname; | ||||
if (g_VFS->GetRealPath(pathname, realPathname) == INFO::OK) | if (g_VFS->GetRealPath(pathname, realPathname) == INFO::OK) | ||||
msg->realPath = realPathname.string(); | msg->realPath = realPathname.string(); | ||||
} | } | ||||
static Status AddToFilenames(const VfsPath& pathname, const CFileInfo& UNUSED(fileInfo), const uintptr_t cbData) | static Status AddToFilenames(const VfsPath& pathname, const CFileInfo& UNUSED(fileInfo), const uintptr_t cbData) | ||||
{ | { | ||||
std::vector<std::wstring>& filenames = *(std::vector<std::wstring>*)cbData; | std::vector<std::wstring>& filenames = *(std::vector<std::wstring>*)cbData; | ||||
Show All 18 Lines |
Use the alphabet order.