Skip to content

Commit

Permalink
refactor: Cleaned up anim code
Browse files Browse the repository at this point in the history
  • Loading branch information
Pazaz committed Jul 7, 2024
1 parent 0d32b7c commit 41a7719
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 92 deletions.
32 changes: 17 additions & 15 deletions client/src/main/java/client.java
Original file line number Diff line number Diff line change
Expand Up @@ -4776,30 +4776,30 @@ private void updateEntity(@OriginalArg(0) PathingEntity entity, @OriginalArg(2)
}

@OriginalMember(owner = "client!client", name = "a", descriptor = "(Lclient!x;I)V")
private void updateForceMovement(@OriginalArg(0) PathingEntity enttiy) {
@Pc(4) int delta = enttiy.forceMoveEndCycle - loopCycle;
@Pc(14) int dstX = enttiy.forceMoveStartSceneTileX * 128 + enttiy.size * 64;
@Pc(24) int dstZ = enttiy.forceMoveStartSceneTileZ * 128 + enttiy.size * 64;
private void updateForceMovement(@OriginalArg(0) PathingEntity entity) {
@Pc(4) int delta = entity.forceMoveEndCycle - loopCycle;
@Pc(14) int dstX = entity.forceMoveStartSceneTileX * 128 + entity.size * 64;
@Pc(24) int dstZ = entity.forceMoveStartSceneTileZ * 128 + entity.size * 64;

enttiy.x += (dstX - enttiy.x) / delta;
enttiy.z += (dstZ - enttiy.z) / delta;
entity.x += (dstX - entity.x) / delta;
entity.z += (dstZ - entity.z) / delta;

enttiy.seqTrigger = 0;
entity.seqTrigger = 0;

if (enttiy.forceMoveFaceDirection == 0) {
enttiy.dstYaw = 1024;
if (entity.forceMoveFaceDirection == 0) {
entity.dstYaw = 1024;
}

if (enttiy.forceMoveFaceDirection == 1) {
enttiy.dstYaw = 1536;
if (entity.forceMoveFaceDirection == 1) {
entity.dstYaw = 1536;
}

if (enttiy.forceMoveFaceDirection == 2) {
enttiy.dstYaw = 0;
if (entity.forceMoveFaceDirection == 2) {
entity.dstYaw = 0;
}

if (enttiy.forceMoveFaceDirection == 3) {
enttiy.dstYaw = 512;
if (entity.forceMoveFaceDirection == 3) {
entity.dstYaw = 512;
}
}

Expand Down Expand Up @@ -6779,6 +6779,7 @@ protected void load() {
World3D.init(512, 334, 500, 800, distance);
WordFilter.unpack(wordenc);
} catch (@Pc(1357) Exception ex) {
ex.printStackTrace();
this.errorLoading = true;
}
}
Expand Down Expand Up @@ -11505,6 +11506,7 @@ private boolean read() {
} catch (@Pc(3862) IOException ex) {
this.tryReconnect();
} catch (@Pc(3867) Exception ex) {
ex.printStackTrace();
String error = "T2 - " + this.packetType + "," + this.lastPacketType1 + "," + this.lastPacketType2 + " - " + this.packetSize + "," + (this.sceneBaseTileX + this.localPlayer.pathTileX[0]) + "," + (this.sceneBaseTileZ + this.localPlayer.pathTileZ[0]) + " - ";
for (int i = 0; i < this.packetSize && i < 50; i++) {
error = error + this.in.data[i] + ",";
Expand Down
8 changes: 4 additions & 4 deletions runetek3/src/main/java/jagex2/config/LocType.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public class LocType {
public String[] op;

@OriginalMember(owner = "client!ac", name = "C", descriptor = "Z")
private boolean disposeAlpha;
private boolean animHasAlpha;

@OriginalMember(owner = "client!ac", name = "D", descriptor = "I")
public int mapfunction;
Expand Down Expand Up @@ -228,7 +228,7 @@ public void reset() {
this.ambient = 0;
this.contrast = 0;
this.op = null;
this.disposeAlpha = false;
this.animHasAlpha = false;
this.mapfunction = -1;
this.mapscene = -1;
this.mirror = false;
Expand Down Expand Up @@ -292,7 +292,7 @@ public void decode(@OriginalArg(1) Packet dat) {
this.anim = -1;
}
} else if (code == 25) {
this.disposeAlpha = true;
this.animHasAlpha = true;
} else if (code == 28) {
this.wallwidth = dat.g1();
} else if (code == 29) {
Expand Down Expand Up @@ -432,7 +432,7 @@ public Model getModel(@OriginalArg(0) int shape, @OriginalArg(1) int rotation, @
@Pc(235) boolean scaled = this.resizex != 128 || this.resizey != 128 || this.resizez != 128;
@Pc(250) boolean translated = this.offsetx != 0 || this.offsety != 0 || this.offsetz != 0;

@Pc(284) Model modified = new Model(model, this.recol_s == null, !this.disposeAlpha, rotation == 0 && transformId == -1 && !scaled && !translated);
@Pc(284) Model modified = new Model(model, this.recol_s == null, !this.animHasAlpha, rotation == 0 && transformId == -1 && !scaled && !translated);
if (transformId != -1) {
modified.createLabelReferences();
modified.applyTransform(transformId);
Expand Down
6 changes: 3 additions & 3 deletions runetek3/src/main/java/jagex2/config/NpcType.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class NpcType {
public int walkanim_l = -1;

@OriginalMember(owner = "client!bc", name = "r", descriptor = "Z")
private boolean disposeAlpha = false;
private boolean animHasAlpha = false;

@OriginalMember(owner = "client!bc", name = "s", descriptor = "[I")
private int[] recol_s;
Expand Down Expand Up @@ -167,7 +167,7 @@ public void decode(@OriginalArg(1) Packet dat) {
} else if (code == 14) {
this.walkanim = dat.g2();
} else if (code == 16) {
this.disposeAlpha = true;
this.animHasAlpha = true;
} else if (code == 17) {
this.walkanim = dat.g2();
this.walkanim_b = dat.g2();
Expand Down Expand Up @@ -247,7 +247,7 @@ public Model getSequencedModel(@OriginalArg(0) int primaryTransformId, @Original
modelCache.put(this.index, model);
}

tmp = new Model(model, !this.disposeAlpha);
tmp = new Model(model, !this.animHasAlpha);

if (primaryTransformId != -1 && secondaryTransformId != -1) {
tmp.applyTransforms(primaryTransformId, secondaryTransformId, seqMask);
Expand Down
2 changes: 2 additions & 0 deletions runetek3/src/main/java/jagex2/config/ObjType.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,10 @@ public void decode(@OriginalArg(1) Packet dat) {
this.yof2d -= 65536;
}
} else if (code == 9) {
// animHasAlpha from code10?
this.code9 = true;
} else if (code == 10) {
// seq?
this.code10 = dat.g2();
} else if (code == 11) {
this.stackable = true;
Expand Down
4 changes: 2 additions & 2 deletions runetek3/src/main/java/jagex2/config/SpotAnimType.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class SpotAnimType {
public SeqType seq;

@OriginalMember(owner = "client!kc", name = "h", descriptor = "Z")
public boolean disposeAlpha = false;
public boolean animHasAlpha = false;

@OriginalMember(owner = "client!kc", name = "i", descriptor = "[I")
private final int[] recol_s = new int[6];
Expand Down Expand Up @@ -94,7 +94,7 @@ public void decode(@OriginalArg(1) Packet dat) {
this.seq = SeqType.instances[this.anim];
}
} else if (code == 3) {
this.disposeAlpha = true;
this.animHasAlpha = true;
} else if (code == 4) {
this.resizeh = dat.g2();
} else if (code == 5) {
Expand Down
4 changes: 2 additions & 2 deletions runetek3/src/main/java/jagex2/dash3d/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public void readLandscape(@OriginalArg(1) int originX, @OriginalArg(5) int origi
opcode = buf.g1();
if (opcode == 0) {
if (level == 0) {
this.levelHeightmap[0][stx][stz] = -perlin(stx + originX + 932731, stz + 556238 + originZ) * 8;
this.levelHeightmap[0][stx][stz] = -perlin(stx + originX + 932731, stz + originZ + 556238) * 8;
} else {
this.levelHeightmap[level][stx][stz] = this.levelHeightmap[level - 1][stx][stz] - 240;
}
Expand All @@ -416,7 +416,7 @@ public void readLandscape(@OriginalArg(1) int originX, @OriginalArg(5) int origi

if (opcode <= 49) {
this.levelTileOverlayIds[level][stx][stz] = buf.g1b();
this.levelTileOverlayShape[level][stx][stz] = (byte) ((opcode - 2) / 4);
this.levelTileOverlayShape[level][stx][stz] = (byte) ((opcode - 2) >> 2);
this.levelTileOverlayRotation[level][stx][stz] = (byte) (opcode - 2 & 0x3);
} else if (opcode <= 81) {
this.levelTileFlags[level][stx][stz] = (byte) (opcode - 49);
Expand Down
2 changes: 1 addition & 1 deletion runetek3/src/main/java/jagex2/dash3d/entity/NpcEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Model draw(int loopCycle) {
@Pc(20) Model model = this.getSequencedModel();
@Pc(25) SpotAnimType spotanim = SpotAnimType.instances[super.spotanimId];

@Pc(41) Model model1 = new Model(spotanim.getModel(), true, !spotanim.disposeAlpha, false);
@Pc(41) Model model1 = new Model(spotanim.getModel(), true, !spotanim.animHasAlpha, false);
model1.translate(-super.spotanimOffset, 0, 0);
model1.createLabelReferences();
model1.applyTransform(spotanim.seq.frames[super.spotanimFrame]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public Model draw(int loopCycle) {

if (super.spotanimId != -1 && super.spotanimFrame != -1) {
@Pc(35) SpotAnimType spotanim = SpotAnimType.instances[super.spotanimId];
@Pc(51) Model model2 = new Model(spotanim.getModel(), true, !spotanim.disposeAlpha, false);
@Pc(51) Model model2 = new Model(spotanim.getModel(), true, !spotanim.animHasAlpha, false);

model2.translate(-super.spotanimOffset, 0, 0);
model2.createLabelReferences();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void update(@OriginalArg(1) int delta) {
@Override
public Model draw(int loopCycle) {
@Pc(3) Model tmp = this.spotanim.getModel();
@Pc(19) Model model = new Model(tmp, true, !this.spotanim.disposeAlpha, false);
@Pc(19) Model model = new Model(tmp, true, !this.spotanim.animHasAlpha, false);

if (this.spotanim.seq != null) {
model.createLabelReferences();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void update(@OriginalArg(0) int delta) {
@Override
public Model draw(int loopCycle) {
@Pc(3) Model tmp = this.type.getModel();
@Pc(19) Model model = new Model(tmp, true, !this.type.disposeAlpha, false);
@Pc(19) Model model = new Model(tmp, true, !this.type.animHasAlpha, false);

if (!this.seqComplete) {
model.createLabelReferences();
Expand Down
33 changes: 21 additions & 12 deletions runetek3/src/main/java/jagex2/graphics/AnimBase.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
package jagex2.graphics;

import jagex2.io.Jagfile;
import jagex2.io.Packet;
import org.openrs2.deob.annotation.OriginalArg;
import org.openrs2.deob.annotation.OriginalClass;
import org.openrs2.deob.annotation.OriginalMember;
import org.openrs2.deob.annotation.Pc;

import jagex2.io.Jagfile;
import jagex2.io.Packet;

// name taken from runetek5
@OriginalClass("client!f")
public class AnimBase {

public static final int OP_BASE = 0;
public static final int OP_TRANSLATE = 1;
public static final int OP_ROTATE = 2;
public static final int OP_SCALE = 3;
public static final int OP_ALPHA = 5;

@OriginalMember(owner = "client!f", name = "a", descriptor = "[Lclient!f;")
public static AnimBase[] instances;

@OriginalMember(owner = "client!f", name = "b", descriptor = "I")
public int length;

// an operation for a specific group - [group]
@OriginalMember(owner = "client!f", name = "c", descriptor = "[I")
public int[] types;

// labels for a specific group - [group] [label]
@OriginalMember(owner = "client!f", name = "d", descriptor = "[[I")
public int[][] labels;

Expand All @@ -37,24 +46,24 @@ public static void unpack(@OriginalArg(1) Jagfile models) {
@Pc(55) int id = head.g2();
@Pc(58) int length = head.g1();

@Pc(61) int[] transformTypes = new int[length];
@Pc(64) int[][] groupLabels = new int[length][];
@Pc(61) int[] types = new int[length];
@Pc(64) int[][] labels = new int[length][];

for (@Pc(66) int j = 0; j < length; j++) {
transformTypes[j] = type.g1();
for (@Pc(66) int g = 0; g < length; g++) {
types[g] = type.g1();

@Pc(76) int groupCount = label.g1();
groupLabels[j] = new int[groupCount];
@Pc(76) int labelCount = label.g1();
labels[g] = new int[labelCount];

for (@Pc(83) int k = 0; k < groupCount; k++) {
groupLabels[j][k] = label.g1();
for (@Pc(83) int l = 0; l < labelCount; l++) {
labels[g][l] = label.g1();
}
}

instances[id] = new AnimBase();
instances[id].length = length;
instances[id].types = transformTypes;
instances[id].labels = groupLabels;
instances[id].types = types;
instances[id].labels = labels;
}
}
}
27 changes: 16 additions & 11 deletions runetek3/src/main/java/jagex2/graphics/AnimFrame.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package jagex2.graphics;

import jagex2.io.Jagfile;
import jagex2.io.Packet;
import org.openrs2.deob.annotation.OriginalArg;
import org.openrs2.deob.annotation.OriginalClass;
import org.openrs2.deob.annotation.OriginalMember;
import org.openrs2.deob.annotation.Pc;

import jagex2.io.Jagfile;
import jagex2.io.Packet;

// name taken from runetek5
@OriginalClass("client!g")
public class AnimFrame {
Expand All @@ -23,15 +24,19 @@ public class AnimFrame {
@OriginalMember(owner = "client!g", name = "d", descriptor = "I")
public int length;

// groups to use from base
@OriginalMember(owner = "client!g", name = "e", descriptor = "[I")
public int[] bases;
public int[] groups;

// x adjustment for group
@OriginalMember(owner = "client!g", name = "f", descriptor = "[I")
public int[] x;

// y adjustment for group
@OriginalMember(owner = "client!g", name = "g", descriptor = "[I")
public int[] y;

// z adjustment for group
@OriginalMember(owner = "client!g", name = "h", descriptor = "[I")
public int[] z;

Expand All @@ -46,7 +51,7 @@ public static void unpack(@OriginalArg(1) Jagfile models) {
@Pc(53) int count = head.g2();
instances = new AnimFrame[count + 1];

@Pc(61) int[] labels = new int[500];
@Pc(61) int[] groups = new int[500];
@Pc(64) int[] x = new int[500];
@Pc(67) int[] y = new int[500];
@Pc(70) int[] z = new int[500];
Expand All @@ -68,10 +73,10 @@ public static void unpack(@OriginalArg(1) Jagfile models) {
int flags = tran1.g1();

if (flags > 0) {
if (base.types[j] != 0) {
if (base.types[j] != AnimBase.OP_BASE) {
for (@Pc(124) int group = j - 1; group > lastGroup; group--) {
if (base.types[group] == 0) {
labels[current] = group;
if (base.types[group] == AnimBase.OP_BASE) {
groups[current] = group;
x[current] = 0;
y[current] = 0;
z[current] = 0;
Expand All @@ -81,10 +86,10 @@ public static void unpack(@OriginalArg(1) Jagfile models) {
}
}

labels[current] = j;
groups[current] = j;

@Pc(160) short defaultValue = 0;
if (base.types[labels[current]] == 3) {
if (base.types[groups[current]] == AnimBase.OP_SCALE) {
defaultValue = 128;
}

Expand Down Expand Up @@ -112,13 +117,13 @@ public static void unpack(@OriginalArg(1) Jagfile models) {
}

frame.length = current;
frame.bases = new int[current];
frame.groups = new int[current];
frame.x = new int[current];
frame.y = new int[current];
frame.z = new int[current];

for (int j = 0; j < current; j++) {
frame.bases[j] = labels[j];
frame.groups[j] = groups[j];
frame.x[j] = x[j];
frame.y[j] = y[j];
frame.z[j] = z[j];
Expand Down
Loading

0 comments on commit 41a7719

Please sign in to comment.