use of thpmc.engine.api.entity.TickBase in project THP-Engine by TheHollowPlanetMC.
the class TickRunner method run.
@Override
public void run() {
if (beforeTime + TIME - 20 > System.currentTimeMillis())
return;
if (isStopped)
return;
if (i % TPS == 0) {
long time = System.currentTimeMillis();
tps = ((double) Math.round((20.0 / (((double) (time - beforeTime)) / 1000.0)) * 10)) / 10;
beforeTime = time;
}
currentThread = Thread.currentThread();
this.lastTickMS = System.currentTimeMillis();
// Should remove check
entities.removeIf(TickBase::shouldRemove);
tickOnlyEntities.removeIf(TickBase::shouldRemove);
// Add entities
if (addEntities.size() != 0) {
try {
ADD_LOCK.lock();
for (TickBase entity : addEntities) {
if (entity instanceof EngineEntity) {
entities.add((EngineEntity) entity);
} else {
tickOnlyEntities.add(entity);
}
}
addEntities.clear();
} finally {
ADD_LOCK.unlock();
}
}
// tick
tickOnlyEntities.forEach(TickBase::tick);
entities.forEach(TickBase::tick);
// Tracker
for (EnginePlayer enginePlayer : EnginePlayer.getAllPlayers()) {
EntityTracker entityTracker = getEntityTracker(enginePlayer);
entityTracker.tick(entities);
}
if (i % 40 == 0) {
trackerMap.keySet().removeIf(enginePlayer -> !enginePlayer.getBukkitPlayer().isOnline());
}
entities.forEach(EngineEntity::setPreviousPosition);
if (i % 100 == 0)
System.out.printf("ID -> %d TPS: %.1f%n", ID, tps);
i++;
}
Aggregations