Skip to content

Commit

Permalink
Added support for new animation system, decreased cpu usage a lot
Browse files Browse the repository at this point in the history
  • Loading branch information
dosier committed May 1, 2024
1 parent de122fa commit 13312b7
Show file tree
Hide file tree
Showing 63 changed files with 2,966 additions and 380 deletions.
2 changes: 1 addition & 1 deletion qodat-api/src/main/kotlin/qodat/cache/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ abstract class Cache(val name: String) {

abstract fun getAnimationSkeletonDefinition(frameHash: Int) : AnimationTransformationGroup

abstract fun getFrameDefinition(frameHash: Int) : AnimationFrameDefinition?
abstract fun getFrameDefinition(frameHash: Int) : AnimationFrameLegacyDefinition?

abstract fun getInterface(groupId: Int): Array<InterfaceDefinition>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
package qodat.cache.definition

/**
* TODO: add documentation
*
* @author Stan van der Bend (https://www.rune-server.ee/members/StanDev/)
* @since 28/01/2021
*/
interface AnimationFrameDefinition {

val transformationCount : Int
val transformationGroupAccessIndices : IntArray
val transformationDeltaX : IntArray
val transformationDeltaY : IntArray
val transformationDeltaZ : IntArray

val transformationGroup : AnimationTransformationGroup
}
interface AnimationFrameDefinition
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package qodat.cache.definition

/**
* TODO: add documentation
*
* @author Stan van der Bend (https://www.rune-server.ee/members/StanDev/)
* @since 28/01/2021
*/
interface AnimationFrameLegacyDefinition : AnimationFrameDefinition {

val transformationCount : Int
val transformationGroupAccessIndices : IntArray
val transformationDeltaX : IntArray
val transformationDeltaY : IntArray
val transformationDeltaZ : IntArray

val transformationGroup : AnimationTransformationGroup
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package qodat.cache.definition

import net.runelite.cache.definitions.SequenceDefinition

interface AnimationMayaDefinition : AnimationDefinition {

val animMayaID : Int
val animMayaFrameSounds: Map<Int, SequenceDefinition.Sound>
val animMayaStart: Int
val animMayaEnd: Int
val animMayaMasks: BooleanArray

}
21 changes: 20 additions & 1 deletion qodat-api/src/main/kotlin/qodat/cache/models/RS2Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public class RS2Model implements ModelDefinition
private transient int[][] vertexGroups;
private transient int[][] faceGroups;

private int[][] animayaGroups;
private int[][] animayaScales;


/**
* Computes the UV coordinates for every three-vertex face that has a
Expand Down Expand Up @@ -580,6 +583,22 @@ public void setTexturePrimaryColors(short[] texturePrimaryColors) {
this.texturePrimaryColors = texturePrimaryColors;
}

public void setAnimayaGroups(int[][] animayaGroups) {
this.animayaGroups = animayaGroups;
}

public void setAnimayaScales(int[][] animayaScales) {
this.animayaScales = animayaScales;
}

public int[][] getAnimayaGroups() {
return animayaGroups;
}

public int[][] getAnimayaScales() {
return animayaScales;
}

public void setPriority(byte priority) {
this.priority = priority;
}
Expand Down Expand Up @@ -642,4 +661,4 @@ public void setTextureTriangleVertexIndices3(short[] textureTriangleVertexIndice
this.textureTriangleVertexIndices3 = textureTriangleVertexIndices3;
}

}
}
3 changes: 3 additions & 0 deletions qodat-api/src/main/kotlin/qodat/cache/models/RSModelLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class RSModelLoader {
setFaceTextureConfigs(it.textureCoords)
faceRenderPriorities = it.faceRenderPriorities
faceRenderTypes = it.faceRenderTypes
setAnimayaGroups(it.animayaGroups)
setAnimayaScales(it.animayaScales)

}
}
} catch (e: Exception) {
Expand Down
35 changes: 35 additions & 0 deletions src/main/kotlin/jagex/AnimationState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package jagex;

public enum AnimationState implements MouseWheel {

DEFAULT(0, 0),
CUSTOM1(1, 1),
CUSTOM2(2, 2),
REPEAT(3, 3),
MIRROR(4, 4);

final int field1508;
final int field1507;

AnimationState(int var3, int var4) {
this.field1508 = var3;
this.field1507 = var4;
}

static AnimationState method2292(int var0) {
AnimationState var1 = (AnimationState)class4.findEnumerated(method2852(), var0);
if (var1 == null) {
var1 = DEFAULT;
}

return var1;
}

public int rsOrdinal() {
return this.field1507;
}

static AnimationState[] method2852() {
return new AnimationState[]{AnimationState.DEFAULT, AnimationState.CUSTOM1, AnimationState.CUSTOM2, AnimationState.REPEAT, AnimationState.MIRROR};
}
}
137 changes: 137 additions & 0 deletions src/main/kotlin/jagex/Bone.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package jagex;

public class Bone {

public final int index;
public Bone parentBone;
float[][] rotations;
final BoneTransform[] boneTransforms;
BoneTransform[] computedBoneTransforms;
BoneTransform[] finalBoneTransforms;
BoneTransform baseTransform = new BoneTransform();
boolean baseTransformUpdate = true;
BoneTransform globalTransform = new BoneTransform();
boolean globalTransformUpdated = true;
BoneTransform localTransform = new BoneTransform();
float[][] inverseBindMatrices;
float[][] bindMatrices;
float[][] positions;

public Bone(int transformCount, Buffer buffer, boolean readTransforms) {
this.index = buffer.readShort();
this.boneTransforms = new BoneTransform[transformCount];
this.computedBoneTransforms = new BoneTransform[this.boneTransforms.length];
this.finalBoneTransforms = new BoneTransform[this.boneTransforms.length];
this.rotations = new float[this.boneTransforms.length][3];

for(int i = 0; i < this.boneTransforms.length; ++i) {
this.boneTransforms[i] = new BoneTransform(buffer, readTransforms);
this.rotations[i][0] = buffer.readIntAsFloat();
this.rotations[i][1] = buffer.readIntAsFloat();
this.rotations[i][2] = buffer.readIntAsFloat();
}

this.updateTransforms();
}

void updateTransforms() {
this.inverseBindMatrices = new float[this.boneTransforms.length][3];
this.bindMatrices = new float[this.boneTransforms.length][3];
this.positions = new float[this.boneTransforms.length][3];
BoneTransform tempTransform;
synchronized(BoneTransform.classPool) {
if (BoneTransform.poolSize == 0) {
tempTransform = new BoneTransform();
} else {
BoneTransform.classPool[--BoneTransform.poolSize].identityMatrix();
tempTransform = BoneTransform.classPool[BoneTransform.poolSize];
}
}

BoneTransform transform = tempTransform;

for(int i = 0; i < this.boneTransforms.length; ++i) {
BoneTransform bone = this.getBoneTransform(i);
transform.copy(bone);
transform.normalize();
this.inverseBindMatrices[i] = transform.extractRotation();
this.bindMatrices[i][0] = bone.matrix[12];
this.bindMatrices[i][1] = bone.matrix[13];
this.bindMatrices[i][2] = bone.matrix[14];
this.positions[i] = bone.extractScale();
}

transform.release();
}

BoneTransform getBoneTransform(int index) {
return this.boneTransforms[index];
}

BoneTransform getComputedBoneTransform(int index) {
if (this.computedBoneTransforms[index] == null) {
this.computedBoneTransforms[index] = new BoneTransform(this.getBoneTransform(index));
if (this.parentBone != null) {
this.computedBoneTransforms[index].combine(this.parentBone.getComputedBoneTransform(index));
} else {
this.computedBoneTransforms[index].combine(BoneTransform.identity);
}
}

return this.computedBoneTransforms[index];
}

BoneTransform getFinalBoneTransform(int index) {
if (this.finalBoneTransforms[index] == null) {
this.finalBoneTransforms[index] = new BoneTransform(this.getComputedBoneTransform(index));
this.finalBoneTransforms[index].normalize();
}

return this.finalBoneTransforms[index];
}

void setBaseTransform(BoneTransform var1) {
this.baseTransform.copy(var1);
this.baseTransformUpdate = true;
this.globalTransformUpdated = true;
}

BoneTransform getBaseTransform() {
return this.baseTransform;
}

BoneTransform getGlobalTransform() {
if (this.baseTransformUpdate) {
this.globalTransform.copy(this.getBaseTransform());
if (this.parentBone != null) {
this.globalTransform.combine(this.parentBone.getGlobalTransform());
}

this.baseTransformUpdate = false;
}

return this.globalTransform;
}

public BoneTransform getTransform(int index) {
if (this.globalTransformUpdated) {
this.localTransform.copy(this.getFinalBoneTransform(index));
this.localTransform.combine(this.getGlobalTransform());
this.globalTransformUpdated = false;
}

return this.localTransform;
}

float[] getInverseBindMatrix(int index) {
return this.inverseBindMatrices[index];
}

float[] getBindMatrix(int index) {
return this.bindMatrices[index];
}

float[] getPosition(int index) {
return this.positions[index];
}
}
Loading

0 comments on commit 13312b7

Please sign in to comment.