Search in sources :

Example 61 with Triple

use of org.apache.commons.lang3.tuple.Triple in project sponge by softelnet.

the class BaseKnowledgeBaseInterpreter method getCustomRuleEventSpec.

/**
 * Resolves event specification "<name> <alias> : <mode>". Uses default value when one not provided.
 *
 * @param eventSpecString event specification.
 * @return rule event specification, i.e. a triple of (name, alias, mode).
 */
protected RuleEventSpec getCustomRuleEventSpec(String eventSpecString) {
    if (eventSpecString == null) {
        throw new SpongeException("Event specification is null");
    }
    List<String> mainList = Arrays.stream(eventSpecString.split(":")).map(s -> s.trim()).filter(s -> !s.isEmpty()).collect(Collectors.toList());
    if (mainList.isEmpty()) {
        throw new SpongeException("Event specification is empty");
    } else if (mainList.size() > 2) {
        throw new SpongeException("Event specification has too many elements separated by ':'");
    }
    ImmutablePair<String, String> nameAlias = resolveEventNameAndAlias(mainList.get(0));
    EventMode eventMode = RuleAdapter.DEFAULT_MODE;
    if (mainList.size() == 2) {
        try {
            eventMode = EventMode.valueOf(mainList.get(1).toUpperCase());
        } catch (Exception e) {
            throw new SpongeException("Event mode is incorrect: " + mainList.get(1));
        }
    }
    return new GenericRuleEventSpec(nameAlias.getLeft(), nameAlias.getRight(), eventMode);
}
Also used : Arrays(java.util.Arrays) KnowledgeBaseInterpreter(org.openksavi.sponge.kb.KnowledgeBaseInterpreter) Logger(org.slf4j.Logger) Plugin(org.openksavi.sponge.plugin.Plugin) LoggerFactory(org.slf4j.LoggerFactory) GenericRuleEventSpec(org.openksavi.sponge.core.rule.GenericRuleEventSpec) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) KnowledgeBaseEngineOperations(org.openksavi.sponge.kb.KnowledgeBaseEngineOperations) EventMode(org.openksavi.sponge.rule.EventMode) KnowledgeBaseType(org.openksavi.sponge.kb.KnowledgeBaseType) List(java.util.List) RuleAdapter(org.openksavi.sponge.rule.RuleAdapter) RuleEventSpec(org.openksavi.sponge.rule.RuleEventSpec) StringTokenizer(java.util.StringTokenizer) SpongeException(org.openksavi.sponge.SpongeException) Processor(org.openksavi.sponge.Processor) SpongeUtils(org.openksavi.sponge.core.util.SpongeUtils) EventMode(org.openksavi.sponge.rule.EventMode) SpongeException(org.openksavi.sponge.SpongeException) GenericRuleEventSpec(org.openksavi.sponge.core.rule.GenericRuleEventSpec) SpongeException(org.openksavi.sponge.SpongeException)

Example 62 with Triple

use of org.apache.commons.lang3.tuple.Triple in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class WorldPhysicsCollider method updatePotentialCollisionCache.

