Skip to content

Commit bed5257

Browse files
authored
Merge branch 'develop' into PathfindingImp
2 parents 446c298 + 051b946 commit bed5257

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+928
-1416
lines changed

README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Each tick, the `update` methods is called for all active tasks.
261261
## Example Node and Task
262262

263263
<pre>
264-
import org.terasology.rendering.nui.properties.Range;
264+
import org.terasology.engine.rendering.nui.properties.Range;
265265

266266
public class TimerNode extends DecoratorNode {
267267
@Range(min = 0, max = 20)

module.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"id": "Pathfinding",
3-
"version": "1.0.0",
3+
"version": "1.0.1-SNAPSHOT",
44
"author": "synopia",
55
"displayName": "Pathfinding Framework",
66
"description": "A pathfinding module mainly meant as a library/framework for other modules",
77
"dependencies": [
88
{ "id": "BiomesAPI", "minVersion": "4.0.0" },
99
{ "id": "CoreAssets", "minVersion": "2.0.1" },
10-
{ "id": "CoreWorlds", "minVersion": "1.1.0" }
10+
{ "id": "CoreWorlds", "minVersion": "1.1.0", "maxVersion": "3.0.0" },
11+
{ "id": "ModuleTestingEnvironment", "minVersion": "0.3.1", "optional": "true" }
1112
],
1213
"isServerSideOnly": true,
1314
"isLibrary": true

natives/.donotdelete

Whitespace-only changes.

src/main/java/org/terasology/navgraph/BaseRegion.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
/*
2-
* Copyright 2014 MovingBlocks
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2020 The Terasology Foundation
2+
// SPDX-License-Identifier: Apache-2.0
163
package org.terasology.navgraph;
174

185
import java.util.HashSet;

src/main/java/org/terasology/navgraph/BitMap.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
/*
2-
* Copyright 2014 MovingBlocks
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2020 The Terasology Foundation
2+
// SPDX-License-Identifier: Apache-2.0
163
package org.terasology.navgraph;
174

185
import java.util.BitSet;
Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
/*
2-
* Copyright 2014 MovingBlocks
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2020 The Terasology Foundation
2+
// SPDX-License-Identifier: Apache-2.0
163
package org.terasology.navgraph;
174

185
import com.google.common.collect.Sets;
6+
import org.terasology.engine.world.block.BlockArea;
197

208
import java.util.Set;
219

@@ -29,76 +17,51 @@ public enum Type {
2917
}
3018

3119
public final Set<Floor> neighborFloors = Sets.newHashSet();
32-
private Rect area;
20+
private final BlockArea area = new BlockArea(BlockArea.INVALID);
3321
private Type type;
34-
private Floor floor;
22+
private final Floor floor;
3523

3624
public Entrance(Floor floor) {
3725
this.floor = floor;
3826
}
3927

4028
public boolean isPartOfEntrance(int x, int y) {
41-
if (area == null) {
29+
if (!area.isValid()) {
4230
return true;
4331
}
4432
if (area.contains(x, y)) {
4533
return true;
4634
}
47-
int x1 = Math.min(area.x, x);
48-
int y1 = Math.min(area.y, y);
49-
int x2 = Math.max(area.x + area.w, x);
50-
int y2 = Math.max(area.y + area.h, y);
35+
int x1 = Math.min(area.minX(), x);
36+
int y1 = Math.min(area.minY(), y);
37+
int x2 = Math.max(area.maxX(), x);
38+
int y2 = Math.max(area.maxY(), y);
5139

5240
if (type == Type.VERTICAL) {
53-
return y2 - y1 == 0 && area.w + 1 == x2 - x1;
41+
return y2 - y1 == 0 && area.getSizeX() == x2 - x1;
5442
} else if (type == Type.HORIZONTAL) {
55-
return x2 - x1 == 0 && area.h + 1 == y2 - y1;
43+
return x2 - x1 == 0 && area.getSizeY() == y2 - y1;
5644
} else {
5745
return x2 - x1 <= 1 && y2 - y1 <= 1;
5846
}
5947
}
6048

6149
public void addToEntrance(int x, int y) {
62-
if (area == null) {
63-
area = new Rect(x, y, 0, 0);
64-
} else {
65-
if (!area.contains(x, y)) {
66-
int x1 = Math.min(area.x, x);
67-
int y1 = Math.min(area.y, y);
68-
int x2 = Math.max(area.x + area.w, x);
69-
int y2 = Math.max(area.y + area.h, y);
70-
area = new Rect(x1, y1, x2 - x1, y2 - y1);
71-
if (area.w > area.h) {
72-
type = Type.VERTICAL;
73-
} else if (area.w < area.h) {
74-
type = Type.HORIZONTAL;
75-
}
50+
51+
if (!area.contains(x, y)) {
52+
area.union(x, y);
53+
if (area.getSizeX() > area.getSizeY()) {
54+
type = Type.VERTICAL;
55+
} else if (area.getSizeX() < area.getSizeY()) {
56+
type = Type.HORIZONTAL;
7657
}
7758
}
7859
}
7960

8061
public WalkableBlock getAbstractBlock() {
81-
int mx = area.x + area.w / 2;
82-
int my = area.y + area.h / 2;
62+
int mx = (area.minX() + area.getSizeX()) / 2;
63+
int my = (area.minY() + area.getSizeY()) / 2;
8364

8465
return floor.getBlock(mx, my);
8566
}
86-
87-
private static final class Rect {
88-
int x;
89-
int y;
90-
int w;
91-
int h;
92-
93-
private Rect(int x, int y, int w, int h) {
94-
this.x = x;
95-
this.y = y;
96-
this.w = w;
97-
this.h = h;
98-
}
99-
100-
private boolean contains(int px, int py) {
101-
return px >= x && py >= y && px < x + h && py < y + h;
102-
}
103-
}
10467
}

src/main/java/org/terasology/navgraph/Floor.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
1-
/*
2-
* Copyright 2014 MovingBlocks
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2020 The Terasology Foundation
2+
// SPDX-License-Identifier: Apache-2.0
163
package org.terasology.navgraph;
174

185
import com.google.common.collect.Lists;
19-
20-
import org.terasology.math.ChunkMath;
21-
import org.terasology.math.geom.Vector3i;
6+
import org.joml.Vector3i;
7+
import org.terasology.engine.world.chunks.Chunks;
228

239
import java.util.Arrays;
2410
import java.util.List;
@@ -97,7 +83,7 @@ public void resetEntrances() {
9783
* @return if it is an entrance
9884
*/
9985
public boolean isEntrance(WalkableBlock block) {
100-
Vector3i position = ChunkMath.calcRelativeBlockPos(block.getBlockPosition());
86+
Vector3i position = Chunks.toRelative(block.getBlockPosition(), new Vector3i());
10187
return isEntrance(position.x, position.z);
10288
}
10389

@@ -115,7 +101,7 @@ public boolean isEntrance(int x, int y) {
115101
* Sets entranceMap[x + y * NavGraphChunk.SIZE_Z] to an entrance.
116102
* @param x the x location of the Block
117103
* @param y the y location of the Block
118-
* @return Entrance object at (x,y)
104+
* @return Entrance object at (x,y)
119105
*/
120106
public Entrance setEntrance(int x, int y) {
121107
if (entranceMap[x + y * NavGraphChunk.SIZE_Z] != null) {
@@ -158,7 +144,7 @@ public Entrance setEntrance(int x, int y) {
158144
* @param neighbor the block being set as the neighbor to block
159145
*/
160146
public void setEntrance(WalkableBlock block, WalkableBlock neighbor) {
161-
Vector3i position = ChunkMath.calcRelativeBlockPos(block.getBlockPosition());
147+
Vector3i position = Chunks.toRelative(block.getBlockPosition(), new Vector3i());
162148
Entrance entrance = setEntrance(position.x, position.z);
163149
entrance.neighborFloors.add(neighbor.floor);
164150
}

src/main/java/org/terasology/navgraph/FloorFinder.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
/*
2-
* Copyright 2014 MovingBlocks
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2020 The Terasology Foundation
2+
// SPDX-License-Identifier: Apache-2.0
163
package org.terasology.navgraph;
174

185
import com.google.common.collect.Lists;
196
import com.google.common.collect.Maps;
20-
import org.terasology.math.geom.Vector3i;
7+
import org.joml.Vector3ic;
218

229
import java.util.Collections;
2310
import java.util.Comparator;
@@ -91,7 +78,7 @@ public int compare(Region o1, Region o2) {
9178
}
9279

9380
void findRegions(NavGraphChunk map) {
94-
Vector3i worldPos = map.worldPos;
81+
Vector3ic worldPos = map.worldPos;
9582
regions.clear();
9683
regionMap.clear();
9784
sweepMap.clear();
@@ -123,7 +110,7 @@ void findRegions(NavGraphChunk map) {
123110
Sweep sweep = sweepMap.remove(block);
124111
Region region = sweep.region;
125112
regionMap.put(block, region);
126-
region.setPassable(block.x() - worldPos.x, block.z() - worldPos.z);
113+
region.setPassable(block.x() - worldPos.x(), block.z() - worldPos.z());
127114
}
128115
}
129116
}

src/main/java/org/terasology/navgraph/NavGraphCell.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
/*
2-
* Copyright 2014 MovingBlocks
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2020 The Terasology Foundation
2+
// SPDX-License-Identifier: Apache-2.0
163
package org.terasology.navgraph;
174

185
import java.util.ArrayList;

src/main/java/org/terasology/navgraph/NavGraphChanged.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
/*
2-
* Copyright 2014 MovingBlocks
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2020 The Terasology Foundation
2+
// SPDX-License-Identifier: Apache-2.0
163
package org.terasology.navgraph;
174

18-
import org.terasology.entitySystem.event.Event;
5+
import org.terasology.engine.entitySystem.event.Event;
196

207
/**
218
* Created by synopia on 02.02.14.

0 commit comments

Comments
 (0)