public void MakeReadOnly() { if (this.frozenArray != null) { // already made frozen return; } var count = this.list.Count; if (count == 0) { throw new Exception("There is a spawn list without entries defined"); } // let's calculate frozen array - see frozenArray description this.frozenArray = new ArrayWithWeights <IProtoSpawnableObject>(this.list); this.list = null; this.frozenCustomObjectPadding = this.customObjectPadding.ToReadOnlyListDictionary(); this.customObjectPadding = null; var isContainsOnlyStaticObjects = true; foreach (var entry in this.frozenArray) { if (!(entry.Value is IProtoStaticWorldObject)) { isContainsOnlyStaticObjects = false; } } this.IsContainsOnlyStaticObjects = isContainsOnlyStaticObjects; }
private void Freeze() { if (this.frozenEntries == null) { this.frozenEntries = new ArrayWithWeights <Entry>(this.entries); } }
public static SoundResource ClientGetSound( ArrayWithWeights <SoundResource> soundsSet, object soundPreset, object repetitionProtectionKey) { Api.ValidateIsClient(); Entry entry = null; var key = new Key(soundsSet, soundPreset, repetitionProtectionKey); foreach (var e in List) { if (e.Key == key) { // found entry entry = e; break; } } if (entry == null) { // no entry found - create new entry = new Entry(key, CalculateMaxRepeatCount(soundsSet)); List.Add(entry); } return(entry.GetSound(soundsSet)); }
public SoundResource GetSound(ArrayWithWeights <SoundResource> soundsSet) { this.LastAccessedTime = ClientCore.ClientRealTime; var historySize = this.history.Length; // let's get not repeated sound entry while (true) { var randomSoundResource = soundsSet.GetSingleRandomElement(); var isFoundInHistory = false; for (var index = 0; index < historySize; index++) { if (randomSoundResource.Equals(this.history[index])) { isFoundInHistory = true; break; } } if (isFoundInHistory) { // continue search continue; } // found not yet played sound resource this.history[this.nextHistoryEntryIndex] = randomSoundResource; this.nextHistoryEntryIndex++; if (this.nextHistoryEntryIndex == historySize) { // recycle history from beginning this.nextHistoryEntryIndex = 0; } return(randomSoundResource); } }
public void MakeReadOnly() { if (this.frozenArray != null) { // already made frozen return; } var count = this.list.Count; if (count == 0) { throw new Exception("There is a spawn list without entries defined"); } // let's calculate frozen array - see frozenArray description this.frozenArray = new ArrayWithWeights <IProtoSpawnableObject>(this.list); this.list = null; this.frozenCustomObjectPadding = this.customObjectPadding.ToReadOnlyListDictionary(); this.customObjectPadding = null; }
public ReadOnlySoundResourceSet(List <ValueWithWeight <SoundResource> > sounds) { this.sounds = new ArrayWithWeights <SoundResource>(sounds); }
private static int CalculateMaxRepeatCount(ArrayWithWeights <SoundResource> soundsSet) { var result = soundsSet.Count / 2; return(result > 2 ? 2 : result); }