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.16 by root, Thu Jul 26 00:38:34 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{
74 i->second = face; 78 i->second = face;
75 else 79 else
76 ht.insert (std::make_pair (strdup (str), face)); 80 ht.insert (std::make_pair (strdup (str), face));
77} 81}
78 82
83//TODO: remove
84// for gcfclient-compatibility, to vanish at some point
85faceidx old_sound_index [SOUND_CAST_SPELL_0];
86
79/* 87/*
80 * Plays a sound for specified player only 88 * Plays a sound for specified player only
81 */ 89 */
82void 90void
83client::play_sound (faceidx sound, int dx, int dy) 91client::play_sound (faceidx sound, int dx, int dy)
84{ 92{
85 if (!sound) 93 if (!sound)
86 return; 94 return;
87 95
96 if (dx < -MAX_SOUND_DISTANCE || dx > MAX_SOUND_DISTANCE) return;
97 if (dy < -MAX_SOUND_DISTANCE || dy > MAX_SOUND_DISTANCE) return;
98
88 if (fx_want [FT_SOUND]) 99 if (fx_want [FT_SOUND])
89 { 100 {
90 // cfplus 101 // cfplus
91 send_face (sound); 102 send_face (sound);
92 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;
93 110
94 packet sl ("sc"); 111 packet sl ("sc");
95 112
96 uint8 *len = sl.cur; 113 uint8 *len = sl.cur;
97 114
98 sl << uint8 (0) // group length 115 sl << uint8 (0) // group length
99 << uint8 (0) // type == one-time effect 116 << uint8 (0) // type == one-time effect
100 << ber32 (sound) 117 << ber32 (sound)
101 << sint8 (dx) 118 << sint8 (dx)
102 << sint8 (dy); 119 << sint8 (dy)
120 << uint8 (vol); // 0 == silent, 255 max
103 121
104 *len = sl.cur - len; // patch in group length 122 *len = sl.cur - len; // patch in group length
105 123
106 send_packet (sl); 124 send_packet (sl);
107 } 125 }
108 else if (this->sound) 126 else if (this->sound)
109 { 127 {
128 //TODO: remove, or make bearable
110 // gcfclient compatibility 129 // gcfclient compatibility
111 // fetch compatibility sound index first
112 130
131 int gcfclient_sound;
132 for (gcfclient_sound = SOUND_CAST_SPELL_0; gcfclient_sound--; )
133 if (old_sound_index [gcfclient_sound] == sound)
134 {
113 packet sl ("sound"); 135 packet sl ("sound");
114 136
115 sl << uint8 (dx) 137 sl << uint8 (dx)
116 << uint8 (dy) 138 << uint8 (dy)
117 << uint16 (sound) 139 << uint16 (gcfclient_sound)
118 << uint8 (SOUND_NORMAL); 140 << uint8 (SOUND_NORMAL);
119 141
120 send_packet (sl); 142 send_packet (sl);
143
144 break;
145 }
121 } 146 }
122} 147}
123 148

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines