shattered_support 0.3 → 0.3.1

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.
data/lib/base.rb CHANGED
@@ -1,198 +1,168 @@
1
- module ShatteredSupport
2
-
3
- BEFORE_INIT_CALL_VALUES = :before_init_call_values
4
- BEFORE_INIT_SET_VALUES = :before_init_set_values
5
-
6
-
7
- def self.append_features(base)
8
- super
9
- base.extend(ClassMethods)
10
- end
11
- module ClassMethods
12
- # An actor is the MVC encapsulated into one object.
13
- # With actors, you can send requests to each of the model, view and control
14
- # objects, and even retrieve results from the MVC objects.
15
- #
16
- # Here is how it works: You specify a actor in a game state with some starting
17
- # attributes:
18
- #
19
- # actor :napolean, :mood => 'snobbish'
20
- #
21
- # The options are the same as the camera options, except they propogate through
22
- # the MVC object(as all commands do).
23
- #
24
- # When obtaining a result, the result will be the a response in the following order
25
- # - Model
26
- # - View
27
- # - Controller
28
- #
29
- # They are sorted so that you get the most useful response first.
30
- def actor( name, options = {} )
31
- before_init_call( :actor, name, options )
32
- end
33
-
34
- def before_init_set(variable, options={})
35
- self.write_inheritable_array(BEFORE_INIT_SET_VALUES, [[ variable, options ]] )
36
- end
37
-
38
- def before_init_call(function, *arguments)
39
- self.write_inheritable_array(BEFORE_INIT_CALL_VALUES, [[function, [*arguments]]])
40
- end
41
- end
42
- class Base
43
- attr_writer :actor
44
- def self.new(*options)
45
- new_base = allocate
46
- new_base.pre_initialize
47
- new_base.send(:initialize, *options)
48
- return new_base
49
- end
50
- def state
51
- Configuration.environment[:state]
52
- end
53
- def pre_initialize
54
- pre_initialize_set
55
- pre_initialize_call
56
- end
57
-
58
- def each_init_value(name)
59
- startup_attributes = self.class.read_inheritable_attribute( name ) || []
60
- startup_attributes.each do |actor, options|
61
- next if options.nil?
62
- yield actor, options
63
- end
64
- end
65
-
66
- def pre_initialize_set
67
- each_init_value(BEFORE_INIT_SET_VALUES) do |variable, options|
68
- call_object_function_for_each_key( variable, options )
69
- end
70
- # self.class.write_inheritable_attribute(BEFORE_INIT_SET_VALUES, nil)
71
- end
72
-
73
- def pre_initialize_call
74
- each_init_value(BEFORE_INIT_CALL_VALUES) do |function, args|
75
- call_object_function( :self, function, args )
76
- end
77
- # self.class.write_inheritable_attribute(BEFORE_INIT_CALL_VALUES, nil)
78
- end
79
-
80
- def actors
81
- return @actors || []
82
- end
83
-
84
- # There are two uses for the instance class actor function:
85
- # The first is to access the actor that the base object is a part of.
86
- # The second is to create a new actor with the same arguments
87
- # ShatteredSupport::Base.actor
88
- def actor(*args)
89
- return @actor if args.length == 0
90
-
91
- name, options = args
92
- actor_options={}
93
- ['model', 'view', 'controller'].each do |type|
94
- begin
95
- require "#{SHATTERED_ROOT}/app/#{type.pluralize}/#{name}_#{type}"
96
- class_name = "#{name.to_s.camelize}#{type.camelize}"
97
- actor_options[type.to_sym] = eval(class_name).new
98
- rescue MissingSourceFile
99
- end
100
- end
101
- actor_options[:testing] = options.delete(:testing)
102
- actor = Actor.new(name,actor_options)
103
-
104
- attr_reader(name.to_sym, actor)
105
- call_object_function_for_each_key( name.to_sym, options )
106
-
107
- options[:testing] = actor_options[:testing] if !actor_options[:testing].nil?
108
-
109
- @actors ||= []
110
- @actors << actor
111
- end
112
-
113
- # Overwrite this function to recieve an update event every frame, with the
114
- # seconds elapsed since last update.
115
- def update_event(time_elapsed)
116
- actors.each do |actor|
117
- actor.update_actors(time_elapsed)
118
- actor.update(time_elapsed)
119
- end
120
- end
121
-
122
- # remove_from_scene? should just be defined in model.
123
- # Refactor?
124
- def remove_from_scene?
125
- return false
126
- end
127
-
128
- def update_actors(time_elapsed)
129
- update_event time_elapsed
130
- remove_dead_actors
131
- end
132
-
133
- def update(time_elapsed)
134
- end
135
-
136
- def remove_dead_actors
137
- actors.each do |actor|
138
- remove_from_scene actor if actor.remove_from_scene?
139
- end
140
- end
141
-
142
- def remove_from_scene(actor)
143
- actors.delete actor
144
- actor.unload!
145
- end
146
-
147
- protected
148
- def call_object_function_for_each_key( actor, options )
149
- call_object_function(actor, :position=, options.delete(:position)) if options.has_key? :position
150
- options.each_pair do |action, params|
151
- call_object_function actor, "#{action}=", params
152
- end
153
- end
154
- def call_object_function(actor, action, params)
155
- begin
156
- if params.is_a? Symbol #|| (params.length == 1 && params[0].is_a?(Symbol)) this will allow substitution in before_init_call. This may not be intended behavior.
157
- params = eval(params.to_s)
158
- end
159
- rescue NameError
1
+
2
+ $:.unshift(File.dirname(__FILE__)) unless
3
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
4
+
5
+ require 'timer/timer'
6
+ require 'vector'
7
+
8
+ module ShatteredSupport
9
+
10
+ BEFORE_INIT_CALL_VALUES = :before_init_call_values
11
+ BEFORE_INIT_SET_VALUES = :before_init_set_values
12
+
13
+
14
+ def self.append_features(base)
15
+ super
16
+ base.extend(ClassMethods)
17
+ end
18
+ module ClassMethods
19
+ def before_init_set(variable, options={})
20
+ self.write_inheritable_array(BEFORE_INIT_SET_VALUES, [[ variable, options ]] )
21
+ end
22
+
23
+ def before_init_call(function, *arguments)
24
+ self.write_inheritable_array(BEFORE_INIT_CALL_VALUES, [[function, [*arguments]]])
25
+ end
26
+ end
27
+ class Base
28
+ def self.new(*options)
29
+ new_base = allocate
30
+ new_base.pre_initialize
31
+ new_base.send(:initialize, *options)
32
+ return new_base
33
+ end
34
+ def state
35
+ Configuration.environment[:state]
36
+ end
37
+ def pre_initialize
38
+ pre_initialize_set
39
+ pre_initialize_call
40
+ end
41
+
42
+ def each_init_value(name)
43
+ startup_attributes = self.class.read_inheritable_attribute( name ) || []
44
+ startup_attributes.each do |actor, options|
45
+ next if options.nil?
46
+ yield actor, options
47
+ end
48
+ end
49
+
50
+ def pre_initialize_set
51
+ each_init_value(BEFORE_INIT_SET_VALUES) do |variable, options|
52
+ call_object_function_for_each_key( variable, options )
53
+ end
54
+ # self.class.write_inheritable_attribute(BEFORE_INIT_SET_VALUES, nil)
55
+ end
56
+
57
+ def pre_initialize_call
58
+ each_init_value(BEFORE_INIT_CALL_VALUES) do |function, args|
59
+ call_object_function( :self, function, args )
60
+ end
61
+ # self.class.write_inheritable_attribute(BEFORE_INIT_CALL_VALUES, nil)
62
+ end
63
+
64
+
65
+ # Overwrite this function to recieve an update event every frame, with the
66
+ # seconds elapsed since last update.
67
+ def update_event(time_elapsed)
68
+ actors.each do |actor|
69
+ actor.update_actors(time_elapsed)
70
+ actor.update(time_elapsed)
71
+ end
72
+ end
73
+
74
+ # remove_from_scene? should just be defined in model.
75
+ # Refactor?
76
+ def remove_from_scene?
77
+ return false
78
+ end
79
+
80
+ def update_actors(time_elapsed)
81
+ update_event time_elapsed
82
+ remove_dead_actors
83
+ end
84
+
85
+ def update(time_elapsed)
86
+ end
87
+
88
+ def remove_dead_actors
89
+ actors.each do |actor|
90
+ remove_from_scene actor if actor.remove_from_scene?
91
+ end
92
+ end
93
+
94
+ def remove_from_scene(actor)
95
+ actors.delete actor
96
+ actor.unload!
97
+ end
98
+
99
+ protected
100
+ def call_object_function_for_each_key( actor, options )
101
+ call_object_function(actor, :position=, options.delete(:position)) if options.has_key? :position
102
+ options.each_pair do |action, params|
103
+ call_object_function actor, "#{action}=", params
104
+ end
105
+ end
106
+ def call_object_function(actor, action, params)
107
+ begin
108
+ if params.is_a? Symbol #|| (params.length == 1 && params[0].is_a?(Symbol)) this will allow substitution in before_init_call. This may not be intended behavior.
109
+ params = eval(params.to_s)
110
+ end
111
+ rescue NameError
160
112
  puts "It is not advisable to pass #{params.inspect} to #{action.inspect} for #{actor.inspect}."
