Search in sources :

Example 1 with MapIndex

use of org.apollo.cache.map.MapIndex in project apollo by apollo-rsps.

the class WorldObjectsDecoder method run.

/**
 * Decode the {@code MapObject}s from the cache and register them with the world.
 */
@Override
public void run() {
    Map<Integer, MapIndex> mapIndices = MapIndex.getIndices();
    try {
        for (MapIndex index : mapIndices.values()) {
            MapObjectsDecoder decoder = MapObjectsDecoder.create(fs, index);
            List<MapObject> objects = decoder.decode();
            int mapX = index.getX(), mapY = index.getY();
            for (MapObject object : objects) {
                Position position = new Position(mapX + object.getLocalX(), mapY + object.getLocalY(), object.getHeight());
                StaticGameObject gameObject = new StaticGameObject(world, object.getId(), position, object.getType(), object.getOrientation());
                regionRepository.fromPosition(position).addEntity(gameObject, false);
            }
        }
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}
Also used : Position(org.apollo.game.model.Position) MapObjectsDecoder(org.apollo.cache.map.MapObjectsDecoder) UncheckedIOException(java.io.UncheckedIOException) MapIndex(org.apollo.cache.map.MapIndex) StaticGameObject(org.apollo.game.model.entity.obj.StaticGameObject) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) MapObject(org.apollo.cache.map.MapObject)

Example 2 with MapIndex

use of org.apollo.cache.map.MapIndex 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)

Example 3 with MapIndex

use of org.apollo.cache.map.MapIndex in project apollo by apollo-rsps.

the class WorldMapDecoder method run.

/**
 * Decode all {@link MapFile}s and notify the {@link CollisionManager} of any tiles that are
 * flagged as blocked or on a bridge.
 */
@Override
public void run() {
    Map<Integer, MapIndex> mapIndices = MapIndex.getIndices();
    try {
        for (MapIndex index : mapIndices.values()) {
            MapFileDecoder decoder = MapFileDecoder.create(fs, index);
            MapFile mapFile = decoder.decode();
            MapPlane[] mapPlanes = mapFile.getPlanes();
            int mapX = index.getX(), mapY = index.getY();
            for (MapPlane plane : mapPlanes) {
                markTiles(mapX, mapY, plane);
            }
        }
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}
Also used : MapFileDecoder(org.apollo.cache.map.MapFileDecoder) MapFile(org.apollo.cache.map.MapFile) UncheckedIOException(java.io.UncheckedIOException) MapIndex(org.apollo.cache.map.MapIndex) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) MapPlane(org.apollo.cache.map.MapPlane)

Aggregations

MapIndex (org.apollo.cache.map.MapIndex)3 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Archive (org.apollo.cache.archive.Archive)1 ArchiveEntry (org.apollo.cache.archive.ArchiveEntry)1 MapFile (org.apollo.cache.map.MapFile)1 MapFileDecoder (org.apollo.cache.map.MapFileDecoder)1 MapObject (org.apollo.cache.map.MapObject)1 MapObjectsDecoder (org.apollo.cache.map.MapObjectsDecoder)1 MapPlane (org.apollo.cache.map.MapPlane)1 Position (org.apollo.game.model.Position)1 StaticGameObject (org.apollo.game.model.entity.obj.StaticGameObject)1