Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

ASM long -> 3 int transformation for light engine #84

Open
wants to merge 65 commits into
base: MC_1.18
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
050d5c8
Add processCubeUnloads to ASM transformer
Barteks2x Feb 18, 2021
c9847d5
Add scheduleCubeUnload to ASM transformer
Barteks2x Feb 18, 2021
857a540
Add saveAllCubes to ASM transformer, prepare for adding cubeSave
Barteks2x Feb 18, 2021
206349d
Add cubeSave to ASM transformer
Barteks2x Feb 18, 2021
972d662
Added basic remapping
BelgianSalamander Sep 27, 2021
ffa599f
ASM to change computedLevels and queues in DynamicGraphMinFixedPoint …
CursedFlames Sep 25, 2021
4f3033f
Fixed method remapping
BelgianSalamander Sep 28, 2021
3cc91ca
Added data flow analysis
BelgianSalamander Sep 30, 2021
be9196f
SkyLightEngine now remaps fine
BelgianSalamander Oct 5, 2021
6ec4ba5
Created LinkedInt3HashSet. Still very buggy
BelgianSalamander Oct 7, 2021
0d30ddf
Fixed LinkedInt3HashSet
BelgianSalamander Oct 7, 2021
7348981
Added LinkedInt3HashSet to DynamicGraphMinFixedPoint
BelgianSalamander Oct 7, 2021
70ddf6e
implement a fast hashmap for 3D integer points to unsigned byte values
DaMatrix Oct 7, 2021
06eaac7
add poll method to Int3UByteLinkedHashMap
DaMatrix Oct 7, 2021
d0ff0fe
Added removeIf, MinPoint abstract methods and annotations
BelgianSalamander Nov 17, 2021
b9c1df6
Nearly finished DynamicGraphMinFixedPoint transform
BelgianSalamander Nov 19, 2021
b1592f0
Added TypeTransformer system
BelgianSalamander Jan 3, 2022
aa0be02
Started fixing DUP and SWAP
BelgianSalamander Jan 4, 2022
7e1b02e
Fixed new getSyntheticEmitter
BelgianSalamander Jan 10, 2022
d16ad40
Created TypeTransformerMethods test
BelgianSalamander Jan 11, 2022
eef8984
Can now load pre-transformed classes from .mixin.out
BelgianSalamander Jan 11, 2022
0ff1e11
Added basic support for mixin's invokers
BelgianSalamander Jan 12, 2022
9ddf891
Fixed unit test
BelgianSalamander Jan 12, 2022
f09903c
Added interface system
BelgianSalamander Jan 13, 2022
70336fc
Added variables to JSONBytecodeFactory. Worlds load!!!
BelgianSalamander Jan 13, 2022
44c87ed
Fixed last warning!
BelgianSalamander Jan 13, 2022
59668b9
Removed class duplication
BelgianSalamander Jan 31, 2022
2cdd66c
Add ConstructorReplacer
BelgianSalamander Jan 31, 2022
e2be851
Replaced interface system with better invoker replacement
BelgianSalamander Jan 31, 2022
e548cbc
Small cleanup
BelgianSalamander Feb 1, 2022
48e4060
Temporary fix for CubicAquifer ArrayIndexOutOfBoundsException for lar…
BelgianSalamander Feb 1, 2022
854ec76
Fixed checkstyle syntax issues
BelgianSalamander Feb 1, 2022
72b9ea7
Passes CheckStyle
BelgianSalamander Feb 1, 2022
a88cecf
Documentation
BelgianSalamander Feb 8, 2022
16f3602
Fixed something from previous commit
BelgianSalamander Feb 9, 2022
c381b0e
Added type inference unit test
BelgianSalamander Feb 10, 2022
733c15c
Added test for config
BelgianSalamander Feb 11, 2022
9e68f02
Merge branch 'MC_1.17' into MC_1.17_lightEngineAsm
BelgianSalamander Feb 13, 2022
b776291
Fixed mistake from merge
BelgianSalamander Feb 19, 2022
f0f63e6
Start adding info to crash log
BelgianSalamander May 22, 2022
31449f4
Merge 1.18 into ASM
BelgianSalamander Nov 15, 2022
4d8dda3
Automatically map the tt config
BelgianSalamander Nov 18, 2022
bd522ad
Get type info at compile time
BelgianSalamander Nov 18, 2022
271a93c
Actually load type info
BelgianSalamander Nov 20, 2022
c50ddd6
Worlds load!
BelgianSalamander Nov 22, 2022
7fe5b81
Fix Aquifer
BelgianSalamander Nov 22, 2022
9f0d28f
Much needed clean-up
BelgianSalamander Nov 22, 2022
8bea7aa
Make tests work
BelgianSalamander Nov 22, 2022
f8b060b
Merge with upstream
BelgianSalamander Apr 28, 2023
af0c492
Fix loom issues
BelgianSalamander Apr 28, 2023
ba21029
Remove method alias system - don't know why I added it in the first p…
BelgianSalamander Jun 25, 2023
bc4109a
Start docs
BelgianSalamander Jun 25, 2023
660f14a
Bump dasm and javaheaders version to get around jitpack issues
Barteks2x Jun 25, 2023
7b77abc
Remap names in ASMConfigPlugin for dasm
Barteks2x Jun 25, 2023
85a4c56
Fix checkstyle and CubicChunksCore submodule
Barteks2x Jun 25, 2023
48cc80a
Merge remote-tracking branch 'upstream/MC_1.18' into MC_1.17_lightEng…
BelgianSalamander Jun 25, 2023
b5dc953
Small merge fixes
BelgianSalamander Jun 25, 2023
06fa6e1
Make type hint specification more sensible
BelgianSalamander Jul 1, 2023
a0db0a3
Start addressing minor review comments
BelgianSalamander Jul 4, 2023
91e9a13
Fix unit test issue
BelgianSalamander Jul 5, 2023
c933a82
More small fixes + renaming
BelgianSalamander Jul 16, 2023
5c31315
pass checkstyle
CursedFlames Jul 16, 2023
69b25f4
remove unused invokers field on Config
CursedFlames Jul 16, 2023
e330b41
misc minor tweaks
CursedFlames Jul 16, 2023
5f647d8
Int3List bounds checking + misc
CursedFlames Jul 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,13 @@

