adventuretest-client/src/ambiance.h

141 lines
2.8 KiB
C
Raw Permalink Normal View History

2015-06-18 11:15:06 -07:00
/*
* ambience.h
*
* Created on: Jun 13, 2015
* Author: brandon
*/
#ifndef SRC_AMBIANCE_H_
#define SRC_AMBIANCE_H_
#include "gamedef.h"
#include "environment.h"
2017-02-11 19:45:33 -08:00
#include "clientenvironment.h"
2015-06-18 11:15:06 -07:00
#include "sound.h"
#include "settings.h"
#include "sound_openal.h"
2015-07-02 16:38:12 -07:00
#include "nodedef.h"
2015-06-18 11:15:06 -07:00
class Ambiance
{
public:
Ambiance(ISoundManager *sound, ClientEnvironment &e);
2015-07-02 16:38:12 -07:00
void doAmbiance(float dtime, u32 tod);
2015-06-18 11:15:06 -07:00
private:
2015-07-24 20:11:33 -07:00
bool playSound(std::string name, float gain, bool fade = false);
void doFades(float dtime);
2015-07-02 16:38:12 -07:00
bool nodesInRange(v3s16 pos, short searchRange, short searchAbove, short searchBelow, std::string nodeName, short accuracy, int count);
2015-06-18 11:15:06 -07:00
std::string getNodeName(v3s16 pos);
2015-07-02 16:38:12 -07:00
int getNodeId(v3s16 pos);
2015-06-18 11:15:06 -07:00
void stopEnvironment(int env);
2015-07-02 16:38:12 -07:00
int readEnvironment();
2015-07-24 20:11:33 -07:00
void fadeSound(int soundid, float step, float gain);
2015-07-02 16:38:12 -07:00
u32 m_timeOfDay;
2015-06-18 11:15:06 -07:00
ISoundManager *m_sound;
ClientEnvironment m_env;
2015-07-02 16:38:12 -07:00
int m_background_sound;
2015-06-18 11:15:06 -07:00
std::map<std::string, int> m_sounds_playing;
typedef std::map<std::string, int>::iterator m_sounds_it;
2015-07-24 20:11:33 -07:00
struct fade_status {
fade_status() {}
fade_status(float step, float current_gain, float target_gain):
step(step),
current_gain(current_gain),
target_gain(target_gain){}
float step;
float current_gain;
float target_gain;
};
std::map<int, fade_status> m_sounds_fading; // 0 = step, 1 = current gain, 2 = goal gain
typedef std::map<int, fade_status>::iterator m_fading_it;
2015-06-18 11:15:06 -07:00
v3f lastpos;
bool ascending;
bool descending;
bool moving;
bool underwater;
float startDelay;
float envDelay;
2015-07-02 16:38:12 -07:00
float tickDelay;
2015-06-18 11:15:06 -07:00
2015-07-16 14:33:40 -07:00
int currentEnv;
2015-06-18 11:15:06 -07:00
int lastEnv;
float lastPlay;
2015-07-02 16:38:12 -07:00
int TOD;
int lastTOD;
2015-06-18 11:15:06 -07:00
struct env_sound {
2015-07-16 14:33:40 -07:00
env_sound() {}
env_sound(std::string name,
float gain):
name(name),
gain(gain) {}
2015-06-18 11:15:06 -07:00
std::string name;
float gain;
};
struct ambiance_environment {
2015-07-16 14:33:40 -07:00
ambiance_environment() {}
ambiance_environment(std::string name,
int frequency,
int sound_count,
std::string on_start,
std::string on_stop,
std::string background_sound,
float next_sound_delay):
name(name),
frequency(frequency),
sound_count(sound_count),
on_start(on_start),
on_stop(on_stop),
background_sound(background_sound),
next_sound_delay(next_sound_delay) {}
2015-06-18 11:15:06 -07:00
std::string name;
int frequency;
int sound_count;
std::string on_start;
std::string on_stop;
2015-07-02 16:38:12 -07:00
std::string background_sound;
2015-06-18 11:15:06 -07:00
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,
2015-07-02 16:38:12 -07:00
ENV_PLAINS,
ENV_PLAINS_NIGHT,
ENV_FOREST,
ENV_FOREST_NIGHT,
ENV_SNOW,
ENV_SNOW_NIGHT,
ENV_OCEAN,
ENV_DESERT,
ENV_DESERT_NIGHT,
ENV_JUNGLE,
ENV_JUNGLE_NIGHT
2015-06-18 11:15:06 -07:00
};
2015-07-02 16:38:12 -07:00
enum time_of_day {
MORNING,
DAY,
DUSK,
NIGHT
};
ambiance_environment a_env[15];
2015-06-18 11:15:06 -07:00
};
#endif /* SRC_AMBIANCE_H_ */