Example usage for com.badlogic.gdx.utils LongMap LongMap

List of usage examples for com.badlogic.gdx.utils LongMap LongMap

Introduction

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

Prototype

public LongMap() 

Source Link

Document

Creates a new map with an initial capacity of 32 and a load factor of 0.8.

Usage

From source file:com.mob.dao.loaders.BodyLoader.java

License:Open Source License

@Override
public LongMap<Body> load(DataInputStream file) throws IOException {
    LongMap<Body> bodys = new LongMap<Body>();
    int numBodys;

    file.skipBytes(GAME_FILE_HEADER_SIZE);
    numBodys = Util.leShort(file.readShort());

    for (int i = 1; i <= numBodys; i++) {
        int grhArray[] = new int[4], headOffSetX, headOffSetY;

        grhArray[Heading.NORTH.toInt()] = Util.leShort(file.readShort());
        grhArray[Heading.EAST.toInt()] = Util.leShort(file.readShort());
        grhArray[Heading.SOUTH.toInt()] = Util.leShort(file.readShort());
        grhArray[Heading.WEST.toInt()] = Util.leShort(file.readShort());

        headOffSetX = Util.leShort(file.readShort());
        headOffSetY = Util.leShort(file.readShort());

        bodys.put(i, new Body(grhArray, headOffSetX, headOffSetY));
    }//from   w  ww  .j a va  2 s  .  co  m

    return bodys;
}

From source file:com.mob.dao.loaders.FxLoader.java

License:Open Source License

@Override
public LongMap<Fx> load(DataInputStream file) throws IOException {
    LongMap<Fx> fxs = new LongMap<Fx>();
    int numFxs;/*from  w w  w  .ja va 2s.com*/

    file.skipBytes(GAME_FILE_HEADER_SIZE);
    numFxs = Util.leShort(file.readShort());

    for (int i = 1; i <= numFxs; i++) {
        int offsetX, offsetY, fxIndex;

        fxIndex = Util.leShort(file.readShort());
        offsetX = Util.leShort(file.readShort());
        offsetY = Util.leShort(file.readShort());

        fxs.put(i, new Fx(fxIndex, offsetX, offsetY));
    }

    return fxs;
}

From source file:com.mob.dao.loaders.GraphicLoader.java

License:Open Source License

@Override
public LongMap<Graphic> load(DataInputStream file) throws IOException {
    int grh = 0;// w w w.  j a v a  2 s  .  c  o m
    LongMap<Graphic> inits = new LongMap<Graphic>();

    file.skipBytes(4);
    int numGraphics = Util.leInt(file.readInt());
    //inits.ensureCapacity(numGraphics);

    try {
        do {
            int fileNum = 0, sX = 0, sY = 0, numFrames, pixelWidth, pixelHeight, frames[] = new int[0];
            float speed = 0.0f, tileWidth, tileHeight;

            grh = Util.leInt(file.readInt());
            numFrames = Util.leShort(file.readShort());

            if (numFrames > 1) {
                frames = new int[numFrames];
                for (int j = 0; j < numFrames; j++) {
                    frames[j] = Util.leInt(file.readInt());
                    if (frames[j] <= 0)
                        throw new IOException("frames[]: " + frames[j]);
                }

                // Hardcodeamos speed (Java no lee single floating points de VB)
                file.skipBytes(4);
                speed = (numFrames * 1000) / 60;
                if (speed <= 0)
                    throw new IOException("speed (numFrames > 1)");

                pixelWidth = inits.get(frames[0]).getPixelWidth();
                if (pixelWidth <= 0)
                    throw new IOException("pixelWidth (numFrames > 1)");

                pixelHeight = inits.get(frames[0]).getPixelHeight();
                if (pixelHeight <= 0)
                    throw new IOException("pixelHeight (numFrames > 1)");

                tileWidth = inits.get(frames[0]).getTileWidth();
                if (tileWidth <= 0)
                    throw new IOException("tileWidth (numFrames > 1)");
                tileHeight = inits.get(frames[0]).getTileHeight();
                if (tileHeight <= 0)
                    throw new IOException("tileHeight (numFrames > 1)");
            } else {
                // Read normal GRH
                fileNum = Util.leInt(file.readInt());

                if (fileNum <= 0)
                    throw new IOException("fileNum");

                sX = Util.leShort(file.readShort());
                if (sX < 0)
                    throw new IOException("sX (numFrames < 1)");

                sY = Util.leShort(file.readShort());
                if (sY < 0)
                    throw new IOException("sY (numFrames < 1)");

                pixelWidth = Util.leShort(file.readShort());
                if (pixelWidth <= 0)
                    throw new IOException("pixelWidth (numFrames < 1)");

                pixelHeight = Util.leShort(file.readShort());
                if (pixelHeight <= 0)
                    throw new IOException("pixelHeight (numFrames < 1)");

                tileWidth = (float) pixelWidth / Tile.TILE_PIXEL_WIDTH;
                tileHeight = (float) pixelHeight / Tile.TILE_PIXEL_HEIGHT;
            }

            inits.put(grh, new Graphic(sX, sY, fileNum, pixelWidth, pixelHeight, tileWidth, tileHeight, frames,
                    speed));
        } while (grh > 0);
    } catch (EOFException ex) {
        return inits;
    }

    throw new RuntimeException("Unable to read graphics assets file");
}

