game_machine 0.0.8
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.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +72 -0
- data/Rakefile +38 -0
- data/bin/game_machine +79 -0
- data/config/cluster.conf +65 -0
- data/config/config.example.yml +93 -0
- data/config/game_messages.proto +45 -0
- data/config/messages.proto +339 -0
- data/config/regions.example.yml +9 -0
- data/config/standalone.conf +36 -0
- data/db/do_not_delete +0 -0
- data/game_machine.gemspec +38 -0
- data/games/example/boot.rb +6 -0
- data/games/example/data/game_data.yml +13 -0
- data/games/example/lib/aggressive_npc.rb +176 -0
- data/games/example/lib/authentication_handler.rb +69 -0
- data/games/example/lib/chatbot.rb +61 -0
- data/games/example/lib/combat_controller.rb +145 -0
- data/games/example/lib/example_controller.rb +21 -0
- data/games/example/lib/game.rb +85 -0
- data/games/example/lib/models/attack.rb +9 -0
- data/games/example/lib/models/combat_update.rb +11 -0
- data/games/example/lib/models/player_command.rb +7 -0
- data/games/example/lib/models/user.rb +11 -0
- data/games/example/lib/models/vitals.rb +17 -0
- data/games/example/lib/npc.rb +111 -0
- data/games/example/lib/npc_group.rb +42 -0
- data/games/example/lib/npc_movement.rb +116 -0
- data/games/example/lib/player_manager.rb +58 -0
- data/games/example/lib/player_register.rb +80 -0
- data/games/example/lib/tracking_handler.rb +17 -0
- data/games/example/lib/zone_manager.rb +57 -0
- data/games/preload.rb +8 -0
- data/integration_tests/basic_spec.rb +68 -0
- data/integration_tests/bot_spec.rb +18 -0
- data/integration_tests/chat_spec.rb +45 -0
- data/integration_tests/distributed_spec.rb +34 -0
- data/integration_tests/entity_tracking_spec.rb +48 -0
- data/integration_tests/mono_spec.rb +16 -0
- data/integration_tests/objectdb_spec.rb +55 -0
- data/integration_tests/tcp_client_spec.rb +71 -0
- data/integration_tests/udp_client_spec.rb +61 -0
- data/integration_tests/udp_spec.rb +20 -0
- data/integration_tests/udt_client_spec.rb +23 -0
- data/integration_tests/udt_spec.rb +31 -0
- data/java/.gitignore +1 -0
- data/java/build.gradle +93 -0
- data/java/component.erb +396 -0
- data/java/gradle.properties +6 -0
- data/java/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/java/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/java/gradlew +164 -0
- data/java/gradlew.bat +90 -0
- data/java/local_lib/protostuff-compiler-1.0.7-jarjar.jar +0 -0
- data/java/settings.gradle +2 -0
- data/java/src/main/java/com/game_machine/core/ActorFactory.java +25 -0
- data/java/src/main/java/com/game_machine/core/ActorUtil.java +39 -0
- data/java/src/main/java/com/game_machine/core/CommandProxy.java +9 -0
- data/java/src/main/java/com/game_machine/core/EntitySerializer.java +66 -0
- data/java/src/main/java/com/game_machine/core/EventStreamHandler.java +43 -0
- data/java/src/main/java/com/game_machine/core/GameMachineLoader.java +25 -0
- data/java/src/main/java/com/game_machine/core/Grid.java +195 -0
- data/java/src/main/java/com/game_machine/core/GridValue.java +30 -0
- data/java/src/main/java/com/game_machine/core/IActorFactory.java +7 -0
- data/java/src/main/java/com/game_machine/core/NetMessage.java +28 -0
- data/java/src/main/java/com/game_machine/core/UdpServer.java +97 -0
- data/java/src/main/java/com/game_machine/core/UdpServerHandler.java +90 -0
- data/java/src/main/resources/game_machine.java.stg +738 -0
- data/java/src/main/resources/logback.xml +14 -0
- data/java/src/main/resources/logging.properties +3 -0
- data/java/src/main/resources/protostuff.properties +7 -0
- data/lib/game_machine.rb +85 -0
- data/lib/game_machine/actor.rb +7 -0
- data/lib/game_machine/actor/base.rb +184 -0
- data/lib/game_machine/actor/builder.rb +108 -0
- data/lib/game_machine/actor/development.rb +31 -0
- data/lib/game_machine/actor/factory.rb +35 -0
- data/lib/game_machine/actor/mono_actor.rb +89 -0
- data/lib/game_machine/actor/ref.rb +81 -0
- data/lib/game_machine/actor/reloadable.rb +98 -0
- data/lib/game_machine/actor/system.rb +32 -0
- data/lib/game_machine/akka.rb +98 -0
- data/lib/game_machine/app_config.rb +49 -0
- data/lib/game_machine/application.rb +181 -0
- data/lib/game_machine/auth_handlers/base.rb +21 -0
- data/lib/game_machine/auth_handlers/public.rb +34 -0
- data/lib/game_machine/bot/chat.rb +66 -0
- data/lib/game_machine/bot/client.rb +54 -0
- data/lib/game_machine/client_manager.rb +204 -0
- data/lib/game_machine/clients.rb +4 -0
- data/lib/game_machine/clients/client.rb +45 -0
- data/lib/game_machine/clients/tcp_client.rb +25 -0
- data/lib/game_machine/clients/test_client.rb +151 -0
- data/lib/game_machine/clients/udp_client.rb +25 -0
- data/lib/game_machine/clients/udt_client.rb +34 -0
- data/lib/game_machine/cluster_monitor.rb +115 -0
- data/lib/game_machine/commands.rb +23 -0
- data/lib/game_machine/commands/base.rb +21 -0
- data/lib/game_machine/commands/chat_commands.rb +88 -0
- data/lib/game_machine/commands/datastore_commands.rb +60 -0
- data/lib/game_machine/commands/grid_commands.rb +35 -0
- data/lib/game_machine/commands/message_helper.rb +25 -0
- data/lib/game_machine/commands/misc_commands.rb +29 -0
- data/lib/game_machine/commands/navigation_commands.rb +24 -0
- data/lib/game_machine/commands/player_commands.rb +28 -0
- data/lib/game_machine/commands/proxy.rb +16 -0
- data/lib/game_machine/console.rb +3 -0
- data/lib/game_machine/console/build.rb +74 -0
- data/lib/game_machine/console/install.rb +92 -0
- data/lib/game_machine/console/server.rb +120 -0
- data/lib/game_machine/data_store.rb +52 -0
- data/lib/game_machine/data_stores/couchbase.rb +18 -0
- data/lib/game_machine/data_stores/mapdb.rb +49 -0
- data/lib/game_machine/data_stores/memory.rb +35 -0
- data/lib/game_machine/data_stores/redis.rb +46 -0
- data/lib/game_machine/endpoints.rb +6 -0
- data/lib/game_machine/endpoints/mono_gateway.rb +87 -0
- data/lib/game_machine/endpoints/tcp.rb +51 -0
- data/lib/game_machine/endpoints/tcp_handler.rb +75 -0
- data/lib/game_machine/endpoints/udp.rb +88 -0
- data/lib/game_machine/endpoints/udp_incoming.rb +113 -0
- data/lib/game_machine/endpoints/udp_outgoing.rb +46 -0
- data/lib/game_machine/game_loader.rb +46 -0
- data/lib/game_machine/game_systems.rb +14 -0
- data/lib/game_machine/game_systems/agents/controller.rb +118 -0
- data/lib/game_machine/game_systems/chat.rb +256 -0
- data/lib/game_machine/game_systems/chat_manager.rb +108 -0
- data/lib/game_machine/game_systems/chat_topic.rb +36 -0
- data/lib/game_machine/game_systems/devnull.rb +13 -0
- data/lib/game_machine/game_systems/entity_loader.rb +12 -0
- data/lib/game_machine/game_systems/entity_tracking.rb +133 -0
- data/lib/game_machine/game_systems/local_echo.rb +16 -0
- data/lib/game_machine/game_systems/objectdb_proxy.rb +61 -0
- data/lib/game_machine/game_systems/private_chat.rb +20 -0
- data/lib/game_machine/game_systems/region_manager.rb +91 -0
- data/lib/game_machine/game_systems/region_service.rb +94 -0
- data/lib/game_machine/game_systems/region_settings.rb +13 -0
- data/lib/game_machine/game_systems/remote_echo.rb +14 -0
- data/lib/game_machine/game_systems/stress_test.rb +21 -0
- data/lib/game_machine/grid.rb +60 -0
- data/lib/game_machine/grid_replicator.rb +31 -0
- data/lib/game_machine/handlers/authentication.rb +55 -0
- data/lib/game_machine/handlers/game.rb +63 -0
- data/lib/game_machine/handlers/request.rb +80 -0
- data/lib/game_machine/hashring.rb +48 -0
- data/lib/game_machine/helpers/game_message.rb +159 -0
- data/lib/game_machine/helpers/state_machine.rb +29 -0
- data/lib/game_machine/java_lib.rb +51 -0
- data/lib/game_machine/logger.rb +39 -0
- data/lib/game_machine/message_buffer.rb +58 -0
- data/lib/game_machine/message_queue.rb +63 -0
- data/lib/game_machine/model.rb +125 -0
- data/lib/game_machine/models.rb +3 -0
- data/lib/game_machine/models/player_status_update.rb +8 -0
- data/lib/game_machine/models/region.rb +9 -0
- data/lib/game_machine/mono_server.rb +20 -0
- data/lib/game_machine/navigation.rb +4 -0
- data/lib/game_machine/navigation/detour.rb +20 -0
- data/lib/game_machine/navigation/detour_navmesh.rb +53 -0
- data/lib/game_machine/navigation/detour_path.rb +53 -0
- data/lib/game_machine/navigation/path.rb +31 -0
- data/lib/game_machine/object_db.rb +67 -0
- data/lib/game_machine/protobuf.rb +6 -0
- data/lib/game_machine/protobuf/game_messages.rb +24 -0
- data/lib/game_machine/protobuf/generate.rb +113 -0
- data/lib/game_machine/protobuf_extensions/entity_helper.rb +11 -0
- data/lib/game_machine/reloadable_monitor.rb +26 -0
- data/lib/game_machine/restart_watcher.rb +17 -0
- data/lib/game_machine/ruby_extensions/nilclass.rb +10 -0
- data/lib/game_machine/ruby_extensions/string.rb +17 -0
- data/lib/game_machine/scheduler.rb +23 -0
- data/lib/game_machine/securerandom.rb +6 -0
- data/lib/game_machine/settings.rb +11 -0
- data/lib/game_machine/system_monitor.rb +19 -0
- data/lib/game_machine/system_stats.rb +24 -0
- data/lib/game_machine/uniqueid.rb +23 -0
- data/lib/game_machine/vector.rb +95 -0
- data/lib/game_machine/version.rb +3 -0
- data/lib/game_machine/write_behind_cache.rb +164 -0
- data/mono/bin/csharp/common.xslt +109 -0
- data/mono/bin/csharp/csharp.xslt +628 -0
- data/mono/bin/csharp/descriptor.proto +533 -0
- data/mono/bin/csharp/protobuf-net.dll +0 -0
- data/mono/bin/csharp/protobuf-net.pdb +0 -0
- data/mono/bin/csharp/protobuf-net.xml +2879 -0
- data/mono/bin/csharp/protogen.exe.config +3 -0
- data/mono/bin/csharp/protogen.pdb +0 -0
- data/mono/bin/csharp/protogen_csharp.exe +0 -0
- data/mono/bin/csharp/vb.xslt +745 -0
- data/mono/bin/csharp/xml.xslt +26 -0
- data/mono/server/Makefile +6 -0
- data/mono/server/NLog.config +12 -0
- data/mono/server/NLog.dll +0 -0
- data/mono/server/actor.cs +37 -0
- data/mono/server/build.bat +3 -0
- data/mono/server/cscompmgd.dll +0 -0
- data/mono/server/iactor.cs +11 -0
- data/mono/server/message_router.cs +67 -0
- data/mono/server/message_util.cs +29 -0
- data/mono/server/messages.cs +1888 -0
- data/mono/server/protobuf-net.dll +0 -0
- data/mono/server/proxy_client.cs +73 -0
- data/mono/server/proxy_server.cs +30 -0
- data/mono/server/test_actor.cs +33 -0
- data/pathfinding/bin/premake4 +0 -0
- data/pathfinding/include/mesh_loader.h +28 -0
- data/pathfinding/include/pathfind.h +167 -0
- data/pathfinding/main.cpp +39 -0
- data/pathfinding/mesh_loader.cpp +108 -0
- data/pathfinding/pathfind.cpp +174 -0
- data/pathfinding/pathfinder.cs +66 -0
- data/pathfinding/premake4.lua +109 -0
- data/script/server.sh +109 -0
- data/script/watch.sh +11 -0
- data/spec/actor/actor_spec.rb +73 -0
- data/spec/actor/builder_spec.rb +56 -0
- data/spec/actor/ref_spec.rb +83 -0
- data/spec/application_spec.rb +7 -0
- data/spec/client_manager_spec.rb +171 -0
- data/spec/commands/chat_commands_spec.rb +38 -0
- data/spec/commands/datastore_commands_spec.rb +91 -0
- data/spec/commands/grid_commands_spec.rb +37 -0
- data/spec/commands/navigation_commands_spec.rb +51 -0
- data/spec/commands/player_commands_spec.rb +48 -0
- data/spec/commands_spec.rb +38 -0
- data/spec/data_stores/mapdb_spec.rb +46 -0
- data/spec/data_stores/redis_spec.rb +44 -0
- data/spec/game_systems/agents/controller_spec.rb +84 -0
- data/spec/game_systems/agents/test_agent.rb +10 -0
- data/spec/game_systems/agents/test_agent_config.rb +29 -0
- data/spec/game_systems/chat_manager_spec.rb +66 -0
- data/spec/game_systems/chat_spec.rb +187 -0
- data/spec/game_systems/entity_tracking_spec.rb +64 -0
- data/spec/game_systems/region_manager_spec.rb +138 -0
- data/spec/grid_spec.rb +37 -0
- data/spec/handlers/authentication_spec.rb +36 -0
- data/spec/handlers/game_spec.rb +49 -0
- data/spec/handlers/request_spec.rb +65 -0
- data/spec/hashring_spec.rb +59 -0
- data/spec/integration_helper.rb +120 -0
- data/spec/java_grid_spec.rb +89 -0
- data/spec/message_buffer_spec.rb +67 -0
- data/spec/message_expectations.rb +47 -0
- data/spec/message_queue_spec.rb +23 -0
- data/spec/misc_spec.rb +71 -0
- data/spec/model_spec.rb +103 -0
- data/spec/mono_spec.rb +36 -0
- data/spec/mono_test.rb +18 -0
- data/spec/navigation/detour_navmesh_spec.rb +34 -0
- data/spec/navigation/detour_path_spec.rb +25 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/udp_server_spec.rb +10 -0
- data/spec/write_behind_cache_spec.rb +109 -0
- data/web/app.rb +131 -0
- data/web/config/trinidad.yml +4 -0
- data/web/controllers/auth_controller.rb +19 -0
- data/web/controllers/base_controller.rb +16 -0
- data/web/controllers/index_controller.rb +7 -0
- data/web/controllers/log_controller.rb +47 -0
- data/web/controllers/messages_controller.rb +59 -0
- data/web/controllers/player_register_controller.rb +15 -0
- data/web/log/development.log +1339 -0
- data/web/tmp/restart.txt +0 -0
- data/web/views/game_messages.haml +45 -0
- data/web/views/index.haml +6 -0
- data/web/views/layout.haml +41 -0
- data/web/views/logs.haml +32 -0
- data/web/views/player_register.haml +22 -0
- data/web/views/player_registered.haml +2 -0
- data/web/views/register_layout.haml +22 -0
- data/web/views/restart.haml +35 -0
- metadata +576 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
<configuration>
|
2
|
+
|
3
|
+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
4
|
+
<!-- encoders are assigned the type
|
5
|
+
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
|
6
|
+
<encoder>
|
7
|
+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
8
|
+
</encoder>
|
9
|
+
</appender>
|
10
|
+
|
11
|
+
<root level="info">
|
12
|
+
<appender-ref ref="STDOUT" />
|
13
|
+
</root>
|
14
|
+
</configuration>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
modules = messages
|
2
|
+
messages.source = src/main/resources/messages.proto
|
3
|
+
#java_bean, gwt_overlay, java_v2protoc_schema
|
4
|
+
messages.output = src/main/resources/game_machine.java.stg
|
5
|
+
messages.outputDir = src/main/java
|
6
|
+
#messages.options = some_key,key:value,another_key
|
7
|
+
messages.options = generate_pipe_schema,generate_helper_methods,generate_field_map
|
data/lib/game_machine.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
require_relative 'game_machine/ruby_extensions/nilclass'
|
5
|
+
require_relative 'game_machine/ruby_extensions/string'
|
6
|
+
require_relative 'game_machine/securerandom'
|
7
|
+
|
8
|
+
module GameMachine
|
9
|
+
def self.env
|
10
|
+
ENV.fetch('GAME_ENV')
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.app_root
|
14
|
+
ENV.fetch('APP_ROOT')
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.java_root
|
18
|
+
ENV.fetch('JAVA_ROOT')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
require 'java'
|
22
|
+
|
23
|
+
jars = Dir[File.join(GameMachine.app_root, 'java/lib', '*.jar')]
|
24
|
+
jars.each {|jar| require jar}
|
25
|
+
|
26
|
+
#java_import 'com.game_machine.core.net.client.UdtClient'
|
27
|
+
#java_import 'com.game_machine.core.net.client.UdtClientHandler'
|
28
|
+
|
29
|
+
require_relative 'game_machine/java_lib'
|
30
|
+
|
31
|
+
require_relative 'game_machine/protobuf'
|
32
|
+
require_relative 'game_machine/version'
|
33
|
+
require_relative 'game_machine/grid'
|
34
|
+
require_relative 'game_machine/game_loader'
|
35
|
+
require_relative 'game_machine/message_buffer'
|
36
|
+
require_relative 'game_machine/vector'
|
37
|
+
require_relative 'game_machine/logger'
|
38
|
+
require_relative 'game_machine/app_config'
|
39
|
+
require_relative 'game_machine/helpers/state_machine'
|
40
|
+
require_relative 'game_machine/actor'
|
41
|
+
require_relative 'game_machine/commands'
|
42
|
+
require_relative 'game_machine/model'
|
43
|
+
require_relative 'game_machine/models'
|
44
|
+
require_relative 'game_machine/handlers/authentication'
|
45
|
+
require_relative 'game_machine/hashring'
|
46
|
+
require_relative 'game_machine/application'
|
47
|
+
require_relative 'game_machine/game_systems'
|
48
|
+
require_relative 'game_machine/handlers/request'
|
49
|
+
require_relative 'game_machine/handlers/game'
|
50
|
+
require_relative 'game_machine/actor/builder'
|
51
|
+
require_relative 'game_machine/message_queue'
|
52
|
+
require_relative 'game_machine/object_db'
|
53
|
+
require_relative 'game_machine/write_behind_cache'
|
54
|
+
require_relative 'game_machine/data_store'
|
55
|
+
require_relative 'game_machine/auth_handlers/base'
|
56
|
+
require_relative 'game_machine/auth_handlers/public'
|
57
|
+
require_relative 'game_machine/system_monitor'
|
58
|
+
require_relative 'game_machine/cluster_monitor'
|
59
|
+
require_relative 'game_machine/system_stats'
|
60
|
+
require_relative 'game_machine/reloadable_monitor'
|
61
|
+
require_relative 'game_machine/client_manager'
|
62
|
+
require_relative 'game_machine/scheduler'
|
63
|
+
require_relative 'game_machine/endpoints'
|
64
|
+
require_relative 'game_machine/protobuf_extensions/entity_helper'
|
65
|
+
require_relative 'game_machine/helpers/game_message'
|
66
|
+
require_relative 'game_machine/grid_replicator'
|
67
|
+
require_relative 'game_machine/akka'
|
68
|
+
require_relative 'game_machine/clients'
|
69
|
+
require_relative 'game_machine/mono_server'
|
70
|
+
require_relative 'game_machine/restart_watcher'
|
71
|
+
require_relative 'game_machine/uniqueid'
|
72
|
+
|
73
|
+
if Config::CONFIG['target_os'] == 'linux'
|
74
|
+
require_relative 'game_machine/navigation'
|
75
|
+
else
|
76
|
+
GameMachine.logger.info "Pathfinding disabled (windows support not yet available)"
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
java.util.concurrent.TimeUnit::MILLISECONDS
|
81
|
+
java.util.concurrent.TimeUnit::SECONDS
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
@@ -0,0 +1,184 @@
|
|
1
|
+
module GameMachine
|
2
|
+
module Actor
|
3
|
+
|
4
|
+
class DuplicateHashringError < StandardError;end
|
5
|
+
class MissingHashringError < StandardError;end
|
6
|
+
|
7
|
+
# @abstract All game actors inherit fromm this class
|
8
|
+
class Base < JavaLib::UntypedActor
|
9
|
+
|
10
|
+
ON_RECEIVE_HOOKS = {}
|
11
|
+
|
12
|
+
@@player_controller = nil
|
13
|
+
|
14
|
+
class << self
|
15
|
+
alias_method :apply, :new
|
16
|
+
alias_method :create, :new
|
17
|
+
|
18
|
+
# Sets the system wide player controller class.
|
19
|
+
# When a player logs in, a player controller with this class
|
20
|
+
# will be created. The system notifies the player controller when
|
21
|
+
# various player lifecycle events happen.
|
22
|
+
#
|
23
|
+
# This should only be called on subclasses, never on the Actor base
|
24
|
+
# class
|
25
|
+
def set_player_controller
|
26
|
+
@@player_controller = self
|
27
|
+
GameMachine.logger.info("Player controller set to #{self.name}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def player_controller
|
31
|
+
@@player_controller
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def aspects
|
36
|
+
@aspects ||= []
|
37
|
+
end
|
38
|
+
|
39
|
+
# Sets the message types that this actor knows about. Can be called
|
40
|
+
# multiple times. If passed an array of more then one message type,
|
41
|
+
# both message types will need to be present on an entity before the
|
42
|
+
# system will route the entity to the actor.
|
43
|
+
#
|
44
|
+
# messages will be routed to actors based on the aspects it has
|
45
|
+
def aspect(new_aspects)
|
46
|
+
aspects << new_aspects
|
47
|
+
unless Application.registered.include?(self)
|
48
|
+
Application.register(self)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def reset_hashrings
|
53
|
+
@@hashrings = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def hashrings
|
57
|
+
@@hashrings ||= java.util.concurrent.ConcurrentHashMap.new
|
58
|
+
end
|
59
|
+
|
60
|
+
def hashring(name)
|
61
|
+
hashrings.fetch(name,nil)
|
62
|
+
end
|
63
|
+
|
64
|
+
def add_hashring(name,hashring)
|
65
|
+
if hashring(name)
|
66
|
+
raise DuplicateHashringError, "name=#{name}"
|
67
|
+
end
|
68
|
+
hashrings[name] = hashring
|
69
|
+
end
|
70
|
+
|
71
|
+
# Find a local actor by name
|
72
|
+
# @return [Actor::Ref]
|
73
|
+
def find(name=self.name)
|
74
|
+
Actor::Ref.new(local_path(name),name)
|
75
|
+
end
|
76
|
+
|
77
|
+
# find using fully qualified address, ie akka://cluster@ ...
|
78
|
+
def find_by_address(address,name=self.name)
|
79
|
+
path = "#{address}#{local_path(name)}"
|
80
|
+
Actor::Ref.new(path,name)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Find a remote actor by name
|
84
|
+
# @return [Actor::Ref]
|
85
|
+
def find_remote(server,name=self.name)
|
86
|
+
Actor::Ref.new(remote_path(server,name),name)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Returns a local actor ref from the distributed ring of actors based
|
90
|
+
# on a consistent hashing of the id.
|
91
|
+
# @return [Actor::Ref]
|
92
|
+
def find_distributed_local(id,name=self.name)
|
93
|
+
ensure_hashring(name)
|
94
|
+
Actor::Ref.new(local_distributed_path(id, name),name)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns an actor ref from the distributed ring of actors based
|
98
|
+
# on a consistent hashing of the id. The actor returned can be from
|
99
|
+
# any server in the cluster
|
100
|
+
# @return [Actor::Ref]
|
101
|
+
def find_distributed(id,name=self.name)
|
102
|
+
ensure_hashring(name)
|
103
|
+
Actor::Ref.new(distributed_path(id, name),name)
|
104
|
+
end
|
105
|
+
|
106
|
+
def local_path(name)
|
107
|
+
"/user/#{name}"
|
108
|
+
end
|
109
|
+
|
110
|
+
def model_filter(message)
|
111
|
+
if message.is_a?(MessageLib::Entity) && message.has_json_entity
|
112
|
+
# Don't convert outgoing messages
|
113
|
+
if message.send_to_player
|
114
|
+
message
|
115
|
+
else
|
116
|
+
message = Model.from_entity(message)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
message
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def ensure_hashring(name)
|
125
|
+
unless hashring(name)
|
126
|
+
raise MissingHashringError
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def remote_path(server,name)
|
131
|
+
"#{Akka.address_for(server)}/user/#{name}"
|
132
|
+
end
|
133
|
+
|
134
|
+
def local_distributed_path(id,name)
|
135
|
+
bucket = hashring(name).bucket_for(id)
|
136
|
+
"/user/#{bucket}"
|
137
|
+
end
|
138
|
+
|
139
|
+
def distributed_path(id,name)
|
140
|
+
server = Akka.instance.hashring.bucket_for(id)
|
141
|
+
bucket = hashring(name).bucket_for(id)
|
142
|
+
"#{server}/user/#{bucket}"
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
# This indirection is primarily because Akka's test actors
|
148
|
+
# hide onReceive, so in tests we need to call receive_message
|
149
|
+
def receive_message(message)
|
150
|
+
message = self.class.model_filter(message)
|
151
|
+
on_receive(message)
|
152
|
+
end
|
153
|
+
|
154
|
+
# So we can hook into message passing for our own filters and the like
|
155
|
+
def onReceive(message)
|
156
|
+
receive_message(message)
|
157
|
+
end
|
158
|
+
|
159
|
+
def on_receive(message)
|
160
|
+
unhandled(message)
|
161
|
+
end
|
162
|
+
|
163
|
+
def sender
|
164
|
+
Actor::Ref.new(get_sender)
|
165
|
+
end
|
166
|
+
|
167
|
+
def schedule_message(message,update_interval,unit=:ms)
|
168
|
+
if unit == :seconds
|
169
|
+
unit = java.util.concurrent.TimeUnit::SECONDS
|
170
|
+
elsif unit == :ms
|
171
|
+
unit = java.util.concurrent.TimeUnit::MILLISECONDS
|
172
|
+
else
|
173
|
+
GameMachine.logger.error "Invalid unit argument for schedule_message (#{unit})"
|
174
|
+
return
|
175
|
+
end
|
176
|
+
|
177
|
+
duration = GameMachine::JavaLib::Duration.create(update_interval, unit)
|
178
|
+
scheduler = get_context.system.scheduler
|
179
|
+
dispatcher = get_context.system.dispatcher
|
180
|
+
scheduler.schedule(duration, duration, get_self, message, dispatcher, nil)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'jruby/core_ext'
|
2
|
+
module GameMachine
|
3
|
+
module Actor
|
4
|
+
|
5
|
+
class Builder
|
6
|
+
|
7
|
+
attr_reader :name
|
8
|
+
|
9
|
+
# Creates an actor builder instance. First argument is the actor class
|
10
|
+
# remaining arguments are optional and will be passed to post_init
|
11
|
+
# @param args
|
12
|
+
# @return self
|
13
|
+
def initialize(*args)
|
14
|
+
@klass = args.shift
|
15
|
+
@name = @klass.name
|
16
|
+
@create_hashring = false
|
17
|
+
@hashring_size = 0
|
18
|
+
factory = Actor::Factory.new(@klass,args)
|
19
|
+
@props = JavaLib::Props.create(
|
20
|
+
JavaLib::ActorFactory.java_class,factory,@klass.name)
|
21
|
+
@actor_system = Akka.instance.actor_system
|
22
|
+
end
|
23
|
+
|
24
|
+
# Special case. Must be created like so:
|
25
|
+
# Actor::Builder.new(SingletonActorClass).singleton
|
26
|
+
# NO OTHER OPTIONS. It will fail anyways if you do
|
27
|
+
def singleton
|
28
|
+
@actor_system.actor_of(
|
29
|
+
JavaLib::ClusterSingletonManager.defaultProps(
|
30
|
+
@props,@name,JavaLib::PoisonPill.get_instance,nil),'singleton')
|
31
|
+
@actor_system.actor_of(
|
32
|
+
JavaLib::ClusterSingletonProxy.defaultProps(
|
33
|
+
"user/singleton/#{@name}", nil), @name);
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_ref
|
37
|
+
JavaLib::TestActorRef.create(@actor_system,@props,@name)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Sets the parent actor
|
41
|
+
# @param parent
|
42
|
+
# @return self
|
43
|
+
def with_parent(parent)
|
44
|
+
@actor_system = parent
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
# Sets the actor's name
|
49
|
+
# @param name
|
50
|
+
# @return self
|
51
|
+
def with_name(name)
|
52
|
+
@name = name
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def with_dispatcher(name)
|
57
|
+
@props = @props.with_dispatcher(name)
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
# Run the actor under a router
|
62
|
+
# @param router_class [Class] num_router [Integer]
|
63
|
+
# @return self
|
64
|
+
def with_router(router_class,num_routers)
|
65
|
+
@props = @props.with_router(
|
66
|
+
router_class.new(num_routers)
|
67
|
+
)
|
68
|
+
self
|
69
|
+
end
|
70
|
+
|
71
|
+
# Creates this router as a distributed router. It will create a group
|
72
|
+
# of actors distributed using consistent hashing. Suggest a hashring size
|
73
|
+
# of at least 40 up to 160.
|
74
|
+
# @param hashring_size [Integer]
|
75
|
+
# @return self
|
76
|
+
def distributed(hashring_size)
|
77
|
+
@create_hashring = true
|
78
|
+
@hashring_size = hashring_size
|
79
|
+
self
|
80
|
+
end
|
81
|
+
|
82
|
+
# Start the actor(s). If the actor is distributed returns the entire
|
83
|
+
# Array of actor refs in the hash ring, otherwise a single actor ref
|
84
|
+
# @return actor ref
|
85
|
+
def start
|
86
|
+
GameMachine.logger.debug "Game actor #{@name} starting"
|
87
|
+
if @create_hashring
|
88
|
+
hashring = create_hashring(@hashring_size)
|
89
|
+
hashring.buckets.map do |bucket_name|
|
90
|
+
@actor_system.actor_of(@props, bucket_name)
|
91
|
+
end
|
92
|
+
else
|
93
|
+
@actor_system.actor_of(@props, @name)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def create_hashring(bucket_count)
|
101
|
+
hashring = Hashring.create_actor_ring(@name,bucket_count)
|
102
|
+
@klass.add_hashring(@name,hashring)
|
103
|
+
hashring
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module GameMachine
|
2
|
+
module Actor
|
3
|
+
module Development
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
Reloadable.register(base.name)
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def reload_on_change?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def kill_self(reason)
|
18
|
+
raise "Killing #{self}: #{reason}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def onReceive(message)
|
22
|
+
message = Base.model_filter(message)
|
23
|
+
if message == 'reload_because_changed'
|
24
|
+
kill_self("Actor code change")
|
25
|
+
else
|
26
|
+
on_receive(message)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|