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,58 @@
|
|
1
|
+
module GameMachine
|
2
|
+
class MessageBuffer
|
3
|
+
|
4
|
+
attr_reader :bytes, :next_message_length
|
5
|
+
def initialize
|
6
|
+
reset
|
7
|
+
end
|
8
|
+
|
9
|
+
def messages
|
10
|
+
byte_messages = []
|
11
|
+
return byte_messages if bytes.nil?
|
12
|
+
stream = JavaLib::ByteArrayInputStream.new(bytes)
|
13
|
+
if next_message_length == 0
|
14
|
+
@next_message_length = read_message_length(stream)
|
15
|
+
end
|
16
|
+
while next_message_length >= 1 && stream.available >= next_message_length
|
17
|
+
message_bytes = Java::byte[next_message_length].new
|
18
|
+
stream.read(message_bytes,0,next_message_length)
|
19
|
+
byte_messages << message_bytes
|
20
|
+
if stream.available >= 1
|
21
|
+
@next_message_length = read_message_length(stream)
|
22
|
+
if next_message_length > stream.available
|
23
|
+
@bytes = Java::byte[stream.available].new
|
24
|
+
stream.read(@bytes,0,stream.available)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
reset
|
28
|
+
end
|
29
|
+
end
|
30
|
+
byte_messages
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_bytes(bytes_to_add)
|
34
|
+
if @bytes.nil?
|
35
|
+
@bytes = bytes_to_add
|
36
|
+
else
|
37
|
+
new_bytes = Java::byte[bytes_to_add.length + @bytes.length].new
|
38
|
+
java.lang.System.arraycopy(@bytes, 0, new_bytes, 0, @bytes.length)
|
39
|
+
java.lang.System.arraycopy(bytes_to_add, 0, new_bytes, @bytes.length, bytes_to_add.length)
|
40
|
+
@bytes = new_bytes
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def reset
|
47
|
+
@next_message_length = 0
|
48
|
+
@bytes = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def read_message_length(s)
|
52
|
+
ProtoLib::CodedInput.readRawVarint32(s)
|
53
|
+
rescue Exception => e
|
54
|
+
raise "Error reading protobuf message length: #{e.to_s}"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module GameMachine
|
2
|
+
class MessageQueue < Actor::Base
|
3
|
+
|
4
|
+
def preStart
|
5
|
+
if getContext.system.name == 'cluster'
|
6
|
+
@mediator = JavaLib::DistributedPubSubExtension.get(get_context.system).mediator
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def on_receive(message)
|
11
|
+
unless @mediator
|
12
|
+
GameMachine.logger.info "Cluster mediator not found, message queue disabled!"
|
13
|
+
unhandled(message)
|
14
|
+
return
|
15
|
+
end
|
16
|
+
if message.is_a?(MessageLib::Publish)
|
17
|
+
publish(message)
|
18
|
+
elsif message.is_a?(MessageLib::Subscribe)
|
19
|
+
subscribe(message)
|
20
|
+
elsif message.is_a?(MessageLib::Unsubscribe)
|
21
|
+
unsubscribe(message)
|
22
|
+
elsif message.is_a?(JavaLib::DistributedPubSubMediator::SubscribeAck)
|
23
|
+
GameMachine.logger.debug "Subscribed"
|
24
|
+
else
|
25
|
+
unhandled(message)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def subscribe(message)
|
32
|
+
if message.topic
|
33
|
+
sub = Java::akka::contrib::pattern::DistributedPubSubMediator::Subscribe.new(message.topic, get_sender)
|
34
|
+
else
|
35
|
+
sub = Java::akka::contrib::pattern::DistributedPubSubMediator::Put.new(get_sender)
|
36
|
+
end
|
37
|
+
@mediator.tell(sub, get_sender)
|
38
|
+
end
|
39
|
+
|
40
|
+
def unsubscribe(message)
|
41
|
+
sub = Java::akka::contrib::pattern::DistributedPubSubMediator::Unsubscribe.new(message.topic, get_sender)
|
42
|
+
@mediator.tell(sub, get_sender)
|
43
|
+
end
|
44
|
+
|
45
|
+
def publish(publish)
|
46
|
+
if publish.message.has_chat_message
|
47
|
+
publish_message = publish.message #publish.message.chat_message.message
|
48
|
+
else
|
49
|
+
publish_message = publish.message
|
50
|
+
end
|
51
|
+
if publish.topic
|
52
|
+
message = Java::akka::contrib::pattern::DistributedPubSubMediator::Publish.new(publish.topic, publish_message)
|
53
|
+
elsif publish.path
|
54
|
+
message = Java::akka::contrib::pattern::DistributedPubSubMediator::SendToAll.new(publish.path, publish_message,true)
|
55
|
+
else
|
56
|
+
GameMachine.logger.error("Publish missing topic or path")
|
57
|
+
return
|
58
|
+
end
|
59
|
+
@mediator.tell(message, get_sender)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'json'
|
2
|
+
# JSON models that will get converted appropriately when sent to or
|
3
|
+
# received by actors.
|
4
|
+
|
5
|
+
# JsonEntity messages always get converted. JsonStorage messages
|
6
|
+
# are a special case for the object database and are left untouched
|
7
|
+
# by the tell/ask/on_receive filters
|
8
|
+
|
9
|
+
require 'ostruct'
|
10
|
+
|
11
|
+
module GameMachine
|
12
|
+
class Model < OpenStruct
|
13
|
+
include GameMachine::Commands
|
14
|
+
|
15
|
+
class << self
|
16
|
+
|
17
|
+
def attribute(*args)
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def find!(id)
|
22
|
+
scoped_id = scope_for(id)
|
23
|
+
if entity = Commands::Base.commands.datastore.get!(scoped_id)
|
24
|
+
from_entity(entity,:json_storage)
|
25
|
+
else
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def find(id,timeout=1000)
|
31
|
+
scoped_id = scope_for(id)
|
32
|
+
if entity = Commands::Base.commands.datastore.get(scoped_id,timeout)
|
33
|
+
from_entity(entity,:json_storage)
|
34
|
+
else
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# TODO cache klass names in hash to avoid constantize
|
40
|
+
def from_entity(entity,type=:json_entity)
|
41
|
+
if type == :json_storage
|
42
|
+
json = entity.json_storage.json
|
43
|
+
else
|
44
|
+
json = entity.json_entity.json
|
45
|
+
end
|
46
|
+
|
47
|
+
attributes = JSON.parse(json)
|
48
|
+
if klass = attributes.delete('klass')
|
49
|
+
model = klass.constantize.new(attributes)
|
50
|
+
model.id = model.unscoped_id
|
51
|
+
model
|
52
|
+
else
|
53
|
+
raise "Unable to find klass attribute in #{attributes.inspect}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def scope_for(id)
|
58
|
+
if id_scope
|
59
|
+
"#{id_scope}|#{id}"
|
60
|
+
else
|
61
|
+
id
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_id_scope(scope)
|
66
|
+
@id_scope = scope
|
67
|
+
end
|
68
|
+
|
69
|
+
def id_scope
|
70
|
+
@id_scope
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def attributes
|
75
|
+
self.marshal_dump
|
76
|
+
end
|
77
|
+
|
78
|
+
def scoped_id
|
79
|
+
if self.class.id_scope
|
80
|
+
self.class.scope_for(id)
|
81
|
+
else
|
82
|
+
id
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def unscoped_id
|
87
|
+
if self.class.id_scope
|
88
|
+
id.sub(/^#{self.class.id_scope}\|/,'')
|
89
|
+
else
|
90
|
+
id
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def to_json
|
95
|
+
attributes['id'] = scoped_id
|
96
|
+
JSON.dump(attributes.merge(:klass => self.class.name))
|
97
|
+
end
|
98
|
+
|
99
|
+
def to_entity
|
100
|
+
MessageLib::Entity.new.set_id(scoped_id).set_json_entity(to_json_entity)
|
101
|
+
end
|
102
|
+
|
103
|
+
def to_json_entity
|
104
|
+
MessageLib::JsonEntity.new.set_json(to_json).set_klass(self.class.name)
|
105
|
+
end
|
106
|
+
|
107
|
+
def to_storage_entity
|
108
|
+
MessageLib::Entity.new.set_id(scoped_id).set_json_storage(to_json_storage)
|
109
|
+
end
|
110
|
+
|
111
|
+
def to_json_storage
|
112
|
+
MessageLib::JsonStorage.new.set_json(to_json)
|
113
|
+
end
|
114
|
+
|
115
|
+
def save
|
116
|
+
commands.datastore.put(to_storage_entity)
|
117
|
+
end
|
118
|
+
|
119
|
+
def save!
|
120
|
+
commands.datastore.put!(to_storage_entity)
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module GameMachine
|
2
|
+
class MonoServer
|
3
|
+
|
4
|
+
attr_reader :mono_path
|
5
|
+
def initialize
|
6
|
+
@mono_path = File.join(GameMachine.app_root,'mono','server')
|
7
|
+
end
|
8
|
+
|
9
|
+
def run!
|
10
|
+
# mono server blocks. We run in a loop so if it dies or we restart it,
|
11
|
+
# it will just get restarted
|
12
|
+
Thread.new do
|
13
|
+
loop do
|
14
|
+
system("cd #{mono_path} && mono server.exe #{Application.config.mono_gateway_port}")
|
15
|
+
sleep 10
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'benchmark'
|
3
|
+
module GameMachine
|
4
|
+
module Navigation
|
5
|
+
module Detour
|
6
|
+
extend FFI::Library
|
7
|
+
sofile = File.join(File.dirname(__FILE__), '../../../pathfinding/bin/libdetour_path.so')
|
8
|
+
if File.exists?(sofile)
|
9
|
+
ffi_lib sofile
|
10
|
+
attach_function :findPath, [:pointer,:float,:float,:float,:float,:float,:float, :int, :pointer], :int
|
11
|
+
attach_function :loadNavMesh, [:int, :string], :int
|
12
|
+
attach_function :freePath, [:pointer], :void
|
13
|
+
attach_function :getPathPtr, [:int], :pointer
|
14
|
+
attach_function :freeQuery, [:pointer], :void
|
15
|
+
attach_function :getQuery, [:int], :pointer
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module GameMachine
|
2
|
+
module Navigation
|
3
|
+
class DetourNavmesh
|
4
|
+
|
5
|
+
def self.meshes
|
6
|
+
if @meshes
|
7
|
+
@meshes
|
8
|
+
else
|
9
|
+
@meshes = java.util.concurrent.ConcurrentHashMap.new
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.create(id,meshfile)
|
14
|
+
if meshes.has_key?(id)
|
15
|
+
return false
|
16
|
+
end
|
17
|
+
meshes[id] = new(id,meshfile)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find(id)
|
21
|
+
meshes.fetch(id,nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :id, :meshfile, :loaded
|
25
|
+
def initialize(id,meshfile)
|
26
|
+
@id = id
|
27
|
+
@meshfile = meshfile
|
28
|
+
unless File.exists?(meshfile)
|
29
|
+
raise "Navigation mesh file does not exist (#{meshfile})"
|
30
|
+
end
|
31
|
+
@loaded = false
|
32
|
+
end
|
33
|
+
|
34
|
+
def loaded?
|
35
|
+
loaded
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_mesh!
|
39
|
+
if loaded?
|
40
|
+
raise "DetourNavmesh #{id} already loaded"
|
41
|
+
end
|
42
|
+
|
43
|
+
load_res = Detour.loadNavMesh(id,meshfile)
|
44
|
+
unless load_res == 1
|
45
|
+
raise "DetourNavmesh #{id} failed to load (#{load_res})"
|
46
|
+
end
|
47
|
+
@loaded = true
|
48
|
+
load_res
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module GameMachine
|
2
|
+
module Navigation
|
3
|
+
class DetourPath
|
4
|
+
|
5
|
+
def self.query_ref(navmesh_id)
|
6
|
+
if navmesh = DetourNavmesh.find(navmesh_id)
|
7
|
+
Thread.current[navmesh_id.to_s.to_sym] ||= new(navmesh)
|
8
|
+
else
|
9
|
+
raise "Navmesh with id #{navmesh_id} not found"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :navmesh, :error, :max_paths
|
14
|
+
def initialize(navmesh)
|
15
|
+
@navmesh = navmesh
|
16
|
+
@max_paths = 256
|
17
|
+
@error = nil
|
18
|
+
|
19
|
+
unless navmesh.loaded?
|
20
|
+
raise "Navmesh #{navmesh.id} not loaded"
|
21
|
+
end
|
22
|
+
@query_ptr = Detour.getQuery(navmesh.id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy_query
|
26
|
+
Detour.freeQuery(@query_ptr)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Detour coords:
|
30
|
+
# z = unity x, x = unity z
|
31
|
+
def find_path( start_x, start_y, start_z, end_x, end_y, end_z,straight_path)
|
32
|
+
|
33
|
+
@error = nil
|
34
|
+
|
35
|
+
ptr = Detour.getPathPtr(max_paths)
|
36
|
+
paths_found = Detour.findPath(
|
37
|
+
@query_ptr,start_z,start_y,
|
38
|
+
start_x, end_z,end_y,end_x, straight_path, ptr
|
39
|
+
)
|
40
|
+
|
41
|
+
if paths_found <= 0
|
42
|
+
@error = paths_found
|
43
|
+
return []
|
44
|
+
end
|
45
|
+
|
46
|
+
fptr = ptr.read_pointer()
|
47
|
+
path = fptr.null? ? [] : ptr.get_array_of_float(0,paths_found*3)
|
48
|
+
Detour.freePath(ptr)
|
49
|
+
path.each_slice(3).map {|i| Vector.new(i[2],i[1],i[0])}.to_a
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module GameMachine
|
2
|
+
module Navigation
|
3
|
+
class Path
|
4
|
+
|
5
|
+
attr_accessor :path, :current_location
|
6
|
+
attr_reader :current_point
|
7
|
+
def initialize(path,current_location)
|
8
|
+
@path = path
|
9
|
+
@current_point = path.first
|
10
|
+
@current_location = current_location
|
11
|
+
end
|
12
|
+
|
13
|
+
def set_path(path)
|
14
|
+
@path = path
|
15
|
+
@current_point = path.first
|
16
|
+
end
|
17
|
+
|
18
|
+
def next_point
|
19
|
+
if point_reached?
|
20
|
+
@current_point = path.shift
|
21
|
+
end
|
22
|
+
@current_point
|
23
|
+
end
|
24
|
+
|
25
|
+
def point_reached?
|
26
|
+
return true if current_point.nil?
|
27
|
+
current_location.distance(current_point) < 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|