161
113
  puts " It will try to be evaluated. Use a string instead."
162
- end
163
- begin
164
- eval(actor.to_s).send( action.to_sym, *params )
165
- rescue NoMethodError => bang
166
- raise NoMethodError, "Error upon method #{action} for #{actor} of type #{eval(actor.to_s).class}: #{bang.message}"
167
- end
168
- end
169
- def unload!
170
- end
171
-
172
- public
173
-
174
- # attr helpers. This defines instance level attr_* functions.
175
- def attr_reader(*args)
176
- name, value = args
177
- attr_define(:reader, name, value)
178
- end
179
-
180
- def attr_writer(*args)
181
- name, value = args
182
- attr_define(:reader, name, value)
183
- end
184
-
185
- def attr_accessor(*args)
186
- name, value = args
187
- attr_define(:accessor, name, value)
188
- end
189
-
190
- protected
191
-
192
- def attr_define(accessor_level, name, value)
193
- self.class.send(:"attr_#{accessor_level}", :"#{name}")
194
- instance_variable_set(:"@#{name}", value) if !value.nil?
195
- end
196
-
197
- end
198
- end
114
+ end
115
+ begin
116
+ sendee = eval(actor.to_s)
117
+ sendee.send( action.to_sym, *params )
118
+ rescue NoMethodError, ArgumentError => bang
119
+ message="Error upon #{actor.to_s}.send(#{action.to_sym.inspect}, #{params.inspect}):\n\r #{bang.class}: #{bang.message}"
120
+ bang = ShatteredSupport::RetossError.new(bang,message)
121
+ raise bang
122
+ end
123
+ end
124
+ def unload!
125
+ end
126
+
127
+ public
128
+
129
+ # attr helpers. This defines instance level attr_* functions.
130
+ def attr_reader(*args)
131
+ name, value = args
132
+ attr_define(:reader, name, value)
133
+ end
134
+
135
+ def attr_writer(*args)
136
+ name, value = args
137
+ attr_define(:writer, name, value)
138
+ end
139
+
140
+ def attr_accessor(*args)
141
+ name, value = args
142
+ attr_define(:accessor, name, value)
143
+ end
144
+
145
+ protected
146
+
147
+ def attr_define(accessor_level, name, value)
148
+ self.class.send(:"attr_#{accessor_level}", :"#{name}")
149
+ instance_variable_set(:"@#{name}", value) if !value.nil?
150
+ end
151
+
152
+ end
153
+
154
+ class Error < StandardError
155
+ end
156
+
157
+ class RetossError < StandardError
158
+ attr_accessor :message
159
+ def initialize(error, message)
160
+ self.message = message
161
+ set_backtrace error.backtrace
162
+ end
163
+ end
164
+ end
165
+
166
+ ShatteredSupport::Base.class_eval do
167
+ include ShatteredSupport::Timer
168
+ end
@@ -5,8 +5,58 @@ class Object
5
5
  def method_defined?(method)
