Changeset View
Changeset View
Standalone View
Standalone View
source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp
Show All 25 Lines | |||||
#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/MiniMapTexture.h" | #include "graphics/MiniMapTexture.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 "graphics/Water.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/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/SceneRenderer.h" | #include "renderer/SceneRenderer.h" | ||||
#include "renderer/WaterManager.h" | #include "renderer/WaterRenderer.h" | ||||
#include "scriptinterface/Object.h" | #include "scriptinterface/Object.h" | ||||
#include "scriptinterface/JSON.h" | #include "scriptinterface/JSON.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/components/ICmpOwnership.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" | ||||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | MESSAGEHANDLER(ImportHeightmap) | ||||
// 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); | ||||
g_Game->GetWorld()->GetWater()->SetMapSize(terrain->GetTilesPerSide()); | |||||
// 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(), | ||||
&g_Renderer.GetSceneRenderer().GetWaterManager(), &g_Renderer.GetSceneRenderer().GetSkyManager(), | &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) | ||||
{ | { | ||||
msg->settings = g_Game->GetSimulation2()->GetMapSettingsString(); | msg->settings = g_Game->GetSimulation2()->GetMapSettingsString(); | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | QUERYHANDLER(RasterizeMinimap) | ||||
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_Game->GetWorld()->GetWater()->GetWaterHeight(); | ||||
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) | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | void MakeDirty() | ||||
// (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); | ||||
g_Game->GetWorld()->GetWater()->SetMapSize(terrain->GetTilesPerSide()); | |||||
} | } | ||||
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