Fixed compilation problems and added MultiLOC

(MultiLOC is MultiLowOverheadCache)
This commit is contained in:
OLEGSHA 2020-11-21 23:51:14 +03:00
parent 372f173723
commit ce2d4297dd
3 changed files with 27 additions and 2 deletions

View File

@ -0,0 +1,25 @@
package ru.windcorp.progressia.common.util;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
public class MultiLOC {
private final Map<Class<?>, LowOverheadCache<?>> caches = new HashMap<>();
public <T> MultiLOC addClass(Class<T> clazz, Supplier<T> generator) {
caches.put(clazz, new LowOverheadCache<>(generator));
return this;
}
public <T> T grab(Class<T> clazz) {
return clazz.cast(caches.get(clazz).grab());
}
@SuppressWarnings("unchecked")
public void release(Object obj) {
((LowOverheadCache<Object>) caches.get(obj.getClass())).release(obj);
}
}

View File

@ -53,7 +53,7 @@ public class ImplementedChangeTracker implements Changer {
Vec3i blockInChunk = Vectors.grab3i(); Vec3i blockInChunk = Vectors.grab3i();
Coordinates.convertInWorldToInChunk(position, blockInChunk); Coordinates.convertInWorldToInChunk(position, blockInChunk);
world.getChunkByBlock(position).setBlock(blockInChunk, block); world.getChunkByBlock(position).setBlock(blockInChunk, block, true);
Vectors.release(blockInChunk); Vectors.release(blockInChunk);
} }

View File

@ -2,7 +2,7 @@ package ru.windcorp.progressia.server.world.block;
import ru.windcorp.progressia.server.world.Changer; import ru.windcorp.progressia.server.world.Changer;
public interface UpdatableBlock { public interface UpdateableBlock {
void update(BlockTickContext context, Changer changer); void update(BlockTickContext context, Changer changer);