OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** A local player (API known to the main isolate when creating players). */ | 5 /** A local player (API known to the main isolate when creating players). */ |
6 interface Player default PlayerImpl { | 6 interface Player default PlayerImpl { |
7 | 7 |
8 Player(); | 8 Player(); |
9 | 9 |
10 final Future<SendPort> portToPlayer; | 10 final Future<SendPort> portToPlayer; |
11 | 11 |
(...skipping 14 matching lines...) Expand all Loading... | |
26 /** shoot asynchronously. */ | 26 /** shoot asynchronously. */ |
27 Future<int> shoot(int x, int y); | 27 Future<int> shoot(int x, int y); |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 /** | 31 /** |
32 * A default implementation for player that sends messages to an isolate, which | 32 * A default implementation for player that sends messages to an isolate, which |
33 * contains the actual player state. | 33 * contains the actual player state. |
34 */ | 34 */ |
35 class PlayerImpl implements Player { | 35 class PlayerImpl implements Player { |
36 final Future<SendPort> portToPlayer; | 36 final SendPort portToPlayer; |
Siggi Cherem (dart-lang)
2012/08/02 16:43:35
another note - we tried to make spawnFunction retu
Mads Ager (google)
2012/08/03 05:51:35
Thanks for filing that bug Siggi. Based on your co
| |
37 | 37 |
38 PlayerImpl() : portToPlayer = new PlayerState().spawn(); | 38 PlayerImpl() : portToPlayer = spawnFunction(spawnPlayer); |
Siggi Cherem (dart-lang)
2012/08/02 16:43:35
FYI - this will break once dart2js bug is fixed, t
Mads Ager (google)
2012/08/03 05:51:35
Thanks Siggi! I'll add a comment that the players
| |
39 | 39 |
40 void setup(Window window, int player) { | 40 void setup(Window window, int player) { |
41 portToPlayer.then((SendPort port) => port.call( | 41 portToPlayer.call( |
42 { "action" : MessageIds.SETUP, | 42 { "action" : MessageIds.SETUP, |
43 "args" : [player] })); | 43 "args" : [player] }); |
44 } | 44 } |
45 | 45 |
46 void set enemy(SendPort portToEnemy) { | 46 void set enemy(SendPort portToEnemy) { |
47 portToPlayer.then((port) => port.call( | 47 portToPlayer.call( |
48 { "action" : MessageIds.SET_ENEMY, | 48 { "action" : MessageIds.SET_ENEMY, |
49 "args" : [portToEnemy]})); | 49 "args" : [portToEnemy]}); |
50 } | 50 } |
51 | 51 |
52 void set _portForTest(SendPort testPort) { | 52 void set _portForTest(SendPort testPort) { |
53 portToPlayer.then((port) => port.call( | 53 portToPlayer.call( |
54 { "action" : MessageIds.SET_PORT_FOR_TEST, | 54 { "action" : MessageIds.SET_PORT_FOR_TEST, |
55 "args" : [testPort]})); | 55 "args" : [testPort]}); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 /** | 59 /** |
60 * A default implementation for an enemy that sends messages to an isolate, | 60 * A default implementation for an enemy that sends messages to an isolate, |
61 * which contains the actual enemy state. | 61 * which contains the actual enemy state. |
62 */ | 62 */ |
63 class EnemyImpl implements Enemy { | 63 class EnemyImpl implements Enemy { |
64 SendPort portToEnemy; | 64 SendPort portToEnemy; |
65 | 65 |
(...skipping 28 matching lines...) Expand all Loading... | |
94 | 94 |
95 /** message indicating that the enemy is ready to play. */ | 95 /** message indicating that the enemy is ready to play. */ |
96 static final ENEMY_IS_READY = 3; | 96 static final ENEMY_IS_READY = 3; |
97 | 97 |
98 /** message describing a shoot action. */ | 98 /** message describing a shoot action. */ |
99 static final SHOOT = 4; | 99 static final SHOOT = 4; |
100 | 100 |
101 /** message to set up a test port, used to make tests non-flaky. */ | 101 /** message to set up a test port, used to make tests non-flaky. */ |
102 static final SET_PORT_FOR_TEST = 5; | 102 static final SET_PORT_FOR_TEST = 5; |
103 } | 103 } |
OLD | NEW |