-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add mixinextras and remove overwrite - Merge AsyncFontTexture and FontTexture Signed-off-by: Jozufozu <[email protected]>
- Loading branch information
Showing
11 changed files
with
186 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 0 additions & 159 deletions
159
common/src/backend/java/dev/engine_room/flywheel/backend/font/AsyncFontTexture.java
This file was deleted.
Oops, something went wrong.
129 changes: 21 additions & 108 deletions
129
common/src/backend/java/dev/engine_room/flywheel/backend/mixin/CodePointMapMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.