2024-04-16 03:08:25 +00:00
|
|
|
extends Sampler
|
|
|
|
class_name SamplerPriority
|
|
|
|
|
|
|
|
|
|
|
|
## Always sample the object with the highest priority in the queue.
|
|
|
|
|
|
|
|
|
2024-04-16 22:55:17 +00:00
|
|
|
## Get a reference.
|
|
|
|
func sample() -> Priority:
|
|
|
|
if len(possibilities) == 0:
|
|
|
|
return null
|
|
|
|
|
|
|
|
# FIXME: Change this to something more efficient when needed
|
|
|
|
var highest_possibility: Priority = null
|
|
|
|
for possibility in possibilities:
|
2024-04-17 03:26:13 +00:00
|
|
|
Log.p(self, "Possibility: %s (%d)" % [possibility, possibility.priority])
|
2024-04-17 02:52:11 +00:00
|
|
|
if highest_possibility == null or possibility.priority > highest_possibility.priority:
|
2024-04-16 22:55:17 +00:00
|
|
|
highest_possibility = possibility
|
|
|
|
|
|
|
|
if highest_possibility == null:
|
|
|
|
return null
|
|
|
|
|
2024-04-17 03:26:13 +00:00
|
|
|
Log.p(self, "Sampled: %s (%d)" % [highest_possibility, highest_possibility.priority])
|
2024-04-16 22:55:17 +00:00
|
|
|
return highest_possibility.get_ref()
|
2024-04-17 02:52:11 +00:00
|
|
|
|
|
|
|
func get_refs() -> Array[Node]:
|
|
|
|
var refs: Array[Node] = []
|
|
|
|
for possibility in possibilities:
|
|
|
|
refs.append(possibility.get_ref())
|
|
|
|
return refs
|