Class: Teien::BaseObjectManagerProxy

Inherits:
BaseObjectManagerBase show all
Defined in:
lib/teien/base_object/base_object_manager_proxy.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

#initializeBaseObjectManagerProxy

Returns a new instance of BaseObjectManagerProxy.



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

def initialize()
  super()
  @quit = false
end

Instance Method Details

#create_object_from_event(event) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/teien/base_object/base_object_manager_proxy.rb', line 44

def create_object_from_event(event)
  obj = create_object(event.name, event.object_info, event.physics_info)
  obj.set_position(event.pos)
  obj.set_linear_velocity(event.linear_vel)
  obj.set_angular_velocity(event.angular_vel)
  obj.set_rotation(event.quat)
  obj.set_acceleration(event.accel)
  obj.attached_objects  = event.attached_objects
end

#finalizeObject

called by Garden class. clear all managers.



67
68
69
70
71
# File 'lib/teien/base_object/base_object_manager_proxy.rb', line 67

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

#receive_event(event, from) ⇒ Object

EventRouter handler



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/teien/base_object/base_object_manager_proxy.rb', line 24

def receive_event(event, from)

  # There was a case which this manager gets a new sync packet 
  # after finalizing.
  return if @quit
    
  case event
  when Event::BaseObject::SyncEnv
    set_gravity(event.gravity)
    set_ambient_light(event.ambient_light_color)
    set_sky_dome(event.sky_dome.enable, event.sky_dome.materialName)
  when Event::BaseObject::SyncObject
    if @objects[event.name]
      sync_object_with_event(event, @objects[event.name])
    else
      create_object_from_event(event)
    end
  end
end

#setupObject

EventRouter handler



14
15
# File 'lib/teien/base_object/base_object_manager_proxy.rb', line 14

def setup()
end

#sync_object_with_event(event, obj) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/teien/base_object/base_object_manager_proxy.rb', line 54

def sync_object_with_event(event, obj)
  obj.set_position_with_interpolation(event.pos)
  obj.set_linear_velocity(event.linear_vel)
#    obj.set_linear_velocity_with_interpolation(event.linear_vel)
#    obj.set_angular_velocity(event.angular_vel)
  obj.set_angular_velocity_with_interpolation(event.angular_vel)
  obj.set_rotation(event.quat)
  obj.set_acceleration(event.accel)
  obj.attached_objects  = event.attached_objects
end

#update(delta) ⇒ Object

EventRouter handler



18
19
20
21
# File 'lib/teien/base_object/base_object_manager_proxy.rb', line 18

def update(delta)
  @physics.update(delta)
  return !@quit
end