Search in sources :

Example 51 with LocationComponent

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

the class HierarchicalAISystem method update.

// TODO add way to recognize if attacked
@Override
public void update(float delta) {
    for (EntityRef entity : entityManager.getEntitiesWith(HierarchicalAIComponent.class, CharacterMovementComponent.class, LocationComponent.class)) {
        LocationComponent location = entity.getComponent(LocationComponent.class);
        Vector3f worldPos = location.getWorldPosition();
        // Skip this AI if not in a loaded chunk
        if (!worldProvider.isBlockRelevant(worldPos)) {
            continue;
        }
        // goto Hierarchical system
        loop(entity, location, worldPos);
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 52 with LocationComponent

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

the class EntityCreateBenchmark 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);
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) MeshComponent(org.terasology.rendering.logic.MeshComponent) 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 53 with LocationComponent

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

the class IterateSingleComponentBenchmark 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 54 with LocationComponent

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

the class CharacterMovementSystemUtility method setToInterpolateState.

public void setToInterpolateState(EntityRef entity, CharacterStateEvent a, CharacterStateEvent b, long time) {
    float t = (float) (time - a.getTime()) / (b.getTime() - a.getTime());
    Vector3f newPos = BaseVector3f.lerp(a.getPosition(), b.getPosition(), t);
    Quat4f newRot = BaseQuat4f.interpolate(a.getRotation(), b.getRotation(), t);
    LocationComponent location = entity.getComponent(LocationComponent.class);
    location.setWorldPosition(newPos);
    location.setWorldRotation(newRot);
    entity.saveComponent(location);
    CharacterMovementComponent movementComponent = entity.getComponent(CharacterMovementComponent.class);
    movementComponent.mode = a.getMode();
    movementComponent.setVelocity(a.getVelocity());
    movementComponent.grounded = a.isGrounded();
    if (b.getFootstepDelta() < a.getFootstepDelta()) {
        movementComponent.footstepDelta = t * (1 + b.getFootstepDelta() - a.getFootstepDelta()) + a.getFootstepDelta();
        if (movementComponent.footstepDelta > 1) {
            movementComponent.footstepDelta -= 1;
        }
    } else {
        movementComponent.footstepDelta = t * (b.getFootstepDelta() - a.getFootstepDelta()) + a.getFootstepDelta();
    }
    entity.saveComponent(movementComponent);
    setPhysicsLocation(entity, newPos);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) BaseVector3f(org.terasology.math.geom.BaseVector3f) LocationComponent(org.terasology.logic.location.LocationComponent) Quat4f(org.terasology.math.geom.Quat4f) BaseQuat4f(org.terasology.math.geom.BaseQuat4f)

Example 55 with LocationComponent

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

the class CharacterSystem method isPredictionOfEventCorrect.

private boolean isPredictionOfEventCorrect(EntityRef character, ActivationRequest event) {
    CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
    EntityRef camera = GazeAuthoritySystem.getGazeEntityForCharacter(character);
    LocationComponent location = camera.getComponent(LocationComponent.class);
    Vector3f direction = location.getWorldDirection();
    if (!(vectorsAreAboutEqual(event.getDirection(), direction))) {
        logger.error("Direction at client {} was different than direction at server {}", event.getDirection(), direction);
    }
    // Assume the exact same value in case there are rounding mistakes:
    direction = event.getDirection();
    Vector3f originPos = location.getWorldPosition();
    if (!(vectorsAreAboutEqual(event.getOrigin(), originPos))) {
        String msg = "Player {} seems to have cheated: It stated that it performed an action from {} but the predicted position is {}";
        logger.info(msg, getPlayerNameFromCharacter(character), event.getOrigin(), originPos);
        return false;
    }
    if (event.isOwnedEntityUsage()) {
        if (!event.getUsedOwnedEntity().exists()) {
            String msg = "Denied activation attempt by {} since the used entity does not exist on the authority";
            logger.info(msg, getPlayerNameFromCharacter(character));
            return false;
        }
        if (!networkSystem.getOwnerEntity(event.getUsedOwnedEntity()).equals(networkSystem.getOwnerEntity(character))) {
            String msg = "Denied activation attempt by {} since it does not own the entity at the authority";
            logger.info(msg, getPlayerNameFromCharacter(character));
            return false;
        }
    } else {
        // check for cheats so that data can later be trusted:
        if (event.getUsedOwnedEntity().exists()) {
            String msg = "Denied activation attempt by {} since it is not properly marked as owned entity usage";
            logger.info(msg, getPlayerNameFromCharacter(character));
            return false;
        }
    }
    if (event.isEventWithTarget()) {
        if (!event.getTarget().exists()) {
            String msg = "Denied activation attempt by {} since the target does not exist on the authority";
            logger.info(msg, getPlayerNameFromCharacter(character));
            // can happen if target existed on client
            return false;
        }
        HitResult result = physics.rayTrace(originPos, direction, characterComponent.interactionRange, Sets.newHashSet(character), DEFAULTPHYSICSFILTER);
        if (!result.isHit()) {
            String msg = "Denied activation attempt by {} since at the authority there was nothing to activate at that place";
            logger.info(msg, getPlayerNameFromCharacter(character));
            return false;
        }
        EntityRef hitEntity = result.getEntity();
        if (!hitEntity.equals(event.getTarget())) {
            /**
             * Tip for debugging this issue: Obtain the network id of hit entity and search it in both client and
             * server entity dump. When certain fields don't get replicated, then wrong entity might get hin in the
             * hit test.
             */
            String msg = "Denied activation attempt by {} since at the authority another entity would have been activated";
            logger.info(msg, getPlayerNameFromCharacter(character));
            return false;
        }
        if (!(vectorsAreAboutEqual(event.getHitPosition(), result.getHitPoint()))) {
            String msg = "Denied activation attempt by {} since at the authority the object got hit at a differnt position";
            logger.info(msg, getPlayerNameFromCharacter(character));
            return false;
        }
    } else {
        // In order to trust the data later we need to verify it even if it should be correct if no one cheats:
        if (event.getTarget().exists()) {
            String msg = "Denied activation attempt by {} since the event was not properly labeled as having a target";
            logger.info(msg, getPlayerNameFromCharacter(character));
            return false;
        }
        if (!(vectorsAreAboutEqual(event.getHitPosition(), originPos))) {
            String msg = "Denied activation attempt by {} since the event was not properly labeled as having a hit postion";
            logger.info(msg, getPlayerNameFromCharacter(character));
            return false;
        }
    }
    return true;
}
Also used : HitResult(org.terasology.physics.HitResult) Vector3f(org.terasology.math.geom.Vector3f) PlayerCharacterComponent(org.terasology.logic.players.PlayerCharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent)

Aggregations

LocationComponent (org.terasology.logic.location.LocationComponent)68 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