Skip to content

Commit

Permalink
Renamed: Buffer#readU*
Browse files Browse the repository at this point in the history
Refactored: Censor (mostly)
  • Loading branch information
galsjel committed Jan 8, 2023
1 parent 9bac90c commit 6f9ff70
Show file tree
Hide file tree
Showing 28 changed files with 1,023 additions and 971 deletions.
18 changes: 9 additions & 9 deletions src/main/java/BitmapFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@ public class BitmapFont {
public BitmapFont(FileArchive archive, String name, boolean quill) throws IOException {
Buffer dat = new Buffer(archive.read(name + ".dat"));
Buffer idx = new Buffer(archive.read("index.dat"));
idx.position = dat.read16U() + 4;
idx.position = dat.readU16() + 4;

int k = idx.read8U();
int k = idx.readU8();

if (k > 0) {
idx.position += 3 * (k - 1);
}

for (int c = 0; c < 256; c++) {
charOffsetX[c] = idx.read8U();
charOffsetY[c] = idx.read8U();
charOffsetX[c] = idx.readU8();
charOffsetY[c] = idx.readU8();

int w = charMaskWidth[c] = idx.read16U();
int h = charMaskHeight[c] = idx.read16U();
int storeOrder = idx.read8U();
int w = charMaskWidth[c] = idx.readU16();
int h = charMaskHeight[c] = idx.readU16();
int storeOrder = idx.readU8();

int len = w * h;
charMask[c] = new byte[len];

if (storeOrder == 0) {
for (int i = 0; i < len; i++) {
charMask[c][i] = dat.read();
charMask[c][i] = dat.read8();
}
} else if (storeOrder == 1) {
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
charMask[c][x + (y * w)] = dat.read();
charMask[c][x + (y * w)] = dat.read8();
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/Buffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* A {@link Buffer} encapsulates a finite amount of data and provides methods for reading and writing to that data.
* The <code>write()</code> and <code>read()</code> methods describe the type of data they use by attributes in their
* suffix. The naming convention is <code>(read|write)[type][U:unsigned][endianness][modifier]</code>.
* suffix. The naming convention is <code>(read[U:unsigned]|write)[type][endianness][modifier]</code>.
* <p>
* <b>Types:</b><br/>
* # — the number of bytes<br/>
Expand Down Expand Up @@ -135,7 +135,7 @@ public void writeA(byte[] src, int off, int len) {
}
}

public byte read() {
public byte read8() {
return data[position++];
}

Expand All @@ -147,19 +147,19 @@ public byte read8S() {
return (byte) (128 - data[position++]);
}

public int read8U() {
public int readU8() {
return data[position++] & 0xff;
}

public int read8UA() {
public int readU8A() {
return (data[position++] - 128) & 0xff;
}

public int read8UC() {
public int readU8C() {
return -data[position++] & 0xff;
}

public int read8US() {
public int readU8S() {
return (128 - data[position++]) & 0xff;
}

Expand All @@ -170,9 +170,9 @@ public int read8US() {
*/
public int readSmart() {
if ((data[position] & 0xff) < 128) {
return read8U() - 64;
return readU8() - 64;
} else {
return read16U() - 49152;
return readU16() - 49152;
}
}

Expand All @@ -181,30 +181,30 @@ public int readSmart() {
*
* @return the value.
*/
public int readSmartU() {
public int readUSmart() {
if ((data[position] & 0xff) < 128) {
return read8U();
return readU8();
} else {
return read16U() - 32768;
return readU16() - 32768;
}
}

public int read16U() {
public int readU16() {
position += 2;
return ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
}

public int read16UA() {
public int readU16A() {
position += 2;
return ((data[position - 2] & 0xff) << 8) + ((data[position - 1] - 128) & 0xff);
}

public int read16ULE() {
public int readU16LE() {
position += 2;
return ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
}

public int read16ULEA() {
public int readU16LEA() {
position += 2;
return ((data[position - 1] & 0xff) << 8) + ((data[position - 2] - 128) & 0xff);
}
Expand Down
Loading

0 comments on commit 6f9ff70

Please sign in to comment.