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
data/mono/server/proxy_server.cs
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
using System;
|
2
|
-
using System.Diagnostics;
|
3
|
-
using System.Net;
|
4
|
-
using System.Net.Sockets;
|
5
|
-
using System.Text;
|
6
|
-
using System.Threading;
|
7
|
-
using System.Threading.Tasks;
|
8
|
-
using System.IO;
|
9
|
-
using ProtoBuf;
|
10
|
-
using GameMachine;
|
11
|
-
using NLog;
|
12
|
-
|
13
|
-
namespace GameMachine
|
14
|
-
{
|
15
|
-
public class ProxyServer
|
16
|
-
{
|
17
|
-
|
18
|
-
public static Logger logger = LogManager.GetLogger("GameMachine");
|
19
|
-
static void Main(string[] args)
|
20
|
-
{
|
21
|
-
ProxyClient proxyClient = new ProxyClient(Int32.Parse(args[0]));
|
22
|
-
proxyClient.Start();
|
23
|
-
|
24
|
-
ProxyServer.logger.Info("Proxy Starting");
|
25
|
-
Console.WriteLine("Press any key to exit.");
|
26
|
-
Console.ReadLine();
|
27
|
-
}
|
28
|
-
|
29
|
-
}
|
30
|
-
}
|
data/mono/server/test_actor.cs
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
using System;
|
2
|
-
using System.Text;
|
3
|
-
using System.IO;
|
4
|
-
using System.Threading;
|
5
|
-
using System.Runtime.InteropServices;
|
6
|
-
using ProtoBuf;
|
7
|
-
using System.Collections.Generic;
|
8
|
-
using Entity = GameMachine.Messages.Entity;
|
9
|
-
using GameMachine;
|
10
|
-
|
11
|
-
namespace GameMachine
|
12
|
-
{
|
13
|
-
public class TestActor : GameMachine.Actor
|
14
|
-
{
|
15
|
-
|
16
|
-
public TestActor()
|
17
|
-
{
|
18
|
-
}
|
19
|
-
|
20
|
-
public override void OnReceive(object message)
|
21
|
-
{
|
22
|
-
try
|
23
|
-
{
|
24
|
-
Entity entity = message as Entity;
|
25
|
-
Tell("/GameMachine/GameSystems/Devnull", entity);
|
26
|
-
} catch (Exception ex)
|
27
|
-
{
|
28
|
-
ProxyServer.logger.Info(ex);
|
29
|
-
}
|
30
|
-
|
31
|
-
}
|
32
|
-
}
|
33
|
-
}
|
@@ -1,167 +0,0 @@
|
|
1
|
-
#define _USE_MATH_DEFINES
|
2
|
-
#include <math.h>
|
3
|
-
#include <stdio.h>
|
4
|
-
#include <stdlib.h>
|
5
|
-
#include <string.h>
|
6
|
-
#include "Recast.h"
|
7
|
-
#include "DetourCommon.h"
|
8
|
-
#include "DetourNavMesh.h"
|
9
|
-
#include "DetourNavMeshBuilder.h"
|
10
|
-
#include "DetourNavMeshQuery.h"
|
11
|
-
#include "mesh_loader.h"
|
12
|
-
|
13
|
-
#if _MSC_VER // TRUE for Microsoft compiler.
|
14
|
-
#define EXPORT_API __declspec(dllexport) // Required for VC++
|
15
|
-
#else
|
16
|
-
#define EXPORT_API // Otherwise don't define.
|
17
|
-
#endif
|
18
|
-
|
19
|
-
#define VERTEX_SIZE 3
|
20
|
-
#define INVALID_POLYREF 0
|
21
|
-
|
22
|
-
static const int P_FAILURE = -1;
|
23
|
-
static const int P_NO_START_POLY = -2;
|
24
|
-
static const int P_NO_END_POLY = -3;
|
25
|
-
static const int P_PATH_NOT_FOUND = -4;
|
26
|
-
static const int P_MESH_NOT_FOUND = -5;
|
27
|
-
static const int P_QUERY_NOT_FOUND = -6;
|
28
|
-
|
29
|
-
static dtNavMesh* meshes[1024];
|
30
|
-
static dtNavMeshQuery* queries[4096];
|
31
|
-
static const int MAX_POLYS = 256;
|
32
|
-
static const int MAX_STEER_POINTS = 10;
|
33
|
-
static const int MAX_SMOOTH = 256;
|
34
|
-
static const float STEP_SIZE = 0.5f;
|
35
|
-
static const float SLOP = 0.01f;
|
36
|
-
|
37
|
-
extern "C" EXPORT_API int loadNavMesh(int map, const char *file);
|
38
|
-
|
39
|
-
extern "C" EXPORT_API dtNavMeshQuery* getQuery(int map);
|
40
|
-
|
41
|
-
extern "C" void EXPORT_API freeQuery(dtNavMeshQuery* query);
|
42
|
-
|
43
|
-
extern "C" EXPORT_API int findPath(dtNavMeshQuery* query, float startx,
|
44
|
-
float starty, float startz, float endx, float endy, float endz,
|
45
|
-
int find_straight_path, float* resultPath);
|
46
|
-
|
47
|
-
extern "C" EXPORT_API float* getPathPtr(int max_paths);
|
48
|
-
|
49
|
-
extern "C" EXPORT_API void freePath(float* path);
|
50
|
-
|
51
|
-
enum SamplePolyFlags
|
52
|
-
{
|
53
|
-
SAMPLE_POLYFLAGS_WALK = 0x01, // Ability to walk (ground, grass, road)
|
54
|
-
SAMPLE_POLYFLAGS_SWIM = 0x02, // Ability to swim (water).
|
55
|
-
SAMPLE_POLYFLAGS_DOOR = 0x04, // Ability to move through doors.
|
56
|
-
SAMPLE_POLYFLAGS_JUMP = 0x08, // Ability to jump.
|
57
|
-
SAMPLE_POLYFLAGS_DISABLED = 0x10, // Disabled polygon
|
58
|
-
SAMPLE_POLYFLAGS_ALL = 0xffff // All abilities.
|
59
|
-
};
|
60
|
-
|
61
|
-
|
62
|
-
// Returns a random number [0..1)
|
63
|
-
static float frand()
|
64
|
-
{
|
65
|
-
// return ((float)(rand() & 0xffff)/(float)0xffff);
|
66
|
-
return (float)rand()/(float)RAND_MAX;
|
67
|
-
}
|
68
|
-
|
69
|
-
inline bool inRange(const float* v1, const float* v2, const float r, const float h)
|
70
|
-
{
|
71
|
-
const float dx = v2[0] - v1[0];
|
72
|
-
const float dy = v2[1] - v1[1];
|
73
|
-
const float dz = v2[2] - v1[2];
|
74
|
-
return (dx*dx + dz*dz) < r*r && fabsf(dy) < h;
|
75
|
-
}
|
76
|
-
|
77
|
-
static bool getSteerTarget(dtNavMeshQuery* navQuery, const float* startPos, const float* endPos,
|
78
|
-
const float minTargetDist,
|
79
|
-
const dtPolyRef* path, const int pathSize,
|
80
|
-
float* steerPos, unsigned char& steerPosFlag, dtPolyRef& steerPosRef,
|
81
|
-
float* outPoints = 0, int* outPointCount = 0)
|
82
|
-
{
|
83
|
-
// Find steer target.
|
84
|
-
static const int MAX_STEER_POINTS = 3;
|
85
|
-
float steerPath[MAX_STEER_POINTS*3];
|
86
|
-
unsigned char steerPathFlags[MAX_STEER_POINTS];
|
87
|
-
dtPolyRef steerPathPolys[MAX_STEER_POINTS];
|
88
|
-
int nsteerPath = 0;
|
89
|
-
navQuery->findStraightPath(startPos, endPos, path, pathSize,
|
90
|
-
steerPath, steerPathFlags, steerPathPolys, &nsteerPath, MAX_STEER_POINTS);
|
91
|
-
if (!nsteerPath)
|
92
|
-
return false;
|
93
|
-
|
94
|
-
if (outPoints && outPointCount)
|
95
|
-
{
|
96
|
-
*outPointCount = nsteerPath;
|
97
|
-
for (int i = 0; i < nsteerPath; ++i)
|
98
|
-
dtVcopy(&outPoints[i*3], &steerPath[i*3]);
|
99
|
-
}
|
100
|
-
|
101
|
-
|
102
|
-
// Find vertex far enough to steer to.
|
103
|
-
int ns = 0;
|
104
|
-
while (ns < nsteerPath)
|
105
|
-
{
|
106
|
-
// Stop at Off-Mesh link or when point is further than slop away.
|
107
|
-
if ((steerPathFlags[ns] & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ||
|
108
|
-
!inRange(&steerPath[ns*3], startPos, minTargetDist, 1000.0f))
|
109
|
-
break;
|
110
|
-
ns++;
|
111
|
-
}
|
112
|
-
// Failed to find good point to steer to.
|
113
|
-
if (ns >= nsteerPath)
|
114
|
-
return false;
|
115
|
-
|
116
|
-
dtVcopy(steerPos, &steerPath[ns*3]);
|
117
|
-
steerPos[1] = startPos[1];
|
118
|
-
steerPosFlag = steerPathFlags[ns];
|
119
|
-
steerPosRef = steerPathPolys[ns];
|
120
|
-
|
121
|
-
return true;
|
122
|
-
}
|
123
|
-
|
124
|
-
static int fixupCorridor(dtPolyRef* path, const int npath, const int maxPath,
|
125
|
-
const dtPolyRef* visited, const int nvisited)
|
126
|
-
{
|
127
|
-
int furthestPath = -1;
|
128
|
-
int furthestVisited = -1;
|
129
|
-
|
130
|
-
// Find furthest common polygon.
|
131
|
-
for (int i = npath-1; i >= 0; --i)
|
132
|
-
{
|
133
|
-
bool found = false;
|
134
|
-
for (int j = nvisited-1; j >= 0; --j)
|
135
|
-
{
|
136
|
-
if (path[i] == visited[j])
|
137
|
-
{
|
138
|
-
furthestPath = i;
|
139
|
-
furthestVisited = j;
|
140
|
-
found = true;
|
141
|
-
}
|
142
|
-
}
|
143
|
-
if (found)
|
144
|
-
break;
|
145
|
-
}
|
146
|
-
|
147
|
-
// If no intersection found just return current path.
|
148
|
-
if (furthestPath == -1 || furthestVisited == -1)
|
149
|
-
return npath;
|
150
|
-
|
151
|
-
// Concatenate paths.
|
152
|
-
|
153
|
-
// Adjust beginning of the buffer to include the visited.
|
154
|
-
const int req = nvisited - furthestVisited;
|
155
|
-
const int orig = rcMin(furthestPath+1, npath);
|
156
|
-
int size = rcMax(0, npath-orig);
|
157
|
-
if (req+size > maxPath)
|
158
|
-
size = maxPath-req;
|
159
|
-
if (size)
|
160
|
-
memmove(path+req, path+orig, size*sizeof(dtPolyRef));
|
161
|
-
|
162
|
-
// Store visited
|
163
|
-
for (int i = 0; i < req; ++i)
|
164
|
-
path[i] = visited[(nvisited-1)-i];
|
165
|
-
|
166
|
-
return req+size;
|
167
|
-
}
|
data/pathfinding/pathfind.cpp
DELETED
@@ -1,174 +0,0 @@
|
|
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
|
-
|
data/pathfinding/pathfinder.cs
DELETED
@@ -1,66 +0,0 @@
|
|
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
|
-
}
|