Skip to content

Commit

Permalink
feat: Npc/obj dots for mapview
Browse files Browse the repository at this point in the history
  • Loading branch information
Pazaz committed May 2, 2024
1 parent 1c25375 commit d2ca5d5
Showing 1 changed file with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions mapview/src/main/java/mapview.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public final class mapview extends GameShell {
@OriginalMember(owner = "mapview!mapview", name = "U", descriptor = "[[B")
private byte[][] locMapscenes;

private boolean[][] objTiles;

private boolean[][] npcTiles;

@OriginalMember(owner = "mapview!mapview", name = "X", descriptor = "Lmapview!j;")
private PixFont b12;

Expand Down Expand Up @@ -132,6 +136,11 @@ public final class mapview extends GameShell {
@OriginalMember(owner = "mapview!mapview", name = "W", descriptor = "[Lmapview!h;")
private Pix24[] imageMapfunction = new Pix24[50];

private Pix24 imageMapdot0;
private Pix24 imageMapdot1;
private Pix24 imageMapdot2;
private Pix24 imageMapdot3;

@OriginalMember(owner = "mapview!mapview", name = "gb", descriptor = "[I")
private int[] visibleMapFunctionsX = new int[2000];

Expand Down Expand Up @@ -271,6 +280,14 @@ protected void load() {
this.locMapfunctions = new byte[1280][1216];
this.readLocData(locData, this.locWalls, this.locMapscenes, this.locMapfunctions);

byte[] objData = worldmap.read("obj.dat", null);
this.objTiles = new boolean[1280][1216];
this.readObjData(objData, this.objTiles);

byte[] npcData = worldmap.read("npc.dat", null);
this.npcTiles = new boolean[1280][1216];
this.readNpcData(npcData, this.npcTiles);

try {
for (int i = 0; i < 50; i++) {
this.imageMapscene[i] = new Pix8(worldmap, "mapscene", i);
Expand All @@ -285,6 +302,11 @@ protected void load() {
} catch (@Pc(204) Exception ignore) {
}

this.imageMapdot0 = new Pix24(worldmap, "mapdots", 0);
this.imageMapdot1 = new Pix24(worldmap, "mapdots", 1);
this.imageMapdot2 = new Pix24(worldmap, "mapdots", 2);
this.imageMapdot3 = new Pix24(worldmap, "mapdots", 3);

this.b12 = new PixFont(worldmap, "b12");
this.f11 = new WorldmapFont(11, true, this);
this.f12 = new WorldmapFont(12, true, this);
Expand Down Expand Up @@ -357,6 +379,48 @@ private void readLocData(@OriginalArg(0) byte[] data, @OriginalArg(1) byte[][] w
}
}

private void readObjData(byte[] data, boolean[][] objs) {
int pos = 0;
while (pos < data.length) {
int mx = (data[pos++] & 0xFF) * 64 - 2304;
int mz = (data[pos++] & 0xFF) * 64 - 2816;

if (mx > 0 && mz > 0 && mx + 64 < 1280 && mz + 64 < 1216) {
for (int x = 0; x < 64; x++) {
boolean[] obj = objs[x + mx];
int zIndex = 1216 - mz - 1;

for (int z = -64; z < 0; z++) {
obj[zIndex--] = data[pos++] == 1;
}
}
} else {
pos += 4096;
}
}
}

private void readNpcData(byte[] data, boolean[][] npcs) {
int pos = 0;
while (pos < data.length) {
int mx = (data[pos++] & 0xFF) * 64 - 2304;
int mz = (data[pos++] & 0xFF) * 64 - 2816;

if (mx > 0 && mz > 0 && mx + 64 < 1280 && mz + 64 < 1216) {
for (int x = 0; x < 64; x++) {
boolean[] npc = npcs[x + mx];
int zIndex = 1216 - mz - 1;

for (int z = -64; z < 0; z++) {
npc[zIndex--] = data[pos++] == 1;
}
}
} else {
pos += 4096;
}
}
}

@OriginalMember(owner = "mapview!mapview", name = "a", descriptor = "([B[[B)V")
private void readUnderlayData(@OriginalArg(0) byte[] data, @OriginalArg(1) byte[][] underlays) {
@Pc(3) int pos = 0;
Expand Down Expand Up @@ -523,8 +587,14 @@ protected void unload() {
this.locWalls = null;
this.locMapfunctions = null;
this.locMapscenes = null;
this.objTiles = null;
this.npcTiles = null;
this.imageMapscene = null;
this.imageMapfunction = null;
this.imageMapdot0 = null;
this.imageMapdot1 = null;
this.imageMapdot2 = null;
this.imageMapdot3 = null;
this.b12 = null;
this.visibleMapFunctionsX = null;
this.visibleMapFunctionsY = null;
Expand Down Expand Up @@ -1030,6 +1100,64 @@ private void drawMap(@OriginalArg(0) int left, @OriginalArg(1) int top, @Origina
}
}

for (int x = 0; x < visibleX; x++) {
int startX = widthRatio * x >> 16;
int endX = widthRatio * (x + 1) >> 16;
int lengthX = endX - startX;
if (lengthX <= 0) {
continue;
}

startX += widthOffset;
endX += widthOffset;

boolean[] objs = this.objTiles[x + left];
for (int y = 0; y < visibleY; y++) {
int startY = heightRatio * y >> 16;
int endY = heightRatio * (y + 1) >> 16;
int lengthY = endY - startY;
if (lengthY <= 0) {
continue;
}

startY += heightOffset;
endY += heightOffset;

if (objs[y + top]) {
this.imageMapdot0.draw(startX, startY);
}
}
}

for (int x = 0; x < visibleX; x++) {
int startX = widthRatio * x >> 16;
int endX = widthRatio * (x + 1) >> 16;
int lengthX = endX - startX;
if (lengthX <= 0) {
continue;
}

startX += widthOffset;
endX += widthOffset;

boolean[] npcs = this.npcTiles[x + left];
for (int y = 0; y < visibleY; y++) {
int startY = heightRatio * y >> 16;
int endY = heightRatio * (y + 1) >> 16;
int lengthY = endY - startY;
if (lengthY <= 0) {
continue;
}

startY += heightOffset;
endY += heightOffset;

if (npcs[y + top]) {
this.imageMapdot1.draw(startX, startY);
}
}
}

for (int i = 0; i < visibleMapFunctionCount; i++) {
this.imageMapfunction[this.visibleMapFunctions[i]].draw(this.visibleMapFunctionsX[i] - 7, this.visibleMapFunctionsY[i] - 7);
}
Expand Down

0 comments on commit d2ca5d5

Please sign in to comment.