// TODO: The greatest physics lag starts here.
private void updatePotentialCollisionCache() {
    ticksSinceCacheUpdate = 0D;
    // in the same tick
    if (Math.random() > .5) {
        ticksSinceCacheUpdate -= .05D;
    }
    int oldSize = cachedPotentialHits.size();
    // Resets the potential hits array in O(1) time! Isn't that something.
    // cachedPotentialHits.resetQuick();
    cachedPotentialHits.clear();
    AxisAlignedBB shipBBOriginal = parent.getPhysicsTransformAABB();
    if (shipBBOriginal == null) {
        return;
    }
    final AxisAlignedBB shipBB = shipBBOriginal.grow(3);
    // Use the physics tick collision box instead of the game tick collision box.
    // We are using grow(3) on both because for some reason if we don't then ships start
    // jiggling through the ground. God I can't wait for a new physics engine.
    final AxisAlignedBB collisionBB = shipBB.grow(AABB_EXPANSION).expand(calculator.getLinearVelocity().x * .2, calculator.getLinearVelocity().y * .2, calculator.getLinearVelocity().z * .2);
    // Ship is outside of world blockSpace, just skip this all togvalkyrium
    if (collisionBB.maxY < 0 || collisionBB.minY > 255) {
        return;
    }
    // Has a -1 on the minY value, I hope this helps with preventing things from
    // falling through the floor
    BlockPos min = new BlockPos(collisionBB.minX, Math.max(collisionBB.minY - 1, 0), collisionBB.minZ);
    BlockPos max = new BlockPos(collisionBB.maxX, Math.min(collisionBB.maxY, 255), collisionBB.maxZ);
    centerPotentialHit = new BlockPos((min.getX() + max.getX()) / 2D, (min.getY() + max.getY()) / 2D, (min.getZ() + max.getZ()) / 2D);
    ChunkCache cache = parent.getCachedSurroundingChunks();
    if (cache == null) {
        System.err.println("VS Cached Surrounding Chunks was null! This is going to cause catastophric terrible events!!");
        return;
    }
    int chunkMinX = min.getX() >> 4;
    int chunkMaxX = (max.getX() >> 4) + 1;
    int chunkMinZ = min.getZ() >> 4;
    int chunkMaxZ = (max.getZ() >> 4) + 1;
    // long startTime = System.nanoTime();
    int minX = min.getX();
    int minY = min.getY();
    int minZ = min.getZ();
    int maxX = max.getX();
    int maxY = max.getY();
    int maxZ = max.getZ();
    // More multithreading!
    if (VSConfig.MULTITHREADING_SETTINGS.multithreadCollisionCacheUpdate && parent.getBlockPositions().size() > 100) {
        List<Triple<Integer, Integer, TIntList>> tasks = new ArrayList<>();
        for (int chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
            for (int chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
                tasks.add(new ImmutableTriple<>(chunkX, chunkZ, new TIntArrayList()));
            }
        }
        Consumer<Triple<Integer, Integer, TIntList>> consumer = i -> {
            // i is a Tuple<Integer, Integer>
            // updateCollisionCacheParrallel(cache, cachedPotentialHits, i.getFirst(),
            // i.getSecond(), minX, minY, minZ, maxX, maxY, maxZ);
            updateCollisionCacheSequential(cache, i.getLeft(), i.getMiddle(), minX, minY, minZ, maxX, maxY, maxZ, shipBB, i.getRight());
        };
        ValkyrienSkiesMod.getPhysicsThreadPool().submit(() -> tasks.parallelStream().forEach(consumer)).join();
        tasks.forEach(task -> cachedPotentialHits.addAll(task.getRight()));
    } else {
        // Cast to double to avoid overflow errors
        double size = ((double) (chunkMaxX - chunkMinX)) * ((double) (chunkMaxZ - chunkMinZ));
        if (size > 300000) {
            // Sanity check; don't execute the rest of the code because we'll just freeze the physics thread.
            return;
        }
        // TODO: VS thread freezes here.
        for (int chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
            for (int chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
                updateCollisionCacheSequential(cache, chunkX, chunkZ, minX, minY, minZ, maxX, maxY, maxZ, shipBB, cachedPotentialHits);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Triple(org.apache.commons.lang3.tuple.Triple) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) SpatialDetector(org.valkyrienskies.mod.common.ships.block_relocation.SpatialDetector) TIntArrayList(gnu.trove.list.array.TIntArrayList) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ITerrainOctreeProvider(org.valkyrienskies.mod.common.util.datastructures.ITerrainOctreeProvider) ArrayList(java.util.ArrayList) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) ValkyrienSkiesMod(org.valkyrienskies.mod.common.ValkyrienSkiesMod) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Vector3d(org.joml.Vector3d) PhysicsCalculations(org.valkyrienskies.mod.common.physics.PhysicsCalculations) Chunk(net.minecraft.world.chunk.Chunk) Triple(org.apache.commons.lang3.tuple.Triple) TIntList(gnu.trove.list.TIntList) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) IBitOctree(org.valkyrienskies.mod.common.util.datastructures.IBitOctree) ChunkCache(net.minecraft.world.ChunkCache) Iterator(java.util.Iterator) Collection(java.util.Collection) TransformType(valkyrienwarfare.api.TransformType) BlockPos(net.minecraft.util.math.BlockPos) Consumer(java.util.function.Consumer) IBlockState(net.minecraft.block.state.IBlockState) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) List(java.util.List) VSConfig(org.valkyrienskies.mod.common.config.VSConfig) MathHelper(net.minecraft.util.math.MathHelper) Vector3dc(org.joml.Vector3dc) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) ChunkCache(net.minecraft.world.ChunkCache) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 63 with Triple

use of org.apache.commons.lang3.tuple.Triple in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class WorldWaterCollider method updatePotentialCollisionCache.

private void updatePotentialCollisionCache() {
    secondsSinceCollisionCacheUpdate = 0;
    // ships from all updating in the same tick
    if (Math.random() > .5) {
        secondsSinceCollisionCacheUpdate -= .01;
    }
    cachedPotentialHits.clear();
    AxisAlignedBB shipBBOriginal = parent.getPhysicsTransformAABB();
    if (shipBBOriginal == null) {
        return;
    }
    // We are using grow(3) because its good.
    final AxisAlignedBB shipBB = shipBBOriginal.grow(3);
    final AxisAlignedBB collisionBB = shipBB.grow(AABB_EXPANSION).grow(2 * Math.ceil(RANGE_CHECK));
    // Ship is outside of world blockSpace, just skip this
    if (collisionBB.maxY < 0 || collisionBB.minY > 255) {
        return;
    }
    // Has a -1 on the minY value, I hope this helps with preventing things from
    // falling through the floor
    final BlockPos min = new BlockPos(collisionBB.minX, Math.max(collisionBB.minY - 1, 0), collisionBB.minZ);
    final BlockPos max = new BlockPos(collisionBB.maxX, Math.min(collisionBB.maxY, 255), collisionBB.maxZ);
    centerPotentialHit = new BlockPos((min.getX() + max.getX()) / 2.0, (min.getY() + max.getY()) / 2.0, (min.getZ() + max.getZ()) / 2.0);
    final ChunkCache cache = parent.getCachedSurroundingChunks();
    if (cache == null) {
        System.err.println("VS Cached Surrounding Chunks was null! This is going to cause catastophric terrible events!!");
        return;
    }
    final int chunkMinX = min.getX() >> 4;
    final int chunkMaxX = (max.getX() >> 4) + 1;
    final int chunkMinZ = min.getZ() >> 4;
    final int chunkMaxZ = (max.getZ() >> 4) + 1;
    final int minX = min.getX();
    final int minY = min.getY();
    final int minZ = min.getZ();
    final int maxX = max.getX();
    final int maxY = max.getY();
    final int maxZ = max.getZ();
    // More multithreading!
    if (VSConfig.MULTITHREADING_SETTINGS.multithreadCollisionCacheUpdate && parent.getBlockPositions().size() > 100) {
        final List<Triple<Integer, Integer, TIntList>> tasks = new ArrayList<>();
        for (int chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
            for (int chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
                tasks.add(new ImmutableTriple<>(chunkX, chunkZ, new TIntArrayList()));
            }
        }
        Consumer<Triple<Integer, Integer, TIntList>> consumer = i -> updateCollisionCacheSequential(cache, i.getLeft(), i.getMiddle(), minX, minY, minZ, maxX, maxY, maxZ, shipBB, i.getRight());
        ValkyrienSkiesMod.getPhysicsThreadPool().submit(() -> tasks.parallelStream().forEach(consumer)).join();
        tasks.forEach(task -> cachedPotentialHits.addAll(task.getRight()));
    } else {
        // Cast to double to avoid overflow errors
        final double size = ((double) (chunkMaxX - chunkMinX)) * ((double) (chunkMaxZ - chunkMinZ));
        if (size > 300000) {
            // Sanity check; don't execute the rest of the code because we'll just freeze the physics thread.
            return;
        }
        for (int chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
            for (int chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
                updateCollisionCacheSequential(cache, chunkX, chunkZ, minX, minY, minZ, maxX, maxY, maxZ, shipBB, cachedPotentialHits);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) Triple(org.apache.commons.lang3.tuple.Triple) TIntList(gnu.trove.list.TIntList) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) SpatialDetector(org.valkyrienskies.mod.common.ships.block_relocation.SpatialDetector) IBitOctree(org.valkyrienskies.mod.common.util.datastructures.IBitOctree) TIntArrayList(gnu.trove.list.array.TIntArrayList) ChunkCache(net.minecraft.world.ChunkCache) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TransformType(valkyrienwarfare.api.TransformType) BlockPos(net.minecraft.util.math.BlockPos) ITerrainOctreeProvider(org.valkyrienskies.mod.common.util.datastructures.ITerrainOctreeProvider) ArrayList(java.util.ArrayList) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Consumer(java.util.function.Consumer) List(java.util.List) VSConfig(org.valkyrienskies.mod.common.config.VSConfig) MathHelper(net.minecraft.util.math.MathHelper) ValkyrienSkiesMod(org.valkyrienskies.mod.common.ValkyrienSkiesMod) Vector3d(org.joml.Vector3d) PhysicsCalculations(org.valkyrienskies.mod.common.physics.PhysicsCalculations) Chunk(net.minecraft.world.chunk.Chunk) Triple(org.apache.commons.lang3.tuple.Triple) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) ChunkCache(net.minecraft.world.ChunkCache) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 64 with Triple

use of org.apache.commons.lang3.tuple.Triple in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EntityCollisionInjector method getLadderCollisions.

/**
 * Returns all the possible ladders that the entity could potentially climb with
 */
public static Iterable<Triple<PhysicsObject, BlockPos, IBlockState>> getLadderCollisions(final EntityLivingBase entity, final List<PhysicsObject> collidingShips) {
    final boolean isSpectator = entity instanceof EntityPlayer && ((EntityPlayer) entity).isSpectator();
    final World world = entity.getEntityWorld();
    final List<Triple<PhysicsObject, BlockPos, IBlockState>> ladderCollisions = new ArrayList<>();
    if (!isSpectator) {
        final AxisAlignedBB bb = entity.getEntityBoundingBox();
        for (PhysicsObject physicsObject : collidingShips) {
            final Polygon playerPolyInShip = new Polygon(bb, physicsObject.getShipTransform(), TransformType.GLOBAL_TO_SUBSPACE);
            final AxisAlignedBB playerPolyInShipBB = playerPolyInShip.getEnclosedAABB();
            int mX = MathHelper.floor(playerPolyInShipBB.minX);
            int mY = MathHelper.floor(playerPolyInShipBB.minY);
            int mZ = MathHelper.floor(playerPolyInShipBB.minZ);
            for (int y2 = mY; (double) y2 < playerPolyInShipBB.maxY; ++y2) {
                for (int x2 = mX; (double) x2 < playerPolyInShipBB.maxX; ++x2) {
                    for (int z2 = mZ; (double) z2 < playerPolyInShipBB.maxZ; ++z2) {
                        BlockPos tmp = new BlockPos(x2, y2, z2);
                        IBlockState state = world.getBlockState(tmp);
                        if (state.getBlock().isLadder(state, world, tmp, entity)) {
                            ladderCollisions.add(Triple.of(physicsObject, tmp, state));
                        }
                    }
                }
            }
        }
    }
    return ladderCollisions;
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Polygon(org.valkyrienskies.mod.common.collision.Polygon) ShipPolygon(org.valkyrienskies.mod.common.collision.ShipPolygon) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 65 with Triple

use of org.apache.commons.lang3.tuple.Triple in project ImmersiveEngineering by BluSunrize.

the class ApiUtils method raytraceWires.

public static Connection raytraceWires(World world, Vec3d start, Vec3d end, @Nullable Connection ignored) {
    Map<BlockPos, ImmersiveNetHandler.BlockWireInfo> inDim = ImmersiveNetHandler.INSTANCE.blockWireMap.lookup(world.provider.getDimension());
    AtomicReference<Connection> ret = new AtomicReference<>();
    AtomicDouble minDistSq = new AtomicDouble(Double.POSITIVE_INFINITY);
    if (inDim != null) {
        Utils.rayTrace(start, end, world, (pos) -> {
            if (inDim.containsKey(pos)) {
                ImmersiveNetHandler.BlockWireInfo info = inDim.get(pos);
                for (int i = 0; i < 2; i++) {
                    Set<Triple<Connection, Vec3d, Vec3d>> conns = i == 0 ? info.in : info.near;
                    for (Triple<Connection, Vec3d, Vec3d> conn : conns) {
                        Connection c = conn.getLeft();
                        if (ignored == null || !c.hasSameConnectors(ignored)) {
                            Vec3d startRelative = start.add(-pos.getX(), -pos.getY(), -pos.getZ());
                            Vec3d across = conn.getRight().subtract(conn.getMiddle());
                            double t = Utils.getCoeffForMinDistance(startRelative, conn.getMiddle(), across);
                            t = MathHelper.clamp(0, t, 1);
                            Vec3d closest = conn.getMiddle().add(t * across.x, t * across.y, t * across.z);
                            double distSq = closest.squareDistanceTo(startRelative);
                            if (distSq < minDistSq.get()) {
                                ret.set(c);
                                minDistSq.set(distSq);
                            }
                        }
                    }
                }
            }
        });
    }
    return ret.get();
}
Also used : AtomicDouble(com.google.common.util.concurrent.AtomicDouble) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) MessageObstructedConnection(blusunrize.immersiveengineering.common.util.network.MessageObstructedConnection) AtomicReference(java.util.concurrent.atomic.AtomicReference) Triple(org.apache.commons.lang3.tuple.Triple) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple)

Aggregations

Triple (org.apache.commons.lang3.tuple.Triple)51 ArrayList (java.util.ArrayList)20 ImmutableTriple (org.apache.commons.lang3.tuple.ImmutableTriple)18 List (java.util.List)13 Pair (org.apache.commons.lang3.tuple.Pair)10 Test (org.junit.Test)8 Collectors (java.util.stream.Collectors)7 java.util (java.util)6 Organization (alfio.model.user.Organization)5 Event (alfio.model.Event)4 Ticket (alfio.model.Ticket)4 TicketReservation (alfio.model.TicketReservation)4 IOException (java.io.IOException)4 BlockPos (net.minecraft.util.math.BlockPos)4 Mutable (org.apache.commons.lang3.mutable.Mutable)4 Triple (org.apache.hyracks.algebricks.common.utils.Triple)4 alfio.model (alfio.model)3 TicketCategory (alfio.model.TicketCategory)3 TemplateManager (alfio.util.TemplateManager)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3