RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.fs.cache.decoder.RegionDecoder Class Reference

A class which parses static object definitions, which include tool.mapviewer tiles and landscapes. More...

Inheritance diagram for com.runehive.fs.cache.decoder.RegionDecoder:
Collaboration diagram for com.runehive.fs.cache.decoder.RegionDecoder:

Public Member Functions

void load (final Cache mapIndex, final RegionDefinition def)
 RegionDecoder (FileSystem fs)
 Creates the ObjectDefinitionDecoder.
void run ()

Private Member Functions

void parseGameObject (Region region, ByteBuffer buf, int x, int y, IntSet downHeights)
 Parses a GameObject on the specified coordinates.
void parseTerrain (Region region, ByteBuffer mapBuffer, IntSet downHeights)
 Loads all of the tool.mapviewer indexes entries and decodes each.

Private Attributes

final AtomicInteger decoded = new AtomicInteger()
 Amount of regions correctly decoded.
final AtomicInteger errors = new AtomicInteger()
 Amount of regions incorrectly decoded.
final FileSystem fs
 The FileSystem.

Static Private Attributes

static final Logger LOGGER = LogManager.getLogger(RegionDecoder.class)

Detailed Description

A class which parses static object definitions, which include tool.mapviewer tiles and landscapes.

Author
Ryley Kimmel ryley.nosp@m..kim.nosp@m.mel@l.nosp@m.ive..nosp@m.com
Artem Batutin artem.nosp@m.batu.nosp@m.tin@g.nosp@m.mail.nosp@m..com

Definition at line 29 of file RegionDecoder.java.

Constructor & Destructor Documentation

◆ RegionDecoder()

com.runehive.fs.cache.decoder.RegionDecoder.RegionDecoder ( FileSystem fs)

Creates the ObjectDefinitionDecoder.

Parameters
fsThe FileSystem.

Definition at line 53 of file RegionDecoder.java.

53 {
54 this.fs = fs;
55 }

References fs.

Member Function Documentation

◆ load()

void com.runehive.fs.cache.decoder.RegionDecoder.load ( final Cache mapIndex,
final RegionDefinition def )

Definition at line 67 of file RegionDecoder.java.

67 {
68 final int hash = def.getHash();
69 final int x = (hash >> 8 & 0xFF) << 6;
70 final int y = (hash & 0xFF) << 6;
71 try {
72 final Region region = World.getRegions().getRegion(x, y);
73
74 ByteBuffer terrainData = mapIndex.get(def.getTerrainFile());
75 if (terrainData == null) {
76 errors.getAndIncrement();
77 return;
78 }
79 ByteBuffer terrainBuffer = ByteBuffer.wrap(CompressionUtil.gunzip(terrainData.array()));
80
81 final IntSet downHeights = new IntOpenHashSet();
82
83 parseTerrain(region, terrainBuffer, downHeights);
84
85 ByteBuffer gameObjectData = mapIndex.get(def.getObjectFile());
86 if (gameObjectData == null) {
87 errors.getAndIncrement();
88 return;
89 }
90 ByteBuffer gameObjectBuffer = ByteBuffer.wrap(CompressionUtil.gunzip(gameObjectData.array()));
91 parseGameObject(region, gameObjectBuffer, x, y, downHeights);
92
93 decoded.getAndIncrement();
94 } catch (Exception e) {
95 e.printStackTrace();
96 errors.getAndIncrement();
97 }
98 }

References decoded, errors, com.runehive.fs.cache.Cache.get(), com.runehive.game.world.region.RegionManager.getRegion(), com.runehive.game.world.World.getRegions(), com.runehive.fs.util.CompressionUtil.gunzip(), parseGameObject(), and parseTerrain().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseGameObject()

void com.runehive.fs.cache.decoder.RegionDecoder.parseGameObject ( Region region,
ByteBuffer buf,
int x,
int y,
IntSet downHeights )
private

Parses a GameObject on the specified coordinates.

Parameters
bufThe uncompressed game object data buffer.
xThe x coordinate this object is on.
yThe y coordinate this object is on.

Definition at line 107 of file RegionDecoder.java.

107 {
108 int objId = -1;
109 while (true) {
110 int objIdOffset = ByteBufferUtil.getSmart(buf);
111 if (objIdOffset == 0) break;
112
113 objId += objIdOffset;
114 int objPosInfo = 0;
115
116 while (true) {
117 int objPosInfoOffset = ByteBufferUtil.getSmart(buf);
118 if (objPosInfoOffset == 0) break;
119 objPosInfo += objPosInfoOffset - 1;
120
121 int objOtherInfo = buf.get() & 0xFF;
122 int localY = objPosInfo & 0x3f;
123 int localX = objPosInfo >> 6 & 0x3f;
124 int height = objPosInfo >> 12 & 0x3;
125
126 Optional<ObjectType> type = ObjectType.valueOf(objOtherInfo >> 2);
127 Optional<ObjectDirection> face = ObjectDirection.valueOf(objOtherInfo & 0x3);
128
129 if (downHeights.contains(Position.hash(localX, localY, 1))) {
130 if (--height < 0) continue;
131 } else if (downHeights.contains(Position.hash(localX, localY, height))) {
132 height--;
133 }
134
135 if (!type.isPresent() || !face.isPresent()) {
136 continue;
137 }
138
139 Position pos = new Position(localX + x, localY + y, height);
140 GameObjectDefinition def = GameObjectDefinition.forId(objId);
141
142 if (def == null)
143 continue;
144
145 StaticGameObject staticObject = new StaticGameObject(def, pos, type.get(), face.get());
146
147 if (Region.SKIPPED_OBJECTS.contains(pos)) {
148 region.skip(staticObject);
149 } else {
150 TraversalMap.markObject(region, staticObject, true, true);
151 }
152 }
153 }
154 }
void skip(GameObject gameObject)
Definition Region.java:273

