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;
|
return;
|
||||||
|
|
||||||
for (File traceFile : traceFiles) {
|
for (File traceFile : traceFiles) {
|
||||||
if (traceFile.getName().contains(".records"))
|
if (traceFile.getName().contains(".meta"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (TraceRepository.getVersion(traceFile) == TraceRepository.SERIALISATION_VERSION) {
|
if (TraceRepository.getVersion(traceFile) == TraceRepository.SERIALISATION_VERSION) {
|
||||||
add(TraceRepository.readTrace(traceFile));
|
add(TraceRepository.readTrace(traceFile));
|
||||||
} else {
|
} else {
|
||||||
String uuid = traceFile.getName().replace(".meta", "");
|
String uuid = traceFile.getName().replace(".records", "");
|
||||||
|
|
||||||
new File(tracesFolder, uuid + ".records").deleteOnExit();
|
new File(tracesFolder, uuid + ".records").deleteOnExit();
|
||||||
new File(tracesFolder, uuid + ".meta").deleteOnExit();
|
new File(tracesFolder, uuid + ".meta").deleteOnExit();
|
||||||
|
|||||||
+55
-29
@@ -34,17 +34,16 @@ public class TraceRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static Trace readTrace(File metadataFile) {
|
public static Trace readTrace(File recordsFile) {
|
||||||
@Cleanup
|
@Cleanup
|
||||||
ObjectInputStream reader = new ObjectInputStream(new FileInputStream(metadataFile));
|
ObjectInputStream reader = new ObjectInputStream(new FileInputStream(recordsFile));
|
||||||
UUID uuid = UUID.fromString(reader.readUTF());
|
UUID uuid = UUID.fromString(reader.readUTF());
|
||||||
Region region = Region.getREGION_MAP().get(reader.readUTF());
|
Region region = Region.getREGION_MAP().get(reader.readUTF());
|
||||||
Date date = (Date) reader.readObject();
|
Date date = (Date) reader.readObject();
|
||||||
File recordsFile = new File(tracesFolder,uuid + ".records");
|
|
||||||
int serialisationVersion = reader.readInt();
|
int serialisationVersion = reader.readInt();
|
||||||
int recordsCount = 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
|
@SneakyThrows
|
||||||
@@ -53,38 +52,65 @@ public class TraceRepository {
|
|||||||
outputStream.writeUTF(trace.getUuid().toString());
|
outputStream.writeUTF(trace.getUuid().toString());
|
||||||
outputStream.writeUTF(trace.getRegion().getName());
|
outputStream.writeUTF(trace.getRegion().getName());
|
||||||
outputStream.writeObject(trace.getDate());
|
outputStream.writeObject(trace.getDate());
|
||||||
outputStream.writeInt(SERIALISATION_VERSION);
|
outputStream.writeInt(SERIALISATION_VERSION + 1);
|
||||||
outputStream.writeInt(records.size());
|
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.flush();
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
|
|
||||||
|
|
||||||
writeTraceRecords(trace.getRecordsSaveFile(), records);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
protected static void writeTraceRecords(File recordsFile, List<TNTPoint> records) {
|
private static void writeTNTPoint(ObjectOutputStream outputStream, TNTPoint tntPoint, boolean writeTickData) {
|
||||||
DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(recordsFile));
|
byte data = 0;
|
||||||
for (TNTPoint record : records) {
|
if (writeTickData) data |= 0x01;
|
||||||
outputStream.writeInt(record.getTntId());
|
if (tntPoint.isExplosion()) data |= 0x02;
|
||||||
outputStream.writeBoolean(record.isExplosion());
|
if (tntPoint.isInWater()) data |= 0x04;
|
||||||
outputStream.writeBoolean(record.isInWater());
|
if (tntPoint.isAfterFirstExplosion()) data |= 0x08;
|
||||||
outputStream.writeBoolean(record.isAfterFirstExplosion());
|
if (tntPoint.isDestroyedBuildArea()) data |= 0x10;
|
||||||
outputStream.writeBoolean(record.isDestroyedBuildArea());
|
if (tntPoint.isDestroyedTestBlock()) data |= 0x20;
|
||||||
outputStream.writeBoolean(record.isDestroyedTestBlock());
|
outputStream.write(data);
|
||||||
outputStream.writeLong(record.getTicksSinceStart());
|
|
||||||
outputStream.writeInt(record.getFuse());
|
if (writeTickData) {
|
||||||
Location location = record.getLocation();
|
outputStream.writeLong(tntPoint.getTicksSinceStart());
|
||||||
outputStream.writeDouble(location.getX());
|
outputStream.writeInt(tntPoint.getFuse());
|
||||||
outputStream.writeDouble(location.getY());
|
|
||||||
outputStream.writeDouble(location.getZ());
|
|
||||||
Vector velocity = record.getVelocity();
|
|
||||||
outputStream.writeDouble(velocity.getX());
|
|
||||||
outputStream.writeDouble(velocity.getY());
|
|
||||||
outputStream.writeDouble(velocity.getZ());
|
|
||||||
}
|
}
|
||||||
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
|
@SneakyThrows
|
||||||
|
|||||||
Reference in New Issue
Block a user