use of gnu.trove.iterator.TIntIterator in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class BalloonProcessor method checkBalloonForSplit.
// Loop through all balloon air positions, and if some are split; remove the smaller group
private void checkBalloonForSplit() {
HashSet<BlockPos> posititionsNeedingAtatchment = new HashSet<BlockPos>();
ArrayList<BalloonAirDetector> foundSets = new ArrayList<BalloonAirDetector>();
MutableBlockPos mutable = new MutableBlockPos();
posititionsNeedingAtatchment.addAll(internalAirPositions);
while (posititionsNeedingAtatchment.size() > 0) {
BlockPos start = getRandomPosFromSet(posititionsNeedingAtatchment);
BalloonAirDetector detector = new BalloonAirDetector(start, parent.worldObj, currentBalloonSize, this, posititionsNeedingAtatchment);
foundSets.add(detector);
TIntIterator iterator = detector.foundSet.iterator();
while (iterator.hasNext()) {
int hash = iterator.next();
detector.setPosWithRespectTo(hash, start, mutable);
posititionsNeedingAtatchment.remove(mutable);
}
}
if (foundSets.size() > 1) {
for (BalloonAirDetector split : foundSets) {
System.out.println(split.foundSet.size());
}
processFoundSplits(foundSets);
// System.out.println("Post: "+internalAirPositions.size());
}
}
use of gnu.trove.iterator.TIntIterator in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldPhysicsCollider method processPotentialCollisionsAccurately.
// Runs through the cache ArrayList, checking each possible BlockPos for SOLID blocks that can collide, if it finds any it will
// move to the next method
//TODO: Optimize from here, this is taking 10x the processing time of updating collision cache!
private void processPotentialCollisionsAccurately() {
final MutableBlockPos localCollisionPos = new MutableBlockPos();
final Vector inWorld = new Vector();
int minX, minY, minZ, maxX, maxY, maxZ, x, y, z;
final double rangeCheck = .65D;
TIntIterator intIterator = cachedPotentialHits.iterator();
while (intIterator.hasNext()) {
// Converts the int to a mutablePos
SpatialDetector.setPosWithRespectTo(intIterator.next(), centerPotentialHit, mutablePos);
inWorld.X = mutablePos.getX() + .5;
inWorld.Y = mutablePos.getY() + .5;
inWorld.Z = mutablePos.getZ() + .5;
parent.coordTransform.fromGlobalToLocal(inWorld);
minX = MathHelper.floor_double(inWorld.X - rangeCheck);
minY = MathHelper.floor_double(inWorld.Y - rangeCheck);
minZ = MathHelper.floor_double(inWorld.Z - rangeCheck);
maxX = MathHelper.floor_double(inWorld.X + rangeCheck);
maxY = MathHelper.floor_double(inWorld.Y + rangeCheck);
maxZ = MathHelper.floor_double(inWorld.Z + rangeCheck);
/**
* Something here is causing the game to freeze :/
*/
int minChunkX = minX >> 4;
int minChunkY = minY >> 4;
int minChunkZ = minZ >> 4;
int maxChunkX = maxX >> 4;
int maxChunkY = maxY >> 4;
int maxChunkZ = maxZ >> 4;
entireLoop: if (!(minChunkY > 15 || maxChunkY < 0)) {
for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
if (parent.ownsChunk(chunkX, chunkZ)) {
final Chunk chunkIn = parent.VKChunkCache.getChunkAt(chunkX, chunkZ);
int minXToCheck = chunkX << 4;
int maxXToCheck = minXToCheck + 15;
int minZToCheck = chunkZ << 4;
int maxZToCheck = minZToCheck + 15;
minXToCheck = Math.max(minXToCheck, minX);
maxXToCheck = Math.min(maxXToCheck, maxX);
minZToCheck = Math.max(minZToCheck, minZ);
maxZToCheck = Math.min(maxZToCheck, maxZ);
for (int chunkY = minChunkY; chunkY <= maxChunkY; chunkY++) {
ExtendedBlockStorage storage = chunkIn.storageArrays[chunkY];
if (storage != null) {
int minYToCheck = chunkY << 4;
int maxYToCheck = minYToCheck + 15;
minYToCheck = Math.max(minYToCheck, minY);
maxYToCheck = Math.min(maxYToCheck, maxY);
for (x = minXToCheck; x <= maxXToCheck; x++) {
for (z = minZToCheck; z <= maxZToCheck; z++) {
for (y = minYToCheck; y <= maxYToCheck; y++) {
final IBlockState state = storage.get(x & 15, y & 15, z & 15);
if (state.getMaterial().isSolid()) {
localCollisionPos.setPos(x, y, z);
boolean brokeAWorldBlock = handleLikelyCollision(mutablePos, localCollisionPos, parent.surroundingWorldChunksCache.getBlockState(mutablePos), state);
if (brokeAWorldBlock) {
int positionRemoved = SpatialDetector.getHashWithRespectTo(mutablePos.getX(), mutablePos.getY(), mutablePos.getZ(), centerPotentialHit);
cachedHitsToRemove.add(positionRemoved);
break entireLoop;
}
}
}
}
}
}
}
}
}
}
}
//The old way of doing things
/*for (x = minX; x <= maxX; x++) {
for (z = minZ; z <= maxZ; z++) {
if (parent.ownsChunk(x >> 4, z >> 4)) {
for (y = minY; y <= maxY; y++) {
final Chunk chunkIn = parent.VKChunkCache.getChunkAt(x >> 4, z >> 4);
final IBlockState state = chunkIn.getBlockState(x, y, z);
if (state.getMaterial().isSolid()) {
localCollisionPos.setPos(x, y, z);
handleLikelyCollision(mutablePos, localCollisionPos, parent.surroundingWorldChunksCache.getBlockState(mutablePos), state);
}
}
}
}
}*/
}
}
use of gnu.trove.iterator.TIntIterator in project ProPPR by TeamCohen.
the class LightweightStateGraph method serialize.
public String serialize(boolean featureIndex) {
StringBuilder ret = //numNodes
new StringBuilder().append(this.nodeSize()).append("\t").append(this.edgeCount).append(// waiting for label dependency size
"\t");
int labelDependencies = 0;
StringBuilder sb = new StringBuilder();
boolean first = true;
if (featureIndex) {
sb.append("\t");
for (int fi = 1; fi <= this.featureTab.size(); fi++) {
if (!first)
sb.append(LearningGraphBuilder.FEATURE_INDEX_DELIM);
else
first = false;
Feature f = this.featureTab.getSymbol(fi);
sb.append(f);
}
}
// foreach src node
for (TIntObjectIterator<TIntArrayList> it = this.near.iterator(); it.hasNext(); ) {
it.advance();
int ui = it.key();
TIntArrayList nearu = it.value();
HashSet<Integer> outgoingFeatures = new HashSet<Integer>();
//foreach dst from src
for (TIntIterator vit = nearu.iterator(); vit.hasNext(); ) {
int vi = vit.next();
sb.append("\t");
sb.append(ui).append(LearningGraphBuilder.SRC_DST_DELIM).append(vi);
sb.append(LearningGraphBuilder.EDGE_DELIM);
//foreach feature on src,dst
for (TIntDoubleIterator fit = edgeFeatureDict.get(ui).get(vi).iterator(); fit.hasNext(); ) {
fit.advance();
int fi = fit.key();
double wi = fit.value();
outgoingFeatures.add(fi);
sb.append(fi).append(LearningGraphBuilder.FEATURE_WEIGHT_DELIM).append(wi).append(LearningGraphBuilder.EDGE_FEATURE_DELIM);
}
// drop last ','
sb.deleteCharAt(sb.length() - 1);
}
labelDependencies += outgoingFeatures.size() * nearu.size();
}
ret.append(labelDependencies).append(sb);
return ret.toString();
}
use of gnu.trove.iterator.TIntIterator in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldPhysicsCollider method runPhysCollision.
//Runs the collision code
public void runPhysCollision() {
// Multiply by 20 to convert seconds (physTickSpeed) into ticks (ticksSinceCacheUpdate)
ticksSinceCacheUpdate += 20D * calculator.physTickSpeed;
TIntIterator iterator = cachedHitsToRemove.iterator();
while (iterator.hasNext()) {
cachedPotentialHits.remove(iterator.next());
}
cachedHitsToRemove.clear();
if (shouldUpdateCollisonCache()) {
updatePotentialCollisionCache();
// Collections.shuffle(cachedPotentialHits);
}
processPotentialCollisionsAccurately();
}
use of gnu.trove.iterator.TIntIterator in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class BalloonProcessor method doLastHoleCheck.
private boolean doLastHoleCheck(BlockPos holeToCheck, BlockPos[] adjacentPositions) {
BalloonHoleDetector holeDetector = new BalloonHoleDetector(holeToCheck, parent.worldObj, 2500, this);
if (!holeDetector.cleanHouse) {
// Wow the hole is actually filled! Add the new positions here!
TIntIterator newBallonWallIterator = holeDetector.newBalloonWalls.iterator();
TIntIterator newAirPostitionsIterator = holeDetector.foundSet.iterator();
while (newBallonWallIterator.hasNext()) {
int hash = newBallonWallIterator.next();
BlockPos fromHash = holeDetector.getPosWithRespectTo(hash, holeDetector.firstBlock);
balloonWalls.add(fromHash);
internalAirPositions.remove(fromHash);
balloonHoles.remove(fromHash);
}
while (newAirPostitionsIterator.hasNext()) {
int hash = newAirPostitionsIterator.next();
BlockPos fromHash = holeDetector.getPosWithRespectTo(hash, holeDetector.firstBlock);
internalAirPositions.add(fromHash);
balloonWalls.remove(fromHash);
balloonHoles.remove(fromHash);
}
return true;
}
return false;
}
Aggregations