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,174 @@
|
|
1
|
+
#include "pathfind.h"
|
2
|
+
|
3
|
+
extern "C" EXPORT_API int loadNavMesh(int map, const char *file) {
|
4
|
+
if (meshes[map] != 0) {
|
5
|
+
return 0;
|
6
|
+
}
|
7
|
+
dtNavMesh* navMesh;
|
8
|
+
navMesh = load_navmesh(file);
|
9
|
+
meshes[map] = navMesh;
|
10
|
+
return 1;
|
11
|
+
}
|
12
|
+
|
13
|
+
extern "C" EXPORT_API dtNavMeshQuery* getQuery(int map) {
|
14
|
+
if (meshes[map] == 0) {
|
15
|
+
fprintf (stderr, "Unable to load navmesh\n");
|
16
|
+
return 0;
|
17
|
+
}
|
18
|
+
|
19
|
+
dtNavMeshQuery* query = dtAllocNavMeshQuery();
|
20
|
+
query->init(meshes[map], 4096);
|
21
|
+
return query;
|
22
|
+
}
|
23
|
+
|
24
|
+
extern "C" void EXPORT_API freeQuery(dtNavMeshQuery* query) {
|
25
|
+
dtFreeNavMeshQuery(query);
|
26
|
+
}
|
27
|
+
|
28
|
+
extern "C" EXPORT_API int findPath(dtNavMeshQuery* query, float startx, float starty,
|
29
|
+
float startz, float endx, float endy, float endz, int find_straight_path,
|
30
|
+
float* resultPath) {
|
31
|
+
|
32
|
+
if (query == NULL) {
|
33
|
+
return P_QUERY_NOT_FOUND;
|
34
|
+
}
|
35
|
+
|
36
|
+
float m_spos[3] = {startx,starty,startz};
|
37
|
+
float m_epos[3] = {endx,endy,endz};
|
38
|
+
|
39
|
+
|
40
|
+
dtPolyRef m_polys[MAX_POLYS];
|
41
|
+
|
42
|
+
dtQueryFilter m_filter;
|
43
|
+
float straight[MAX_POLYS*3];
|
44
|
+
int straightPathCount = 0;
|
45
|
+
float polyPickExt[3] = {40,40,40};
|
46
|
+
int m_npolys = 0;
|
47
|
+
|
48
|
+
float m_steerPoints[MAX_STEER_POINTS*3];
|
49
|
+
int m_steerPointCount;
|
50
|
+
float m_smoothPath[MAX_SMOOTH*3];
|
51
|
+
int m_nsmoothPath = 0;
|
52
|
+
|
53
|
+
m_filter.setIncludeFlags(SAMPLE_POLYFLAGS_ALL ^ SAMPLE_POLYFLAGS_DISABLED);
|
54
|
+
m_filter.setExcludeFlags(0);
|
55
|
+
|
56
|
+
dtPolyRef m_startRef, m_endRef;
|
57
|
+
|
58
|
+
dtStatus res;
|
59
|
+
|
60
|
+
res = query->findNearestPoly(m_spos, polyPickExt, &m_filter, &m_startRef, 0);
|
61
|
+
if (res == DT_SUCCESS) {
|
62
|
+
if (m_startRef == 0) {
|
63
|
+
return P_NO_START_POLY;
|
64
|
+
}
|
65
|
+
} else {
|
66
|
+
return P_NO_START_POLY;
|
67
|
+
}
|
68
|
+
|
69
|
+
res = query->findNearestPoly(m_epos, polyPickExt, &m_filter, &m_endRef, 0);
|
70
|
+
if (res == DT_SUCCESS) {
|
71
|
+
if (m_endRef == 0) {
|
72
|
+
return P_NO_END_POLY;
|
73
|
+
}
|
74
|
+
} else {
|
75
|
+
return P_NO_END_POLY;
|
76
|
+
}
|
77
|
+
|
78
|
+
res = query->findPath(m_startRef, m_endRef, m_spos, m_epos, &m_filter, m_polys, &m_npolys, MAX_POLYS);
|
79
|
+
if (res != DT_SUCCESS) {
|
80
|
+
return P_PATH_NOT_FOUND;
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
if (find_straight_path == 0) {
|
85
|
+
dtPolyRef polys[MAX_POLYS];
|
86
|
+
memcpy(polys, m_polys, sizeof(dtPolyRef)*m_npolys);
|
87
|
+
int npolys = m_npolys;
|
88
|
+
|
89
|
+
float iterPos[3], targetPos[3];
|
90
|
+
query->closestPointOnPoly(m_startRef, m_spos, iterPos,0);
|
91
|
+
query->closestPointOnPoly(polys[npolys-1], m_epos, targetPos,0);
|
92
|
+
|
93
|
+
m_nsmoothPath = 0;
|
94
|
+
|
95
|
+
dtVcopy(&m_smoothPath[m_nsmoothPath*3], iterPos);
|
96
|
+
m_nsmoothPath++;
|
97
|
+
|
98
|
+
while (npolys && m_nsmoothPath < MAX_SMOOTH) {
|
99
|
+
// Find location to steer towards.
|
100
|
+
float steerPos[3];
|
101
|
+
unsigned char steerPosFlag;
|
102
|
+
dtPolyRef steerPosRef;
|
103
|
+
|
104
|
+
if (!getSteerTarget(query, iterPos, targetPos, SLOP, polys, npolys, steerPos, steerPosFlag, steerPosRef)) {
|
105
|
+
break;
|
106
|
+
}
|
107
|
+
|
108
|
+
bool endOfPath = (steerPosFlag & DT_STRAIGHTPATH_END) ? true : false;
|
109
|
+
bool offMeshConnection = (steerPosFlag & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ? true : false;
|
110
|
+
|
111
|
+
// Find movement delta.
|
112
|
+
float delta[3], len;
|
113
|
+
dtVsub(delta, steerPos, iterPos);
|
114
|
+
len = dtSqrt(dtVdot(delta,delta));
|
115
|
+
// If the steer target is end of path or off-mesh link, do not move past the location.
|
116
|
+
if ((endOfPath || offMeshConnection) && len < STEP_SIZE) {
|
117
|
+
len = 1;
|
118
|
+
} else {
|
119
|
+
len = STEP_SIZE / len;
|
120
|
+
}
|
121
|
+
|
122
|
+
float moveTgt[3];
|
123
|
+
dtVmad(moveTgt, iterPos, delta, len);
|
124
|
+
|
125
|
+
// Move
|
126
|
+
float result[3];
|
127
|
+
dtPolyRef visited[16];
|
128
|
+
int nvisited = 0;
|
129
|
+
query->moveAlongSurface(polys[0], iterPos, moveTgt, &m_filter, result, visited, &nvisited, 16);
|
130
|
+
|
131
|
+
npolys = fixupCorridor(polys, npolys, MAX_POLYS, visited, nvisited);
|
132
|
+
float h = 0;
|
133
|
+
query->getPolyHeight(polys[0], result, &h);
|
134
|
+
result[1] = h;
|
135
|
+
dtVcopy(iterPos, result);
|
136
|
+
|
137
|
+
if (endOfPath && inRange(iterPos, steerPos, SLOP, 1.0f)) {
|
138
|
+
// Reached end of path.
|
139
|
+
fprintf (stderr, "End of path reached\n");
|
140
|
+
dtVcopy(iterPos, targetPos);
|
141
|
+
if (m_nsmoothPath < MAX_SMOOTH) {
|
142
|
+
dtVcopy(&m_smoothPath[m_nsmoothPath*3], iterPos);
|
143
|
+
m_nsmoothPath++;
|
144
|
+
}
|
145
|
+
break;
|
146
|
+
}
|
147
|
+
|
148
|
+
if (m_nsmoothPath < MAX_SMOOTH) {
|
149
|
+
dtVcopy(&m_smoothPath[m_nsmoothPath*3], iterPos);
|
150
|
+
m_nsmoothPath++;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
memcpy(resultPath, m_smoothPath, sizeof(float)*3*m_nsmoothPath);
|
155
|
+
return m_nsmoothPath;
|
156
|
+
}
|
157
|
+
|
158
|
+
|
159
|
+
query->findStraightPath(m_spos, m_epos, m_polys, m_npolys, straight, 0, 0, &straightPathCount, MAX_POLYS);
|
160
|
+
memcpy(resultPath, straight, sizeof(float)*3*straightPathCount);
|
161
|
+
return straightPathCount;
|
162
|
+
}
|
163
|
+
|
164
|
+
extern "C" EXPORT_API float* getPathPtr(int max_paths) {
|
165
|
+
float *path;
|
166
|
+
path = new float[max_paths*3];
|
167
|
+
return path;
|
168
|
+
}
|
169
|
+
|
170
|
+
extern "C" EXPORT_API void freePath(float* path) {
|
171
|
+
delete [] path;
|
172
|
+
}
|
173
|
+
|
174
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
using UnityEngine;
|
3
|
+
using System;
|
4
|
+
using System.Collections.Generic;
|
5
|
+
using System.Runtime.InteropServices;
|
6
|
+
using System.Text;
|
7
|
+
|
8
|
+
namespace pathfinder
|
9
|
+
{
|
10
|
+
public class Pathfinder
|
11
|
+
{
|
12
|
+
public static int maxPaths = 256;
|
13
|
+
private IntPtr query;
|
14
|
+
private bool hasQuery = false;
|
15
|
+
|
16
|
+
|
17
|
+
public Pathfinder (int navmeshId, string navmeshPath)
|
18
|
+
{
|
19
|
+
int navmeshLoadRes = loadNavMesh (navmeshId, navmeshPath);
|
20
|
+
if (navmeshLoadRes == 1 || navmeshLoadRes == 0) {
|
21
|
+
query = getQuery (navmeshId);
|
22
|
+
hasQuery = true;
|
23
|
+
} else {
|
24
|
+
Debug.Log (string.Format ("loadNavMesh returned {0}",navmeshLoadRes));
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
public Vector3[] FindPath (Vector3 start, Vector3 end, bool straight = false)
|
29
|
+
{
|
30
|
+
if (hasQuery == false) {
|
31
|
+
return null;
|
32
|
+
}
|
33
|
+
int straightPath = straight ? 1 : 0;
|
34
|
+
float[,] resultPath = new float[Pathfinder.maxPaths, 3];
|
35
|
+
int numPaths = findPath (query, start.z, start.y, start.x, end.z, end.y, end.x, straightPath, resultPath);
|
36
|
+
|
37
|
+
Vector3[] paths = new Vector3[numPaths];
|
38
|
+
for (int i = 0; i < numPaths; i++) {
|
39
|
+
paths [i] = new Vector3 (resultPath [i, 2], resultPath [i, 1], resultPath [i, 0]);
|
40
|
+
}
|
41
|
+
return paths;
|
42
|
+
}
|
43
|
+
|
44
|
+
[DllImport("detour_path")]
|
45
|
+
public static extern IntPtr getQuery (int map);
|
46
|
+
|
47
|
+
[DllImport("detour_path")]
|
48
|
+
public static extern void freeQuery (IntPtr query);
|
49
|
+
|
50
|
+
[DllImport("detour_path")]
|
51
|
+
public static extern int loadNavMesh (int map, string filename);
|
52
|
+
|
53
|
+
[DllImport("detour_path")]
|
54
|
+
public static extern int findPath (
|
55
|
+
IntPtr query,
|
56
|
+
float startx,
|
57
|
+
float starty,
|
58
|
+
float startz,
|
59
|
+
float endx,
|
60
|
+
float endy,
|
61
|
+
float endz,
|
62
|
+
int find_straight_path,
|
63
|
+
[In, Out] float[,] resultPath
|
64
|
+
);
|
65
|
+
}
|
66
|
+
}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
local action = _ACTION or ""
|
2
|
+
local todir = "build/"
|
3
|
+
|
4
|
+
solution "pathfinding"
|
5
|
+
configurations {
|
6
|
+
"debug",
|
7
|
+
"release"
|
8
|
+
}
|
9
|
+
location (todir)
|
10
|
+
|
11
|
+
-- extra warnings, no exceptions or rtti
|
12
|
+
flags {
|
13
|
+
"ExtraWarnings",
|
14
|
+
"NoExceptions",
|
15
|
+
"NoRTTI"
|
16
|
+
}
|
17
|
+
|
18
|
+
-- debug configs
|
19
|
+
configuration "debug*"
|
20
|
+
defines { "DEBUG" }
|
21
|
+
flags { "Symbols" }
|
22
|
+
|
23
|
+
targetdir ( "build/" .. action .. "/debug" )
|
24
|
+
-- linux library cflags and libs
|
25
|
+
configuration { "linux", "gmake" }
|
26
|
+
buildoptions {
|
27
|
+
"-fpic"
|
28
|
+
}
|
29
|
+
linkoptions {
|
30
|
+
"-fpic"
|
31
|
+
}
|
32
|
+
|
33
|
+
-- windows library cflags and libs
|
34
|
+
configuration { "windows" }
|
35
|
+
|
36
|
+
-- release configs
|
37
|
+
configuration "release*"
|
38
|
+
defines { "NDEBUG" }
|
39
|
+
flags { "Optimize" }
|
40
|
+
targetdir ( "build/" .. action .. "/release" )
|
41
|
+
|
42
|
+
-- windows specific
|
43
|
+
configuration "windows"
|
44
|
+
defines { "WIN32", "_WINDOWS", "_CRT_SECURE_NO_WARNINGS" }
|
45
|
+
|
46
|
+
project "Detour"
|
47
|
+
language "C++"
|
48
|
+
kind "StaticLib"
|
49
|
+
includedirs {
|
50
|
+
"recastnavigation/Detour/Include"
|
51
|
+
}
|
52
|
+
files {
|
53
|
+
"recastnavigation/Detour/Include/*.h",
|
54
|
+
"recastnavigation/Detour/Source/*.cpp"
|
55
|
+
}
|
56
|
+
targetdir (todir .. "/lib")
|
57
|
+
configuration "not windows"
|
58
|
+
postbuildcommands { "cp lib/libDetour.a ../bin" }
|
59
|
+
|
60
|
+
project "detour_path"
|
61
|
+
language "C++"
|
62
|
+
kind "SharedLib"
|
63
|
+
includedirs {
|
64
|
+
"recastnavigation/Detour/Include",
|
65
|
+
"recastnavigation/Recast/Include",
|
66
|
+
"include"
|
67
|
+
}
|
68
|
+
|
69
|
+
libdirs {todir .. "lib" }
|
70
|
+
files {
|
71
|
+
"recastnavigation/Detour/Include/*.h",
|
72
|
+
"recastnavigation/Recast/Include/Recast.h",
|
73
|
+
"recastnavigation/Detour/Source/*.cpp",
|
74
|
+
"include/*.h",
|
75
|
+
"*.cpp"
|
76
|
+
}
|
77
|
+
targetdir (todir .. "/lib")
|
78
|
+
|
79
|
+
-- project dependencies
|
80
|
+
links {
|
81
|
+
"Detour"
|
82
|
+
}
|
83
|
+
configuration "not windows"
|
84
|
+
postbuildcommands { "cp lib/libdetour_path.so ../bin" }
|
85
|
+
|
86
|
+
project "pathfind_test"
|
87
|
+
language "C++"
|
88
|
+
kind "ConsoleApp"
|
89
|
+
includedirs {
|
90
|
+
"recastnavigation/Detour/Include",
|
91
|
+
"recastnavigation/Recast/Include",
|
92
|
+
"include"
|
93
|
+
}
|
94
|
+
libdirs {todir .. "lib" }
|
95
|
+
files {
|
96
|
+
"recastnavigation/Detour/Include/*.h",
|
97
|
+
"recastnavigation/Recast/Include/Recast.h",
|
98
|
+
"recastnavigation/Detour/Source/*.cpp",
|
99
|
+
"include/*.h",
|
100
|
+
"*.cpp"
|
101
|
+
}
|
102
|
+
targetdir (todir .. "/bin")
|
103
|
+
links {
|
104
|
+
"Detour",
|
105
|
+
"detour_path"
|
106
|
+
}
|
107
|
+
configuration "not windows"
|
108
|
+
postbuildcommands { "cp bin/pathfind_test ../bin" }
|
109
|
+
|
data/script/server.sh
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#export LD_PRELOAD=/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/libjsig.so
|
3
|
+
SCRIPT_PATH=`dirname "$0"`; SCRIPT_PATH=`eval "cd \"$SCRIPT_PATH\" && pwd"`
|
4
|
+
SERVER_HOME=$SCRIPT_PATH/../
|
5
|
+
SERVER_LOG=$SERVER_HOME/log
|
6
|
+
SERVER_TMP=$SERVER_HOME/tmp
|
7
|
+
|
8
|
+
mkdir -p $SERVER_LOG
|
9
|
+
mkdir -p $SERVER_TMP
|
10
|
+
|
11
|
+
cd $SERVER_HOME
|
12
|
+
|
13
|
+
#unset GEM_HOME
|
14
|
+
#unset BUNDLE_GEMFILE
|
15
|
+
#unset GEM_PATH
|
16
|
+
CWD=$(pwd)
|
17
|
+
APP_NAME=game_machine
|
18
|
+
|
19
|
+
ERR_FILE=$SERVER_HOME/log/game_machine.stderr
|
20
|
+
OUT_FILE=$SERVER_HOME/log/game_machine.stdout
|
21
|
+
|
22
|
+
PID_PATH=$SERVER_HOME/tmp
|
23
|
+
PID_FILE=$PID_PATH/game_machine.pid
|
24
|
+
mkdir -p $PID_PATH
|
25
|
+
ARGV="$2"
|
26
|
+
|
27
|
+
start_daemon() {
|
28
|
+
if [ -e "$PID_FILE" ]; then
|
29
|
+
echo "PID file already exists."
|
30
|
+
exit 1
|
31
|
+
else
|
32
|
+
if [ -e "./bin/game_machine" ]; then
|
33
|
+
echo "Starting local $APP_NAME with args $ARGV."
|
34
|
+
nohup ./bin/game_machine s -s "$ARGV" 2>> "$ERR_FILE" >> "$OUT_FILE" &
|
35
|
+
else
|
36
|
+
echo "Starting $APP_NAME with args $ARGV."
|
37
|
+
nohup game_machine server "$ARGV" 2>> "$ERR_FILE" >> "$OUT_FILE" &
|
38
|
+
fi
|
39
|
+
echo $! > "$PID_FILE"
|
40
|
+
exit $?
|
41
|
+
fi
|
42
|
+
}
|
43
|
+
|
44
|
+
stop_daemon() {
|
45
|
+
if [ -e "$PID_FILE" ]; then
|
46
|
+
echo "Stopping $APP_NAME."
|
47
|
+
PID=`cat $PID_FILE`
|
48
|
+
for i in 1 2 3 4 5 6 7 8 9 10
|
49
|
+
do
|
50
|
+
if [ "$i" -gt 2 ] ;then
|
51
|
+
echo "Using kill -9"
|
52
|
+
kill -9 $PID 2> /dev/null
|
53
|
+
else
|
54
|
+
kill -TERM $PID 2> /dev/null
|
55
|
+
fi
|
56
|
+
echo "try $i"
|
57
|
+
if [ `ps $PID 2> /dev/null | grep $PID | wc -l` -eq 1 ]; then
|
58
|
+
echo "$APP_NAME still running"
|
59
|
+
else
|
60
|
+
echo "$APP_NAME killed"
|
61
|
+
break;
|
62
|
+
fi
|
63
|
+
sleep 1
|
64
|
+
done
|
65
|
+
rm $PID_FILE
|
66
|
+
else
|
67
|
+
echo "PID file not found."
|
68
|
+
return 1
|
69
|
+
fi
|
70
|
+
}
|
71
|
+
|
72
|
+
check_status() {
|
73
|
+
if [ -e "$PID_FILE" ]; then
|
74
|
+
PID=`cat $PID_FILE`
|
75
|
+
if [ `ps $PID 2> /dev/null | grep $PID | wc -l` -eq 1 ]; then
|
76
|
+
echo "$APP_NAME is running"
|
77
|
+
return 0
|
78
|
+
else
|
79
|
+
echo "$APP_NAME is not running (stale pidfile)"
|
80
|
+
return 3
|
81
|
+
fi
|
82
|
+
fi
|
83
|
+
|
84
|
+
echo "$APP_NAME is not running"
|
85
|
+
return 3
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
case $1 in
|
90
|
+
start)
|
91
|
+
start_daemon
|
92
|
+
;;
|
93
|
+
stop)
|
94
|
+
stop_daemon
|
95
|
+
;;
|
96
|
+
status)
|
97
|
+
check_status
|
98
|
+
;;
|
99
|
+
restart)
|
100
|
+
stop_daemon
|
101
|
+
sleep 1
|
102
|
+
start_daemon
|
103
|
+
;;
|
104
|
+
*)
|
105
|
+
echo "usage: $0 start|stop|restart|status"
|
106
|
+
exit 1
|
107
|
+
;;
|
108
|
+
esac
|
109
|
+
|