Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/MiniMapTexture.cpp
Show First 20 Lines • Show All 294 Lines • ▼ Show 20 Lines | void CMiniMapTexture::Update(const float UNUSED(deltaRealTime)) | ||||
{ | { | ||||
m_TerrainTextureDirty = true; | m_TerrainTextureDirty = true; | ||||
m_FinalTextureDirty = true; | m_FinalTextureDirty = true; | ||||
} | } | ||||
} | } | ||||
void CMiniMapTexture::Render(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) | void CMiniMapTexture::Render(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) | ||||
{ | { | ||||
const CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); | ||||
Stan: What happens in non visual mode? | |||||
phositAuthorUnsubmitted Done Inline ActionsIn non visual mode Render is not called phosit: In non visual mode Render is not called | |||||
if (!terrain) | |||||
return; | |||||
if (!m_TerrainTexture) | if (!m_TerrainTexture) | ||||
CreateTextures(deviceCommandContext, terrain); | CreateTextures(deviceCommandContext, terrain); | ||||
if (m_TerrainTextureDirty) | if (m_TerrainTextureDirty) | ||||
RebuildTerrainTexture(deviceCommandContext, terrain); | RebuildTerrainTexture(deviceCommandContext, terrain); | ||||
RenderFinalTexture(deviceCommandContext); | RenderFinalTexture(deviceCommandContext); | ||||
} | } | ||||
void CMiniMapTexture::CreateTextures( | void CMiniMapTexture::CreateTextures( | ||||
Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CTerrain* terrain) | Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CTerrain& terrain) | ||||
{ | { | ||||
DestroyTextures(); | DestroyTextures(); | ||||
m_MapSize = terrain->GetVerticesPerSide(); | m_MapSize = terrain.GetVerticesPerSide(); | ||||
const size_t textureSize = round_up_to_pow2(static_cast<size_t>(m_MapSize)); | const size_t textureSize = round_up_to_pow2(static_cast<size_t>(m_MapSize)); | ||||
const Renderer::Backend::Sampler::Desc defaultSamplerDesc = | const Renderer::Backend::Sampler::Desc defaultSamplerDesc = | ||||
Renderer::Backend::Sampler::MakeDefaultSampler( | Renderer::Backend::Sampler::MakeDefaultSampler( | ||||
Renderer::Backend::Sampler::Filter::LINEAR, | Renderer::Backend::Sampler::Filter::LINEAR, | ||||
Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE); | Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE); | ||||
Renderer::Backend::IDevice* backendDevice = deviceCommandContext->GetDevice(); | Renderer::Backend::IDevice* backendDevice = deviceCommandContext->GetDevice(); | ||||
Show All 28 Lines | |||||
{ | { | ||||
m_TerrainTexture.reset(); | m_TerrainTexture.reset(); | ||||
m_FinalTexture.reset(); | m_FinalTexture.reset(); | ||||
m_TerrainData.reset(); | m_TerrainData.reset(); | ||||
} | } | ||||
void CMiniMapTexture::RebuildTerrainTexture( | void CMiniMapTexture::RebuildTerrainTexture( | ||||
Renderer::Backend::IDeviceCommandContext* deviceCommandContext, | Renderer::Backend::IDeviceCommandContext* deviceCommandContext, | ||||
const CTerrain* terrain) | const CTerrain& terrain) | ||||
{ | { | ||||
const u32 x = 0; | const u32 x = 0; | ||||
const u32 y = 0; | const u32 y = 0; | ||||
const u32 width = m_MapSize - 1; | const u32 width = m_MapSize - 1; | ||||
const u32 height = m_MapSize - 1; | const u32 height = m_MapSize - 1; | ||||
m_WaterHeight = g_Renderer.GetSceneRenderer().GetWaterManager().m_WaterHeight; | m_WaterHeight = g_Renderer.GetSceneRenderer().GetWaterManager().m_WaterHeight; | ||||
m_TerrainTextureDirty = false; | m_TerrainTextureDirty = false; | ||||
for (u32 j = 0; j < height; ++j) | for (u32 j = 0; j < height; ++j) | ||||
{ | { | ||||
u32* dataPtr = m_TerrainData.get() + ((y + j) * width) + x; | u32* dataPtr = m_TerrainData.get() + ((y + j) * width) + x; | ||||
for (u32 i = 0; i < width; ++i) | for (u32 i = 0; i < width; ++i) | ||||
{ | { | ||||
const float avgHeight = ( terrain->GetVertexGroundLevel((int)i, (int)j) | const float avgHeight = ( | ||||
+ terrain->GetVertexGroundLevel((int)i+1, (int)j) | terrain.GetVertexGroundLevel(static_cast<int>(i), static_cast<int>(j)) | ||||
+ terrain->GetVertexGroundLevel((int)i, (int)j+1) | + terrain.GetVertexGroundLevel(static_cast<int>(i+1), static_cast<int>(j)) | ||||
+ terrain->GetVertexGroundLevel((int)i+1, (int)j+1) | + terrain.GetVertexGroundLevel(static_cast<int>(i), static_cast<int>(j+1)) | ||||
+ terrain.GetVertexGroundLevel(static_cast<int>(i+1), static_cast<int>(j+1)) | |||||
) / 4.0f; | ) / 4.0f; | ||||
if (avgHeight < m_WaterHeight && avgHeight > m_WaterHeight - m_ShallowPassageHeight) | if (avgHeight < m_WaterHeight && avgHeight > m_WaterHeight - m_ShallowPassageHeight) | ||||
{ | { | ||||
// shallow water | // shallow water | ||||
*dataPtr++ = 0xffc09870; | *dataPtr++ = 0xffc09870; | ||||
} | } | ||||
else if (avgHeight < m_WaterHeight) | else if (avgHeight < m_WaterHeight) | ||||
{ | { | ||||
// Set water as constant color for consistency on different maps | // Set water as constant color for consistency on different maps | ||||
*dataPtr++ = 0xffa07850; | *dataPtr++ = 0xffa07850; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
int hmap = ((int)terrain->GetHeightMap()[(y + j) * m_MapSize + x + i]) >> 8; | int hmap = static_cast<int>(terrain.GetHeightMap()[(y + j) * m_MapSize + x + i]) >> 8; | ||||
int val = (hmap / 3) + 170; | int val = (hmap / 3) + 170; | ||||
u32 color = 0xFFFFFFFF; | u32 color = 0xFFFFFFFF; | ||||
CMiniPatch* mp = terrain->GetTile(x + i, y + j); | CMiniPatch* mp = terrain.GetTile(x + i, y + j); | ||||
if (mp) | if (mp) | ||||
{ | { | ||||
CTerrainTextureEntry* tex = mp->GetTextureEntry(); | CTerrainTextureEntry* tex = mp->GetTextureEntry(); | ||||
if (tex) | if (tex) | ||||
{ | { | ||||
// If the texture can't be loaded yet, set the dirty flags | // If the texture can't be loaded yet, set the dirty flags | ||||
// so we'll try regenerating the terrain texture again soon | // so we'll try regenerating the terrain texture again soon | ||||
if (!tex->GetTexture()->TryLoad()) | if (!tex->GetTexture()->TryLoad()) | ||||
▲ Show 20 Lines • Show All 404 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
What happens in non visual mode?