Java 类com.badlogic.gdx.utils.IntMap 实例源码

项目:Tower-Defense-Galaxy    文件:EnemySpawner.java   
public void tick(float delta, GameScreen screen) {
    if (!started && screen.isPaused()) {
        started = true;
        prevTime = System.currentTimeMillis();
    }
    if (spawns != null && enemyIndex < spawns.size() && System.currentTimeMillis() > prevTime + spawns.get(enemyIndex).getDelay()) {
        prevTime = System.currentTimeMillis();
        String name = spawns.get(enemyIndex).getName();
        ModelInstance instance;
        try {
            Class<?> c = enemyClasses.get(name);
            Constructor constructor = c.getConstructor(Matrix4.class, Map.class, btCollisionWorld.class, IntMap.class, List.class, Map.class);
            enemies.add((Enemy) constructor.newInstance(new Matrix4().setToTranslation(pos), models, world, entity, path, sounds));
        } catch (Exception e) {
            Gdx.app.log("EnemySpawner spawn enemy", e.toString());
        }
        enemyIndex++;
    }
    //for (Enemy enemy : enemies)
    //   enemy.tick(delta, path);
}
项目:Tower-Defense-Galaxy    文件:Basic.java   
public Basic(Matrix4 transform, double speeed, int hp, int health, int range, float coolDown, EnumSet<Types> types, EnumSet<Effects> effects, ModelInstance instance, btCollisionWorld world, IntMap<Entity> entities, List<Vector3> path, Map<String, Sound> sounds) {
    super(transform, speeed, hp, health, range, coolDown, types, effects, instance, new btCompoundShape(), world, entities, ATTACK_ANIMATION, ATTACK_OFFSET, path, sounds);
    ((btCompoundShape)shape).addChildShape(new Matrix4(new Vector3(0, 30, 0), new Quaternion().setEulerAngles(0, 0, 0), new Vector3(1, 1, 1)), new btBoxShape(new Vector3(75, 30, 90)));
    //System.out.println(getModelInstance().getAnimation("Spider_Armature|walk_ani_vor").id);
    listener = new AnimationController.AnimationListener() {
        @Override
        public void onEnd(AnimationController.AnimationDesc animationDesc) {

        }

        @Override
        public void onLoop(AnimationController.AnimationDesc animationDesc) {

        }
    };
    //animation.setAnimation("Spider_Armature|walk_ani_vor");
    //animation.animate("Spider_Armature|walk_ani_vor", -1);
    //animation.action("Spider_Armature|walk_ani_vor", 0, 1000, -1, 1, listener, 0);
    //animation.animate("Spider_Armature|Attack", 0, 1000, 1, 1, listener, 0);
    //animation.queue("Spider_Armature|walk_ani_vor", 0, 1000, -1, 1, listener, 0);
}
项目:Tower-Defense-Galaxy    文件:GameScreen.java   
@Override
protected void update(float delta) {
    if (!paused && !isLoading) {
        /*for (IntMap.Entry<Entity> entry : entities.entries()) {
            entry.value.tick(delta);
            if (entry.value.isDead) {
                entry.value.destroy();
            }
        }*/
        Iterator<IntMap.Entry<Entity>> iterator = entities.entries().iterator();

        while (iterator.hasNext()) {
            IntMap.Entry<Entity> entry = iterator.next();
            entry.value.tick(delta);
            if (entry.value.isDead) {
                iterator.remove();
            }
        }
        enemies.tick(delta, this);

        collisionWorld.performDiscreteCollisionDetection();

        camHandler.update(delta);
    }
}
项目:gdx-cclibs    文件:IntMapSerializer.java   
public void write (Kryo kryo, Output output, IntMap map) {
    int length = map.size;
    output.writeVarInt(length, true);
    output.writeBoolean(false); // whether type is written (in case future version of IntMap supports type awareness)
    Serializer valueSerializer = null;
    if (valueGenericType != null) {
        if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueGenericType);
        valueGenericType = null;
    }

    for (Iterator iter = map.iterator(); iter.hasNext();) {
        IntMap.Entry entry = (IntMap.Entry)iter.next();
        output.writeInt(entry.key);
        if (valueSerializer != null) {
            kryo.writeObjectOrNull(output, entry.value, valueSerializer);
        } else
            kryo.writeClassAndObject(output, entry.value);
    }
}
项目:nhglib    文件:SystemInputHandler.java   
public SystemInputHandler(InputProxy inputProxy, InputMultiplexer inputMultiplexer, Array<NhgInput> systemInputArray) {
    this.inputProxy = inputProxy;

    vec0 = new Vector2();

    keyboardButtonInputs = new IntMap<>();
    mouseButtonInputs = new IntMap<>();
    touchInputs = new IntMap<>();

    activeKeyboardButtonInputs = new Array<>();
    activeMouseButtonInputs = new Array<>();
    activeTouchInputs = new Array<>();

    mapSystemInput(systemInputArray);
    handleSystemInput(inputMultiplexer);
}
项目:fabulae    文件:Inventory.java   
/**
 * Copies all items from this inventory into the destination inventory
 */
public void copyAllItemsTo(Inventory destinationInventory) {
    for (BagType bag : BagType.values()) {
        IntMap<InventoryItem> sourceBag = getBag(bag);
        for (Entry<InventoryItem> slot : sourceBag.entries()) {
            InventoryItem item = slot.value;
            if (item != null) {
                InventoryItem newCopy = item.createNewInstance();
                if (item.getStackSize() > 1) {
                    for (int i = 1; i < item.getStackSize(); ++i) {
                        newCopy.addToStack(newCopy.createNewInstance());
                    }
                }
                destinationInventory.addToBag(bag, newCopy, slot.key);
            }
        }
    }
}
项目:fabulae    文件:Inventory.java   
/**
 * Removes the item in the supplied slot from the bag and returns it. If the
 * slot was empty, null is returned.
 * 
 * If the item was stackable and removeWholeStack is false, its stack is
 * decreased and the item removed from the stack is returned.
 * 
 * @param bagType
 * @param slot
 * @param removeWholeStack
 *            - if true, the whole stack is removed at once
 * @return
 */
public InventoryItem removeFromBag(BagType bagType, Integer slot,
        boolean removeWholeStack) {
    IntMap<InventoryItem> bag = bags.get(bagType);
    InventoryItem existingItem = bag.get(slot);
    if (existingItem == null) {
        return null;
    }
    if (existingItem.isInfinite() || (!removeWholeStack && existingItem.getStackSize() > 1)) {
        existingItem = existingItem.removeFromStack();
    } else {
        bag.remove(slot);
    }
    existingItem.setInventory(null);
    onItemRemove(existingItem, bagType);
    return existingItem;
}
项目:DigBlock    文件:World.java   
@Override
public void processTouch(IntMap<Int2> touch) {
    int deltaX, deltaY;
    for(IntMap.Entry entry:touch.entries()) {
        Int2 value = (Int2)entry.value;
        Int2 xy = InputHandler.getXY(entry.key);
        deltaX = value.x-xy.x;
        deltaY = value.y-xy.y;
        if(value.x < InputHandler.vWidth/2) {
            player.axisInput(-deltaX/100f,deltaY/100f);
        } else {
            if(player.setRot(deltaX,deltaY)) {
                value.x = xy.x;
                value.y = xy.y;
                player.jumpCount();
            }
        }
    }
}
项目:LWPTools    文件:GaussianBlurShaderProvider.java   
boolean disposeShader(ShaderProgram shaderProgram){
    if (shaderProgram == null)
        return false;

    for (IntMap.Entry<UniqueShader> entry : blurPassShaderPrograms.entries()){
        UniqueShader uniqueShader = entry.value;
        if (uniqueShader.shaderProgram == shaderProgram){
            uniqueShader.refCount--;
            if (uniqueShader.refCount < 1){
                shaderProgram.dispose();
                blurPassShaderPrograms.remove(entry.key);
                return true;
            } else {
                return false;
            }
        }
    }

    //not found!
    shaderProgram.dispose();
    return true;
}
项目:libgdxcn    文件:AndroidControllers.java   
private void gatherControllers(boolean sendEvent) {
    // gather all joysticks and gamepads, remove any disconnected ones
    IntMap<AndroidController> removedControllers = new IntMap<AndroidController>();
    removedControllers.putAll(controllerMap);

    for(int deviceId: InputDevice.getDeviceIds()) {
        InputDevice device = InputDevice.getDevice(deviceId);
        AndroidController controller = controllerMap.get(deviceId);
        if(controller != null) {
            removedControllers.remove(deviceId);
        } else {
            addController(deviceId, sendEvent);
        }
    }

    for(Entry<AndroidController> entry: removedControllers.entries()) {
        removeController(entry.key);
    }
}
项目:ShapeOfThingsThatWere    文件:DiscoverySystem.java   
private Iterable<Entity> getNeighbors(Entity empire) {
  IntMap<Entity> neighbors = new IntMap<>();

  // collect entities we have relations with
  for (Entity e : relations.get(empire).relations.keySet())
    neighbors.put(e.getId(), e);

  // collect entities we share influence with
  for (MapPosition p : influences.get(empire).influencedTiles)
    for (Entry inf : map.getInfluenceAt(p))
      if (inf.key != empire.getId() && !neighbors.containsKey(inf.key)
      // may be pending insertion into world if just revolted
          && world.getEntityManager().isActive(inf.key))
        neighbors.put(inf.key, world.getEntity(inf.key));

  return neighbors.values();
}
项目:gaiasky    文件:Constellation.java   
@Override
public void setUp() {
    if (!allLoaded) {
        int npairs = ids.size;
        if (lines == null) {
            lines = new IPosition[npairs][];
        }
        IntMap<IPosition> hipMap = sg.getStarMap();
        allLoaded = true;
        for (int i = 0; i < npairs; i++) {
            int[] pair = ids.get(i);
            IPosition s1, s2;
            s1 = hipMap.get(pair[0]);
            s2 = hipMap.get(pair[1]);
            if (lines[i] == null && s1 != null && s2 != null) {
                lines[i] = new IPosition[] { s1, s2 };
            } else {
                allLoaded = false;
            }
        }
    }
}
项目:vis-editor    文件:IntMapJsonSerializer.java   
@Override
public IntMap<T> deserialize (JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonArray jsonArray = json.getAsJsonArray();

    IntMap<T> intMap = new IntMap<>(jsonArray.size());

    for (JsonElement element : jsonArray) {
        JsonObject object = element.getAsJsonObject();
        Entry<String, JsonElement> entry = object.entrySet().iterator().next();
        int mapKey = Integer.parseInt(entry.getKey());
        Class<?> mapObjectClass = GsonUtils.readClassProperty(object, context);
        intMap.put(mapKey, context.deserialize(entry.getValue(), mapObjectClass));
    }

    return intMap;
}
项目:GDX-Logic-Bricks    文件:CollisionSensorSystem.java   
private Array<CollisionSensor> filterCollisionSensors(Entity entity) {
    Array<CollisionSensor> collisionSensors = new Array<CollisionSensor>();
    CollisionSensorComponent collisionSensorComponent = entity.getComponent(CollisionSensorComponent.class);
    if (collisionSensorComponent != null) {
        IntMap.Values<ObjectSet<CollisionSensor>> values = collisionSensorComponent.sensors.values();
        while (values.hasNext()) {
            for (CollisionSensor sensor : values.next()) {
                if (sensor.targetTag != null) {
                    collisionSensors.add(sensor);
                }
            }
        }
    }
    return collisionSensors;

}
项目:GDX-Logic-Bricks    文件:RaySensorSystem.java   
@Override
public void entityAdded(Entity entity) {
    Log.debug(tag, "EntityAdded add RaySensors");
    RigidBodiesComponents rigidBodiesComponent = entity.getComponent(RigidBodiesComponents.class);
    RaySensorComponent raySensorComponent = entity.getComponent(RaySensorComponent.class);
    if (raySensorComponent != null) {
        IntMap.Values<ObjectSet<RaySensor>> values = raySensorComponent.sensors.values();
        while (values.hasNext()) {
            for (RaySensor sensor : values.next()) {
                if (sensor.attachedRigidBody == null)
                    sensor.attachedRigidBody = rigidBodiesComponent.rigidBodies.first();

            }
        }
    }

}
项目:GDX-Logic-Bricks    文件:MouseSensorSystem.java   
@Override
public void entityAdded(Entity entity) {
    MouseSensorComponent mouseComponent = entity.getComponent(MouseSensorComponent.class);
    if (mouseComponent != null) {
        IntMap.Values<ObjectSet<MouseSensor>> values = mouseComponent.sensors.values();
        while (values.hasNext()) {
            for (MouseSensor sensor : values.next()) {
                ObjectSet eventSensors;
                if (mouseSensors.containsKey(sensor.mouseEvent)) {
                    eventSensors = mouseSensors.get(sensor.mouseEvent);

                } else {
                    eventSensors = new ObjectSet<MouseSensor>();
                    mouseSensors.put(sensor.mouseEvent, eventSensors);
                }
                eventSensors.add(sensor);

            }
        }
    }

}
项目:GDX-Logic-Bricks    文件:Game.java   
public Game(LogicBricksEngine engine, World physics) {
    this.engine = engine;
    this.physics = physics;
    renderingSystem = new RenderingSystem();
    engine.addSystem(renderingSystem);

    levelFactories = new IntMap<LevelFactory>();
    categoryBitsManager = new CategoryBitsManager();

    //engine.update(0);

    Gdx.input.setInputProcessor(engine.getInputs());
    physics.setContactListener(this);
    Gdx.app.setLogLevel(Settings.DEBUG_LEVEL);

}
项目:shadow-engine    文件:DefaultMusicSystem.java   
public DefaultMusicSystem(Level level) {
    this.level = level;
    for (IntMap.Entry<Music> entry : Musics.playing) {
        if (entry.key < 1 || entry.key > 3) {
            Musics.set(entry.key, null);
        }
    }
    musics = new Music[] {
            Musics.set(1, "main_1"),
            Musics.set(2, "main_2"),
            Musics.set(-2, "main_night_2"),
            Musics.set(3, "main_3")
    };
    musics[0].setVolume(1f);
    for (int i = 1; i < musics.length; i++) {
        musics[i].setVolume(0f);
    }
    for (int i = 1; i < musics.length; i++) {
        musics[i].setPosition(musics[i-1].getPosition());
    }
    for (int i = 0; i < musics.length; i++) {
        musics[i].play();
    }
}
项目:Mindustry    文件:ColorMapper.java   
private static IntMap<BlockPair> map(Object...objects){
    IntMap<BlockPair> colors = new IntMap<>();
    for(int i = 0; i < objects.length/2; i ++){
        colors.put(Color.rgba8888(Color.valueOf((String)objects[i*2])), (BlockPair)objects[i*2+1]);
        pairs.add((BlockPair)objects[i*2+1]);
    }
    for(Entry<BlockPair> e : colors.entries()){
        reverseColors.put(e.value.wall == Blocks.air ? e.value.floor : e.value.wall, e.key);
    }
    return colors;
}
项目:Tower-Defense-Galaxy    文件:AttackingEntity.java   
public AttackingEntity(Matrix4 transform, int hp, int health, int range, EnumSet<Types> types, EnumSet<Effects> effects, float coolDown, ModelInstance instance, btCollisionShape shape, btCollisionWorld world, IntMap<Entity> entities, String attackAnimation, Vector3 attackOffset, Map<String, Sound> sounds){
    super(transform, hp, health, types, effects, instance, shape, world, entities, sounds);
    this.coolDown = coolDown;
    this.range = range;
    this.attackAnimation = attackAnimation;
    this.attackOffset = attackOffset;
    callback = new ClosestRayResultCallback(new Vector3(), new Vector3());
}
项目:Tower-Defense-Galaxy    文件:Entity.java   
public Entity(Matrix4 transform, int hp, int health, EnumSet<Types> types, EnumSet<Effects> effects, ModelInstance instance, btCollisionShape shape, btCollisionWorld world, IntMap<Entity> entities, Map<String, Sound> sounds){
    this.instance = instance;
    this.transform = transform;
    this.hp = hp;
    this.types = types;
    this.health = health;
    this.effects = effects;
    this.sounds = sounds;
    animation = new AnimationController(instance);
    this.instance.transform.set(transform);
    this.shape = shape;
    body = new btCollisionObject();
    body.setCollisionShape(shape);
    body.setWorldTransform(this.instance.transform);
    this.world = world;
    tempVector = new Vector3();
    tempVector2 = new Vector3();
    this.entities = entities;
    tempQuaternion = new Quaternion();
    quaternion = new Quaternion();
    if(this instanceof Enemy || this instanceof Projectile)
        body.setCollisionFlags(body.getCollisionFlags());
    int index = getNextIndex();
    entities.put(index, this);
    body.setUserValue(index);
    world.addCollisionObject(body);
    boundingBox = instance.calculateBoundingBox(new BoundingBox());
    //for(Node node: instance.nodes)
        //System.out.println();
}
项目:Tower-Defense-Galaxy    文件:Gun.java   
public Gun(Matrix4 transform, int hp, int health, int range, float cooldown, EnumSet<Types> types, EnumSet<Effects> effects, ModelInstance instance, btCollisionShape shape, btCollisionWorld world, IntMap<Entity> entities, String attack, EntityTemplate<Bullet> projectile, Vector3 attackOffset, Map<String, Sound> sounds) {
    super(transform, hp, health, range, cooldown, types, effects, instance, shape, world, entities, attack, projectile, attackOffset, sounds);
    nodes = new HashMap<String, Node>();
    /*for(Node node: instance.model.nodes) {
        System.out.println(node.id);
        if (node.id.startsWith("Leg")) {
            legs.add(node);
        }
    }*/
    //legs.get(0).rotation.setEulerAngles(100, 0, 0);

    for(Node node: instance.getNode("Gun_root").getChildren())
        nodes.put(node.id, node);
}
项目:Tower-Defense-Galaxy    文件:EnemySpawner.java   
public EnemySpawner(Vector3 pos, Map<String, Class<?>> enemyClasses, List<Spawn> spawns, Map<String, Model> models, List<Enemy> enemies, List<Vector3> path, btCollisionWorld world, IntMap<Entity> entities, Map<String, Sound> sounds) {
    this.enemies = enemies;
    this.pos = pos;
    this.enemyClasses = enemyClasses;
    this.models = models;
    this.spawns = spawns;
    this.path = path;
    this.world = world;
    this.entity = entities;
    this.sounds = sounds;
    System.out.println(spawns);
}
项目:Tower-Defense-Galaxy    文件:Projectile.java   
public Projectile(Matrix4 transform, Vector3 velocity, int hp, int health, float speed, EnumSet<Types> types, EnumSet<Effects> effects, ModelInstance model, btCollisionShape shape, boolean isTower, btCollisionWorld world, IntMap<Entity> entities, float lifetime, Map<String, Sound> sounds) {
    super(transform, hp, health, types, effects, model, shape, world, entities, sounds);
    this.isTower = isTower;
    this.velocity = velocity;
    this.velocity.scl(speed);
    this.lifetime = lifetime;
}
项目:gdx-cclibs    文件:IntMapSerializer.java   
public IntMap read (Kryo kryo, Input input, Class<IntMap> type) {
    int length = input.readVarInt(true);
    input.readBoolean(); // currently unused
    IntMap map = new IntMap(length);

    Class valueClass = null;

    Serializer valueSerializer = null;
    if (valueGenericType != null) {
        valueClass = valueGenericType;
        if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueClass);
        valueGenericType = null;
    }

    kryo.reference(map);

    for (int i = 0; i < length; i++) {
        int key = input.readInt();
        Object value;
        if (valueSerializer != null) {
            value = kryo.readObjectOrNull(input, valueClass, valueSerializer);
        } else
            value = kryo.readClassAndObject(input);
        map.put(key, value);
    }
    return map;
}
项目:gdx-cclibs    文件:RenderContextAccumulator.java   
public boolean hasPendingChanges () {
    State pending = this.pending;
    State current = this.current;

    if (pending.depthMasking != current.depthMasking) return true;

    if (pending.depthTesting != current.depthTesting) return true;

    if (pending.depthTesting && pending.depthFunc != current.depthFunc) return true;

    if (pending.blending != current.blending) return true;

    if (pending.blending) {
        if (pending.blendSrcFuncColor != current.blendSrcFuncColor || pending.blendDstFuncColor != current.blendDstFuncColor
            || pending.blendSrcFuncAlpha != current.blendSrcFuncAlpha || pending.blendDstFuncAlpha != current.blendDstFuncAlpha)
            return true;
        if (pending.blendEquationColor != current.blendEquationColor || pending.blendEquationAlpha != current.blendEquationAlpha)
            return true;
    }

    IntMap<GLTexture> actualTextureUnits = current.textureUnits;
    for (IntMap.Entry<GLTexture> entry : pending.textureUnits) {
        if (actualTextureUnits.get(entry.key) != entry.value) return true;
    }

    return false;
}
项目:PixelDungeonTC    文件:DesktopInputProcessor.java   
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
    for (IntMap.Entry<Touch> entry : pointers) {
        entry.value.update(screenX, screenY);
    }
    eventTouch.dispatch(null);
    return true;
}
项目:gdxjam-ugg    文件:InputController.java   
public InputController(Stage playStage, Stage guiStage){
    this.playStage = playStage;
    this.guiStage = guiStage;
    this.inputMultiplexer = new InputMultiplexer(guiStage, playStage);
    this.commandManager = new CommandManager();
    this.players = new IntMap<>();
    this.mappedKeysForPlayer = new ObjectMap<>();
}
项目:gdxjam-ugg    文件:InputController.java   
public <T extends Command> InputController mapKeyToCommand(int playerId, InputPeripheralType peripheralType, int key, Class<T> commandClass){
    Player targetPlayer = this.players.get(playerId);
    targetPlayer.mapCommand(peripheralType, key, commandClass);
    IntMap<Player> mappedKeys = this.mappedKeysForPlayer.get(peripheralType);
    if(mappedKeys == null){
        mappedKeys = new IntMap<>();
        this.mappedKeysForPlayer.put(peripheralType, mappedKeys);
    }
    mappedKeys.put(key, targetPlayer);
    return this;
}
项目:gdxjam-ugg    文件:InputController.java   
private Player getTargetPlayerForKey(int key, InputPeripheralType peripheralType){
    IntMap<Player> mappedKeys = this.mappedKeysForPlayer.get(peripheralType);
    if(mappedKeys == null)
        return null;
    else
        return mappedKeys.get(key);
}
项目:gdxjam-ugg    文件:ParticleData.java   
@Override
public void assignComponents(GameEntity gameEntity) {
    ParticleTypesComponent particleC = gameEntity.addComponent(ParticleTypesComponent.class);
    for(IntMap.Entry<ParticleType> entry : particleTypes){
        particleC.particleTypes.put(entry.key, entry.value);
    }

}
项目:gdxjam-ugg    文件:Player.java   
public <T extends Command> Player mapCommand(InputPeripheralType peripheralType, int key, Class<T> commandClass){
    IntMap<Class> mappedByPeripheral = mappedCommands.get(peripheralType);
    if(mappedByPeripheral == null) {
        mappedByPeripheral = new IntMap<>();
           mappedCommands.put(peripheralType, mappedByPeripheral);
    }
    mappedByPeripheral.put(key, commandClass);
    return this;
}
项目:gdxjam-ugg    文件:Player.java   
public <T extends Command> Class<T> getCommandClass(InputPeripheralType peripheralType, int key){
    IntMap<Class> mappedByPeripheral = mappedCommands.get(peripheralType);
    if(mappedByPeripheral != null){
        Class<T> command = mappedByPeripheral.get(key);
        if(command != null) {
            return command;
        }else{
            Logger.getInstance().error("No command found for key [" + key + "] and peripheral [" + peripheralType + "]");
        }
    }else{
        Logger.getInstance().log("No commands found for peripheral [" + peripheralType + "]");
    }
    return null;
}
项目:Undertailor    文件:OpenALAudio.java   
public OpenALAudio (int simultaneousSources, int deviceBufferCount, int deviceBufferSize) {
    this.deviceBufferSize = deviceBufferSize;
    this.deviceBufferCount = deviceBufferCount;

    registerSound("ogg", Ogg.Sound.class);
    registerMusic("ogg", Ogg.Music.class);
    registerSound("wav", Wav.Sound.class);
    registerMusic("wav", Wav.Music.class);
    registerSound("mp3", Mp3.Sound.class);
    registerMusic("mp3", Mp3.Music.class);

    try {
        AL.create();
    } catch (LWJGLException ex) {
        noDevice = true;
        ex.printStackTrace();
        return;
    }

    allSources = new IntArray(false, simultaneousSources);
    for (int i = 0; i < simultaneousSources; i++) {
        int sourceID = alGenSources();
        if (alGetError() != AL_NO_ERROR) break;
        allSources.add(sourceID);
    }
    idleSources = new IntArray(allSources);
    soundIdToSource = new LongMap<Integer>();
    sourceToSoundId = new IntMap<Long>();

    FloatBuffer orientation = (FloatBuffer)BufferUtils.createFloatBuffer(6)
        .put(new float[] {0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f}).flip();
    alListener(AL_ORIENTATION, orientation);
    FloatBuffer velocity = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).flip();
    alListener(AL_VELOCITY, velocity);
    FloatBuffer position = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).flip();
    alListener(AL_POSITION, position);

    recentSounds = new OpenALSound[simultaneousSources];
}
项目:fabulae    文件:ItemPile.java   
@Override
public void onInventoryClose() {
    super.onInventoryClose();
    if (shouldBeRemoved) {
        GameMap map = getMap();
        map.removeGameObject(ItemPile.this);
        IntMap<InventoryItem> backPack = getBag(BagType.BACKPACK);
        if (backPack.size == 1) {
            InventoryItem lastItem = backPack.values().next();
            Tile tile = position().tile();
            new PickableGameObject(lastItem, tile.getX(), tile.getY(), map);
            backPack.clear();
        }
    }
}
项目:fabulae    文件:Inventory.java   
public Inventory(InventoryContainer ic) {
    bags = new ObjectMap<BagType, IntMap<InventoryItem>>();
    for (BagType bag : BagType.values()) {
        bags.put(bag, new IntMap<InventoryItem>());
    }
    this.parentContainer = ic;
}
项目:fabulae    文件:Inventory.java   
/**
 * Returns the item with the specified id from this Inventory, or null if
 * such item cannot be found.
 * 
 * The item is not actually removed from the intenvory when returned!
 * 
 * @param id
 * @return
 */
public InventoryItem getItem(String id) {
    id = id.toLowerCase(Locale.ENGLISH);
    for (BagType bagType : BagType.values()) {
        IntMap<InventoryItem> bag = bags.get(bagType);
        for (InventoryItem item : bag.values()) {
            if (id.equals(item.getId())) {
                return item;
            }
        }
    }

    return null;
}
项目:fabulae    文件:Inventory.java   
/**
 * Adds the supplied InventoryItem to the supplied slot in the bag. If the
 * slot is already occupied, and the item there is not stackable, the item
 * there will be replaced by the new one and returned by this method.
 * 
 * Otherwise the new item is just added to the stack and null is returned.
 * 
 * If the supplied item already belonged to a different inventory, it will
 * be removed from there.
 * 
 * @param bagType
 * @param item
 * @param slot
 *            - if it is null, the first empty slot is used
 * @return
 */
public InventoryItem addToBag(BagType bagType, InventoryItem item,
        Integer slot) {
    IntMap<InventoryItem> bag = bags.get(bagType);
    InventoryItem existingItem = null;

    // remove from previous owner if we had one
    removeFromPreviousInventry(item);

    if (slot == null) {
        slot = findAcceptableSlot(bag, item);
    }

    if (bag.containsKey(slot)) {
        existingItem = bag.get(slot);
    }
    if (existingItem != null && existingItem.isStackable(item)) {
        existingItem.addToStack(item);
        existingItem = null;
    } else {
        item.setSlot(slot);
        item.setInventory(this);
        item.setInventoryBag(bagType);
        bag.put(slot, item);
        if (existingItem != null) {
            existingItem.setInventory(null);
            onItemRemove(existingItem, bagType);
        }
    }
    onItemAdd(item, bagType);
    return existingItem;
}
项目:fabulae    文件:Inventory.java   
private int findAcceptableSlot(IntMap<InventoryItem> bag, InventoryItem item) {
    int slot = 0;
    // first check for occupied slot that's stackable with the item
    for (Entry<InventoryItem> entry: bag.entries()) {
        if (entry.value.isStackable(item)) {
            return entry.key;
        }
    }
    // then search for an embty slot
    while (bag.containsKey(slot)) {
        ++slot;
    }
    return slot;
}
项目:fabulae    文件:Inventory.java   
/**
 * Removes all items from all bags of this inventory.
 */
public void clear() {
    for (ObjectMap.Entry<BagType, IntMap<InventoryItem>> bag : bags.entries()) {
        Iterator<Entry<InventoryItem>> iterator = bag.value.iterator();
        while (iterator.hasNext()) {
            InventoryItem item = iterator.next().value;
            item.setInventory(null);
            onItemRemove(item, bag.key);
            iterator.remove();
        }
    }
}