nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: Advice on useless repeated types
[nit.git]
/
lib
/
bucketed_game.nit
diff --git
a/lib/bucketed_game.nit
b/lib/bucketed_game.nit
index
fca65b0
..
a621c54
100644
(file)
--- a/
lib/bucketed_game.nit
+++ b/
lib/bucketed_game.nit
@@
-22,8
+22,11
@@
# such as a forest with many individual trees.
module bucketed_game
# such as a forest with many individual trees.
module bucketed_game
+import serialization
+
# Something acting on the game
class Turnable[G: Game]
# Something acting on the game
class Turnable[G: Game]
+ auto_serializable
# Execute `turn` for this instance.
fun do_turn(turn: GameTurn[G]) is abstract
# Execute `turn` for this instance.
fun do_turn(turn: GameTurn[G]) is abstract
@@
-32,6
+35,8
@@
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]
+ auto_serializable
+
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
@@
-44,24
+49,21
@@
end
# Optimized organization of `Bucketable` instances
class Buckets[G: Game]
super Turnable[G]
# Optimized organization of `Bucketable` instances
class Buckets[G: Game]
super Turnable[G]
+ auto_serializable
# 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)
@@
-116,10
+118,12
@@
end
# Event raised at the first turn
class FirstTurnEvent
super GameEvent
# Event raised at the first turn
class FirstTurnEvent
super GameEvent
+ auto_serializable
end
# Game logic on the client
class ThinGame
end
# Game logic on the client
class ThinGame
+ auto_serializable
# Game tick when `self` should act.
#
# Game tick when `self` should act.
#
@@
-129,17
+133,19
@@
end
# Game turn on the client
class ThinGameTurn[G: ThinGame]
# Game turn on the client
class ThinGameTurn[G: ThinGame]
+ auto_serializable
# Game tick when `self` should act.
var tick: Int is protected writable
# Game tick when `self` should act.
var tick: Int is protected writable
- # List of game events occured for `self`.
- var events: List[GameEvent] = new List[GameEvent] is protected writable
+ # Game events occurred for `self`.
+ var events = new Array[GameEvent] is protected writable
end
# Game turn on the full logic
class GameTurn[G: Game]
super ThinGameTurn[G]
end
# Game turn on the full logic
class GameTurn[G: Game]
super ThinGameTurn[G]
+ auto_serializable
# Game that `self` belongs to.
var game: G
# Game that `self` belongs to.
var game: G
@@
-167,6
+173,7
@@
end
# Full game logic
class Game
super ThinGame
# Full game logic
class Game
super ThinGame
+ auto_serializable
# Game type used in this implementation.
type G: Game
# Game type used in this implementation.
type G: Game
@@
-179,8
+186,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