Class: GameMachine::Actor::Base Abstract
- Inherits:
-
JavaLib::GameActor
- Object
- JavaLib::GameActor
- GameMachine::Actor::Base
- Defined in:
- lib/game_machine/actor/base.rb
Overview
All game actors inherit fromm this class
Direct Known Subclasses
GameActor, ClientManager, Clients::TestClient, CloudUpdater, ClusterMonitor, Commands::Proxy, DefaultHandlers::ZoneManager, Endpoints::UdpIncoming, Endpoints::UdpOutgoing, GameSystems::Agents::Controller, GameSystems::Chat, GameSystems::ChatManager, GameSystems::ChatTopic, GameSystems::Devnull, GameSystems::EntityLoader, GameSystems::EntityTracking, GameSystems::JsonModelPersistence, GameSystems::LocalEcho, GameSystems::ObjectDbProxy, GameSystems::PrivateChat, GameSystems::RegionManager, GameSystems::RegionService, GameSystems::RemoteEcho, GameSystems::StressTest, GameSystems::TeamManager, GridReplicator, Handlers::Game, Handlers::Request, MessageQueue, ObjectDb, ReloadableMonitor, RestartWatcher, Scheduler, SystemMonitor, SystemStats, WriteBehindCache
Constant Summary collapse
- ON_RECEIVE_HOOKS =
{}
- @@player_controller =
nil
Class Method Summary collapse
-
.aspect(new_aspects) ⇒ Object
Sets the message types that this actor knows about.
- .aspects ⇒ Object
-
.find(name = self.name) ⇒ Actor::Ref
Find a local actor by name.
-
.find_by_address(address, name = self.name) ⇒ Object
find using fully qualified address, ie akka://cluster@ …
-
.find_distributed(id, name = self.name) ⇒ Actor::Ref
Returns an actor ref from the distributed ring of actors based on a consistent hashing of the id.
-
.find_distributed_local(id, name = self.name) ⇒ Actor::Ref
Returns a local actor ref from the distributed ring of actors based on a consistent hashing of the id.
-
.find_remote(server, name = self.name) ⇒ Actor::Ref
Find a remote actor by name.
- .hashring(name) ⇒ Object
- .local_path(name) ⇒ Object
- .model_filter(message) ⇒ Object
- .player_controller ⇒ Object
-
.set_player_controller ⇒ Object
Sets the system wide player controller class.
Instance Method Summary collapse
- #on_receive(message) ⇒ Object
-
#onReceive(message) ⇒ Object
So we can hook into message passing for our own filters and the like.
-
#receive_message(message) ⇒ Object
This indirection is primarily because Akka’s test actors hide onReceive, so in tests we need to call receive_message.
- #schedule_message(message, update_interval, unit = :ms) ⇒ Object
- #sender ⇒ Object
Class Method Details
.aspect(new_aspects) ⇒ Object
Sets the message types that this actor knows about. Can be called multiple times. If passed an array of more then one message type, both message types will need to be present on an entity before the system will route the entity to the actor.
messages will be routed to actors based on the aspects it has
45 46 47 48 49 50 |
# File 'lib/game_machine/actor/base.rb', line 45 def aspect(new_aspects) aspects << new_aspects unless Application.registered.include?(self) Application.register(self) end end |
.aspects ⇒ Object
35 36 37 |
# File 'lib/game_machine/actor/base.rb', line 35 def aspects @aspects ||= [] end |
.find(name = self.name) ⇒ Actor::Ref
Find a local actor by name
58 59 60 |
# File 'lib/game_machine/actor/base.rb', line 58 def find(name=self.name) Actor::Ref.new(local_path(name),name) end |
.find_by_address(address, name = self.name) ⇒ Object
find using fully qualified address, ie akka://cluster@ …
63 64 65 66 |
# File 'lib/game_machine/actor/base.rb', line 63 def find_by_address(address,name=self.name) path = "#{address}#{local_path(name)}" Actor::Ref.new(path,name) end |
.find_distributed(id, name = self.name) ⇒ Actor::Ref
Returns an actor ref from the distributed ring of actors based on a consistent hashing of the id. The actor returned can be from any server in the cluster
85 86 87 |
# File 'lib/game_machine/actor/base.rb', line 85 def find_distributed(id,name=self.name) Actor::Ref.new(distributed_path(id, name),name) end |
.find_distributed_local(id, name = self.name) ⇒ Actor::Ref
Returns a local actor ref from the distributed ring of actors based on a consistent hashing of the id.
77 78 79 |
# File 'lib/game_machine/actor/base.rb', line 77 def find_distributed_local(id,name=self.name) Actor::Ref.new(local_distributed_path(id, name),name) end |
.find_remote(server, name = self.name) ⇒ Actor::Ref
Find a remote actor by name
70 71 72 |
# File 'lib/game_machine/actor/base.rb', line 70 def find_remote(server,name=self.name) Actor::Ref.new(remote_path(server,name),name) end |
.hashring(name) ⇒ Object
52 53 54 |
# File 'lib/game_machine/actor/base.rb', line 52 def hashring(name) JavaLib::Hashring.get_hashring(name) end |
.local_path(name) ⇒ Object
89 90 91 |
# File 'lib/game_machine/actor/base.rb', line 89 def local_path(name) "/user/#{name}" end |
.model_filter(message) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/game_machine/actor/base.rb', line 93 def model_filter() if .is_a?(MessageLib::Entity) && .has_json_entity # Don't convert outgoing messages if .send_to_player else model = Model.from_entity() if .has_player model.player_id = .player.id end return model end end end |
.player_controller ⇒ Object
30 31 32 |
# File 'lib/game_machine/actor/base.rb', line 30 def player_controller @@player_controller end |
.set_player_controller ⇒ Object
Sets the system wide player controller class. When a player logs in, a player controller with this class will be created. The system notifies the player controller when various player lifecycle events happen.
This should only be called on subclasses, never on the Actor base class
25 26 27 28 |
# File 'lib/game_machine/actor/base.rb', line 25 def set_player_controller @@player_controller = self GameMachine.logger.info("Player controller set to #{self.name}") end |
Instance Method Details
#on_receive(message) ⇒ Object
140 141 142 |
# File 'lib/game_machine/actor/base.rb', line 140 def on_receive() unhandled() end |
#onReceive(message) ⇒ Object
So we can hook into message passing for our own filters and the like
136 137 138 |
# File 'lib/game_machine/actor/base.rb', line 136 def onReceive() () end |
#receive_message(message) ⇒ Object
This indirection is primarily because Akka’s test actors hide onReceive, so in tests we need to call receive_message
130 131 132 133 |
# File 'lib/game_machine/actor/base.rb', line 130 def () = self.class.model_filter() on_receive() end |
#schedule_message(message, update_interval, unit = :ms) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/game_machine/actor/base.rb', line 148 def (,update_interval,unit=:ms) if unit == :seconds unit = java.util.concurrent.TimeUnit::SECONDS elsif unit == :ms unit = java.util.concurrent.TimeUnit::MILLISECONDS else GameMachine.logger.error "Invalid unit argument for schedule_message (#{unit})" return end duration = GameMachine::JavaLib::Duration.create(update_interval, unit) scheduler = get_context.system.scheduler dispatcher = get_context.system.dispatcher scheduler.schedule(duration, duration, get_self, , dispatcher, nil) end |
#sender ⇒ Object
144 145 146 |
# File 'lib/game_machine/actor/base.rb', line 144 def sender Actor::Ref.new(get_sender) end |