RuneHive-Game
Loading...
Searching...
No Matches
AnimationDefinitionDecoder.java
Go to the documentation of this file.
1package com.runehive.fs.cache.decoder;
2
3import com.runehive.fs.cache.FileSystem;
4import com.runehive.fs.cache.archive.Archive;
5import io.netty.buffer.ByteBuf;
6import io.netty.buffer.Unpooled;
7import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
8import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
9import org.apache.logging.log4j.LogManager;
10import org.apache.logging.log4j.Logger;
11
12/**
13 * A class which parses animation definitions.
14 */
15public final class AnimationDefinitionDecoder implements Runnable {
16
17 /** The logger to log process output. */
18 private final static Logger LOGGER = LogManager.getLogger(AnimationDefinitionDecoder.class);
19
20 public static final Int2ObjectMap<AnimationDefinition> definitions = new Int2ObjectOpenHashMap<>();
21
22 /** The IndexedFileSystem. */
23 private final FileSystem fs;
24
26 this.fs = fs;
27 }
28
29 @Override
30 public void run() {
31 LOGGER.info("Loading animation definitions.");
32
33 final Archive archive = fs.getArchive(FileSystem.CONFIG_ARCHIVE);
34 final ByteBuf buffer = Unpooled.wrappedBuffer(archive.getData("seq.dat"));
35 try {
36 final int highestFileId = buffer.readUnsignedShort();
37 for (int i = 0; i <= highestFileId; i++) {
38 final int id = buffer.readUnsignedShort();
39 if (id == 65535) break;
40
41 final int length = buffer.readUnsignedShort();
42 final ByteBuf animBuffer = buffer.readBytes(length);
43 try {
44 final AnimationDefinition definition = new AnimationDefinition(id);
45 definition.decode(animBuffer);
46
47 definitions.put(id, definition);
48 } finally {
49 animBuffer.release();
50 }
51
52 if (id >= highestFileId) break;
53 }
54 } finally {
55 buffer.release();
56 }
57
58 LOGGER.info("Loaded " + definitions.size() + " animation definitions.");
59 }
60
61}
Represents a file system of Caches and Archives.
static final int CONFIG_ARCHIVE
Represents the id of the configurations archive.
Represents an archive within the Cache.
Definition Archive.java:25
static final Int2ObjectMap< AnimationDefinition > definitions
static final Logger LOGGER
The logger to log process output.