nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: Fix for Android
[nit.git]
/
lib
/
bucketed_game.nit
diff --git
a/lib/bucketed_game.nit
b/lib/bucketed_game.nit
index
dc97725
..
ad79e6c
100644
(file)
--- a/
lib/bucketed_game.nit
+++ b/
lib/bucketed_game.nit
@@
-20,7
+20,9
@@
#
# Allows for fast support of a large number of entities with rare actions,
# such as a forest with many individual trees.
#
# Allows for fast support of a large number of entities with rare actions,
# such as a forest with many individual trees.
-module bucketed_game
+module bucketed_game is serialize
+
+import serialization
# Something acting on the game
class Turnable[G: Game]
# Something acting on the game
class Turnable[G: Game]
@@
-32,6
+34,7
@@
end
# Something acting on the game from time to time
class Bucketable[G: Game]
super Turnable[G]
# Something acting on the game from time to time
class Bucketable[G: Game]
super Turnable[G]
+
private var act_at: nullable Int = null
# Cancel the previously registered acting turn
private var act_at: nullable Int = null
# Cancel the previously registered acting turn
@@
-48,20
+51,16
@@
class Buckets[G: Game]
# Bucket type used in this implementation.
type BUCKET: HashSet[Bucketable[G]]
# Bucket type used in this implementation.
type BUCKET: HashSet[Bucketable[G]]
- private var buckets: Array[BUCKET] is noinit
-
private var next_bucket: nullable BUCKET = null
private var current_bucket_key: Int = -1
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)
+ # Number of `buckets`, default at 100
+ #
+ # Must be set prior to using any other methods of this class.
+ var n_buckets = 100
- for b in [0 .. n_buckets [do
- buckets[b] = new HashSet[Bucketable[G]]
- end
- end
+ private var buckets: Array[BUCKET] =
+ [for b in n_buckets.times do new HashSet[Bucketable[G]]] is lazy
# Add the Bucketable event `e` at `at_tick`.
fun add_at(e: Bucketable[G], at_tick: Int)
# Add the Bucketable event `e` at `at_tick`.
fun add_at(e: Bucketable[G], at_tick: Int)
@@
-129,11
+128,12
@@
end
# Game turn on the client
class ThinGameTurn[G: ThinGame]
# Game turn on the client
class ThinGameTurn[G: ThinGame]
- var tick: Int = 0 is protected writable
- var events: List[GameEvent] = new List[GameEvent] is protected writable
+ # Game tick when `self` should act.
+ var tick: Int is protected writable
- init (t: Int) do tick = t
+ # Game events occurred for `self`.
+ var events = new Array[GameEvent] is protected writable
end
# Game turn on the full logic
end
# Game turn on the full logic
@@
-143,10
+143,10
@@
class GameTurn[G: Game]
# Game that `self` belongs to.
var game: G
# Game that `self` belongs to.
var game: G
- init (g: G)
- do
- super(g.tick)
- game = g
+ # Create a new game turn for `game`.
+ init (game: G) is old_style_init do
+ super(game.tick)
+ self.game = game
end
# Insert the Bucketable event `e` to be executed at next tick.
end
# Insert the Bucketable event `e` to be executed at next tick.
@@
-178,8
+178,6
@@
class Game
# but cannot be used to add new Events.
var last_turn: nullable ThinGameTurn[G] = null
# but cannot be used to add new Events.
var last_turn: nullable ThinGameTurn[G] = null
- init do end
-
# Execute and return a new GameTurn.
#
# This method calls `do_pre_turn` before executing the GameTurn
# Execute and return a new GameTurn.
#
# This method calls `do_pre_turn` before executing the GameTurn