Skip to content

Commit

Permalink
Overwritten overwrites
Browse files Browse the repository at this point in the history
- Add mixinextras and remove overwrite
- Merge AsyncFontTexture and FontTexture

Signed-off-by: Jozufozu <jozsefaug@gmail.com>
  • Loading branch information
IThundxr authored and Jozufozu committed Sep 26, 2024
1 parent 463f60a commit bf15b20
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 371 deletions.
2 changes: 2 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ jarSets {
dependencies {
modCompileOnly("net.fabricmc:fabric-loader:${property("fabric_loader_version")}")

compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.1")!!)

testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,146 +1,59 @@
package dev.engine_room.flywheel.backend.mixin;

import java.util.Arrays;
import java.util.function.IntFunction;

import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;

import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;

import net.minecraft.client.gui.font.CodepointMap;

@Mixin(CodepointMap.class)
public class CodePointMapMixin<T> {
@Shadow
@Final
private T[][] blockMap;

@Shadow
@Final
private T[] empty;

@Shadow
@Final
private IntFunction<T[]> blockConstructor;

@Unique
private final Object flywheel$lock = new Object();

/**
* @author
* @reason
*/
@Overwrite
public void clear() {
@WrapMethod(method = "clear")
private void flywheel$wrapClearAsSynchronized(Operation<Void> original) {
synchronized (flywheel$lock) {
Arrays.fill(this.blockMap, this.empty);
original.call();
}
}

/**
* @author
* @reason
*/
@Nullable
@Overwrite
public T get(int index) {
int i = index >> 8;
int j = index & 0xFF;
@WrapMethod(method = "get")
private T flywheel$wrapGetAsSynchronized(int index, Operation<T> original) {
synchronized (flywheel$lock) {
return this.blockMap[i][j];
return original.call(index);
}
}

/**
* @author
* @reason
*/
@Nullable
@Overwrite
public T put(int index, T value) {
int i = index >> 8;
int j = index & 0xFF;
T object;
@WrapMethod(method = "put")
private T flywheel$wrapPutAsSynchronized(int index, T value, Operation<T> original) {
synchronized (flywheel$lock) {
T[] objects = this.blockMap[i];
if (objects == this.empty) {
objects = this.blockConstructor.apply(256);
this.blockMap[i] = objects;
objects[j] = value;
return null;
}
object = objects[j];
objects[j] = value;
return original.call(index, value);
}
return object;
}

/**
* @author
* @reason
*/
@Overwrite
public T computeIfAbsent(int index, IntFunction<T> valueIfAbsentGetter) {
int i = index >> 8;
int j = index & 0xFF;
T out;
@WrapMethod(method = "computeIfAbsent")
private T flywheel$wrapComputeIfAbsentAsSynchronized(int index, IntFunction<T> valueIfAbsentGetter, Operation<T> original) {
synchronized (flywheel$lock) {
T[] objects = this.blockMap[i];
T object = objects[j];
if (object != null) {
return object;
}
if (objects == this.empty) {
objects = this.blockConstructor.apply(256);
this.blockMap[i] = objects;
}
out = valueIfAbsentGetter.apply(index);
objects[j] = out;
return original.call(index, valueIfAbsentGetter);
}
return out;
}

/**
* @author
* @reason
*/
@Nullable
@Overwrite
public T remove(int index) {
int i = index >> 8;
int j = index & 0xFF;
T object;
@WrapMethod(method = "remove")
private T flywheel$wrapRemoveAsSynchronized(int index, Operation<T> original) {
synchronized (flywheel$lock) {
T[] objects = this.blockMap[i];
if (objects == this.empty) {
return null;
}
object = objects[j];
objects[j] = null;
return original.call(index);
}
return object;
}

/**
* @author
* @reason
*/
@Overwrite
public void forEach(CodepointMap.Output<T> output) {
@WrapMethod(method = "forEach")
private void flywheel$wrapForEachAsSynchronized(CodepointMap.Output<T> output, Operation<Void> original) {
synchronized (flywheel$lock) {
for (int i = 0; i < this.blockMap.length; ++i) {
T[] objects = this.blockMap[i];
if (objects == this.empty) continue;
for (int j = 0; j < objects.length; ++j) {
T object = objects[j];
if (object == null) continue;
int k = i << 8 | j;
output.accept(k, object);
}
}
original.call(output);
}
}
}
Loading

0 comments on commit bf15b20

Please sign in to comment.