Class: Teien::BaseObjectManager

Inherits:
BaseObjectManagerBase show all
Defined in:
lib/teien/base_object/base_object_manager.rb

Instance Attribute Summary

Attributes inherited from BaseObjectManagerBase

#ambient_light_color, #gravity, #objects, #physics, #plugins_cfg, #resources_cfg

Instance Method Summary collapse

Methods inherited from BaseObjectManagerBase

#check_collision, #create_object, #quit, #set_ambient_light, #set_gravity, #set_sky_dome

Methods included from Dispatcher

#notify, #notify_reversely, #register_receiver

Constructor Details

#initialize(sync_period) ⇒ BaseObjectManager

Returns a new instance of BaseObjectManager.



8
9
10
11
12
# File 'lib/teien/base_object/base_object_manager.rb', line 8

def initialize(sync_period)
  super()
  @sync_period = sync_period
  @sync_timer = sync_period
end

Instance Method Details

#connection_binded(from) ⇒ Object

EventRouter handler



32
33
34
35
36
# File 'lib/teien/base_object/base_object_manager.rb', line 32

def connection_binded(from)
  event = Event::BaseObject::SyncEnv.new(@gravity, @ambient_light_color, @sky_dome)
  @event_router.send_event(event, from)
  notify_objects(from)
end

#finalizeObject



48
49
50
51
# File 'lib/teien/base_object/base_object_manager.rb', line 48

def finalize()
  @physics.finalize()
  @objects = {}
end

#notify_objects(to = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/teien/base_object/base_object_manager.rb', line 38

def notify_objects(to = nil)
  @objects.each_value { |obj|
    if to
      to.send_object(Event::BaseObject::SyncObject.new(obj))
    else
      @event_router.send_event(Event::BaseObject::SyncObject.new(obj))
    end
  }
end

#setupObject

EventRouter handler



15
16
# File 'lib/teien/base_object/base_object_manager.rb', line 15

def setup()
end

#update(delta) ⇒ Object

EventRouter handler



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/teien/base_object/base_object_manager.rb', line 19

def update(delta)
  @physics.update(delta)

  @sync_timer += delta
  if (@sync_timer > @sync_period)
    notify_objects()
    @sync_timer = 0
  end

  return !@quit
end