10 protected static ref
array<int> m_FreeEffectIDs;
12 protected static int m_HighestFreeEffectID = 1;
14 static const int INVALID_ID = 0;
16 protected static bool m_IsCleanup;
18 protected static bool m_IsInitialized;
48 int id = EffectRegister(eff);
50 eff.SetPosition( pos );
66 static int PlayOnObject(notnull
Effect eff,
Object obj,
vector local_pos =
"0 0 0",
vector local_ori =
"0 0 0",
bool force_rotation_relative_to_world =
false)
71 int id = EffectRegister(eff);
76 eff.SetPosition(local_pos);
80 eff.SetPosition(obj.GetPosition());
84 eff.SetLocalPosition(local_pos);
85 eff.SetAttachedLocalOri(local_ori);
87 if (force_rotation_relative_to_world)
93 eff_particle.ForceParticleRotationRelativeToWorld(force_rotation_relative_to_world);
106 static void Stop(
int effect_id)
108 Effect eff = m_EffectsMap.Get(effect_id);
116 ErrorEx(
string.Format(
"Failed to stop Effect with ID %1. The ID is not registered in m_EffectsMap!", effect_id));
140 static EffectSound CreateSound(
string sound_set,
vector position,
float play_fade_in = 0,
float stop_fade_out = 0,
bool loop =
false,
bool enviroment =
false)
143 effect_sound.SetSoundSet(sound_set);
144 effect_sound.SetPosition(position);
145 effect_sound.SetSoundFadeIn(play_fade_in);
146 effect_sound.SetSoundFadeOut(stop_fade_out);
147 effect_sound.SetSoundLoop(loop);
148 effect_sound.SetEnviromentVariables(enviroment);
150 EffectRegister( effect_sound );
165 static EffectSound PlaySound(
string sound_set,
vector position,
float play_fade_in = 0,
float stop_fade_out = 0,
bool loop =
false)
167 EffectSound effect_sound = CreateSound(sound_set, position, play_fade_in, stop_fade_out, loop,
false);
169 effect_sound.SoundPlay();
184 static EffectSound PlaySoundParams(notnull
SoundParams params,
vector position,
float play_fade_in = 0,
float stop_fade_out = 0,
bool loop =
false)
186 EffectSound effect_sound = CreateSound(params.GetName(), position, play_fade_in, stop_fade_out, loop,
false);
188 effect_sound.SoundPlayEx(params);
203 static EffectSound PlaySoundCachedParams(
string sound_set,
vector position,
float play_fade_in = 0,
float stop_fade_out = 0,
bool loop =
false)
205 SoundParams params = GetCachedSoundParam(sound_set);
207 EffectSound effect_sound = CreateSound(params.GetName(), position, play_fade_in, stop_fade_out, loop,
false);
209 effect_sound.SoundPlayEx(params);
224 static EffectSound PlaySoundEnviroment(
string sound_set,
vector position,
float play_fade_in = 0,
float stop_fade_out = 0,
bool loop =
false)
226 EffectSound effect_sound = CreateSound(sound_set, position, play_fade_in, stop_fade_out, loop,
true);
228 effect_sound.SoundPlay();
243 static EffectSound PlaySoundOnObject(
string sound_set,
Object parent_object,
float play_fade_in = 0,
float stop_fade_out = 0,
bool loop =
false)
245 EffectSound effect_sound = CreateSound(sound_set, parent_object.GetPosition(), play_fade_in, stop_fade_out, loop);
247 effect_sound.SetParent( parent_object );
248 effect_sound.SetLocalPosition(
vector.Zero );
249 effect_sound.SoundPlay();
267 static void DestroyEffect(
Effect effect)
271 if (effect.CanDestroy())
279 effect.SetAutodestroy(
true);
290 static bool IsEffectExist(
int effect_id )
293 return m_EffectsMap[effect_id] !=
null;
303 static Effect GetEffectByID(
int effect_id)
306 return m_EffectsMap[effect_id];
318 static int EffectRegister(
Effect effect)
320 if (effect.IsRegistered())
322 ErrorEx(
string.Format(
"Attempted to register Effect '%1' which was already registered.", effect.GetDebugName()),
ErrorExSeverity.INFO);
323 return effect.GetID();
330 id = GetFreeEffectID();
331 m_EffectsMap.Insert(
id, effect);
332 effect.Event_OnRegistered(
id);
335 ErrorEx(
"Attempted to register Effect while SEffectManager is cleaning up, request ignored.",
ErrorExSeverity.WARNING);
347 static void EffectUnregister(
int id)
353 if ( m_EffectsMap.Find(
id, effect) )
355 effect.Event_OnUnregistered();
356 m_EffectsMap.Remove(
id);
359 if ( m_FreeEffectIDs.Find(
id) == -1 )
361 m_FreeEffectIDs.Insert(
id);
369 static void EffectUnregisterEx(
Effect effect)
371 EffectUnregister(effect.GetID());
378 protected static int GetFreeEffectID()
382 if (m_FreeEffectIDs.Count() > 0)
384 return_id = m_FreeEffectIDs.Get(0);
385 m_FreeEffectIDs.Remove(0);
389 return_id = m_HighestFreeEffectID;
390 ++m_HighestFreeEffectID;
412 DestroyEffect(sound_effect);
421 static SoundParams GetCachedSoundParam(
string soundset)
424 if (!m_ParamsMap.Find(soundset, params))
427 m_ParamsMap.Insert(soundset, params);
446 static void Event_OnSoundWaveEnded(
EffectSound effect_sound)
490 static void Cleanup()
501 if (m_ParamsMap.Count() > 0)
504 if (m_EffectsMap.Count() > 0)
513 Print(
"--- SEffectManager Cleanup dump - Begin ------------------------");
514 Print(
string.Format(
"Effect count: %1", m_EffectsMap.Count()));
519 foreach (
int id,
Effect eff : m_EffectsMap)
521 eff.Event_OnUnregistered();
523 Print(
string.Format(
"%1 :: %2 :: %3", eff,
typename.EnumToString(
EffectType, eff.GetEffectType()), eff.GetDebugName() ));
528 Print(
"--- SEffectManager Cleanup dump - End --------------------------");
532 m_EffectsMap.Clear();
535 m_HighestFreeEffectID = 1;