-- Node definitions
--
+-- Default node sounds
+
+function default.node_sound_defaults(table)
+ table = table or {}
+ table.footstep = table.footstep or
+ {name="", gain=1.0}
+ table.dug = table.dug or
+ {name="default_dug_node", gain=1.0}
+ return table
+end
+
+function default.node_sound_stone_defaults(table)
+ table = table or {}
+ table.footstep = table.footstep or
+ {name="default_hard_footstep", gain=0.2}
+ default.node_sound_defaults(table)
+ return table
+end
+
+function default.node_sound_dirt_defaults(table)
+ table = table or {}
+ table.footstep = table.footstep or
+ {name="", gain=0.5}
+ --table.dug = table.dug or
+ -- {name="default_dirt_break", gain=0.5}
+ default.node_sound_defaults(table)
+ return table
+end
+
+function default.node_sound_sand_defaults(table)
+ table = table or {}
+ table.footstep = table.footstep or
+ {name="default_grass_footstep", gain=0.25}
+ table.dug = table.dug or
+ {name="default_dirt_break", gain=0.25}
+ default.node_sound_defaults(table)
+ return table
+end
+
+function default.node_sound_wood_defaults(table)
+ table = table or {}
+ table.footstep = table.footstep or
+ {name="default_hard_footstep", gain=0.3}
+ default.node_sound_defaults(table)
+ return table
+end
+
+function default.node_sound_leaves_defaults(table)
+ table = table or {}
+ table.footstep = table.footstep or
+ {name="default_grass_footstep", gain=0.25}
+ table.dug = table.dug or
+ {name="", gain=1.0}
+ default.node_sound_defaults(table)
+ return table
+end
+
+function default.node_sound_glass_defaults(table)
+ table = table or {}
+ table.footstep = table.footstep or
+ {name="default_stone_footstep", gain=0.25}
+ table.dug = table.dug or
+ {name="default_break_glass", gain=1.0}
+ default.node_sound_defaults(table)
+ return table
+end
+
+--
+
minetest.register_node("default:stone", {
description = "Stone",
tile_images = {"default_stone.png"},
groups = {cracky=3},
drop = 'default:cobble',
legacy_mineral = true,
+ sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("default:stone_with_coal", {
is_ground_content = true,
groups = {cracky=3},
drop = 'default:coal_lump',
+ sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("default:stone_with_iron", {
is_ground_content = true,
groups = {cracky=3},
drop = 'default:iron_lump',
+ sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("default:dirt_with_grass", {
is_ground_content = true,
groups = {crumbly=3},
drop = 'default:dirt',
- sounds = {
- --footstep = "default_grass_footstep",
+ sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.5},
- },
+ }),
})
minetest.register_node("default:dirt_with_grass_footsteps", {
is_ground_content = true,
groups = {crumbly=3},
drop = 'default:dirt',
+ sounds = default.node_sound_dirt_defaults({
+ footstep = {name="default_grass_footstep", gain=0.5},
+ }),
})
minetest.register_node("default:dirt", {
tile_images = {"default_dirt.png"},
is_ground_content = true,
groups = {crumbly=3},
+ sounds = default.node_sound_dirt_defaults(),
})
minetest.register_node("default:sand", {
tile_images = {"default_sand.png"},
is_ground_content = true,
groups = {crumbly=3},
+ sounds = default.node_sound_sand_defaults(),
})
minetest.register_node("default:gravel", {
tile_images = {"default_gravel.png"},
is_ground_content = true,
groups = {crumbly=2},
+ sounds = default.node_sound_sand_defaults({
+ footstep = {name="default_gravel_footstep", gain=0.5}
+ }),
})
minetest.register_node("default:sandstone", {
is_ground_content = true,
groups = {crumbly=2,cracky=2},
drop = 'default:sand',
+ sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("default:clay", {
is_ground_content = true,
groups = {crumbly=3},
drop = 'default:clay_lump 4',
+ sounds = default.node_sound_dirt_defaults({
+ footstep = "",
+ }),
})
minetest.register_node("default:brick", {
is_ground_content = true,
groups = {cracky=3},
drop = 'default:clay_brick 4',
+ sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("default:tree", {
tile_images = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"},
is_ground_content = true,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=1},
+ sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("default:jungletree", {
tile_images = {"default_jungletree_top.png", "default_jungletree_top.png", "default_jungletree.png"},
is_ground_content = true,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=1},
+ sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("default:junglegrass", {
paramtype = "light",
walkable = false,
groups = {snappy=3},
+ sounds = default.node_sound_leaves_defaults(),
})
minetest.register_node("default:leaves", {
}
}
},
+ sounds = default.node_sound_leaves_defaults(),
})
minetest.register_node("default:cactus", {
tile_images = {"default_cactus_top.png", "default_cactus_top.png", "default_cactus_side.png"},
is_ground_content = true,
groups = {snappy=2,choppy=3},
+ sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("default:papyrus", {
is_ground_content = true,
walkable = false,
groups = {snappy=3},
+ sounds = default.node_sound_leaves_defaults(),
})
minetest.register_node("default:bookshelf", {
tile_images = {"default_wood.png", "default_wood.png", "default_bookshelf.png"},
is_ground_content = true,
groups = {snappy=2,choppy=3,oddly_breakable_by_hand=2},
+ sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("default:glass", {
sunlight_propagates = true,
is_ground_content = true,
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3},
+ sounds = default.node_sound_glass_defaults(),
})
minetest.register_node("default:fence_wood", {
fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
+ sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("default:rail", {
},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3},
legacy_wallmounted = true,
+ sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("default:wood", {
tile_images = {"default_wood.png"},
is_ground_content = true,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
+ sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("default:mese", {
tile_images = {"default_mese.png"},
is_ground_content = true,
groups = {cracky=1},
+ sounds = default.node_sound_defaults(),
})
minetest.register_node("default:cloud", {
description = "Cloud",
tile_images = {"default_cloud.png"},
is_ground_content = true,
+ sounds = default.node_sound_defaults(),
})
minetest.register_node("default:water_flowing", {
},
groups = {choppy=2,dig_immediate=3},
legacy_wallmounted = true,
+ sounds = default.node_sound_defaults(),
})
minetest.register_node("default:sign_wall", {
},
groups = {choppy=2,dig_immediate=2},
legacy_wallmounted = true,
+ sounds = default.node_sound_defaults(),
})
minetest.register_node("default:chest", {
metadata_name = "chest",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
legacy_facedir_simple = true,
+ sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("default:chest_locked", {
metadata_name = "locked_chest",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
legacy_facedir_simple = true,
+ sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("default:furnace", {
metadata_name = "furnace",
groups = {cracky=2},
legacy_facedir_simple = true,
+ sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("default:cobble", {
tile_images = {"default_cobble.png"},
is_ground_content = true,
groups = {cracky=3},
+ sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("default:mossycobble", {
tile_images = {"default_mossycobble.png"},
is_ground_content = true,
groups = {cracky=3},
+ sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("default:steelblock", {
tile_images = {"default_steel_block.png"},
is_ground_content = true,
groups = {snappy=1,bendy=2},
+ sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("default:nyancat", {
paramtype2 = "facedir",
groups = {cracky=2},
legacy_facedir_simple = true,
+ sounds = default.node_sound_defaults(),
})
minetest.register_node("default:nyancat_rainbow", {
tile_images = {"default_nc_rb.png"},
inventory_image = "default_nc_rb.png",
groups = {cracky=2},
+ sounds = default.node_sound_defaults(),
})
minetest.register_node("default:sapling", {
paramtype = "light",
walkable = false,
groups = {snappy=2,dig_immediate=3},
+ sounds = default.node_sound_defaults(),
})
minetest.register_node("default:apple", {
walkable = false,
groups = {fleshy=3,dig_immediate=3},
on_use = minetest.item_eat(4),
+ sounds = default.node_sound_defaults(),
})
--
}
};
-class SoundMaker
+class NodeDugEvent: public MtEvent
{
public:
- ISoundManager *m_sound;
+ v3s16 p;
+ MapNode n;
+ NodeDugEvent(v3s16 p, MapNode n):
+ p(p),
+ n(n)
+ {}
+ const char* getType() const
+ {return "NodeDug";}
+};
+
+class SoundMaker
+{
+ ISoundManager *m_sound;
+ INodeDefManager *m_ndef;
+public:
float m_player_step_timer;
SimpleSoundSpec m_player_step_sound;
SimpleSoundSpec m_player_leftpunch_sound;
SimpleSoundSpec m_player_rightpunch_sound;
- SoundMaker(ISoundManager *sound):
+ SoundMaker(ISoundManager *sound, INodeDefManager *ndef):
m_sound(sound),
+ m_ndef(ndef),
m_player_step_timer(0)
{
}
}
}
- void playPlayerLeftPunch()
- {
- if(m_player_leftpunch_sound.exists()){
- m_sound->playSound(m_player_leftpunch_sound, false);
- }
- }
-
- void playPlayerRightPunch()
- {
- if(m_player_rightpunch_sound.exists()){
- m_sound->playSound(m_player_rightpunch_sound, false);
- }
- }
-
static void viewBobbingStep(MtEvent *e, void *data)
{
SoundMaker *sm = (SoundMaker*)data;
static void cameraPunchLeft(MtEvent *e, void *data)
{
SoundMaker *sm = (SoundMaker*)data;
- sm->playPlayerLeftPunch();
+ sm->m_sound->playSound(sm->m_player_leftpunch_sound, false);
}
static void cameraPunchRight(MtEvent *e, void *data)
{
SoundMaker *sm = (SoundMaker*)data;
- sm->playPlayerRightPunch();
+ sm->m_sound->playSound(sm->m_player_rightpunch_sound, false);
+ }
+
+ static void nodeDug(MtEvent *e, void *data)
+ {
+ SoundMaker *sm = (SoundMaker*)data;
+ NodeDugEvent *nde = (NodeDugEvent*)e;
+ sm->m_sound->playSound(sm->m_ndef->get(nde->n).sound_dug, false);
}
void registerReceiver(MtEventManager *mgr)
mgr->reg("PlayerJump", SoundMaker::playerJump, this);
mgr->reg("CameraPunchLeft", SoundMaker::cameraPunchLeft, this);
mgr->reg("CameraPunchRight", SoundMaker::cameraPunchRight, this);
+ mgr->reg("NodeDug", SoundMaker::nodeDug, this);
}
void step(float dtime)
}
};
+// Locally stored sounds don't need to be preloaded because of this
+class GameOnDemandSoundFetcher: public OnDemandSoundFetcher
+{
+ std::set<std::string> m_fetched;
+public:
+
+ void fetchSounds(const std::string &name,
+ std::set<std::string> &dst_paths,
+ std::set<std::vector<char> > &dst_datas)
+ {
+ if(m_fetched.count(name))
+ return;
+ m_fetched.insert(name);
+ std::string base = porting::path_share + DIR_DELIM + "testsounds";
+ dst_paths.insert(base + DIR_DELIM + name + ".ogg");
+ dst_paths.insert(base + DIR_DELIM + name + "1.ogg");
+ dst_paths.insert(base + DIR_DELIM + name + "2.ogg");
+ dst_paths.insert(base + DIR_DELIM + name + "3.ogg");
+ dst_paths.insert(base + DIR_DELIM + name + "4.ogg");
+ dst_paths.insert(base + DIR_DELIM + name + "5.ogg");
+ dst_paths.insert(base + DIR_DELIM + name + "6.ogg");
+ dst_paths.insert(base + DIR_DELIM + name + "7.ogg");
+ dst_paths.insert(base + DIR_DELIM + name + "8.ogg");
+ dst_paths.insert(base + DIR_DELIM + name + "9.ogg");
+ }
+};
+
void the_game(
bool &kill,
bool random_input,
// Create node definition manager
IWritableNodeDefManager *nodedef = createNodeDefManager();
+ // Sound fetcher (useful when testing)
+ GameOnDemandSoundFetcher soundfetcher;
+
// Sound manager
ISoundManager *sound = NULL;
bool sound_is_dummy = false;
#if USE_AUDIO
infostream<<"Attempting to use OpenAL audio"<<std::endl;
- sound = createOpenALSoundManager(NULL);
+ sound = createOpenALSoundManager(&soundfetcher);
if(!sound)
infostream<<"Failed to initialize OpenAL audio"<<std::endl;
#endif
EventManager eventmgr;
// Sound maker
- SoundMaker soundmaker(sound);
+ SoundMaker soundmaker(sound, nodedef);
soundmaker.registerReceiver(&eventmgr);
- // Test sounds
+ // Preload sounds
+#if 0
sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM
+ "sounds" + DIR_DELIM + "default_grass_walk1.ogg");
sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM
+ "sounds" + DIR_DELIM + "default_place_node2.ogg");
sound->loadSound("default_place_node", porting::path_share + DIR_DELIM
+ "sounds" + DIR_DELIM + "default_place_node3.ogg");
+#endif
// Add chat log output for errors to be shown in chat
LogOutputBuffer chat_log_error_buf(LMT_ERROR);
}
bool left_punch = false;
+ soundmaker.m_player_leftpunch_sound.name = "";
if(playeritem_usable && input->getLeftState())
{
params = getDigParams(nodedef->get(n).groups, tp);
}
- soundmaker.m_player_leftpunch_sound.gain = 0.5;
- if(params.main_group == "crumbly")
- soundmaker.m_player_leftpunch_sound.name =
- "default_dig_crumbly";
- else if(params.main_group == "cracky")
+ if(params.main_group != ""){
+ soundmaker.m_player_leftpunch_sound.gain = 0.5;
soundmaker.m_player_leftpunch_sound.name =
- "default_dig_cracky";
- else
- soundmaker.m_player_leftpunch_sound.name = "";
+ std::string("default_dig_") + params.main_group;
+ }
float dig_time_complete = 0.0;
infostream<<"Digging completed"<<std::endl;
client.interact(2, pointed);
client.setCrack(-1, v3s16(0,0,0));
+ MapNode wasnode = map.getNode(nodepos);
client.removeNode(nodepos);
dig_time = 0;
// We don't want a corresponding delay to
// very time consuming nodes
- if(nodig_delay_timer > 0.5)
- {
- nodig_delay_timer = 0.5;
- }
+ if(nodig_delay_timer > 0.3)
+ nodig_delay_timer = 0.3;
// We want a slight delay to very little
// time consuming nodes
float mindelay = 0.15;
if(nodig_delay_timer < mindelay)
- {
nodig_delay_timer = mindelay;
- }
+
+ // Send event to trigger sound
+ MtEvent *e = new NodeDugEvent(nodepos, wasnode);
+ gamedef->event()->put(e);
}
dig_time += dtime;