Class: GameMachine::GameSystems::EntityTracking

Inherits:
Actor::Base
  • Object
show all
Includes:
Commands
Defined in:
lib/game_machine/game_systems/entity_tracking.rb

Overview

Note:

Handles player location tracking and neighbor requests. The client must explicitly send a TrackEntit component to the server to be tracked, it doesn’t happen automatically.

Constant Summary collapse

EXTRA =
java.util.concurrent.ConcurrentHashMap.new

Constants inherited from Actor::Base

Actor::Base::ON_RECEIVE_HOOKS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commands

#commands

Methods inherited from Actor::Base

aspect, aspects, find, find_by_address, find_distributed, find_distributed_local, find_remote, hashring, local_path, model_filter, #onReceive, player_controller, #receive_message, #schedule_message, #sender, set_player_controller

Instance Attribute Details

#aoe_gridObject (readonly)

Returns the value of attribute aoe_grid.



18
19
20
# File 'lib/game_machine/game_systems/entity_tracking.rb', line 18

def aoe_grid
  @aoe_grid
end

#extra_paramsObject (readonly)

Returns the value of attribute extra_params.



18
19
20
# File 'lib/game_machine/game_systems/entity_tracking.rb', line 18

def extra_params
  @extra_params
end

#gridObject (readonly)

Returns the value of attribute grid.



18
19
20
# File 'lib/game_machine/game_systems/entity_tracking.rb', line 18

def grid
  @grid
end

Instance Method Details

#on_receive(message) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/game_machine/game_systems/entity_tracking.rb', line 30

def on_receive(message)
  if message.is_a?(MessageLib::Entity)
    if message.get_neighbors
      send_neighbors(message)
    end

    # If a tracking handler is defined, it must return true to have
    # the player location saved
    if message.track_entity
      #GameMachine.logger.info "#{message.player.id} tracked"
      if @tracking_handler && message.entity_type == 'player'
        if @tracking_handler.verify(message)
          set_entity_location(message)
        end
      else
        set_entity_location(message)
      end
    end
  elsif message.is_a?(MessageLib::ClientManagerEvent)
    if message.event == 'disconnected'
      @grid.remove(message.player_id)
      @aoe_grid.remove(message.player_id)
      EXTRA.delete(message.player_id)
      GameMachine.logger.info "#{message.player_id} removed from grid"
    end
  else
    unhandled(message)
  end
end

#post_initObject



20
21
22
23
24
25
26
27
28
# File 'lib/game_machine/game_systems/entity_tracking.rb', line 20

def post_init
  @entity_updates = []
  @grid = Grid.find_or_create('default')
  @aoe_grid = Grid.find_or_create('aoe')
  @paths = {}
  @width = grid.get_width
  @cell_count = grid.get_cell_count
  commands.misc.client_manager_register(self.class.name)
end