Search in sources :

Example 1 with TIntIterator

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);
							}
						}
					}
				}
			}*/
    }
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) IBlockState(net.minecraft.block.state.IBlockState) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Vector(ValkyrienWarfareBase.API.Vector)

Example 2 with TIntIterator

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();
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) TIntDoubleIterator(gnu.trove.iterator.TIntDoubleIterator) Feature(edu.cmu.ml.proppr.prove.wam.Feature) TIntArrayList(gnu.trove.list.array.TIntArrayList) HashSet(java.util.HashSet)

Example 3 with TIntIterator

use of gnu.trove.iterator.TIntIterator in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method assembleShip.

private void assembleShip(EntityPlayer player, SpatialDetector detector, BlockPos centerInWorld) {
    MutableBlockPos pos = new MutableBlockPos();
    TIntIterator iter = detector.foundSet.iterator();
    int radiusNeeded = 1;
    while (iter.hasNext()) {
        int i = iter.next();
        detector.setPosWithRespectTo(i, BlockPos.ORIGIN, pos);
        int xRad = Math.abs(pos.getX() >> 4);
        int zRad = Math.abs(pos.getZ() >> 4);
        radiusNeeded = Math.max(Math.max(zRad, xRad), radiusNeeded + 1);
    }
    //		radiusNeeded = Math.max(radiusNeeded, 5);
    iter = detector.foundSet.iterator();
    radiusNeeded = Math.min(radiusNeeded, ValkyrienWarfareMod.chunkManager.getManagerForWorld(wrapper.worldObj).maxChunkRadius);
    // System.out.println(radiusNeeded);
    claimNewChunks(radiusNeeded);
    claimedChunks = new Chunk[(ownedChunks.radius * 2) + 1][(ownedChunks.radius * 2) + 1];
    claimedChunksEntries = new PlayerChunkMapEntry[(ownedChunks.radius * 2) + 1][(ownedChunks.radius * 2) + 1];
    for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
        for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
            Chunk chunk = new Chunk(worldObj, x, z);
            injectChunkIntoWorld(chunk, x, z, true);
            claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ] = chunk;
        }
    }
    //Prevents weird shit from spawning at the edges of a ship
    replaceOuterChunksWithAir();
    VKChunkCache = new VWChunkCache(worldObj, claimedChunks);
    int minChunkX = claimedChunks[0][0].xPosition;
    int minChunkZ = claimedChunks[0][0].zPosition;
    refrenceBlockPos = getRegionCenter();
    centerCoord = new Vector(refrenceBlockPos.getX(), refrenceBlockPos.getY(), refrenceBlockPos.getZ());
    createPhysicsCalculations();
    //The ship just got build, how can it not be the latest?
    physicsProcessor.isShipPastBuild90 = true;
    BlockPos centerDifference = refrenceBlockPos.subtract(centerInWorld);
    while (iter.hasNext()) {
        int i = iter.next();
        detector.setPosWithRespectTo(i, centerInWorld, pos);
        IBlockState state = detector.cache.getBlockState(pos);
        TileEntity worldTile = detector.cache.getTileEntity(pos);
        pos.setPos(pos.getX() + centerDifference.getX(), pos.getY() + centerDifference.getY(), pos.getZ() + centerDifference.getZ());
        ownedChunks.chunkOccupiedInLocal[(pos.getX() >> 4) - minChunkX][(pos.getZ() >> 4) - minChunkZ] = true;
        Chunk chunkToSet = claimedChunks[(pos.getX() >> 4) - minChunkX][(pos.getZ() >> 4) - minChunkZ];
        int storageIndex = pos.getY() >> 4;
        if (chunkToSet.storageArrays[storageIndex] == chunkToSet.NULL_BLOCK_STORAGE) {
            chunkToSet.storageArrays[storageIndex] = new ExtendedBlockStorage(storageIndex << 4, true);
        }
        chunkToSet.storageArrays[storageIndex].set(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15, state);
        if (worldTile != null) {
            NBTTagCompound tileEntNBT = new NBTTagCompound();
            tileEntNBT = worldTile.writeToNBT(tileEntNBT);
            // Change the Block position to be inside of the Ship
            tileEntNBT.setInteger("x", pos.getX());
            tileEntNBT.setInteger("y", pos.getY());
            tileEntNBT.setInteger("z", pos.getZ());
            //Fuck this old code
            //				TileEntity newInstance = VKChunkCache.getTileEntity(pos);
            //				newInstance.readFromNBT(tileEntNBT);
            TileEntity newInstance = TileEntity.create(worldObj, tileEntNBT);
            newInstance.validate();
            Class tileClass = newInstance.getClass();
            Field[] fields = tileClass.getDeclaredFields();
            for (Field field : fields) {
                try {
                    field.setAccessible(true);
                    Object o = field.get(newInstance);
                    if (o != null) {
                        if (o instanceof BlockPos) {
                            BlockPos inTilePos = (BlockPos) o;
                            int hash = detector.getHashWithRespectTo(inTilePos.getX(), inTilePos.getY(), inTilePos.getZ(), detector.firstBlock);
                            if (detector.foundSet.contains(hash)) {
                                if (!(o instanceof MutableBlockPos)) {
                                    inTilePos = inTilePos.add(centerDifference.getX(), centerDifference.getY(), centerDifference.getZ());
                                    field.set(newInstance, inTilePos);
                                } else {
                                    MutableBlockPos mutable = (MutableBlockPos) o;
                                    mutable.setPos(inTilePos.getX() + centerDifference.getX(), inTilePos.getY() + centerDifference.getY(), inTilePos.getZ() + centerDifference.getZ());
                                }
                            }
                        }
                    }
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
            worldObj.setTileEntity(newInstance.getPos(), newInstance);
            newInstance.markDirty();
        }
    // chunkCache.setBlockState(pos, state);
    // worldObj.setBlockState(pos, state);
    }
    iter = detector.foundSet.iterator();
    short[][] changes = new short[claimedChunks.length][claimedChunks[0].length];
    while (iter.hasNext()) {
        int i = iter.next();
        // BlockPos respectTo = detector.getPosWithRespectTo(i, centerInWorld);
        detector.setPosWithRespectTo(i, centerInWorld, pos);
        // detector.cache.setBlockState(pos, Blocks.air.getDefaultState());
        // TODO: Get this to update on clientside as well, you bastard!
        TileEntity tile = worldObj.getTileEntity(pos);
        if (tile != null) {
            tile.invalidate();
        }
        worldObj.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
    }
    for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
        for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
            claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].isTerrainPopulated = true;
        //				claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].generateSkylightMap();
        // claimedChunks[x-ownedChunks.minX][z-ownedChunks.minZ].checkLight();
        }
    }
    detectBlockPositions();
    //TODO: This fixes the lighting, but it adds lag; maybe remove this
    for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
        for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
            //				claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].isTerrainPopulated = true;
            claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].generateSkylightMap();
            claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].checkLight();
        }
    }
    coordTransform = new CoordTransformObject(this);
    physicsProcessor.processInitialPhysicsData();
    physicsProcessor.updateParentCenterOfMass();
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) VWChunkCache(ValkyrienWarfareBase.Relocation.VWChunkCache) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SPacketUnloadChunk(net.minecraft.network.play.server.SPacketUnloadChunk) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) TileEntity(net.minecraft.tileentity.TileEntity) Field(java.lang.reflect.Field) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Vector(ValkyrienWarfareBase.API.Vector)

