forked from xjboss/KCauldronX
Return loop iterating over entites on overloaded server
This commit is contained in:
parent
9d56192606
commit
b2e14cb247
@ -321,8 +321,7 @@
|
||||
- if (this.playerEntity.isPlayerSleeping())
|
||||
+ /*if (this.playerEntity.isPlayerSleeping()) // KCauldron - moved up
|
||||
{
|
||||
- this.playerEntity.onUpdateEntity();
|
||||
+ this.playerEntity.onUpdateEntity();
|
||||
this.playerEntity.onUpdateEntity();
|
||||
this.playerEntity.setPositionAndRotation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch);
|
||||
worldserver.updateEntity(this.playerEntity);
|
||||
return;
|
||||
|
@ -107,11 +107,11 @@
|
||||
- public List loadedTileEntityList = new ArrayList();
|
||||
- private List addedTileEntityList = new ArrayList();
|
||||
- private List field_147483_b = new ArrayList();
|
||||
+ public Queue<Entity> loadedEntityList_KC = new ConcurrentLinkedQueue<Entity>(); // KCauldron
|
||||
+ public List<Entity> loadedEntityList = new kcauldron.wrapper.QueueToList<Entity>(loadedEntityList_KC); // KCauldron
|
||||
+ public Queue<Entity> loadedEntityList_KC = new kcauldron.wrapper.ProcessingQueue<Entity>(new ConcurrentLinkedQueue<Entity>()); // KCauldron
|
||||
+ public List<Entity> loadedEntityList = new kcauldron.wrapper.QueueToList<Entity>(((kcauldron.wrapper.ProcessingQueue<Entity>)loadedEntityList_KC).unwrap()); // KCauldron
|
||||
+ public List<Entity> unloadedEntityList = com.google.common.collect.ImmutableList.of(); // KCauldron
|
||||
+ public Queue<TileEntity> loadedTileEntityList_KC = new ConcurrentLinkedQueue<TileEntity>(); // KCauldron
|
||||
+ public List<TileEntity> loadedTileEntityList = new kcauldron.wrapper.QueueToList<TileEntity>(loadedTileEntityList_KC); // KCauldron
|
||||
+ public Queue<TileEntity> loadedTileEntityList_KC = new kcauldron.wrapper.ProcessingQueue<TileEntity>(new ConcurrentLinkedQueue<TileEntity>()); // KCauldron
|
||||
+ public List<TileEntity> loadedTileEntityList = new kcauldron.wrapper.QueueToList<TileEntity>(((kcauldron.wrapper.ProcessingQueue<TileEntity>)loadedTileEntityList_KC).unwrap()); // KCauldron
|
||||
+ private List<TileEntity> addedTileEntityList = new ArrayList<TileEntity>(); // KCauldron
|
||||
+ public List<TileEntity> field_147483_b = com.google.common.collect.ImmutableList.of(); // KCauldron
|
||||
public List playerEntities = new ArrayList();
|
||||
|
@ -4,7 +4,7 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class CollectionWrapper<T, C extends Collection<T>> implements Collection<T> {
|
||||
private C mCollection;
|
||||
protected C mCollection;
|
||||
|
||||
public CollectionWrapper(C collection) {
|
||||
mCollection = collection;
|
||||
@ -74,4 +74,8 @@ public class CollectionWrapper<T, C extends Collection<T>> implements Collection
|
||||
public <T> T[] toArray(T[] a) {
|
||||
return mCollection.toArray(a);
|
||||
}
|
||||
|
||||
public C unwrap() {
|
||||
return mCollection;
|
||||
}
|
||||
}
|
||||
|
132
src/main/java/kcauldron/wrapper/ProcessingQueue.java
Normal file
132
src/main/java/kcauldron/wrapper/ProcessingQueue.java
Normal file
@ -0,0 +1,132 @@
|
||||
package kcauldron.wrapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ProcessingQueue<T> extends QueueWrapper<T> {
|
||||
public class ProcessingIterator implements Iterator<T> {
|
||||
private Iterator<T> mRealIterator = mCollection.iterator();
|
||||
private AtomicInteger mPosition = new AtomicInteger(0);
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
final int size = mSize.get();
|
||||
final int position = mPosition.get();
|
||||
if (size == 0 || position >= size) {
|
||||
mPosition.compareAndSet(position, 0);
|
||||
mRealIterator = mCollection.iterator();
|
||||
return false;
|
||||
}
|
||||
boolean value = mRealIterator.hasNext();
|
||||
if (!value) {
|
||||
mRealIterator = mCollection.iterator();
|
||||
value = mRealIterator.hasNext();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
T value = mRealIterator.next();
|
||||
mPosition.incrementAndGet();
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
mRealIterator.remove();
|
||||
mSize.decrementAndGet();
|
||||
mPosition.decrementAndGet();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
mPosition.set(0);
|
||||
}
|
||||
}
|
||||
|
||||
private final AtomicInteger mSize;
|
||||
private final ProcessingIterator mIterator = new ProcessingIterator();
|
||||
|
||||
@Override
|
||||
public boolean add(T e) {
|
||||
boolean result = super.add(e);
|
||||
if (result) {
|
||||
mSize.incrementAndGet();
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean offer(T e) {
|
||||
boolean result = super.offer(e);
|
||||
if (result) {
|
||||
mSize.incrementAndGet();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends T> c) {
|
||||
boolean result = false;
|
||||
for (T t : c) {
|
||||
result |= add(t);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove() {
|
||||
T result = super.remove();
|
||||
mSize.decrementAndGet();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
boolean result = super.remove(o);
|
||||
if (result) {
|
||||
mSize.decrementAndGet();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
boolean result = false;
|
||||
for (Object t : c) {
|
||||
result |= remove(t);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
boolean result = super.retainAll(c);
|
||||
if (result) {
|
||||
mSize.set(mCollection.size());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T poll() {
|
||||
T result = super.remove();
|
||||
if (result != null) {
|
||||
mSize.decrementAndGet();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ProcessingQueue(Queue<T> collection) {
|
||||
super(collection);
|
||||
mSize = new AtomicInteger(collection.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessingIterator iterator() {
|
||||
mIterator.reset();
|
||||
return mIterator;
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Queue;
|
||||
|
||||
public class QueueToList<T> extends CollectionWrapper<T, Queue<T>>implements List<T> {
|
||||
public class QueueToList<T> extends CollectionWrapper<T, Queue<T>> implements List<T> {
|
||||
private final Queue<T> mQueue;
|
||||
private final LinkedHelper<T> mHelper;
|
||||
|
||||
|
34
src/main/java/kcauldron/wrapper/QueueWrapper.java
Normal file
34
src/main/java/kcauldron/wrapper/QueueWrapper.java
Normal file
@ -0,0 +1,34 @@
|
||||
package kcauldron.wrapper;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
public class QueueWrapper<T> extends CollectionWrapper<T, Queue<T>> implements Queue<T>{
|
||||
public QueueWrapper(Queue<T> collection) {
|
||||
super(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T element() {
|
||||
return mCollection.element();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean offer(T e) {
|
||||
return mCollection.offer(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T peek() {
|
||||
return mCollection.peek();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T poll() {
|
||||
return mCollection.poll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove() {
|
||||
return mCollection.remove();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user