zyps 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. data/README.txt +2 -2
  2. data/bin/zyps_demo +2 -8
  3. data/bin/zyps_server +14 -41
  4. data/lib/zyps/environmental_factors.rb +33 -5
  5. data/lib/zyps/remote.rb +103 -0
  6. data/test/zyps/test_actions.rb +2 -1
  7. data/test/zyps/test_conditions.rb +0 -6
  8. data/test/zyps/test_environmental_factors.rb +1 -2
  9. data/test/zyps/test_remote.rb +113 -0
  10. metadata +11 -183
  11. data/doc/classes/Zyps/AccelerateAction.html +0 -200
  12. data/doc/classes/Zyps/AccelerateAction.src/M000020.html +0 -19
  13. data/doc/classes/Zyps/AccelerateAction.src/M000021.html +0 -19
  14. data/doc/classes/Zyps/AccelerateAction.src/M000022.html +0 -18
  15. data/doc/classes/Zyps/Accelerator.html +0 -181
  16. data/doc/classes/Zyps/Accelerator.src/M000044.html +0 -19
  17. data/doc/classes/Zyps/Accelerator.src/M000045.html +0 -18
  18. data/doc/classes/Zyps/Action.html +0 -217
  19. data/doc/classes/Zyps/Action.src/M000014.html +0 -18
  20. data/doc/classes/Zyps/Action.src/M000015.html +0 -18
  21. data/doc/classes/Zyps/Action.src/M000016.html +0 -17
  22. data/doc/classes/Zyps/Action.src/M000017.html +0 -18
  23. data/doc/classes/Zyps/AgeCondition.html +0 -181
  24. data/doc/classes/Zyps/AgeCondition.src/M000058.html +0 -18
  25. data/doc/classes/Zyps/AgeCondition.src/M000059.html +0 -18
  26. data/doc/classes/Zyps/ApproachAction.html +0 -207
  27. data/doc/classes/Zyps/ApproachAction.src/M000074.html +0 -19
  28. data/doc/classes/Zyps/ApproachAction.src/M000075.html +0 -19
  29. data/doc/classes/Zyps/ApproachAction.src/M000076.html +0 -38
  30. data/doc/classes/Zyps/Behavior.html +0 -206
  31. data/doc/classes/Zyps/Behavior.src/M000012.html +0 -20
  32. data/doc/classes/Zyps/Behavior.src/M000013.html +0 -31
  33. data/doc/classes/Zyps/BlendAction.html +0 -181
  34. data/doc/classes/Zyps/BlendAction.src/M000066.html +0 -18
  35. data/doc/classes/Zyps/BlendAction.src/M000067.html +0 -18
  36. data/doc/classes/Zyps/Clock.html +0 -180
  37. data/doc/classes/Zyps/Clock.src/M000069.html +0 -18
  38. data/doc/classes/Zyps/Clock.src/M000070.html +0 -21
  39. data/doc/classes/Zyps/Clock.src/M000071.html +0 -18
  40. data/doc/classes/Zyps/CollisionCondition.html +0 -148
  41. data/doc/classes/Zyps/CollisionCondition.src/M000083.html +0 -18
  42. data/doc/classes/Zyps/Color.html +0 -299
  43. data/doc/classes/Zyps/Color.src/M000038.html +0 -18
  44. data/doc/classes/Zyps/Color.src/M000039.html +0 -16
  45. data/doc/classes/Zyps/Color.src/M000040.html +0 -16
  46. data/doc/classes/Zyps/Color.src/M000041.html +0 -16
  47. data/doc/classes/Zyps/Color.src/M000042.html +0 -18
  48. data/doc/classes/Zyps/Color.src/M000043.html +0 -22
  49. data/doc/classes/Zyps/Condition.html +0 -118
  50. data/doc/classes/Zyps/Creature.html +0 -190
  51. data/doc/classes/Zyps/Creature.src/M000025.html +0 -19
  52. data/doc/classes/Zyps/Creature.src/M000026.html +0 -18
  53. data/doc/classes/Zyps/DestroyAction.html +0 -181
  54. data/doc/classes/Zyps/DestroyAction.src/M000054.html +0 -18
  55. data/doc/classes/Zyps/DestroyAction.src/M000055.html +0 -20
  56. data/doc/classes/Zyps/EatAction.html +0 -149
  57. data/doc/classes/Zyps/EatAction.src/M000068.html +0 -21
  58. data/doc/classes/Zyps/Enclosure.html +0 -206
  59. data/doc/classes/Zyps/Enclosure.src/M000010.html +0 -18
  60. data/doc/classes/Zyps/Enclosure.src/M000011.html +0 -31
  61. data/doc/classes/Zyps/Environment.html +0 -203
  62. data/doc/classes/Zyps/Environment.src/M000081.html +0 -19
  63. data/doc/classes/Zyps/Environment.src/M000082.html +0 -67
  64. data/doc/classes/Zyps/EnvironmentalFactor.html +0 -118
  65. data/doc/classes/Zyps/FaceAction.html +0 -148
  66. data/doc/classes/Zyps/FaceAction.src/M000080.html +0 -18
  67. data/doc/classes/Zyps/FleeAction.html +0 -207
  68. data/doc/classes/Zyps/FleeAction.src/M000084.html +0 -19
  69. data/doc/classes/Zyps/FleeAction.src/M000085.html +0 -19
  70. data/doc/classes/Zyps/FleeAction.src/M000086.html +0 -38
  71. data/doc/classes/Zyps/Friction.html +0 -181
  72. data/doc/classes/Zyps/Friction.src/M000072.html +0 -19
  73. data/doc/classes/Zyps/Friction.src/M000073.html +0 -18
  74. data/doc/classes/Zyps/GameObject.html +0 -282
  75. data/doc/classes/Zyps/GameObject.src/M000060.html +0 -19
  76. data/doc/classes/Zyps/GameObject.src/M000061.html +0 -16
  77. data/doc/classes/Zyps/GameObject.src/M000062.html +0 -19
  78. data/doc/classes/Zyps/GameObject.src/M000063.html +0 -16
  79. data/doc/classes/Zyps/GameObject.src/M000064.html +0 -16
  80. data/doc/classes/Zyps/Gravity.html +0 -145
  81. data/doc/classes/Zyps/Gravity.src/M000065.html +0 -16
  82. data/doc/classes/Zyps/Location.html +0 -167
  83. data/doc/classes/Zyps/Location.src/M000037.html +0 -18
  84. data/doc/classes/Zyps/NoMatchException.html +0 -111
  85. data/doc/classes/Zyps/PopulationLimit.html +0 -183
  86. data/doc/classes/Zyps/PopulationLimit.src/M000027.html +0 -19
  87. data/doc/classes/Zyps/PopulationLimit.src/M000028.html +0 -20
  88. data/doc/classes/Zyps/ProximityCondition.html +0 -182
  89. data/doc/classes/Zyps/ProximityCondition.src/M000056.html +0 -18
  90. data/doc/classes/Zyps/ProximityCondition.src/M000057.html +0 -18
  91. data/doc/classes/Zyps/PullAction.html +0 -199
  92. data/doc/classes/Zyps/PullAction.src/M000046.html +0 -19
  93. data/doc/classes/Zyps/PullAction.src/M000047.html +0 -19
  94. data/doc/classes/Zyps/PullAction.src/M000048.html +0 -23
  95. data/doc/classes/Zyps/PushAction.html +0 -199
  96. data/doc/classes/Zyps/PushAction.src/M000049.html +0 -19
  97. data/doc/classes/Zyps/PushAction.src/M000050.html +0 -19
  98. data/doc/classes/Zyps/PushAction.src/M000051.html +0 -23
  99. data/doc/classes/Zyps/SpeedLimit.html +0 -181
  100. data/doc/classes/Zyps/SpeedLimit.src/M000023.html +0 -18
  101. data/doc/classes/Zyps/SpeedLimit.src/M000024.html +0 -18
  102. data/doc/classes/Zyps/TagAction.html +0 -181
  103. data/doc/classes/Zyps/TagAction.src/M000052.html +0 -18
  104. data/doc/classes/Zyps/TagAction.src/M000053.html +0 -18
  105. data/doc/classes/Zyps/TagCondition.html +0 -181
  106. data/doc/classes/Zyps/TagCondition.src/M000018.html +0 -18
  107. data/doc/classes/Zyps/TagCondition.src/M000019.html +0 -18
  108. data/doc/classes/Zyps/TrailsView.html +0 -209
  109. data/doc/classes/Zyps/TrailsView.src/M000008.html +0 -40
  110. data/doc/classes/Zyps/TrailsView.src/M000009.html +0 -78
  111. data/doc/classes/Zyps/TurnAction.html +0 -200
  112. data/doc/classes/Zyps/TurnAction.src/M000077.html +0 -19
  113. data/doc/classes/Zyps/TurnAction.src/M000078.html +0 -19
  114. data/doc/classes/Zyps/TurnAction.src/M000079.html +0 -18
  115. data/doc/classes/Zyps/Utility.html +0 -251
  116. data/doc/classes/Zyps/Utility.src/M000001.html +0 -26
  117. data/doc/classes/Zyps/Utility.src/M000002.html +0 -22
  118. data/doc/classes/Zyps/Utility.src/M000003.html +0 -18
  119. data/doc/classes/Zyps/Utility.src/M000004.html +0 -21
  120. data/doc/classes/Zyps/Utility.src/M000005.html +0 -25
  121. data/doc/classes/Zyps/Utility.src/M000006.html +0 -21
  122. data/doc/classes/Zyps/Utility.src/M000007.html +0 -21
  123. data/doc/classes/Zyps/Vector.html +0 -281
  124. data/doc/classes/Zyps/Vector.src/M000029.html +0 -19
  125. data/doc/classes/Zyps/Vector.src/M000030.html +0 -16
  126. data/doc/classes/Zyps/Vector.src/M000031.html +0 -21
  127. data/doc/classes/Zyps/Vector.src/M000032.html +0 -16
  128. data/doc/classes/Zyps/Vector.src/M000033.html +0 -18
  129. data/doc/classes/Zyps/Vector.src/M000034.html +0 -16
  130. data/doc/classes/Zyps/Vector.src/M000035.html +0 -18
  131. data/doc/classes/Zyps/Vector.src/M000036.html +0 -25
  132. data/doc/classes/Zyps.html +0 -161
  133. data/doc/created.rid +0 -1
  134. data/doc/files/COPYING_LESSER_txt.html +0 -311
  135. data/doc/files/COPYING_txt.html +0 -1003
  136. data/doc/files/README_txt.html +0 -236
  137. data/doc/files/lib/zyps/actions_rb.html +0 -134
  138. data/doc/files/lib/zyps/conditions_rb.html +0 -134
  139. data/doc/files/lib/zyps/environmental_factors_rb.html +0 -134
  140. data/doc/files/lib/zyps/views/trails_rb.html +0 -134
  141. data/doc/files/lib/zyps_rb.html +0 -134
  142. data/doc/fr_class_index.html +0 -62
  143. data/doc/fr_file_index.html +0 -34
  144. data/doc/fr_method_index.html +0 -112
  145. data/doc/index.html +0 -24
  146. data/doc/rdoc-style.css +0 -208
data/README.txt CHANGED
@@ -11,7 +11,7 @@ Zyps are small creatures with minds of their own. You can create dozens of Zyps
11
11
  == Requirements
12
12
 
13
13
  * Ruby: http://www.ruby-lang.org
14
- * Ruby-GNOME2: http://ruby-gnome2.sourceforge.jp
14
+ * Ruby-GNOME2 (for the GUI): http://ruby-gnome2.sourceforge.jp
15
15
  * Rake (to build from source): http://rake.rubyforge.org
16
16
 
17
17
 
@@ -34,7 +34,7 @@ To see a tutorial on the library, at a command line, type:
34
34
 
35
35
  zyps_demo
36
36
 
37
- To run a DRb server that clients can connect to:
37
+ To run a server that offers a DRb Environment object clients can connect to:
38
38
 
39
39
  zyps_server [options]
40
40
  -h, --help Display program help.
data/bin/zyps_demo CHANGED
@@ -22,6 +22,7 @@ begin
22
22
  require 'zyps'
23
23
  require 'zyps/actions'
24
24
  require 'zyps/conditions'
25
+ require 'zyps/environmental_factors'
25
26
  require 'zyps/views/trails'
26
27
  rescue LoadError
27
28
  require 'rubygems'
@@ -187,13 +188,6 @@ class Demo
187
188
  end
188
189
 
189
190
 
190
- class Gravity < EnvironmentalFactor
191
- #Accelerate object toward the 'ground'.
192
- def act(target)
193
- target.vector.y += 9.8
194
- end
195
- end
196
-
197
191
  #Demonstrates environmental factors by adding gravity to the environment.
198
192
  def test_environmental_factors
199
193
 
@@ -205,7 +199,7 @@ class Demo
205
199
  animate(FRAME_COUNT)
206
200
 
207
201
  say("Let's add a new EnvironmentalFactor to simulate gravity.")
208
- gravity = Gravity.new
202
+ gravity = Gravity.new(200)
209
203
 
210
204
  say("We add gravity to the Environment.")
211
205
  @environment.environmental_factors << gravity
data/bin/zyps_server CHANGED
@@ -25,6 +25,7 @@ begin
25
25
  require 'zyps/actions'
26
26
  require 'zyps/conditions'
27
27
  require 'zyps/environmental_factors'
28
+ require 'zyps/remote'
28
29
  require 'zyps/views/trails'
29
30
  require 'drb'
30
31
  rescue LoadError
@@ -44,41 +45,15 @@ include Zyps
44
45
  DEFAULT_VIEW_WIDTH = 800
45
46
  DEFAULT_VIEW_HEIGHT = 600
46
47
  DEFAULT_MAX_SPEED = 500
47
- DEFAULT_MAX_POPULATION = 25
48
+ DEFAULT_MAX_POPULATION = 100
48
49
  DEFAULT_FPS = 60
49
50
 
50
51
 
51
- #Extend Environment for serving over DRb.
52
- class Environment
53
-
54
- include DRbUndumped
55
-
56
- def initialize (objects = [], environmental_factors = [])
57
- @objects, @environmental_factors = objects, environmental_factors
58
- @clock = Clock.new
59
- @objects.extend DRbUndumped
60
- @environmental_factors.extend DRbUndumped
61
- end
62
-
63
- alias old_objects= objects=
64
- def objects=(value)
65
- old_objects=(value)
66
- @objects.extend DRbUndumped
67
- end
68
-
69
- alias old_environmental_factors= environmental_factors=
70
- def environmental_factors=(value)
71
- old_environmental_factors=(value)
72
- @environmental_factors.extend DRbUndumped
73
- end
74
-
75
- end
76
-
77
52
  #A server for a Zyps Environment.
78
- class EnvironmentServer
53
+ class ZypsServer
79
54
 
80
55
  #Port to open service on.
81
- attr_accessor :url
56
+ attr_accessor :uri
82
57
  #Maximum allowed number of objects.
83
58
  attr_accessor :max_population
84
59
  #View dimensions.
@@ -86,7 +61,7 @@ class EnvironmentServer
86
61
 
87
62
  #Set up default values.
88
63
  def initialize(
89
- url = nil,
64
+ uri = nil,
90
65
  view_width = DEFAULT_VIEW_WIDTH,
91
66
  view_height = DEFAULT_VIEW_HEIGHT,
92
67
  fps = DEFAULT_FPS,
@@ -94,8 +69,8 @@ class EnvironmentServer
94
69
  max_speed = DEFAULT_MAX_SPEED,
95
70
  enclosure = true
96
71
  )
97
- @url, @view_width, @view_height, @fps, @max_population, @max_speed, @enclosure =
98
- url, view_width, view_height, fps, max_population, max_speed, enclosure
72
+ @uri, @view_width, @view_height, @fps, @max_population, @max_speed, @enclosure =
73
+ uri, view_width, view_height, fps, max_population, max_speed, enclosure
99
74
  end
100
75
 
101
76
  #Create app window, game environment, view, and network service.
@@ -173,12 +148,10 @@ class EnvironmentServer
173
148
  end
174
149
 
175
150
  #Start a network service.
176
- DRb.start_service(
177
- @url,
178
- environment
179
- )
151
+ server = EnvironmentServer.new(environment, @uri)
152
+ server.start
180
153
  #Display our URI.
181
- puts "Zyps server active at #{DRb.uri}"
154
+ puts "Zyps server active at #{server.uri}"
182
155
 
183
156
  #Disable file system access.
184
157
  $SAFE = 2
@@ -219,10 +192,10 @@ class EnvironmentServer
219
192
  ) {|value| @enclosure = false}
220
193
  options.on(
221
194
  "-u",
222
- "--url [url]",
195
+ "--uri [uri]",
223
196
  String,
224
- "dRuby URL to run the server on. If not defined, one will be selected and printed to STDOUT."
225
- ) {|value| @url = value}
197
+ "dRuby URI to run the server on. If not defined, one will be selected and printed to STDOUT."
198
+ ) {|value| @uri = value}
226
199
  options.on(
227
200
  "-f",
228
201
  "--fps [frames]",
@@ -251,7 +224,7 @@ end
251
224
 
252
225
  begin
253
226
  #Create a server.
254
- server = EnvironmentServer.new
227
+ server = ZypsServer.new
255
228
  #Parse the command line.
256
229
  server.process_options(ARGV)
257
230
  #Start the server.
@@ -85,19 +85,34 @@ class Accelerator < EnvironmentalFactor
85
85
 
86
86
  def initialize(vector)
87
87
  self.vector = vector
88
- @clock = Clock.new
88
+ @clocks = {} #Don't use Hash.new <block>, as it can't transmit via DRb.
89
89
  end
90
90
 
91
91
  #Accelerate the target away from the actor, but limited by elapsed time.
92
92
  def act(object)
93
- object.vector += Vector.new(@vector.speed * @clock.elapsed_time, @vector.pitch)
93
+ #Track time since last action for each GameObject.
94
+ @clocks[object] ||= Clock.new
95
+ #Push on object.
96
+ object.vector += Vector.new(@vector.speed * @clocks[object].elapsed_time, @vector.pitch)
94
97
  end
95
98
 
96
99
  end
97
100
 
98
101
  #Gravity pulls all objects downward.
99
102
  class Gravity < Accelerator
100
- def initialize; super(Vector.new(9.8, 270)); end
103
+
104
+ #Rate of acceleration.
105
+ attr_accessor :force
106
+
107
+ def initialize(force = 9.8)
108
+ super(Vector.new(force, 90))
109
+ self.force = force
110
+ end
111
+
112
+ def force= (force)
113
+ @vector.speed = force
114
+ end
115
+
101
116
  end
102
117
 
103
118
 
@@ -109,12 +124,25 @@ class Friction < EnvironmentalFactor
109
124
 
110
125
  def initialize(force)
111
126
  self.force = force
112
- @clock = Clock.new
127
+ #Track time since last action for each GameObject.
128
+ @clocks = {} #Don't use Hash.new <block>, as it can't transmit via DRb.
113
129
  end
114
130
 
115
131
  #Reduce the target's speed at the given rate.
116
132
  def act(object)
117
- object.vector.speed -= @force * @clock.elapsed_time
133
+ #Track time since last action for each GameObject.
134
+ @clocks[object] ||= Clock.new
135
+ #Slow object.
136
+ acceleration = @force * @clocks[object].elapsed_time
137
+ speed = object.vector.speed
138
+ if speed > 0
139
+ speed -= acceleration
140
+ speed = 0 if speed < 0
141
+ elsif speed < 0
142
+ speed += acceleration
143
+ speed = 0 if speed > 0
144
+ end
145
+ object.vector.speed = speed
118
146
  end
119
147
 
120
148
  end
@@ -0,0 +1,103 @@
1
+ # Copyright 2007 Jay McGavren, jay@mcgavren.com.
2
+ #
3
+ # This file is part of Zyps.
4
+ #
5
+ # Zyps is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation; either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+
19
+ module Zyps
20
+
21
+
22
+ require 'drb'
23
+ require 'zyps'
24
+ require 'zyps/actions'
25
+ require 'zyps/conditions'
26
+ require 'zyps/environmental_factors'
27
+
28
+
29
+ #An Environment proxy, served over DRb.
30
+ #As with all DRb services, it is recommended you set $SAFE to 1 or higher.
31
+ class EnvironmentServer
32
+
33
+
34
+ #The URI on which the server is operating.
35
+ attr_reader :uri
36
+
37
+
38
+ def initialize(environment = Environment.new, uri = nil)
39
+ @environment, @uri = environment, uri
40
+ end
41
+
42
+
43
+ #Offer the given environment for remote connections.
44
+ def start
45
+
46
+ #Ensure GameObject and EnvironmentalFactor lists stay on server side.
47
+ @environment.objects.extend DRbUndumped
48
+ @environment.environmental_factors.extend DRbUndumped
49
+
50
+ #Ensure Environment stays on server side.
51
+ class <<@environment
52
+ include DRbUndumped
53
+ alias old_objects= objects=
54
+ def objects=(value)
55
+ old_objects=(value)
56
+ @objects.extend DRbUndumped
57
+ end
58
+ alias old_environmental_factors= environmental_factors=
59
+ def environmental_factors=(value)
60
+ old_environmental_factors=(value)
61
+ @environmental_factors.extend DRbUndumped
62
+ end
63
+ end
64
+
65
+ #Start a network service.
66
+ @server = DRb::DRbServer.new(
67
+ @uri,
68
+ @environment
69
+ )
70
+ @uri ||= @server.uri
71
+
72
+ end
73
+
74
+
75
+ #Wait until the server is finished running.
76
+ def wait
77
+ @server.thread.join
78
+ end
79
+
80
+
81
+ #Stop the server.
82
+ def stop
83
+ @server.stop_service
84
+ end
85
+
86
+
87
+ end
88
+
89
+
90
+ #Get proxies to remote Environment objects via DRb.
91
+ #As with all DRb services, it is recommended you set $SAFE to 1 or higher.
92
+ module EnvironmentClient
93
+
94
+ #Get an environment proxy from the given URI.
95
+ def EnvironmentClient.get_environment(uri)
96
+ DRb.start_service()
97
+ DRbObject.new_with_uri(uri)
98
+ end
99
+
100
+ end
101
+
102
+
103
+ end #module Zyps
@@ -29,8 +29,9 @@ REQUIRED_ACCURACY = 0.001
29
29
 
30
30
 
31
31
  #Redefine Clock to return a predictable time.
32
+ ELAPSED_TIME = 0.1
32
33
  class Clock
33
- def elapsed_time; 0.1; end
34
+ def elapsed_time; ELAPSED_TIME; end
34
35
  end
35
36
 
36
37
 
@@ -24,12 +24,6 @@ require 'test/unit'
24
24
  include Zyps
25
25
 
26
26
 
27
- #Redefine Clock to return a predictable time.
28
- class Clock
29
- def elapsed_time; 0.1; end
30
- end
31
-
32
-
33
27
  class TestConditions < Test::Unit::TestCase
34
28
 
35
29
 
@@ -25,9 +25,8 @@ include Zyps
25
25
 
26
26
 
27
27
  #Redefine Clock to return a predictable time.
28
- ELAPSED_TIME = 0.1
29
28
  class Clock
30
- def elapsed_time; ELAPSED_TIME; end
29
+ def elapsed_time; 0.1; end
31
30
  end
32
31
 
33
32
 
@@ -0,0 +1,113 @@
1
+ # Copyright 2007 Jay McGavren, jay@mcgavren.com.
2
+ #
3
+ # This file is part of Zyps.
4
+ #
5
+ # Zyps is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation; either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+
19
+ require 'test/unit'
20
+ require 'zyps/remote' #Require only the remote library, to ensure it requires the others for us.
21
+
22
+
23
+ include Zyps
24
+
25
+
26
+ #Redefine Clock to return a predictable time.
27
+ class Clock
28
+ def elapsed_time; 0.1; end
29
+ end
30
+
31
+
32
+ class TestRemote < Test::Unit::TestCase
33
+
34
+ URI = 'druby://localhost:8989'
35
+ SPEED = 1
36
+ PITCH = 0
37
+ RATE = 1
38
+
39
+ def setup
40
+ @environment = Environment.new
41
+ @server = EnvironmentServer.new(@environment, URI)
42
+ @server.start
43
+ @client = EnvironmentClient.get_environment(URI)
44
+ end
45
+
46
+ def teardown
47
+ @server.stop
48
+ end
49
+
50
+ def test_uri
51
+ assert_equal(URI, @server.uri)
52
+ end
53
+
54
+ #Add an object to local environment and ensure client receives it.
55
+ def test_local_add_object
56
+ object = GameObject.new
57
+ @environment.objects << object
58
+ assert_equal(object, @client.objects.pop)
59
+ end
60
+
61
+ #Add an object to remote environment and ensure client receives it.
62
+ def test_remote_add_object
63
+ object = GameObject.new
64
+ @environment.objects << object
65
+ assert_equal(object, @client.objects.pop)
66
+ end
67
+
68
+ #Place GameObjects and ensure they can move.
69
+ def test_objects
70
+ object = GameObject.new
71
+ object.vector = Vector.new(SPEED, PITCH)
72
+ @client.objects << object
73
+ @environment.interact
74
+ assert_in_delta(0.1 * SPEED, @client.objects[0].location.x, 0.001)
75
+ end
76
+
77
+ #Place Creature with Action and ensure it's carried out.
78
+ def test_actions
79
+ creature = Creature.new
80
+ creature.vector = Vector.new(SPEED, PITCH)
81
+ behavior = Behavior.new
82
+ behavior.actions << TurnAction.new(RATE)
83
+ creature.behaviors << behavior
84
+ @client.objects << creature
85
+ @client.objects << Creature.new #Second creature to interact with.
86
+ @environment.interact
87
+ assert_in_delta(PITCH + 0.1 * RATE, @client.objects[0].vector.pitch, 0.001)
88
+ end
89
+
90
+ #Place Creature with Condition and ensure it's followed.
91
+ def test_conditions
92
+ creature = Creature.new
93
+ creature.vector = Vector.new(SPEED, PITCH)
94
+ behavior = Behavior.new
95
+ behavior.actions << TurnAction.new(RATE)
96
+ behavior.conditions << TagCondition.new('foobar') #Will return false.
97
+ creature.behaviors << behavior
98
+ @client.objects << creature
99
+ @client.objects << Creature.new #Second creature to interact with.
100
+ @environment.interact
101
+ #Ensure pitch is unaltered, as condition was false.
102
+ assert_in_delta(PITCH, @client.objects[0].vector.pitch, 0.001)
103
+ end
104
+
105
+ #Add EnvironmentalFactors and ensure they're usable.
106
+ def test_environmental_factors
107
+ @client.objects << Creature.new
108
+ @client.environmental_factors << Accelerator.new(Vector.new(SPEED, PITCH))
109
+ @environment.interact
110
+ assert_in_delta(SPEED * 0.1, @client.objects[0].vector.speed, 0.001)
111
+ end
112
+
113
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: zyps
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.6.1
7
- date: 2007-10-24 00:00:00 -07:00
6
+ version: 0.6.2
7
+ date: 2007-11-01 00:00:00 -07:00
8
8
  summary: A game library for Ruby
9
9
  require_paths:
10
10
  - lib
@@ -36,192 +36,20 @@ files:
36
36
  - bin/zyps_demo
37
37
  - bin/zyps_server
38
38
  - lib/zyps
39
- - lib/zyps.rb
40
- - lib/zyps/views
41
39
  - lib/zyps/actions.rb
42
- - lib/zyps/environmental_factors.rb
43
40
  - lib/zyps/conditions.rb
41
+ - lib/zyps/environmental_factors.rb
42
+ - lib/zyps/remote.rb
43
+ - lib/zyps/views
44
44
  - lib/zyps/views/trails.rb
45
- - test/zyps
45
+ - lib/zyps.rb
46
46
  - test/test_zyps.rb
47
- - test/zyps/test_behaviors.rb
47
+ - test/zyps
48
48
  - test/zyps/test_actions.rb
49
- - test/zyps/test_environmental_factors.rb
49
+ - test/zyps/test_behaviors.rb
50
50
  - test/zyps/test_conditions.rb
51
- - doc/created.rid
52
- - doc/rdoc-style.css
53
- - doc/files
54
- - doc/classes
55
- - doc/fr_file_index.html
56
- - doc/fr_class_index.html
57
- - doc/fr_method_index.html
58
- - doc/index.html
59
- - doc/files/lib
60
- - doc/files/COPYING_LESSER_txt.html
61
- - doc/files/COPYING_txt.html
62
- - doc/files/README_txt.html
63
- - doc/files/lib/zyps_rb.html
64
- - doc/files/lib/zyps
65
- - doc/files/lib/zyps/actions_rb.html
66
- - doc/files/lib/zyps/environmental_factors_rb.html
67
- - doc/files/lib/zyps/conditions_rb.html
68
- - doc/files/lib/zyps/views
69
- - doc/files/lib/zyps/views/trails_rb.html
70
- - doc/classes/Zyps
71
- - doc/classes/Zyps.html
72
- - doc/classes/Zyps/Utility.src
73
- - doc/classes/Zyps/TrailsView.src
74
- - doc/classes/Zyps/Enclosure.src
75
- - doc/classes/Zyps/Behavior.src
76
- - doc/classes/Zyps/Action.src
77
- - doc/classes/Zyps/TagCondition.src
78
- - doc/classes/Zyps/AccelerateAction.src
79
- - doc/classes/Zyps/SpeedLimit.src
80
- - doc/classes/Zyps/Creature.src
81
- - doc/classes/Zyps/PopulationLimit.src
82
- - doc/classes/Zyps/Vector.src
83
- - doc/classes/Zyps/Location.src
84
- - doc/classes/Zyps/Color.src
85
- - doc/classes/Zyps/Accelerator.src
86
- - doc/classes/Zyps/PullAction.src
87
- - doc/classes/Zyps/PushAction.src
88
- - doc/classes/Zyps/TagAction.src
89
- - doc/classes/Zyps/DestroyAction.src
90
- - doc/classes/Zyps/ProximityCondition.src
91
- - doc/classes/Zyps/AgeCondition.src
92
- - doc/classes/Zyps/GameObject.src
93
- - doc/classes/Zyps/Gravity.src
94
- - doc/classes/Zyps/BlendAction.src
95
- - doc/classes/Zyps/EatAction.src
96
- - doc/classes/Zyps/Clock.src
97
- - doc/classes/Zyps/Friction.src
98
- - doc/classes/Zyps/ApproachAction.src
99
- - doc/classes/Zyps/TurnAction.src
100
- - doc/classes/Zyps/FaceAction.src
101
- - doc/classes/Zyps/Environment.src
102
- - doc/classes/Zyps/CollisionCondition.src
103
- - doc/classes/Zyps/FleeAction.src
104
- - doc/classes/Zyps/Utility.html
105
- - doc/classes/Zyps/TrailsView.html
106
- - doc/classes/Zyps/Enclosure.html
107
- - doc/classes/Zyps/Behavior.html
108
- - doc/classes/Zyps/Action.html
109
- - doc/classes/Zyps/TagCondition.html
110
- - doc/classes/Zyps/AccelerateAction.html
111
- - doc/classes/Zyps/SpeedLimit.html
112
- - doc/classes/Zyps/Creature.html
113
- - doc/classes/Zyps/PopulationLimit.html
114
- - doc/classes/Zyps/Vector.html
115
- - doc/classes/Zyps/Location.html
116
- - doc/classes/Zyps/Color.html
117
- - doc/classes/Zyps/Accelerator.html
118
- - doc/classes/Zyps/NoMatchException.html
119
- - doc/classes/Zyps/PullAction.html
120
- - doc/classes/Zyps/PushAction.html
121
- - doc/classes/Zyps/TagAction.html
122
- - doc/classes/Zyps/DestroyAction.html
123
- - doc/classes/Zyps/ProximityCondition.html
124
- - doc/classes/Zyps/AgeCondition.html
125
- - doc/classes/Zyps/EnvironmentalFactor.html
126
- - doc/classes/Zyps/GameObject.html
127
- - doc/classes/Zyps/Gravity.html
128
- - doc/classes/Zyps/BlendAction.html
129
- - doc/classes/Zyps/EatAction.html
130
- - doc/classes/Zyps/Clock.html
131
- - doc/classes/Zyps/Friction.html
132
- - doc/classes/Zyps/ApproachAction.html
133
- - doc/classes/Zyps/TurnAction.html
134
- - doc/classes/Zyps/FaceAction.html
135
- - doc/classes/Zyps/Environment.html
136
- - doc/classes/Zyps/CollisionCondition.html
137
- - doc/classes/Zyps/Condition.html
138
- - doc/classes/Zyps/FleeAction.html
139
- - doc/classes/Zyps/Utility.src/M000001.html
140
- - doc/classes/Zyps/Utility.src/M000002.html
141
- - doc/classes/Zyps/Utility.src/M000003.html
142
- - doc/classes/Zyps/Utility.src/M000004.html
143
- - doc/classes/Zyps/Utility.src/M000005.html
144
- - doc/classes/Zyps/Utility.src/M000006.html
145
- - doc/classes/Zyps/Utility.src/M000007.html
146
- - doc/classes/Zyps/TrailsView.src/M000008.html
147
- - doc/classes/Zyps/TrailsView.src/M000009.html
148
- - doc/classes/Zyps/Enclosure.src/M000010.html
149
- - doc/classes/Zyps/Enclosure.src/M000011.html
150
- - doc/classes/Zyps/Behavior.src/M000012.html
151
- - doc/classes/Zyps/Behavior.src/M000013.html
152
- - doc/classes/Zyps/Action.src/M000014.html
153
- - doc/classes/Zyps/Action.src/M000015.html
154
- - doc/classes/Zyps/Action.src/M000016.html
155
- - doc/classes/Zyps/Action.src/M000017.html
156
- - doc/classes/Zyps/TagCondition.src/M000018.html
157
- - doc/classes/Zyps/TagCondition.src/M000019.html
158
- - doc/classes/Zyps/AccelerateAction.src/M000020.html
159
- - doc/classes/Zyps/AccelerateAction.src/M000021.html
160
- - doc/classes/Zyps/AccelerateAction.src/M000022.html
161
- - doc/classes/Zyps/SpeedLimit.src/M000023.html
162
- - doc/classes/Zyps/SpeedLimit.src/M000024.html
163
- - doc/classes/Zyps/Creature.src/M000025.html
164
- - doc/classes/Zyps/Creature.src/M000026.html
165
- - doc/classes/Zyps/PopulationLimit.src/M000027.html
166
- - doc/classes/Zyps/PopulationLimit.src/M000028.html
167
- - doc/classes/Zyps/Vector.src/M000029.html
168
- - doc/classes/Zyps/Vector.src/M000030.html
169
- - doc/classes/Zyps/Vector.src/M000031.html
170
- - doc/classes/Zyps/Vector.src/M000032.html
171
- - doc/classes/Zyps/Vector.src/M000033.html
172
- - doc/classes/Zyps/Vector.src/M000034.html
173
- - doc/classes/Zyps/Vector.src/M000035.html
174
- - doc/classes/Zyps/Vector.src/M000036.html
175
- - doc/classes/Zyps/Location.src/M000037.html
176
- - doc/classes/Zyps/Color.src/M000038.html
177
- - doc/classes/Zyps/Color.src/M000039.html
178
- - doc/classes/Zyps/Color.src/M000040.html
179
- - doc/classes/Zyps/Color.src/M000041.html
180
- - doc/classes/Zyps/Color.src/M000042.html
181
- - doc/classes/Zyps/Color.src/M000043.html
182
- - doc/classes/Zyps/Accelerator.src/M000044.html
183
- - doc/classes/Zyps/Accelerator.src/M000045.html
184
- - doc/classes/Zyps/PullAction.src/M000046.html
185
- - doc/classes/Zyps/PullAction.src/M000047.html
186
- - doc/classes/Zyps/PullAction.src/M000048.html
187
- - doc/classes/Zyps/PushAction.src/M000049.html
188
- - doc/classes/Zyps/PushAction.src/M000050.html
189
- - doc/classes/Zyps/PushAction.src/M000051.html
190
- - doc/classes/Zyps/TagAction.src/M000052.html
191
- - doc/classes/Zyps/TagAction.src/M000053.html
192
- - doc/classes/Zyps/DestroyAction.src/M000054.html
193
- - doc/classes/Zyps/DestroyAction.src/M000055.html
194
- - doc/classes/Zyps/ProximityCondition.src/M000056.html
195
- - doc/classes/Zyps/ProximityCondition.src/M000057.html
196
- - doc/classes/Zyps/AgeCondition.src/M000058.html
197
- - doc/classes/Zyps/AgeCondition.src/M000059.html
198
- - doc/classes/Zyps/GameObject.src/M000060.html
199
- - doc/classes/Zyps/GameObject.src/M000061.html
200
- - doc/classes/Zyps/GameObject.src/M000062.html
201
- - doc/classes/Zyps/GameObject.src/M000063.html
202
- - doc/classes/Zyps/GameObject.src/M000064.html
203
- - doc/classes/Zyps/Gravity.src/M000065.html
204
- - doc/classes/Zyps/BlendAction.src/M000066.html
205
- - doc/classes/Zyps/BlendAction.src/M000067.html
206
- - doc/classes/Zyps/EatAction.src/M000068.html
207
- - doc/classes/Zyps/Clock.src/M000069.html
208
- - doc/classes/Zyps/Clock.src/M000070.html
209
- - doc/classes/Zyps/Clock.src/M000071.html
210
- - doc/classes/Zyps/Friction.src/M000072.html
211
- - doc/classes/Zyps/Friction.src/M000073.html
212
- - doc/classes/Zyps/ApproachAction.src/M000074.html
213
- - doc/classes/Zyps/ApproachAction.src/M000075.html
214
- - doc/classes/Zyps/ApproachAction.src/M000076.html
215
- - doc/classes/Zyps/TurnAction.src/M000077.html
216
- - doc/classes/Zyps/TurnAction.src/M000078.html
217
- - doc/classes/Zyps/TurnAction.src/M000079.html
218
- - doc/classes/Zyps/FaceAction.src/M000080.html
219
- - doc/classes/Zyps/Environment.src/M000081.html
220
- - doc/classes/Zyps/Environment.src/M000082.html
221
- - doc/classes/Zyps/CollisionCondition.src/M000083.html
222
- - doc/classes/Zyps/FleeAction.src/M000084.html
223
- - doc/classes/Zyps/FleeAction.src/M000085.html
224
- - doc/classes/Zyps/FleeAction.src/M000086.html
51
+ - test/zyps/test_environmental_factors.rb
52
+ - test/zyps/test_remote.rb
225
53
  test_files:
226
54
  - test/test_zyps.rb
227
55
  rdoc_options: