提取RVO 寻路

This commit is contained in:
PC-20230316NUNE\Administrator
2024-02-05 18:56:55 +08:00
parent 04043cc6fc
commit 16d943ab6b
208 changed files with 42246 additions and 37182 deletions

View File

@@ -28,18 +28,18 @@ namespace Pathfinding {
// This is enough in theory, but this script will also update the destination every
// frame as the destination is used for debugging and may be used for other things by other
// scripts as well. So it makes sense that it is up to date every frame.
if (ai != null) ai.onSearchPath += OnUpdate;
if (ai != null) ai.onSearchPath += OnUpdatePos;
}
void OnDisable () {
if (ai != null) ai.onSearchPath -= OnUpdate;
if (ai != null) ai.onSearchPath -= OnUpdatePos;
}
/// <summary>Updates the AI's destination every frame</summary>
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
this.OnUpdate();
this.OnUpdatePos();
}
public void SetTarget(Vector3 pos)
@@ -47,7 +47,7 @@ namespace Pathfinding {
this.pos = pos;
}
public void OnUpdate()
public void OnUpdatePos()
{
if (ai != null) ai.destination = pos;
}

View File

@@ -41,7 +41,9 @@ namespace Pathfinding {
}
/// <summary>Update is called once per frame</summary>
void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
if (targets.Length == 0) return;
// Note: using reachedEndOfPath and pathPending instead of reachedDestination here because

View File

@@ -374,12 +374,9 @@ namespace Pathfinding {
Init();
}
/// <summary>
/// Starts searching for paths.
/// If you override this method you should in most cases call base.Start () at the start of it.
/// See: <see cref="Init"/>
/// </summary>
protected virtual void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
startHasRun = true;
Init();
}

View File

@@ -377,13 +377,16 @@ namespace Pathfinding {
seeker.startEndModifier.adjustStartPoint = () => simulatedPosition;
}
/// <summary>
/// Starts searching for paths.
/// If you override this function you should in most cases call base.Start () at the start of it.
/// See: <see cref="Init"/>
/// See: <see cref="RepeatTrySearchPath"/>
/// </summary>
protected virtual void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
startHasRun = true;
Init();
}

View File

@@ -11,7 +11,9 @@ namespace Pathfinding.Examples {
public GraphNode targetNode;
public BlockManager.TraversalProvider traversalProvider;
void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
blocker.BlockAtCurrentPosition();
}

View File

