classpublicPriority 3
CacheVectorProvider
com.hypixel.hytale.builtin.hytalegenerator.vectorproviders.CacheVectorProvider
extends VectorProvider
1
Methods
1
Public Methods
2
Fields
1
Constructors
Constructors
public
CacheVectorProvider(VectorProvider vectorProvider, int threadCount)Methods
Public Methods (1)
public
Vector3d process(VectorProvider.Context context)@Nonnull@Override
Fields
Private/Package Fields (2)
private
WorkerIndexer.Data<CacheVectorProvider.Cache> threadDataprivate
VectorProvider vectorProviderInheritance
Parent
Current
Interface
Child
Use mouse wheel to zoom, drag to pan. Click nodes to navigate.
Related Classes
Used By
Source Code
package com.hypixel.hytale.builtin.hytalegenerator.vectorproviders;
import com.hypixel.hytale.builtin.hytalegenerator.threadindexer.WorkerIndexer;
import com.hypixel.hytale.math.vector.Vector3d;
import javax.annotation.Nonnull;
public class CacheVectorProvider extends VectorProvider {
@Nonnull
private final VectorProvider vectorProvider;
@Nonnull
private final WorkerIndexer.Data<CacheVectorProvider.Cache> threadData;
public CacheVectorProvider(@Nonnull VectorProvider vectorProvider, int threadCount) {
if (threadCount <= 0) {
throw new IllegalArgumentException("threadCount must be greater than 0");
} else {
this.vectorProvider = vectorProvider;
this.threadData = new WorkerIndexer.Data<>(threadCount, CacheVectorProvider.Cache::new);
}
}
@Nonnull
@Override
public Vector3d process(@Nonnull VectorProvider.Context context) {
CacheVectorProvider.Cache cache = this.threadData.get(context.workerId);
if (cache.position != null && cache.position.equals(context.position)) {
return cache.value;
} else {
if (cache.position == null) {
cache.position = new Vector3d();
}
cache.position.assign(context.position);
cache.value = this.vectorProvider.process(context);
return cache.value;
}
}
public static class Cache {
Vector3d position;
Vector3d value;
public Cache() {
}
}
}