use of gnu.trove.iterator.TIntIterator in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class SpatialDetector method calculateSpatialOccupation.
protected void calculateSpatialOccupation() {
nextQueue.add(firstBlock.getY() + maxRange * maxRangeHalved + maxRangeSquared * maxRangeHalved);
MutableBlockPos inRealWorld = new MutableBlockPos();
int hash;
while (!nextQueue.isEmpty() && !cleanHouse) {
TIntIterator queueIter = nextQueue.iterator();
foundSet.addAll(nextQueue);
nextQueue = new TIntHashSet();
while (queueIter.hasNext()) {
hash = queueIter.next();
setPosWithRespectTo(hash, firstBlock, inRealWorld);
if (corners) {
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY() - 1, inRealWorld.getZ() - 1, hash - maxRange - 1 - maxRangeSquared);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY() - 1, inRealWorld.getZ(), hash - maxRange - 1);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY() - 1, inRealWorld.getZ() + 1, hash - maxRange - 1 + maxRangeSquared);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY(), inRealWorld.getZ() - 1, hash - maxRange - maxRangeSquared);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY(), inRealWorld.getZ(), hash - maxRange);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY(), inRealWorld.getZ() + 1, hash - maxRange + maxRangeSquared);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY() + 1, inRealWorld.getZ() - 1, hash - maxRange + 1 - maxRangeSquared);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY() + 1, inRealWorld.getZ(), hash - maxRange + 1);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY() + 1, inRealWorld.getZ() + 1, hash - maxRange + 1 + maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() - 1, inRealWorld.getZ() - 1, hash - 1 - maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() - 1, inRealWorld.getZ(), hash - 1);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() - 1, inRealWorld.getZ() + 1, hash - 1 + maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY(), inRealWorld.getZ() - 1, hash - maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY(), inRealWorld.getZ() + 1, hash + maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() + 1, inRealWorld.getZ() - 1, hash + 1 - maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() + 1, inRealWorld.getZ(), hash + 1);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() + 1, inRealWorld.getZ() + 1, hash + 1 + maxRangeSquared);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY() - 1, inRealWorld.getZ() - 1, hash + maxRange - 1 - maxRangeSquared);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY() - 1, inRealWorld.getZ(), hash + maxRange - 1);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY() - 1, inRealWorld.getZ() + 1, hash + maxRange - 1 + maxRangeSquared);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY(), inRealWorld.getZ() - 1, hash + maxRange - maxRangeSquared);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY(), inRealWorld.getZ(), hash + maxRange);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY(), inRealWorld.getZ() + 1, hash + maxRange + maxRangeSquared);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY() + 1, inRealWorld.getZ() - 1, hash + maxRange + 1 - maxRangeSquared);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY() + 1, inRealWorld.getZ(), hash + maxRange + 1);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY() + 1, inRealWorld.getZ() + 1, hash + maxRange + 1 + maxRangeSquared);
} else {
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY(), inRealWorld.getZ(), hash + maxRange);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY(), inRealWorld.getZ(), hash - maxRange);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() + 1, inRealWorld.getZ(), hash + 1);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() - 1, inRealWorld.getZ(), hash - 1);
tryExpanding(inRealWorld.getX(), inRealWorld.getY(), inRealWorld.getZ() + 1, hash + maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY(), inRealWorld.getZ() - 1, hash - maxRangeSquared);
}
}
}
}
use of gnu.trove.iterator.TIntIterator in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldServerShipManager method spawnNewShips.
private void spawnNewShips() {
for (final ImmutableTriple<BlockPos, ShipData, BlockFinder.BlockFinderType> spawnData : spawnQueue) {
final BlockPos physicsInfuserPos = spawnData.getLeft();
final ShipData toSpawn = spawnData.getMiddle();
final BlockFinder.BlockFinderType blockBlockFinderType = spawnData.getRight();
if (loadedShips.containsKey(toSpawn.getUuid())) {
throw new IllegalStateException("Tried spawning a ShipData that was already loaded?\n" + toSpawn);
}
final SpatialDetector detector = BlockFinder.getBlockFinderFor(blockBlockFinderType, physicsInfuserPos, world, VSConfig.maxDetectedShipSize + 1, true);
if (VSConfig.showAnnoyingDebugOutput) {
System.out.println("Attempting to spawn " + toSpawn + " on the thread " + Thread.currentThread().getName());
}
if (detector.foundSet.size() > VSConfig.maxDetectedShipSize || detector.cleanHouse) {
System.err.println("Ship too big or bedrock detected!");
// Skip ship construction
continue;
}
// Fill the chunk claims
int radius = 7;
// TEMP CODE
// Eventually want to create mechanisms that control how many chunks are allocated to a ship
// But for now, lets just give them a bunch of chunks.
ChunkPos centerPos = toSpawn.getChunkClaim().getCenterPos();
for (int chunkX = -radius; chunkX <= radius; chunkX++) {
for (int chunkZ = -radius; chunkZ <= radius; chunkZ++) {
toSpawn.getChunkClaim().addChunkClaim(centerPos.x + chunkX, centerPos.z + chunkZ);
}
}
// When copying the ship chunks we want to keep track of the inertia and center of mass.
IPhysicsObjectCenterOfMassProvider centerOfMassProvider = new BasicCenterOfMassProvider();
// Then create the ship chunks
MutableBlockPos srcLocationPos = new MutableBlockPos();
BlockPos centerDifference = toSpawn.getChunkClaim().getRegionCenter().subtract(physicsInfuserPos);
MutableBlockPos pasteLocationPos = new MutableBlockPos();
Map<Long, Chunk> copiedChunksMap = new HashMap<>();
// First, copy the blocks and tiles to the new chunks
TIntIterator blocksIterator = detector.foundSet.iterator();
while (blocksIterator.hasNext()) {
int hashedPos = blocksIterator.next();
SpatialDetector.setPosWithRespectTo(hashedPos, detector.firstBlock, srcLocationPos);
// Get the BlockPos from the hashedPos
pasteLocationPos.setPos(srcLocationPos.getX() + centerDifference.getX(), srcLocationPos.getY() + centerDifference.getY(), srcLocationPos.getZ() + centerDifference.getZ());
// Then add it to the ShipData block positions set
toSpawn.blockPositions.add(pasteLocationPos.getX(), pasteLocationPos.getY(), pasteLocationPos.getZ());
// Then create a chunk to accommodate this block (if one does not already exist).
int newChunkX = pasteLocationPos.getX() >> 4;
int newChunkZ = pasteLocationPos.getZ() >> 4;
long newChunkPosLong = ChunkPos.asLong(newChunkX, newChunkZ);
if (!copiedChunksMap.containsKey(newChunkPosLong)) {
Chunk chunk = new Chunk(world, newChunkX, newChunkZ);
copiedChunksMap.put(newChunkPosLong, chunk);
}
// Then copy the IBlockState & TileEntity to the new Chunk
// Get the old world Chunk
Chunk chunkToSet = world.getChunk(srcLocationPos);
// Get the new Chunk
Chunk newChunk = copiedChunksMap.get(newChunkPosLong);
// Then get the old IBlockState, as efficiently as possible
int storageIndex = srcLocationPos.getY() >> 4;
// Check that we're placing the block in a valid position
if (storageIndex < 0 || storageIndex >= chunkToSet.storageArrays.length) {
// Invalid position, abort!
throw new IllegalStateException("Incorrect block copy!\n" + srcLocationPos);
}
IBlockState srcState = chunkToSet.storageArrays[storageIndex].get(srcLocationPos.getX() & 15, srcLocationPos.getY() & 15, srcLocationPos.getZ() & 15);
// Then paste that IBlockState into the new ship chunk
int newChunkStorageIndex = pasteLocationPos.getY() >> 4;
if (newChunk.storageArrays[newChunkStorageIndex] == Chunk.NULL_BLOCK_STORAGE) {
newChunk.storageArrays[newChunkStorageIndex] = new ExtendedBlockStorage(newChunkStorageIndex << 4, true);
}
newChunk.storageArrays[newChunkStorageIndex].set(pasteLocationPos.getX() & 15, pasteLocationPos.getY() & 15, pasteLocationPos.getZ() & 15, srcState);
// If this block is force block, then add it to the activeForcePositions list of the ship.
if (BlockPhysicsDetails.isBlockProvidingForce(srcState)) {
toSpawn.activeForcePositions.add(pasteLocationPos);
}
// Also update the center of mass and inertia provider
centerOfMassProvider.onSetBlockState(toSpawn.getInertiaData(), pasteLocationPos, Blocks.AIR.getDefaultState(), srcState);
// Then copy the TileEntity (if there is one)
TileEntity srcTile = world.getTileEntity(srcLocationPos);
if (srcTile != null) {
TileEntity pasteTile;
if (srcTile instanceof IRelocationAwareTile) {
pasteTile = ((IRelocationAwareTile) srcTile).createRelocatedTile(pasteLocationPos, toSpawn);
} else {
NBTTagCompound tileEntNBT = srcTile.writeToNBT(new NBTTagCompound());
// Change the block position to be inside of the Ship
tileEntNBT.setInteger("x", pasteLocationPos.getX());
tileEntNBT.setInteger("y", pasteLocationPos.getY());
tileEntNBT.setInteger("z", pasteLocationPos.getZ());
pasteTile = TileEntity.create(world, tileEntNBT);
}
// Finally, add the new TileEntity to the new ship chunk.
newChunk.addTileEntity(pasteTile);
}
}
for (final Chunk chunk : copiedChunksMap.values()) {
chunk.generateSkylightMap();
}
// Then delete the copied blocks from the old chunks
blocksIterator = detector.foundSet.iterator();
while (blocksIterator.hasNext()) {
int hashedPos = blocksIterator.next();
SpatialDetector.setPosWithRespectTo(hashedPos, detector.firstBlock, srcLocationPos);
Chunk chunkToSet = world.getChunk(srcLocationPos);
// Then get the old IBlockState, as efficiently as possible
int storageIndex = srcLocationPos.getY() >> 4;
// Check that we're placing the block in a valid position
if (storageIndex < 0 || storageIndex >= chunkToSet.storageArrays.length) {
// Invalid position, abort!
throw new IllegalStateException("Incorrect block copy!\n" + srcLocationPos);
}
IBlockState srcState = chunkToSet.storageArrays[storageIndex].get(srcLocationPos.getX() & 15, srcLocationPos.getY() & 15, srcLocationPos.getZ() & 15);
// THIS IS TEMP because its extremely inefficient.
// Come up with a clever way to let clients figure this out in the future.
world.notifyBlockUpdate(srcLocationPos, srcState, Blocks.AIR.getDefaultState(), 3);
// Finally, delete the old IBlockState and TileEntity from the old Chunk
chunkToSet.storageArrays[storageIndex].set(srcLocationPos.getX() & 15, srcLocationPos.getY() & 15, srcLocationPos.getZ() & 15, Blocks.AIR.getDefaultState());
// Delete the TileEntity at this pos (if there is one)
world.removeTileEntity(srcLocationPos);
chunkToSet.markDirty();
}
// Then relight the original chunks
{
Set<Long> chunksRelit = new HashSet<>();
blocksIterator = detector.foundSet.iterator();
while (blocksIterator.hasNext()) {
int hashedPos = blocksIterator.next();
SpatialDetector.setPosWithRespectTo(hashedPos, detector.firstBlock, srcLocationPos);
int changedChunkX = pasteLocationPos.getX() >> 4;
int changedChunkZ = pasteLocationPos.getZ() >> 4;
long changedChunkPos = ChunkPos.asLong(changedChunkX, changedChunkZ);
if (chunksRelit.contains(changedChunkPos)) {
continue;
}
final Chunk chunk = world.getChunk(changedChunkX, changedChunkZ);
chunk.generateSkylightMap();
chunk.checkLight();
chunk.markDirty();
chunksRelit.add(changedChunkPos);
}
}
// Then inject the ship chunks into the world
toSpawn.getChunkClaim().forEach((x, z) -> {
long chunkLong = ChunkPos.asLong(x, z);
if (copiedChunksMap.containsKey(chunkLong)) {
injectChunkIntoWorldServer(copiedChunksMap.get(chunkLong), x, z);
} else {
injectChunkIntoWorldServer(new Chunk(world, x, z), x, z);
}
});
// Add shipData to the ShipData storage
QueryableShipData.get(world).addShip(toSpawn);
// Finally, instantiate the PhysicsObject representation of this ShipData
PhysicsObject physicsObject = new PhysicsObject(world, toSpawn);
loadedShips.put(toSpawn.getUuid(), physicsObject);
}
spawnQueue.clear();
}
use of gnu.trove.iterator.TIntIterator in project OsmAnd-tools by osmandapp.
the class IndexRouteCreator method getMainType.
private int getMainType(TIntCollection types) {
if (types.isEmpty()) {
return -1;
}
TIntIterator tit = types.iterator();
int main = tit.next();
while (tit.hasNext()) {
int rt = tit.next();
if (getBaseOrderForType(rt) < getBaseOrderForType(main)) {
main = rt;
}
}
return main;
}
use of gnu.trove.iterator.TIntIterator in project BoofCV by lessthanoptimal.
the class LearnNodeWeights method addImage.
/**
* Adds a new image to the weight computation. It's highly recommended that the same images used to train
* the tree be added here. This will ensure that all nodes are filled in with a valid weight.
*
* @param descriptors Set of all image feature descriptors for a single image
*/
public void addImage(List<Point> descriptors) {
// Increment image counter
totalImages++;
// Reset work data structures
nodesInImage.clear();
// Mark nodes that descriptors pass through as being a member of this image
for (int descIdx = 0; descIdx < descriptors.size(); descIdx++) {
tree.searchPathToLeaf(descriptors.get(descIdx), (depth, node) -> nodesInImage.add(node.index));
}
// Number of times each leaf node in the graph is seen at least once in an image
TIntIterator iterator = nodesInImage.iterator();
while (iterator.hasNext()) {
numberOfImagesWithNode.data[iterator.next()]++;
}
}
Aggregations