<!-- Metrics -->

<module name="CyclomaticComplexity"/>
<module name="CyclomaticComplexity">
<property name="switchBlockAsSingleDecisionPoint" value="true"/>
<property name="max" value="15"/>
<property name="tokens" value="LITERAL_WHILE , LITERAL_DO , LITERAL_FOR , LITERAL_IF , LITERAL_SWITCH , LITERAL_CASE , LITERAL_CATCH , QUESTION"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure of the consequences of this; would like others to review

</module>
<!-- <module name="JavaNCSS"/> TODO fix and enable -->

<module name="NPathComplexity"/>

<!-- Misc -->
Expand Down
13 changes: 8 additions & 5 deletions config/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

<suppressions>
<!-- suppress for time measurement code -->
<suppress checks="InnerAssignment" files="DebugVisualization.java|Int3HashSet.java"/>
<suppress checks="InnerAssignment" files="DebugVisualization.java|Int3HashSet.java|LinkedInt3HashSet.java|Int3UByteLinkedHashMap.java|Int3List.java"/>
<!-- class transformers will often repeat the same class name string literal -->
<suppress checks="MultipleStringLiterals" files=".*Transformer\.java"/>
<suppress checks="MultipleStringLiterals" files=".*Transformer\.java|ASMConfigPlugin\.java|TypeInferenceTest.java|ConfigTest.java"/>
<!-- implementations of ChunkAccess, getHeight for heightmap and world height are semantically not overloads but have the same name -->
<suppress checks="OverloadMethodsDeclarationOrder"
files="SectionSizeCubeAccessWrapper.java|LevelCube.java|ProtoCube.java|ImposterProtoCube.java|NoiseAndSurfaceBuilderHelper.java|CubeWorldGenRegion.java"/>
Expand All @@ -35,8 +35,11 @@
<!-- Mixins may have an underscore to separate target from functionality -->
<suppress checks="TypeName" files=".*Mixin.*\.java"/>
<suppress checks="DeclarationOrder" files="MixinNaturalSpawner.java|Int3HashSet.java"/>
<suppress checks="HiddenField" files="Int3HashSet.java"/>
<suppress checks="NoFinalizer" files="Int3HashSet.java"/>
<suppress checks="HiddenField" files="Int3HashSet.java|LinkedInt3HashSet.java|Int3UByteLinkedHashMap.java|Int3List.java"/>
<suppress checks="NoFinalizer" files="Int3HashSet.java|LinkedInt3HashSet.java|Int3UByteLinkedHashMap.java|Int3List.java"/>
<suppress checks="EmptyForIteratorPad" files="Int3HashSet.java|Int3HashSetTest.java"/>
<suppress checks="ModifiedControlVariable" files="Int3HashSetTest.java"/>
<suppress checks="EmptyBlock" files="Int3UByteLinkedHashMapTest.java"/>
<suppress checks="ModifiedControlVariable" files="Int3HashSetTest.java|Int3UByteLinkedHashMapTest.java"/>
<!-- TODO These need refactoring -->
<suppress checks="CyclomaticComplexity" files="Int3UByteLinkedHashMap.java"/>
</suppressions>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ modid=cubicchunks
# Fabric Properties - https://fabricmc.net/versions.html
minecraft_version=1.17.1
yarn_version=1.17.1+build.37
loader_version=0.11.6
loader_version=0.11.7

