SteamWar/BauSystem2.0
Archiviert
12
0

Added option for bundeling to trace rendering
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
D4rkr34lm 2023-12-23 17:43:34 +01:00
Ursprung 85512be3a8
Commit beb49cdcd1
5 geänderte Dateien mit 86 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,63 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.tracer2;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
public enum BundleFilter {
LOOSE((TNTRecord a, TNTRecord b) -> {
if(a.isExplosion() != b.isExplosion()) return Optional.of(false);
if(a.getLocation().distance(b.getLocation()) <= BundleFilter.pixelSize) return Optional.of(false);
if(a.getVelocity().distance(b.getVelocity()) <= BundleFilter.pixelSize) return Optional.of(false);
return Optional.of(true);
}),
DEFAULT((TNTRecord a, TNTRecord b) -> {
if(a.isExplosion() != b.isExplosion()) return Optional.of(false);
if(a.getTicksSinceStart() != b.getTicksSinceStart()) return Optional.empty();
if(a.getLocation().distance(b.getLocation()) <= BundleFilter.pixelSize) return Optional.of(false);
if(a.getVelocity().distance(b.getVelocity()) <= BundleFilter.pixelSize) return Optional.of(false);
return Optional.of(true);
}),
STRICT((TNTRecord a, TNTRecord b) -> {
if(a.isExplosion() != b.isExplosion()) return Optional.of(false);
if(!a.getLocation().equals(b.getLocation())) return Optional.of(false);
if(!a.getVelocity().equals(b.getVelocity())) return Optional.of(false);
if(a.getTicksSinceStart() != b.getTicksSinceStart()) return Optional.empty();
return Optional.of(true);
}),
NONE((TNTRecord a, TNTRecord b) -> {
return Optional.empty();
});
public BiFunction<TNTRecord, TNTRecord, Optional<Boolean>> apply;
private static final double pixelSize = 0.0625;
BundleFilter(BiFunction<TNTRecord, TNTRecord, Optional<Boolean>> apply){
this.apply = apply;
}
}

Datei anzeigen

@ -28,7 +28,6 @@ import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.TNTPrimeEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.EntitySpawnEvent;

Datei anzeigen

@ -78,7 +78,7 @@ public class Trace {
* @param player The player the trace is rendered to * @param player The player the trace is rendered to
* @param flags Flags modefieing the rendering * @param flags Flags modefieing the rendering
*/ */
public void render(Player player, Collection<ViewFlag> flags){ public void render(Player player, Collection<ViewFlag> flags, BundleFilter bundleFilter){
List<TNTRecord> workingRecords = records; List<TNTRecord> workingRecords = records;
//Apply filters //Apply filters
@ -86,7 +86,7 @@ public class Trace {
workingRecords = flag.filter.apply(workingRecords); workingRecords = flag.filter.apply(workingRecords);
//Bundle records at unique positions //Bundle records at unique positions
List<List<TNTRecord>> bundles = bundleRecords(workingRecords); List<List<TNTRecord>> bundles = bundleRecords(workingRecords, bundleFilter);
//Render bundled records //Render bundled records
REntityServer server = new REntityServer(); REntityServer server = new REntityServer();
@ -106,20 +106,27 @@ public class Trace {
* @param records The TNTRecords that are supposed to be bundled * @param records The TNTRecords that are supposed to be bundled
* @return A list of bundles * @return A list of bundles
*/ */
private List<List<TNTRecord>> bundleRecords(List<TNTRecord> records){ private List<List<TNTRecord>> bundleRecords(List<TNTRecord> records, BundleFilter filter){
Map <Location, List<TNTRecord>> entitiesRecords = new HashMap<>(); ArrayList<List<TNTRecord>> bundles = new ArrayList<>();
for(TNTRecord record : records) { recordsLoop : for(TNTRecord record : records) {
if(entitiesRecords.containsKey(record.getLocation())) for(int i = bundles.size() - 1; i >= 0; i--){
entitiesRecords.get(record.getLocation()); List<TNTRecord> bundle = bundles.get(i);
Optional<Boolean> filterResult = filter.apply.apply(record, bundle.get(0));
if(filterResult.isPresent() && filterResult.get())
bundle.add(record);
else{ else{
List <TNTRecord> entityRecords = new ArrayList<>(); ArrayList<TNTRecord> newBundle = new ArrayList<>();
entityRecords.add(record); newBundle.add(record);
entitiesRecords.put(record.getLocation(), entityRecords); continue recordsLoop;
}
} }
} }
return new LinkedList<>(entitiesRecords.values()); return bundles;
} }
/** Hides this trail for the given player /** Hides this trail for the given player

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bausystem.features.tracer2; package de.steamwar.bausystem.features.tracer2;
import de.steamwar.bausystem.region.Region;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance; import de.steamwar.linkage.LinkedInstance;
@ -31,8 +32,9 @@ public class TraceCommand extends SWCommand {
public Recorder recorder; public Recorder recorder;
public TraceCommand(){super("tracetest");} public TraceCommand(){super("tracetest");}
@Register @Register(value = "start")
public void test(@Validator Player player){ public void test(@Validator Player player){
Region region = Region.getRegion(player.getLocation());
} }
} }

Datei anzeigen

@ -20,10 +20,7 @@
package de.steamwar.bausystem.features.tracer2; package de.steamwar.bausystem.features.tracer2;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.entity.REntityServer;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import java.util.*; import java.util.*;
@ -97,12 +94,4 @@ public class TraceManager implements Listener {
public Set<Trace> getAll(){ public Set<Trace> getAll(){
return new HashSet<>(traces.values()); return new HashSet<>(traces.values());
} }
/** Renders the given trace records
*
* @param player The player the trace is rendered to
* @param trace the trace to render
* @param flags Flags modefieing the rendering
*/
} }