Search in sources :

Example 31 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class IterateMultipleComponentBenchmark method run.

@Override
public void run() {
    for (EntityRef entity : entityManager.getEntitiesWith(MeshComponent.class, LocationComponent.class)) {
        LocationComponent loc = entity.getComponent(LocationComponent.class);
        MeshComponent meshComp = entity.getComponent(MeshComponent.class);
        loc.getLocalPosition();
    }
}
Also used : MeshComponent(org.terasology.rendering.logic.MeshComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 32 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class IterateMultipleComponentBenchmark method setup.

@Override
public void setup() {
    FastRandom rand = new FastRandom(0L);
    rawEntityData = Lists.newArrayList();
    for (int i = 0; i < 1000; ++i) {
        List<Component> entityData = Lists.newArrayList();
        if (rand.nextFloat() < 0.75f) {
            entityData.add(new LocationComponent());
        }
        if (rand.nextFloat() < 0.5f) {
            entityData.add(new MeshComponent());
        }
        if (rand.nextFloat() < 0.25f) {
            entityData.add(new BlockComponent());
        }
        rawEntityData.add(entityData);
    }
    entityManager = new PojoEntityManager();
    for (List<Component> rawEntity : rawEntityData) {
        entityManager.create(rawEntity);
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) MeshComponent(org.terasology.rendering.logic.MeshComponent) PojoEntityManager(org.terasology.entitySystem.entity.internal.PojoEntityManager) FastRandom(org.terasology.utilities.random.FastRandom) MeshComponent(org.terasology.rendering.logic.MeshComponent) BlockComponent(org.terasology.world.block.BlockComponent) Component(org.terasology.entitySystem.Component) LocationComponent(org.terasology.logic.location.LocationComponent) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 33 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class IterateSingleComponentBenchmark method run.

@Override
public void run() {
    for (EntityRef entity : entityManager.getEntitiesWith(LocationComponent.class)) {
        LocationComponent loc = entity.getComponent(LocationComponent.class);
        loc.getLocalPosition();
    }
}
Also used : EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 34 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class SectorUtil method getWatchedChunks.

/**
 * Watched chunks are defined as the union of:
 * <ul>
 *     <li>The chunk in which the {@link LocationComponent#getWorldPosition()} resides, if any</li>
 *     <li>The set of chunks in {@link SectorRegionComponent#chunks}, if any</li>
 * </ul>
 *
 * @param entity the entity to query the watched chunks of
 * @return the set of positions of this entity's watched chunks
 */
public static Set<Vector3i> getWatchedChunks(EntityRef entity) {
    Set<Vector3i> chunks = new HashSet<>();
    LocationComponent loc = entity.getComponent(LocationComponent.class);
    if (loc != null) {
        chunks.add(ChunkMath.calcChunkPos(loc.getWorldPosition()));
    }
    SectorRegionComponent regionComponent = entity.getComponent(SectorRegionComponent.class);
    if (regionComponent != null) {
        chunks.addAll(regionComponent.chunks);
    }
    return chunks;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) LocationComponent(org.terasology.logic.location.LocationComponent) HashSet(java.util.HashSet)

Example 35 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class TargetSystem method updateTarget.

public boolean updateTarget(Vector3f pos, Vector3f dir, float maxDist) {
    if (targetBlockPos != null && !target.exists()) {
        target = blockRegistry.getEntityAt(targetBlockPos);
    }
    HitResult hitInfo = physics.rayTrace(pos, dir, maxDist, filter);
    EntityRef newTarget = hitInfo.getEntity();
    if (hitInfo.isWorldHit()) {
        if (targetBlockPos != null) {
            if (targetBlockPos.equals(hitInfo.getBlockPosition())) {
                return false;
            }
        }
        targetBlockPos = hitInfo.getBlockPosition();
    } else {
        if (target.equals(newTarget)) {
            return false;
        }
        targetBlockPos = null;
    }
    prevTarget = target;
    target = newTarget;
    LocationComponent location = target.getComponent(LocationComponent.class);
    if (location != null && targetBlockPos != null) {
        location.setLocalPosition(targetBlockPos.toVector3f());
    }
    return true;
}
Also used : HitResult(org.terasology.physics.HitResult) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent)

Aggregations

LocationComponent (org.terasology.logic.location.LocationComponent)69 EntityRef (org.terasology.entitySystem.entity.EntityRef)40 Vector3f (org.terasology.math.geom.Vector3f)39 ClientComponent (org.terasology.network.ClientComponent)17 Quat4f (org.terasology.math.geom.Quat4f)16 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)11 Command (org.terasology.logic.console.commandSystem.annotations.Command)10 Vector3i (org.terasology.math.geom.Vector3i)10 BlockComponent (org.terasology.world.block.BlockComponent)7 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)6 BaseQuat4f (org.terasology.math.geom.BaseQuat4f)6 Vector3f (javax.vecmath.Vector3f)5 Component (org.terasology.entitySystem.Component)5 BaseVector3f (org.terasology.math.geom.BaseVector3f)5 MeshComponent (org.terasology.rendering.logic.MeshComponent)5 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)4 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)4 Matrix4f (org.terasology.math.geom.Matrix4f)4 BlockFamily (org.terasology.world.block.family.BlockFamily)4 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)3