From source file:com.mob.dao.loaders.HeadLoader.java

License:Open Source License

@Override
public LongMap<Head> load(DataInputStream file) throws IOException {
    LongMap<Head> heads = new LongMap<Head>();
    int numHeads;

    file.skipBytes(GAME_FILE_HEADER_SIZE);
    numHeads = Util.leShort(file.readShort());

    for (int i = 1; i <= numHeads; i++) {
        int headIndex[] = new int[4];

        headIndex[Heading.NORTH.toInt()] = Util.leShort(file.readShort());
        headIndex[Heading.EAST.toInt()] = Util.leShort(file.readShort());
        headIndex[Heading.SOUTH.toInt()] = Util.leShort(file.readShort());
        headIndex[Heading.WEST.toInt()] = Util.leShort(file.readShort());

        heads.put(i, new Head(headIndex));
    }/*from   www . j a  v a2 s . c o m*/

    return heads;

}

From source file:com.mob.dao.loaders.HelmetLoader.java

License:Open Source License

@Override
public LongMap<Helmet> load(DataInputStream file) throws IOException {
    LongMap<Helmet> helmets = new LongMap<Helmet>();
    int numHelmets;

    file.skipBytes(GAME_FILE_HEADER_SIZE);
    numHelmets = Util.leShort(file.readShort());

    for (int i = 1; i <= numHelmets; i++) {
        int helmetIndex[] = new int[4];

        helmetIndex[Heading.NORTH.toInt()] = Util.leShort(file.readShort());
        helmetIndex[Heading.EAST.toInt()] = Util.leShort(file.readShort());
        helmetIndex[Heading.SOUTH.toInt()] = Util.leShort(file.readShort());
        helmetIndex[Heading.WEST.toInt()] = Util.leShort(file.readShort());

        helmets.put(i, new Helmet(helmetIndex));
    }/*  ww w  . jav  a2 s  .c om*/
    return helmets;

}

From source file:com.mob.dao.loaders.ShieldLoader.java

License:Open Source License

