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
Binary file
|
@@ -0,0 +1,73 @@
|
|
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 Entity = GameMachine.Messages.Entity;
|
12
|
+
|
13
|
+
namespace GameMachine
|
14
|
+
{
|
15
|
+
public class ProxyClient
|
16
|
+
{
|
17
|
+
private IPEndPoint udp_ep;
|
18
|
+
private UdpClient udpClient;
|
19
|
+
private int port = 8800;
|
20
|
+
private string host = "127.0.0.1";
|
21
|
+
|
22
|
+
public ProxyClient(int _port)
|
23
|
+
{
|
24
|
+
port = _port;
|
25
|
+
}
|
26
|
+
|
27
|
+
public void Start()
|
28
|
+
{
|
29
|
+
udp_ep = new IPEndPoint(IPAddress.Any, 11000);
|
30
|
+
udpClient = new UdpClient(udp_ep);
|
31
|
+
receiveData();
|
32
|
+
|
33
|
+
Task.Factory.StartNew(() => {
|
34
|
+
Ping(); });
|
35
|
+
}
|
36
|
+
|
37
|
+
private void Ping()
|
38
|
+
{
|
39
|
+
Entity entity = new Entity();
|
40
|
+
entity.id = "ping";
|
41
|
+
byte[] bytes = MessageUtil.EntityToByteArray(entity);
|
42
|
+
while (true)
|
43
|
+
{
|
44
|
+
Thread.Sleep(1000);
|
45
|
+
Send(bytes);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
private void SendCallback(IAsyncResult ar)
|
50
|
+
{
|
51
|
+
UdpClient u = (UdpClient)ar.AsyncState;
|
52
|
+
u.EndSend(ar);
|
53
|
+
}
|
54
|
+
|
55
|
+
public void Send(byte[] bytes)
|
56
|
+
{
|
57
|
+
udpClient.BeginSend(bytes, bytes.Length, host, port, new AsyncCallback(SendCallback), udpClient);
|
58
|
+
}
|
59
|
+
|
60
|
+
private void dataReady(IAsyncResult ar)
|
61
|
+
{
|
62
|
+
byte[] bytes = udpClient.EndReceive(ar, ref udp_ep);
|
63
|
+
receiveData();
|
64
|
+
MessageRouter.Route(bytes, this);
|
65
|
+
}
|
66
|
+
|
67
|
+
private void receiveData()
|
68
|
+
{
|
69
|
+
udpClient.BeginReceive(new AsyncCallback(dataReady), udp_ep);
|
70
|
+
}
|
71
|
+
|
72
|
+
}
|
73
|
+
}
|
@@ -0,0 +1,30 @@
|
|
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
|
+
}
|
@@ -0,0 +1,33 @@
|
|
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
|
+
}
|
Binary file
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#include "DetourNavMesh.h"
|
2
|
+
|
3
|
+
static const int NAVMESHSET_MAGIC = 'M'<<24 | 'S'<<16 | 'E'<<8 | 'T'; //'MSET';
|
4
|
+
static const int NAVMESHSET_VERSION = 1;
|
5
|
+
|
6
|
+
struct NavMeshSetRcnHeader
|
7
|
+
{
|
8
|
+
long version;
|
9
|
+
int numTiles;
|
10
|
+
dtNavMeshParams params;
|
11
|
+
};
|
12
|
+
struct NavMeshSetHeader
|
13
|
+
{
|
14
|
+
int magic;
|
15
|
+
int version;
|
16
|
+
int numTiles;
|
17
|
+
dtNavMeshParams params;
|
18
|
+
};
|
19
|
+
|
20
|
+
struct NavMeshTileHeader
|
21
|
+
{
|
22
|
+
dtTileRef tileRef;
|
23
|
+
int dataSize;
|
24
|
+
};
|
25
|
+
|
26
|
+
void save_navmesh(const char* path, const dtNavMesh* mesh);
|
27
|
+
dtNavMesh* load_navmesh(const char* path);
|
28
|
+
|
@@ -0,0 +1,167 @@
|
|
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
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#include "pathfind.h"
|
2
|
+
|
3
|
+
int main (int argc, char* argv[]) {
|
4
|
+
|
5
|
+
int find_straight_path = 1;
|
6
|
+
float *newPath;
|
7
|
+
newPath = getPathPtr(MAX_SMOOTH);
|
8
|
+
|
9
|
+
//const char *file = "/home2/chris/game_machine/server/detour/meshes/terrain.bin";
|
10
|
+
const char *file = "/home2/chris/game_machine/data/meshes/all_tiles_navmesh.bin";
|
11
|
+
|
12
|
+
|
13
|
+
int loadRes = loadNavMesh(1,file);
|
14
|
+
fprintf (stderr, "loadNavMesh returned %d\n", loadRes);
|
15
|
+
dtNavMeshQuery* query = getQuery(1);
|
16
|
+
|
17
|
+
if (loadRes == 1) {
|
18
|
+
for (int j = 0; j < 1; ++j) {
|
19
|
+
for (int i = 0; i < 1; ++i) {
|
20
|
+
//int res = findPath(query, 563.0, 0.2, 504.0, 509.0, 0.2, 528.0,
|
21
|
+
int res = findPath(query, 563.0f, 0.2f, 504.0f, 563.0f, 0.2f, 541.0f,
|
22
|
+
find_straight_path, newPath);
|
23
|
+
fprintf (stderr, "findPath returned %d\n", res);
|
24
|
+
for (int i = 0; i < res; ++i) {
|
25
|
+
//fprintf (stderr, "%d\n", i);
|
26
|
+
const float* v = &newPath[i*3];
|
27
|
+
fprintf (stderr, "%f.%f.%f\n", v[0], v[1], v[2]);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
fprintf (stderr, "endLoop\n");
|
34
|
+
freePath(newPath);
|
35
|
+
fprintf (stderr, "freePath\n");
|
36
|
+
freeQuery(query);
|
37
|
+
fprintf (stderr, "freeQuery\n");
|
38
|
+
return 1;
|
39
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
#include <string>
|
2
|
+
#include <cstring>
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <stdio.h>
|
5
|
+
#include "Recast.h"
|
6
|
+
#include "DetourCommon.h"
|
7
|
+
#include "DetourNavMesh.h"
|
8
|
+
#include "DetourNavMeshBuilder.h"
|
9
|
+
#include "DetourNavMeshQuery.h"
|
10
|
+
|
11
|
+
#include "mesh_loader.h"
|
12
|
+
|
13
|
+
|
14
|
+
void save_navmesh(const char* path, const dtNavMesh* mesh) {
|
15
|
+
if (!mesh) return;
|
16
|
+
|
17
|
+
FILE* fp = fopen(path, "wb");
|
18
|
+
if (!fp)
|
19
|
+
return;
|
20
|
+
|
21
|
+
// Store header.
|
22
|
+
NavMeshSetHeader header;
|
23
|
+
header.magic = NAVMESHSET_MAGIC;
|
24
|
+
header.version = NAVMESHSET_VERSION;
|
25
|
+
header.numTiles = 0;
|
26
|
+
for (int i = 0; i < mesh->getMaxTiles(); ++i)
|
27
|
+
{
|
28
|
+
const dtMeshTile* tile = mesh->getTile(i);
|
29
|
+
if (!tile || !tile->header || !tile->dataSize) continue;
|
30
|
+
header.numTiles++;
|
31
|
+
}
|
32
|
+
memcpy(&header.params, mesh->getParams(), sizeof(dtNavMeshParams));
|
33
|
+
fwrite(&header, sizeof(NavMeshSetHeader), 1, fp);
|
34
|
+
|
35
|
+
// Store tiles.
|
36
|
+
for (int i = 0; i < mesh->getMaxTiles(); ++i)
|
37
|
+
{
|
38
|
+
const dtMeshTile* tile = mesh->getTile(i);
|
39
|
+
if (!tile || !tile->header || !tile->dataSize) continue;
|
40
|
+
|
41
|
+
NavMeshTileHeader tileHeader;
|
42
|
+
tileHeader.tileRef = mesh->getTileRef(tile);
|
43
|
+
tileHeader.dataSize = tile->dataSize;
|
44
|
+
fwrite(&tileHeader, sizeof(tileHeader), 1, fp);
|
45
|
+
|
46
|
+
fwrite(tile->data, tile->dataSize, 1, fp);
|
47
|
+
}
|
48
|
+
|
49
|
+
fclose(fp);
|
50
|
+
}
|
51
|
+
|
52
|
+
dtNavMesh* load_navmesh(const char* path)
|
53
|
+
{
|
54
|
+
FILE* fp = fopen(path, "rb");
|
55
|
+
if (!fp) return 0;
|
56
|
+
|
57
|
+
// Read header.
|
58
|
+
NavMeshSetHeader header;
|
59
|
+
fread(&header, sizeof(NavMeshSetHeader), 1, fp);
|
60
|
+
if (header.magic != NAVMESHSET_MAGIC)
|
61
|
+
{
|
62
|
+
fclose(fp);
|
63
|
+
fprintf (stderr, "Bad magic %d\n", header.magic);
|
64
|
+
return 0;
|
65
|
+
}
|
66
|
+
|
67
|
+
if (header.version != NAVMESHSET_VERSION)
|
68
|
+
{
|
69
|
+
fclose(fp);
|
70
|
+
fprintf (stderr, "Bad version %d\n", header.version);
|
71
|
+
return 0;
|
72
|
+
}
|
73
|
+
|
74
|
+
dtNavMesh* mesh = dtAllocNavMesh();
|
75
|
+
if (!mesh)
|
76
|
+
{
|
77
|
+
fclose(fp);
|
78
|
+
return 0;
|
79
|
+
}
|
80
|
+
dtStatus status = mesh->init(&header.params);
|
81
|
+
if (dtStatusFailed(status))
|
82
|
+
{
|
83
|
+
fclose(fp);
|
84
|
+
return 0;
|
85
|
+
}
|
86
|
+
|
87
|
+
// Read tiles.
|
88
|
+
for (int i = 0; i < header.numTiles; ++i)
|
89
|
+
{
|
90
|
+
NavMeshTileHeader tileHeader;
|
91
|
+
fread(&tileHeader, sizeof(tileHeader), 1, fp);
|
92
|
+
if (!tileHeader.tileRef || !tileHeader.dataSize)
|
93
|
+
break;
|
94
|
+
|
95
|
+
unsigned char* data = (unsigned char*)dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM);
|
96
|
+
if (!data) break;
|
97
|
+
memset(data, 0, tileHeader.dataSize);
|
98
|
+
fread(data, tileHeader.dataSize, 1, fp);
|
99
|
+
|
100
|
+
//fprintf (stderr, "Adding tile %s\n", data);
|
101
|
+
mesh->addTile(data, tileHeader.dataSize, DT_TILE_FREE_DATA, tileHeader.tileRef, 0);
|
102
|
+
}
|
103
|
+
|
104
|
+
fclose(fp);
|
105
|
+
|
106
|
+
return mesh;
|
107
|
+
}
|
108
|
+
|