|
Drag[en]gine Script Module DragonScript 1.35
|
List of weighted entries for random retrieval. More...
Classes | |
| class | Entry |
| Entry. More... | |
Public Member Functions | |
| void | add (Object object, float weight) |
| Add object. | |
| WeightedRandomList | collect (Block ablock) |
| New weighted random list with filtered elements. | |
| void | forEach (Block ablock) |
| Visit entries with block. | |
| Object | getObjectAt (int index) |
| Object at index. | |
| float | getWeightAt (int index) |
| Weight at index. | |
| int | indexOfObject (Object object) |
| Index of first object or -1 if absent. | |
| WeightedRandomList | new () |
| Create list. | |
| WeightedRandomList | new (WeightedRandomList list) |
| Create copy of list. | |
| Object | random (float randomValue) |
| Random object using random value in the range from 0 to 1. | |
| void | removeAll () |
| Remove all objects. | |
| void | removeFrom (int index) |
| Remove object from index. | |
| void | removeObject (Object object) |
| Remove first occurance of object. | |
| void | setWeightAt (int index, float weight) |
| Set weight at index. | |
Public Attributes | |
| bool | pDirtyThresholds |
| Array | pEntries |
| float | pMaxThreshold |
Protected Member Functions | |
| bool | getDirtyThresholds () |
| Threshold are dirty. | |
| float | getMaxThreshold () |
| Maximum threshold. | |
| void | updateThresholds () |
| Update thresholds. | |
List of weighted entries for random retrieval.
List entries have a weight assigned representing the percentage chance of the entry to be selected. If all entries have the same weight ths list behaves the same as Array.random(). Using different weights allows to favor or disfavor certain elements.
| void Dragengine.Utils.WeightedRandomList.add | ( | Object | object, |
| float | weight ) |
| WeightedRandomList Dragengine.Utils.WeightedRandomList.collect | ( | Block | ablock | ) |
New weighted random list with filtered elements.
Block is called with arguments (Object object, float Weight) and has to return true to include the object or false to exclude the object.
References indexOfObject(), and pEntries.
Referenced by updateThresholds().
| void Dragengine.Utils.WeightedRandomList.forEach | ( | Block | ablock | ) |
Visit entries with block.
Black is called with arguments (Object object, float weight).
References getObjectAt(), and pEntries.
Referenced by updateThresholds().
|
protected |
Threshold are dirty.
Referenced by updateThresholds().
|
protected |
Maximum threshold.
Referenced by updateThresholds().
| Object Dragengine.Utils.WeightedRandomList.getObjectAt | ( | int | index | ) |
Object at index.
Referenced by forEach().
| float Dragengine.Utils.WeightedRandomList.getWeightAt | ( | int | index | ) |
Weight at index.
Referenced by random().
| int Dragengine.Utils.WeightedRandomList.indexOfObject | ( | Object | object | ) |
Index of first object or -1 if absent.
References pEntries.
Referenced by collect(), and updateThresholds().
| WeightedRandomList Dragengine.Utils.WeightedRandomList.new | ( | ) |
Create list.
Referenced by add(), removeAll(), removeObject(), and updateThresholds().
| WeightedRandomList Dragengine.Utils.WeightedRandomList.new | ( | WeightedRandomList | list | ) |
Create copy of list.
| Object Dragengine.Utils.WeightedRandomList.random | ( | float | randomValue | ) |
Random object using random value in the range from 0 to 1.
| EInvalidParam | List is empty. |
This function is useful to create reproducible results for example game saves.
References getWeightAt(), and pEntries.
Referenced by updateThresholds().
| void Dragengine.Utils.WeightedRandomList.removeAll | ( | ) |
Remove all objects.
References new(), pDirtyThresholds, pEntries, and pMaxThreshold.
Referenced by updateThresholds().
| void Dragengine.Utils.WeightedRandomList.removeFrom | ( | int | index | ) |
Remove object from index.
Referenced by updateThresholds().
| void Dragengine.Utils.WeightedRandomList.removeObject | ( | Object | object | ) |
Remove first occurance of object.
References new(), pDirtyThresholds, pEntries, and pMaxThreshold.
Referenced by updateThresholds().
| void Dragengine.Utils.WeightedRandomList.setWeightAt | ( | int | index, |
| float | weight ) |
Set weight at index.
References pDirtyThresholds, and pMaxThreshold.
Referenced by updateThresholds().
|
protected |
Update thresholds.
References add(), collect(), forEach(), getDirtyThresholds(), getMaxThreshold(), indexOfObject(), new(), pDirtyThresholds, pEntries, pMaxThreshold, random(), removeAll(), removeFrom(), removeObject(), setWeightAt(), and updateThresholds().
Referenced by updateThresholds().
| bool Dragengine.Utils.WeightedRandomList.pDirtyThresholds |
Referenced by removeAll(), removeObject(), setWeightAt(), and updateThresholds().
| Array Dragengine.Utils.WeightedRandomList.pEntries |
Referenced by collect(), forEach(), indexOfObject(), random(), removeAll(), removeObject(), and updateThresholds().
| float Dragengine.Utils.WeightedRandomList.pMaxThreshold |
Referenced by removeAll(), removeObject(), setWeightAt(), and updateThresholds().