Skip to content

Commit

Permalink
Refactoring: Perlin noise (#2)
Browse files Browse the repository at this point in the history
* refactor: start to perlin noise

* refactor: move noise statics

* refactor: additional noise methods/fields
  • Loading branch information
MatthewBishop authored Jan 23, 2024
1 parent be005b3 commit 2244fb6
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 170 deletions.
189 changes: 107 additions & 82 deletions client/src/main/java/Class57.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,80 @@
@OriginalClass("client!os")
public abstract class Class57 {

@OriginalMember(owner = "client!q", name = "n", descriptor = "[I")
public static final int[] fadeCurves = new int[4096];

static {
for (@Pc(11) int local11 = 0; local11 < 4096; local11++) {
fadeCurves[local11] = fade(local11);
}
}

@OriginalMember(owner = "client!os", name = "j", descriptor = "[S")
private short[] aShortArray126;
private short[] powerOfTwo;

@OriginalMember(owner = "client!os", name = "c", descriptor = "I")
private int anInt6714 = 4;
private int yFactor = 4;

@OriginalMember(owner = "client!os", name = "e", descriptor = "I")
private int anInt6716 = 4;
private int zFactor = 4;

@OriginalMember(owner = "client!os", name = "d", descriptor = "I")
private int anInt6715 = 0;
private int seed = 0;

@OriginalMember(owner = "client!os", name = "g", descriptor = "I")
private int anInt6718 = 4;
private int xFactor = 4;

@OriginalMember(owner = "client!os", name = "l", descriptor = "[S")
private final short[] aShortArray127 = new short[512];
private final short[] pImp = new short[512];

@OriginalMember(owner = "client!os", name = "k", descriptor = "I")
protected int anInt6721 = 4;
protected int factorsOfTwo = 4;

@OriginalMember(owner = "client!os", name = "<init>", descriptor = "(IIIII)V")
protected Class57(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3, @OriginalArg(4) int arg4) {
this.anInt6718 = arg2;
this.anInt6714 = arg3;
this.anInt6715 = arg0;
this.anInt6721 = arg1;
this.anInt6716 = arg4;
this.method6012();
this.method6014();
protected Class57(@OriginalArg(0) int seed, @OriginalArg(1) int factorsOfTwo, @OriginalArg(2) int xFactor, @OriginalArg(3) int yFactor, @OriginalArg(4) int zFactor) {
this.xFactor = xFactor;
this.yFactor = yFactor;
this.seed = seed;
this.factorsOfTwo = factorsOfTwo;
this.zFactor = zFactor;
this.initPerlin1();
this.initPerlin2();
}

@OriginalMember(owner = "client!jr", name = "a", descriptor = "(IIIII)I")
private static int grad(@OriginalArg(0) int z, @OriginalArg(2) int x, @OriginalArg(3) int y, @OriginalArg(4) int hash) {
@Pc(7) int h = hash & 0xF;
@Pc(16) int u = h < 8 ? x : y;
@Pc(40) int v = h < 4 ? y : (h == 12 || h == 14 ? x : z);
return ((h & 0x2) == 0 ? v : -v) + ((h & 0x1) == 0 ? u : -u);
}

@OriginalMember(owner = "client!pj", name = "b", descriptor = "(IB)I")
private static int fade(@OriginalArg(0) int t) {
@Pc(13) int depth = t * (t * t >> 12) >> 12;
@Pc(19) int x = t * 6 - 61440;
@Pc(32) int y = (t * x >> 12) + 40960;
return y * depth >> 12;
}

@OriginalMember(owner = "client!os", name = "a", descriptor = "(III)V")
protected abstract void method6011(@OriginalArg(1) int arg0, @OriginalArg(2) int arg1);
protected abstract void apply(@OriginalArg(1) int arg0, @OriginalArg(2) int arg1);

@OriginalMember(owner = "client!os", name = "a", descriptor = "(B)V")
private void method6012() {
this.aShortArray126 = new short[this.anInt6721];
for (@Pc(12) int local12 = 0; local12 < this.anInt6721; local12++) {
this.aShortArray126[local12] = (short) Math.pow(2.0D, (double) local12);
private void initPerlin1() {
this.powerOfTwo = new short[this.factorsOfTwo];
for (@Pc(12) int local12 = 0; local12 < this.factorsOfTwo; local12++) {
this.powerOfTwo[local12] = (short) Math.pow(2.0D, (double) local12);
}
}

@OriginalMember(owner = "client!os", name = "a", descriptor = "(IIBI)V")
protected final void method6013() {
@Pc(12) int[] local12 = new int[128];
protected final void noise() {
@Pc(12) int[] widths = new int[128];
@Pc(15) int[] local15 = new int[128];
for (@Pc(17) int local17 = 0; local17 < 128; local17++) {
local12[local17] = (local17 << 12) / 128;
widths[local17] = (local17 << 12) / 128;
}
@Pc(38) int[] local38 = new int[16];
for (@Pc(40) int local40 = 0; local40 < 128; local40++) {
Expand All @@ -64,100 +89,100 @@ protected final void method6013() {
for (@Pc(60) int local60 = 0; local60 < 16; local60++) {
local38[local60] = (local60 << 12) / 16;
}
this.method6015();
this.setup();
for (@Pc(79) int local79 = 0; local79 < 16; local79++) {
for (@Pc(83) int local83 = 0; local83 < 128; local83++) {
for (@Pc(87) int local87 = 0; local87 < 128; local87++) {
for (@Pc(91) int local91 = 0; local91 < this.anInt6721; local91++) {
@Pc(100) int local100 = this.aShortArray126[local91] << 12;
@Pc(107) int local107 = local100 * this.anInt6716 >> 12;
@Pc(114) int local114 = local100 * this.anInt6714 >> 12;
@Pc(121) int local121 = this.anInt6718 * local100 >> 12;
@Pc(129) int local129 = local12[local87] * local100 >> 12;
@Pc(137) int local137 = local100 * local15[local83] >> 12;
@Pc(145) int local145 = local38[local79] * local100 >> 12;
@Pc(150) int local150 = local137 * this.anInt6714;
@Pc(155) int local155 = local145 * this.anInt6716;
@Pc(160) int local160 = local129 * this.anInt6718;
@Pc(164) int local164 = local160 >> 12;
@Pc(168) int local168 = local164 + 1;
@Pc(172) int local172 = local164 & 0xFF;
@Pc(176) int local176 = local150 >> 12;
@Pc(180) int local180 = local176 + 1;
@Pc(184) int local184 = local176 & 0xFF;
@Pc(188) int local188 = local155 >> 12;
@Pc(192) int local192 = local188 + 1;
if (local168 >= local121) {
local168 = 0;
for (@Pc(87) int x = 0; x < 128; x++) {
for (@Pc(91) int index = 0; index < this.factorsOfTwo; index++) {
@Pc(100) int factorOfTwo = this.powerOfTwo[index] << 12;
@Pc(107) int maxZ = factorOfTwo * this.zFactor >> 12;
@Pc(114) int maxY = factorOfTwo * this.yFactor >> 12;
@Pc(121) int maxX = this.xFactor * factorOfTwo >> 12;
@Pc(129) int local129 = widths[x] * factorOfTwo >> 12;
@Pc(137) int local137 = factorOfTwo * local15[local83] >> 12;
@Pc(145) int local145 = local38[local79] * factorOfTwo >> 12;
@Pc(150) int local150 = local137 * this.yFactor;
@Pc(155) int local155 = local145 * this.zFactor;
@Pc(160) int xo = local129 * this.xFactor;
@Pc(164) int x0 = xo >> 12;
@Pc(168) int x1 = x0 + 1;
@Pc(172) int x0u = x0 & 0xFF;
@Pc(176) int y0 = local150 >> 12;
@Pc(180) int y1 = y0 + 1;
@Pc(184) int y0u = y0 & 0xFF;
@Pc(188) int z0 = local155 >> 12;
@Pc(192) int z1 = z0 + 1;
if (x1 >= maxX) {
x1 = 0;
} else {
local168 &= 0xFF;
x1 &= 0xFF;
}
if (local114 > local180) {
local180 &= 0xFF;
if (maxY > y1) {
y1 &= 0xFF;
} else {
local180 = 0;
y1 = 0;
}
local188 &= 0xFF;
if (local192 >= local107) {
local192 = 0;
z0 &= 0xFF;
if (z1 >= maxZ) {
z1 = 0;
} else {
local192 &= 0xFF;
z1 &= 0xFF;
}
local145 = local155 & 0xFFF;
local137 = local150 & 0xFFF;
local129 = local160 & 0xFFF;
local129 = xo & 0xFFF;
@Pc(249) int local249 = local137 - 4096;
@Pc(253) int local253 = local145 - 4096;
@Pc(258) short local258 = this.aShortArray127[local188];
@Pc(262) int local262 = StockMarketOffer.anIntArray360[local145];
@Pc(266) int local266 = StockMarketOffer.anIntArray360[local137];
@Pc(271) short local271 = this.aShortArray127[local192];
@Pc(275) int local275 = StockMarketOffer.anIntArray360[local129];
@Pc(258) short local258 = this.pImp[z0];
@Pc(262) int w = fadeCurves[local145];
@Pc(266) int local266 = fadeCurves[local137];
@Pc(271) short local271 = this.pImp[z1];
@Pc(275) int local275 = fadeCurves[local129];
@Pc(279) int local279 = local129 - 4096;
@Pc(287) short local287 = this.aShortArray127[local180 + local258];
@Pc(294) short local294 = this.aShortArray127[local271 + local180];
@Pc(302) short local302 = this.aShortArray127[local184 + local271];
@Pc(309) short local309 = this.aShortArray127[local184 + local258];
@Pc(321) int local321 = Static169.method3211(local145, local129, local137, this.aShortArray127[local309 + local172]);
@Pc(333) int local333 = Static169.method3211(local145, local279, local137, this.aShortArray127[local168 + local309]);
@Pc(287) short local287 = this.pImp[y1 + local258];
@Pc(294) short local294 = this.pImp[local271 + y1];
@Pc(302) short local302 = this.pImp[y0u + local271];
@Pc(309) short local309 = this.pImp[y0u + local258];
@Pc(321) int local321 = grad(local145, local129, local137, this.pImp[local309 + x0u]);
@Pc(333) int local333 = grad(local145, local279, local137, this.pImp[x1 + local309]);
@Pc(344) int local344 = local321 + (local275 * (local333 - local321) >> 12);
@Pc(356) int local356 = Static169.method3211(local145, local129, local249, this.aShortArray127[local172 + local287]);
@Pc(368) int local368 = Static169.method3211(local145, local279, local249, this.aShortArray127[local287 + local168]);
@Pc(356) int local356 = grad(local145, local129, local249, this.pImp[x0u + local287]);
@Pc(368) int local368 = grad(local145, local279, local249, this.pImp[local287 + x1]);
@Pc(379) int local379 = ((local368 - local356) * local275 >> 12) + local356;
@Pc(390) int local390 = (local266 * (local379 - local344) >> 12) + local344;
@Pc(402) int local402 = Static169.method3211(local253, local129, local137, this.aShortArray127[local172 + local302]);
@Pc(415) int local415 = Static169.method3211(local253, local279, local137, this.aShortArray127[local168 + local302]);
@Pc(402) int local402 = grad(local253, local129, local137, this.pImp[x0u + local302]);
@Pc(415) int local415 = grad(local253, local279, local137, this.pImp[x1 + local302]);
@Pc(426) int local426 = (local275 * (local415 - local402) >> 12) + local402;
@Pc(438) int local438 = Static169.method3211(local253, local129, local249, this.aShortArray127[local294 + local172]);
@Pc(450) int local450 = Static169.method3211(local253, local279, local249, this.aShortArray127[local294 + local168]);
@Pc(438) int local438 = grad(local253, local129, local249, this.pImp[local294 + x0u]);
@Pc(450) int local450 = grad(local253, local279, local249, this.pImp[local294 + x1]);
@Pc(461) int local461 = (local275 * (local450 - local438) >> 12) + local438;
@Pc(473) int local473 = local426 + (local266 * (local461 - local426) >> 12);
this.method6011(local91, local390 + (local262 * (local473 - local390) >> 12));
this.apply(index, local390 + (w * (local473 - local390) >> 12));
}
this.method6017();
this.add();
}
}
}
}

@OriginalMember(owner = "client!os", name = "b", descriptor = "(B)V")
private void method6014() {
@Pc(12) Random local12 = new Random((long) this.anInt6715);
private void initPerlin2() {
@Pc(12) Random local12 = new Random((long) this.seed);
for (@Pc(14) int local14 = 0; local14 < 255; local14++) {
this.aShortArray127[local14] = (short) local14;
this.pImp[local14] = (short) local14;
}
for (@Pc(39) int local39 = 0; local39 < 255; local39++) {
@Pc(46) int local46 = 255 - local39;
@Pc(51) int local51 = Static382.method6361(local46, local12);
@Pc(56) short local56 = this.aShortArray127[local51];
this.aShortArray127[local51] = this.aShortArray127[local46];
this.aShortArray127[local46] = this.aShortArray127[local46 + 256] = local56;
@Pc(56) short local56 = this.pImp[local51];
this.pImp[local51] = this.pImp[local46];
this.pImp[local46] = this.pImp[local46 + 256] = local56;
}
}

@OriginalMember(owner = "client!os", name = "a", descriptor = "(I)V")
protected abstract void method6015();
protected abstract void setup();

@OriginalMember(owner = "client!os", name = "a", descriptor = "(Z)V")
protected abstract void method6017();
protected abstract void add();
}
42 changes: 21 additions & 21 deletions client/src/main/java/Class57_Sub1.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,51 @@
public class Class57_Sub1 extends Class57 {

@OriginalMember(owner = "client!eb", name = "r", descriptor = "I")
private int anInt6726;
private int elevation;

@OriginalMember(owner = "client!eb", name = "t", descriptor = "[B")
private byte[] aByteArray95;
private byte[] subData;

@OriginalMember(owner = "client!eb", name = "u", descriptor = "I")
private int anInt6728;
private int writerIndex;

@OriginalMember(owner = "client!eb", name = "n", descriptor = "[I")
private final int[] anIntArray466 = new int[this.anInt6721];
private final int[] pows = new int[this.factorsOfTwo];

@OriginalMember(owner = "client!eb", name = "<init>", descriptor = "(IIIIIF)V")
protected Class57_Sub1(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3, @OriginalArg(4) int arg4, @OriginalArg(5) float arg5) {
super(arg0, arg1, arg2, arg3, arg4);
for (@Pc(15) int local15 = 0; local15 < super.anInt6721; local15++) {
this.anIntArray466[local15] = (short) (Math.pow((double) arg5, (double) local15) * 4096.0D);
protected Class57_Sub1(@OriginalArg(0) int seed, @OriginalArg(1) int factorsOfTwo, @OriginalArg(2) int xFactor, @OriginalArg(3) int yFactor, @OriginalArg(4) int zFactor, @OriginalArg(5) float frequency) {
super(seed, factorsOfTwo, xFactor, yFactor, zFactor);
for (@Pc(15) int index = 0; index < super.factorsOfTwo; index++) {
this.pows[index] = (short) (Math.pow((double) frequency, (double) index) * 4096.0D);
}
}

@OriginalMember(owner = "client!eb", name = "a", descriptor = "(Z)V")
@Override
protected final void method6017() {
this.anInt6726 = Math.abs(this.anInt6726);
if (this.anInt6726 >= 4096) {
this.anInt6726 = 4095;
protected final void add() {
this.elevation = Math.abs(this.elevation);
if (this.elevation >= 4096) {
this.elevation = 4095;
}
this.method6020(this.anInt6728++, (byte) (this.anInt6726 >> 4));
this.anInt6726 = 0;
this.modify(this.writerIndex++, (byte) (this.elevation >> 4));
this.elevation = 0;
}

@OriginalMember(owner = "client!eb", name = "a", descriptor = "(III)V")
@Override
protected final void method6011(@OriginalArg(1) int arg0, @OriginalArg(2) int arg1) {
this.anInt6726 += this.anIntArray466[arg0] * arg1 >> 12;
protected final void apply(@OriginalArg(1) int index, @OriginalArg(2) int noise) {
this.elevation += this.pows[index] * noise >> 12;
}

@OriginalMember(owner = "client!eb", name = "a", descriptor = "(IB)V")
protected void method6020(@OriginalArg(0) int arg0, @OriginalArg(1) byte arg1) {
this.aByteArray95[this.anInt6728++] = (byte) ((arg1 >> 1 & 0x7F) + 127);
protected void modify(@OriginalArg(0) int arg0, @OriginalArg(1) byte arg1) {
this.subData[this.writerIndex++] = (byte) ((arg1 >> 1 & 0x7F) + 127);
}

@OriginalMember(owner = "client!eb", name = "a", descriptor = "(I)V")
@Override
protected final void method6015() {
this.anInt6726 = 0;
this.anInt6728 = 0;
protected final void setup() {
this.elevation = 0;
this.writerIndex = 0;
}
}
16 changes: 8 additions & 8 deletions client/src/main/java/Class57_Sub1_Sub1.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public final class Class57_Sub1_Sub1 extends Class57_Sub1 {

@OriginalMember(owner = "client!v", name = "x", descriptor = "[B")
private byte[] aByteArray96;
private byte[] data;

@OriginalMember(owner = "client!v", name = "<init>", descriptor = "()V")
public Class57_Sub1_Sub1() {
Expand All @@ -16,19 +16,19 @@ public Class57_Sub1_Sub1() {

@OriginalMember(owner = "client!v", name = "a", descriptor = "(IB)V")
@Override
protected void method6020(@OriginalArg(0) int arg0, @OriginalArg(1) byte arg1) {
protected void modify(@OriginalArg(0) int arg0, @OriginalArg(1) byte arg1) {
@Pc(3) int local3 = arg0 * 2;
@Pc(12) byte local12 = (byte) ((arg1 >> 1 & 0x7F) + 127);
@Pc(15) int local15 = local3;
@Pc(16) int local16 = local3 + 1;
this.aByteArray96[local15] = local12;
this.aByteArray96[local16] = local12;
this.data[local15] = local12;
this.data[local16] = local12;
}

@OriginalMember(owner = "client!v", name = "b", descriptor = "(III)[B")
public byte[] method6022() {
this.aByteArray96 = new byte[524288];
this.method6013();
return this.aByteArray96;
public byte[] generate() {
this.data = new byte[524288];
this.noise();
return this.data;
}
}
Loading

0 comments on commit 2244fb6

Please sign in to comment.