Skip to content

Commit

Permalink
Merge 'remotes/trunk'
Browse files Browse the repository at this point in the history
  • Loading branch information
KieranP committed Jul 2, 2017
2 parents 89530a3 + 649bef6 commit 00d798a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"pers": "Paradise"
},
"description": "Home gardens ranged from simple fenced-in areas to large manicured and colonnaded enclosures.",
"cost": {"food": 0, "wood": 500, "stone": 100, "metal": 0},
"cost": {"food": 0, "wood": 300, "stone": 100, "metal": 0},
"requirements": {"tech": "phase_town"},
"requirementsTooltip": "Unlocked in Town Phase.",
"icon": "population.png",
Expand Down
7 changes: 6 additions & 1 deletion source/maths/NUSpline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/

#include "precompiled.h"

#include <algorithm>

#include "NUSpline.h"
#include "Matrix3D.h"

Expand Down Expand Up @@ -218,7 +221,7 @@ void TNSpline::AddNode(const CFixedVector3D& pos, const CFixedVector3D& rotation
//Inserts node before position
void TNSpline::InsertNode(const int index, const CFixedVector3D& pos, const CFixedVector3D& UNUSED(rotation), fixed timePeriod)
{
if (NodeCount >= MAX_SPLINE_NODES || index < 0 || index > NodeCount - 1)
if (NodeCount >= MAX_SPLINE_NODES || index < 0 || index > NodeCount)
return;

if (NodeCount == 0)
Expand All @@ -230,6 +233,8 @@ void TNSpline::InsertNode(const int index, const CFixedVector3D& pos, const CFix
temp.Position = pos;
temp.Distance = timePeriod;
Node.insert(Node.begin() + index, temp);
if (index > 0)
std::swap(Node[index].Distance, Node[index - 1].Distance);
++NodeCount;
}

Expand Down
28 changes: 24 additions & 4 deletions source/renderer/WaterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,14 @@ void WaterManager::UnloadWaterTextures()
// Calculate our binary heightmap from the terrain heightmap.
void WaterManager::RecomputeDistanceHeightmap()
{
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
if (!terrain || !terrain->GetHeightMap())
return;

size_t SideSize = m_MapSize*2;
if (m_DistanceHeightmap == NULL)
m_DistanceHeightmap = new float[SideSize*SideSize];

CTerrain* terrain = g_Game->GetWorld()->GetTerrain();

// Create a manhattan-distance heightmap.
// This is currently upsampled by a factor of 2 to get more precision
// This could be refined to only be done near the coast itself, but it's probably not necessary.
Expand Down Expand Up @@ -483,6 +485,8 @@ void WaterManager::CreateWaveMeshes()
{
size_t SideSize = m_MapSize*2;
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
if (!terrain || !terrain->GetHeightMap())
return;

for (WaveObject* const& obj : m_ShoreWaves)
{
Expand Down Expand Up @@ -944,13 +948,15 @@ void WaterManager::RenderWaves(const CFrustum& frustrum)
// Calculate The blurred normal map to get an idea of where water ought to go.
void WaterManager::RecomputeBlurredNormalMap()
{
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
if (!terrain || !terrain->GetHeightMap())
return;

// used to cache terrain normals since otherwise we'd recalculate them a lot (I'm blurring the "normal" map).
// this might be updated to actually cache in the terrain manager but that's not for now.
if (m_BlurredNormalMap == NULL)
m_BlurredNormalMap = new CVector3D[m_MapSize*m_MapSize];

CTerrain* terrain = g_Game->GetWorld()->GetTerrain();

// It's really slow to calculate normals so cache them first.
CVector3D* normals = new CVector3D[m_MapSize*m_MapSize];

Expand Down Expand Up @@ -997,6 +1003,17 @@ void WaterManager::RecomputeBlurredNormalMap()
delete[] normals;
}

void WaterManager::RecomputeWaterData()
{
if (!m_MapSize)
return;

RecomputeBlurredNormalMap();
RecomputeDistanceHeightmap();
RecomputeWindStrength();
CreateWaveMeshes();
}

///////////////////////////////////////////////////////////////////
// Calculate the strength of the wind at a given point on the map.
// This is too slow and should support limited recomputation.
Expand All @@ -1006,6 +1023,9 @@ void WaterManager::RecomputeWindStrength()
m_WindStrength = new float[m_MapSize*m_MapSize];

CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
if (!terrain || !terrain->GetHeightMap())
return;

float waterLevel = m_WaterHeight;

CVector2D windDir = CVector2D(cos(m_WindAngle),sin(m_WindAngle));
Expand Down
7 changes: 6 additions & 1 deletion source/renderer/WaterManager.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -154,6 +154,11 @@ class WaterManager
*/
void UnloadWaterTextures();

/**
* RecomputeWaterData: calculates all derived data from the waterheight
*/
void RecomputeWaterData();

/**
* RecomputeWindStrength: calculates the intensity of waves
*/
Expand Down
5 changes: 1 addition & 4 deletions source/simulation2/components/CCmpTerrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ class CCmpTerrain : public ICmpTerrain
if (ReloadWater && CRenderer::IsInitialised())
{
g_Renderer.GetWaterManager()->SetMapSize(vertices);
g_Renderer.GetWaterManager()->RecomputeBlurredNormalMap();
g_Renderer.GetWaterManager()->RecomputeDistanceHeightmap();
g_Renderer.GetWaterManager()->RecomputeWindStrength();
g_Renderer.GetWaterManager()->CreateWaveMeshes();
g_Renderer.GetWaterManager()->RecomputeWaterData();
}
MakeDirty(0, 0, tiles+1, tiles+1);
}
Expand Down
14 changes: 5 additions & 9 deletions source/simulation2/components/CCmpWaterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class CCmpWaterManager : public ICmpWaterManager
Init(paramNode);

deserialize.NumberFixed_Unbounded("height", m_WaterHeight);

RecomputeWaterData();
}

virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))
Expand Down Expand Up @@ -97,10 +99,8 @@ class CCmpWaterManager : public ICmpWaterManager
{
if (CRenderer::IsInitialised())
{
g_Renderer.GetWaterManager()->RecomputeBlurredNormalMap();
g_Renderer.GetWaterManager()->RecomputeDistanceHeightmap();
g_Renderer.GetWaterManager()->RecomputeWindStrength();
g_Renderer.GetWaterManager()->CreateWaveMeshes();
g_Renderer.GetWaterManager()->RecomputeWaterData();
g_Renderer.GetWaterManager()->m_WaterHeight = m_WaterHeight.ToFloat();
}

// Tell the terrain it'll need to recompute its cached render data
Expand All @@ -114,11 +114,7 @@ class CCmpWaterManager : public ICmpWaterManager

m_WaterHeight = h;

// Tell the terrain it'll need to recompute its cached render data
GetSimContext().GetTerrain().MakeDirty(RENDERDATA_UPDATE_VERTICES);

if (CRenderer::IsInitialised())
g_Renderer.GetWaterManager()->m_WaterHeight = h.ToFloat();
RecomputeWaterData();

CMessageWaterChanged msg;
GetSimContext().GetComponentManager().BroadcastMessage(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ BEGIN_COMMAND(AddPathNode)
fixed::FromFloat(focus.Y),
fixed::FromFloat(focus.Z)
);
spline.InsertNode(index, target, CFixedVector3D(), fixed::FromInt(1));
spline.InsertNode(index + 1, target, CFixedVector3D(), fixed::FromInt(1));

spline.BuildSpline();
cmpCinemaManager->DeletePath(name);
Expand Down

0 comments on commit 00d798a

Please sign in to comment.