6
6
  return self.class.method_defined?(method)
7
7
  end
8
+
9
+ def v(x, y, z)
10
+ Vector.new(x, y, z)
11
+ end
12
+ end
13
+
14
+ class File
15
+ # File.each_in_path will recursively look for all files, starting at the given path.
16
+ # It will yield with each result.
17
+ def self.each_in_path(path)
18
+ Dir.each_in_path(path) do |directory|
19
+ Dir.foreach( directory ) do |filename|
20
+ resource = directory + "/#{filename}"
21
+ yield(resource) if File.file? resource
22
+ end
23
+ end
24
+ end
25
+
26
+ # This finds all files in paths (an array or string) matching the given extensions:
27
+ #
28
+ # Usage:
29
+ # -File.find_by_extensions(SHATTERED_ROOT,"ogg","mp3","wav")
30
+ # -File.find_by_extension(["apps","media","plugins"], "rmaterial")
31
+ def self.find_by_extensions(paths, *extensions)
32
+ paths = [paths] if paths.is_a? String
33
+ extensions.collect! { |ext| ext[0].chr == "." ? ext[1..-1] : ext } # get rid of "." in ".ogg"
34
+ reg_exp = /\.(#{extensions.join("|")})$/
35
+ files = []
36
+ paths.each do |path|
37
+ each_in_path(path) do |filename|
38
+ files << filename if filename =~ reg_exp
39
+ end
40
+ end
41
+ return files
42
+ end
43
+ # See File#find_by_extensions
44
+ def self.find_by_extension(paths, extension)
45
+ find_by_extensions(paths, extension)
46
+ end
47
+ end
48
+
49
+ class Dir
50
+ # Dir.each_in_path will recursively yield all non-hidden directories from the given path.
51
+ def self.each_in_path(path, &block)
52
+ return unless File.directory? path
53
+ yield path
54
+ foreach(path) do |directory|
55
+ next if directory =~ /\..*/
56
+ each_in_path("#{path}/#{directory}", &block)
57
+ end
58
+ end
8
59
  end
9
60
 
10
61
  require File.dirname(__FILE__)+"/base"
11
- require File.dirname(__FILE__)+"/actor"
12
62
  require File.dirname(__FILE__)+"/runner"
@@ -0,0 +1,77 @@
1
+ module ShatteredSupport
2
+ module Timer
3
+
4
+ class Timer
5
+ attr_reader :events_remaining
6
+ def initialize
7
+ @events_remaining = []
8
+ end
9
+ def in(seconds, &block)
10
+ @events_remaining << TimedEvent.new(seconds, &block)
11
+ end
12
+ def every(seconds, &block)
13
+ @events_remaining << ContinuousTimedEvent.new(seconds,&block)
14
+ end
15
+ def update(time_elapsed)
16
+ events_for_update = @events_remaining.dup
17
+ events_for_update.each do |event|
18
+ event.update(time_elapsed)
19
+ @events_remaining.delete(event) if event.processed?
20
+ end
21
+ end
22
+ end
23
+
24
+ class TimedEvent
25
+ attr_accessor :time_remaining
26
+ def initialize(seconds, &block)
27
+ @event = block
28
+ if(seconds != :frame)
29
+ @time_remaining = seconds
30
+ @initial_time = @time_remaining
31
+ else
32
+ @time_remaining = 0
33
+ @initial_time = 0
34
+ end
35
+ end
36
+ def update(time_elapsed)
37
+ return if processed?
38
+ @time_remaining -= time_elapsed
39
+ if time_up?
40
+ process_event
41
+ @processed=true
42
+ end
43
+ end
44
+ def processed?
45
+ return @processed == true
46
+ end
47
+ def reset
48
+ @time_remaining = @initial_time
49
+ end
50
+ private
51
+ def process_event
52
+ @event.call(@initial_time - @time_remaining)
53
+ end
54
+ def time_up?
55
+ return @time_remaining <= 0
56
+ end
57
+ end
58
+
59
+ class ContinuousTimedEvent < TimedEvent
60
+ def update(time_elapsed)
61
+ @time_remaining -= time_elapsed
62
+ if(time_up?)
63
+ process_event
64
+ reset
65
+ end
66
+ end
67
+ def reset
68
+ @time_remaining += @initial_time
69
+ @time_remaining = 0 if @time_remaining < 0
70
+ end
71
+ def processed?
72
+ false
73
+ end
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__)+'/timed_event'
2
+
3
+ module ShatteredSupport
4
+ module Timer
5
+ def self.append_features(base)
6
+ super
7
+ base.extend(ClassMethods)
8
+ base.send(:include, InstanceMethods)
9
+ end
10
+ module ClassMethods
11
+ # Timers are controller events that occur after a specified period of time.
12
+ # The time values are seconds by default.
13
+ #
14
+ # timer :in
15
+ # If you want an event to occur once after a specified amount of time, use
16
+ # timer :in => 3.seconds, :action => :method_to_call
17
+ #
18
+ # timer :every
19
+ # If you want an event to occur once every specified amount of time, use
20
+ # timer :every => 3.seconds, :action => :method_to_call
21
+ # If you want to be notified of every frame update, use
22
+ # timer :every => :frame, :action => :method_to_call
23
+ #
24
+ # Inside the instance, you can still create timer events, using the timer object:
25
+ # timer.in( 3.seconds ) { ... }
26
+ # timer.every( 3.seconds ) { ... }
27
+ def timer(options = {})
28
+ if options[:action].nil?
29
+ throw ShatteredSupport::Error,
30
+ "Timer event must specify an :action => :method"
31
+ end
32
+ if options[:in].nil? && options[:every].nil?
33
+ throw ShatteredSupport::Error,
34
+ "Timer event must specify a time. (timer :in or timer :every)"
35
+ end
36
+ time = options[:in] || options[:every]
37
+ action = options[:action]
38
+ before_init_call(:timer_in, time, action) unless options[:in].nil?
39
+ before_init_call(:timer_every, time, action) unless options[:every].nil?
40
+ end
41
+ end
42
+ module InstanceMethods
43
+ def timer
44
+ @timer ||= Timer.new
45
+ end
46
+ private
47
+ def timer_in(time, action)
48
+ timer.in(time) do |time_elapsed|
49
+ timer_enactment(action, time_elapsed)
50
+ end
51
+ end
52
+ def timer_every(time, action)
53
+ timer.every(time) do |time_elapsed|
54
+ timer_enactment(action, time_elapsed)
55
+ end
56
+ end
57
+ def timer_enactment(action, time_elapsed)
58
+ begin
59
+ send(action.to_sym)
60
+ rescue ArgumentError => argument_error
61
+ raise argument_error unless argument_error.message.to_sym == :"wrong number of arguments (0 for 1)"
62
+ send(action.to_sym,time_elapsed)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
data/lib/vector.rb ADDED
@@ -0,0 +1,172 @@
1
+
2
+ class Array
3
+ # Vector extensions for array. Allows for coersion of a 3 element Array into a vector.
4
+
5
+ # Randomize the order of an array
6
+ #
7
+ # [1, 2, 3].shuffle #=> [2, 3, 1]
8
+ #
9
+ def shuffle
10
+ sort_by {rand}
11
+ end
12
+
13
+ # Create a vector from an array.
14
+ #
15
+ # [1, 2, 3].to_v #=> same as Vector.new(1, 2, 3)
16
+ #
17
+ def to_v
18
+ raise StandardError, "vector #{self.inspect} does not have 3 elements" if self.length < 3
19
+ Vector.new self[0], self[1] ,self[2]
20
+ end
21
+
22
+ # Returns this Array as an Ogre vector object: Vector3. Should only be used internally by
23
+ # Shattered to communicate with the Ogre engine.
24
+ def to_v3
25
+ self.to_v.to_v3
26
+ end
27
+ end
28
+
29
+ module ShatteredSupport
30
+ class Vector
31
+
32
+ attr_reader :x, :y, :z
33
+
34
+ # Create a new Vector object. It requires exactly 3 arguments: x, y and z.
35
+ def initialize(x_val, y_val, z_val)
36
+ @x, @y, @z = x_val.to_f, y_val.to_f, z_val.to_f
37
+ end
38
+
39
+ # Iterate through x, y and z with a black. The passed value is the value of the component.
40
+ def each(&block)
41
+ self.to_a.each do |item|
42
+ yield item
43
+ end
44
+ end
45
+
46
+ # Returns this Vector as an Ogre vector object: Vector3. Should only be used internally by
47
+ # Shattered to communicate with the Ogre engine.
48
+ def to_v3
49
+ ShatteredOgre::Vector3.new @x, @y, @z
50
+ end
51
+
52
+ # Returns self
53
+ def to_v
54
+ self
55
+ end
56
+
57
+ # Returns an array with x, y and z dumped into its elements
58
+ #
59
+ # Vector.new(1, 2, 3).to_a #=> [1, 2, 3]
60
+ def to_a
61
+ [@x, @y, @z]
62
+ end
63
+
64
+ # Add 2 Vectors together.
65
+ def +(*args)
66
+ vector = convert_args_to_vector(args)
67
+ Vector.new(
68
+ self.x + vector.x,
69
+ self.y + vector.y,
70
+ self.z + vector.z
71
+ )
72
+ end
73
+
74
+ # Subtract one Vector form another.
75
+ def -(args)
76
+ vector = convert_args_to_vector(args)
77
+ Vector.new(
78
+ self.x - vector.x,
79
+ self.y - vector.y,
80
+ self.z - vector.z
81
+ )
82
+ end
83
+
84
+ # Multiply all components of a vector by a scalar amount.
85
+ def *(value)
86
+ result = []
87
+ each do |i|
88
+ result << i * value
89
+ end
90
+ result.to_v
91
+ end
92
+
93
+ # Divide all components of a vector by a scalar amount
94
+ def /(value)
95
+ result = Array.new
96
+ self.each do |i|
97
+ result << i/value.to_f
98
+ end
99
+ result.to_v
100
+ end
101
+
102
+ # Returns this Vector but normalized to a length of 1.
103
+ def normalize
104
+ self * (1 / length)
105
+ end
106
+ alias_method :normalise, :normalize
107
+
108
+ # Same as #normalize but is destructive.
109
+ def normalize!
110
+ @x, @y, @z = normalize.to_a
111
+ end
112
+ alias_method :normalise!, :normalize!
113
+
114
+ # Return the value specified by bracket notation.
115
+ def [](index)
116
+ case
117
+ when index == 0 || index == :x || index == 'x'
118
+ @x
119
+ when index == 1 || index == :y || index == 'y'
120
+ @y
121
+ when index == 2 || index == :z || index == 'z'
122
+ @z
123
+ end
124
+ end
125
+
126
+ # Set the value specified by bracket notation.
127
+ def []=(index, value)
128
+ case
129
+ when index == 0 || index == :x || index == 'x'
130
+ @x = value.to_f
131
+ when index == 1 || index == :y || index == 'y'
132
+ @y = value.to_f
133
+ when index == 2 || index == :z || index == 'z'
134
+ @z = value.to_f
135
+ end
136
+ end
137
+
138
+ def x=(value)
139
+ @x = value.to_f
140
+ end
141
+
142
+ def y=(value)
143
+ @y = value.to_f
144
+ end
145
+
146
+ def z=(value)
147
+ @z = value.to_f
148
+ end
149
+
150
+
151
+ # Returns the length of this vector.
152
+ def length
153
+ Math.sqrt(x**2 + y**2 + z**2)
154
+ end
155
+
156
+ def to_s
157
+ "#<Vector [#@x, #@y, #@z]>"
158
+ end
159
+
160
+ private
161
+
162
+ def convert_args_to_vector(*args)
163
+ args.flatten!
164
+ if args.first.is_a? Vector
165
+ args.first
166
+ else
167
+ args.to_v
168
+ end
169
+ end
170
+
171
+ end
172
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: shattered_support
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.3"
7
- date: 2006-04-23
6
+ version: 0.3.1
7
+ date: 2006-05-16
8
8
  summary: "Shattered Support: Allows a common derivation point for shattered MVC."
