forked from SteamWar/SteamWar
Add a simple smaller Trace file, not finished!
This commit is contained in:
+2
-2
@@ -58,13 +58,13 @@ public class TraceManager implements Listener {
|
||||
return;
|
||||
|
||||
for (File traceFile : traceFiles) {
|
||||
if (traceFile.getName().contains(".records"))
|
||||
if (traceFile.getName().contains(".meta"))
|
||||
continue;
|
||||
|
||||
if (TraceRepository.getVersion(traceFile) == TraceRepository.SERIALISATION_VERSION) {
|
||||
add(TraceRepository.readTrace(traceFile));
|
||||
} else {
|
||||
String uuid = traceFile.getName().replace(".meta", "");
|
||||
String uuid = traceFile.getName().replace(".records", "");
|
||||
|
||||
new File(tracesFolder, uuid + ".records").deleteOnExit();
|
||||
new File(tracesFolder, uuid + ".meta").deleteOnExit();
|
||||
|
||||
+55
-29
@@ -34,17 +34,16 @@ public class TraceRepository {
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static Trace readTrace(File metadataFile) {
|
||||
public static Trace readTrace(File recordsFile) {
|
||||
@Cleanup
|
||||
ObjectInputStream reader = new ObjectInputStream(new FileInputStream(metadataFile));
|
||||
ObjectInputStream reader = new ObjectInputStream(new FileInputStream(recordsFile));
|
||||
UUID uuid = UUID.fromString(reader.readUTF());
|
||||
Region region = Region.getREGION_MAP().get(reader.readUTF());
|
||||
Date date = (Date) reader.readObject();
|
||||
File recordsFile = new File(tracesFolder,uuid + ".records");
|
||||
int serialisationVersion = reader.readInt();
|
||||
int recordsCount = reader.readInt();
|
||||
|
||||
return new Trace(uuid, region, date, metadataFile, recordsFile, recordsCount);
|
||||
return new Trace(uuid, region, date, recordsFile, recordsFile, recordsCount);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@@ -53,38 +52,65 @@ public class TraceRepository {
|
||||
outputStream.writeUTF(trace.getUuid().toString());
|
||||
outputStream.writeUTF(trace.getRegion().getName());
|
||||
outputStream.writeObject(trace.getDate());
|
||||
outputStream.writeInt(SERIALISATION_VERSION);
|
||||
outputStream.writeInt(SERIALISATION_VERSION + 1);
|
||||
outputStream.writeInt(records.size());
|
||||
|
||||
Map<Integer, List<TNTPoint>> pointsByTNTId = new HashMap<>();
|
||||
records.forEach(tntPoint -> {
|
||||
pointsByTNTId.computeIfAbsent(tntPoint.getTntId(), integer -> new ArrayList<>()).add(tntPoint);
|
||||
});
|
||||
|
||||
for (Map.Entry<Integer, List<TNTPoint>> entry : pointsByTNTId.entrySet()) {
|
||||
outputStream.writeInt(entry.getKey());
|
||||
outputStream.write(entry.getValue().size());
|
||||
|
||||
for (int i = 0; i < entry.getValue().size(); i++) {
|
||||
TNTPoint current = entry.getValue().get(i);
|
||||
if (i == 0) {
|
||||
writeTNTPoint(outputStream, current, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
TNTPoint last = entry.getValue().get(i - 1);
|
||||
|
||||
boolean writeTickData = true;
|
||||
if (last.getTicksSinceStart() + 1 == current.getTicksSinceStart() && last.getFuse() - 1 == current.getFuse()) {
|
||||
writeTickData = false;
|
||||
}
|
||||
|
||||
writeTNTPoint(outputStream, current, writeTickData);
|
||||
}
|
||||
}
|
||||
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
|
||||
writeTraceRecords(trace.getRecordsSaveFile(), records);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
protected static void writeTraceRecords(File recordsFile, List<TNTPoint> records) {
|
||||
DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(recordsFile));
|
||||
for (TNTPoint record : records) {
|
||||
outputStream.writeInt(record.getTntId());
|
||||
outputStream.writeBoolean(record.isExplosion());
|
||||
outputStream.writeBoolean(record.isInWater());
|
||||
outputStream.writeBoolean(record.isAfterFirstExplosion());
|
||||
outputStream.writeBoolean(record.isDestroyedBuildArea());
|
||||
outputStream.writeBoolean(record.isDestroyedTestBlock());
|
||||
outputStream.writeLong(record.getTicksSinceStart());
|
||||
outputStream.writeInt(record.getFuse());
|
||||
Location location = record.getLocation();
|
||||
outputStream.writeDouble(location.getX());
|
||||
outputStream.writeDouble(location.getY());
|
||||
outputStream.writeDouble(location.getZ());
|
||||
Vector velocity = record.getVelocity();
|
||||
outputStream.writeDouble(velocity.getX());
|
||||
outputStream.writeDouble(velocity.getY());
|
||||
outputStream.writeDouble(velocity.getZ());
|
||||
private static void writeTNTPoint(ObjectOutputStream outputStream, TNTPoint tntPoint, boolean writeTickData) {
|
||||
byte data = 0;
|
||||
if (writeTickData) data |= 0x01;
|
||||
if (tntPoint.isExplosion()) data |= 0x02;
|
||||
if (tntPoint.isInWater()) data |= 0x04;
|
||||
if (tntPoint.isAfterFirstExplosion()) data |= 0x08;
|
||||
if (tntPoint.isDestroyedBuildArea()) data |= 0x10;
|
||||
if (tntPoint.isDestroyedTestBlock()) data |= 0x20;
|
||||
outputStream.write(data);
|
||||
|
||||
if (writeTickData) {
|
||||
outputStream.writeLong(tntPoint.getTicksSinceStart());
|
||||
outputStream.writeInt(tntPoint.getFuse());
|
||||
}
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
Location location = tntPoint.getLocation();
|
||||
outputStream.writeDouble(location.getX());
|
||||
outputStream.writeDouble(location.getY());
|
||||
outputStream.writeDouble(location.getZ());
|
||||
|
||||
Vector velocity = tntPoint.getVelocity();
|
||||
outputStream.writeDouble(velocity.getX());
|
||||
outputStream.writeDouble(velocity.getY());
|
||||
outputStream.writeDouble(velocity.getZ());
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
|
||||
Reference in New Issue
Block a user