Search in sources :

Example 1 with ArchiveEntry

use of org.apollo.cache.archive.ArchiveEntry in project apollo by apollo-rsps.

the class MapIndexDecoder method decode.

/**
 * Decodes {@link MapIndex}s from the specified {@link IndexedFileSystem}.
 *
 * @return A {@link Map} of packed coordinates to their MapDefinitions.
 * @throws IOException If there is an error reading or decoding the Archive.
 */
public Map<Integer, MapIndex> decode() throws IOException {
    Archive archive = fs.getArchive(0, VERSIONS_ARCHIVE_FILE_ID);
    ArchiveEntry entry = archive.getEntry("map_index");
    Map<Integer, MapIndex> definitions = new HashMap<>();
    ByteBuffer buffer = entry.getBuffer();
    int count = buffer.capacity() / (3 * Short.BYTES + Byte.BYTES);
    for (int times = 0; times < count; times++) {
        int id = buffer.getShort() & 0xFFFF;
        int terrain = buffer.getShort() & 0xFFFF;
        int objects = buffer.getShort() & 0xFFFF;
        boolean members = buffer.get() == 1;
        definitions.put(id, new MapIndex(id, terrain, objects, members));
    }
    return definitions;
}
Also used : Archive(org.apollo.cache.archive.Archive) HashMap(java.util.HashMap) ArchiveEntry(org.apollo.cache.archive.ArchiveEntry) MapIndex(org.apollo.cache.map.MapIndex) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Archive (org.apollo.cache.archive.Archive)1 ArchiveEntry (org.apollo.cache.archive.ArchiveEntry)1 MapIndex (org.apollo.cache.map.MapIndex)1