Enable script in big world (#884)

* add docs for tower

* fix: LEAK: ByteBuf.release() was not called

* enableScriptInBigWorld

* not print log when loaded scripts from cache

* revert the change of server tick

* revert the change of server tick

* fix

* optimize the performance: lazy load & cache

* fix the refresh group

* fix NPE

Co-authored-by: Melledy <52122272+Melledy@users.noreply.github.com>
This commit is contained in:
Akka
2022-05-15 19:19:24 +08:00
committed by GitHub
parent eb64b25f12
commit 6dc30e4def
21 changed files with 643 additions and 321 deletions

View File

@@ -0,0 +1,41 @@
package emu.grasscutter.scripts;
import ch.ethz.globis.phtree.PhTree;
import emu.grasscutter.utils.Position;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
public class SceneIndexManager {
public static <T> void buildIndex(PhTree<T> tree, List<T> elements, Function<T, long[]> extractor){
elements.forEach(e -> tree.put(extractor.apply(e), e));
}
public static <T> List<T> queryNeighbors(PhTree<T> tree, Position position, int range){
var result = new ArrayList<T>();
var arrPos = position.toLongArray();
var query = tree.query(calRange(arrPos, -range), calRange(arrPos, range));
while(query.hasNext()){
var element = query.next();
result.add(element);
}
return result;
}
public static <T> List<T> queryNeighbors(PhTree<T> tree, long[] position, int range){
var result = new ArrayList<T>();
var query = tree.query(calRange(position, -range), calRange(position, range));
while(query.hasNext()){
var element = query.next();
result.add(element);
}
return result;
}
private static long[] calRange(long[] position, int range){
var newPos = position.clone();
for(int i=0;i<position.length;i++){
newPos[i] += range;
}
return newPos;
}
}