Skip to content

Commit bbe3dd9

Browse files
Ruinerzhul
Rui
authored andcommittedJun 14, 2017
Fix no sound bug (#5968)
1 parent ddcd026 commit bbe3dd9

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed
 

Diff for: ‎src/itemdef.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ void ItemDefinition::reset()
124124

125125
void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
126126
{
127-
128-
writeU8(os, 3); // version (proto > 20)
127+
u8 version = (protocol_version >= 34) ? 4 : 3;
128+
writeU8(os, version);
129129
writeU8(os, type);
130130
os << serializeString(name);
131131
os << serializeString(description);
@@ -156,8 +156,11 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
156156
writeF1000(os, sound_place_failed.gain);
157157
os << serializeString(palette_image);
158158
writeU32(os, color.color);
159-
writeF1000(os, sound_place.pitch);
160-
writeF1000(os, sound_place_failed.pitch);
159+
160+
if (version >= 4) {
161+
writeF1000(os, sound_place.pitch);
162+
writeF1000(os, sound_place_failed.pitch);
163+
}
161164
}
162165

163166
void ItemDefinition::deSerialize(std::istream &is)
@@ -167,7 +170,7 @@ void ItemDefinition::deSerialize(std::istream &is)
167170

168171
// Deserialize
169172
int version = readU8(is);
170-
if(version < 1 || version > 3)
173+
if (version < 1 || version > 4)
171174
throw SerializationError("unsupported ItemDefinition version");
172175
type = (enum ItemType)readU8(is);
173176
name = deSerializeString(is);
@@ -216,8 +219,11 @@ void ItemDefinition::deSerialize(std::istream &is)
216219
sound_place_failed.gain = readF1000(is);
217220
palette_image = deSerializeString(is);
218221
color.set(readU32(is));
219-
sound_place.pitch = readF1000(is);
220-
sound_place_failed.pitch = readF1000(is);
222+
223+
if (version >= 4) {
224+
sound_place.pitch = readF1000(is);
225+
sound_place_failed.pitch = readF1000(is);
226+
}
221227
} catch(SerializationError &e) {};
222228
}
223229

Diff for: ‎src/sound_openal.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ class OpenALSoundManager: public ISoundManager
576576
}
577577
int handle = -1;
578578
if (fade > 0) {
579-
handle = playSoundRaw(buf, loop, 0.0f, 0.0f);
579+
handle = playSoundRaw(buf, loop, 0.0f, pitch);
580580
fadeSound(handle, fade, volume);
581581
} else {
582582
handle = playSoundRaw(buf, loop, volume, pitch);

0 commit comments

Comments
 (0)