Example 4 with TIntIterator

use of gnu.trove.iterator.TIntIterator in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class SpatialDetector method calculateSpatialOccupation.

public 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);
            }
        }
    }
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) TIntHashSet(gnu.trove.set.hash.TIntHashSet)

Example 5 with TIntIterator

use of gnu.trove.iterator.TIntIterator in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class SpatialDetector method getBlockPosArrayList.

public ArrayList<BlockPos> getBlockPosArrayList() {
    ArrayList<BlockPos> detectedBlockPos = new ArrayList<BlockPos>();
    TIntIterator intIter = foundSet.iterator();
    while (intIter.hasNext()) {
        int hash = (Integer) intIter.next();
        BlockPos fromHash = getPosWithRespectTo(hash, firstBlock);
        if (fromHash.getY() + 128 - firstBlock.getY() < 0) {
            System.err.println("I really hope this doesnt happen");
            return new ArrayList<BlockPos>();
        }
        detectedBlockPos.add(fromHash);
    }
    return detectedBlockPos;
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) ArrayList(java.util.ArrayList) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

TIntIterator (gnu.trove.iterator.TIntIterator)29 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)13 BlockPos (net.minecraft.util.math.BlockPos)8 TIntHashSet (gnu.trove.set.hash.TIntHashSet)4 ArrayList (java.util.ArrayList)4 IBlockState (net.minecraft.block.state.IBlockState)4 Chunk (net.minecraft.world.chunk.Chunk)4 TIntList (gnu.trove.list.TIntList)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 HashSet (java.util.HashSet)3 ExtendedBlockStorage (net.minecraft.world.chunk.storage.ExtendedBlockStorage)3 Vector (ValkyrienWarfareBase.API.Vector)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 EntityData (org.terasology.protobuf.EntityData)2 VWChunkCache (ValkyrienWarfareBase.Relocation.VWChunkCache)1 JsonObject (com.google.gson.JsonObject)1 Feature (edu.cmu.ml.proppr.prove.wam.Feature)1