Changeset View
Changeset View
Standalone View
Standalone View
source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp
Show First 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | MESSAGEHANDLER(ImportHeightmap) | ||||
{ | { | ||||
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(); | ||||
const ssize_t newSize = (sqrt(heightmap_source.size()) - 1) / PATCH_SIZE; | const ssize_t newSize = (sqrt(heightmap_source.size()) - 1) / PATCH_SIZE; | ||||
const ssize_t offset = (newSize - terrain->GetPatchesPerSide()) / 2; | const ssize_t offset = (newSize - terrain.GetPatchesPerSide()) / 2; | ||||
terrain->ResizeAndOffset(newSize, offset, offset); | terrain.ResizeAndOffset(newSize, offset, offset); | ||||
// 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); | ||||
if (cmpTerrain) | if (cmpTerrain) | ||||
cmpTerrain->ReloadTerrain(); | cmpTerrain->ReloadTerrain(); | ||||
g_Game->GetView()->GetLOSTexture().MakeDirty(); | g_Game->GetView()->GetLOSTexture().MakeDirty(); | ||||
} | } | ||||
MESSAGEHANDLER(SaveMap) | MESSAGEHANDLER(SaveMap) | ||||
{ | { | ||||
CMapWriter writer; | CMapWriter writer; | ||||
VfsPath pathname = VfsPath(*msg->filename).ChangeExtension(L".pmp"); | VfsPath pathname = VfsPath(*msg->filename).ChangeExtension(L".pmp"); | ||||
writer.SaveMap(pathname, | writer.SaveMap(pathname, | ||||
g_Game->GetWorld()->GetTerrain(), | &g_Game->GetWorld()->GetTerrain(), | ||||
&g_Renderer.GetSceneRenderer().GetWaterManager(), &g_Renderer.GetSceneRenderer().GetSkyManager(), | &g_Renderer.GetSceneRenderer().GetWaterManager(), &g_Renderer.GetSceneRenderer().GetSkyManager(), | ||||
&g_LightEnv, g_Game->GetView()->GetCamera(), g_Game->GetView()->GetCinema(), | &g_LightEnv, g_Game->GetView()->GetCamera(), g_Game->GetView()->GetCinema(), | ||||
&g_Renderer.GetPostprocManager(), | &g_Renderer.GetPostprocManager(), | ||||
g_Game->GetSimulation2()); | g_Game->GetSimulation2()); | ||||
} | } | ||||
QUERYHANDLER(GetMapSettings) | QUERYHANDLER(GetMapSettings) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
msg->sizes = g_Game->GetSimulation2()->GetMapSizes(); | msg->sizes = g_Game->GetSimulation2()->GetMapSizes(); | ||||
} | } | ||||
QUERYHANDLER(RasterizeMinimap) | QUERYHANDLER(RasterizeMinimap) | ||||
{ | { | ||||
// TODO: remove the code duplication of the rasterization algorithm, using | // TODO: remove the code duplication of the rasterization algorithm, using | ||||
// CMinimap version. | // CMinimap version. | ||||
const CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); | ||||
const ssize_t dimension = terrain->GetVerticesPerSide() - 1; | const ssize_t dimension = terrain.GetVerticesPerSide() - 1; | ||||
const ssize_t bpp = 24; | const ssize_t bpp = 24; | ||||
const ssize_t imageDataSize = dimension * dimension * (bpp / 8); | const ssize_t imageDataSize = dimension * dimension * (bpp / 8); | ||||
std::vector<u8> imageBytes(imageDataSize); | std::vector<u8> imageBytes(imageDataSize); | ||||
float shallowPassageHeight = CMiniMapTexture::GetShallowPassageHeight(); | float shallowPassageHeight = CMiniMapTexture::GetShallowPassageHeight(); | ||||
ssize_t w = dimension; | ssize_t w = dimension; | ||||
ssize_t h = dimension; | ssize_t h = dimension; | ||||
const float waterHeight = g_Renderer.GetSceneRenderer().GetWaterManager().m_WaterHeight; | const float waterHeight = g_Renderer.GetSceneRenderer().GetWaterManager().m_WaterHeight; | ||||
for (ssize_t j = 0; j < h; ++j) | for (ssize_t j = 0; j < h; ++j) | ||||
{ | { | ||||
// Work backwards to vertically flip the image. | // Work backwards to vertically flip the image. | ||||
ssize_t position = 3 * (h - j - 1) * dimension; | ssize_t position = 3 * (h - j - 1) * dimension; | ||||
for (ssize_t i = 0; i < w; ++i) | for (ssize_t i = 0; i < w; ++i) | ||||
{ | { | ||||
float avgHeight = (terrain->GetVertexGroundLevel(i, j) | float avgHeight = (terrain.GetVertexGroundLevel(i, j) | ||||
+ terrain->GetVertexGroundLevel(i + 1, j) | + terrain.GetVertexGroundLevel(i + 1, j) | ||||
+ terrain->GetVertexGroundLevel(i, j + 1) | + terrain.GetVertexGroundLevel(i, j + 1) | ||||
+ terrain->GetVertexGroundLevel(i + 1, j + 1) | + terrain.GetVertexGroundLevel(i + 1, j + 1) | ||||
vladislavbelov: `const` while at it. | |||||
) / 4.0f; | ) / 4.0f; | ||||
if (avgHeight < waterHeight && avgHeight > waterHeight - shallowPassageHeight) | if (avgHeight < waterHeight && avgHeight > waterHeight - shallowPassageHeight) | ||||
{ | { | ||||
// shallow water | // shallow water | ||||
imageBytes[position++] = 0x70; | imageBytes[position++] = 0x70; | ||||
imageBytes[position++] = 0x98; | imageBytes[position++] = 0x98; | ||||
imageBytes[position++] = 0xc0; | imageBytes[position++] = 0xc0; | ||||
} | } | ||||
else if (avgHeight < waterHeight) | else if (avgHeight < waterHeight) | ||||
{ | { | ||||
// Set water as constant color for consistency on different maps | // Set water as constant color for consistency on different maps | ||||
imageBytes[position++] = 0x50; | imageBytes[position++] = 0x50; | ||||
imageBytes[position++] = 0x78; | imageBytes[position++] = 0x78; | ||||
imageBytes[position++] = 0xa0; | imageBytes[position++] = 0xa0; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
u32 color = std::numeric_limits<u32>::max(); | u32 color = std::numeric_limits<u32>::max(); | ||||
u32 hmap = static_cast<u32>(terrain->GetHeightMap()[j * dimension + i]) >> 8; | u32 hmap = static_cast<u32>(terrain.GetHeightMap()[j * dimension + i]) >> 8; | ||||
float scale = hmap / 3.0f + 170.0f / 255.0f; | float scale = hmap / 3.0f + 170.0f / 255.0f; | ||||
CMiniPatch* mp = terrain->GetTile(i, j); | CMiniPatch* mp = terrain.GetTile(i, j); | ||||
if (mp) | if (mp) | ||||
{ | { | ||||
CTerrainTextureEntry* tex = mp->GetTextureEntry(); | CTerrainTextureEntry* tex = mp->GetTextureEntry(); | ||||
if (tex) | if (tex) | ||||
color = tex->GetBaseColor(); | color = tex->GetBaseColor(); | ||||
} | } | ||||
// Convert | // Convert | ||||
Show All 10 Lines | |||||
QUERYHANDLER(GetRMSData) | QUERYHANDLER(GetRMSData) | ||||
{ | { | ||||
msg->data = g_Game->GetSimulation2()->GetRMSData(); | msg->data = g_Game->GetSimulation2()->GetRMSData(); | ||||
} | } | ||||
QUERYHANDLER(GetCurrentMapSize) | QUERYHANDLER(GetCurrentMapSize) | ||||
{ | { | ||||
msg->size = g_Game->GetWorld()->GetTerrain()->GetTilesPerSide(); | msg->size = g_Game->GetWorld()->GetTerrain().GetTilesPerSide(); | ||||
} | } | ||||
BEGIN_COMMAND(ResizeMap) | BEGIN_COMMAND(ResizeMap) | ||||
{ | { | ||||
bool Within(const CFixedVector3D& pos, const int centerX, const int centerZ, const int radius) | bool Within(const CFixedVector3D& pos, const int centerX, const int centerZ, const int radius) | ||||
{ | { | ||||
int dx = abs(pos.X.ToInt_RoundToZero() - centerX); | int dx = abs(pos.X.ToInt_RoundToZero() - centerX); | ||||
if (dx > radius) | if (dx > radius) | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | void MakeDirty() | ||||
// 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(ssize_t patches, int offsetX, int offsetY) | void ResizeTerrain(ssize_t patches, int offsetX, int offsetY) | ||||
{ | { | ||||
CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); | ||||
terrain->ResizeAndOffset(patches, -offsetX, -offsetY); | terrain.ResizeAndOffset(patches, -offsetX, -offsetY); | ||||
} | } | ||||
void DeleteObjects(const std::vector<DeletedObject>& deletedObjects) | void DeleteObjects(const std::vector<DeletedObject>& deletedObjects) | ||||
{ | { | ||||
for (const DeletedObject& deleted : deletedObjects) | for (const DeletedObject& deleted : deletedObjects) | ||||
g_Game->GetSimulation2()->DestroyEntity(deleted.entityId); | g_Game->GetSimulation2()->DestroyEntity(deleted.entityId); | ||||
g_Game->GetSimulation2()->FlushDestroyedEntities(); | g_Game->GetSimulation2()->FlushDestroyedEntities(); | ||||
▲ Show 20 Lines • Show All 211 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
const while at it.