@Override
public LongMap<Shield> load(DataInputStream file) throws IOException {
    LongMap<Shield> shields = new LongMap<Shield>();
    Ini iniFile = new Ini();
    Config c = new Config();
    c.setLowerCaseSection(true);//from w  w  w. j  a  va  2 s  .c  o  m
    iniFile.setConfig(c);

    try {
        iniFile.load(file);

        int numShields = Integer.parseInt(iniFile.get("init", "NumEscudos"));

        for (int i = 1; i <= numShields; i++) {
            int[] shieldIndex = new int[4];

            if (iniFile.get("esc" + String.valueOf(i), "Dir1") == null) {
                shieldIndex[Heading.NORTH.toInt()] = 0;
                shieldIndex[Heading.EAST.toInt()] = 0;
                shieldIndex[Heading.SOUTH.toInt()] = 0;
                shieldIndex[Heading.WEST.toInt()] = 0;
                shields.put(i, new Shield(shieldIndex));
                continue;
            }

            shieldIndex[Heading.NORTH.toInt()] = Integer
                    .parseInt(iniFile.get("esc" + String.valueOf(i), "Dir1"));
            shieldIndex[Heading.EAST.toInt()] = Integer
                    .parseInt(iniFile.get("esc" + String.valueOf(i), "Dir2"));
            shieldIndex[Heading.SOUTH.toInt()] = Integer
                    .parseInt(iniFile.get("esc" + String.valueOf(i), "Dir3"));
            shieldIndex[Heading.WEST.toInt()] = Integer
                    .parseInt(iniFile.get("esc" + String.valueOf(i), "Dir4"));

            shields.put(i, new Shield(shieldIndex));
        }

        return shields;
    } catch (InvalidFileFormatException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.mob.dao.loaders.WeaponLoader.java

License:Open Source License

@Override
public LongMap<Weapon> load(DataInputStream file) {
    LongMap<Weapon> weapons = new LongMap<Weapon>();
    Ini iniFile = new Ini();
    Config c = new Config();
    c.setLowerCaseSection(true);//from   w w w.  jav a2 s. c  o  m
    iniFile.setConfig(c);

    try {
        iniFile.load(file);

        int numArmas = Integer.parseInt(iniFile.get("init", "NumArmas"));

        for (int i = 1; i <= numArmas; i++) {
            int[] weaponIndex = new int[4];

            if (iniFile.get("arma" + String.valueOf(i), "Dir1") == null) {
                weaponIndex[Heading.NORTH.toInt()] = 0;
                weaponIndex[Heading.EAST.toInt()] = 0;
                weaponIndex[Heading.SOUTH.toInt()] = 0;
                weaponIndex[Heading.WEST.toInt()] = 0;
                weapons.put(i, new Weapon(weaponIndex));
                continue;
            }

            weaponIndex[Heading.NORTH.toInt()] = Integer
                    .parseInt(iniFile.get("arma" + String.valueOf(i), "Dir1"));
            weaponIndex[Heading.EAST.toInt()] = Integer
                    .parseInt(iniFile.get("arma" + String.valueOf(i), "Dir2"));
            weaponIndex[Heading.SOUTH.toInt()] = Integer
                    .parseInt(iniFile.get("arma" + String.valueOf(i), "Dir3"));
            weaponIndex[Heading.WEST.toInt()] = Integer
                    .parseInt(iniFile.get("arma" + String.valueOf(i), "Dir4"));

            weapons.put(i, new Weapon(weaponIndex));
        }

        return weapons;
    } catch (InvalidFileFormatException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.mygdx.game.utilities.Engine.java

License:Apache License

public Engine() {
    entities = new Array<Entity>(false, 16);
    entitiesById = new LongMap<Entity>();
}

From source file:de.longri.cachebox3.sqlite.dao.CacheListDAO.java

License:Open Source License

public CacheList ReadCacheList(CacheList cacheList, String join, String where, boolean withDescription,
        boolean fullDetails, boolean loadAllWaypoints) {
    if (cacheList == null)
        return null;

    // Clear List before read
    cacheList.clear();//ww  w  .j a  v a2s . c  o  m
    boolean error = false;

    log.trace("ReadCacheList 1.Waypoints");
    LongMap<CB_List<Waypoint>> waypoints = new LongMap<CB_List<Waypoint>>();

    // zuerst alle Waypoints einlesen
    CB_List<Waypoint> wpList = new CB_List<Waypoint>();
    long aktCacheID = -1;

    String sql = fullDetails ? WaypointDAO.SQL_WP_FULL : WaypointDAO.SQL_WP;
    if (!((fullDetails || loadAllWaypoints))) {
        // when CacheList should be loaded without full details and without all Waypoints
        // do not load all waypoints from db!
        sql += " WHERE IsStart=\"true\" or Type=" + CacheTypes.Final.ordinal(); // StartWaypoint or CacheTypes.Final
    }
    sql += " ORDER BY 'CacheId'";
    SQLiteGdxDatabaseCursor reader = Database.Data.rawQuery(sql, null);
    if (reader == null)
        return cacheList;

    reader.moveToFirst();
    while (!reader.isAfterLast()) {
        WaypointDAO waypointDAO = new WaypointDAO();
        Waypoint wp = waypointDAO.getWaypoint(reader, fullDetails);
        if (!(fullDetails || loadAllWaypoints)) {
            // wenn keine FullDetails geladen werden sollen dann sollen nur die Finals und Start-Waypoints geladen werden
            if (!(wp.IsStart || wp.Type == CacheTypes.Final)) {
                reader.moveToNext();
                continue;
            }
        }
        if (wp.CacheId != aktCacheID) {
            aktCacheID = wp.CacheId;
            wpList = new CB_List<Waypoint>();
            waypoints.put(aktCacheID, wpList);
        }
        wpList.add(wp);
        reader.moveToNext();

    }
    reader.close();
    log.debug(wpList.size() + " Waypoints readed!");
    log.debug("ReadCacheList 2.Caches");
    try {
        if (fullDetails) {
            sql = SQL.SQL_GET_CACHE + ", " + SQL.SQL_DETAILS;
            if (withDescription) {
                // load Cache with Description, Solver, Notes for Transfering Data from Server to ACB
                sql += "," + SQL.SQL_GET_DETAIL_WITH_DESCRIPTION;
            }
        } else {
            sql = SQL.SQL_GET_CACHE;

        }

        sql += " FROM `Caches` AS `c` " + join + " " + ((where.length() > 0) ? "WHERE " + where : where);
        reader = Database.Data.rawQuery(sql, null);

    } catch (Exception e) {
        log.error("CacheList.LoadCaches() sql+ \n" + sql, e);
        error = true;
    }

    if (!error) {
        reader.moveToFirst();

        CacheDAO cacheDAO = new CacheDAO();

        while (!reader.isAfterLast()) {
            Cache cache = cacheDAO.ReadFromCursor(reader, fullDetails, withDescription);
            boolean doAdd = true;
            if (FilterInstances.hasCorrectedCoordinates != 0) {
                if (waypoints.containsKey(cache.Id)) {
                    CB_List<Waypoint> tmpwaypoints = waypoints.get(cache.Id);
                    for (int i = 0, n = tmpwaypoints.size(); i < n; i++) {
                        cache.waypoints.add(tmpwaypoints.get(i));
                    }
                }
                boolean hasCorrectedCoordinates = cache.CorrectedCoordiantesOrMysterySolved();
                if (FilterInstances.hasCorrectedCoordinates < 0) {
                    // show only those without corrected ones
                    if (hasCorrectedCoordinates)
                        doAdd = false;
                } else if (FilterInstances.hasCorrectedCoordinates > 0) {
                    // only those with corrected ones
                    if (!hasCorrectedCoordinates)
                        doAdd = false;
                }
            }
            if (doAdd) {
                cacheList.add(cache);
                cache.waypoints.clear();
                if (waypoints.containsKey(cache.Id)) {
                    CB_List<Waypoint> tmpwaypoints = waypoints.get(cache.Id);

                    for (int i = 0, n = tmpwaypoints.size(); i < n; i++) {
                        cache.waypoints.add(tmpwaypoints.get(i));
                    }

                    waypoints.remove(cache.Id);
                }
            }
            // ++Global.CacheCount;
            reader.moveToNext();

        }
        reader.close();
    } else {
        log.error("Corrupt database try cache by cache");

        // get all id's
        reader = Database.Data.rawQuery(SQL.SQL_ALL_CACHE_IDS, null);
        reader.moveToFirst();
        ArrayList<Long> idList = new ArrayList<Long>(reader.getCount());

        while (!reader.isAfterLast()) {
            idList.add(reader.getLong(0));
            reader.moveToNext();
        }

        CacheDAO cacheDAO = new CacheDAO();

        for (Long id : idList) {
            Cache cache = null;
            try {
                cache = cacheDAO.getFromDbByCacheId(id);
            } catch (Exception e) {
                log.error("Can't read Cache (id:" + id + ") from database.");
                try {
                    Database.Data.delete("Caches", "id=" + id, null);
                } catch (Exception e1) {
                    log.error("Can't delete this Cache. Skip it!");
                }
                continue;
            }

            boolean doAdd = true;
            if (FilterInstances.hasCorrectedCoordinates != 0) {
                if (waypoints.containsKey(cache.Id)) {
                    CB_List<Waypoint> tmpwaypoints = waypoints.get(cache.Id);
                    for (int i = 0, n = tmpwaypoints.size(); i < n; i++) {
                        cache.waypoints.add(tmpwaypoints.get(i));
                    }
                }
                boolean hasCorrectedCoordinates = cache.CorrectedCoordiantesOrMysterySolved();
                if (FilterInstances.hasCorrectedCoordinates < 0) {
                    // show only those without corrected ones
                    if (hasCorrectedCoordinates)
                        doAdd = false;
                } else if (FilterInstances.hasCorrectedCoordinates > 0) {
                    // only those with corrected ones
                    if (!hasCorrectedCoordinates)
                        doAdd = false;
                }
            }
            if (doAdd) {
                cacheList.add(cache);
                cache.waypoints.clear();
                if (waypoints.containsKey(cache.Id)) {
                    CB_List<Waypoint> tmpwaypoints = waypoints.get(cache.Id);

                    for (int i = 0, n = tmpwaypoints.size(); i < n; i++) {
                        cache.waypoints.add(tmpwaypoints.get(i));
                    }

                    waypoints.remove(cache.Id);
                }
            }
        }
    }
    // clear other never used WP`s from Mem
    waypoints.clear();
    waypoints = null;

    // do it manual (or automated after fix), got hanging app on startup
    // log.debug( "ReadCacheList 3.Sorting");
    try

    {
        // Collections.sort(cacheList);
    } catch (

    Exception e)

    {
        // log.error( "CacheListDAO.ReadCacheList()", "Sort ERROR", e);
    }
    // log.debug( "ReadCacheList 4. ready");
    return cacheList;

}

From source file:me.scarlet.undertailor.audio.SoundFactory.java

License:Open Source License

public SoundFactory(String audioName, AudioManager manager, File soundFile)
        throws UnsupportedAudioFileException {
    this.soundData = new LongMap<>();
    this.audioName = audioName;
    this.soundFile = soundFile;
    this.manager = manager;

    try {//from  w  w  w .  j a  v a 2  s .c  om
        this.loadDisposable().get().dispose();
    } catch (GdxRuntimeException e) {
        UnsupportedAudioFileException thrown = new UnsupportedAudioFileException("Could not load sound file at "
                + this.soundFile.getAbsolutePath() + " (unsupported type, ogg/mp3/wav only)");
        thrown.initCause(e);
        throw thrown;
    } catch (Exception e) { // from compfuture.get(); can't happen
    }
}