ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/sounds.C
(Generate patch)

Comparing deliantra/server/socket/sounds.C (file contents):
Revision 1.17 by root, Thu Jul 26 21:44:43 2007 UTC vs.
Revision 1.22 by root, Wed Aug 1 01:07:42 2007 UTC

39/** 39/**
40 * Maximum distance a player may hear a sound from. 40 * Maximum distance a player may hear a sound from.
41 * This is only used for new client/server sound. If the sound source 41 * This is only used for new client/server sound. If the sound source
42 * on the map is farther away than this, we don't sent it to the client. 42 * on the map is farther away than this, we don't sent it to the client.
43 */ 43 */
44#define MAX_SOUND_DISTANCE 10 44#define MAX_SOUND_DISTANCE 16
45 45
46// the hashtable 46// the hashtable
47typedef std::tr1::unordered_map 47typedef std::tr1::unordered_map
48 < 48 <
49 const char *, 49 const char *,
58faceidx 58faceidx
59sound_find (const char *str) 59sound_find (const char *str)
60{ 60{
61 auto (i, ht.find (str)); 61 auto (i, ht.find (str));
62 62
63 return i == ht.end () 63 if (i != ht.end ())
64 ? 0
65 : i->second; 64 return i->second;
65
66 //TODO: really fall back to face name?
67 char face[128];
68 snprintf (face, 128, "sound/%s", str);
69 return face_find (face);
66} 70}
67 71
68void 72void
69sound_set (const char *str, faceidx face) 73sound_set (const char *str, faceidx face)
70{ 74{
87client::play_sound (faceidx sound, int dx, int dy) 91client::play_sound (faceidx sound, int dx, int dy)
88{ 92{
89 if (!sound) 93 if (!sound)
90 return; 94 return;
91 95
96 if (dx < -MAX_SOUND_DISTANCE || dx > MAX_SOUND_DISTANCE) return;
97 if (dy < -MAX_SOUND_DISTANCE || dy > MAX_SOUND_DISTANCE) return;
98
92 if (fx_want [FT_SOUND]) 99 if (fx_want [FT_SOUND])
93 { 100 {
94 // cfplus 101 // cfplus
95 send_face (sound); 102 send_face (sound);
96 flush_fx (); 103 flush_fx ();
104
105 uint8 vol = clamp (255 - idistance (dx, dy) * 361 / MAX_SOUND_DISTANCE, 0, 255);
106
107 // cut off volume here
108 if (vol < 8)
109 return;
97 110
98 packet sl ("sc"); 111 packet sl ("sc");
99 112
100 uint8 *len = sl.cur; 113 uint8 *len = sl.cur;
101 114
102 sl << uint8 (0) // group length 115 sl << uint8 (0) // group length
103 << uint8 (0) // type == one-time effect 116 << uint8 (0) // type == one-time effect
104 << ber32 (sound) 117 << ber32 (sound)
105 << sint8 (dx) 118 << sint8 (dx)
106 << sint8 (dy); 119 << sint8 (dy)
120 << uint8 (vol); // 0 == silent, 255 max
107 121
108 *len = sl.cur - len; // patch in group length 122 *len = sl.cur - len; // patch in group length
109 123
110 send_packet (sl); 124 send_packet (sl);
111 } 125 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines