game_machine 0.0.11 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +12 -1
- data/Gemfile.lock +32 -47
- data/Rakefile +0 -27
- data/bin/bundle_run.sh +1 -0
- data/bin/game_machine +29 -27
- data/config/cluster.conf +6 -5
- data/config/default.conf +164 -0
- data/config/game_machine.sql +33 -0
- data/config/game_messages.proto +87 -25
- data/config/gamecloud.conf +140 -0
- data/config/messages.proto +46 -53
- data/config/test.conf +149 -0
- data/game_machine.gemspec +10 -5
- data/games/boot.rb +3 -0
- data/games/example/data/game_data.yml +4 -4
- data/games/example/lib/aggressive_npc.rb +1 -1
- data/games/example/lib/game.rb +1 -2
- data/games/example/lib/player_register.rb +1 -1
- data/games/routes.rb +9 -0
- data/games/tutorial/boot.rb +12 -0
- data/games/tutorial/item_manager.rb +256 -0
- data/games/tutorial/object_store.rb +55 -0
- data/games/tutorial/seed.rb +52 -0
- data/games/tutorial/sql_store.rb +30 -0
- data/java/project/build.gradle +134 -0
- data/java/project/component.erb +719 -0
- data/java/{gradle.properties → project/gradle.properties} +1 -1
- data/java/project/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/java/{gradle → project/gradle}/wrapper/gradle-wrapper.properties +2 -2
- data/java/{gradlew → project/gradlew} +0 -0
- data/java/{gradlew.bat → project/gradlew.bat} +0 -0
- data/java/project/local_lib/AdminUi.jar +0 -0
- data/java/{local_lib/protostuff-compiler-1.0.7-jarjar.jar → project/local_lib/protostuff-compiler-1.0.8-jarjar.jar} +0 -0
- data/java/project/local_lib/sigar/libsigar-amd64-freebsd-6.so +0 -0
- data/java/project/local_lib/sigar/libsigar-amd64-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-amd64-solaris.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ia64-hpux-11.sl +0 -0
- data/java/project/local_lib/sigar/libsigar-ia64-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-pa-hpux-11.sl +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc-aix-5.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc64-aix-5.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc64-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-s390x-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-sparc-solaris.so +0 -0
- data/java/project/local_lib/sigar/libsigar-sparc64-solaris.so +0 -0
- data/java/project/local_lib/sigar/libsigar-universal-macosx.dylib +0 -0
- data/java/project/local_lib/sigar/libsigar-universal64-macosx.dylib +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-freebsd-5.so +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-freebsd-6.so +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-solaris.so +0 -0
- data/java/project/local_lib/sigar/sigar-amd64-winnt.dll +0 -0
- data/java/project/local_lib/sigar/sigar-x86-winnt.dll +0 -0
- data/java/project/local_lib/sigar/sigar-x86-winnt.lib +0 -0
- data/java/project/model.erb +99 -0
- data/java/{settings.gradle → project/settings.gradle} +0 -0
- data/java/project/src/main/java/com/game_machine/authentication/DefaultAuthenticator.java +28 -0
- data/java/project/src/main/java/com/game_machine/authentication/PlayerAuthenticator.java +6 -0
- data/java/project/src/main/java/com/game_machine/authentication/PublicAuthenticator.java +20 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/ActorFactory.java +0 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/ActorUtil.java +13 -0
- data/java/project/src/main/java/com/game_machine/core/AuthorizedPlayers.java +23 -0
- data/java/project/src/main/java/com/game_machine/core/ClientMessageDecoder.java +36 -0
- data/java/project/src/main/java/com/game_machine/core/ClientMessageEncoder.java +19 -0
- data/java/project/src/main/java/com/game_machine/core/CloudClient.java +298 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/CommandProxy.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/Commands.java +20 -0
- data/java/project/src/main/java/com/game_machine/core/DatastoreCommands.java +43 -0
- data/java/project/src/main/java/com/game_machine/core/DbConnectionPool.java +72 -0
- data/java/project/src/main/java/com/game_machine/core/DefaultMovementVerifier.java +56 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/EntitySerializer.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/EntityTracking.java +119 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/EventStreamHandler.java +1 -1
- data/java/project/src/main/java/com/game_machine/core/GameActor.java +73 -0
- data/java/project/src/main/java/com/game_machine/core/GameMachineLoader.java +43 -0
- data/java/project/src/main/java/com/game_machine/core/GameMessageActor.java +44 -0
- data/java/project/src/main/java/com/game_machine/core/Grid.java +255 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/GridValue.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/Hashring.java +66 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/IActorFactory.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/LocalLinkedBuffer.java +20 -0
- data/java/project/src/main/java/com/game_machine/core/MessageGateway.java +120 -0
- data/java/project/src/main/java/com/game_machine/core/MessagePersister.java +26 -0
- data/java/project/src/main/java/com/game_machine/core/MonoProxy.java +39 -0
- data/java/project/src/main/java/com/game_machine/core/MovementVerifier.java +7 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/NetMessage.java +10 -6
- data/java/project/src/main/java/com/game_machine/core/PersistentMessage.java +9 -0
- data/java/project/src/main/java/com/game_machine/core/PlayerCommands.java +31 -0
- data/java/project/src/main/java/com/game_machine/core/TcpServer.java +100 -0
- data/java/project/src/main/java/com/game_machine/core/TcpServerHandler.java +54 -0
- data/java/project/src/main/java/com/game_machine/core/TcpServerInitializer.java +32 -0
- data/java/project/src/main/java/com/game_machine/core/UdpClient.java +86 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/UdpServer.java +18 -27
- data/java/{src → project/src}/main/java/com/game_machine/core/UdpServerHandler.java +23 -26
- data/java/project/src/main/java/com/game_machine/core/Vector3.java +159 -0
- data/java/project/src/main/java/com/game_machine/orm/models/PlayerItem.java +118 -0
- data/java/project/src/main/java/com/game_machine/orm/models/TestObject.java +110 -0
- data/java/project/src/main/java/com/game_machine/tutorial/LootGenerator.java +26 -0
- data/java/{src → project/src}/main/resources/game_machine.java.stg +3 -1
- data/java/project/src/main/resources/logback.properties +13 -0
- data/java/project/src/main/resources/logback.xml +76 -0
- data/java/{src → project/src}/main/resources/protostuff.properties +0 -0
- data/java/src/main/java/game/MyGameActor.java +26 -0
- data/lib/game_machine.rb +17 -16
- data/lib/game_machine/actor.rb +1 -1
- data/lib/game_machine/actor/base.rb +8 -31
- data/lib/game_machine/actor/builder.rb +5 -6
- data/lib/game_machine/actor/game_actor.rb +55 -0
- data/lib/game_machine/actor/reloadable.rb +6 -1
- data/lib/game_machine/akka.rb +26 -32
- data/lib/game_machine/app_config.rb +39 -26
- data/lib/game_machine/application.rb +56 -62
- data/lib/game_machine/client_manager.rb +14 -8
- data/lib/game_machine/cloud_updater.rb +51 -0
- data/lib/game_machine/cluster_monitor.rb +3 -3
- data/lib/game_machine/commands.rb +1 -1
- data/lib/game_machine/commands/misc_commands.rb +4 -8
- data/lib/game_machine/commands/player_commands.rb +8 -0
- data/lib/game_machine/console.rb +1 -0
- data/lib/game_machine/console/build.rb +57 -24
- data/lib/game_machine/console/bundle.rb +95 -0
- data/lib/game_machine/console/deploy.rb +30 -0
- data/lib/game_machine/console/install.rb +70 -36
- data/lib/game_machine/console/server.rb +2 -69
- data/lib/game_machine/data_store.rb +111 -15
- data/lib/game_machine/data_stores/couchbase.rb +8 -3
- data/lib/game_machine/data_stores/gamecloud.rb +93 -0
- data/lib/game_machine/data_stores/jdbc.rb +98 -0
- data/lib/game_machine/default_handlers.rb +2 -0
- data/lib/game_machine/default_handlers/team_handler.rb +51 -0
- data/lib/game_machine/default_handlers/zone_manager.rb +30 -0
- data/lib/game_machine/endpoints.rb +0 -4
- data/lib/game_machine/endpoints/udp_incoming.rb +13 -5
- data/lib/game_machine/endpoints/udp_outgoing.rb +15 -9
- data/lib/game_machine/game_systems.rb +0 -2
- data/lib/game_machine/game_systems/agents/controller.rb +2 -2
- data/lib/game_machine/game_systems/entity_tracking.rb +0 -3
- data/lib/game_machine/game_systems/region_manager.rb +3 -2
- data/lib/game_machine/game_systems/region_service.rb +2 -2
- data/lib/game_machine/game_systems/remote_echo.rb +10 -0
- data/lib/game_machine/game_systems/team_manager.rb +2 -11
- data/lib/game_machine/grid.rb +5 -18
- data/lib/game_machine/handlers/authentication.rb +1 -9
- data/lib/game_machine/handlers/game.rb +27 -2
- data/lib/game_machine/handlers/player_authentication.rb +87 -0
- data/lib/game_machine/handlers/request.rb +9 -11
- data/lib/game_machine/hocon_config.rb +81 -0
- data/lib/game_machine/java_lib.rb +14 -1
- data/lib/game_machine/logger.rb +10 -23
- data/lib/game_machine/models.rb +1 -0
- data/lib/game_machine/mono_server.rb +6 -1
- data/lib/game_machine/object_db.rb +12 -6
- data/lib/game_machine/protobuf.rb +1 -1
- data/lib/game_machine/protobuf/game_messages.rb +13 -3
- data/lib/game_machine/protobuf/generate.rb +107 -5
- data/lib/game_machine/restart_watcher.rb +1 -1
- data/lib/game_machine/routes.rb +23 -0
- data/lib/game_machine/scheduler.rb +1 -1
- data/lib/game_machine/securerandom.rb +2 -0
- data/lib/game_machine/system_stats.rb +28 -7
- data/lib/game_machine/version.rb +1 -1
- data/lib/game_machine/wavefront_ext.rb +47 -0
- data/lib/game_machine/write_behind_cache.rb +24 -9
- data/mono/server/Makefile +1 -1
- data/mono/server/Newtonsoft.Json.dll +0 -0
- data/mono/server/build.bat +1 -1
- data/mono/server/callable.cs +9 -0
- data/mono/server/echo.cs +17 -0
- data/mono/server/message_router.cs +16 -23
- data/mono/server/messages.cs +1792 -417
- data/mono/server/protobuf-net.dll +0 -0
- data/mono/server/server.cs +120 -0
- data/mono/server/server.exe +0 -0
- data/pathfinding/astar.cpp +149 -0
- data/pathfinding/build.sh +6 -0
- data/pathfinding/build.txt +16 -0
- data/pathfinding/crowd.cpp +194 -0
- data/pathfinding/include/astar.h +49 -0
- data/pathfinding/include/common.h +5 -0
- data/pathfinding/include/crowd.h +43 -0
- data/pathfinding/include/micropather.h +511 -0
- data/pathfinding/include/navmesh.h +114 -0
- data/pathfinding/include/pathfinder.h +24 -0
- data/pathfinding/main.cpp +108 -17
- data/pathfinding/micropather.cpp +1062 -0
- data/pathfinding/navmesh.cpp +408 -0
- data/pathfinding/overrides/DetourCrowd.cpp +1446 -0
- data/pathfinding/overrides/DetourNavMeshQuery.cpp +3551 -0
- data/pathfinding/overrides/DetourNavMeshQuery.h +538 -0
- data/pathfinding/pathfinder.cpp +117 -0
- data/pathfinding/{bin → premake}/premake4 +0 -0
- data/pathfinding/premake/premake4.exe +0 -0
- data/pathfinding/premake4.lua +12 -3
- data/spec/actor/actor_spec.rb +0 -7
- data/spec/client_manager_spec.rb +1 -1
- data/spec/couchproxy_spec.rb +38 -0
- data/spec/entity_persistence_spec.rb +129 -0
- data/spec/game_systems/team_manager_spec.rb +2 -2
- data/spec/hashring_spec.rb +17 -39
- data/spec/java_grid_spec.rb +0 -2
- data/spec/misc_spec.rb +111 -0
- data/spec/mono_spec.rb +50 -3
- data/spec/reliable_message_spec.rb +38 -0
- data/spec/spec_helper.rb +4 -4
- data/spec/spec_helper_minimal.rb +10 -0
- data/web/app.rb +108 -86
- data/web/config/trinidad.yml +1 -0
- data/web/views/add_player.erb +25 -0
- data/web/views/index.erb +0 -0
- data/web/views/layout.erb +48 -0
- data/web/views/login.erb +25 -0
- data/web/views/players.erb +24 -0
- metadata +209 -94
- data/config/config.example.yml +0 -100
- data/config/regions.example.yml +0 -9
- data/games/example/lib/authentication_handler.rb +0 -69
- data/games/models.rb +0 -3
- data/games/models/clan_member.rb +0 -8
- data/games/models/clan_profile.rb +0 -9
- data/games/models/player.rb +0 -7
- data/games/plugins.rb +0 -1
- data/games/plugins/team_handler.rb +0 -49
- data/games/preload.rb +0 -13
- data/java/.gitignore +0 -1
- data/java/build.gradle +0 -95
- data/java/component.erb +0 -396
- data/java/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/java/src/main/java/com/game_machine/core/GameMachineLoader.java +0 -25
- data/java/src/main/java/com/game_machine/core/Grid.java +0 -195
- data/java/src/main/resources/logback.xml +0 -14
- data/java/src/main/resources/logging.properties +0 -3
- data/lib/game_machine/actor/mono_actor.rb +0 -89
- data/lib/game_machine/auth_handlers/base.rb +0 -21
- data/lib/game_machine/auth_handlers/public.rb +0 -34
- data/lib/game_machine/endpoints/mono_gateway.rb +0 -87
- data/lib/game_machine/endpoints/tcp.rb +0 -51
- data/lib/game_machine/endpoints/tcp_handler.rb +0 -75
- data/lib/game_machine/endpoints/udp.rb +0 -88
- data/lib/game_machine/game_loader.rb +0 -46
- data/lib/game_machine/game_systems/region_settings.rb +0 -13
- data/lib/game_machine/hashring.rb +0 -48
- data/lib/game_machine/settings.rb +0 -11
- data/mono/server/actor.cs +0 -37
- data/mono/server/iactor.cs +0 -11
- data/mono/server/message_util.cs +0 -29
- data/mono/server/proxy_client.cs +0 -73
- data/mono/server/proxy_server.cs +0 -30
- data/mono/server/test_actor.cs +0 -33
- data/pathfinding/include/pathfind.h +0 -167
- data/pathfinding/pathfind.cpp +0 -174
- data/pathfinding/pathfinder.cs +0 -66
- data/script/server.sh +0 -109
- data/script/watch.sh +0 -11
- data/spec/commands/navigation_commands_spec.rb +0 -51
- data/spec/game_systems/entity_tracking_spec.rb +0 -64
- data/spec/navigation/detour_navmesh_spec.rb +0 -34
- data/spec/navigation/detour_path_spec.rb +0 -25
- data/spec/udp_server_spec.rb +0 -10
- data/web/controllers/auth_controller.rb +0 -19
- data/web/controllers/base_controller.rb +0 -16
- data/web/controllers/index_controller.rb +0 -7
- data/web/controllers/log_controller.rb +0 -47
- data/web/controllers/messages_controller.rb +0 -59
- data/web/controllers/player_register_controller.rb +0 -15
- data/web/views/game_messages.haml +0 -45
- data/web/views/index.haml +0 -6
- data/web/views/layout.haml +0 -41
- data/web/views/logs.haml +0 -32
- data/web/views/player_register.haml +0 -22
- data/web/views/player_registered.haml +0 -2
- data/web/views/register_layout.haml +0 -22
- data/web/views/restart.haml +0 -35
Binary file
|
@@ -0,0 +1,120 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Net;
|
3
|
+
using System.Net.Sockets;
|
4
|
+
using System.Text;
|
5
|
+
using System.Threading;
|
6
|
+
using System.Threading.Tasks;
|
7
|
+
using System.IO;
|
8
|
+
using ProtoBuf;
|
9
|
+
using GameMachine;
|
10
|
+
using NLog;
|
11
|
+
using MonoMessage = GameMachine.Messages.MonoMessage;
|
12
|
+
using Entity = GameMachine.Messages.Entity;
|
13
|
+
|
14
|
+
namespace GameMachine
|
15
|
+
{
|
16
|
+
public class DataPacket
|
17
|
+
{
|
18
|
+
public Socket sock;
|
19
|
+
public byte[] buf;
|
20
|
+
public EndPoint ep;
|
21
|
+
|
22
|
+
public DataPacket(Socket sock, byte[] buf, EndPoint ep)
|
23
|
+
{
|
24
|
+
this.sock = sock;
|
25
|
+
this.buf = buf;
|
26
|
+
this.ep = ep;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
public class Server
|
31
|
+
{
|
32
|
+
|
33
|
+
public static int port = 24320;
|
34
|
+
public static Logger logger = LogManager.GetLogger("GameMachine");
|
35
|
+
private Socket server;
|
36
|
+
private MessageRouter router;
|
37
|
+
|
38
|
+
static void Main(string[] args)
|
39
|
+
{
|
40
|
+
Server server = new Server();
|
41
|
+
server.Run();
|
42
|
+
|
43
|
+
Server.logger.Info("Server Starting");
|
44
|
+
Console.WriteLine("Press any key to exit.");
|
45
|
+
Console.ReadLine();
|
46
|
+
}
|
47
|
+
|
48
|
+
public void Run()
|
49
|
+
{
|
50
|
+
router = new MessageRouter();
|
51
|
+
server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
52
|
+
server.Bind(new IPEndPoint(IPAddress.Loopback, port));
|
53
|
+
|
54
|
+
for (int i=0; i<5; i++)
|
55
|
+
{
|
56
|
+
BeginReceive();
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
private void BeginReceive()
|
61
|
+
{
|
62
|
+
byte[] buffer = new byte[4096];
|
63
|
+
EndPoint ep = (EndPoint)new IPEndPoint(IPAddress.Loopback, 0);
|
64
|
+
DataPacket packet = new DataPacket(server, buffer, ep);
|
65
|
+
server.BeginReceiveFrom(packet.buf, 0, packet.buf.Length, SocketFlags.None, ref packet.ep, new AsyncCallback(Received), packet);
|
66
|
+
}
|
67
|
+
|
68
|
+
private void Received(IAsyncResult iar)
|
69
|
+
{
|
70
|
+
try
|
71
|
+
{
|
72
|
+
DataPacket packet = (DataPacket)iar.AsyncState;
|
73
|
+
int msgLen = packet.sock.EndReceiveFrom(iar, ref packet.ep);
|
74
|
+
byte[] localMsg = new byte[msgLen];
|
75
|
+
Array.Copy(packet.buf, localMsg, msgLen);
|
76
|
+
|
77
|
+
server.BeginReceiveFrom(packet.buf, 0, packet.buf.Length, SocketFlags.None, ref packet.ep, new AsyncCallback(Received), packet);
|
78
|
+
|
79
|
+
Task.Factory.StartNew(() => {
|
80
|
+
MonoMessage monoMessage = ByteArrayToMonoMessage(localMsg);
|
81
|
+
monoMessage.entity = router.Route(monoMessage.klass, monoMessage.entity);
|
82
|
+
byte[] bytes = MonoMessageToByteArray(monoMessage);
|
83
|
+
server.BeginSendTo(bytes, 0, bytes.Length, SocketFlags.None, packet.ep, new AsyncCallback(Sent), packet.ep);
|
84
|
+
});
|
85
|
+
|
86
|
+
} catch (ObjectDisposedException e)
|
87
|
+
{
|
88
|
+
Console.WriteLine(e.Message);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
public void Sent(IAsyncResult ar)
|
93
|
+
{
|
94
|
+
try
|
95
|
+
{
|
96
|
+
server.EndSend(ar);
|
97
|
+
} catch (Exception ex)
|
98
|
+
{
|
99
|
+
Console.WriteLine(ex.Message);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
public static MonoMessage ByteArrayToMonoMessage(byte[] bytes)
|
104
|
+
{
|
105
|
+
MonoMessage monoMessage;
|
106
|
+
MemoryStream stream = new MemoryStream(bytes);
|
107
|
+
monoMessage = Serializer.Deserialize<MonoMessage>(stream);
|
108
|
+
return monoMessage;
|
109
|
+
}
|
110
|
+
|
111
|
+
public static byte[] MonoMessageToByteArray(MonoMessage monoMessage)
|
112
|
+
{
|
113
|
+
byte[] data;
|
114
|
+
MemoryStream stream = new MemoryStream();
|
115
|
+
Serializer.Serialize(stream, monoMessage);
|
116
|
+
data = stream.ToArray();
|
117
|
+
return data;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
Binary file
|
@@ -0,0 +1,149 @@
|
|
1
|
+
#include <map>
|
2
|
+
|
3
|
+
#include "astar.h"
|
4
|
+
using namespace std;
|
5
|
+
|
6
|
+
Astar::Astar(int a, int b) : width(a), height(b), gmap(width*height+1), pather(0)
|
7
|
+
{
|
8
|
+
pather = new MicroPather( this, 100);
|
9
|
+
}
|
10
|
+
|
11
|
+
void Astar::setPassable(int x, int y)
|
12
|
+
{
|
13
|
+
gmap[ y*width + x] = '\0';
|
14
|
+
}
|
15
|
+
|
16
|
+
void Astar::setBlocked(int x, int y)
|
17
|
+
{
|
18
|
+
gmap[ y*width + x] = 'D';
|
19
|
+
}
|
20
|
+
|
21
|
+
int Astar::Passable( int nx, int ny )
|
22
|
+
{
|
23
|
+
if ( nx >= 0 && nx < width
|
24
|
+
&& ny >= 0 && ny < height )
|
25
|
+
{
|
26
|
+
int index = ny*width+nx;
|
27
|
+
char c = gmap[ index ];
|
28
|
+
if ( c == '\0' )
|
29
|
+
return 1;
|
30
|
+
else if ( c == 'D' )
|
31
|
+
return 2;
|
32
|
+
}
|
33
|
+
return 0;
|
34
|
+
}
|
35
|
+
|
36
|
+
void Astar::ClearPath()
|
37
|
+
{
|
38
|
+
path.resize( 0 );
|
39
|
+
pather->Reset();
|
40
|
+
}
|
41
|
+
|
42
|
+
int Astar::findPath(int startx, int starty, int endx, int endy)
|
43
|
+
{
|
44
|
+
int result = 0;
|
45
|
+
float totalCost;
|
46
|
+
|
47
|
+
if (Passable(startx,starty) && Passable(endx,endy))
|
48
|
+
{
|
49
|
+
result = pather->Solve( XYToNode( startx, starty ), XYToNode( endx, endy ), &path, &totalCost );
|
50
|
+
if ( result == MicroPather::SOLVED ) {
|
51
|
+
return path.size();
|
52
|
+
}
|
53
|
+
}
|
54
|
+
return result;
|
55
|
+
}
|
56
|
+
|
57
|
+
void Astar::NodeToXY( void* node, int* x, int* y )
|
58
|
+
{
|
59
|
+
intptr_t index = (intptr_t)node;
|
60
|
+
*y = index / width;
|
61
|
+
*x = index - *y * width;
|
62
|
+
}
|
63
|
+
|
64
|
+
void* Astar::XYToNode( int x, int y )
|
65
|
+
{
|
66
|
+
return (void*) ( y*width + x );
|
67
|
+
}
|
68
|
+
|
69
|
+
int Astar::getYAt(int i)
|
70
|
+
{
|
71
|
+
int y;
|
72
|
+
intptr_t index = (intptr_t)path[i];
|
73
|
+
y = index / width;
|
74
|
+
return y;
|
75
|
+
}
|
76
|
+
|
77
|
+
int Astar::getXAt(int i)
|
78
|
+
{
|
79
|
+
int x,y;
|
80
|
+
intptr_t index = (intptr_t)path[i];
|
81
|
+
y = index / width;
|
82
|
+
x = index - y * width;
|
83
|
+
return x;
|
84
|
+
}
|
85
|
+
|
86
|
+
float Astar::LeastCostEstimate( void* nodeStart, void* nodeEnd )
|
87
|
+
{
|
88
|
+
int xStart, yStart, xEnd, yEnd;
|
89
|
+
NodeToXY( nodeStart, &xStart, &yStart );
|
90
|
+
NodeToXY( nodeEnd, &xEnd, &yEnd );
|
91
|
+
|
92
|
+
/* Compute the minimum path cost using distance measurement. It is possible
|
93
|
+
to compute the exact minimum path using the fact that you can move only
|
94
|
+
on a straight line or on a diagonal, and this will yield a better result.
|
95
|
+
*/
|
96
|
+
int dx = xStart - xEnd;
|
97
|
+
int dy = yStart - yEnd;
|
98
|
+
return (float) sqrt( (double)(dx*dx) + (double)(dy*dy) );
|
99
|
+
}
|
100
|
+
|
101
|
+
void Astar::AdjacentCost( void* node, micropather::MPVector< StateCost > *neighbors )
|
102
|
+
{
|
103
|
+
int x, y;
|
104
|
+
const int dx[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
|
105
|
+
const int dy[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
|
106
|
+
const float cost[8] = { 1.0f, 1.41f, 1.0f, 1.41f, 1.0f, 1.41f, 1.0f, 1.41f };
|
107
|
+
|
108
|
+
NodeToXY( node, &x, &y );
|
109
|
+
|
110
|
+
for( int i=0; i<8; ++i ) {
|
111
|
+
int nx = x + dx[i];
|
112
|
+
int ny = y + dy[i];
|
113
|
+
|
114
|
+
int pass = Passable( nx, ny );
|
115
|
+
if ( pass > 0 ) {
|
116
|
+
if ( pass == 1)
|
117
|
+
{
|
118
|
+
// Normal floor
|
119
|
+
StateCost nodeCost = { XYToNode( nx, ny ), cost[i] };
|
120
|
+
neighbors->push_back( nodeCost );
|
121
|
+
}
|
122
|
+
else
|
123
|
+
{
|
124
|
+
// Normal floor
|
125
|
+
StateCost nodeCost = { XYToNode( nx, ny ), FLT_MAX };
|
126
|
+
neighbors->push_back( nodeCost );
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
void Astar::PrintStateInfo( void* node )
|
133
|
+
{
|
134
|
+
int x, y;
|
135
|
+
NodeToXY( node, &x, &y );
|
136
|
+
printf( "(%d,%d)", x, y );
|
137
|
+
}
|
138
|
+
|
139
|
+
void Astar::Print()
|
140
|
+
{
|
141
|
+
unsigned k;
|
142
|
+
// Wildly inefficient demo code.
|
143
|
+
unsigned size = path.size();
|
144
|
+
for( k=0; k<size; ++k ) {
|
145
|
+
int x, y;
|
146
|
+
NodeToXY( path[k], &x, &y );
|
147
|
+
fprintf (stderr, "%d.%d\n", x,y);
|
148
|
+
}
|
149
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
First you need to clone recastnavigation into the pathfinding folder.
|
3
|
+
|
4
|
+
There are premake4 binaries for linux and windows in the premake folder.
|
5
|
+
|
6
|
+
Run one of the premake binaries with the options for your OS. This should give you a build folder. For windows open the sln and build. For linux cd to the build folder and type 'make'.
|
7
|
+
|
8
|
+
The linux build will copy the libraries to the bin folder which is where game machine expects to find them. On windows you will need to copy them there manually.
|
9
|
+
|
10
|
+
pathfinding.cs is a wrapper around the dll for windows that can be used in Unity (or any C# game engine). Note that the query methods have coordinate mappings where we swap x and z. This is so it works correctly with our own obj export. Feel free to change that if needed. This is the C# code, native code always uses recast coordinates.
|
11
|
+
|
12
|
+
The dll provides simple functionality for loading navigation meshes and performing pathfinding queries. pathfinding.cs is a good reference for how to use it.
|
13
|
+
|
14
|
+
In ruby the Navigation module has several classes for working with navigation meshes and doing queries. It uses the ruby FFI to call the library.
|
15
|
+
|
16
|
+
Also, look at clients/unity/GameMachine/Editor/ExportScene.cs which is an obj file exporter that can export terrain + object meshes to a single obj file that recastdemo can use.
|
@@ -0,0 +1,194 @@
|
|
1
|
+
#include "crowd.h"
|
2
|
+
using namespace std;
|
3
|
+
|
4
|
+
Crowd::Crowd(Navmesh* n)
|
5
|
+
|
6
|
+
{
|
7
|
+
navmesh = n;
|
8
|
+
crowd = dtAllocCrowd();
|
9
|
+
|
10
|
+
nav = navmesh->getMesh();
|
11
|
+
|
12
|
+
crowd->init(MAX_AGENTS, 0.6f, nav);
|
13
|
+
|
14
|
+
// Make polygons with 'disabled' flag invalid.
|
15
|
+
crowd->getEditableFilter(0)->setExcludeFlags(navmesh->SAMPLE_POLYFLAGS_DISABLED);
|
16
|
+
|
17
|
+
// Setup local avoidance params to different qualities.
|
18
|
+
dtObstacleAvoidanceParams params;
|
19
|
+
// Use mostly default settings, copy from dtCrowd.
|
20
|
+
memcpy(¶ms, crowd->getObstacleAvoidanceParams(0), sizeof(dtObstacleAvoidanceParams));
|
21
|
+
|
22
|
+
// Low (11)
|
23
|
+
params.velBias = 0.5f;
|
24
|
+
params.adaptiveDivs = 5;
|
25
|
+
params.adaptiveRings = 2;
|
26
|
+
params.adaptiveDepth = 1;
|
27
|
+
crowd->setObstacleAvoidanceParams(0, ¶ms);
|
28
|
+
|
29
|
+
// Medium (22)
|
30
|
+
params.velBias = 0.5f;
|
31
|
+
params.adaptiveDivs = 5;
|
32
|
+
params.adaptiveRings = 2;
|
33
|
+
params.adaptiveDepth = 2;
|
34
|
+
crowd->setObstacleAvoidanceParams(1, ¶ms);
|
35
|
+
|
36
|
+
// Good (45)
|
37
|
+
params.velBias = 0.5f;
|
38
|
+
params.adaptiveDivs = 7;
|
39
|
+
params.adaptiveRings = 2;
|
40
|
+
params.adaptiveDepth = 3;
|
41
|
+
crowd->setObstacleAvoidanceParams(2, ¶ms);
|
42
|
+
|
43
|
+
// High (66)
|
44
|
+
params.velBias = 0.5f;
|
45
|
+
params.adaptiveDivs = 7;
|
46
|
+
params.adaptiveRings = 3;
|
47
|
+
params.adaptiveDepth = 3;
|
48
|
+
|
49
|
+
crowd->setObstacleAvoidanceParams(3, ¶ms);
|
50
|
+
|
51
|
+
memset(m_trails, 0, sizeof(m_trails));
|
52
|
+
|
53
|
+
m_vod = dtAllocObstacleAvoidanceDebugData();
|
54
|
+
m_vod->init(2048);
|
55
|
+
|
56
|
+
memset(&m_agentDebug, 0, sizeof(m_agentDebug));
|
57
|
+
m_agentDebug.idx = -1;
|
58
|
+
m_agentDebug.vod = m_vod;
|
59
|
+
fprintf (stderr, "Crowd initialized\n");
|
60
|
+
}
|
61
|
+
|
62
|
+
int Crowd::addAgent(const float* p, float accel, float speed, float radius, float height, int optflag, float sepWeight)
|
63
|
+
{
|
64
|
+
dtCrowdAgentParams ap;
|
65
|
+
memset(&ap, 0, sizeof(ap));
|
66
|
+
ap.radius = radius;
|
67
|
+
ap.height = height;
|
68
|
+
ap.maxAcceleration = accel;
|
69
|
+
ap.maxSpeed = speed;
|
70
|
+
ap.collisionQueryRange = ap.radius * 12.0f;
|
71
|
+
ap.pathOptimizationRange = ap.radius * 30.0f;
|
72
|
+
ap.updateFlags = 0;
|
73
|
+
ap.updateFlags |= DT_CROWD_ANTICIPATE_TURNS;
|
74
|
+
ap.updateFlags |= DT_CROWD_OPTIMIZE_VIS;
|
75
|
+
ap.updateFlags |= DT_CROWD_OPTIMIZE_TOPO;
|
76
|
+
ap.updateFlags |= DT_CROWD_OBSTACLE_AVOIDANCE;
|
77
|
+
ap.updateFlags |= DT_CROWD_SEPARATION;
|
78
|
+
|
79
|
+
ap.obstacleAvoidanceType = (unsigned char)3.0f;
|
80
|
+
ap.separationWeight = sepWeight;
|
81
|
+
|
82
|
+
int idx = crowd->addAgent(p, &ap);
|
83
|
+
if (idx != -1)
|
84
|
+
{
|
85
|
+
if (m_targetRef)
|
86
|
+
crowd->requestMoveTarget(idx, m_targetRef, m_targetPos);
|
87
|
+
|
88
|
+
// Init trail
|
89
|
+
AgentTrail* trail = &m_trails[idx];
|
90
|
+
for (int i = 0; i < AGENT_MAX_TRAIL; ++i)
|
91
|
+
dtVcopy(&trail->trail[i*3], p);
|
92
|
+
trail->htrail = 0;
|
93
|
+
}
|
94
|
+
return idx;
|
95
|
+
}
|
96
|
+
|
97
|
+
void Crowd::removeAgent(const int idx)
|
98
|
+
{
|
99
|
+
crowd->removeAgent(idx);
|
100
|
+
}
|
101
|
+
|
102
|
+
static void calcVel(float* vel, const float* pos, const float* tgt, const float speed)
|
103
|
+
{
|
104
|
+
dtVsub(vel, tgt, pos);
|
105
|
+
vel[1] = 0.0;
|
106
|
+
dtVnormalize(vel);
|
107
|
+
dtVscale(vel, vel, speed);
|
108
|
+
}
|
109
|
+
|
110
|
+
dtCrowd* Crowd::getCrowd()
|
111
|
+
{
|
112
|
+
return crowd;
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
void Crowd::setMoveTarget(const float* p, bool adjust, int agentIdx)
|
117
|
+
{
|
118
|
+
|
119
|
+
// Find nearest point on navmesh and set move request to that location.
|
120
|
+
dtNavMeshQuery* navquery = dtAllocNavMeshQuery();
|
121
|
+
navquery->init(nav, 4096);
|
122
|
+
|
123
|
+
myQueryFilter filter;
|
124
|
+
filter.setNavmesh(navmesh);
|
125
|
+
filter.setIncludeFlags(navmesh->SAMPLE_POLYFLAGS_ALL ^ navmesh->SAMPLE_POLYFLAGS_DISABLED);
|
126
|
+
filter.setExcludeFlags(0);
|
127
|
+
const float* ext = crowd->getQueryExtents();
|
128
|
+
|
129
|
+
if (adjust)
|
130
|
+
{
|
131
|
+
float vel[3];
|
132
|
+
// Request velocity
|
133
|
+
if (agentIdx != -1)
|
134
|
+
{
|
135
|
+
const dtCrowdAgent* ag = crowd->getAgent(agentIdx);
|
136
|
+
if (ag && ag->active)
|
137
|
+
{
|
138
|
+
calcVel(vel, ag->npos, p, ag->params.maxSpeed);
|
139
|
+
crowd->requestMoveVelocity(agentIdx, vel);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
else
|
143
|
+
{
|
144
|
+
for (int i = 0; i < crowd->getAgentCount(); ++i)
|
145
|
+
{
|
146
|
+
const dtCrowdAgent* ag = crowd->getAgent(i);
|
147
|
+
if (!ag->active) continue;
|
148
|
+
calcVel(vel, ag->npos, p, ag->params.maxSpeed);
|
149
|
+
crowd->requestMoveVelocity(i, vel);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
else
|
154
|
+
{
|
155
|
+
navquery->findNearestPoly(p, ext, &filter, &m_targetRef, m_targetPos);
|
156
|
+
|
157
|
+
if (agentIdx != -1)
|
158
|
+
{
|
159
|
+
const dtCrowdAgent* ag = crowd->getAgent(agentIdx);
|
160
|
+
if (ag && ag->active)
|
161
|
+
crowd->requestMoveTarget(agentIdx, m_targetRef, m_targetPos);
|
162
|
+
}
|
163
|
+
else
|
164
|
+
{
|
165
|
+
for (int i = 0; i < crowd->getAgentCount(); ++i)
|
166
|
+
{
|
167
|
+
const dtCrowdAgent* ag = crowd->getAgent(i);
|
168
|
+
if (!ag->active) continue;
|
169
|
+
crowd->requestMoveTarget(i, m_targetRef, m_targetPos);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
void Crowd::updateTick(const float dt)
|
176
|
+
{
|
177
|
+
crowd->update(dt, &m_agentDebug);
|
178
|
+
|
179
|
+
// Update agent trails
|
180
|
+
for (int i = 0; i < crowd->getAgentCount(); ++i)
|
181
|
+
{
|
182
|
+
const dtCrowdAgent* ag = crowd->getAgent(i);
|
183
|
+
AgentTrail* trail = &m_trails[i];
|
184
|
+
if (!ag->active)
|
185
|
+
continue;
|
186
|
+
// Update agent movement trail.
|
187
|
+
trail->htrail = (trail->htrail + 1) % AGENT_MAX_TRAIL;
|
188
|
+
dtVcopy(&trail->trail[trail->htrail*3], ag->npos);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|