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.
Files changed (273) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +72 -0
  4. data/Rakefile +38 -0
  5. data/bin/game_machine +79 -0
  6. data/config/cluster.conf +65 -0
  7. data/config/config.example.yml +93 -0
  8. data/config/game_messages.proto +45 -0
  9. data/config/messages.proto +339 -0
  10. data/config/regions.example.yml +9 -0
  11. data/config/standalone.conf +36 -0
  12. data/db/do_not_delete +0 -0
  13. data/game_machine.gemspec +38 -0
  14. data/games/example/boot.rb +6 -0
  15. data/games/example/data/game_data.yml +13 -0
  16. data/games/example/lib/aggressive_npc.rb +176 -0
  17. data/games/example/lib/authentication_handler.rb +69 -0
  18. data/games/example/lib/chatbot.rb +61 -0
  19. data/games/example/lib/combat_controller.rb +145 -0
  20. data/games/example/lib/example_controller.rb +21 -0
  21. data/games/example/lib/game.rb +85 -0
  22. data/games/example/lib/models/attack.rb +9 -0
  23. data/games/example/lib/models/combat_update.rb +11 -0
  24. data/games/example/lib/models/player_command.rb +7 -0
  25. data/games/example/lib/models/user.rb +11 -0
  26. data/games/example/lib/models/vitals.rb +17 -0
  27. data/games/example/lib/npc.rb +111 -0
  28. data/games/example/lib/npc_group.rb +42 -0
  29. data/games/example/lib/npc_movement.rb +116 -0
  30. data/games/example/lib/player_manager.rb +58 -0
  31. data/games/example/lib/player_register.rb +80 -0
  32. data/games/example/lib/tracking_handler.rb +17 -0
  33. data/games/example/lib/zone_manager.rb +57 -0
  34. data/games/preload.rb +8 -0
  35. data/integration_tests/basic_spec.rb +68 -0
  36. data/integration_tests/bot_spec.rb +18 -0
  37. data/integration_tests/chat_spec.rb +45 -0
  38. data/integration_tests/distributed_spec.rb +34 -0
  39. data/integration_tests/entity_tracking_spec.rb +48 -0
  40. data/integration_tests/mono_spec.rb +16 -0
  41. data/integration_tests/objectdb_spec.rb +55 -0
  42. data/integration_tests/tcp_client_spec.rb +71 -0
  43. data/integration_tests/udp_client_spec.rb +61 -0
  44. data/integration_tests/udp_spec.rb +20 -0
  45. data/integration_tests/udt_client_spec.rb +23 -0
  46. data/integration_tests/udt_spec.rb +31 -0
  47. data/java/.gitignore +1 -0
  48. data/java/build.gradle +93 -0
  49. data/java/component.erb +396 -0
  50. data/java/gradle.properties +6 -0
  51. data/java/gradle/wrapper/gradle-wrapper.jar +0 -0
  52. data/java/gradle/wrapper/gradle-wrapper.properties +6 -0
  53. data/java/gradlew +164 -0
  54. data/java/gradlew.bat +90 -0
  55. data/java/local_lib/protostuff-compiler-1.0.7-jarjar.jar +0 -0
  56. data/java/settings.gradle +2 -0
  57. data/java/src/main/java/com/game_machine/core/ActorFactory.java +25 -0
  58. data/java/src/main/java/com/game_machine/core/ActorUtil.java +39 -0
  59. data/java/src/main/java/com/game_machine/core/CommandProxy.java +9 -0
  60. data/java/src/main/java/com/game_machine/core/EntitySerializer.java +66 -0
  61. data/java/src/main/java/com/game_machine/core/EventStreamHandler.java +43 -0
  62. data/java/src/main/java/com/game_machine/core/GameMachineLoader.java +25 -0
  63. data/java/src/main/java/com/game_machine/core/Grid.java +195 -0
  64. data/java/src/main/java/com/game_machine/core/GridValue.java +30 -0
  65. data/java/src/main/java/com/game_machine/core/IActorFactory.java +7 -0
  66. data/java/src/main/java/com/game_machine/core/NetMessage.java +28 -0
  67. data/java/src/main/java/com/game_machine/core/UdpServer.java +97 -0
  68. data/java/src/main/java/com/game_machine/core/UdpServerHandler.java +90 -0
  69. data/java/src/main/resources/game_machine.java.stg +738 -0
  70. data/java/src/main/resources/logback.xml +14 -0
  71. data/java/src/main/resources/logging.properties +3 -0
  72. data/java/src/main/resources/protostuff.properties +7 -0
  73. data/lib/game_machine.rb +85 -0
  74. data/lib/game_machine/actor.rb +7 -0
  75. data/lib/game_machine/actor/base.rb +184 -0
  76. data/lib/game_machine/actor/builder.rb +108 -0
  77. data/lib/game_machine/actor/development.rb +31 -0
  78. data/lib/game_machine/actor/factory.rb +35 -0
  79. data/lib/game_machine/actor/mono_actor.rb +89 -0
  80. data/lib/game_machine/actor/ref.rb +81 -0
  81. data/lib/game_machine/actor/reloadable.rb +98 -0
  82. data/lib/game_machine/actor/system.rb +32 -0
  83. data/lib/game_machine/akka.rb +98 -0
  84. data/lib/game_machine/app_config.rb +49 -0
  85. data/lib/game_machine/application.rb +181 -0
  86. data/lib/game_machine/auth_handlers/base.rb +21 -0
  87. data/lib/game_machine/auth_handlers/public.rb +34 -0
  88. data/lib/game_machine/bot/chat.rb +66 -0
  89. data/lib/game_machine/bot/client.rb +54 -0
  90. data/lib/game_machine/client_manager.rb +204 -0
  91. data/lib/game_machine/clients.rb +4 -0
  92. data/lib/game_machine/clients/client.rb +45 -0
  93. data/lib/game_machine/clients/tcp_client.rb +25 -0
  94. data/lib/game_machine/clients/test_client.rb +151 -0
  95. data/lib/game_machine/clients/udp_client.rb +25 -0
  96. data/lib/game_machine/clients/udt_client.rb +34 -0
  97. data/lib/game_machine/cluster_monitor.rb +115 -0
  98. data/lib/game_machine/commands.rb +23 -0
  99. data/lib/game_machine/commands/base.rb +21 -0
  100. data/lib/game_machine/commands/chat_commands.rb +88 -0
  101. data/lib/game_machine/commands/datastore_commands.rb +60 -0
  102. data/lib/game_machine/commands/grid_commands.rb +35 -0
  103. data/lib/game_machine/commands/message_helper.rb +25 -0
  104. data/lib/game_machine/commands/misc_commands.rb +29 -0
  105. data/lib/game_machine/commands/navigation_commands.rb +24 -0
  106. data/lib/game_machine/commands/player_commands.rb +28 -0
  107. data/lib/game_machine/commands/proxy.rb +16 -0
  108. data/lib/game_machine/console.rb +3 -0
  109. data/lib/game_machine/console/build.rb +74 -0
  110. data/lib/game_machine/console/install.rb +92 -0
  111. data/lib/game_machine/console/server.rb +120 -0
  112. data/lib/game_machine/data_store.rb +52 -0
  113. data/lib/game_machine/data_stores/couchbase.rb +18 -0
  114. data/lib/game_machine/data_stores/mapdb.rb +49 -0
  115. data/lib/game_machine/data_stores/memory.rb +35 -0
  116. data/lib/game_machine/data_stores/redis.rb +46 -0
  117. data/lib/game_machine/endpoints.rb +6 -0
  118. data/lib/game_machine/endpoints/mono_gateway.rb +87 -0
  119. data/lib/game_machine/endpoints/tcp.rb +51 -0
  120. data/lib/game_machine/endpoints/tcp_handler.rb +75 -0
  121. data/lib/game_machine/endpoints/udp.rb +88 -0
  122. data/lib/game_machine/endpoints/udp_incoming.rb +113 -0
  123. data/lib/game_machine/endpoints/udp_outgoing.rb +46 -0
  124. data/lib/game_machine/game_loader.rb +46 -0
  125. data/lib/game_machine/game_systems.rb +14 -0
  126. data/lib/game_machine/game_systems/agents/controller.rb +118 -0
  127. data/lib/game_machine/game_systems/chat.rb +256 -0
  128. data/lib/game_machine/game_systems/chat_manager.rb +108 -0
  129. data/lib/game_machine/game_systems/chat_topic.rb +36 -0
  130. data/lib/game_machine/game_systems/devnull.rb +13 -0
  131. data/lib/game_machine/game_systems/entity_loader.rb +12 -0
  132. data/lib/game_machine/game_systems/entity_tracking.rb +133 -0
  133. data/lib/game_machine/game_systems/local_echo.rb +16 -0
  134. data/lib/game_machine/game_systems/objectdb_proxy.rb +61 -0
  135. data/lib/game_machine/game_systems/private_chat.rb +20 -0
  136. data/lib/game_machine/game_systems/region_manager.rb +91 -0
  137. data/lib/game_machine/game_systems/region_service.rb +94 -0
  138. data/lib/game_machine/game_systems/region_settings.rb +13 -0
  139. data/lib/game_machine/game_systems/remote_echo.rb +14 -0
  140. data/lib/game_machine/game_systems/stress_test.rb +21 -0
  141. data/lib/game_machine/grid.rb +60 -0
  142. data/lib/game_machine/grid_replicator.rb +31 -0
  143. data/lib/game_machine/handlers/authentication.rb +55 -0
  144. data/lib/game_machine/handlers/game.rb +63 -0
  145. data/lib/game_machine/handlers/request.rb +80 -0
  146. data/lib/game_machine/hashring.rb +48 -0
  147. data/lib/game_machine/helpers/game_message.rb +159 -0
  148. data/lib/game_machine/helpers/state_machine.rb +29 -0
  149. data/lib/game_machine/java_lib.rb +51 -0
  150. data/lib/game_machine/logger.rb +39 -0
  151. data/lib/game_machine/message_buffer.rb +58 -0
  152. data/lib/game_machine/message_queue.rb +63 -0
  153. data/lib/game_machine/model.rb +125 -0
  154. data/lib/game_machine/models.rb +3 -0
  155. data/lib/game_machine/models/player_status_update.rb +8 -0
  156. data/lib/game_machine/models/region.rb +9 -0
  157. data/lib/game_machine/mono_server.rb +20 -0
  158. data/lib/game_machine/navigation.rb +4 -0
  159. data/lib/game_machine/navigation/detour.rb +20 -0
  160. data/lib/game_machine/navigation/detour_navmesh.rb +53 -0
  161. data/lib/game_machine/navigation/detour_path.rb +53 -0
  162. data/lib/game_machine/navigation/path.rb +31 -0
  163. data/lib/game_machine/object_db.rb +67 -0
  164. data/lib/game_machine/protobuf.rb +6 -0
  165. data/lib/game_machine/protobuf/game_messages.rb +24 -0
  166. data/lib/game_machine/protobuf/generate.rb +113 -0
  167. data/lib/game_machine/protobuf_extensions/entity_helper.rb +11 -0
  168. data/lib/game_machine/reloadable_monitor.rb +26 -0
  169. data/lib/game_machine/restart_watcher.rb +17 -0
  170. data/lib/game_machine/ruby_extensions/nilclass.rb +10 -0
  171. data/lib/game_machine/ruby_extensions/string.rb +17 -0
  172. data/lib/game_machine/scheduler.rb +23 -0
  173. data/lib/game_machine/securerandom.rb +6 -0
  174. data/lib/game_machine/settings.rb +11 -0
  175. data/lib/game_machine/system_monitor.rb +19 -0
  176. data/lib/game_machine/system_stats.rb +24 -0
  177. data/lib/game_machine/uniqueid.rb +23 -0
  178. data/lib/game_machine/vector.rb +95 -0
  179. data/lib/game_machine/version.rb +3 -0
  180. data/lib/game_machine/write_behind_cache.rb +164 -0
  181. data/mono/bin/csharp/common.xslt +109 -0
  182. data/mono/bin/csharp/csharp.xslt +628 -0
  183. data/mono/bin/csharp/descriptor.proto +533 -0
  184. data/mono/bin/csharp/protobuf-net.dll +0 -0
  185. data/mono/bin/csharp/protobuf-net.pdb +0 -0
  186. data/mono/bin/csharp/protobuf-net.xml +2879 -0
  187. data/mono/bin/csharp/protogen.exe.config +3 -0
  188. data/mono/bin/csharp/protogen.pdb +0 -0
  189. data/mono/bin/csharp/protogen_csharp.exe +0 -0
  190. data/mono/bin/csharp/vb.xslt +745 -0
  191. data/mono/bin/csharp/xml.xslt +26 -0
  192. data/mono/server/Makefile +6 -0
  193. data/mono/server/NLog.config +12 -0
  194. data/mono/server/NLog.dll +0 -0
  195. data/mono/server/actor.cs +37 -0
  196. data/mono/server/build.bat +3 -0
  197. data/mono/server/cscompmgd.dll +0 -0
  198. data/mono/server/iactor.cs +11 -0
  199. data/mono/server/message_router.cs +67 -0
  200. data/mono/server/message_util.cs +29 -0
  201. data/mono/server/messages.cs +1888 -0
  202. data/mono/server/protobuf-net.dll +0 -0
  203. data/mono/server/proxy_client.cs +73 -0
  204. data/mono/server/proxy_server.cs +30 -0
  205. data/mono/server/test_actor.cs +33 -0
  206. data/pathfinding/bin/premake4 +0 -0
  207. data/pathfinding/include/mesh_loader.h +28 -0
  208. data/pathfinding/include/pathfind.h +167 -0
  209. data/pathfinding/main.cpp +39 -0
  210. data/pathfinding/mesh_loader.cpp +108 -0
  211. data/pathfinding/pathfind.cpp +174 -0
  212. data/pathfinding/pathfinder.cs +66 -0
  213. data/pathfinding/premake4.lua +109 -0
  214. data/script/server.sh +109 -0
  215. data/script/watch.sh +11 -0
  216. data/spec/actor/actor_spec.rb +73 -0
  217. data/spec/actor/builder_spec.rb +56 -0
  218. data/spec/actor/ref_spec.rb +83 -0
  219. data/spec/application_spec.rb +7 -0
  220. data/spec/client_manager_spec.rb +171 -0
  221. data/spec/commands/chat_commands_spec.rb +38 -0
  222. data/spec/commands/datastore_commands_spec.rb +91 -0
  223. data/spec/commands/grid_commands_spec.rb +37 -0
  224. data/spec/commands/navigation_commands_spec.rb +51 -0
  225. data/spec/commands/player_commands_spec.rb +48 -0
  226. data/spec/commands_spec.rb +38 -0
  227. data/spec/data_stores/mapdb_spec.rb +46 -0
  228. data/spec/data_stores/redis_spec.rb +44 -0
  229. data/spec/game_systems/agents/controller_spec.rb +84 -0
  230. data/spec/game_systems/agents/test_agent.rb +10 -0
  231. data/spec/game_systems/agents/test_agent_config.rb +29 -0
  232. data/spec/game_systems/chat_manager_spec.rb +66 -0
  233. data/spec/game_systems/chat_spec.rb +187 -0
  234. data/spec/game_systems/entity_tracking_spec.rb +64 -0
  235. data/spec/game_systems/region_manager_spec.rb +138 -0
  236. data/spec/grid_spec.rb +37 -0
  237. data/spec/handlers/authentication_spec.rb +36 -0
  238. data/spec/handlers/game_spec.rb +49 -0
  239. data/spec/handlers/request_spec.rb +65 -0
  240. data/spec/hashring_spec.rb +59 -0
  241. data/spec/integration_helper.rb +120 -0
  242. data/spec/java_grid_spec.rb +89 -0
  243. data/spec/message_buffer_spec.rb +67 -0
  244. data/spec/message_expectations.rb +47 -0
  245. data/spec/message_queue_spec.rb +23 -0
  246. data/spec/misc_spec.rb +71 -0
  247. data/spec/model_spec.rb +103 -0
  248. data/spec/mono_spec.rb +36 -0
  249. data/spec/mono_test.rb +18 -0
  250. data/spec/navigation/detour_navmesh_spec.rb +34 -0
  251. data/spec/navigation/detour_path_spec.rb +25 -0
  252. data/spec/spec_helper.rb +40 -0
  253. data/spec/udp_server_spec.rb +10 -0
  254. data/spec/write_behind_cache_spec.rb +109 -0
  255. data/web/app.rb +131 -0
  256. data/web/config/trinidad.yml +4 -0
  257. data/web/controllers/auth_controller.rb +19 -0
  258. data/web/controllers/base_controller.rb +16 -0
  259. data/web/controllers/index_controller.rb +7 -0
  260. data/web/controllers/log_controller.rb +47 -0
  261. data/web/controllers/messages_controller.rb +59 -0
  262. data/web/controllers/player_register_controller.rb +15 -0
  263. data/web/log/development.log +1339 -0
  264. data/web/tmp/restart.txt +0 -0
  265. data/web/views/game_messages.haml +45 -0
  266. data/web/views/index.haml +6 -0
  267. data/web/views/layout.haml +41 -0
  268. data/web/views/logs.haml +32 -0
  269. data/web/views/player_register.haml +22 -0
  270. data/web/views/player_registered.haml +2 -0
  271. data/web/views/register_layout.haml +22 -0
  272. data/web/views/restart.haml +35 -0
  273. 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,3 @@
1
+
2
+ require_relative 'models/region'
3
+ require_relative 'models/player_status_update'
@@ -0,0 +1,8 @@
1
+ module GameMachine
2
+ module Models
3
+ class PlayerStatusUpdate < Model
4
+ attribute :player_id, String
5
+ attribute :status, String
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module GameMachine
2
+ module Models
3
+ class Region < Model
4
+ attribute :name, String
5
+ attribute :server, String
6
+ attribute :manager, String
7
+ end
8
+ end
9
+ end
@@ -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,4 @@
1
+ require_relative 'navigation/detour'
2
+ require_relative 'navigation/detour_navmesh'
3
+ require_relative 'navigation/detour_path'
4
+ require_relative 'navigation/path'
@@ -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