# Optiomized organization of `Bucketable` instances
class Buckets[G: Game]
super Turnable[G]
- type Bucket: HashSet[Bucketable[G]]
+ type BUCKET: HashSet[Bucketable[G]]
- private var buckets: Array[Bucket]
+ private var buckets: Array[BUCKET]
- private var next_bucket: nullable Bucket = null
+ private var next_bucket: nullable BUCKET = null
private var current_bucket_key: Int = -1
init
do
var n_buckets = 100
- buckets = new Array[Bucket].with_capacity(n_buckets)
+ buckets = new Array[BUCKET].with_capacity(n_buckets)
for b in [0 .. n_buckets [do
- buckets[b] = new Bucket
+ buckets[b] = new HashSet[Bucketable[G]]
end
end
current_bucket_key = key_for_tick(turn.tick)
var current_bucket = buckets[current_bucket_key]
- next_bucket = new Bucket
+ next_bucket = new HashSet[Bucketable[G]]
for e in current_bucket do
if e.act_at == turn.tick then
end
# Game related event
-class GameEvent
+interface GameEvent
+ fun apply( game : ThinGame ) is abstract
end
# Event raised at the first turn
do
game.buckets.add_at(e, tick + t)
end
+
+ fun add_event( event : GameEvent )
+ do
+ event.apply( game )
+ events.add( event )
+ end
end
# Full game logic
var buckets: Buckets[G] = new Buckets[G]
+ # Last turn executed in this game
+ # Can be used to consult the latest events (by the display for example),
+ # but cannot be used to add new Events.
+ var last_turn: nullable ThinGameTurn[G] = null
+
init do end
fun do_turn: GameTurn[G]
buckets.do_turn(turn)
do_post_turn(turn)
+ last_turn = turn
+
tick += 1
return turn