summaryrefslogtreecommitdiff
path: root/src/game
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
parentd87217dffc1582b8dbed10da62b3b4d3f7b511de (diff)
3D audio.
Diffstat (limited to 'src/game')
-rw-r--r--src/game/assets.cpp19
-rw-r--r--src/game/game.cpp36
-rw-r--r--src/game/game.hpp14
-rw-r--r--src/game/interface.cpp4
-rw-r--r--src/game/units.cpp4
5 files changed, 48 insertions, 29 deletions
diff --git a/src/game/assets.cpp b/src/game/assets.cpp
index f0dddbf..a020bf6 100644
--- a/src/game/assets.cpp
+++ b/src/game/assets.cpp
@@ -24,7 +24,7 @@ spider_assets_t spider;
nest_assets_t nest;
fx_assets_t fx;
deco_assets_t deco;
-ambience_assets_t ambience;
+audio::ambient_t ambients[AMBIENT_COUNT];
render::animated_texture_t unit_selected;
render::animated_texture_t unit_selected_halo;
@@ -42,13 +42,14 @@ void load(void)
soldier.dead.load("assets/units/soldier/dead_", 1);
soldier.fire.load("assets/units/soldier/fire.ogg");
-
+ soldier.fire.volume = 4.0f;
+
soldier.step_stone.load("assets/units/soldier/step_stone_1.ogg");
soldier.step_stone.load("assets/units/soldier/step_stone_2.ogg");
soldier.step_stone.load("assets/units/soldier/step_stone_3.ogg");
soldier.step_stone.load("assets/units/soldier/step_stone_4.ogg");
soldier.step_stone.load("assets/units/soldier/step_stone_5.ogg");
- soldier.step_stone.volume = 0.4f;
+ soldier.step_stone.volume = 1.0f;
spider.idle.load("assets/units/spider/idle", 2, 2, 2);
spider.walking.load("assets/units/spider/walking", 2, 2, 2);
@@ -83,12 +84,12 @@ void load(void)
world::register_tile(TILE_GRAVEL, 0);
render::register_tile(TILE_GRAVEL, "assets/tiles/gravel.png", NULL, 0.0f);
- ambience.nexus.load("assets/ambience/nexus.ogg");
- ambience.chasm.load("assets/ambience/chasm.ogg");
- ambience.wind.load("assets/ambience/wind.ogg");
- ambience.water.load("assets/ambience/water.ogg");
-
- ambience.nexus.weight = 1.0f;
+ ambients[AMBIENT_NEXUS].load("assets/ambience/nexus.ogg");
+ ambients[AMBIENT_CHASM].load("assets/ambience/chasm.ogg");
+ ambients[AMBIENT_CHASM].volume = 4.0f;
+ ambients[AMBIENT_WIND].load("assets/ambience/wind.ogg");
+ ambients[AMBIENT_WATER].load("assets/ambience/water.ogg");
+ ambients[AMBIENT_WATER].volume = 0.2f;
}
} // namespace game::assets
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_)
diff --git a/src/game/game.hpp b/src/game/game.hpp
index bb2ce69..331c1d1 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -41,6 +41,14 @@ namespace game {
CF_BODY_SMALL = 8,
CF_WATER = 16
};
+
+ enum {
+ AMBIENT_NEXUS,
+ AMBIENT_CHASM,
+ AMBIENT_WIND,
+ AMBIENT_WATER,
+ AMBIENT_COUNT
+ };
extern size_t selection_cookie;
@@ -77,16 +85,12 @@ namespace game {
render::animated_texture_t wart;
} deco_assets_t;
- typedef struct {
- audio::ambient_t nexus, chasm, wind, water;
- } ambience_assets_t;
-
extern soldier_assets_t soldier;
extern spider_assets_t spider;
extern nest_assets_t nest;
extern fx_assets_t fx;
extern deco_assets_t deco;
- extern ambience_assets_t ambience;
+ extern audio::ambient_t ambients[AMBIENT_COUNT];
extern render::animated_texture_t unit_selected;
extern render::animated_texture_t unit_selected_halo;
extern render::animated_texture_t move_marker;
diff --git a/src/game/interface.cpp b/src/game/interface.cpp
index d3ef661..25d256c 100644
--- a/src/game/interface.cpp
+++ b/src/game/interface.cpp
@@ -165,6 +165,10 @@ void state_t::tick(double dt)
window->setView(sf::View(view_center, view_size));
}
+ camera_3d[0] = view_center[0];
+ camera_3d[1] = view_center[1];
+ camera_3d[2] = view_scale;
+
mouse = sf::Mouse::getPosition(*window);
wmouse = window->mapPixelToCoords(sf::Mouse::getPosition(*window));
diff --git a/src/game/units.cpp b/src/game/units.cpp
index 30cfdd5..47e729c 100644
--- a/src/game/units.cpp
+++ b/src/game/units.cpp
@@ -354,7 +354,7 @@ void unit_soldier_t::shoot(v2f_t aim)
flash->place(&game->world);
last_attack = game->now;
- assets::soldier.fire.play();
+ assets::soldier.fire.play_3d(x);
//target->damage(3, this); FIXME
}
@@ -458,7 +458,7 @@ void unit_soldier_t::on_think(void)
if (move.moving && (x - move.last_step).len() > 0.5f) {
move.last_step = x;
- assets::soldier.step_stone.play();
+ assets::soldier.step_stone.play_3d(x);
}
}