Java 类com.badlogic.gdx.ai.msg.MessageManager 实例源码

项目:GdxDemo3D    文件:GameEngine.java   
public void update(float deltaTime) {
    // Update AI time
    GdxAI.getTimepiece().update(deltaTime);

    // Dispatch delayed messages
    MessageManager.getInstance().update();

    // Update Bullet simulation
    // On default fixedTimeStep = 1/60, small objects (the stick) will fall through 
    // the ground (the ground has relatively big triangles).
    dynamicsWorld.stepSimulation(deltaTime, 10, 1f / 240f);

    for (GameObject object : objectsById.values()) {
        if (object != null) {
            object.update(deltaTime);
        }
    }
}
项目:GdxDemo3D    文件:HumanCharacter.java   
@Override
public void update(HumanCharacter entity) {
    if (entity.isMoving()) {
        // Keep on updating movement animation
        updateAnimation(entity);
    } else {
        GameScreen.screen.sounds.whistle.play();
        // If the entity owns a dog send it a delayed message to emulate reaction time
        if (entity.dog != null) {
            MessageManager.getInstance().dispatchMessage(MathUtils.randomTriangular(.8f, 2f, 1.2f), null, entity.dog,
                    Constants.MSG_DOG_LETS_PLAY);
        }
        // Transition to the appropriate idle state depending on the previous state
        HumanState previousState = entity.stateMachine.getPreviousState();
        HumanState nextState = HumanState.IDLE_STAND;
        if (previousState != null) {
            if (previousState.isMovementState()) {
                nextState = previousState.idleState;
            } else if (previousState.isIdleState()) {
                nextState = previousState;
            }
        }
        entity.stateMachine.changeState(nextState);
    }
}
项目:GdxDemo3D    文件:HumanCharacter.java   
@Override
public void enter(HumanCharacter entity) {
    // Turn off animation
    entity.animations.setAnimation("armature|idle_stand", -1);
    entity.animations.paused = true;

    // Stop steering and let friction and gravity arrest the entity
    entity.stopSteering(false);

    // Set ragdoll control
    entity.setRagdollControl(true);

    // Dog owners inform the dog of the death and clear dog button
    if (entity.dog != null) {
        MessageManager.getInstance().dispatchMessage(MathUtils.randomTriangular(.8f, 2f, 1.2f), null, entity.dog, Constants.MSG_DOG_HUMAN_IS_DEAD);
        MessageManager.getInstance().dispatchMessage(Constants.MSG_GUI_CLEAR_DOG_BUTTON, entity);
    }
}
项目:GdxDemo3D    文件:HumanCharacter.java   
protected void prepareToMove(HumanCharacter entity, float steeringMultiplier) {
    entity.moveState = this;

    // Apply the multiplier to steering limits
    entity.setMaxLinearSpeed(HumanSteerSettings.maxLinearSpeed * steeringMultiplier);
    entity.setMaxLinearAcceleration(HumanSteerSettings.maxLinearAcceleration * steeringMultiplier);
    entity.setMaxAngularSpeed(HumanSteerSettings.maxAngularSpeed * steeringMultiplier);
    entity.setMaxAngularAcceleration(HumanSteerSettings.maxAngularAcceleration * steeringMultiplier);

    entity.followPathSteerer.followPathSB.setDecelerationRadius(HumanSteerSettings.decelerationRadius * steeringMultiplier);

    // If the entity owns a dog tell him you don't want to play and re-enable whistle
    if (entity.dog != null) {
        MessageManager.getInstance().dispatchMessage(MathUtils.randomTriangular(.8f, 2f, 1.2f), null, entity.dog, Constants.MSG_DOG_LETS_STOP_PLAYING);
        MessageManager.getInstance().dispatchMessage(Constants.MSG_GUI_SET_DOG_BUTTON_TO_WHISTLE, entity);
    }
}
项目:GdxDemo3D    文件:GameStage.java   
public CharacterController(TextureAtlas buttonAtlas) {
    whistleButton = new CharacterButton(HumanState.WHISTLE, buttonAtlas, "whistle-up", "whistle-down", "whistle-down");
    throwButton = new CharacterButton(HumanState.THROW, buttonAtlas, "throw-up", "throw-down", "throw-down");

    radioGroup = new ButtonGroup<CharacterButton>(
            new CharacterButton(HumanState.MOVE_RUN, buttonAtlas, "run-up", "run-down", "run-down"),
            new CharacterButton(HumanState.MOVE_WALK, buttonAtlas, "walk-up", "walk-down", "walk-down"),
            new CharacterButton(HumanState.MOVE_CROUCH, buttonAtlas, "crouch-up", "crouch-down", "crouch-down"),
            //new CharacterButton(CharacterState.MOVE_CRAWL, buttonAtlas, "crawl-up", "crawl-down", "crawl-down"),
            new CharacterButton(HumanState.DEAD, buttonAtlas, "kill-up", "kill-down", "kill-down")
    );

    // Add whistle button and save the reference to the 1st cell
    this.dogCell = add(whistleButton);

    // Add radio buttons
    for (CharacterButton btn : radioGroup.getButtons()) {
        add(btn);
    }

    // Register this controller's interests
    MessageManager.getInstance().addListeners(this,
            Constants.MSG_GUI_CLEAR_DOG_BUTTON,
            Constants.MSG_GUI_SET_DOG_BUTTON_TO_WHISTLE,
            Constants.MSG_GUI_SET_DOG_BUTTON_TO_THROW);
}
项目:GDXJam    文件:EntityUtils.java   
public static void clearTarget (Entity target) {
    ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(TargetComponent.class).get());

    for (Entity entity : entities) {
        TargetComponent targetComp = Components.TARGET.get(entity);
        if (targetComp.getTarget() == target) {
            targetComp.setTarget(null);

            //Dispatch a message to the entites FSM that there target was removed from the engine
            if (Components.FSM.has(entity)) {
                FSMComponent fsm = Components.FSM.get(entity);
                MessageManager.getInstance().dispatchMessage(null, fsm, TelegramMessage.TARGET_REMOVED.ordinal(), target);
            }
        }

    }
}
项目:GDXJam    文件:SquadEntityListener.java   
public void clearTarget (Entity target) {
    ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(TargetComponent.class, SquadComponent.class).get());

    for (Entity squad : entities) {
        SquadComponent squadComp = Components.SQUAD.get(squad);
        squadComp.untrack(squad, target);   //The squad no longer will track the target

        TargetComponent targetComp = Components.TARGET.get(squad);
        //If we were targeting that squad we remove it from our target
        if (targetComp.getTarget() == target) {
            targetComp.setTarget(null);

            //Dispatch a message to the entites FSM that there target was removed from the engine
            if (Components.FSM.has(squad)) {
                FSMComponent fsm = Components.FSM.get(squad);
                MessageManager.getInstance().dispatchMessage(null, fsm, TelegramMessage.TARGET_REMOVED.ordinal(), target);
            }
        }

    }
}
项目:GDXJam    文件:SquadComponent.java   
public void track (Entity self, Entity target) {
    if ((target.flags & EntityCategory.RESOURCE) == EntityCategory.RESOURCE) {
        resourcesTracked.add(target);
        resourceAgents.add(Components.STEERABLE.get(target));
        sortTrackedResources();
        MessageManager.getInstance().dispatchMessage(null, Components.FSM.get(self),
            TelegramMessage.DISCOVERED_RESOURCE.ordinal());
    } else if ((target.flags & EntityCategory.SQUAD) == EntityCategory.SQUAD) {
        if (EntityUtils.isSameFaction(self, target)) {
            friendliesTracked.add(target);
            friendlyAgents.add(Components.STEERABLE.get(target));
        } else {
            enemiesTracked.add(target);
            MessageManager.getInstance().dispatchMessage(null, Components.FSM.get(self), TelegramMessage.DISCOVERED_ENEMY.ordinal());
        }

    }
}
项目:ninja-rabbit    文件:LevelScreen.java   
@Override
public void render(final float delta) {
    accumulator += Math.min(delta, 0.25f);
    while (accumulator >= TIME_STEP) {
        world.step(TIME_STEP, VELOCITY_ITERATIONS, POSITION_ITERATIONS);
        accumulator -= TIME_STEP;
    }

    ninjaRabbit.update(viewport.getCamera());
    viewport.getCamera().update();
    game.getBatch().setProjectionMatrix(viewport.getCamera().combined);
    environment.update(viewport.getCamera());

    game.getBatch().begin();
    ninjaRabbit.step(game.getBatch());
    environment.step(game.getBatch());
    game.getBatch().end();

    MessageManager.getInstance().update(delta);

    hud.render();
}
项目:ninja-rabbit    文件:NinjaRabbitInputProcessor.java   
@Override
public boolean keyDown(final int keycode) {
    switch (keycode) {
    case JUMP_KEY:
        character.changeState(NinjaRabbitState.JUMP);
        break;
    case LEFT_KEY:
        character.changeState(NinjaRabbitState.LEFT);
        break;
    case RIGHT_KEY:
        character.changeState(NinjaRabbitState.RIGHT);
        break;
    case DUCK_KEY:
        // character.execute(NinjaRabbit.DUCK);
        break;
    case RESET_KEY:
        MessageManager.getInstance().dispatchMessage(null, MessageType.DEAD.code(), character);
        break;
    default:
        break;
    }
    return super.keyDown(keycode);
}
项目:gdx-ai    文件:StateMachineTest.java   
@Override
public void render () {
    float delta = Gdx.graphics.getDeltaTime();
    elapsedTime += delta;

    // Update time
    GdxAI.getTimepiece().update(delta);

    if (elapsedTime > 0.8f) {
        // Update Bob and his wife
        bob.update(elapsedTime);
        elsa.update(elapsedTime);

        // Dispatch any delayed messages
        MessageManager.getInstance().update();

        elapsedTime = 0;
    }
}
项目:GDX-Logic-Bricks    文件:MessageSensorSystemTest.java   
@Test
public void messageTest() {
    engine.addEntity(player);
    MessageManager.getInstance().dispatchMessage(messageActuator, MessageHandler.getMessageKey(message));

    engine.update(1);
    assertTrue(sensor.positive);
    assertEquals(LogicBrick.BrickMode.BM_ON, sensor.pulseState);

    engine.update(1);
    assertTrue(sensor.pulseState == LogicBrick.BrickMode.BM_OFF);
    assertTrue(sensor.positive);

    sensor.managedMessage = true;
    engine.update(1);
    assertTrue(sensor.pulseState == LogicBrick.BrickMode.BM_ON);
    assertFalse(sensor.positive);

}
项目:nhglib    文件:EngineStateRunning.java   
@Override
public void update(NhgEntry nhgEntry) {
    float delta = Gdx.graphics.getDeltaTime();

    MessageManager.getInstance().update();
    nhgEntry.nhg.assets.update();
    nhgEntry.nhg.entities.update(delta);

    nhgEntry.onUpdate(delta);
}
项目:nhglib    文件:AssetStateLoading.java   
@Override
public void update(Assets assets) {
    if (assets.assetManager.update()) {
        assets.fsm.changeState(AssetsStates.IDLE);
        MessageManager.getInstance().dispatchMessage(AssetsStates.ASSETS_GC);

        assets.assetLoadingFinished();
        publishLoadedAssets(assets);
    }
}
项目:nhglib    文件:AssetStateIdle.java   
public AssetStateIdle() {
    MessageManager.getInstance().addListener(new Telegraph() {
        @Override
        public boolean handleMessage(Telegram msg) {
            startGcTask();
            return true;
        }
    }, AssetsStates.ASSETS_GC);
}
项目:GdxDemo3D    文件:SetThrowButtonTask.java   
@Override
public Status execute () {
    DogCharacter dog = getObject();
    HumanCharacter human = dog.human;
    if (human.selected && dog.humanWantToPlay) {
        int msg = enabled ? Constants.MSG_GUI_SET_DOG_BUTTON_TO_THROW : Constants.MSG_GUI_CLEAR_DOG_BUTTON;
        boolean sendTelegram = enabled && dog.humanWantToPlay && !dog.stickThrown;
        if (!enabled)
            sendTelegram = dog.humanWantToPlay && dog.stickThrown;
        if (sendTelegram) {
            MessageManager.getInstance().dispatchMessage(msg, human);
        }
    }
    return Status.SUCCEEDED;
}
项目:GdxDemo3D    文件:DogCharacter.java   
@Override
public boolean handleMessage(Telegram telegram) {
    switch (telegram.message) {
        case Constants.MSG_DOG_LETS_PLAY:
            humanWantToPlay = true;
            stickThrown = false;
            break;
        case Constants.MSG_DOG_LETS_STOP_PLAYING:
            humanWantToPlay = false;
            break;
        case Constants.MSG_DOG_HUMAN_IS_DEAD:
            humanIsDead = true;
            humanWantToPlay = false;
            alreadyCriedForHumanDeath = false;
            break;
        case Constants.MSG_DOG_HUMAN_IS_RESURRECTED:
            humanIsDead = false;
            alreadyCriedForHumanDeath = false;
            break;
        case Constants.MSG_DOG_STICK_THROWN:
            stickThrown = true;
            break;
    }
    // Update GUI buttons if the dog's owner is selected
    if (this.human != null && this.human.selected) {
        MessageManager.getInstance().dispatchMessage(Constants.MSG_GUI_UPDATE_DOG_BUTTON, this.human);
    }
    return true;
}
项目:GdxDemo3D    文件:HumanCharacter.java   
@Override
public void enter(HumanCharacter entity) {
    // Stop steering and let friction and gravity arrest the entity
    entity.stopSteering(false);

    HumanState prevState = entity.stateMachine.getPreviousState();
    if (prevState != null && prevState.isMovementState()) {
        // Save animation speed multiplier
        entity.animationSpeedMultiplier = prevState.animationMultiplier;
    }
    MessageManager.getInstance().dispatchMessage(Constants.MSG_GUI_CLEAR_DOG_BUTTON, entity);
}
项目:GdxDemo3D    文件:HumanCharacter.java   
@Override
public void exit(HumanCharacter entity) {
    entity.animations.paused = false;
    entity.setRagdollControl(false);

    // Dog owners inform the dog of the resurrection and enable whistle button
    if (entity.dog != null) {
        MessageManager.getInstance().dispatchMessage(MathUtils.randomTriangular(.8f, 1.5f), null, entity.dog, Constants.MSG_DOG_HUMAN_IS_RESURRECTED);
        MessageManager.getInstance().dispatchMessage(Constants.MSG_GUI_SET_DOG_BUTTON_TO_WHISTLE, entity);
    }
}
项目:GdxDemo3D    文件:HumanCharacter.java   
public void onStickLanded() {
    stick.hasLanded = true;
    // If the entity owns a dog send it a delayed message to emulate reaction time
    if (dog != null) {
        MessageManager.getInstance().dispatchMessage(MathUtils.randomTriangular(.3f, 1.2f, .6f), null, dog,
                Constants.MSG_DOG_STICK_THROWN);
    }
}
项目:GDXJam    文件:ConstructionSystem.java   
public void constructUnit (Entity squad) {
    if (resourceSystem.resources >= unitCost) {
        resourceSystem.resources -= unitCost;
        EntityFactory.createUnit(squad);
        MessageManager.getInstance().dispatchMessage(this, Components.FSM.get(squad),
            TelegramMessage.CONSTRUCT_UNIT_CONFRIM.ordinal());
    } else {
        MessageManager.getInstance().dispatchMessage(TelegramMessage.GUI_INSUFFICIENT_RESOURCES.ordinal());
    }
}
项目:GDXJam    文件:GUISystem.java   
public GUISystem () {
    this.stage = new Stage();
    this.skin = Assets.skin;

    MessageManager.getInstance().addListener(this, TelegramMessage.SQUAD_INPUT_SELECTED.ordinal());
    MessageManager.getInstance().addListener(this, TelegramMessage.GUI_INSUFFICIENT_RESOURCES.ordinal());

    initGUI();
    initAlertTasks();
}
项目:Boogie    文件:DownloadUtils.java   
@Override
public void run()
{
    if (tempFiles.size >= size)
    {
        MessageManager.getInstance().dispatchMessage(null, StateMessage.DownloadCompleted);
    }
}
项目:ninja-rabbit    文件:LevelPlayerStatusProcessor.java   
@Override
protected void doUpdate(final Entity entity) {
    // No time or lives left: game over
    if (getStatus().getTime() < 0 || getStatus().getLives() < 1 && !gameOverSignaled) {
        MessageManager.getInstance().dispatchMessage(this, MessageType.GAME_OVER.code());
        gameOverSignaled = true;
    }
}
项目:ninja-rabbit    文件:LevelPlayerStatusProcessor.java   
@Override
public boolean handleMessage(final Telegram msg) {
    getStatus().setLevel((byte) (getStatus().getLevel() + 1));
    getStatus().setTime(PlayerStatus.DEFAULT_TIME);
    MessageManager.getInstance().dispatchMessage(this, MessageType.BEGIN_LEVEL.code());
    return true;
}
项目:ninja-rabbit    文件:NinjaRabbitGame.java   
/**
 * Clears all remaining messages and listeners in the {@link MessageManager} instance and
 * re-adds the ones from related to this {@link Telegraph}.
 */
private void addListeners() {
    MessageManager manager = MessageManager.getInstance();
    manager.clear();
    manager.addListeners(this, MessageType.GAME_OVER.code(),
            MessageType.RESET.code(), MessageType.BEGIN_LEVEL.code());
}
项目:ninja-rabbit    文件:NinjaRabbitInputProcessor.java   
public NinjaRabbitInputProcessor(final Entity ninjaRabbit) {
    if (ninjaRabbit == null) {
        throw new IllegalArgumentException("'character' cannot be null");
    }
    this.character = ninjaRabbit;
    MessageManager.getInstance().addListener(this, MessageType.EXIT.code());
}
项目:ninja-rabbit    文件:NinjaRabbitControllerProcessor.java   
@Override
public boolean buttonDown(final Controller controller, final int buttonCode) {
    if (buttonCode == JUMP_KEY) {
        character.changeState(NinjaRabbitState.JUMP);
    } else if (buttonCode == RESET_KEY) {
        MessageManager.getInstance().dispatchMessage(null, MessageType.DEAD.code(), character);
    }
    return super.buttonDown(controller, buttonCode);
}
项目:ninja-rabbit    文件:CarrotPhysicsProcessor.java   
/**
 * @param contact
 */
private void collectCarrot(final Fixture fixture) {
    Collectible carrot = (Collectible) fixture.getBody().getUserData();
    if (!carrot.isCollected()) {
        carrot.setCollected(true);
        MessageManager.getInstance().dispatchMessage(null, MessageType.COLLECTED.code(), carrot);
    }
}
项目:gdx-ai    文件:TelegramProviderTest.java   
@Override
public void create () {
    super.create();
    MessageManager.getInstance().clear();
    elapsedTime = 0;
    // build a new city
    city = new City();

}
项目:gdx-ai    文件:TelegramProviderTest.java   
@Override
public void update () {
    elapsedTime += GdxAI.getTimepiece().getDeltaTime();
    if (elapsedTime > 1.5f) {
        MessageManager.getInstance().dispatchMessage(null, MSG_TIME_TO_ACT);
        elapsedTime = 0;
    }
}
项目:gdx-ai    文件:TelegramProviderTest.java   
public House (City city) {
    this.id = city.houses.size + 1;
    citizens = new Array<Citizen>();
    Gdx.app.log(toString(), "New house in town");
    // Mr & Mrs
    citizens.add(new Citizen(this));
    citizens.add(new Citizen(this));
    MessageManager.getInstance().addListeners(this, TelegramProviderTest.MSG_TIME_TO_ACT);
}
项目:gdx-ai    文件:TelegramProviderTest.java   
public Citizen (House house) {
    this.id = house.citizens.size + 1;
    this.house = house;
    Gdx.app.log(toString(), "Hi there, I'm new in town and I live in house number " + house.id);
    MessageManager.getInstance().addListener(this, TelegramProviderTest.MSG_EXISTING_CITIZEN);
    MessageManager.getInstance().addProvider(this, TelegramProviderTest.MSG_EXISTING_CITIZEN);
}
项目:gdx-ai    文件:BulletJumpTest.java   
@Override
public void update () {
    MessageManager.getInstance().update();
    character.update(GdxAI.getTimepiece().getDeltaTime());

    super.update();
}
项目:gdx-ai    文件:InterruptibleFlatTiledAStarTest.java   
@Override
public void dispose () {
    renderer.dispose();

    worldMap = null;
    activePath = null;
    workPath = null;
    heuristic = null;
    pathFinder = null;
    pathSmoother = null;
    scheduler = null;

    MessageManager.getInstance().clear();
}
项目:gdx-ai    文件:InterruptibleHierarchicalTiledAStarTest.java   
@Override
public void dispose () {
    renderer.dispose();

    worldMap = null;
    paths = null;
    heuristic = null;
    pathFinder = null;
    pathSmoother = null;
    scheduler = null;

    MessageManager.getInstance().clear();
}
项目:gdx-ai    文件:InterruptibleHierarchicalTiledAStarTest.java   
private void requestNewPathFinding (HierarchicalTiledNode startNode, HierarchicalTiledNode endNode, int pathIndex) {
    TiledSmoothableGraphPath<HierarchicalTiledNode> path = paths[pathIndex];

    MyPathFinderRequest pfRequest = requestPool.obtain();
    pfRequest.startNode = startNode;
    pfRequest.endNode = endNode;
    pfRequest.heuristic = heuristic;
    pfRequest.resultPath = path;
    pfRequest.pathIndex = pathIndex;
    pfRequest.responseMessageCode = PF_RESPONSE;
    MessageManager.getInstance().dispatchMessage(this, PF_REQUEST, pfRequest);
}
项目:GDX-Logic-Bricks    文件:MessageSensorSystem.java   
@Override
public void entityAdded(Entity entity) {
    MessageSensorComponent messageSensors = entity.getComponent(MessageSensorComponent.class);
    if (messageSensors != null) {
        IntMap.Values<ObjectSet<MessageSensor>> values = messageSensors.sensors.values();
        while (values.hasNext()) {
            for (MessageSensor sensor : values.next()) {
                if (sensor.autoRegister)
                    MessageManager.getInstance().addListener(sensor, MessageHandler.getMessageKey(sensor.subject));
            }
        }
    }
}
项目:GDX-Logic-Bricks    文件:MessageSensorSystem.java   
@Override
public void entityRemoved(Entity entity) {
    MessageSensorComponent messageSensors = entity.getComponent(MessageSensorComponent.class);
    if (messageSensors != null) {
        IntMap.Values<ObjectSet<MessageSensor>> values = messageSensors.sensors.values();
        while (values.hasNext()) {
            for (MessageSensor sensor : values.next()) {
                MessageManager.getInstance().removeListener(sensor, MessageHandler.getMessageKey(sensor.subject));
            }

        }
    }
}
项目:GDX-Logic-Bricks    文件:PropertySensorSystem.java   
@Override
public void entityRemoved(Entity entity) {
    PropertySensorComponent propertySensors = entity.getComponent(PropertySensorComponent.class);
    if (propertySensors != null) {
        IntMap.Values<ObjectSet<PropertySensor>> values = propertySensors.sensors.values();
        while (values.hasNext()) {
            for (PropertySensor sensor : values.next()) {
                if (sensor.evaluationType.equals(PropertySensor.EvaluationType.CHANGED))
                    MessageManager.getInstance().removeListener(sensor, MessageHandler.getMessageKey(sensor.property + "_Changed"));
            }
        }
    }
}