Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/terrain/StarMixSelector.cpp
blob: 88c8a5436f5c428b1f521a88656e1f53c70a93a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "StarMixSelector.hpp"
#include "StarInterpolation.hpp"

namespace Star {

char const* const MixSelector::Name = "mix";

MixSelector::MixSelector(Json const& config, TerrainSelectorParameters const& parameters, TerrainDatabase const* database)
  : TerrainSelector(Name, config, parameters) {
  auto readSource = [&](Json const& sourceConfig) {
    String type = sourceConfig.getString("type");
    return database->createSelectorType(type, sourceConfig, parameters);
  };

  m_mixSource = readSource(config.get("mixSource"));
  m_aSource = readSource(config.get("aSource"));
  m_bSource = readSource(config.get("bSource"));
}

float MixSelector::get(int x, int y) const {
  auto f = clamp(m_mixSource->get(x, y), -1.0f, 1.0f);
  if (f == -1)
    return m_aSource->get(x, y);
  if (f == 1)
    return m_bSource->get(x, y);
  return lerp(f * 0.5f + 0.5f, m_aSource->get(x, y), m_bSource->get(x, y));
}

}