walk sounds

This commit is contained in:
darkrose 2014-08-19 16:26:31 +10:00
parent e6854a1293
commit c255099ec1
28 changed files with 109 additions and 36 deletions

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.

View File

@ -33,7 +33,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define CAMERA_OFFSET_STEP 200 #define CAMERA_OFFSET_STEP 200
Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control): Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, Client *client):
m_client(client),
m_smgr(smgr), m_smgr(smgr),
m_playernode(NULL), m_playernode(NULL),
m_headnode(NULL), m_headnode(NULL),
@ -129,25 +130,9 @@ inline f32 my_modf(f32 x)
void Camera::step(f32 dtime) void Camera::step(f32 dtime)
{ {
if (m_view_bobbing_state != 0) if (m_view_bobbing_state != 0) {
{
//f32 offset = dtime * m_view_bobbing_speed * 0.035;
f32 offset = dtime * m_view_bobbing_speed * 0.030; f32 offset = dtime * m_view_bobbing_speed * 0.030;
if (m_view_bobbing_state == 2) if (m_view_bobbing_state == 2) {
{
#if 0
// Animation is getting turned off
if (m_view_bobbing_anim < 0.5)
m_view_bobbing_anim -= offset;
else
m_view_bobbing_anim += offset;
if (m_view_bobbing_anim <= 0 || m_view_bobbing_anim >= 1)
{
m_view_bobbing_anim = 0;
m_view_bobbing_state = 0;
}
#endif
#if 1
// Animation is getting turned off // Animation is getting turned off
if(m_view_bobbing_anim < 0.25){ if(m_view_bobbing_anim < 0.25){
m_view_bobbing_anim -= offset; m_view_bobbing_anim -= offset;
@ -168,10 +153,7 @@ void Camera::step(f32 dtime)
m_view_bobbing_anim = 0; m_view_bobbing_anim = 0;
m_view_bobbing_state = 0; m_view_bobbing_state = 0;
} }
#endif }else{
}
else
{
float was = m_view_bobbing_anim; float was = m_view_bobbing_anim;
m_view_bobbing_anim = my_modf(m_view_bobbing_anim + offset); m_view_bobbing_anim = my_modf(m_view_bobbing_anim + offset);
if ( if (
@ -179,7 +161,7 @@ void Camera::step(f32 dtime)
|| (was < 0.5f && m_view_bobbing_anim >= 0.5f) || (was < 0.5f && m_view_bobbing_anim >= 0.5f)
|| (was > 0.5f && m_view_bobbing_anim <= 0.5f) || (was > 0.5f && m_view_bobbing_anim <= 0.5f)
) { ) {
printf("step\n"); m_client->playStepSound();
} }
} }
} }
@ -188,17 +170,16 @@ void Camera::step(f32 dtime)
f32 offset = dtime * 3.5; f32 offset = dtime * 3.5;
float m_digging_anim_was = m_digging_anim; float m_digging_anim_was = m_digging_anim;
m_digging_anim += offset; m_digging_anim += offset;
if (m_digging_anim >= 1) if (m_digging_anim >= 1) {
{
m_digging_anim = 0; m_digging_anim = 0;
m_digging_button = -1; m_digging_button = -1;
} }
float lim = 0.15; float lim = 0.15;
if (m_digging_anim_was < lim && m_digging_anim >= lim) { if (m_digging_anim_was < lim && m_digging_anim >= lim) {
if (m_digging_button == 0) { if (m_digging_button == 0) {
printf("dig\n"); m_client->playDigSound();
}else if(m_digging_button == 1) { }else if(m_digging_button == 1) {
printf("place\n"); m_client->playPlaceSound();
} }
} }
} }

View File

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class LocalPlayer; class LocalPlayer;
class MapDrawControl; class MapDrawControl;
class ExtrudedSpriteSceneNode; class ExtrudedSpriteSceneNode;
class Client;
/* /*
Client camera class, manages the player and camera scene nodes, the viewing distance Client camera class, manages the player and camera scene nodes, the viewing distance
@ -40,7 +41,7 @@ class ExtrudedSpriteSceneNode;
class Camera class Camera
{ {
public: public:
Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control); Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, Client *client);
~Camera(); ~Camera();
// Get player scene node. // Get player scene node.
@ -130,6 +131,7 @@ public:
void drawWieldedTool(); void drawWieldedTool();
private: private:
Client *m_client;
// Scene manager and nodes // Scene manager and nodes
scene::ISceneManager* m_smgr; scene::ISceneManager* m_smgr;
scene::ISceneNode* m_playernode; scene::ISceneNode* m_playernode;

View File

@ -2251,3 +2251,49 @@ ISoundManager* Client::getSoundManager()
return m_sound; return m_sound;
} }
void Client::playStepSound()
{
if (!m_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);
if (content_features(n).type == CMT_AIR) {
pp.Y--;
n = m_env.getMap().getNodeNoEx(pp);
}
switch (content_features(n).type) {
case CMT_PLANT:
m_sound->playSound("plant-walk",false,1.0);
break;
case CMT_DIRT:
m_sound->playSound("dirt-walk",false,1.0);
break;
case CMT_STONE:
m_sound->playSound("stone-walk",false,1.0);
break;
case CMT_LIQUID:
m_sound->playSound("liquid-walk",false,1.0);
break;
case CMT_WOOD:
m_sound->playSound("wood-walk",false,1.0);
break;
default:;
}
}
void Client::playDigSound()
{
if (!m_sound)
return;
printf("dig\n");
}
void Client::playPlaceSound()
{
if (!m_sound)
return;
printf("place\n");
}

View File

@ -321,6 +321,10 @@ public:
float getRTT(void); float getRTT(void);
virtual ISoundManager* getSoundManager(); virtual ISoundManager* getSoundManager();
void playStepSound();
void playDigSound();
void playPlaceSound();
private: private:
// Virtual methods from con::PeerHandler // Virtual methods from con::PeerHandler

View File

@ -867,7 +867,7 @@ void the_game(
/* /*
Create the camera node Create the camera node
*/ */
Camera camera(smgr, draw_control); Camera camera(smgr, draw_control, &client);
if (!camera.successfullyCreated(error_message)) if (!camera.successfullyCreated(error_message))
return; return;

