forked from oerkki/voxelands
add sounds for other players walking and digging, and mobs walking
This commit is contained in:
parent
004ff0b90a
commit
542b5d5904
Binary file not shown.
|
@ -2341,61 +2341,15 @@ ISoundManager* Client::getSoundManager()
|
|||
// foot: 0 = left, 1 = right
|
||||
void Client::playStepSound(int foot)
|
||||
{
|
||||
if (!m_sound)
|
||||
if (!g_sound)
|
||||
return;
|
||||
|
||||
v3f pf = m_env.getLocalPlayer()->getPosition();
|
||||
v3s16 pp = floatToInt(pf + v3f(0, BS*0.1, 0), BS);
|
||||
MapNode n = m_env.getMap().getNodeNoEx(pp);
|
||||
ContentFeatures *f = &content_features(n);
|
||||
if (f->type == CMT_AIR) {
|
||||
pp.Y--;
|
||||
n = m_env.getMap().getNodeNoEx(pp);
|
||||
f = &content_features(n);
|
||||
}
|
||||
|
||||
std::string snd("");
|
||||
|
||||
if (f->sound_step != "") {
|
||||
snd = f->sound_step;
|
||||
}else{
|
||||
switch (f->type) {
|
||||
case CMT_PLANT:
|
||||
snd = "plant-step";
|
||||
break;
|
||||
case CMT_DIRT:
|
||||
snd = "dirt-step";
|
||||
break;
|
||||
case CMT_STONE:
|
||||
snd = "stone-step";
|
||||
break;
|
||||
case CMT_LIQUID:
|
||||
snd = "liquid-step";
|
||||
break;
|
||||
case CMT_WOOD:
|
||||
snd = "wood-step";
|
||||
break;
|
||||
case CMT_GLASS:
|
||||
snd = "glass-step";
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
||||
if (snd == "")
|
||||
return;
|
||||
|
||||
if (foot == 0) {
|
||||
snd += "-left";
|
||||
}else{
|
||||
snd += "-right";
|
||||
}
|
||||
m_sound->playSound(snd,false);
|
||||
sound_playStep(&m_env.getMap(),m_env.getLocalPlayer()->getPosition(),foot);
|
||||
}
|
||||
|
||||
void Client::playDigSound(content_t c)
|
||||
{
|
||||
if (!m_sound)
|
||||
if (!g_sound)
|
||||
return;
|
||||
|
||||
if (c == CONTENT_IGNORE) {
|
||||
|
@ -2403,33 +2357,7 @@ void Client::playDigSound(content_t c)
|
|||
if ((c&CONTENT_MOB_MASK) != 0)
|
||||
return;
|
||||
}
|
||||
ContentFeatures *f = &content_features(c);
|
||||
if (f->sound_dig != "") {
|
||||
m_sound->playSound(f->sound_dig,false);
|
||||
return;
|
||||
}
|
||||
switch (f->type) {
|
||||
case CMT_PLANT:
|
||||
m_sound->playSound("plant-dig",false);
|
||||
break;
|
||||
case CMT_DIRT:
|
||||
m_sound->playSound("dirt-dig",false);
|
||||
break;
|
||||
case CMT_STONE:
|
||||
m_sound->playSound("stone-dig",false);
|
||||
break;
|
||||
case CMT_LIQUID:
|
||||
m_sound->playSound("liquid-dig",false);
|
||||
break;
|
||||
case CMT_WOOD:
|
||||
m_sound->playSound("wood-dig",false);
|
||||
break;
|
||||
case CMT_GLASS:
|
||||
m_sound->playSound("glass-dig",false);
|
||||
break;
|
||||
default:
|
||||
m_sound->playSound("miss-dig",false);
|
||||
}
|
||||
sound_playDig(c,m_env.getLocalPlayer()->getPosition());
|
||||
}
|
||||
|
||||
void Client::playPlaceSound(content_t c)
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "settings.h"
|
||||
#include "mesh.h"
|
||||
#include <ICameraSceneNode.h>
|
||||
#include "sound.h"
|
||||
|
||||
core::map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
|
||||
|
||||
|
@ -241,6 +242,8 @@ MobCAO::MobCAO():
|
|||
m_shooting_unset_timer(0),
|
||||
m_walking(false),
|
||||
m_walking_unset_timer(0),
|
||||
m_last_step(0),
|
||||
m_next_foot(0),
|
||||
m_draw_type(MDT_AUTO)
|
||||
{
|
||||
ClientActiveObject::registerType(getType(), create);
|
||||
|
@ -471,6 +474,16 @@ void MobCAO::step(float dtime, ClientEnvironment *env)
|
|||
setAnimation(MA_STAND);
|
||||
}
|
||||
}
|
||||
|
||||
if (!m.moves_silently && m_walking && m_draw_type == MDT_MODEL) {
|
||||
m_last_step += dtime;
|
||||
/* roughly sort of when a step sound should probably be heard, maybe */
|
||||
if (m_last_step > 0.5) {
|
||||
m_last_step -= 0.5;
|
||||
sound_playStep(&env->getMap(),m_position,m_next_foot, 0.3);
|
||||
m_next_foot = !m_next_foot;
|
||||
}
|
||||
}
|
||||
}
|
||||
void MobCAO::processMessage(const std::string &data)
|
||||
{
|
||||
|
|
|
@ -234,6 +234,8 @@ private:
|
|||
float m_shooting_unset_timer;
|
||||
bool m_walking;
|
||||
float m_walking_unset_timer;
|
||||
float m_last_step;
|
||||
int m_next_foot;
|
||||
|
||||
MobDrawType m_draw_type;
|
||||
};
|
||||
|
|
|
@ -237,6 +237,7 @@ void content_mob_init()
|
|||
f->motion = MM_WANDER;
|
||||
f->motion_type = MMT_FLYLOW;
|
||||
f->glow_light = LIGHT_MAX-1;
|
||||
f->moves_silently = true;
|
||||
f->spawn_on = CONTENT_JUNGLETREE;
|
||||
f->spawn_in = CONTENT_AIR;
|
||||
f->spawn_min_height = -5;
|
||||
|
@ -286,6 +287,7 @@ void content_mob_init()
|
|||
f->punch_action = MPA_HARM;
|
||||
f->dropped_item = std::string("CraftItem2 ")+itos(CONTENT_CRAFTITEM_OERKKI_DUST)+" 2";
|
||||
f->motion = MM_SEEKER;
|
||||
f->moves_silently = true;
|
||||
f->spawn_on = CONTENT_STONE;
|
||||
f->spawn_in = CONTENT_AIR;
|
||||
f->spawn_max_height = 2;
|
||||
|
@ -362,6 +364,7 @@ void content_mob_init()
|
|||
f->motion_type = MMT_FLY;
|
||||
f->glow_light = LIGHT_MAX-1;
|
||||
f->notices_player = true;
|
||||
f->moves_silently = true;
|
||||
f->attack_player_damage = 3;
|
||||
f->attack_player_range = v3f(2,2,2);
|
||||
f->contact_explosion_diameter = 3;
|
||||
|
@ -463,6 +466,7 @@ void content_mob_init()
|
|||
f->special_dropped_max = 0;
|
||||
f->motion = MM_WANDER;
|
||||
f->motion_type = MMT_SWIM;
|
||||
f->moves_silently = true;
|
||||
f->spawn_on = CONTENT_SAND;
|
||||
f->spawn_in = CONTENT_WATERSOURCE;
|
||||
f->spawn_min_height = -30;
|
||||
|
@ -489,6 +493,7 @@ void content_mob_init()
|
|||
f->dropped_item = std::string("CraftItem2 ")+itos(CONTENT_CRAFTITEM_MEAT)+" 2";
|
||||
f->motion = MM_SEEKER;
|
||||
f->motion_type = MMT_SWIM;
|
||||
f->moves_silently = true;
|
||||
f->spawn_on = CONTENT_SAND;
|
||||
f->spawn_in = CONTENT_WATERSOURCE;
|
||||
f->spawn_min_height = -30;
|
||||
|
@ -593,6 +598,7 @@ void content_mob_init()
|
|||
f->punch_action = MPA_IGNORE;
|
||||
f->motion = MM_THROWN;
|
||||
f->motion_type = MMT_FLY;
|
||||
f->moves_silently = true;
|
||||
f->notices_player = true;
|
||||
f->attack_mob_damage = 5;
|
||||
f->attack_mob_range = v3f(1,1,1);
|
||||
|
@ -611,6 +617,7 @@ void content_mob_init()
|
|||
f->punch_action = MPA_IGNORE;
|
||||
f->motion = MM_THROWN;
|
||||
f->motion_type = MMT_FLY;
|
||||
f->moves_silently = true;
|
||||
f->notices_player = true;
|
||||
f->attack_mob_damage = 20;
|
||||
f->attack_mob_range = v3f(1,1,1);
|
||||
|
|
|
@ -132,6 +132,7 @@ struct MobFeatures {
|
|||
u16 contact_explosion_diameter;
|
||||
content_t contact_place_node;
|
||||
content_t contact_drop_item;
|
||||
bool moves_silently;
|
||||
|
||||
std::string sound_spawn;
|
||||
std::string sound_death;
|
||||
|
@ -260,6 +261,7 @@ struct MobFeatures {
|
|||
contact_explosion_diameter = 0;
|
||||
contact_place_node = CONTENT_IGNORE;
|
||||
contact_drop_item = CONTENT_IGNORE;
|
||||
moves_silently = false;
|
||||
sound_spawn = "";
|
||||
sound_death = "";
|
||||
sound_attack = "";
|
||||
|
|
|
@ -453,6 +453,8 @@ void ServerRemotePlayer::setCharDef(std::string d)
|
|||
|
||||
#ifndef SERVER
|
||||
|
||||
#include "sound.h"
|
||||
|
||||
RemotePlayer::RemotePlayer(
|
||||
scene::ISceneNode* parent,
|
||||
IrrlichtDevice *device,
|
||||
|
@ -461,7 +463,8 @@ RemotePlayer::RemotePlayer(
|
|||
m_node(NULL),
|
||||
m_text(NULL),
|
||||
m_wield(NULL),
|
||||
m_anim_id(PLAYERANIM_STAND)
|
||||
m_anim_id(PLAYERANIM_STAND),
|
||||
m_next_foot(0)
|
||||
{
|
||||
m_box = core::aabbox3d<f32>(-BS/2,0,-BS/2,BS/2,BS*2,BS/2);
|
||||
|
||||
|
@ -595,6 +598,17 @@ void RemotePlayer::move(f32 dtime, Map &map, f32 pos_max_d)
|
|||
moveratio = 1.5;
|
||||
m_showpos = m_oldpos + movevector * moveratio;
|
||||
|
||||
int frame = m_node->getFrameNr();
|
||||
/* roughly sort of when a step sound should probably be heard, maybe */
|
||||
if (frame == 218 || frame == 186 || frame == 209 || frame == 177) {
|
||||
sound_playStep(&map,m_showpos,m_next_foot);
|
||||
m_next_foot = !m_next_foot;
|
||||
}
|
||||
/* roughly sort of when a dig sound should probably be heard, maybe */
|
||||
if (frame == 214 || frame == 205 || frame == 193) {
|
||||
sound_playDig(CMT_STONE,m_showpos);
|
||||
}
|
||||
|
||||
if (
|
||||
(
|
||||
movevector.X < 0.001
|
||||
|
@ -611,10 +625,10 @@ void RemotePlayer::move(f32 dtime, Map &map, f32 pos_max_d)
|
|||
m_node->setFrameLoop(0,79);
|
||||
}
|
||||
}else{
|
||||
if (m_anim_id == PLAYERANIM_DIG) {
|
||||
if (m_anim_id == PLAYERANIM_DIG) { // walk/dig
|
||||
if (m_node->getEndFrame() != 219)
|
||||
m_node->setFrameLoop(200,219);
|
||||
}else if (m_node->getEndFrame() != 187) {
|
||||
}else if (m_node->getEndFrame() != 187) { // walk
|
||||
m_node->setFrameLoop(168,187);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,6 @@ public:
|
|||
void resetInventory();
|
||||
void checkInventory();
|
||||
|
||||
//void move(f32 dtime, Map &map);
|
||||
virtual void move(f32 dtime, Map &map, f32 pos_max_d) = 0;
|
||||
|
||||
v3f getSpeed()
|
||||
|
@ -415,11 +414,9 @@ private:
|
|||
v3f m_showpos;
|
||||
v3f m_camera_offset;
|
||||
u8 m_anim_id;
|
||||
int m_next_foot;
|
||||
};
|
||||
|
||||
#endif // !SERVER
|
||||
|
||||
#ifndef SERVER
|
||||
struct PlayerControl
|
||||
{
|
||||
PlayerControl()
|
||||
|
|
|
@ -24,11 +24,14 @@
|
|||
************************************************************************/
|
||||
|
||||
#include "sound.h"
|
||||
#include "map.h"
|
||||
#include "mapnode.h"
|
||||
#include "content_mapnode.h"
|
||||
#include "content_mob.h"
|
||||
|
||||
// Global DummySoundManager singleton
|
||||
DummySoundManager dummySoundManager;
|
||||
ISoundManager *g_sound = NULL;
|
||||
|
||||
void init_sounds(ISoundManager *sound)
|
||||
{
|
||||
|
@ -114,6 +117,97 @@ void init_sounds(ISoundManager *sound)
|
|||
sound->loadSound("bg-charcreator","bg_charcreator.ogg");
|
||||
}
|
||||
|
||||
void sound_playStep(Map *map, v3f pos, int foot, float gain)
|
||||
{
|
||||
if (!g_sound)
|
||||
return;
|
||||
|
||||
v3s16 p = floatToInt(pos,BS);
|
||||
MapNode n = map->getNodeNoEx(p);
|
||||
ContentFeatures *f = &content_features(n);
|
||||
if (f->type == CMT_AIR) {
|
||||
p.Y--;
|
||||
n = map->getNodeNoEx(p);
|
||||
f = &content_features(n);
|
||||
}
|
||||
|
||||
std::string snd("");
|
||||
|
||||
if (f->sound_step != "") {
|
||||
snd = f->sound_step;
|
||||
}else{
|
||||
switch (f->type) {
|
||||
case CMT_PLANT:
|
||||
snd = "plant-step";
|
||||
break;
|
||||
case CMT_DIRT:
|
||||
snd = "dirt-step";
|
||||
break;
|
||||
case CMT_STONE:
|
||||
snd = "stone-step";
|
||||
break;
|
||||
case CMT_LIQUID:
|
||||
snd = "liquid-step";
|
||||
break;
|
||||
case CMT_WOOD:
|
||||
snd = "wood-step";
|
||||
break;
|
||||
case CMT_GLASS:
|
||||
snd = "glass-step";
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
||||
if (snd == "")
|
||||
return;
|
||||
|
||||
if (foot == 0) {
|
||||
snd += "-left";
|
||||
}else{
|
||||
snd += "-right";
|
||||
}
|
||||
|
||||
g_sound->playSoundAt(snd,false,pos,gain);
|
||||
}
|
||||
|
||||
void sound_playDig(content_t c, v3f pos)
|
||||
{
|
||||
if (!g_sound)
|
||||
return;
|
||||
|
||||
if (c == CONTENT_IGNORE)
|
||||
return;
|
||||
|
||||
ContentFeatures *f = &content_features(c);
|
||||
if (f->sound_dig != "") {
|
||||
g_sound->playSoundAt(f->sound_dig,false,pos);
|
||||
return;
|
||||
}
|
||||
switch (f->type) {
|
||||
case CMT_PLANT:
|
||||
g_sound->playSoundAt("plant-dig",false,pos);
|
||||
break;
|
||||
case CMT_DIRT:
|
||||
g_sound->playSoundAt("dirt-dig",false,pos);
|
||||
break;
|
||||
case CMT_STONE:
|
||||
g_sound->playSoundAt("stone-dig",false,pos);
|
||||
break;
|
||||
case CMT_LIQUID:
|
||||
g_sound->playSoundAt("liquid-dig",false,pos);
|
||||
break;
|
||||
case CMT_WOOD:
|
||||
g_sound->playSoundAt("wood-dig",false,pos);
|
||||
break;
|
||||
case CMT_GLASS:
|
||||
g_sound->playSoundAt("glass-dig",false,pos);
|
||||
break;
|
||||
default:
|
||||
g_sound->playSoundAt("miss-dig",false,pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef SERVER
|
||||
|
||||
|
|
11
src/sound.h
11
src/sound.h
|
@ -30,6 +30,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include "mapnode.h"
|
||||
|
||||
class ISoundManager
|
||||
{
|
||||
|
@ -47,7 +48,7 @@ public:
|
|||
// playSound functions return -1 on failure, otherwise a handle to the
|
||||
// sound. If name=="", call should be ignored without error.
|
||||
virtual int playSound(const std::string &name, bool loop) = 0;
|
||||
virtual int playSoundAt(const std::string &name, bool loop, v3f pos) = 0;
|
||||
virtual int playSoundAt(const std::string &name, bool loop, v3f pos, float gain=1.0) = 0;
|
||||
virtual void stopSound(int sound) = 0;
|
||||
virtual bool soundExists(int sound) = 0;
|
||||
|
||||
|
@ -68,7 +69,7 @@ public:
|
|||
void setListenerGain(float gain) {}
|
||||
|
||||
int playSound(const std::string &name, bool loop) {return 0;}
|
||||
int playSoundAt(const std::string &name, bool loop, v3f pos) {return 0;}
|
||||
int playSoundAt(const std::string &name, bool loop, v3f pos, float gain) {return 0;}
|
||||
void stopSound(int sound) {}
|
||||
bool soundExists(int sound) {return false;}
|
||||
|
||||
|
@ -83,7 +84,13 @@ public:
|
|||
ISoundManager *createSoundManager();
|
||||
void init_sounds(ISoundManager *sound);
|
||||
|
||||
class Map;
|
||||
|
||||
// Global DummySoundManager singleton
|
||||
extern DummySoundManager dummySoundManager;
|
||||
extern ISoundManager *g_sound;
|
||||
|
||||
void sound_playStep(Map *map, v3f pos, int foot, float gain=1.0);
|
||||
void sound_playDig(content_t c, v3f pos);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -336,7 +336,7 @@ public:
|
|||
return sound;
|
||||
}
|
||||
|
||||
PlayingSound* createPlayingSoundAt(SoundBuffer *buf, bool loop, v3f pos)
|
||||
PlayingSound* createPlayingSoundAt(SoundBuffer *buf, bool loop, v3f pos, float gain)
|
||||
{
|
||||
infostream<<"OpenALSoundManager: Creating positional playing sound"
|
||||
<<std::endl;
|
||||
|
@ -353,7 +353,7 @@ public:
|
|||
//alSourcef(sound->source_id, AL_ROLLOFF_FACTOR, 0.7);
|
||||
alSourcef(sound->source_id, AL_REFERENCE_DISTANCE, 30.0);
|
||||
alSourcei(sound->source_id, AL_LOOPING, loop ? AL_TRUE : AL_FALSE);
|
||||
float volume = MYMAX(0.0, buf->gain);
|
||||
float volume = MYMAX(0.0, buf->gain*gain);
|
||||
alSourcef(sound->source_id, AL_GAIN, volume);
|
||||
alSourcePlay(sound->source_id);
|
||||
sound->should_delete = false;
|
||||
|
@ -371,10 +371,10 @@ public:
|
|||
return id;
|
||||
}
|
||||
|
||||
int playSoundRawAt(SoundBuffer *buf, bool loop, v3f pos)
|
||||
int playSoundRawAt(SoundBuffer *buf, bool loop, v3f pos, float gain)
|
||||
{
|
||||
assert(buf);
|
||||
PlayingSound *sound = createPlayingSoundAt(buf, loop, pos);
|
||||
PlayingSound *sound = createPlayingSoundAt(buf, loop, pos, gain);
|
||||
if (!sound)
|
||||
return -1;
|
||||
int id = m_next_id++;
|
||||
|
@ -449,7 +449,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
bool loadSound(const std::string &name, const std::string &filepath, float gain)
|
||||
bool loadSound(const std::string &name, const std::string &filepath, float gain=1.0)
|
||||
{
|
||||
std::string path = getPath("sound",filepath,true);
|
||||
if (path == "")
|
||||
|
@ -490,7 +490,7 @@ public:
|
|||
}
|
||||
return playSoundRaw(buf, loop);
|
||||
}
|
||||
int playSoundAt(const std::string &name, bool loop, v3f pos)
|
||||
int playSoundAt(const std::string &name, bool loop, v3f pos, float gain)
|
||||
{
|
||||
if (name == "")
|
||||
return 0;
|
||||
|
@ -500,7 +500,7 @@ public:
|
|||
<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
return playSoundRawAt(buf, loop, pos);
|
||||
return playSoundRawAt(buf, loop, pos, gain);
|
||||
}
|
||||
void stopSound(int id)
|
||||
{
|
||||
|
@ -557,6 +557,7 @@ public:
|
|||
ISoundManager *createSoundManager()
|
||||
{
|
||||
ISoundManager *sound = new OpenALSoundManager();
|
||||
g_sound = sound;
|
||||
init_sounds(sound);
|
||||
return sound;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue