Example usage for com.badlogic.gdx.utils Array sort

List of usage examples for com.badlogic.gdx.utils Array sort

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils Array sort.

Prototype

public void sort(Comparator<? super T> comparator) 

Source Link

Document

Sorts the array.

Usage

From source file:CB_UI_Base.CB_Texturepacker.MaxRectsPacker.java

License:Apache License

public Array<Page> pack(Array<Rect_Base> inputRects) {
    for (int i = 0, nn = inputRects.size; i < nn; i++) {
        Rect_Base rect = inputRects.get(i);
        rect.width += settings.paddingX;
        rect.height += settings.paddingY;
    }//from  ww w .  ja  v  a  2 s .  c o  m

    if (settings.fast) {
        if (settings.rotation) {
            // Sort by longest side if rotation is enabled.
            inputRects.sort(new Comparator<Rect_Base>() {
                public int compare(Rect_Base o1, Rect_Base o2) {
                    int n1 = o1.width > o1.height ? o1.width : o1.height;
                    int n2 = o2.width > o2.height ? o2.width : o2.height;
                    return n2 - n1;
                }
            });
        } else {
            // Sort only by width (largest to smallest) if rotation is disabled.
            inputRects.sort(new Comparator<Rect_Base>() {
                public int compare(Rect_Base o1, Rect_Base o2) {
                    return o2.width - o1.width;
                }
            });
        }
    }

    Array<Page> pages = new Array<Page>();
    while (inputRects.size > 0) {
        Page result = packPage(inputRects);
        pages.add(result);
        inputRects = result.remainingRects;
    }
    return pages;
}

From source file:com.agateau.pixelwheels.screens.ChampionshipFinishedScreen.java

License:Open Source License

private Array<GameInfo.Entrant> getSortedEntrants() {
    Array<GameInfo.Entrant> entrants = mGameInfo.getEntrants();
    entrants.sort(new Comparator<GameInfo.Entrant>() {
        @Override//  w  w  w  .ja  v  a2 s.  c om
        public int compare(GameInfo.Entrant e1, GameInfo.Entrant e2) {
            int cmp = -Integer.compare(e1.getScore(), e2.getScore());
            if (cmp != 0) {
                return cmp;
            }
            // If it's a tie, the fastest gets the best place
            return Float.compare(e1.getRaceTime(), e2.getRaceTime());
        }
    });
    return entrants;
}

From source file:com.cyphercove.doublehelix.ParticleGroupStrategy.java

License:Apache License

@Override
public void beforeGroup(int group, Array<Decal> contents) {
    Gdx.gl.glEnable(GL20.GL_BLEND);//from   ww  w  .  java 2s . c  o  m
    Gdx.gl.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_COLOR);
    contents.sort(cameraSorter);

    tmpColor.set(Settings.backgroundColor).lerp(Color.WHITE, WHITENESS);

    shader.begin();
    shader.setUniformMatrix("u_projTrans", camera.combined);
    shader.setUniformi("u_texture", 0);
    shader.setUniformf("u_baseColor", tmpColor);
}

From source file:com.cyphercove.doublehelix.ParticleGroupStrategy.java

License:Apache License

@Override
public void beforeBillboardGroup(int group, Array<BillboardDecal> contents) {
    Gdx.gl.glEnable(GL20.GL_BLEND);/*from   w ww. j ava2  s  . c  o m*/
    Gdx.gl.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_COLOR);
    contents.sort(billboardCameraSorter);

    tmpColor.set(Settings.backgroundColor).lerp(Color.WHITE, WHITENESS);

    billboardShader.begin();
    billboardShader.setUniformMatrix("u_projTrans", camera.combined);
    billboardShader.setUniformi("u_texture", 0);
    billboardShader.setUniformf("u_baseColor", tmpColor);
}

From source file:com.github.antag99.retinazer.Engine.java

License:Open Source License

/**
 * @see #Engine(EngineConfig)/*from  www  .  j  a v a2 s  .  c  o  m*/
 * @param initialize if {@link #initialize()} should be called automatically, if false, call it manually before doing anything else with the engine
 */
public Engine(EngineConfig config, boolean initialize) {
    componentManager = new ComponentManager(this, config);
    familyManager = new FamilyManager(this);
    wireManager = new WireManager(this, config);

    Array<EntitySystemRegistration> systemRegistrations = new Array<>();
    for (EntitySystemRegistration system : config.systems) {
        systemRegistrations.add(system);
    }

    systemRegistrations.sort(new Comparator<EntitySystemRegistration>() {
        @Override
        public int compare(EntitySystemRegistration o1, EntitySystemRegistration o2) {
            return o1.order.ordinal() - o2.order.ordinal();
        }
    });

    EntitySystem[] systems = new EntitySystem[systemRegistrations.size];
    ObjectMap<Class<? extends EntitySystem>, EntitySystem> systemsByType = new ObjectMap<>();

    for (int i = 0, n = systemRegistrations.size; i < n; i++) {
        systems[i] = systemRegistrations.get(i).system;
        systemsByType.put(systems[i].getClass(), systems[i]);
    }

    this.systems = systems;
    this.systemsByType = systemsByType;

    for (EntitySystem system : systems)
        wire(system);

    if (initialize)
        initialize();
}

From source file:com.github.fauu.helix.graphics.HelixRenderableSorter.java

License:Open Source License

@Override
public void sort(Camera camera, Array<Renderable> renderables) {
    this.camera = camera;

    renderables.sort(this);
}

From source file:com.kotcrab.vis.editor.module.project.FileAccessModule.java

License:Apache License

public Array<FileHandle> getSceneFiles() {
    Array<FileHandle> files = FileUtils.listRecursive(getAssetsFolder());

    Iterator<FileHandle> it = files.iterator();

    while (it.hasNext())
        if (it.next().extension().equals("scene") == false)
            it.remove();//  ww w  . ja  v a 2 s. c o  m

    files.sort((o1, o2) -> o1.path().toLowerCase().compareTo(o2.path().toLowerCase()));

    return files;
}

From source file:com.kotcrab.vis.editor.module.scene.system.ZIndexManipulator.java

License:Apache License

private void moveEntity(EntityProxy entity, Array<EntityProxy> overlappingEntities, boolean up) {
    int targetZIndex = entity.getZIndex();

    overlappingEntities.sort((o1, o2) -> (int) Math.signum(o1.getZIndex() - o2.getZIndex()) * (up ? 1 : -1));

    for (EntityProxy proxy : overlappingEntities) {
        if (up) {
            if (targetZIndex <= proxy.getZIndex()) {
                targetZIndex = proxy.getZIndex() + 1;
                break;
            }//w w  w . ja  v  a  2 s .  com
        } else {
            if (targetZIndex >= proxy.getZIndex()) {
                targetZIndex = proxy.getZIndex() - 1;
                break;
            }
        }
    }

    if (targetZIndex != entity.getZIndex()) {
        actionGroup
                .execute(new ChangeZIndexAction(renderBatchingSystem, entityManipulator, entity, targetZIndex));
    }
}

From source file:com.kotcrab.vis.ui.widget.file.FileUtils.java

License:Apache License

/**
 * Sorts file list, using this rules: directories first, sorted using provided comparator, then files sorted using provided comparator.
 * @param files list to sort//from ww  w .j  a  v  a  2s. co  m
 * @param comparator comparator used to sort files list
 * @param descending if true then sorted list will be in reversed order
 * @return sorted file list
 */
public static Array<FileHandle> sortFiles(FileHandle[] files, Comparator<FileHandle> comparator,
        boolean descending) {
    Array<FileHandle> directoriesList = new Array<FileHandle>();
    Array<FileHandle> filesList = new Array<FileHandle>();

    for (FileHandle f : files) {
        if (f.isDirectory()) {
            directoriesList.add(f);
        } else {
            filesList.add(f);
        }
    }

    directoriesList.sort(comparator);
    filesList.sort(comparator);

    if (descending) {
        directoriesList.reverse();
        filesList.reverse();
    }

    directoriesList.addAll(filesList); // combine lists
    return directoriesList;
}

From source file:com.pastew.autogearbox.handlers.Box2DSprite.java

License:Apache License

/** draws all the {@link Box2DSprite Box2DSprites} on the {@link Body} or {@link Fixture} that hold them in their user data in the given {@link World} */
public static void draw(Batch batch, World world, boolean sortByZ) {
    @SuppressWarnings("unchecked")
    Array<Body> tmpBodies = Pools.obtain(Array.class);
    world.getBodies(tmpBodies);//from   ww w .  j a  va2s .co  m

    if (sortByZ) {
        @SuppressWarnings("unchecked")
        ObjectMap<Box2DSprite, Object> tmpZMap = Pools.obtain(ObjectMap.class);
        tmpZMap.clear();
        for (Body body : tmpBodies) {
            Box2DSprite tmpBox2DSprite;
            if ((tmpBox2DSprite = userDataAccessor.apply(body.getUserData())) != null)
                tmpZMap.put(tmpBox2DSprite, body);
            for (Fixture fixture : body.getFixtureList())
                if ((tmpBox2DSprite = userDataAccessor.apply(fixture.getUserData())) != null)
                    tmpZMap.put(tmpBox2DSprite, fixture);
        }

        @SuppressWarnings("unchecked")
        Array<Box2DSprite> tmpKeys = Pools.obtain(Array.class);
        Iterator<Box2DSprite> keys = tmpZMap.keys();
        while (keys.hasNext())
            tmpKeys.add(keys.next());
        tmpKeys.sort(zComparator);
        for (Box2DSprite key : tmpKeys) {
            Object value = tmpZMap.get(key);
            if (value instanceof Body)
                key.draw(batch, (Body) value);
            else
                key.draw(batch, (Fixture) value);
        }

        tmpKeys.clear();
        tmpZMap.clear();
        Pools.free(tmpKeys);
        Pools.free(tmpZMap);
    } else
        for (Body body : tmpBodies) {
            Box2DSprite tmpBox2DSprite;
            if ((tmpBox2DSprite = userDataAccessor.apply(body.getUserData())) != null)
                tmpBox2DSprite.draw(batch, body);
            for (Fixture fixture : body.getFixtureList())
                if ((tmpBox2DSprite = userDataAccessor.apply(fixture.getUserData())) != null)
                    tmpBox2DSprite.draw(batch, fixture);
        }

    tmpBodies.clear();
    Pools.free(tmpBodies);
}