Client side ambiance
parent
b6387b4e0f
commit
6d94cd3edf
|
@ -0,0 +1,115 @@
|
|||
--------------Music Lic:
|
||||
Amethystium:
|
||||
--Avalon
|
||||
--Ethereal
|
||||
--Faraway
|
||||
--Strangely Beautiful
|
||||
Used with kind permission from Øystein Ramfjord / AM.mu Records
|
||||
|
||||
Jordach:
|
||||
--dark_ambiance
|
||||
--eastern_feeling
|
||||
These sounds are used for the Mod for Minetest; Ambiance.
|
||||
The included sounds are http://creativecommons.org/licenses/by-nc-sa/3.0/
|
||||
Not Used:--mtest
|
||||
|
||||
-----------Sound Lic:
|
||||
--Nightime Sound, Recorded by Mike Koenig, License: Attribution 3.0 http://soundbible.com/951-Nightime.html
|
||||
--Crickets At Night Sound, License: Attribution 3.0 | Recorded by Mike Koenig |http://soundbible.com/365-Crickets-At-Night.html
|
||||
|
||||
--Medium Pack Of Wolves Howling, License: Public Domain | Recorded by fws.gov, http://soundbible.com/277-Medium-Pack-Of-Wolves-Howling.html
|
||||
|
||||
--Horned Owl Sound, License: Attribution 3.0 | Recorded by Mike Koenig , http://soundbible.com/1851-Horned-Owl.html
|
||||
--Bats In Cave Sound, License: Attr-Noncommercial 3.0 | Recorded by Mike Koenig , http://soundbible.com/1939-Bats-In-Cave.html
|
||||
|
||||
--Spooky Water Drops Sound, License: Attribution 3.0 | Recorded by Mike Koenig, http://soundbible.com/380-Spooky-Water-Drops.html
|
||||
|
||||
|
||||
-- Single Water Droplet Sound, License: Attribution 3.0 | Recorded by Mike Koenig, http://soundbible.com/384-Single-Water-Droplet.html
|
||||
|
||||
--HollowWind, Black Boe, Creative Commons 0 License, http://www.freesound.org/people/Black%20Boe/sounds/22331/
|
||||
|
||||
--drippingwater*.ogg sounds: CC0, Dripping Water Mod, by kddekadenz, http://minetest.net/forum/viewtopic.php?id=1688
|
||||
|
||||
--best cardinal bird: License: Attribution 3.0 | Recorded by PsychoBird, http://soundbible.com/1515-Best-Cardinal-Bird.html
|
||||
|
||||
--birdsongnl: the Attribution License, HerbertBoland, http://www.freesound.org/people/HerbertBoland/sounds/28312/ (end)
|
||||
|
||||
--robin2: Attribution License, reinsamba, http://www.freesound.org/people/reinsamba/sounds/32479/ (end)
|
||||
|
||||
--Craw.WAV, Attribution License, inchadney, http://www.freesound.org/people/inchadney/sounds/52450/
|
||||
|
||||
--bluejay.wav, Creative Commons 0 License, UncleSigmund, http://www.freesound.org/people/UncleSigmund/sounds/42382/
|
||||
|
||||
--scuba1*.ogg- digifishmusic, Attribution License, http://www.freesound.org/people/digifishmusic/sounds/45521/
|
||||
|
||||
--Underwater Pool - Attribution 3.0 | Recorded by Mike Koenig, http://soundbible.com/1660-Underwater-Pool.html
|
||||
|
||||
--dolphin_screaming - Creative Commons 0 License, felix.blume, http://www.freesound.org/people/felix.blume/sounds/161691/
|
||||
|
||||
--dolphins - Attribution Noncommercial License, acclivity, http://www.freesound.org/people/acclivity/sounds/13691/
|
||||
|
||||
ComboWind uses:
|
||||
--wind-in-the-trees -Attribution License, laurent, http://www.freesound.org/people/laurent/sounds/16995/
|
||||
--drygrassInWind- Creative Commons 0 License, felix.blume, http://www.freesound.org/people/felix.blume/sounds/146436/
|
||||
|
||||
--Splash: Attribution 3.0 | Recorded by BlastwaveFx.com, http://soundbible.com/546-Fish-Splashing.html
|
||||
|
||||
--small_waterfall Attribution License, volivieri, http://www.freesound.org/people/volivieri/sounds/38390/
|
||||
|
||||
--Lake_Waves_2*, Attribution License, Benboncan, http://www.freesound.org/people/Benboncan/sounds/67884/
|
||||
|
||||
--water_swimming_splashing*, Attribution Noncommercial License, Robinhood76, http://www.freesound.org/people/Robinhood76/sounds/79657/
|
||||
|
||||
--earth01a, Creative Commons 0 License., Halion , http://www.freesound.org/people/Halion/sounds/17785
|
||||
|
||||
--fiji_beach, Creative Commons 0 License, c97059890, http://www.freesound.org/people/c97059890/sounds/21754/
|
||||
|
||||
--seagull, Attribution Noncommercial License., hazure, http://www.freesound.org/people/hazure/sounds/23707/,
|
||||
|
||||
desert:
|
||||
coyote2, Attribution License, rogerforeman, http://www.freesound.org/people/rogerforeman/sounds/68068/
|
||||
http://www.freesound.org/people/Proxima4/sounds/104319/
|
||||
Desert Monolith.wav, Creative Commons 0 License, Proxima4, http://www.freesound.org/people/Proxima4/sounds/104319/
|
||||
Rattlesnake Rattle, Public Domain, fws.gov, http://soundbible.com/237-Rattlesnake-Rattle.html
|
||||
|
||||
flying:
|
||||
crystal_airlines: Attribution License, suonho, http://www.freesound.org/people/suonho/sounds/56364/
|
||||
|
||||
----------------Not used yet:
|
||||
desert:
|
||||
Desert Simple.wav, Creative Commons 0 License, Proxima4, http://www.freesound.org/people/Proxima4/sounds/104320/
|
||||
|
||||
313hummer (Jordan Craige)
|
||||
--echos http://soundcloud.com/jordan-craige/echos-1
|
||||
Creative Commons Attribution license (reuse allowed) Attribution 3.0 Unported (CC BY 3.0)
|
||||
Not Used:--FoamOfTheSea http://soundcloud.com/jordan-craige/foam-of-the-sea
|
||||
|
||||
xi-intersection:
|
||||
http://soundcloud.com/xi-intersection/mass-effect-uncharted-worlds Creative Commons License
|
||||
--not used:
|
||||
http://soundcloud.com/xi-intersection/donkey-kong-country-2-flight
|
||||
http://soundcloud.com/kogyo/kogyo-skalar-m1
|
||||
|
||||
lava:
|
||||
http://www.freesound.org/people/Halion/sounds/17785/ (almost as good cc) (combine with rocks falling?)
|
||||
http://www.freesound.org/people/pushtobreak/sounds/17823/ (attrib non cc really good)
|
||||
http://www.freesound.org/people/klankbeeld/sounds/123970/ (horror rhythm)
|
||||
Rockfall in mine.wav http://www.freesound.org/people/Benboncan/sounds/60085/
|
||||
|
||||
|
||||
http://www.freesound.org/people/snotch/sounds/96175/ (mud volcano)
|
||||
|
||||
--natural night sounds in Boquete.wav, Attribution License, laurent, http://www.freesound.org/people/laurent/sounds/15851/
|
||||
http://www.freesound.org/people/Dynamicell/sounds/17553/
|
||||
http://www.freesound.org/people/juskiddink/sounds/78955/ aspen tree in wind
|
||||
http://www.freesound.org/people/Benboncan/sounds/69761/ wind in hedge birds animals
|
||||
|
||||
|
||||
ButterflyTea:
|
||||
Creative Commons : Attribution-Noncommercial-Share Alike 3.0
|
||||
http://www.jamendo.com/en/track/904012/dance-of-magical-flowers
|
||||
http://www.jamendo.com/en/track/904013/magic-of-the-seventh-world
|
||||
http://www.jamendo.com/en/track/904016/in-search-of-the-soul
|
||||
|
||||
zero-project
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -391,6 +391,7 @@ set(client_SRCS
|
|||
${common_SRCS}
|
||||
${sound_SRCS}
|
||||
${client_network_SRCS}
|
||||
ambiance.cpp
|
||||
camera.cpp
|
||||
chat.cpp
|
||||
client.cpp
|
||||
|
|
|
@ -0,0 +1,280 @@
|
|||
/*
|
||||
* ambience.cpp
|
||||
|
||||
*
|
||||
* Created on: Jun 13, 2015
|
||||
* Author: brandon
|
||||
*/
|
||||
|
||||
#include "ambiance.h"
|
||||
#include "log.h"
|
||||
#include "localplayer.h"
|
||||
#include "map.h"
|
||||
#include "clientmap.h"
|
||||
|
||||
Ambiance::Ambiance(ISoundManager *sound, ClientEnvironment &e):
|
||||
m_sound(sound),
|
||||
m_env(e)
|
||||
{
|
||||
verbosestream << "[AMBIANCE] Loading sound files...";
|
||||
m_sound->loadSoundFile("bats","client/sounds/bats.ogg");
|
||||
m_sound->loadSoundFile("bird","client/sounds/bird.ogg");
|
||||
m_sound->loadSoundFile("bird2","client/sounds/bird2.ogg");
|
||||
m_sound->loadSoundFile("bird3","client/sounds/bird3.ogg");
|
||||
m_sound->loadSoundFile("bird4","client/sounds/bird4.ogg");
|
||||
m_sound->loadSoundFile("birdsong","client/sounds/birdsong.ogg");
|
||||
m_sound->loadSoundFile("coyote","client/sounds/coyote.ogg");
|
||||
m_sound->loadSoundFile("crickets","client/sounds/crickets.ogg");
|
||||
m_sound->loadSoundFile("crow","client/sounds/crow.ogg");
|
||||
m_sound->loadSoundFile("desert","client/sounds/desert.ogg");
|
||||
m_sound->loadSoundFile("drip_a","client/sounds/drippingwater_drip_a.ogg");
|
||||
m_sound->loadSoundFile("drip_b","client/sounds/drippingwater_drip_b.ogg");
|
||||
m_sound->loadSoundFile("drip_c","client/sounds/drippingwater_drip_c.ogg");
|
||||
m_sound->loadSoundFile("drip_d","client/sounds/drippingwater_drip_d.ogg");
|
||||
m_sound->loadSoundFile("drip_e","client/sounds/drippingwater_drip_e.ogg");
|
||||
m_sound->loadSoundFile("drowning_gasp","client/sounds/drowning_gasp.ogg");
|
||||
m_sound->loadSoundFile("lake_waves_calm","client/sounds/lake_waves_2_calm.ogg");
|
||||
m_sound->loadSoundFile("lake_waves_variety","client/sounds/lake_waves_2_variety.ogg");
|
||||
m_sound->loadSoundFile("owl","client/sounds/owl.ogg");
|
||||
m_sound->loadSoundFile("rattlesnake","client/sounds/rattlesnake.ogg");
|
||||
m_sound->loadSoundFile("rumble","client/sounds/rumble.ogg");
|
||||
m_sound->loadSoundFile("scuba1","client/sounds/scuba1bubbles.ogg");
|
||||
m_sound->loadSoundFile("scuba2","client/sounds/scuba1calm.ogg");
|
||||
m_sound->loadSoundFile("scuba3","client/sounds/scuba1calm2.ogg");
|
||||
m_sound->loadSoundFile("scuba4","client/sounds/scuba1interestingbubbles.ogg");
|
||||
m_sound->loadSoundFile("scuba5","client/sounds/scuba1tubulentbubbles.ogg");
|
||||
m_sound->loadSoundFile("splash","client/sounds/splash.ogg");
|
||||
m_sound->loadSoundFile("swimming1","client/sounds/water_swimming_splashing.ogg");
|
||||
m_sound->loadSoundFile("swimming2","client/sounds/water_swimming_splashing_breath.ogg");
|
||||
|
||||
verbosestream << "done" << std::endl;
|
||||
|
||||
verbosestream << "[AMBIANCE] Setting up environments...";
|
||||
a_env[ENV_UNKNOWN] = { "Unknown", 0, 0, "", "", 0 };
|
||||
|
||||
// setup the various environment's sounds and frequencies
|
||||
a_env[ENV_CAVE] = { "Cave", 400, 6, "", "", 5.75 };
|
||||
a_env[ENV_CAVE].sounds[1] = {"bats",.4};
|
||||
a_env[ENV_CAVE].sounds[2] = {"drip_a",.8};
|
||||
a_env[ENV_CAVE].sounds[3] = {"drip_b",.8};
|
||||
a_env[ENV_CAVE].sounds[4] = {"drip_c",.6};
|
||||
a_env[ENV_CAVE].sounds[5] = {"drip_d",.4};
|
||||
a_env[ENV_CAVE].sounds[6] = {"drip_e",.5};
|
||||
|
||||
a_env[ENV_UNDERWATER] = { "Underwater", 1001, 5, "splash", "drowning_gasp", 0 };
|
||||
a_env[ENV_UNDERWATER].sounds[1] = {"scuba1",1};
|
||||
a_env[ENV_UNDERWATER].sounds[2] = {"scuba2",1};
|
||||
a_env[ENV_UNDERWATER].sounds[3] = {"scuba3",1};
|
||||
a_env[ENV_UNDERWATER].sounds[4] = {"scuba4",1};
|
||||
a_env[ENV_UNDERWATER].sounds[5] = {"scuba5",1};
|
||||
|
||||
a_env[ENV_INWATER] = { "Standing in Water", 1001, 2, "splash", "splash", 0 };
|
||||
a_env[ENV_INWATER].sounds[1] = {"swimming1",.6};
|
||||
a_env[ENV_INWATER].sounds[2] = {"swimming2",.6};
|
||||
|
||||
a_env[ENV_MORNING] = { "Morning", 300, 3, "", "", 7 };
|
||||
a_env[ENV_MORNING].sounds[1] = {"bird2",.5};
|
||||
a_env[ENV_MORNING].sounds[2] = {"bird4",.5};
|
||||
a_env[ENV_MORNING].sounds[3] = {"bird3",.5};
|
||||
|
||||
a_env[ENV_DAY] = { "Day", 400, 5, "", "", 6 };
|
||||
a_env[ENV_DAY].sounds[1] = {"bird2",.5};
|
||||
a_env[ENV_DAY].sounds[2] = {"bird4",.5};
|
||||
a_env[ENV_DAY].sounds[3] = {"bird3",.5};
|
||||
a_env[ENV_DAY].sounds[4] = {"bird",.5};
|
||||
a_env[ENV_DAY].sounds[5] = {"birdsong",.5};
|
||||
|
||||
a_env[ENV_DUSK] = { "Dusk", 1001, 1, "", "", 0 };
|
||||
a_env[ENV_DUSK].sounds[1] = {"crickets",.5};
|
||||
|
||||
a_env[ENV_NIGHT] = { "Night", 600, 1, "", "", 3 };
|
||||
a_env[ENV_NIGHT].sounds[1] = {"crickets",.7};
|
||||
|
||||
verbosestream << "done" << std::endl;
|
||||
}
|
||||
void Ambiance::doAmbiance(float dtime){
|
||||
static bool newEnv = false;
|
||||
if ( startDelay > 3 ) { // delay ambiance 3 seconds from launch of game
|
||||
lastPlay += dtime;
|
||||
//verbosestream << "[AMBIANCE] doAmbiance()" << std::endl;
|
||||
int env_result = readEnvironment();
|
||||
if ( env_result != currentEnv ){
|
||||
lastEnv = currentEnv;
|
||||
currentEnv = env_result;
|
||||
stopEnvironment(lastEnv); // change of enviroment stop all sounds that might be playing
|
||||
if ( !a_env[currentEnv].on_start.empty() ){
|
||||
playSound(a_env[currentEnv].on_start, 1);
|
||||
}
|
||||
newEnv = true;
|
||||
verbosestream << "[AMBIANCE] readEnvironment Results: " << a_env[currentEnv].name << std::endl;
|
||||
} else {
|
||||
newEnv = false;
|
||||
}
|
||||
|
||||
if ( m_sounds_playing.rbegin() != m_sounds_playing.rend() ){
|
||||
if ( m_sound->soundExists(m_sounds_playing.rbegin()->second) ){
|
||||
// if the last sound isn't doesn't playing don't start another one
|
||||
//verbosestream << "[AMBIANCE] dont start a new sound" << std::endl;
|
||||
return;
|
||||
} else {
|
||||
m_sounds_it it = m_sounds_playing.find(m_sounds_playing.rbegin()->first);
|
||||
m_sounds_playing.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
if ( newEnv == true || lastPlay > a_env[currentEnv].next_sound_delay ){
|
||||
srand (time(NULL));
|
||||
int freq = rand() % 1000;
|
||||
//verbosestream << "[AMBIANCE] Freq Random Number: " << to_string(freq) << " :: " << to_string(a_env[currentEnv].frequency) << std::endl;
|
||||
if ( freq <= a_env[currentEnv].frequency ){
|
||||
int s = ( rand() % a_env[currentEnv].sound_count ) + 1;
|
||||
verbosestream << "[AMBIANCE] Sound selected: " << to_string(s) << " " << a_env[currentEnv].sounds[s].name << std::endl;
|
||||
playSound(a_env[currentEnv].sounds[s].name, a_env[currentEnv].sounds[s].gain);
|
||||
}
|
||||
} else {
|
||||
//verbosestream << "[AMBIANCE] No Play" << to_string(lastPlay) <<std::endl;
|
||||
}
|
||||
} else {
|
||||
startDelay += dtime;
|
||||
}
|
||||
}
|
||||
|
||||
// type is 0 - normal sound, 1 start sound, 2 stop sound
|
||||
bool Ambiance::playSound(std::string name, float gain){
|
||||
verbosestream << "[AMBIANCE] playSound(" << name << ")" << std::endl;
|
||||
std::map<std::string, int>::iterator i = m_sounds_playing.find(name);
|
||||
if ( i != m_sounds_playing.end() ){
|
||||
// check the sound buffers to see if it's still playing
|
||||
if ( m_sound->soundExists(i->second) ){
|
||||
// get out of here so we don't play it again
|
||||
verbosestream << "[AMBIANCE] " << name << " is already playing" << std::endl;
|
||||
return false;
|
||||
} else {
|
||||
// remove it from our playing list
|
||||
m_sounds_playing.erase(name);
|
||||
}
|
||||
}
|
||||
int id = m_sound->playSound(name, false, gain);
|
||||
m_sounds_playing[name] = id;
|
||||
lastPlay = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int Ambiance::readEnvironment(){
|
||||
//verbosestream << "[AMBIANCE] readEnvironment() ";
|
||||
ascending = false;
|
||||
descending = false;
|
||||
moving = false;
|
||||
underwater = false;
|
||||
|
||||
LocalPlayer *p = m_env.getLocalPlayer();
|
||||
v3f pos = p->getPosition();
|
||||
v3s16 spos = p->getStandingNodePos();
|
||||
|
||||
// DAY AND NIGHT ARE KIND OF CATCH ALLS
|
||||
// 19000 night starts
|
||||
// 5000 morning starts
|
||||
u32 t = m_env.getTimeOfDay();
|
||||
//verbosestream << t << std::endl;
|
||||
|
||||
if ( pos.Y > ( lastpos.Y + .5 ) )
|
||||
ascending = true;
|
||||
|
||||
if ( pos.Y < ( lastpos.Y - .5 ) )
|
||||
descending = true;
|
||||
|
||||
if ( pos.X != lastpos.X || pos.Z != lastpos.Z )
|
||||
moving = true;
|
||||
|
||||
if ( moving == false && currentEnv == ENV_INWATER ) // for in water only play sounds if they are moving otherwise return unknown
|
||||
return ENV_UNKNOWN;
|
||||
|
||||
// if they haven't moved much don't check the environment
|
||||
//if ( ascending == false && descending == false && moving == false ){
|
||||
// return currentEnv;
|
||||
//}
|
||||
// don't update lastpos until they have moved
|
||||
lastpos = pos;
|
||||
|
||||
//verbosestream << p->getName() << " " << to_string(spos.X) << "," << to_string(spos.Y) << "," << to_string(spos.Z) << std::endl;
|
||||
|
||||
// find the nodes at their body positions
|
||||
std::string lowerBodyNodeName = getNodeName(v3s16(spos.X, (spos.Y+1), spos.Z));
|
||||
std::string upperBodyNodeName = getNodeName(v3s16(spos.X, (spos.Y+2), spos.Z));
|
||||
std::string standingOnNodeName = getNodeName(v3s16(spos.X, spos.Y, spos.Z));
|
||||
std::string aboveHeadNodeName = getNodeName(v3s16(spos.X, (spos.Y+3), spos.Z));
|
||||
|
||||
if ( ( upperBodyNodeName == "default:water_source" || upperBodyNodeName == "default:water_flowing" ) ){
|
||||
underwater = true;
|
||||
return ENV_UNDERWATER;
|
||||
}
|
||||
|
||||
if ( moving == true && ( lowerBodyNodeName == "default:water_source" || lowerBodyNodeName == "default:water_flowing" ) ){
|
||||
return ENV_INWATER;
|
||||
}
|
||||
|
||||
if ( spos.Y < -15 && nodesInRange(spos, 5, "default:stone") > 8 ){
|
||||
// see if they are surrounded by stone
|
||||
return ENV_CAVE;
|
||||
}
|
||||
|
||||
|
||||
// time based catchalls
|
||||
if ( t > 5000 && t < 8000 )
|
||||
return ENV_MORNING;
|
||||
|
||||
if ( t > 8000 && t < 18500 )
|
||||
return ENV_DAY;
|
||||
|
||||
if ( t > 18500 && t < 19500 )
|
||||
return ENV_DUSK;
|
||||
|
||||
if ( t > 19500 || t < 5000 )
|
||||
return ENV_NIGHT;
|
||||
|
||||
return ENV_UNKNOWN;
|
||||
}
|
||||
|
||||
int Ambiance::nodesInRange(v3s16 pos, short searchRange, std::string nodeName){
|
||||
//verbosestream << "[AMBIANCE] nodesInRange(pos, " << to_string(searchRange) << ", " << nodeName << ")" << std::endl;
|
||||
int nodeCount = 0;
|
||||
bool valid_pos;
|
||||
// set positions for node checks
|
||||
v3s16 p1 = v3s16((pos.X - searchRange), (pos.Y - searchRange), (pos.Z - searchRange));
|
||||
v3s16 p2 = v3s16((pos.X + searchRange), (pos.Y + searchRange), (pos.Z + searchRange));
|
||||
//verbosestream << "[AMBIANCE] Searching from " << to_string(p1.X) << ", " << to_string(p1.Y) << ", " << to_string(p1.Z) << " to " << to_string(p2.X) << ", " << to_string(p2.Y) << ", " << to_string(p2.Z) << std::endl;
|
||||
for ( int y = p1.Y; y < p2.Y; y++ ){
|
||||
for ( int x = p1.X; x < p2.X; x++ ){
|
||||
for ( int z = p1.Z; z < p2.Z; z++ ){
|
||||
//verbosestream << "[AMBIANCE] Position " << to_string(x) << ", " << to_string(y) << ", " << to_string(z) << std::endl;
|
||||
MapNode n = m_env.getMap().getNodeNoEx(v3s16(x,y,z), &valid_pos);
|
||||
ContentFeatures f = m_env.getGameDef()->getNodeDefManager()->get(n);
|
||||
//verbosestream << f.name << std::endl;
|
||||
if ( valid_pos == true ){
|
||||
if ( f.name == nodeName )
|
||||
nodeCount++;
|
||||
} else {
|
||||
verbosestream << "[AMBIANCE] Invalid position " << to_string(x) << ", " << to_string(y) << ", " << to_string(z) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//verbosestream << "[AMBIANCE] Node Count: " << to_string(nodeCount) << std::endl;
|
||||
return nodeCount;
|
||||
}
|
||||
|
||||
std::string Ambiance::getNodeName(v3s16 pos){
|
||||
MapNode n = m_env.getMap().getNodeNoEx(pos);
|
||||
ContentFeatures f = m_env.getGameDef()->getNodeDefManager()->get(n);
|
||||
return f.name;
|
||||
}
|
||||
|
||||
void Ambiance::stopEnvironment(int env){
|
||||
// not going to bother seeing if the sounds playing are part of a certain environment just yet, just stop all sounds
|
||||
for ( m_sounds_it i = m_sounds_playing.begin(); i != m_sounds_playing.end(); i++ ){
|
||||
m_sound->stopSound(i->second);
|
||||
}
|
||||
if ( !a_env[env].on_stop.empty() ){
|
||||
playSound(a_env[env].on_stop,1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* ambience.h
|
||||
*
|
||||
* Created on: Jun 13, 2015
|
||||
* Author: brandon
|
||||
*/
|
||||
#ifndef SRC_AMBIANCE_H_
|
||||
#define SRC_AMBIANCE_H_
|
||||
|
||||
#include "gamedef.h"
|
||||
#include "environment.h"
|
||||
#include "sound.h"
|
||||
#include "settings.h"
|
||||
#include "sound_openal.h"
|
||||
|
||||
class Ambiance
|
||||
{
|
||||
public:
|
||||
Ambiance(ISoundManager *sound, ClientEnvironment &e);
|
||||
void doAmbiance(float dtime);
|
||||
private:
|
||||
bool playSound(std::string name, float gain);
|
||||
int nodesInRange(v3s16 pos, short searchRange, std::string nodeName);
|
||||
std::string getNodeName(v3s16 pos);
|
||||
void stopEnvironment(int env);
|
||||
|
||||
ISoundManager *m_sound;
|
||||
ClientEnvironment m_env;
|
||||
|
||||
std::map<std::string, int> m_sounds_playing;
|
||||
typedef std::map<std::string, int>::iterator m_sounds_it;
|
||||
|
||||
v3f lastpos;
|
||||
bool ascending;
|
||||
bool descending;
|
||||
bool moving;
|
||||
bool underwater;
|
||||
|
||||
float startDelay;
|
||||
float envDelay;
|
||||
|
||||
int currentEnv = 0;
|
||||
int lastEnv;
|
||||
float lastPlay;
|
||||
|
||||
struct env_sound {
|
||||
std::string name;
|
||||
float gain;
|
||||
};
|
||||
|
||||
struct ambiance_environment {
|
||||
std::string name;
|
||||
int frequency;
|
||||
int sound_count;
|
||||
std::string on_start;
|
||||
std::string on_stop;
|
||||
float next_sound_delay;
|
||||
env_sound sounds[10];
|
||||
bool on_start_played;
|
||||
bool on_stop_played;
|
||||
};
|
||||
|
||||
enum environment_ids {
|
||||
ENV_UNKNOWN,
|
||||
ENV_CAVE,
|
||||
ENV_UNDERWATER,
|
||||
ENV_INWATER,
|
||||
ENV_MORNING,
|
||||
ENV_DAY,
|
||||
ENV_DUSK,
|
||||
ENV_NIGHT
|
||||
};
|
||||
|
||||
ambiance_environment a_env[8];
|
||||
|
||||
int readEnvironment();
|
||||
};
|
||||
|
||||
#endif /* SRC_AMBIANCE_H_ */
|
|
@ -29,6 +29,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "util/string.h"
|
||||
#include "util/srp.h"
|
||||
#include "client.h"
|
||||
|
||||
#include "ambiance.h"
|
||||
#include "network/clientopcodes.h"
|
||||
#include "filesys.h"
|
||||
#include "porting.h"
|
||||
|
@ -52,6 +54,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "serialization.h"
|
||||
#include "guiscalingfilter.h"
|
||||
|
||||
|
||||
extern gui::IGUIEnvironment* guienv;
|
||||
|
||||
/*
|
||||
|
@ -278,6 +281,7 @@ Client::Client(
|
|||
|
||||
m_cache_smooth_lighting = g_settings->getBool("smooth_lighting");
|
||||
m_cache_enable_shaders = g_settings->getBool("enable_shaders");
|
||||
m_ambiance = new Ambiance(m_sound, m_env);
|
||||
}
|
||||
|
||||
void Client::Stop()
|
||||
|
@ -479,6 +483,10 @@ void Client::step(float dtime)
|
|||
// Step environment
|
||||
m_env.step(dtime);
|
||||
|
||||
if ( g_settings->getBool("ambiance") ){
|
||||
m_ambiance->doAmbiance(dtime);
|
||||
}
|
||||
|
||||
/*
|
||||
Get events
|
||||
*/
|
||||
|
|
|
@ -28,6 +28,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "ambiance.h"
|
||||
#include "clientobject.h"
|
||||
#include "gamedef.h"
|
||||
#include "inventorymanager.h"
|
||||
|
@ -577,6 +579,7 @@ private:
|
|||
|
||||
MeshUpdateThread m_mesh_update_thread;
|
||||
ClientEnvironment m_env;
|
||||
Ambiance *m_ambiance;
|
||||
ParticleManager m_particle_manager;
|
||||
con::Connection m_con;
|
||||
IrrlichtDevice *m_device;
|
||||
|
|
|
@ -143,6 +143,7 @@ void set_default_settings(Settings *settings)
|
|||
settings->setDefault("mouse_sensitivity", "0.2");
|
||||
settings->setDefault("enable_sound", "true");
|
||||
settings->setDefault("sound_volume", "0.8");
|
||||
settings->setDefault("ambiance","true");
|
||||
settings->setDefault("desynchronize_mapblock_texture_animation", "true");
|
||||
settings->setDefault("selectionbox_width","2");
|
||||
settings->setDefault("hud_hotbar_max_width","1.0");
|
||||
|
|
|
@ -369,7 +369,7 @@ void Client::handleCommand_TimeOfDay(NetworkPacket* pkt)
|
|||
m_time_of_day_set = true;
|
||||
|
||||
u32 dr = m_env.getDayNightRatio();
|
||||
infostream << "Client: time_of_day=" << time_of_day
|
||||
infostream << "Client: time_of_day=" << time_of_day << "::" << m_env.getTimeOfDay()
|
||||
<< " time_speed=" << time_speed
|
||||
<< " dr=" << dr << std::endl;
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ SoundBuffer* loadOggFile(const std::string &filepath)
|
|||
char array[BUFFER_SIZE]; // Local fixed size array
|
||||
vorbis_info *pInfo;
|
||||
OggVorbis_File oggFile;
|
||||
|
||||
|
||||
// Do a dumb-ass static string copy for old versions of ov_fopen
|
||||
// because they expect a non-const char*
|
||||
char nonconst[10000];
|
||||
|
@ -211,7 +211,7 @@ public:
|
|||
m_is_initialized(false)
|
||||
{
|
||||
ALCenum error = ALC_NO_ERROR;
|
||||
|
||||
|
||||
infostream<<"Audio: Initializing..."<<std::endl;
|
||||
|
||||
m_device = alcOpenDevice(NULL);
|
||||
|
@ -283,7 +283,7 @@ public:
|
|||
m_buffers.clear();
|
||||
infostream<<"Audio: Deinitialized."<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
void addBuffer(const std::string &name, SoundBuffer *buf)
|
||||
{
|
||||
std::map<std::string, std::vector<SoundBuffer*> >::iterator i =
|
||||
|
@ -375,7 +375,7 @@ public:
|
|||
m_sounds_playing[id] = sound;
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
void deleteSound(int id)
|
||||
{
|
||||
std::map<int, PlayingSound*>::iterator i =
|
||||
|
@ -383,7 +383,7 @@ public:
|
|||
if(i == m_sounds_playing.end())
|
||||
return;
|
||||
PlayingSound *sound = i->second;
|
||||
|
||||
|
||||
alDeleteSources(1, &sound->source_id);
|
||||
|
||||
delete sound;
|
||||
|
@ -411,13 +411,13 @@ public:
|
|||
}
|
||||
return getBuffer(name);
|
||||
}
|
||||
|
||||
|
||||
// Remove stopped sounds
|
||||
void maintain()
|
||||
{
|
||||
verbosestream<<"OpenALSoundManager::maintain(): "
|
||||
<<m_sounds_playing.size()<<" playing sounds, "
|
||||
<<m_buffers.size()<<" sound names loaded"<<std::endl;
|
||||
//verbosestream<<"OpenALSoundManager::maintain(): "
|
||||
// <<m_sounds_playing.size()<<" playing sounds, "
|
||||
// <<m_buffers.size()<<" sound names loaded"<<std::endl;
|
||||
std::set<int> del_list;
|
||||
for(std::map<int, PlayingSound*>::iterator
|
||||
i = m_sounds_playing.begin();
|
||||
|
@ -482,7 +482,7 @@ public:
|
|||
alListenerfv(AL_ORIENTATION, f);
|
||||
warn_if_error(alGetError(), "updateListener");
|
||||
}
|
||||
|
||||
|
||||
void setListenerGain(float gain)
|
||||
{
|
||||
alListenerf(AL_GAIN, gain);
|
||||
|
|
Loading…
Reference in New Issue