Page MenuHomeWildfire Games

D1584.id7863.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D1584.id7863.diff

Index: ps/trunk/source/soundmanager/scripting/SoundGroup.h
===================================================================
--- ps/trunk/source/soundmanager/scripting/SoundGroup.h
+++ ps/trunk/source/soundmanager/scripting/SoundGroup.h
@@ -20,6 +20,7 @@
#include "lib/config2.h"
#include "lib/file/vfs/vfs_path.h"
+#include "lib/types.h"
#include "simulation2/system/Entity.h"
#include "soundmanager/data/SoundData.h"
@@ -80,6 +81,10 @@
void SetDefaultValues();
#if CONFIG2_AUDIO
+ inline u32 FastRand();
+ // Contains the current sound seed for the generator
+ u32 m_Seed;
+ float RandFloat(float min, float max);
// We store the handles so we can load now and play later
std::vector<CSoundData*> m_SoundGroups;
#endif
@@ -104,7 +109,7 @@
float m_PitchUpper;
float m_Priority;
// Up to eight individual parameters, use with eSndGrpFlags.
- uint8_t m_Flags;
+ u8 m_Flags;
};
#endif //#ifndef INCLUDED_SOUNDGROUP_H
Index: ps/trunk/source/soundmanager/scripting/SoundGroup.cpp
===================================================================
--- ps/trunk/source/soundmanager/scripting/SoundGroup.cpp
+++ ps/trunk/source/soundmanager/scripting/SoundGroup.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 2019 Wildfire Games.
+/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -21,12 +21,14 @@
#include "graphics/Camera.h"
#include "graphics/GameView.h"
#include "lib/rand.h"
-#include "ps/Game.h"
#include "ps/CLogger.h"
#include "ps/CStr.h"
#include "ps/Filesystem.h"
+#include "ps/Game.h"
#include "ps/Util.h"
#include "ps/XML/Xeromyces.h"
+#include "simulation2/components/ICmpVisual.h"
+#include "simulation2/system/Component.h"
#include "soundmanager/items/ISoundItem.h"
#include "soundmanager/SoundManager.h"
@@ -35,9 +37,17 @@
extern CGame *g_Game;
#if CONFIG2_AUDIO
-static float RandFloat(float min, float max)
+inline u32 CSoundGroup::FastRand()
{
- return rand(min * 100.f, max * 100.f) / 100.f;
+ // This is a mixed linear congruential random number generator.
+ // The magic numbers are chosen so that they generate pseudo random numbers over a big enough period (0xFFFF).
+ m_Seed = 214013 * m_Seed + 2531011;
+ return (m_Seed >> 16) & 0xFFFF;
+}
+
+float CSoundGroup::RandFloat(float min, float max)
+{
+ return (static_cast<float>(FastRand()) / (0xFFFF)) * (max - min) + min;
}
#endif
@@ -62,6 +72,7 @@
m_ConeInnerAngle = 360.f;
m_ConeOuterAngle = 360.f;
m_Decay = 3.f;
+ m_Seed = 0;
m_IntensityThreshold = 3.f;
}
@@ -179,10 +190,11 @@
hSound->SetRollOff(itemRollOff);
}
- if (TestFlag(eRandPitch))
- hSound->SetPitch(RandFloat(m_PitchLower, m_PitchUpper));
- else
- hSound->SetPitch(m_Pitch);
+ CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), source);
+ if (cmpVisual)
+ m_Seed = cmpVisual->GetActorSeed();
+
+ hSound->SetPitch(TestFlag(eRandPitch) ? RandFloat(m_PitchLower, m_PitchUpper) : m_Pitch);
if (TestFlag(eRandGain))
m_Gain = RandFloat(m_GainLower, m_GainUpper);

File Metadata

Mime Type
text/plain
Expires
Tue, Oct 1, 2:49 AM (20 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3392105
Default Alt Text
D1584.id7863.diff (2 KB)

Event Timeline