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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines