use of org.apollo.cache.map.MapObject 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.MapObject in project apollo by apollo-rsps.
the class MapObjectsDecoder method decode.
/**
* Decodes the data in the {@code buffer} to a list of {@link MapObject}s.
*
* @return A list of decoded {@link MapObject}s.
*/
public List<MapObject> decode() {
List<MapObject> objects = new ArrayList<>();
int id = -1;
int idOffset = BufferUtil.readSmart(buffer);
while (idOffset != 0) {
id += idOffset;
int packed = 0;
int positionOffset = BufferUtil.readSmart(buffer);
while (positionOffset != 0) {
packed += positionOffset - 1;
int attributes = buffer.get() & 0xFF;
int type = attributes >> 2;
int orientation = attributes & 0x3;
objects.add(new MapObject(id, packed, type, orientation));
positionOffset = BufferUtil.readSmart(buffer);
}
idOffset = BufferUtil.readSmart(buffer);
}
return objects;
}
use of org.apollo.cache.map.MapObject in project apollo by apollo-rsps.
the class CollisionManagerTests method createCollisionManager.
/**
* Sets up dependencies for and creates a stub {@link CollisionManager}, then builds the collision matrices
* using the {@code objects} given.
*
* @param objects The objects to build collision matrices from.
* @return A new {@link CollisionManager} with a valid {@link RegionRepository} and every {@link CollisionMatrix}
* built.
*/
private static CollisionManager createCollisionManager(MapObject... objects) {
World world = new World();
RegionRepository regions = world.getRegionRepository();
CollisionManager collisionManager = world.getCollisionManager();
for (MapObject object : objects) {
// treat local coordinates as absolute for simplicity
int x = object.getLocalX(), y = object.getLocalY();
int height = object.getHeight();
Position position = new Position(x, y, height);
Region region = regions.fromPosition(position);
region.addEntity(new StaticGameObject(world, object.getId(), position, object.getType(), object.getOrientation()), false);
}
collisionManager.build(false);
return collisionManager;
}
Aggregations