9
9
  require_paths:
10
10
  - lib
@@ -26,10 +26,12 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
26
26
  platform: ruby
27
27
  authors: []
28
28
  files:
29
- - lib/actor.rb
30
29
  - lib/base.rb
31
30
  - lib/runner.rb
32
31
  - lib/shattered_support.rb
32
+ - lib/vector.rb
33
+ - lib/timer/timed_event.rb
34
+ - lib/timer/timer.rb
33
35
  test_files: []
34
36
  rdoc_options: []
35
37
  extra_rdoc_files: []
data/lib/actor.rb DELETED
@@ -1,40 +0,0 @@
1
- module ShatteredSupport
2
- # An actor is a delegator to a model view control game object.
3
- class Actor
4
- attr_accessor :view, :model, :controller
5
- def initialize( name, options = {} )
6
- @actor_name = name
7
- @view = options[:view]
8
- @model = options[:model]
9
- @controller = options[:controller]
10
-
11
- [@view,@model,@controller].each do |component|
12
- component.actor = self if not component.nil?
13
- end
14
-
15
- if @view.nil? and @model.nil? and @controller.nil? and not options[:testing]
16
- raise NameError, "No model view or controller found for actor #{name}"
17
- end
18
- end
19
- # Whenever an function is called on the actor, it will call that function on it's
20
- # respective model, view, and control objects.
21
- def method_missing(name, *args)
22
- retv=nil
23
- called=false
24
- [@controller, @view, @model].each do |callee|
25
- if(callee.method_defined? name)
26
- retv = callee.send(name,*args)
27
- called = true
28
- end
29
- end
30
- raise NoMethodError, "Could not find method #{name} for actor #{@actor_name}" if !called
31
- return retv
32
- end
33
- # The actor should not normally know of the functions used in it's mvc components.
34
- # is this incorrect behaviour?
35
- def update_input(time_elapsed, input)
36
- return if @controller.nil?
37
- @controller.update_input(time_elapsed, input)
38
- end
39
- end
40
- end