Skip to content

Commit

Permalink
Do not visualise AStar after DebugHelper is deactivated
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzeroglu committed Aug 8, 2020
1 parent cf89ba3 commit 00b7003
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions js/debug/DebugHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var DebugHelper = function(world, threeInstance, scene){
this.lookMeshesByEntityID = {};
this.meshesByAStarIDs = {};
this.meshesByJumpDescriptorIDs = {};
this.visualisedAStars = {};
this.pathMeshes = [];
this.edgeMeshes = [];

Expand Down Expand Up @@ -159,11 +160,18 @@ DebugHelper.prototype.visualiseAStar = function(aStar){
return;
}

this.visualisedAStars[id] = true;

if (aStar.searchID > 0){
this.meshesByAStarIDs[id] = this.visualisePath(aStar.path, aStarPathVisualSize);
}

aStar.onPathConstructed = function(){

if (!this.visualisedAStars[id]){
return;
}

var meshes = this.meshesByAStarIDs[id] || [];

for (var i = 0; i < meshes.length; i ++){
Expand Down Expand Up @@ -262,6 +270,7 @@ DebugHelper.prototype.deactivate = function(){
this.lookMeshesByEntityID = {};
this.meshesByAStarIDs = {};
this.meshesByJumpDescriptorIDs = {};
this.visualisedAStars = {};
this.pathMeshes = [];
this.edgeMeshes = [];
}
Expand Down
6 changes: 6 additions & 0 deletions test/debug/DebugHelperTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("DebugHelper", function(){
expect(debugHelper.lookMeshesByEntityID).to.eql({});
expect(debugHelper.meshesByAStarIDs).to.eql({});
expect(debugHelper.meshesByJumpDescriptorIDs).to.eql({});
expect(debugHelper.visualisedAStars).to.eql({});
expect(debugHelper.pathMeshes).to.eql([]);
expect(debugHelper.edgeMeshes).to.eql([]);
expect(debugHelper.worldMesh).to.eql(null);
Expand Down Expand Up @@ -484,6 +485,7 @@ describe("DebugHelper", function(){

expect(scene.children.length).to.eql(0);
expect(debugHelper.meshesByAStarIDs).to.eql({});
expect(debugHelper.visualisedAStars).to.eql({});

aStar.findShortestPath(vertex1, vertex3);
debugHelper.visualiseAStar(aStar);
Expand All @@ -492,6 +494,10 @@ describe("DebugHelper", function(){
expect(scene.children[0].position).to.eql(vertex3);
expect(scene.children[1].position).to.eql(vertex2);
expect(scene.children[2].position).to.eql(vertex1);

debugHelper.deactivate();
aStar.findShortestPath(vertex1, vertex3);
expect(scene.children.length).to.eql(0);
});

it("should visualise JumpDescriptor", function(){
Expand Down

0 comments on commit 00b7003

Please sign in to comment.