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);
}
}
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;
}
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);
}
}
Aggregations