Skip to content

Commit

Permalink
#35: fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsonax committed Nov 17, 2017
1 parent 5fc3d03 commit a4889b5
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 17,043 deletions.
2 changes: 1 addition & 1 deletion AppData.dat
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<startScene dataType="Struct" type="Duality.ContentRef`1[[Duality.Resources.Scene]]">
<contentPath dataType="String">Data\Examples\PotentialFieldPathfinderExample.Scene.res</contentPath>
</startScene>
<version dataType="UInt">1501</version>
<version dataType="UInt">1534</version>
<websiteUrl dataType="String">http://www.adamslair.net</websiteUrl>
</root>
<!-- XmlFormatterBase Document Separator -->
17,043 changes: 11 additions & 17,032 deletions Data/Examples/PotentialFieldPathfinderExample.Scene.res

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Duality.Plugins.Pathfindax.Examples.Components
[EditorHintCategory(PathfindaxStrings.PathfindaxTest)]
[RequiredComponent(typeof(RigidBody))]
[ExecutionOrder(ExecutionRelation.After, typeof(IDualityPathfinderComponent))]
[ExecutionOrder(ExecutionRelation.After, typeof(DynamicPotentialFieldComponent))]
public class PhysicsParticleFollower : Component, ICmpUpdatable, ICmpInitializable, IPathProvider
{
[EditorHintRange(0, float.MaxValue)]
Expand All @@ -22,7 +23,7 @@ public class PhysicsParticleFollower : Component, ICmpUpdatable, ICmpInitializab
public PathfindaxCollisionCategory CollisionCategory { get; set; }
public Camera Camera { get; set; }
IPath IPathProvider.Path => Path;
private static DynamicPotentialField _dynamicPotentialField;
public DynamicPotentialFieldComponent DynamicPotentialFieldComponent { get; set; }

public AggregratedPotentialField Path { get; private set; }
public Vector2 CurrentPosition => new Vector2(GameObj.Transform.Pos.X, GameObj.Transform.Pos.Y);
Expand All @@ -33,13 +34,8 @@ void ICmpInitializable.OnInit(InitContext context)
{
if (context == InitContext.Activate && DualityApp.ExecContext == DualityApp.ExecutionContext.Game)
{
_pathfinderProxy = new PotentialFieldPathfindProxy();

if (_dynamicPotentialField == null)
{
_dynamicPotentialField = new DynamicPotentialField(_pathfinderProxy.Pathfinder.DefinitionNodeNetwork.GridTransformer, 100f);
}
_dynamicPotentialField.AddPotentialFunction(this, new QuadraticPotentialFunction(() => CurrentPosition, 2, 0.8f));
_pathfinderProxy = new PotentialFieldPathfindProxy();
DynamicPotentialFieldComponent.PotentialField.AddPotentialFunction(this, new QuadraticPotentialFunction(() => CurrentPosition, 2, 0.8f));
_rigidBody = GameObj.GetComponent<RigidBody>();
DualityApp.Mouse.ButtonDown += Mouse_ButtonDown;
}
Expand All @@ -48,7 +44,7 @@ void ICmpInitializable.OnInit(InitContext context)
void ICmpInitializable.OnShutdown(ShutdownContext context)
{
DualityApp.Mouse.ButtonDown -= Mouse_ButtonDown;
_dynamicPotentialField?.RemovePotentialFunction(this);
DynamicPotentialFieldComponent?.PotentialField?.RemovePotentialFunction(this);
}

void ICmpUpdatable.OnUpdate()
Expand All @@ -68,7 +64,7 @@ private void Mouse_ButtonDown(object sender, MouseButtonEventArgs e)
var request = _pathfinderProxy.RequestPath(GameObj.Transform.Pos, targetPos, CollisionCategory, AgentSize);
request.AddCallback(pathrequest =>
{
Path = new AggregratedPotentialField(pathrequest.CompletedPath.GridTransformer, pathrequest.CompletedPath, _dynamicPotentialField);
Path = new AggregratedPotentialField(pathrequest.CompletedPath.GridTransformer, pathrequest.CompletedPath, DynamicPotentialFieldComponent.PotentialField);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Duality.Editor;
using Pathfindax.Grid;
using Pathfindax.PathfindEngine;
using Pathfindax.Paths;
using Pathfindax.Utils;

namespace Duality.Plugins.Pathfindax.Components
{
[EditorHintCategory(PathfindaxStrings.Pathfindax)]
[RequiredComponent(typeof(PotentialFieldPathfinderComponent))]
public class DynamicPotentialFieldComponent : Component, ICmpInitializable
{
public DynamicPotentialField PotentialField { get; private set; }
public float UpdateInterval { get; set; } = 100f;
void ICmpInitializable.OnInit(InitContext context)
{
if (context == InitContext.Activate && DualityApp.ExecContext == DualityApp.ExecutionContext.Game)
{
var pathfinder = GameObj.GetComponent<PotentialFieldPathfinderComponent>();
var definitionNodeNetwork = ((Pathfinder<DefinitionNodeGrid, DijkstraNodeGrid, PotentialField>) pathfinder.Pathfinder).DefinitionNodeNetwork;
PotentialField = new DynamicPotentialField(definitionNodeNetwork.GridTransformer, UpdateInterval);
}
}

void ICmpInitializable.OnShutdown(ShutdownContext context)
{
PotentialField?.Dispose();
PotentialField = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ bool ICmpRenderer.IsVisible(IDrawDevice device)
void ICmpRenderer.Draw(IDrawDevice device)
{
if (!Visualize) return;
if (DualityApp.ExecContext != DualityApp.ExecutionContext.Game) return;
var pathfinder = PathfindaxEngine.GetPathfinder();
if (pathfinder?.DefinitionNodeNetwork != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Components\DynamicPotentialFieldComponent.cs" />
<Compile Include="Components\FlowFieldPathfinderComponent.cs" />
<Compile Include="Components\AstarPathfinderComponent.cs" />
<Compile Include="Components\Interfaces\IDualityPathfinderComponent.cs" />
Expand Down

0 comments on commit a4889b5

Please sign in to comment.