References com.runehive.game.world.object.GameObjectDefinition.forId(), com.runehive.fs.util.ByteBufferUtil.getSmart(), com.runehive.game.world.position.Position.hash(), com.runehive.game.world.pathfinding.TraversalMap.markObject(), com.runehive.game.world.region.Region.SKIPPED_OBJECTS, com.runehive.game.world.object.ObjectDirection.valueOf(), and com.runehive.game.world.object.ObjectType.valueOf().

Referenced by load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseTerrain()

void com.runehive.fs.cache.decoder.RegionDecoder.parseTerrain ( Region region,
ByteBuffer mapBuffer,
IntSet downHeights )
private

Loads all of the tool.mapviewer indexes entries and decodes each.

Parameters
mapBufferThe uncompressed tool.mapviewer entry data buffer.

Definition at line 161 of file RegionDecoder.java.

161 {
162 int[][][] attributes = new int[4][64][64];
163
164 for (int height = 0; height < 4; height++) {
165 for (int localX = 0; localX < 64; localX++) {
166 for (int localY = 0; localY < 64; localY++) {
167 while (true) {
168 int attributeId = mapBuffer.getShort() & 0xFFFF;
169 if (attributeId == 0) {
170 break;
171 }
172 if (attributeId == 1) {
173 int tileHeight = mapBuffer.get() & 0xFF;
174 break;
175 }
176 if (attributeId <= 49) {
177 int overlayId = mapBuffer.getShort() & 0xFFFF;
178 } else if (attributeId <= 81) {
179 attributes[height][localX][localY] = attributeId - 49;
180 }
181 }
182 }
183 }
184 }
185
186 for (int height = 0; height < 4; height++) {
187 for (int localX = 0; localX < 64; localX++) {
188 for (int localY = 0; localY < 64; localY++) {
189
190 if ((attributes[height][localX][localY] & 2) == 2) {
191 downHeights.add(Position.hash(localX, localY, height));
192 }
193
194 if ((attributes[height][localX][localY] & 1) == 1) {
195 int plane = height;
196
197 if ((attributes[1][localX][localY] & 2) == 2) {
198 downHeights.add(Position.hash(localX, localY, 1));
199 plane--;
200 }
201
202 if (plane >= 0) {
203 TraversalMap.block(region, plane, localX, localY);
204 }
205 }
206 }
207 }
208 }
209 }

References com.runehive.game.world.pathfinding.TraversalMap.block(), and com.runehive.game.world.position.Position.hash().

Referenced by load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

void com.runehive.fs.cache.decoder.RegionDecoder.run ( )

Definition at line 58 of file RegionDecoder.java.

58 {
59 LOGGER.info("Loading regional map data.");
60 final Cache mapIndex = fs.getCache(FileSystem.MAP_INDEX);
61 RegionDefinition.getDefinitions()
62 .values()
63 .forEach(def -> load(mapIndex, def));
64 LOGGER.info("Loaded " + decoded + " regions, skipped " + errors + " maps.");
65 }

References decoded, errors, fs, com.runehive.game.world.region.RegionDefinition.getDefinitions(), load(), LOGGER, and com.runehive.fs.cache.FileSystem.MAP_INDEX.

Referenced by com.runehive.RuneHive.processSequentialStartupTasks().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ decoded

final AtomicInteger com.runehive.fs.cache.decoder.RegionDecoder.decoded = new AtomicInteger()
private

Amount of regions correctly decoded.

Definition at line 41 of file RegionDecoder.java.

Referenced by load(), and run().

◆ errors

final AtomicInteger com.runehive.fs.cache.decoder.RegionDecoder.errors = new AtomicInteger()
private

Amount of regions incorrectly decoded.

Definition at line 46 of file RegionDecoder.java.

Referenced by load(), and run().

◆ fs

final FileSystem com.runehive.fs.cache.decoder.RegionDecoder.fs
private

The FileSystem.

Definition at line 36 of file RegionDecoder.java.

Referenced by RegionDecoder(), and run().

◆ LOGGER

final Logger com.runehive.fs.cache.decoder.RegionDecoder.LOGGER = LogManager.getLogger(RegionDecoder.class)
staticprivate

Definition at line 31 of file RegionDecoder.java.

Referenced by run().


The documentation for this class was generated from the following file: