SnapshotBuffer class
Пакет: com.hypixel.hytale.server.core.modules.entity.component
Файл: com/hypixel/hytale/server/core/modules/entity/component/SnapshotBuffer.java
implements: Component<EntityStore>
Поля (10)
| Модификаторы | Тип | Имя |
|---|---|---|
private |
double[] |
positions |
|
SnapshotBuffer |
var1 |
|
int |
var2 |
|
|
var2 |
|
int |
var2 |
|
int |
var2 |
|
int |
var3 |
|
int |
var3 |
|
int |
var3 |
|
int |
var4 |
Методы (25)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
return new |
EntitySnapshotreturn new EntitySnapshot(this.positions[var3], this.positions[var3 + 1], this.positions[var3 + 2], this.rotations[var3], this.rotations[var3 + 1], this.rotations[var3 + 2]) |
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Tick index is in the future") |
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("New size is too small: " + var1) |
abstract |
throw new |
IllegalStateExceptionthrow new IllegalStateException("Snapshots not initialized") |
static |
ComponentType<EntityStore, SnapshotBuffer> |
getComponentTypeComponentType<EntityStore, SnapshotBuffer> getComponentType() |
public |
int |
getCurrentTickIndexint getCurrentTickIndex() |
public |
int |
getOldestTickIndexint getOldestTickIndex() |
|
|
if if(this.currentIndex == -1) |
|
|
if if(var2 > 0) |
|
|
if if(var2 < var3) |
|
|
if if(this.currentIndex == -1) |
|
|
if if(var2 > 0) |
|
|
if if(var2 < 0) |
|
|
if if(this.currentIndex != -1 && this.currentTickIndex == var1 - 1) |
|
|
if if(++this.currentIndex == this.capacity) |
|
|
if if(this.storedCount < this.capacity) |
|
|
if if(this.currentIndex != -1) |
|
|
if if(var1 <= 0) |
|
|
if if(this.rotations == null || this.capacity != var1) |
|
|
if if(this.rotations != null && this.currentIndex != -1) |
public |
boolean |
isInitializedboolean isInitialized() |
private |
EntitySnapshot |
readSnapshotRelativeEntitySnapshot readSnapshotRelative(int var1) |
public |
void |
resizevoid resize(int var1) |
public |
void |
storeSnapshotvoid storeSnapshot(int var1, @Nonnull Vector3d var2, @Nonnull Rotation3f var3) |
private |
void |
writeSlotvoid writeSlot(int var1, @Nonnull Vector3d var2, @Nonnull Rotation3f var3) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.modules.entity.component;
class="kw">import com.hypixel.hytale.component.Component;
class="kw">import com.hypixel.hytale.component.ComponentType;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.server.core.entity.EntitySnapshot;
class="kw">import com.hypixel.hytale.server.core.modules.entity.EntityModule;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">public class SnapshotBuffer class="kw">implements Component<EntityStore> {
class="kw">private double[] positions;
class="kw">private float[] rotations;
class="kw">private int capacity;
class="kw">private int currentTickIndex = Integer.MIN_VALUE;
class="kw">private int oldestTickIndex = Integer.MIN_VALUE;
class="kw">private int currentIndex = -1;
class="kw">private int storedCount = 0;
class="kw">public SnapshotBuffer() {
}
class="kw">public class="kw">static ComponentType<EntityStore, SnapshotBuffer> getComponentType() {
class="kw">return EntityModule.get().getSnapshotBufferComponentType();
}
@Nonnull
class="kw">public EntitySnapshot getSnapshotClamped(int var1) {
if (this.currentIndex == -1) {
throw new IllegalStateException("Snapshots not initialized");
}
int var2 = var1 - this.currentTickIndex;
int var3 = this.oldestTickIndex - this.currentTickIndex;
if (var2 > 0) {
throw new IllegalArgumentException("Tick index is in the future");
}
if (var2 < var3) {
var2 = var3;
}
class="kw">return this.readSnapshotRelative(var2);
}
@Nullable
class="kw">public EntitySnapshot getSnapshot(int var1) {
if (this.currentIndex == -1) {
class="kw">return null;
} else {
int var2 = var1 - this.currentTickIndex;
int var3 = this.oldestTickIndex - this.currentTickIndex;
if (var2 > 0) {
throw new IllegalArgumentException("Tick index is in the future");
} else {
class="kw">return var2 < var3 ? null : this.readSnapshotRelative(var2);
}
}
}
class="kw">private EntitySnapshot readSnapshotRelative(int var1) {
int var2 = this.currentIndex + var1;
if (var2 < 0) {
var2 += this.capacity;
}
int var3 = var2 * 3;
class="kw">return new EntitySnapshot(
this.positions[var3], this.positions[var3 + 1], this.positions[var3 + 2], this.rotations[var3], this.rotations[var3 + 1], this.rotations[var3 + 2]
);
}
class="kw">public void storeSnapshot(int var1, @Nonnull Vector3d var2, @Nonnull Rotation3f var3) {
if (this.currentIndex != -1 && this.currentTickIndex == var1 - 1) {
this.currentTickIndex = var1;
if (++this.currentIndex == this.capacity) {
this.currentIndex = 0;
}
if (this.storedCount < this.capacity) {
this.storedCount++;
} else {
this.oldestTickIndex++;
}
this.writeSlot(this.currentIndex, var2, var3);
} else {
if (this.currentIndex != -1) {
this.currentIndex = -1;
this.currentTickIndex = Integer.MIN_VALUE;
this.oldestTickIndex = Integer.MIN_VALUE;
this.storedCount = 0;
}
this.oldestTickIndex = var1;
this.currentTickIndex = var1;
this.currentIndex = 0;
this.storedCount = 1;
this.writeSlot(0, var2, var3);
}
}
class="kw">private void writeSlot(int var1, @Nonnull Vector3d var2, @Nonnull Rotation3f var3) {
int var4 = var1 * 3;
this.positions[var4] = var2.x;
this.positions[var4 + 1] = var2.y;
this.positions[var4 + 2] = var2.z;
this.rotations[var4] = var3.x;
this.rotations[var4 + 1] = var3.y;
this.rotations[var4 + 2] = var3.z;
}
class="kw">public void resize(int var1) {
if (var1 <= 0) {
throw new IllegalArgumentException("New size is too small: " + var1);
}
if (this.rotations == null || this.capacity != var1) {
this.capacity = var1;
this.positions = new double[var1 * 3];
this.rotations = new float[var1 * 3];
this.currentIndex = -1;
this.currentTickIndex = Integer.MIN_VALUE;
this.oldestTickIndex = Integer.MIN_VALUE;
this.storedCount = 0;
}
}
class="kw">public boolean isInitialized() {
class="kw">return this.currentIndex != -1;
}
class="kw">public int getCurrentTickIndex() {
class="kw">return this.currentTickIndex;
}
class="kw">public int getOldestTickIndex() {
class="kw">return this.oldestTickIndex;
}
@Nonnull
@Override
class="kw">public Component<EntityStore> clone() {
SnapshotBuffer var1 = new SnapshotBuffer();
if (this.rotations != null && this.currentIndex != -1) {
var1.positions = (double[])this.positions.clone();
var1.rotations = (float[])this.rotations.clone();
var1.capacity = this.capacity;
var1.currentTickIndex = this.currentTickIndex;
var1.oldestTickIndex = this.oldestTickIndex;
var1.currentIndex = this.currentIndex;
var1.storedCount = this.storedCount;
class="kw">return var1;
} else {
class="kw">return var1;
}
}
}