Skip to content

Commit

Permalink
Merge branch 'develop' into PathfindingImp
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend authored Aug 30, 2021
2 parents 446c298 + 051b946 commit bed5257
Show file tree
Hide file tree
Showing 45 changed files with 928 additions and 1,416 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ Each tick, the `update` methods is called for all active tasks.
## Example Node and Task

<pre>
import org.terasology.rendering.nui.properties.Range;
import org.terasology.engine.rendering.nui.properties.Range;

public class TimerNode extends DecoratorNode {
@Range(min = 0, max = 20)
Expand Down
5 changes: 3 additions & 2 deletions module.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"id": "Pathfinding",
"version": "1.0.0",
"version": "1.0.1-SNAPSHOT",
"author": "synopia",
"displayName": "Pathfinding Framework",
"description": "A pathfinding module mainly meant as a library/framework for other modules",
"dependencies": [
{ "id": "BiomesAPI", "minVersion": "4.0.0" },
{ "id": "CoreAssets", "minVersion": "2.0.1" },
{ "id": "CoreWorlds", "minVersion": "1.1.0" }
{ "id": "CoreWorlds", "minVersion": "1.1.0", "maxVersion": "3.0.0" },
{ "id": "ModuleTestingEnvironment", "minVersion": "0.3.1", "optional": "true" }
],
"isServerSideOnly": true,
"isLibrary": true
Expand Down
Empty file removed natives/.donotdelete
Empty file.
17 changes: 2 additions & 15 deletions src/main/java/org/terasology/navgraph/BaseRegion.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.navgraph;

import java.util.HashSet;
Expand Down
17 changes: 2 additions & 15 deletions src/main/java/org/terasology/navgraph/BitMap.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.navgraph;

import java.util.BitSet;
Expand Down
79 changes: 21 additions & 58 deletions src/main/java/org/terasology/navgraph/Entrance.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.navgraph;

import com.google.common.collect.Sets;
import org.terasology.engine.world.block.BlockArea;

import java.util.Set;

Expand All @@ -29,76 +17,51 @@ public enum Type {
}

public final Set<Floor> neighborFloors = Sets.newHashSet();
private Rect area;
private final BlockArea area = new BlockArea(BlockArea.INVALID);
private Type type;
private Floor floor;
private final Floor floor;

public Entrance(Floor floor) {
this.floor = floor;
}

public boolean isPartOfEntrance(int x, int y) {
if (area == null) {
if (!area.isValid()) {
return true;
}
if (area.contains(x, y)) {
return true;
}
int x1 = Math.min(area.x, x);
int y1 = Math.min(area.y, y);
int x2 = Math.max(area.x + area.w, x);
int y2 = Math.max(area.y + area.h, y);
int x1 = Math.min(area.minX(), x);
int y1 = Math.min(area.minY(), y);
int x2 = Math.max(area.maxX(), x);
int y2 = Math.max(area.maxY(), y);

if (type == Type.VERTICAL) {
return y2 - y1 == 0 && area.w + 1 == x2 - x1;
return y2 - y1 == 0 && area.getSizeX() == x2 - x1;
} else if (type == Type.HORIZONTAL) {
return x2 - x1 == 0 && area.h + 1 == y2 - y1;
return x2 - x1 == 0 && area.getSizeY() == y2 - y1;
} else {
return x2 - x1 <= 1 && y2 - y1 <= 1;
}
}

public void addToEntrance(int x, int y) {
if (area == null) {
area = new Rect(x, y, 0, 0);
} else {
if (!area.contains(x, y)) {
int x1 = Math.min(area.x, x);
int y1 = Math.min(area.y, y);
int x2 = Math.max(area.x + area.w, x);
int y2 = Math.max(area.y + area.h, y);
area = new Rect(x1, y1, x2 - x1, y2 - y1);
if (area.w > area.h) {
type = Type.VERTICAL;
} else if (area.w < area.h) {
type = Type.HORIZONTAL;
}

if (!area.contains(x, y)) {
area.union(x, y);
if (area.getSizeX() > area.getSizeY()) {
type = Type.VERTICAL;
} else if (area.getSizeX() < area.getSizeY()) {
type = Type.HORIZONTAL;
}
}
}

public WalkableBlock getAbstractBlock() {
int mx = area.x + area.w / 2;
int my = area.y + area.h / 2;
int mx = (area.minX() + area.getSizeX()) / 2;
int my = (area.minY() + area.getSizeY()) / 2;

return floor.getBlock(mx, my);
}

private static final class Rect {
int x;
int y;
int w;
int h;

private Rect(int x, int y, int w, int h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}

private boolean contains(int px, int py) {
return px >= x && py >= y && px < x + h && py < y + h;
}
}
}
28 changes: 7 additions & 21 deletions src/main/java/org/terasology/navgraph/Floor.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.navgraph;

import com.google.common.collect.Lists;

import org.terasology.math.ChunkMath;
import org.terasology.math.geom.Vector3i;
import org.joml.Vector3i;
import org.terasology.engine.world.chunks.Chunks;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -97,7 +83,7 @@ public void resetEntrances() {
* @return if it is an entrance
*/
public boolean isEntrance(WalkableBlock block) {
Vector3i position = ChunkMath.calcRelativeBlockPos(block.getBlockPosition());
Vector3i position = Chunks.toRelative(block.getBlockPosition(), new Vector3i());
return isEntrance(position.x, position.z);
}

Expand All @@ -115,7 +101,7 @@ public boolean isEntrance(int x, int y) {
* Sets entranceMap[x + y * NavGraphChunk.SIZE_Z] to an entrance.
* @param x the x location of the Block
* @param y the y location of the Block
* @return Entrance object at (x,y)
* @return Entrance object at (x,y)
*/
public Entrance setEntrance(int x, int y) {
if (entranceMap[x + y * NavGraphChunk.SIZE_Z] != null) {
Expand Down Expand Up @@ -158,7 +144,7 @@ public Entrance setEntrance(int x, int y) {
* @param neighbor the block being set as the neighbor to block
*/
public void setEntrance(WalkableBlock block, WalkableBlock neighbor) {
Vector3i position = ChunkMath.calcRelativeBlockPos(block.getBlockPosition());
Vector3i position = Chunks.toRelative(block.getBlockPosition(), new Vector3i());
Entrance entrance = setEntrance(position.x, position.z);
entrance.neighborFloors.add(neighbor.floor);
}
Expand Down
23 changes: 5 additions & 18 deletions src/main/java/org/terasology/navgraph/FloorFinder.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.navgraph;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.terasology.math.geom.Vector3i;
import org.joml.Vector3ic;

import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -91,7 +78,7 @@ public int compare(Region o1, Region o2) {
}

void findRegions(NavGraphChunk map) {
Vector3i worldPos = map.worldPos;
Vector3ic worldPos = map.worldPos;
regions.clear();
regionMap.clear();
sweepMap.clear();
Expand Down Expand Up @@ -123,7 +110,7 @@ void findRegions(NavGraphChunk map) {
Sweep sweep = sweepMap.remove(block);
Region region = sweep.region;
regionMap.put(block, region);
region.setPassable(block.x() - worldPos.x, block.z() - worldPos.z);
region.setPassable(block.x() - worldPos.x(), block.z() - worldPos.z());
}
}
}
Expand Down
17 changes: 2 additions & 15 deletions src/main/java/org/terasology/navgraph/NavGraphCell.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.navgraph;

import java.util.ArrayList;
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/org/terasology/navgraph/NavGraphChanged.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.navgraph;

import org.terasology.entitySystem.event.Event;
import org.terasology.engine.entitySystem.event.Event;

/**
* Created by synopia on 02.02.14.
Expand Down
Loading

0 comments on commit bed5257

Please sign in to comment.