@@ -988,7 +988,12 @@ public class AstarPath : VersionedMonoBehaviour {
// and then processes the graph updates
AddWorkItem(new AstarWorkItem(() => {
graphUpdatesWorkItemAdded = false;
lastGraphUpdate = Time.realtimeSinceStartup;
#if UNITY_EDITOR
lastGraphUpdate = Time.realtimeSinceStartup;
#else
lastGraphUpdate = GetSync().Time.realtimeSinceStartup;
#endif
workItem.init();
}, workItem.update));

View File

@@ -130,8 +130,11 @@ namespace Pathfinding {
[UnityEngine.Serialization.FormerlySerializedAs("useWorldSpace")]
private bool legacyUseWorldSpace;
/// <summary>Do some stuff at start</summary>
public void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
if (!Application.isPlaying) return;
// If firstApplied is true, that means the graph was scanned during Awake.
@@ -140,7 +143,7 @@ namespace Pathfinding {
Apply();
}
}
public override void OnPostScan () {
if (applyOnScan) Apply();
}

View File

@@ -91,7 +91,9 @@ namespace Pathfinding {
float graphHeight = 100;
float graphOffset = 50;
public void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
useGUILayout = false;
fpsDrops = new float[fpsDropCounterSize];

View File

@@ -2,6 +2,7 @@ using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using Plugins.JNGame.Sync.Frame.Entity;
using UnityEngine.Profiling;
namespace Pathfinding {
@@ -298,7 +299,7 @@ namespace Pathfinding {
// One tick is 1/10000 of a millisecond.
// We need to check once in a while if the thread should be stopped.
long maxTicks = (long)(10*10000);
long targetTick = System.DateTime.UtcNow.Ticks + maxTicks;
long targetTick = JNTime.Time.Ticks + maxTicks;
while (true) {
// The path we are currently calculating
Path path = queue.Pop();
@@ -321,7 +322,7 @@ namespace Pathfinding {
}
// Tick for when the path started, used for calculating how long time the calculation took
long startTicks = System.DateTime.UtcNow.Ticks;
long startTicks = JNTime.Time.Ticks;
// Prepare the path
ipath.Prepare();
@@ -344,7 +345,7 @@ namespace Pathfinding {
// or when it has finished calculation
ipath.CalculateStep(targetTick);
targetTick = System.DateTime.UtcNow.Ticks + maxTicks;
targetTick = JNTime.Time.Ticks + maxTicks;
// Cancel function (and thus the thread) if no more paths should be accepted.
// This is done when the A* object is about to be destroyed
@@ -354,11 +355,11 @@ namespace Pathfinding {
}
}
path.duration = (System.DateTime.UtcNow.Ticks - startTicks)*0.0001F;
path.duration = (JNTime.Time.Ticks - startTicks)*0.0001F;
#if ProfileAstar
System.Threading.Interlocked.Increment(ref AstarPath.PathsCompleted);
System.Threading.Interlocked.Add(ref AstarPath.TotalSearchTime, System.DateTime.UtcNow.Ticks - startTicks);
System.Threading.Interlocked.Add(ref AstarPath.TotalSearchTime, JNTime.Time.Ticks - startTicks);
#endif
}
@@ -421,7 +422,7 @@ namespace Pathfinding {
IEnumerator CalculatePaths (PathHandler pathHandler) {
// Max number of ticks before yielding/sleeping
long maxTicks = (long)(astar.maxFrameTime*10000);
long targetTick = System.DateTime.UtcNow.Ticks + maxTicks;
long targetTick = JNTime.Time.Ticks + maxTicks;
while (true) {
// The path we are currently calculating
@@ -463,7 +464,7 @@ namespace Pathfinding {
if (tmpOnPathPreSearch != null) tmpOnPathPreSearch(p);
// Tick for when the path started, used for calculating how long time the calculation took
long startTicks = System.DateTime.UtcNow.Ticks;
long startTicks = JNTime.Time.Ticks;
long totalTicks = 0;
@@ -493,12 +494,12 @@ namespace Pathfinding {
// Improves latency
if (p.CompleteState != PathCompleteState.NotCalculated) break;
totalTicks += System.DateTime.UtcNow.Ticks-startTicks;
totalTicks += JNTime.Time.Ticks-startTicks;
// Yield/sleep so other threads can work
yield return null;
startTicks = System.DateTime.UtcNow.Ticks;
startTicks = JNTime.Time.Ticks;
// Cancel function (and thus the thread) if no more paths should be accepted.
// This is done when the A* object is about to be destroyed
@@ -507,10 +508,10 @@ namespace Pathfinding {
p.FailWithError("AstarPath object destroyed");
}
targetTick = System.DateTime.UtcNow.Ticks + maxTicks;
targetTick = JNTime.Time.Ticks + maxTicks;
}
totalTicks += System.DateTime.UtcNow.Ticks-startTicks;
totalTicks += JNTime.Time.Ticks-startTicks;
p.duration = totalTicks*0.0001F;
#if ProfileAstar
@@ -541,9 +542,9 @@ namespace Pathfinding {
// Wait a bit if we have calculated a lot of paths
if (System.DateTime.UtcNow.Ticks > targetTick) {
if (JNTime.Time.Ticks > targetTick) {
yield return null;
targetTick = System.DateTime.UtcNow.Ticks + maxTicks;
targetTick = JNTime.Time.Ticks + maxTicks;
}
}
}

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections.Generic;
using Plugins.JNGame.Sync.Frame.Entity;
using UnityEngine.Profiling;
namespace Pathfinding {
@@ -36,7 +37,7 @@ namespace Pathfinding {
Profiler.BeginSample("Calling Path Callbacks");
// Hard coded limit on 1.0 ms
long targetTick = timeSlice ? System.DateTime.UtcNow.Ticks + 1 * 10000 : 0;
long targetTick = timeSlice ? JNTime.Time.Ticks + 1 * 10000 : 0;
int counter = 0;
// Loop through the linked list and return all paths
@@ -66,7 +67,7 @@ namespace Pathfinding {
// At least 5 paths will be returned, even if timeSlice is enabled
if (counter > 5 && timeSlice) {
counter = 0;
if (System.DateTime.UtcNow.Ticks >= targetTick) {
if (JNTime.Time.Ticks >= targetTick) {
break;
}
}

View File

@@ -446,14 +446,12 @@ namespace Pathfinding.RVO.Sampled {
public static VO SegmentObstacle (Vector2 segmentStart, Vector2 segmentEnd, Vector2 offset, float radius, float inverseDt, float inverseDeltaTime) {
var vo = new VO();
// Adjusted so that a parameter weightFactor of 1 will be the default ("natural") weight factor
vo.weightFactor = 1;
// Just higher than anything else
vo.weightBonus = Mathf.Max(radius, 1)*40;
var closestOnSegment = VectorMath.ClosestPointOnSegment(segmentStart, segmentEnd, Vector2.zero);
// Collision?
if (closestOnSegment.magnitude <= radius) {
vo.colliding = true;
@@ -482,8 +480,6 @@ namespace Pathfinding.RVO.Sampled {
vo.cutoffLine = segmentStart + new Vector2(-cutoffTangent.y, cutoffTangent.x) * radius;
vo.cutoffLine += offset;
// See documentation for details
// The call to Max is just to prevent floating point errors causing NaNs to appear
var startSqrMagnitude = segmentStart.sqrMagnitude;
var normal1 = -VectorMath.ComplexMultiply(segmentStart, new Vector2(radius, Mathf.Sqrt(Mathf.Max(0, startSqrMagnitude - radius*radius)))) / startSqrMagnitude;
var endSqrMagnitude = segmentEnd.sqrMagnitude;
@@ -492,7 +488,6 @@ namespace Pathfinding.RVO.Sampled {
vo.line1 = segmentStart + normal1 * radius + offset;
vo.line2 = segmentEnd + normal2 * radius + offset;
// Note that the normals are already normalized
vo.dir1 = new Vector2(normal1.y, -normal1.x);
vo.dir2 = new Vector2(normal2.y, -normal2.x);

View File

@@ -314,7 +314,10 @@ namespace Pathfinding.RVO {
public float DeltaTime { get { return deltaTime; } }
/// <summary>Is using multithreading</summary>
public bool Multithreading { get { return workers != null && workers.Length > 0; } }
public bool Multithreading
{
get { return false; }
}
/// <summary>
/// Time in seconds between each simulation step.
@@ -722,7 +725,7 @@ namespace Pathfinding.RVO {
doUpdateObstacles = false;
}
}
/// <summary>Should be called once per frame</summary>
public void Update () {
// Initialize last step

View File

@@ -24,7 +24,9 @@ namespace Pathfinding.Examples {
Camera cam;
public void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
cam = Camera.main;
var simu = RVOSimulator.active;
if (simu == null) {

View File

@@ -89,7 +89,10 @@ namespace Pathfinding.Examples {
Vector2[] interpolatedVelocities;
Vector2[] interpolatedRotations;
public void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
mesh = new Mesh();
RVOSimulator rvoSim = FindObjectOfType(typeof(RVOSimulator)) as RVOSimulator;
if (rvoSim == null) {
@@ -230,7 +233,9 @@ namespace Pathfinding.Examples {
}
}
public void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
if (agents == null || mesh == null) return;
if (agents.Count != goals.Count) {

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections;
using Game.Plugins.App.Sync;
namespace Pathfinding.Examples {
/// <summary>
@@ -7,7 +8,7 @@ namespace Pathfinding.Examples {
/// Used in a example scene
/// </summary>
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_r_v_o_agent_placer.php")]
public class RVOAgentPlacer : MonoBehaviour {
public class RVOAgentPlacer : JNGSyncFrameDefault {
public int agents = 100;
public float ringSize = 100;
@@ -19,9 +20,9 @@ namespace Pathfinding.Examples {
public float repathRate = 1;
// Use this for initialization
IEnumerator Start () {
yield return null;
public override void OnSyncStart()
{
base.OnSyncStart();
for (int i = 0; i < agents; i++) {
float angle = ((float)i / agents)*(float)System.Math.PI*2;
@@ -34,7 +35,7 @@ namespace Pathfinding.Examples {
if (ag == null) {
Debug.LogError("Prefab does not have an RVOExampleAgent component attached");
yield break;
return;
}
//ag.radius = radius;

View File

@@ -125,7 +125,9 @@ namespace Pathfinding.Examples {
}
}
public void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
if (GetSync().Time.time >= nextRepath && canSearchAgain) {
RecalculatePath();
}

View File

@@ -1,11 +1,12 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Game.Plugins.App.Sync;
namespace Pathfinding.Examples {
/// <summary>Example script for generating an infinite procedural world</summary>
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_procedural_world.php")]
public class ProceduralWorld : MonoBehaviour {
public class ProceduralWorld : JNGSyncFrameDefault {
public Transform target;
public ProceduralPrefab[] prefabs;
@@ -78,17 +79,20 @@ namespace Pathfinding.Examples {
Dictionary<Int2, ProceduralTile> tiles = new Dictionary<Int2, ProceduralTile>();
// Use this for initialization
void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
// Calculate the closest tiles
// and then recalculate the graph
Update();
// UnityEngine.PlayerLoop.Update();
AstarPath.active.Scan();
StartCoroutine(GenerateTiles());
}
// Update is called once per frame
void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
// Calculate the tile the target is standing on
Int2 p = new Int2(Mathf.RoundToInt((target.position.x - tileSize*0.5f) / tileSize), Mathf.RoundToInt((target.position.z - tileSize*0.5f) / tileSize));

View File

@@ -48,8 +48,9 @@ namespace Pathfinding.Examples {
return Vector3.Cross(derivate, secondDerivative) / (dx*dx*dx);
}
/// <summary>Update is called once per frame</summary>
void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
// Move the agent a small distance along the path, according to its speed
float mn = time;
float mx = time+1;

View File

@@ -8,7 +8,9 @@ namespace Pathfinding {
Matrix4x4 originalMatrix;
public GraphTransform transformation { get; private set; }
void Start () {
public override void OnSyncLoad()
{
base.OnSyncLoad();
originalMatrix = transform.worldToLocalMatrix;
transform.hasChanged = true;
Refresh();

View File

@@ -41,9 +41,10 @@ namespace Pathfinding.Examples {
movementPlane = graph.transformation;
}
protected override void Start () {
public override void OnSyncStart()
{
RefreshTransform();
base.Start();
base.OnSyncStart();
}
protected override void CalculatePathRequestEndpoints (out Vector3 start, out Vector3 end) {

View File

@@ -1,31 +1,37 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Game.Plugins.App.Sync;
namespace Pathfinding.Examples {
/// <summary>Helper script in the example scene 'Turn Based'</summary>
[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(SingleNodeBlocker))]
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_turn_based_door.php")]
public class TurnBasedDoor : MonoBehaviour {
public class TurnBasedDoor : JNGSyncFrameDefault {
Animator animator;
SingleNodeBlocker blocker;
bool open;
void Awake () {
public override void OnSyncLoad()
{
base.OnSyncLoad();
animator = GetComponent<Animator>();
blocker = GetComponent<SingleNodeBlocker>();
}
void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
// Make sure the door starts out blocked
blocker.BlockAtCurrentPosition();
animator.CrossFade("close", 0.2f);
}
public void Close () {
StartCoroutine(WaitAndClose());
// StartCoroutine(WaitAndClose());
}
IEnumerator WaitAndClose () {

View File

@@ -31,7 +31,9 @@ namespace Pathfinding.Examples {
eventSystem = FindObjectOfType<EventSystem>();
}
void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// Ignore any input while the mouse is over a UI element

View File

@@ -1,22 +1,29 @@
using UnityEngine;
using System.Collections;
using Game.Plugins.App.Sync;
namespace Pathfinding.Examples {
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_example_mover.php")]
public class ExampleMover : MonoBehaviour {
public class ExampleMover : JNGSyncFrameDefault {
RVOExampleAgent agent;
public Transform target;
// Use this for initialization
void Awake () {
public override void OnSyncLoad()
{
base.OnSyncLoad();
agent = GetComponent<RVOExampleAgent>();
}
void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
agent.SetTarget(target.position);
}
void LateUpdate () {
public override void OnLateSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnLateSyncUpdate(dt, frame, input);
if (Input.GetKeyDown(KeyCode.Mouse0)) {
agent.SetTarget(target.position);
}

View File

@@ -1,6 +1,7 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Game.Plugins.App.Sync;
using Pathfinding.Util;
namespace Pathfinding.Examples {
/// <summary>
@@ -17,7 +18,7 @@ namespace Pathfinding.Examples {
/// See: Pathfinding.FloodPathTracer
/// </summary>
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_path_types_demo.php")]
public class PathTypesDemo : MonoBehaviour {
public class PathTypesDemo : JNGSyncFrameDefault {
public DemoMode activeDemo = DemoMode.ABPath;
public enum DemoMode {
@@ -64,7 +65,9 @@ namespace Pathfinding.Examples {
List<Vector3> multipoints = new List<Vector3>();
// Update is called once per frame
void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// Find the intersection with the y=0 plane

View File

@@ -1,9 +1,10 @@
using Game.Plugins.App.Sync;
using UnityEngine;
namespace Pathfinding.Examples {
/// <summary>Example script used in the example scenes</summary>
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_door_controller.php")]
public class DoorController : MonoBehaviour {
public class DoorController : JNGSyncFrameDefault {
private bool open = false;
public int opentag = 1;
@@ -13,7 +14,9 @@ namespace Pathfinding.Examples {
Bounds bounds;
public void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
// Capture the bounds of the collider while it is closed
bounds = GetComponent<Collider>().bounds;

View File

@@ -1,3 +1,4 @@
using Game.Plugins.App.Sync;
using UnityEngine;
namespace Pathfinding {
@@ -19,10 +20,12 @@ namespace Pathfinding {
/// </summary>
[AddComponentMenu("Pathfinding/Navmesh/RecastTileUpdate")]
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_recast_tile_update.php")]
public class RecastTileUpdate : MonoBehaviour {
public class RecastTileUpdate : JNGSyncFrameDefault {
public static event System.Action<Bounds> OnNeedUpdates;
void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
ScheduleUpdate();
}

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections;
using Game.Plugins.App.Sync;
using Pathfinding;
namespace Pathfinding.Examples {
@@ -9,8 +10,10 @@ namespace Pathfinding.Examples {
/// </summary>
[ExecuteInEditMode]
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_snap_to_node.php")]
public class SnapToNode : MonoBehaviour {
void Update () {
public class SnapToNode : JNGSyncFrameDefault {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
if (transform.hasChanged && AstarPath.active != null) {
var node = AstarPath.active.GetNearest(transform.position, NNConstraint.None).node;
if (node != null) {

View File

@@ -25,7 +25,9 @@ namespace Pathfinding {
Camera cam;
public void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
//Cache the Main Camera
cam = Camera.main;
// Slightly inefficient way of finding all AIs, but this is just an example script, so it doesn't matter much.
@@ -41,12 +43,14 @@ namespace Pathfinding {
}
/// <summary>Update is called once per frame</summary>
void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
if (!onlyOnDoubleClick && cam != null) {
UpdateTargetPosition();
}
}
public void UpdateTargetPosition () {
Vector3 newPosition = Vector3.zero;
bool positionFound = false;

View File

@@ -211,9 +211,9 @@ namespace Pathfinding {
/// <param name="label">Label to display</param>
/// <param name="selected">Current LayerMask</param>
public static LayerMask LayerMaskField (string label, LayerMask selected) {
if (Event.current.type == EventType.Layout && System.DateTime.UtcNow.Ticks - lastUpdateTick > 10000000L) {
if (Event.current.type == EventType.Layout && JNTime.Time.Ticks - lastUpdateTick > 10000000L) {
layerNames.Clear();
lastUpdateTick = System.DateTime.UtcNow.Ticks;
lastUpdateTick = JNTime.Time.Ticks;
}
string[] currentLayerNames;

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections.Generic;
using Plugins.JNGame.Sync.Frame.Entity;
namespace Pathfinding {
/// <summary>
@@ -613,7 +614,7 @@ namespace Pathfinding {
/// <summary>
/// Calculates the path until completed or until the time has passed targetTick.
/// Usually a check is only done every 500 nodes if the time has passed targetTick.
/// Time/Ticks are got from System.DateTime.UtcNow.Ticks.
/// Time/Ticks are got from JNTime.Time.Ticks.
///
/// Basic outline of what the function does for the standard path (Pathfinding.ABPath).
/// <code>
@@ -670,7 +671,7 @@ namespace Pathfinding {
// Check for time every 500 nodes, roughly every 0.5 ms usually
if (counter > 500) {
// Have we exceded the maxFrameTime, if so we should wait one frame before continuing the search since we don't want the game to lag
if (System.DateTime.UtcNow.Ticks >= targetTick) {
if (JNTime.Time.Ticks >= targetTick) {
// Return instead of yield'ing, a separate function handles the yield (CalculatePaths)
return;
}

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections.Generic;
using Plugins.JNGame.Sync.Frame.Entity;
namespace Pathfinding {
/// <summary>
@@ -598,7 +599,7 @@ namespace Pathfinding {
// Check for time every 500 nodes, roughly every 0.5 ms usually
if (counter > 500) {
// Have we exceded the maxFrameTime, if so we should wait one frame before continuing the search since we don't want the game to lag
if (System.DateTime.UtcNow.Ticks >= targetTick) {
if (JNTime.Time.Ticks >= targetTick) {
// Return instead of yield'ing, a separate function handles the yield (CalculatePaths)
return;
}

View File

@@ -1,3 +1,4 @@
using Plugins.JNGame.Sync.Frame.Entity;
using UnityEngine;
namespace Pathfinding {
@@ -260,7 +261,7 @@ namespace Pathfinding {
// Check for time every 500 nodes, roughly every 0.5 ms usually
if (counter > 500) {
// Have we exceded the maxFrameTime, if so we should wait one frame before continuing the search since we don't want the game to lag
if (System.DateTime.UtcNow.Ticks >= targetTick) {
if (JNTime.Time.Ticks >= targetTick) {
// Return instead of yield'ing, a separate function handles the yield (CalculatePaths)
return;
}

View File

@@ -1,3 +1,4 @@
using Plugins.JNGame.Sync.Frame.Entity;
using UnityEngine;
namespace Pathfinding {
@@ -102,7 +103,7 @@ namespace Pathfinding {
// Check for time every 500 nodes, roughly every 0.5 ms usually
if (counter > 500) {
// Have we exceded the maxFrameTime, if so we should wait one frame before continuing the search since we don't want the game to lag
if (System.DateTime.UtcNow.Ticks >= targetTick) {
if (JNTime.Time.Ticks >= targetTick) {
//Return instead of yield'ing, a separate function handles the yield (CalculatePaths)
return;
}

View File

@@ -201,7 +201,9 @@ namespace Pathfinding.RVO {
}
/// <summary>Creates obstacles</summary>
public void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
addedObstacles = new List<ObstacleVertex>();
sourceObstacles = new List<Vector3[]>();
prevUpdateMatrix = GetMatrix();
@@ -212,7 +214,9 @@ namespace Pathfinding.RVO {
/// Updates obstacle if required.
/// Checks for if the obstacle should be updated (e.g if it has moved)
/// </summary>
public void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
Matrix4x4 m = GetMatrix();
if (m != prevUpdateMatrix) {
@@ -223,7 +227,6 @@ namespace Pathfinding.RVO {
}
}
/// <summary>
/// Finds a simulator in the scene.
///

View File

@@ -75,7 +75,9 @@ namespace Pathfinding {
#endregion
}
void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
if (!AstarPath.active)
throw new System.Exception("No AstarPath object in the scene");
}

View File

@@ -69,7 +69,9 @@ namespace Pathfinding {
[HideInInspector]
public int graphIndex;
void Start () {
public override void OnSyncStart()
{
base.OnSyncStart();
if (AstarPath.active == null) throw new System.Exception("There is no AstarPath object in the scene");
// If one creates this component via a script then they may have already set the graph field.
@@ -84,9 +86,11 @@ namespace Pathfinding {
UpdateGraph();
}
/// <summary>Update is called once per frame</summary>
void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
if (graph == null) return;
// Calculate where the graph center and the target position is in graph space