game_machine 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- 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,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module GameMachine
|
3
|
+
|
4
|
+
describe MessageBuffer do
|
5
|
+
|
6
|
+
let(:message) do
|
7
|
+
MessageLib::ClientMessage.new.add_entity(
|
8
|
+
MessageLib::Entity.new.set_id('0')
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:message_size) {bytes.length - 1}
|
13
|
+
let(:bytes) {message.to_prefixed_byte_array }
|
14
|
+
let(:bytes_without_prefix) {message.to_byte_array }
|
15
|
+
|
16
|
+
subject {MessageBuffer.new}
|
17
|
+
|
18
|
+
describe "#add_bytes" do
|
19
|
+
it "adds bytes to buffer" do
|
20
|
+
puts bytes.length
|
21
|
+
subject.add_bytes(bytes)
|
22
|
+
expect(subject.bytes.length).to eql(bytes.length)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "appends to the buffer when called multiple times" do
|
26
|
+
subject.add_bytes(bytes)
|
27
|
+
subject.add_bytes(bytes)
|
28
|
+
subject.add_bytes(bytes)
|
29
|
+
expect(subject.bytes.length).to eql(3 * bytes.length)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#messages" do
|
34
|
+
it "returns a message" do
|
35
|
+
subject.add_bytes(bytes)
|
36
|
+
expect(subject.messages.size).to eql(1)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns multiple messages" do
|
40
|
+
subject.add_bytes(bytes)
|
41
|
+
subject.add_bytes(bytes)
|
42
|
+
subject.add_bytes(bytes)
|
43
|
+
expect(subject.messages.size).to eql(3)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "correctly handles partial messages" do
|
47
|
+
subject.add_bytes(bytes)
|
48
|
+
part = Java::byte[2].new
|
49
|
+
part[0] = bytes[0]
|
50
|
+
part[1] = bytes[1]
|
51
|
+
subject.add_bytes(part)
|
52
|
+
expect(subject.messages.size).to eql(1)
|
53
|
+
expect(subject.bytes.length).to eq(1)
|
54
|
+
expect(subject.next_message_length).to eql(5)
|
55
|
+
part = Java::byte[4].new
|
56
|
+
part[0] = bytes[2]
|
57
|
+
part[1] = bytes[3]
|
58
|
+
part[2] = bytes[4]
|
59
|
+
part[3] = bytes[5]
|
60
|
+
subject.add_bytes(part)
|
61
|
+
expect(subject.messages.size).to eql(1)
|
62
|
+
expect(subject.bytes).to be_nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
module ClassMethods
|
3
|
+
|
4
|
+
require "rspec/mocks/standalone"
|
5
|
+
require "rspec/expectations"
|
6
|
+
|
7
|
+
include RSpec::Matchers
|
8
|
+
|
9
|
+
def expected
|
10
|
+
@expected ||= {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def actual
|
14
|
+
@actual ||= {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def should_receive_message(message,name=self.name, &blk)
|
18
|
+
blk.call
|
19
|
+
called = false
|
20
|
+
10.times do
|
21
|
+
if actual.has_key?(name)
|
22
|
+
called = true
|
23
|
+
break
|
24
|
+
end
|
25
|
+
sleep 0.020
|
26
|
+
end
|
27
|
+
expect(actual[name]).to eq(message)
|
28
|
+
actual.delete(name)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
module InstanceMethods
|
34
|
+
|
35
|
+
def onReceive(message)
|
36
|
+
on_receive(message)
|
37
|
+
self.class.actual[get_self.path.name] = message
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
result = []
|
42
|
+
ObjectSpace.each_object(::Class) {|klass| result << klass if klass < GameMachine::Actor::Base }
|
43
|
+
result.each do |klass|
|
44
|
+
klass.send(:include, InstanceMethods)
|
45
|
+
klass.send(:extend, ClassMethods)
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module GameMachine
|
4
|
+
describe MessageQueue do
|
5
|
+
|
6
|
+
let(:topic) {'test topic'}
|
7
|
+
let(:message) {'test message'}
|
8
|
+
|
9
|
+
let(:subscribe) do
|
10
|
+
MessageLib::Subscribe.new.set_topic(topic)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:unsubscribe) do
|
14
|
+
MessageLib::Unsubscribe.new.set_topic(topic)
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:publish) do
|
18
|
+
publish = MessageLib::Publish.new
|
19
|
+
publish.set_topic(topic).set_message(message)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/spec/misc_spec.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'jruby/core_ext'
|
3
|
+
module GameMachine
|
4
|
+
describe "misc" do
|
5
|
+
let(:entity) do
|
6
|
+
entity = MessageLib::Entity.new
|
7
|
+
entity.id = '1'
|
8
|
+
player = MessageLib::Player.new
|
9
|
+
player.authtoken = 'authorized'
|
10
|
+
player.id = '2'
|
11
|
+
entity.player = player
|
12
|
+
entity
|
13
|
+
end
|
14
|
+
|
15
|
+
it "singleton manager" do
|
16
|
+
ref = Akka.instance.actor_system.actor_selection('/user/region_manager_proxy')
|
17
|
+
ref.tell('HELLO',nil)
|
18
|
+
sleep 1
|
19
|
+
end
|
20
|
+
|
21
|
+
xit "vector3" do
|
22
|
+
vector = MessageLib::Vector3.new.set_x(0.0)
|
23
|
+
bytes = vector.to_byte_array
|
24
|
+
File.open('/tmp/bytes.txt','wb') {|f| f.write(bytes)}
|
25
|
+
vector = MessageLib::Vector3.parse_from(bytes)
|
26
|
+
expect(vector.x).to eq 0
|
27
|
+
end
|
28
|
+
|
29
|
+
xit "parses game messages" do
|
30
|
+
file = File.join(GameMachine.app_root,'config','game_messages.proto')
|
31
|
+
obj = Protobuf::GameMessages.new(file)
|
32
|
+
fields = obj.create_entity_fields
|
33
|
+
puts fields.inspect
|
34
|
+
end
|
35
|
+
|
36
|
+
xit "extends protobuf messages" do
|
37
|
+
MessageLib::Entity.class_eval do
|
38
|
+
define_method :doit do
|
39
|
+
"done it"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
entity = MessageLib::Entity.new.set_id('3')
|
43
|
+
puts entity.doit
|
44
|
+
end
|
45
|
+
|
46
|
+
xit "protobuf delimited" do
|
47
|
+
message = MessageLib::ClientMessage.new.add_entity(
|
48
|
+
MessageLib::Entity.new.set_id('asjfl;asjflkasjdfljaslf')
|
49
|
+
)
|
50
|
+
prefixed_bytes = message.to_prefixed_byte_array
|
51
|
+
bytes = message.to_byte_array
|
52
|
+
puts prefixed_bytes.size
|
53
|
+
puts bytes.size
|
54
|
+
stream = JavaLib::ByteArrayInputStream.new(prefixed_bytes)
|
55
|
+
puts "stream byte count #{stream.available}"
|
56
|
+
ProtoLib::CodedInput.readRawVarint32(stream, 1)
|
57
|
+
puts "stream byte count #{stream.available}"
|
58
|
+
bytes = Java::byte[stream.available].new
|
59
|
+
stream.read(bytes,0,stream.available)
|
60
|
+
end
|
61
|
+
|
62
|
+
xit "marshal" do
|
63
|
+
system = Akka.instance.actor_system
|
64
|
+
serialization = JavaLib::SerializationExtension.get(system)
|
65
|
+
serializer = serialization.findSerializerFor(entity)
|
66
|
+
bytes = serializer.toBinary(entity)
|
67
|
+
new_entity = serializer.fromBinary(bytes,entity.get_class)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/spec/model_spec.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
require 'benchmark'
|
4
|
+
|
5
|
+
module GameMachine
|
6
|
+
describe "model" do
|
7
|
+
|
8
|
+
class ScopedModel < GameMachine::Model
|
9
|
+
attribute :health, Integer
|
10
|
+
attribute :name, String
|
11
|
+
attribute :defense_skill, Integer
|
12
|
+
attribute :attack_skill, Integer
|
13
|
+
set_id_scope :tm
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestModel < GameMachine::Model
|
17
|
+
attribute :health, Integer
|
18
|
+
attribute :name, String
|
19
|
+
attribute :defense_skill, Integer
|
20
|
+
attribute :attack_skill, Integer
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:scoped_model) do
|
24
|
+
model = ScopedModel.new(:health => 100, :id => 'myid')
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:scoped_storage_entity) do
|
28
|
+
scoped_model.to_storage_entity
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:test_model) do
|
32
|
+
model = TestModel.new(:health => 100, :id => 'myid')
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
context :scoped_model do
|
37
|
+
|
38
|
+
describe "#unscoped_id" do
|
39
|
+
it "should return unscoped id" do
|
40
|
+
scoped_model.id = 'tm|myid'
|
41
|
+
expect(scoped_model.unscoped_id).to eq 'myid'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#scoped_id" do
|
46
|
+
it "should return scoped id" do
|
47
|
+
expect(scoped_model.scoped_id).to eq 'tm|myid'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#from_entity" do
|
52
|
+
it "should unscope id" do
|
53
|
+
model = ScopedModel.from_entity(scoped_storage_entity,:json_storage)
|
54
|
+
expect(model.id).to eq 'myid'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
describe "#save" do
|
61
|
+
|
62
|
+
it "should return true on success" do
|
63
|
+
expect(test_model.save).to be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return false if id is nil" do
|
67
|
+
test_model.id = nil
|
68
|
+
expect(test_model.save).to be_false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#save!" do
|
73
|
+
it "should raise an exception if id is nil" do
|
74
|
+
test_model.id = nil
|
75
|
+
expect {test_model.save!}.to raise_error
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not raise an exception if id is not nil" do
|
79
|
+
expect {test_model.save!}.to_not raise_error
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#to_json" do
|
84
|
+
it "should set klass" do
|
85
|
+
model_hash = JSON.parse(test_model.to_json)
|
86
|
+
expect(model_hash.has_key?('klass')).to be_true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#to_entity" do
|
91
|
+
it "should return an entity with json entity" do
|
92
|
+
expect(test_model.to_entity.has_json_entity).to be_true
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "#from_entity" do
|
97
|
+
it "should return a test model" do
|
98
|
+
entity = test_model.to_entity
|
99
|
+
expect(TestModel.from_entity(entity)).to be_a(TestModel)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/spec/mono_spec.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'mono_test'
|
3
|
+
require "base64"
|
4
|
+
require 'socket'
|
5
|
+
require "uri"
|
6
|
+
require 'net/http'
|
7
|
+
java_import 'java.util.concurrent.ThreadPoolExecutor'
|
8
|
+
java_import 'java.util.concurrent.TimeUnit'
|
9
|
+
java_import 'java.util.concurrent.LinkedBlockingQueue'
|
10
|
+
java_import 'java.util.concurrent.FutureTask'
|
11
|
+
java_import 'java.util.concurrent.Callable'
|
12
|
+
|
13
|
+
CHARS = [*('a'..'z'),*('0'..'9')].flatten
|
14
|
+
STR = Array.new(100) {|i| CHARS.sample}.join
|
15
|
+
STR2 = Array.new(1000) {|i| CHARS.sample}.join
|
16
|
+
|
17
|
+
|
18
|
+
module GameMachine
|
19
|
+
describe 'mono' do
|
20
|
+
|
21
|
+
it "mono gateway" do
|
22
|
+
Actor::Builder.new(Endpoints::MonoGateway).start
|
23
|
+
sleep 1
|
24
|
+
str = Array.new(1000) {|i| CHARS.sample}.join
|
25
|
+
message = MessageLib::Entity.new.set_id(STR)
|
26
|
+
message.set_destination('GameMachine.TestActor')
|
27
|
+
puts timed = Benchmark.realtime {
|
28
|
+
10.times do
|
29
|
+
Endpoints::MonoGateway.find.tell(message)
|
30
|
+
end
|
31
|
+
}
|
32
|
+
sleep 2
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/spec/mono_test.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class MonoTest < GameMachine::Actor::Base
|
2
|
+
|
3
|
+
def post_init(*args)
|
4
|
+
@vm = Mono::Vm.instance
|
5
|
+
end
|
6
|
+
|
7
|
+
def on_receive(message)
|
8
|
+
namespace = 'GameMachine'
|
9
|
+
klass = 'TestActor'
|
10
|
+
response = @vm.send_message(namespace,klass,message)
|
11
|
+
unless response && response.id == message.id
|
12
|
+
#thread_id = JRuby.reference(Thread.current).native_thread.id
|
13
|
+
puts "Response #{response}"
|
14
|
+
end
|
15
|
+
sender.tell(message,self)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module GameMachine
|
4
|
+
module Navigation
|
5
|
+
describe DetourNavmesh do
|
6
|
+
|
7
|
+
let(:meshfile) {File.join(GameMachine.app_root,'../data/meshes/test.bin')}
|
8
|
+
let(:bad_meshfile) {File.join(GameMachine.app_root,'../data/meshes/bad.bin')}
|
9
|
+
let(:navmesh_id) {1}
|
10
|
+
|
11
|
+
describe "#create" do
|
12
|
+
it "raises an error if meshfile does not exist" do
|
13
|
+
expect {
|
14
|
+
DetourNavmesh.create(navmesh_id,bad_meshfile)
|
15
|
+
}.to raise_error(/file does not exist/)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#load_mesh!" do
|
20
|
+
it "should return 1 on success" do
|
21
|
+
expect(DetourNavmesh.create(navmesh_id,meshfile).load_mesh!).to eql(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should raise error on failure" do
|
25
|
+
#Detour.stub(:loadNavMesh).and_return(0)
|
26
|
+
expect {
|
27
|
+
DetourNavmesh.new(navmesh_id,meshfile).load_mesh!
|
28
|
+
}.to raise_error(/failed to load/)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module GameMachine
|
4
|
+
module Navigation
|
5
|
+
describe DetourPath do
|
6
|
+
|
7
|
+
let(:meshfile) {File.join(GameMachine.app_root,'../data/meshes/test.bin')}
|
8
|
+
|
9
|
+
subject {DetourPath}
|
10
|
+
|
11
|
+
describe "#query_ref" do
|
12
|
+
it "returns a detour path for the given navmesh id" do
|
13
|
+
DetourNavmesh.create(2,meshfile)
|
14
|
+
expect(subject.query_ref(1)).to be_a(subject)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "raises an error if the navmesh is not found" do
|
18
|
+
expect {
|
19
|
+
subject.query_ref(3)
|
20
|
+
}.to raise_error(/Navmesh with id 3 not found/)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
ENV['APP_ROOT'] ||= File.expand_path(Dir.pwd)
|
3
|
+
ENV['JAVA_ROOT'] = File.join(ENV['APP_ROOT'],'java')
|
4
|
+
ENV['GAME_ENV'] = 'test'
|
5
|
+
require 'rubygems'
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'game_machine'
|
9
|
+
rescue LoadError
|
10
|
+
require_relative '../lib/game_machine'
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.before(:suite) do
|
15
|
+
GameMachine::Application.initialize!('default',true)
|
16
|
+
end
|
17
|
+
|
18
|
+
config.before(:each) do
|
19
|
+
GameMachine::AuthHandlers::Base.instance
|
20
|
+
GameMachine::Application.create_grids
|
21
|
+
GameMachine::Application.start_actor_system
|
22
|
+
GameMachine::Application.start_core_systems
|
23
|
+
GameMachine::Application.start_handlers
|
24
|
+
#GameMachine::Application.start_game_systems
|
25
|
+
GameMachine::GameLoader.new.load_all
|
26
|
+
end
|
27
|
+
|
28
|
+
config.after(:each) do
|
29
|
+
GameMachine::Application.stop_actor_system
|
30
|
+
end
|
31
|
+
|
32
|
+
config.after(:suite) do
|
33
|
+
puts "after suite"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
begin
|
38
|
+
require_relative 'message_expectations'
|
39
|
+
rescue LoadError
|
40
|
+
end
|