# Dependencies
fabric_version=0.37.2+1.17
CursedFlames marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void main() {
private static float screenWidth = 854.0f;
private static float screenHeight = 480f;
private static GLCapabilities debugGlCapabilities;
private static boolean enabled;
private static boolean enabled = false;

private static VisualizationMode mode = VisualizationMode.AVAILABLE_MODES[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,16 @@ private int getIndex(int x, int y, int z) {
int localX = x - this.minGridX;
int localY = y - this.minGridY;
int localZ = z - this.minGridZ;
return (localY * this.gridSizeZ + localZ) * this.gridSizeX + localX;

int index = (localY * this.gridSizeZ + localZ) * this.gridSizeX + localX;

//FIXME: Because of the way the cache is implemented, this can cause an ArrayIndexOutOfBoundsException.
//The coordinates are unpacked from longs so when outside the proper range, they wrap around and this returns nonsense values.
Cyclonit marked this conversation as resolved.
Show resolved Hide resolved
if (index < 0 || index >= this.aquiferCache.length) {
return 0;
}

return index;
}

@Override
Expand All @@ -117,6 +126,7 @@ public BlockState computeState(BaseStoneSource stoneSource, int x, int y, int z,
int firstDistance2 = Integer.MAX_VALUE;
int secondDistance2 = Integer.MAX_VALUE;
int thirdDistance2 = Integer.MAX_VALUE;

long firstSource = 0;
long secondSource = 0;
long thirdSource = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package io.github.opencubicchunks.cubicchunks.mixin;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

import io.github.opencubicchunks.cubicchunks.mixin.transform.MainTransformer;
import net.fabricmc.loader.api.FabricLoader;
import io.github.opencubicchunks.cubicchunks.utils.Utils;
import net.fabricmc.loader.api.MappingResolver;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
Expand Down Expand Up @@ -41,21 +45,28 @@ public class ASMConfigPlugin implements IMixinConfigPlugin {
}

@Override public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
MappingResolver map = FabricLoader.getInstance().getMappingResolver();
MappingResolver map = Utils.getMappingResolver();
boolean modified = false;
String chunkMapDistanceManager = map.mapClassName("intermediary", "net.minecraft.class_3898$class_3216");
String chunkMap = map.mapClassName("intermediary", "net.minecraft.class_3898");
String chunkHolder = map.mapClassName("intermediary", "net.minecraft.class_3193");
String naturalSpawner = map.mapClassName("intermediary", "net.minecraft.class_1948");

if (targetClassName.equals(chunkMapDistanceManager)) {
modified = true;
MainTransformer.transformProxyTicketManager(targetClass);
} else if (targetClassName.equals(chunkMap)) {
modified = true;
MainTransformer.transformChunkManager(targetClass);
} else if (targetClassName.equals(chunkHolder)) {
modified = true;
MainTransformer.transformChunkHolder(targetClass);
} else if (targetClassName.equals(naturalSpawner)) {
modified = true;
MainTransformer.transformNaturalSpawner(targetClass);
} else {
}

if (!modified) {
return;
}

Expand All @@ -67,20 +78,74 @@ public class ASMConfigPlugin implements IMixinConfigPlugin {
addMethod.setAccessible(true);

ClassInfo ci = ClassInfo.forName(targetClassName);

//Field fieldField = ClassInfo.class.getDeclaredField("fields");
//fieldField.setAccessible(true);
//Set<ClassInfo.Field> fields = (Set<ClassInfo.Field>) fieldField.get(ci);

Set<String> existingMethods = ci.getMethods().stream().map(x -> x.getName() + x.getDesc()).collect(Collectors.toSet());
for (MethodNode method : targetClass.methods) {
if (!existingMethods.contains(method.name + method.desc)) {
addMethod.invoke(ci, method, false);
}
}
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {

/*//Modify descriptors of modified fields
for(FieldNode field: targetClass.fields){
//Should only remove one
fields.removeIf(fieldInfo -> fieldInfo.getName().equals(field.name) && !fieldInfo.getDesc().equals(field.desc));
fields.add(ci.new Field(field, false));
}*/
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException /*| NoSuchFieldException*/ e) {
throw new IllegalStateException(e);
}


}

@Override public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
MappingResolver map = Utils.getMappingResolver();
String dynamicGraphMinFixedPoint = map.mapClassName("intermediary", "net.minecraft.class_3554");
String layerLightEngine = map.mapClassName("intermediary", "net.minecraft.class_3558");
String layerLightSectionStorage = map.mapClassName("intermediary", "net.minecraft.class_3560");
String blockLightSectionStorage = map.mapClassName("intermediary", "net.minecraft.class_3547");
String skyLightSectionStorage = map.mapClassName("intermediary", "net.minecraft.class_3569");
String sectionPos = map.mapClassName("intermediary", "net.minecraft.class_4076");
String blockLightEngine = map.mapClassName("intermediary", "net.minecraft.class_3552");
String skyLightEngine = map.mapClassName("intermediary", "net.minecraft.class_3572");

Set<String> defaulted = Set.of(
blockLightSectionStorage,
skyLightSectionStorage,
blockLightEngine,
skyLightEngine
);

if (targetClassName.equals(dynamicGraphMinFixedPoint)) {
MainTransformer.transformDynamicGraphMinFixedPoint(targetClass);
} else if (targetClassName.equals(layerLightEngine)) {
MainTransformer.transformLayerLightEngine(targetClass);
} else if (targetClassName.equals(layerLightSectionStorage)) {
MainTransformer.transformLayerLightSectionStorage(targetClass);
} else if (targetClassName.equals(sectionPos)) {
MainTransformer.transformSectionPos(targetClass);
} else if (defaulted.contains(targetClassName)) {
MainTransformer.defaultTransform(targetClass);
} else {
return;
}

//Save it without computing extra stuff (like maxs) which means that if the frames are wrong and mixin fails to save it, it will be saved elsewhere
Path savePath = Utils.getGameDir().resolve("longpos-out").resolve(targetClassName.replace('.', '/') + ".class");
try {
Files.createDirectories(savePath.getParent());

ClassWriter writer = new ClassWriter(0);
targetClass.accept(writer);
Files.write(savePath, writer.toByteArray());
System.out.println("Saved " + targetClassName + " to " + savePath);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
package io.github.opencubicchunks.cubicchunks.mixin.asm.common;

import net.minecraft.core.SectionPos;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.world.level.NaturalSpawner;
import net.minecraft.world.level.lighting.BlockLightEngine;
import net.minecraft.world.level.lighting.BlockLightSectionStorage;
import net.minecraft.world.level.lighting.DynamicGraphMinFixedPoint;
import net.minecraft.world.level.lighting.LayerLightEngine;
import net.minecraft.world.level.lighting.LayerLightSectionStorage;
import net.minecraft.world.level.lighting.SkyLightEngine;
import net.minecraft.world.level.lighting.SkyLightSectionStorage;
import org.spongepowered.asm.mixin.Mixin;

@Mixin({
ChunkMap.DistanceManager.class,
ChunkMap.class,
ChunkHolder.class,
NaturalSpawner.class
DynamicGraphMinFixedPoint.class,
NaturalSpawner.class,

//Long Pos Transforms
BlockLightEngine.class,
SkyLightEngine.class,
LayerLightEngine.class,
SectionPos.class,
LayerLightSectionStorage.class,
SkyLightSectionStorage.class,
BlockLightSectionStorage.class
})
public class MixinAsmTarget {
// intentionally empty
Expand Down
Loading