SteamWar/BauSystem2.0
Archiviert
12
0

Optimize BundleFilter
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
yoyosource 2024-04-07 13:29:30 +02:00
Ursprung d8d049d5d9
Commit 207826ae8a
2 geänderte Dateien mit 30 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -30,7 +30,6 @@ import de.steamwar.entity.REntityServer;
import lombok.Getter; import lombok.Getter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.Array;
import java.util.*; import java.util.*;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -222,7 +221,8 @@ public class Trace {
private List<List<TNTRecord>> bundleRecords(List<TNTRecord> records, BundleFilter filter){ private List<List<TNTRecord>> bundleRecords(List<TNTRecord> records, BundleFilter filter){
List<List<TNTRecord>> bundles = new ArrayList<>(); List<List<TNTRecord>> bundles = new ArrayList<>();
recordsLoop : for(TNTRecord record : records) { recordsLoop:
for (TNTRecord record : records) {
if(bundles.isEmpty()){ if(bundles.isEmpty()){
List<TNTRecord> firstBundle = new ArrayList<>(); List<TNTRecord> firstBundle = new ArrayList<>();
firstBundle.add(record); firstBundle.add(record);
@ -232,17 +232,15 @@ public class Trace {
for(int i = bundles.size() - 1; i >= 0; i--){ for(int i = bundles.size() - 1; i >= 0; i--){
List<TNTRecord> bundle = bundles.get(i); List<TNTRecord> bundle = bundles.get(i);
Optional<Boolean> filterResult = filter.apply.apply(record, bundle.get(0)); Boolean filterResult = filter.function.apply(record, bundle.get(0));
if (filterResult == null || !filterResult) {
if(filterResult.isPresent() && filterResult.get())
bundle.add(record);
else{
ArrayList<TNTRecord> newBundle = new ArrayList<>(); ArrayList<TNTRecord> newBundle = new ArrayList<>();
newBundle.add(record); newBundle.add(record);
bundles.add(newBundle); bundles.add(newBundle);
continue recordsLoop; continue recordsLoop;
} else {
bundle.add(record);
} }
} }
} }

Datei anzeigen

@ -20,45 +20,47 @@
package de.steamwar.bausystem.features.tracer.rendering; package de.steamwar.bausystem.features.tracer.rendering;
import de.steamwar.bausystem.features.tracer.TNTRecord; import de.steamwar.bausystem.features.tracer.TNTRecord;
import lombok.RequiredArgsConstructor;
import java.util.Optional;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@RequiredArgsConstructor
public enum BundleFilter { public enum BundleFilter {
//TODO chagne optional to true flase null
LOOSE((TNTRecord a, TNTRecord b) -> { LOOSE((TNTRecord a, TNTRecord b) -> {
if(a.isExplosion() != b.isExplosion()) return Optional.of(false); if (a.isExplosion() != b.isExplosion()) return false;
if(a.getLocation().distance(b.getLocation()) <= BundleFilter.pixelSize) return Optional.of(false); if (a.getLocation().distanceSquared(b.getLocation()) <= BundleFilter.pixelSizeSquared) return false;
if(a.getVelocity().distance(b.getVelocity()) <= BundleFilter.pixelSize) return Optional.of(false); if (a.getVelocity().distanceSquared(b.getVelocity()) <= BundleFilter.pixelSizeSquared) return false;
return Optional.of(true); return true;
}), }),
DEFAULT((TNTRecord a, TNTRecord b) -> { DEFAULT((TNTRecord a, TNTRecord b) -> {
if(a.isExplosion() != b.isExplosion()) return Optional.of(false); if (a.isExplosion() != b.isExplosion()) return false;
if(a.getTicksSinceStart() != b.getTicksSinceStart()) return Optional.empty(); if (a.getTicksSinceStart() != b.getTicksSinceStart()) return null;
if(a.getLocation().distance(b.getLocation()) <= BundleFilter.pixelSize) return Optional.of(false); if (a.getLocation().distanceSquared(b.getLocation()) <= BundleFilter.pixelSizeSquared) return false;
if(a.getVelocity().distance(b.getVelocity()) <= BundleFilter.pixelSize) return Optional.of(false); if (a.getVelocity().distanceSquared(b.getVelocity()) <= BundleFilter.pixelSizeSquared) return false;
return Optional.of(true); return true;
}), }),
STRICT((TNTRecord a, TNTRecord b) -> { STRICT((TNTRecord a, TNTRecord b) -> {
if(a.isExplosion() != b.isExplosion()) return Optional.of(false); if (a.isExplosion() != b.isExplosion()) return false;
if(!a.getLocation().equals(b.getLocation())) return Optional.of(false); if (!a.getLocation().equals(b.getLocation())) return false;
if(!a.getVelocity().equals(b.getVelocity())) return Optional.of(false); if (!a.getVelocity().equals(b.getVelocity())) return false;
if(a.getTicksSinceStart() != b.getTicksSinceStart()) return Optional.empty(); if (a.getTicksSinceStart() != b.getTicksSinceStart()) return null;
return Optional.of(true); return true;
}), }),
NONE((TNTRecord a, TNTRecord b) -> { NONE((TNTRecord a, TNTRecord b) -> {
return Optional.empty(); return null;
}); });
public BiFunction<TNTRecord, TNTRecord, Optional<Boolean>> apply; /**
* {@code null}: Bundling can be stopped from this point forward
* {@code false}: No bundling allowed
* {@code true}: Bundling should be applied
*/
public final BiFunction<TNTRecord, TNTRecord, Boolean> function;
private static final double pixelSize = 0.0625; private static final double pixelSize = 0.0625;
private static final double pixelSizeSquared = pixelSize * pixelSize;
BundleFilter(BiFunction<TNTRecord, TNTRecord, Optional<Boolean>> apply){
this.apply = apply;
}
} }