summaryrefslogtreecommitdiff
path: root/src/game/game.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-03-31 16:04:04 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-03-31 16:04:04 +0200
commitd72e8d61de2f7efba3685dda2dc52b31f64f8a6e (patch)
tree2cda01dcc5b0e17fcf109469ac99296c2212346b /src/game/game.cpp
parentd87217dffc1582b8dbed10da62b3b4d3f7b511de (diff)
3D audio.
Diffstat (limited to 'src/game/game.cpp')
-rw-r--r--src/game/game.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 79685cb..2818c0b 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -285,17 +285,24 @@ void state_t::tick(ntime_t time_)
void state_t::compute_ambience(render::state_t *render)
{
+ const size_t samples = 25;
rectf_t area;
- size_t plains = 0, cave = 0, water = 0, weird = 0;
- float scale, volume;
+ v2f_t origins[AMBIENT_COUNT];
+ size_t hits[AMBIENT_COUNT];
area = render->window_in_world_space();
+ for (size_t i = 0; i < AMBIENT_COUNT; i++) {
+ origins[i] = v2f_t(0, 0);
+ hits[i] = 0;
+ }
+
// resolution chosen arbitrarily
for (size_t y = 0; y < 5; y++)
for (size_t x = 0; x < 5; x++) {
v2f_t point;
world::tile_t *tile;
+ int type;
point[0] = lerp(area[0][0], area[1][0], y / 4.0f);
point[1] = lerp(area[0][1], area[1][1], x / 4.0f);
@@ -304,32 +311,35 @@ void state_t::compute_ambience(render::state_t *render)
switch (tile->type) {
case TILE_DIRT:
- plains++;
+ type = AMBIENT_WIND;
break;
case TILE_GRAVEL:
case TILE_STONE:
- cave++;
+ type = AMBIENT_CHASM;
break;
case TILE_WATER:
- water++;
+ type = AMBIENT_WATER;
break;
case TILE_DIRT_RED:
case TILE_STONE_RED:
- weird++;
+ type = AMBIENT_NEXUS;
break;
+
+ default:
+ continue;
}
- }
- scale = 1.0f / area.dims().len();
- volume = clamp(remap(0.002f, 0.05f, 0.0f, 1.0f, scale), 0.0f, 1.0f);
+ origins[type] += point;
+ hits[type]++;
+ }
- assets::ambience.wind.weight = plains / 25.0f * volume;
- assets::ambience.chasm.weight = cave / 25.0f * volume;
- assets::ambience.water.weight = water / 25.0f * volume;
- assets::ambience.nexus.weight = weird / 25.0f * volume;
+ for (size_t i = 0; i < AMBIENT_COUNT; i++) {
+ assets::ambients[i].origin = origins[i] / hits[i];
+ assets::ambients[i].weight = (float)hits[i] / samples;
+ }
}
die_t::die_t(size_t sides_)