Skip to content

Commit

Permalink
complete async tracker w per-world persis state!
Browse files Browse the repository at this point in the history
  • Loading branch information
insanj committed Apr 7, 2019
1 parent 99d455f commit 7fc91c3
Show file tree
Hide file tree
Showing 24 changed files with 32 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ world_the_end/
uploads/
external/

.gradle/

# Compiled class file
*.class

Expand Down
10 changes: 5 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
<br/>

<a href="https://jdk.java.net/">
<img src="https://img.shields.io/badge/java-10.0.2-red.svg" />
<img src="https://img.shields.io/badge/java-8-red.svg" />
</a>

<a href="https://getbukkit.org/download/craftbukkit">
<img src="https://img.shields.io/badge/bukkit-1.13.2-orange.svg" />
<a href="https://fabricmc.net/">
<img src="https://img.shields.io/badge/fabric-19w12b-orange.svg" />
</a>

<a href="https://www.spigotmc.org/resources/pride.64859/">
<img src="https://img.shields.io/badge/🚀-Download%20on%20spigotmc.org-blue.svg" />
<a href="https://github.com/insanj/pride/releases/">
<img src="https://img.shields.io/badge/🚀-Download%20on%20Github-blue.svg" />
</a>
</p>

Expand Down
Binary file removed plugin/.gradle/4.10.2/fileChanges/last-build.bin
Binary file not shown.
Binary file not shown.
Binary file removed plugin/.gradle/4.10.2/fileContent/fileContent.lock
Binary file not shown.
Binary file removed plugin/.gradle/4.10.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file removed plugin/.gradle/4.10.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file not shown.
Empty file.
Binary file removed plugin/.gradle/4.10.2/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file removed plugin/.gradle/4.10.2/javaCompile/jarAnalysis.bin
Binary file not shown.
Binary file removed plugin/.gradle/4.10.2/javaCompile/javaCompile.lock
Binary file not shown.
Binary file removed plugin/.gradle/4.10.2/javaCompile/taskHistory.bin
Binary file not shown.
Binary file removed plugin/.gradle/4.10.2/taskHistory/taskHistory.bin
Binary file not shown.
Binary file removed plugin/.gradle/4.10.2/taskHistory/taskHistory.lock
Binary file not shown.
Binary file not shown.
2 changes: 0 additions & 2 deletions plugin/.gradle/buildOutputCleanup/cache.properties

This file was deleted.

Binary file removed plugin/.gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
1 change: 0 additions & 1 deletion plugin/.gradle/minecraft/mixin-map-19w12b-10.tiny

This file was deleted.

1 change: 0 additions & 1 deletion plugin/.gradle/minecraft/mixin-map-19w12b-5.tiny

This file was deleted.

1 change: 0 additions & 1 deletion plugin/.gradle/minecraft/mixin-map-19w12b-9.tiny

This file was deleted.

1 change: 0 additions & 1 deletion plugin/.gradle/minecraft/mixin-map-19w13a-2.tiny

This file was deleted.

Empty file removed plugin/.gradle/vcs-1/gc.properties
Empty file.
58 changes: 25 additions & 33 deletions plugin/src/main/java/com/insanj/pride/PrideEntityTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,32 @@ public void register() {

// get all players logged into the server
Set<ServerPlayerEntity> entities = (Set<ServerPlayerEntity>)PlayerStream.all(server).collect(Collectors.toSet());
// System.out.println("entities = " + entities.toString());

// loop through all players active on server
for (ServerPlayerEntity player : entities) {
ServerWorld world = player.getServerWorld();
calculateActivatedPrideAreasForPlayer(world, player);
}

// reset bottleneck counter at end of execution/for loop
superLazyBottleneck = 0;
});
}

// async/thread-based function to run calculations for pride areas off main
public void calculateActivatedPrideAreasForPlayer(ServerWorld world, ServerPlayerEntity player) {
PrideEntityTracker tracker = this;
new Thread(new Runnable() {
public void run() {
String playerName = player.getName().getString();
BlockPos pos = player.getBlockPos();
ServerWorld world = player.getServerWorld();

// get pride areas for world that player is in (should be cached)
PridePersistentState persis = PridePersistentState.get(world);
Map<String, Map<String, Double>> areas = persis.getPrideAreas(world);

if (areas == null || areas.size() <= 0) {
continue; // no areas in this world
return; // no areas in this world
}

// System.out.println(String.format("looping through %s in %s seeing if %s is in range of something", areas.toString(), world.toString(), pos.toString()));
Expand All @@ -106,54 +118,34 @@ public void register() {

if (distanceBetween <= areaDetectionDistance) {
// activate!
if (currentlyActivatedAreas.get(playerName) == null) {
if (tracker.currentlyActivatedAreas.get(playerName) == null) {
ArrayList<String> playerActivatedAreas = new ArrayList<String>();
playerActivatedAreas.add(areaName);

currentlyActivatedAreas.put(playerName, playerActivatedAreas);
tracker.currentlyActivatedAreas.put(playerName, playerActivatedAreas);
player.addChatMessage(new StringTextComponent(String.format("%s activated %s!", playerName, areaName)), false);
}

// activate!
else if (currentlyActivatedAreas.get(playerName).contains(areaName) == false) {
ArrayList<String> playerActivatedAreas = currentlyActivatedAreas.get(playerName);
else if (tracker.currentlyActivatedAreas.get(playerName).contains(areaName) == false) {
ArrayList<String> playerActivatedAreas = tracker.currentlyActivatedAreas.get(playerName);
playerActivatedAreas.add(areaName);

currentlyActivatedAreas.put(playerName, playerActivatedAreas);
tracker.currentlyActivatedAreas.put(playerName, playerActivatedAreas);
player.addChatMessage(new StringTextComponent(String.format("%s activated %s!", playerName, areaName)), false);
}
}

// stop activating...
else {
if (currentlyActivatedAreas.get(playerName).contains(areaName)) {
ArrayList<String> playerActivatedAreas = currentlyActivatedAreas.get(playerName);
if (tracker.currentlyActivatedAreas.get(playerName) != null && tracker.currentlyActivatedAreas.get(playerName).contains(areaName)) {
ArrayList<String> playerActivatedAreas = tracker.currentlyActivatedAreas.get(playerName);
playerActivatedAreas.remove(areaName);
currentlyActivatedAreas.put(playerName, playerActivatedAreas);
tracker.currentlyActivatedAreas.put(playerName, playerActivatedAreas);
}
}
}
}

// reset bottleneck counter at end of execution/for loop
superLazyBottleneck = 0;
});
}

/*
private void useFabricTrackerPrototype() {
int trackingDistance = 50;
int updateIntervalTicks = 1;
boolean alwaysUpdateVelocity = false;
EntityCategory playerCategory = EntityType.PLAYER.category;
EntityType type = FabricEntityTypeBuilder.create(playerCategory, (entityType, world, entity) -> {
System.out.println("yo yo yo!");
System.out.println("tick! entity = " + entity.toString() + " world = " + world.toString());
return entity;
}).trackable(trackingDistance, updateIntervalTicks, alwaysUpdateVelocity).build();
EntityTrackingRegistry.INSTANCE.register(type, trackingDistance, updateIntervalTicks, alwaysUpdateVelocity);
}
*/
}).start();
}
}

0 comments on commit 7fc91c3

Please sign in to comment.