View File

@ -139,7 +139,7 @@ std::string getPath(const char* tp, const std::string &filename, bool must_exist
std::string data_path = g_settings->get("data_path"); std::string data_path = g_settings->get("data_path");
if (data_path != "") { if (data_path != "") {
std::string testpath = data_path + DIR_DELIM + rel_path; std::string testpath = data_path + DIR_DELIM + rel_path;
if (type == "model" || type == "html") { if (type == "model" || type == "html" || type == "sound") {
if (fs::PathExists(testpath)) if (fs::PathExists(testpath))
fullpath = std::string(testpath); fullpath = std::string(testpath);
}else{ }else{
@ -150,7 +150,7 @@ std::string getPath(const char* tp, const std::string &filename, bool must_exist
/* check from user data directory */ /* check from user data directory */
if (fullpath == "") { if (fullpath == "") {
std::string testpath = porting::path_userdata + DIR_DELIM + rel_path; std::string testpath = porting::path_userdata + DIR_DELIM + rel_path;
if (type == "model" || type == "html") { if (type == "model" || type == "html" || type == "sound") {
if (fs::PathExists(testpath)) if (fs::PathExists(testpath))
fullpath = std::string(testpath); fullpath = std::string(testpath);
}else{ }else{
@ -161,7 +161,7 @@ std::string getPath(const char* tp, const std::string &filename, bool must_exist
/* check from default data directory */ /* check from default data directory */
if (fullpath == "") { if (fullpath == "") {
std::string testpath = porting::path_data + DIR_DELIM + rel_path; std::string testpath = porting::path_data + DIR_DELIM + rel_path;
if (type == "model" || type == "html") { if (type == "model" || type == "html" || type == "sound") {
if (fs::PathExists(testpath)) if (fs::PathExists(testpath))
fullpath = std::string(testpath); fullpath = std::string(testpath);
}else{ }else{

View File

@ -24,5 +24,44 @@ DummySoundManager dummySoundManager;
void init_sounds(ISoundManager *sound) void init_sounds(ISoundManager *sound)
{ {
sound->loadSound("grass-walk","grass_footstep.1.ogg"); // walking
// CMT_DIRT
sound->loadSound("dirt-walk","dirt_footstep.1.ogg");
sound->loadSound("dirt-walk","dirt_footstep.2.ogg");
sound->loadSound("dirt-walk","dirt_footstep.3.ogg");
sound->loadSound("dirt-walk","dirt_footstep.4.ogg");
// CMT_STONE
sound->loadSound("stone-walk","stone_footstep.1.ogg");
sound->loadSound("stone-walk","stone_footstep.2.ogg");
sound->loadSound("stone-walk","stone_footstep.3.ogg");
sound->loadSound("stone-walk","stone_footstep.4.ogg");
// CMT_PLANT
sound->loadSound("plant-walk","plant_footstep.1.ogg");
sound->loadSound("plant-walk","plant_footstep.2.ogg");
sound->loadSound("plant-walk","plant_footstep.3.ogg");
sound->loadSound("plant-walk","plant_footstep.4.ogg");
// CMT_LIQUID
sound->loadSound("liquid-walk","liquid_footstep.1.ogg");
sound->loadSound("liquid-walk","liquid_footstep.2.ogg");
sound->loadSound("liquid-walk","liquid_footstep.3.ogg");
sound->loadSound("liquid-walk","liquid_footstep.4.ogg");
// CMT_WOOD
sound->loadSound("wood-walk","wood_footstep.1.ogg");
sound->loadSound("wood-walk","wood_footstep.2.ogg");
sound->loadSound("wood-walk","wood_footstep.3.ogg");
sound->loadSound("wood-walk","wood_footstep.4.ogg");
// digging
// CMT_DIRT
// CMT_STONE
// CMT_PLANT
// CMT_LIQUID
// CMT_WOOD
// placing
// CMT_DIRT
// CMT_STONE
// CMT_PLANT
// CMT_LIQUID
// CMT_WOOD
} }

View File

@ -262,6 +262,7 @@ public:
} }
std::vector<SoundBuffer*> bufs; std::vector<SoundBuffer*> bufs;
bufs.push_back(buf); bufs.push_back(buf);
m_buffers[name] = bufs;
return; return;
} }
@ -413,10 +414,10 @@ public:
int playSound(const std::string &name, bool loop, float volume) int playSound(const std::string &name, bool loop, float volume)
{ {
maintain(); maintain();
if(name == "") if (name == "")
return 0; return 0;
SoundBuffer *buf = getBuffer(name); SoundBuffer *buf = getBuffer(name);
if(!buf){ if (!buf) {
infostream<<"OpenALSoundManager: \""<<name<<"\" not found." infostream<<"OpenALSoundManager: \""<<name<<"\" not found."
<<std::endl; <<std::endl;
return -1; return -1;