Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/PatchRData.cpp
Show All 40 Lines | |||||
#include "ps/VideoMode.h" | #include "ps/VideoMode.h" | ||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "renderer/AlphaMapCalculator.h" | #include "renderer/AlphaMapCalculator.h" | ||||
#include "renderer/DebugRenderer.h" | #include "renderer/DebugRenderer.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/SceneRenderer.h" | #include "renderer/SceneRenderer.h" | ||||
#include "renderer/TerrainRenderer.h" | #include "renderer/TerrainRenderer.h" | ||||
#include "renderer/WaterRenderer.h" | #include "renderer/WaterRenderer.h" | ||||
#include "simulation2/components/ICmpWaterManager.h" | |||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <numeric> | #include <numeric> | ||||
#include <set> | #include <set> | ||||
const ssize_t BlendOffsets[9][2] = { | const ssize_t BlendOffsets[9][2] = { | ||||
{ 0, -1 }, | { 0, -1 }, | ||||
▲ Show 20 Lines • Show All 479 Lines • ▼ Show 20 Lines | void CPatchRData::BuildVertices() | ||||
m_VBBase->m_Owner->UpdateChunkVertices(m_VBBase.Get(), &vertices[0]); | m_VBBase->m_Owner->UpdateChunkVertices(m_VBBase.Get(), &vertices[0]); | ||||
} | } | ||||
void CPatchRData::BuildSide(std::vector<SSideVertex>& vertices, CPatchSideFlags side) | void CPatchRData::BuildSide(std::vector<SSideVertex>& vertices, CPatchSideFlags side) | ||||
{ | { | ||||
ssize_t vsize = PATCH_SIZE + 1; | ssize_t vsize = PATCH_SIZE + 1; | ||||
CTerrain* terrain = m_Patch->m_Parent; | CTerrain* terrain = m_Patch->m_Parent; | ||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*m_Simulation, SYSTEM_ENTITY); | CWater* water = g_Game->GetWorld()->GetWater(); | ||||
for (ssize_t k = 0; k < vsize; k++) | for (ssize_t k = 0; k < vsize; k++) | ||||
{ | { | ||||
ssize_t gx = m_Patch->m_X * PATCH_SIZE; | ssize_t gx = m_Patch->m_X * PATCH_SIZE; | ||||
ssize_t gz = m_Patch->m_Z * PATCH_SIZE; | ssize_t gz = m_Patch->m_Z * PATCH_SIZE; | ||||
switch (side) | switch (side) | ||||
{ | { | ||||
case CPATCH_SIDE_NEGX: gz += k; break; | case CPATCH_SIDE_NEGX: gz += k; break; | ||||
case CPATCH_SIDE_POSX: gx += PATCH_SIZE; gz += PATCH_SIZE-k; break; | case CPATCH_SIDE_POSX: gx += PATCH_SIZE; gz += PATCH_SIZE-k; break; | ||||
case CPATCH_SIDE_NEGZ: gx += PATCH_SIZE-k; break; | case CPATCH_SIDE_NEGZ: gx += PATCH_SIZE-k; break; | ||||
case CPATCH_SIDE_POSZ: gz += PATCH_SIZE; gx += k; break; | case CPATCH_SIDE_POSZ: gz += PATCH_SIZE; gx += k; break; | ||||
} | } | ||||
CVector3D pos; | CVector3D pos; | ||||
terrain->CalcPosition(gx, gz, pos); | terrain->CalcPosition(gx, gz, pos); | ||||
// Clamp the height to the water level | // Clamp the height to the water level if water is enabled. | ||||
if (water) | |||||
{ | |||||
float waterHeight = 0.f; | float waterHeight = 0.f; | ||||
if (cmpWaterManager) | waterHeight = water->GetExactWaterHeight(pos.X, pos.Z); | ||||
waterHeight = cmpWaterManager->GetExactWaterLevel(pos.X, pos.Z); | |||||
pos.Y = std::max(pos.Y, waterHeight); | pos.Y = std::max(pos.Y, waterHeight); | ||||
} | |||||
SSideVertex v0, v1; | SSideVertex v0, v1; | ||||
v0.m_Position = pos; | v0.m_Position = pos; | ||||
v1.m_Position = pos; | v1.m_Position = pos; | ||||
v1.m_Position.Y = 0; | v1.m_Position.Y = 0; | ||||
// If this is the start of this tristrip, but we've already got a partial | // If this is the start of this tristrip, but we've already got a partial | ||||
// tristrip, add a couple of degenerate triangles to join the strips properly | // tristrip, add a couple of degenerate triangles to join the strips properly | ||||
▲ Show 20 Lines • Show All 628 Lines • ▼ Show 20 Lines | void CPatchRData::BuildWater() | ||||
m_VBWater.Reset(); | m_VBWater.Reset(); | ||||
m_VBWaterIndices.Reset(); | m_VBWaterIndices.Reset(); | ||||
m_VBWaterShore.Reset(); | m_VBWaterShore.Reset(); | ||||
m_VBWaterIndicesShore.Reset(); | m_VBWaterIndicesShore.Reset(); | ||||
m_WaterBounds.SetEmpty(); | m_WaterBounds.SetEmpty(); | ||||
// We need to use this to access the water manager or we may not have the | |||||
// actual values but some compiled-in defaults | |||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*m_Simulation, SYSTEM_ENTITY); | |||||
if (!cmpWaterManager) | |||||
return; | |||||
// Build data for water | // Build data for water | ||||
std::vector<SWaterVertex> water_vertex_data; | std::vector<SWaterVertex> water_vertex_data; | ||||
std::vector<GLushort> water_indices; | std::vector<GLushort> water_indices; | ||||
u16 water_index_map[PATCH_SIZE+1][PATCH_SIZE+1]; | u16 water_index_map[PATCH_SIZE+1][PATCH_SIZE+1]; | ||||
memset(water_index_map, 0xFF, sizeof(water_index_map)); | memset(water_index_map, 0xFF, sizeof(water_index_map)); | ||||
// Build data for shore | // Build data for shore | ||||
std::vector<SWaterVertex> water_vertex_data_shore; | std::vector<SWaterVertex> water_vertex_data_shore; | ||||
std::vector<GLushort> water_indices_shore; | std::vector<GLushort> water_indices_shore; | ||||
u16 water_shore_index_map[PATCH_SIZE+1][PATCH_SIZE+1]; | u16 water_shore_index_map[PATCH_SIZE+1][PATCH_SIZE+1]; | ||||
memset(water_shore_index_map, 0xFF, sizeof(water_shore_index_map)); | memset(water_shore_index_map, 0xFF, sizeof(water_shore_index_map)); | ||||
WaterRData& waterRData = g_Game->GetWorld()->GetWater()->GetRData(); | |||||
CPatch* patch = m_Patch; | CPatch* patch = m_Patch; | ||||
CTerrain* terrain = patch->m_Parent; | CTerrain* terrain = patch->m_Parent; | ||||
CWater* water = g_Game->GetWorld()->GetWater(); | |||||
WaterRData& waterRData = water->GetRData(); | |||||
ssize_t mapSize = terrain->GetVerticesPerSide(); | ssize_t mapSize = terrain->GetVerticesPerSide(); | ||||
// Top-left coordinates of our patch. | // Top-left coordinates of our patch. | ||||
ssize_t px = m_Patch->m_X * PATCH_SIZE; | ssize_t px = m_Patch->m_X * PATCH_SIZE; | ||||
ssize_t pz = m_Patch->m_Z * PATCH_SIZE; | ssize_t pz = m_Patch->m_Z * PATCH_SIZE; | ||||
// To whoever implements different water heights, this is a TODO: water height) | // To whoever implements different water heights, this is a TODO: water height) | ||||
float waterHeight = cmpWaterManager->GetExactWaterLevel(0.0f,0.0f); | float waterHeight = water->GetExactWaterHeight(0.0f,0.0f); | ||||
const float* windStrength = waterRData.GetWindStrength(); | const float* windStrength = waterRData.GetWindStrength(); | ||||
// The 4 points making a water tile. | // The 4 points making a water tile. | ||||
int moves[4][2] = { | int moves[4][2] = { | ||||
{0, 0}, | {0, 0}, | ||||
{water_cell_size, 0}, | {water_cell_size, 0}, | ||||
{0, water_cell_size}, | {0, water_cell_size}, | ||||
▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator