chione 0.0.3 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e3f59bc83b67172347b8bdfba8dde65806c4d166
4
- data.tar.gz: 1e55f3d92ded7e6250ab83207d548a5a7c4da4a2
2
+ SHA256:
3
+ metadata.gz: 414e1caef54ca7d5f41452376a2309e343bb52812f567012504628b5ec2347ff
4
+ data.tar.gz: ca11c73c74c4e45c1373e54f224603f059b8eb0338e40b4a8e5cc676dc56c98f
5
5
  SHA512:
6
- metadata.gz: 1e214f19a70f22f2556649740985d211918697acea54942fd76820f500e50f42100b9eed42ce31fbed112be5b82f54282c5a674487262cd0a8df40bacef61266
7
- data.tar.gz: 75323d5fd8dd00fa7f78b22d5150e26e2112fb16c3a0b049ecce5753687bcc76cd3980f340515955607e49bad3c71420cefe31752243185007b85b9175e48ebb
6
+ metadata.gz: 1a21bcb7a924fdeff7f3d1fd4effe157a642baf7ddbc56303cb966b83ad182e41c5b7ab9d9d000dfa7fc963ad36fd1cdab560bdcad2ae2da87a57789a0a8abf5
7
+ data.tar.gz: 2ba9b26c5f7cbf5be5dd1d6b85857215861a4827e2454c67fd6d529154346921582568f1d47248d34bba8aef6af63bce2d860e2e8569009bc79e6afd6e77acf8
Binary file
data.tar.gz.sig CHANGED
Binary file
data/History.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## v0.1.0 [2017-05-22] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ Enhancements:
4
+
5
+ - Refactor the World start/stop logic to make it easier to override in
6
+ implementations which have their own process models.
7
+ - Allow a component's default to be generated by a callable
8
+
9
+ Bugfixes:
10
+
11
+ - Stringify the Manager or System class in `manager/added` and `system/added`
12
+ events.
13
+
14
+
1
15
  ## v0.0.3 [2017-01-04] Michael Granger <ged@FaerieMUD.org>
2
16
 
3
17
  Enhancements:
@@ -13,7 +13,7 @@ module Chione
13
13
 
14
14
 
15
15
  # Gem version
16
- VERSION = '0.0.3'
16
+ VERSION = '0.1.0'
17
17
 
18
18
 
19
19
  require 'chione/mixins'
@@ -29,3 +29,17 @@ end
29
29
 
30
30
 
31
31
 
32
+ RSpec.shared_examples "a Chione Manager" do |args|
33
+
34
+
35
+ let( :chione_world ) { Chione::World.new }
36
+
37
+
38
+ it "can be created by a Chione::World" do
39
+ described_class.new( chione_world )
40
+ end
41
+
42
+ end
43
+
44
+
45
+
@@ -4,19 +4,21 @@
4
4
  require 'loggability'
5
5
 
6
6
  require 'chione' unless defined?( Chione )
7
+ require 'chione/mixins'
8
+
7
9
 
8
10
  # The Component (data) class
9
11
  class Chione::Component
10
- extend Loggability
12
+ extend Loggability,
13
+ Chione::MethodUtilities
11
14
 
12
15
  # Loggability API -- log to the 'chione' logger
13
16
  log_to :chione
14
17
 
15
18
 
19
+ ##
16
20
  # The Hash of fields implemented by the component
17
- class << self
18
- attr_accessor :fields
19
- end
21
+ singleton_attr_accessor :fields
20
22
 
21
23
 
22
24
  ### Declare a field for the component named +name+, with a default value of
@@ -32,7 +34,7 @@ class Chione::Component
32
34
  def initialize( values={} )
33
35
  if self.class.fields
34
36
  self.class.fields.each do |name, default|
35
- self.method( "#{name}=" ).call( values[name] || deep_copy(default) )
37
+ self.method( "#{name}=" ).call( values[name] || default_value(default) )
36
38
  end
37
39
  end
38
40
  end
@@ -61,6 +63,14 @@ class Chione::Component
61
63
  private
62
64
  #######
63
65
 
66
+ ### Process the given +default+ value so it's suitable for use as a default
67
+ ### attribute value.
68
+ def default_value( default )
69
+ return default.call( self ) if default.respond_to?( :call )
70
+ return deep_copy( default )
71
+ end
72
+
73
+
64
74
  ### Make a deep copy of the specified +value+.
65
75
  def deep_copy( value )
66
76
  return Marshal.load( Marshal.dump(value) )
@@ -114,6 +114,13 @@ class Chione::World
114
114
  end
115
115
 
116
116
 
117
+ ### Stop any Managers running in the world.
118
+ def stop_managers
119
+ self.log.info "Stopping managers."
120
+ self.managers.each {|_, mgr| mgr.stop }
121
+ end
122
+
123
+
117
124
  ### Start any Systems registered with the world.
118
125
  def start_systems
119
126
  self.log.info "Starting %d Systems" % [ self.systems.length ]
@@ -127,6 +134,13 @@ class Chione::World
127
134
  end
128
135
 
129
136
 
137
+ ### Stop any Systems running in the world.
138
+ def stop_systems
139
+ self.log.info "Stopping systems."
140
+ self.systems.each {|_, sys| sys.stop }
141
+ end
142
+
143
+
130
144
  ### Returns +true+ if the World has been started (but is not necessarily running yet).
131
145
  def started?
132
146
  return @main_thread && @main_thread.alive?
@@ -139,22 +153,29 @@ class Chione::World
139
153
  end
140
154
 
141
155
 
142
- ### Stop the world.
143
- def stop
144
- self.systems.each {|_, sys| sys.stop }
145
- self.managers.each {|_, mgr| mgr.stop }
146
-
156
+ ### Kill the threads other than the main thread in the world's thread list.
157
+ def kill_world_threads
158
+ self.log.info "Killing child threads."
147
159
  self.world_threads.list.each do |thr|
148
160
  next if thr == @main_thread
161
+ self.log.debug " killing: %p" % [ thr ]
149
162
  thr.join( self.class.max_stop_wait )
150
163
  end
164
+ end
165
+
151
166
 
167
+ ### Stop the world.
168
+ def stop
169
+ self.stop_systems
170
+ self.stop_managers
171
+ self.kill_world_threads
152
172
  self.stop_timing_loop
153
173
  end
154
174
 
155
175
 
156
176
  ### Halt the main timing loop. By default, this just kills the world's main thread.
157
177
  def stop_timing_loop
178
+ self.log.info "Stopping the timing loop."
158
179
  @main_thread.kill
159
180
  end
160
181
 
@@ -184,7 +205,7 @@ class Chione::World
184
205
  ### Publish an event with the specified +event_name+, calling any subscribers with
185
206
  ### the specified +payload+.
186
207
  def publish( event_name, *payload )
187
- self.log.debug "Publishing a %p event: %p" % [ event_name, payload ]
208
+ # self.log.debug "Publishing a %p event: %p" % [ event_name, payload ]
188
209
  @subscriptions.each do |pattern, callbacks|
189
210
  next unless File.fnmatch?( pattern, event_name, File::FNM_EXTGLOB|File::FNM_PATHNAME )
190
211
 
@@ -194,6 +215,7 @@ class Chione::World
194
215
  rescue => err
195
216
  self.log.error "%p while calling %p for a %p event: %s" %
196
217
  [ err.class, callback, event_name, err.message ]
218
+ self.log.debug " %s" % [ err.backtrace.join("\n ") ]
197
219
  callbacks.delete( callback )
198
220
  end
199
221
  end
@@ -281,7 +303,7 @@ class Chione::World
281
303
  system_obj.start
282
304
  end
283
305
 
284
- self.publish( 'system/added', system_type )
306
+ self.publish( 'system/added', system_type.name )
285
307
  return system_obj
286
308
  end
287
309
 
@@ -297,7 +319,7 @@ class Chione::World
297
319
  manager_obj.start
298
320
  end
299
321
 
300
- self.publish( 'manager/added', manager_type )
322
+ self.publish( 'manager/added', manager_type.name )
301
323
  return manager_obj
302
324
  end
303
325
 
@@ -48,6 +48,17 @@ describe Chione::Component do
48
48
  expect( instance2.things ).to be_empty
49
49
  end
50
50
 
51
+
52
+ it "calls a callable default if it responds to #call" do
53
+ component_subclass.field( :oid, default: ->(obj) { obj.object_id } )
54
+
55
+ instance1 = component_subclass.new
56
+ instance2 = component_subclass.new( oid: 121212 )
57
+
58
+ expect( instance1.oid ).to eq( instance1.object_id )
59
+ expect( instance2.oid ).to eq( 121212 )
60
+ end
61
+
51
62
  end
52
63
 
53
64
  end
@@ -379,7 +379,7 @@ describe Chione::World do
379
379
 
380
380
  sys = world.add_system( test_system )
381
381
 
382
- expect( event_payload ).to eq([ 'system/added', [test_system] ])
382
+ expect( event_payload ).to eq([ 'system/added', [test_system.name] ])
383
383
  end
384
384
 
385
385
 
@@ -424,7 +424,7 @@ describe Chione::World do
424
424
 
425
425
  manager = world.add_manager( test_manager )
426
426
 
427
- expect( event_payload ).to eq([ 'manager/added', [test_manager] ])
427
+ expect( event_payload ).to eq([ 'manager/added', [test_manager.name] ])
428
428
  end
429
429
 
430
430
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chione
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -35,7 +35,7 @@ cert_chain:
35
35
  w8aNA5re5+Rt/Vvjxj5AcEnZnZiz5x959NaddQocX32Z1unHw44pzRNUur1GInfW
36
36
  p4vpx2kUSFSAGjtCbDGTNV2AH8w9OU4xEmNz8c5lyoA=
37
37
  -----END CERTIFICATE-----
38
- date: 2017-01-04 00:00:00.000000000 Z
38
+ date: 2017-05-22 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: loggability
@@ -99,14 +99,14 @@ dependencies:
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '0.8'
102
+ version: '0.9'
103
103
  type: :development
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '0.8'
109
+ version: '0.9'
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: hoe-highline
112
112
  requirement: !ruby/object:Gem::Requirement
@@ -169,14 +169,14 @@ dependencies:
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: '3.15'
172
+ version: '3.16'
173
173
  type: :development
174
174
  prerelease: false
175
175
  version_requirements: !ruby/object:Gem::Requirement
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: '3.15'
179
+ version: '3.16'
180
180
  description: |-
181
181
  An Entity/Component System framework inspired by Artemis.
182
182
 
@@ -245,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
245
  version: '0'
246
246
  requirements: []
247
247
  rubyforge_project:
248
- rubygems_version: 2.6.8
248
+ rubygems_version: 2.6.12
249
249
  signing_key:
250
250
  specification_version: 4
251
251
  summary: An Entity/Component System framework inspired by Artemis
metadata.gz.sig CHANGED
Binary file