Skip to content

Commit

Permalink
feat: compile step tree navigation in ic workbench
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTJP committed May 1, 2024
1 parent 0a32fe5 commit 3d055ed
Show file tree
Hide file tree
Showing 14 changed files with 653 additions and 83 deletions.
9 changes: 8 additions & 1 deletion core/src/main/java/mrtjp/projectred/redui/ScrollBarNode.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package mrtjp.projectred.redui;

import codechicken.lib.colour.EnumColour;
import com.mojang.blaze3d.vertex.PoseStack;
import mrtjp.projectred.lib.Point;
import mrtjp.projectred.lib.Rect;
import mrtjp.projectred.lib.Size;
import net.minecraft.client.gui.GuiComponent;

public abstract class ScrollBarNode extends AbstractGuiNode {

Expand All @@ -28,7 +30,12 @@ public void setSliderSize(int w, int h) {
@Override
public void drawBack(PoseStack stack, Point mouse, float partialFrame) {

// Draw scroll bar background
// Draw semi-transparent grey background
int x = getFrame().x();
int y = getFrame().y();
GuiComponent.fillGradient(stack, x, y, x + getFrame().width(), y + getFrame().height(), EnumColour.BLACK.argb(127), EnumColour.BLACK.argb(127), 0);

// Draw slider rectangle
drawSlider(stack, sliderFrame);
}

Expand Down
39 changes: 39 additions & 0 deletions core/src/main/java/mrtjp/projectred/redui/SpriteButtonNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package mrtjp.projectred.redui;

import com.mojang.blaze3d.vertex.PoseStack;

import java.util.function.Supplier;

public class SpriteButtonNode extends AbstractButtonNode {

private RedUISprite sprite;
private Runnable clickReceiver = () -> { };
private Supplier<Boolean> isDisabledProvider = () -> false;

public SpriteButtonNode(RedUISprite sprite) {
this.sprite = sprite;
}

public void setClickReceiver(Runnable clickReceiver) {
this.clickReceiver = clickReceiver;
}

public void setIsDisabledProvider(Supplier<Boolean> isDisabledProvider) {
this.isDisabledProvider = isDisabledProvider;
}

@Override
protected boolean isButtonDisabled() {
return isDisabledProvider.get();
}

@Override
protected void onButtonClicked() {
clickReceiver.run();
}

@Override
protected void drawButtonBody(PoseStack stack, boolean mouseover) {
blitSpriteCentered(stack, sprite);
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.19.2 2024-04-05T16:47:53.695184 ProjectRed-Fabrication Languages: en_us
dd1226a77b7ec67a85f9d088ba5a3f78a16f2bf4 assets/projectred_fabrication/lang/en_us.json
// 1.19.2 2024-04-29T13:40:44.325463 ProjectRed-Fabrication Languages: en_us
5da5b8cc9a7b6e62337421001761920875beea36 assets/projectred_fabrication/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,53 @@
"item.projectred_fabrication.rough_silicon_wafer": "Rough Silicon Wafer",
"item.projectred_fabrication.valid_die": "Valid Die",
"itemGroup.projectred_fabrication": "Project Red: Fabrication",
"projectred_fabrication.dimensions.dies": "%d dies x %d dies",
"projectred_fabrication.dimensions.dies_total": "%d dies x %d dies (%d dies^2)",
"projectred_fabrication.dimensions.nm": "%d nm x %d nm",
"projectred_fabrication.dimensions.nm_total": "%d nm x %d nm (%d nm^2)",
"projectred_fabrication.dimensions.tiles": "%d tiles x %d tiles",
"projectred_fabrication.dimensions.tiles_total": "%d tiles x %d tiles (%d tiles^2)",
"projectred_fabrication.compile.stack": "Stack",
"projectred_fabrication.compile.step.check_flat_maps": "Check flat maps",
"projectred_fabrication.compile.step.check_flat_maps.desc": "Check for flat maps to merge",
"projectred_fabrication.compile.step.check_tile_maps": "Check tile maps",
"projectred_fabrication.compile.step.check_tile_maps.desc": "Check for tile maps to compile",
"projectred_fabrication.compile.step.merge_flat_map": "Compile flat map",
"projectred_fabrication.compile.step.merge_flat_map.desc": "Merge flat map",
"projectred_fabrication.compile.step.merge_tile_map": "Compile tile map",
"projectred_fabrication.compile.step.merge_tile_map.desc": "Compile tile map",
"projectred_fabrication.compile.step.merge_tile_map_add_remaps": "Add remaps",
"projectred_fabrication.compile.step.merge_tile_map_add_remaps.desc": "Declare remaps",
"projectred_fabrication.compile.step.merge_tile_map_alloc": "Alloc",
"projectred_fabrication.compile.step.merge_tile_map_alloc.desc": "Output registers and gate allocation",
"projectred_fabrication.compile.step.merge_tile_map_collect": "Collect",
"projectred_fabrication.compile.step.merge_tile_map_collect.desc": "Gates and registers collected",
"projectred_fabrication.compile.step.merge_tile_map_consume_remaps": "Remap",
"projectred_fabrication.compile.step.merge_tile_map_consume_remaps.desc": "Apply remaps",
"projectred_fabrication.compile.step.merge_tile_map_manifest_search": "Lookup",
"projectred_fabrication.compile.step.merge_tile_map_manifest_search.desc": "Passing signals lookup",
"projectred_fabrication.compile.step.merge_tile_map_pathfind": "Pathfind",
"projectred_fabrication.compile.step.merge_tile_map_pathfind.desc": "Input register search",
"projectred_fabrication.compile.step.merge_tile_map_phase1": "Allocation phase",
"projectred_fabrication.compile.step.merge_tile_map_phase1.desc": "Allocate memory for all tiles",
"projectred_fabrication.compile.step.merge_tile_map_phase2": "Pathfind phase",
"projectred_fabrication.compile.step.merge_tile_map_phase2.desc": "Search for connected registers",
"projectred_fabrication.compile.step.merge_tile_map_phase3": "Lookup phase",
"projectred_fabrication.compile.step.merge_tile_map_phase3.desc": "Look up passing signals",
"projectred_fabrication.compile.step.merge_tile_map_phase4": "Add remaps phase",
"projectred_fabrication.compile.step.merge_tile_map_phase4.desc": "Declare register remaps",
"projectred_fabrication.compile.step.merge_tile_map_phase5": "Remap phase",
"projectred_fabrication.compile.step.merge_tile_map_phase5.desc": "Apply register remaps",
"projectred_fabrication.compile.step.merge_tile_map_phase6": "Collection phase",
"projectred_fabrication.compile.step.merge_tile_map_phase6.desc": "Collect gates and registers",
"projectred_fabrication.compile.step.merge_tile_map_post": "Post-compile",
"projectred_fabrication.compile.step.merge_tile_map_post.desc": "Post-compile",
"projectred_fabrication.compile.step.merge_tile_map_pre": "Pre-compile",
"projectred_fabrication.compile.step.merge_tile_map_pre.desc": "Pre-compile",
"projectred_fabrication.compile.tree": "Tree",
"projectred_fabrication.f.dimensions.dies": "%d dies x %d dies",
"projectred_fabrication.f.dimensions.dies_total": "%d dies x %d dies (%d dies^2)",
"projectred_fabrication.f.dimensions.nm": "%d nm x %d nm",
"projectred_fabrication.f.dimensions.nm_total": "%d nm x %d nm (%d nm^2)",
"projectred_fabrication.f.dimensions.tiles": "%d tiles x %d tiles",
"projectred_fabrication.f.dimensions.tiles_total": "%d tiles x %d tiles (%d tiles^2)",
"projectred_fabrication.f.unit.errors": "%d errors",
"projectred_fabrication.f.unit.ticks": "%d ticks",
"projectred_fabrication.f.unit.warnings": "%d warnings",
"projectred_fabrication.interact.default_state": "Default state",
"projectred_fabrication.interact.delay": "Delay",
"projectred_fabrication.interact.io_direction": "IO direction",
Expand Down Expand Up @@ -111,8 +152,9 @@
"projectred_fabrication.ui.wafer_type": "Wafer type",
"projectred_fabrication.ui.yield": "Yield",
"projectred_fabrication.ui.yield_calculator": "Yield Calculator",
"projectred_fabrication.unit.errors": "%d errors",
"projectred_fabrication.unit.ticks": "%d ticks",
"projectred_fabrication.unit.warnings": "%d warnings",
"projectred_fabrication.unit_only.ticks": "ticks"
"projectred_fabrication.unit.gates": "gates",
"projectred_fabrication.unit.none": "none",
"projectred_fabrication.unit.registers": "registers",
"projectred_fabrication.unit.remaps": "remaps",
"projectred_fabrication.unit.ticks": "ticks"
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,46 @@ protected void addTranslations() {
add(UL_TIME_DELAY, "Delay");
add(UL_DEFAULT_STATE, "Default state");

add(UL_COMPILE_TREE, "Tree");
add(UL_COMPILE_STACK, "Stack");
add(UL_COMPILE_CHECK_TILE_MAP, "Check tile maps");
add(UL_COMPILE_CHECK_FLAT_MAP, "Check flat maps");
add(UL_COMPILE_MERGE_TILE_MAP, "Compile tile map");
add(UL_COMPILE_MERGE_FLAT_MAP, "Compile flat map");
add(UL_COMPILE_MERGE_TILE_MAP_PRE, "Pre-compile");
add(UL_COMPILE_PHASE_1, "Allocation phase");
add(UL_COMPILE_ALLOC, "Alloc");
add(UL_COMPILE_PHASE_2, "Pathfind phase");
add(UL_COMPILE_PATHFIND, "Pathfind");
add(UL_COMPILE_PHASE_3, "Lookup phase");
add(UL_COMPILE_PF_MANIFEST, "Lookup");
add(UL_COMPILE_PHASE_4, "Add remaps phase");
add(UL_COMPILE_ADD_REMAPS, "Add remaps");
add(UL_COMPILE_PHASE_5, "Remap phase");
add(UL_COMPILE_REMAP, "Remap");
add(UL_COMPILE_PHASE_6, "Collection phase");
add(UL_COMPILE_COLLECT, "Collect");
add(UL_COMPILE_MERGE_TILE_MAP_POST, "Post-compile");

add(UL_COMPILE_CHECK_TILE_MAP_DESC, "Check for tile maps to compile");
add(UL_COMPILE_CHECK_FLAT_MAP_DESC, "Check for flat maps to merge");
add(UL_COMPILE_MERGE_TILE_MAP_DESC, "Compile tile map");
add(UL_COMPILE_MERGE_FLAT_MAP_DESC, "Merge flat map");
add(UL_COMPILE_MERGE_TILE_MAP_PRE_DESC, "Pre-compile");
add(UL_COMPILE_PHASE_1_DESC, "Allocate memory for all tiles");
add(UL_COMPILE_ALLOC_DESC, "Output registers and gate allocation");
add(UL_COMPILE_PHASE_2_DESC, "Search for connected registers");
add(UL_COMPILE_PATHFIND_DESC, "Input register search");
add(UL_COMPILE_PHASE_3_DESC, "Look up passing signals");
add(UL_COMPILE_PF_MANIFEST_DESC, "Passing signals lookup");
add(UL_COMPILE_PHASE_4_DESC, "Declare register remaps");
add(UL_COMPILE_ADD_REMAPS_DESC, "Declare remaps");
add(UL_COMPILE_PHASE_5_DESC, "Apply register remaps");
add(UL_COMPILE_REMAP_DESC, "Apply remaps");
add(UL_COMPILE_PHASE_6_DESC, "Collect gates and registers");
add(UL_COMPILE_COLLECT_DESC, "Gates and registers collected");
add(UL_COMPILE_MERGE_TILE_MAP_POST_DESC, "Post-compile");

add(UL_MULTIPLE_DRIVERS_TITLE, "Multiple drivers");
add(UL_MULTIPLE_DRIVERS_DESC, "Multiple registers connected to an input:");
add(UL_DEAD_WIRE_TITLE, "Dead wire");
Expand Down Expand Up @@ -155,5 +195,9 @@ protected void addTranslations() {
add(UL_DIMENSIONS_DIES_TOTAL, "%d dies x %d dies (%d dies^2)");

add(UL_UNIT_ONLY_TICKS, "ticks");
add(UL_UNIT_ONLY_REGISTERS, "registers");
add(UL_UNIT_ONLY_GATES, "gates");
add(UL_UNIT_ONLY_REMAPS, "remaps");
add(UL_UNIT_ONLY_NONE, "none");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class ICCompilerLog implements ICStepThroughAssembler.EventReceiver {
private int warningCount = 0;
private int errorCount = 0;

private final List<Runnable> treeChangedListeners = new LinkedList<>();

public ICCompilerLog(ICEditorStateMachine stateMachine) {
this.stateMachine = stateMachine;
}
Expand Down Expand Up @@ -100,6 +102,7 @@ public void clear() {
problems.clear();
warningCount = 0;
errorCount = 0;
notifyListeners();
}

public int getTotalSteps() {
Expand All @@ -122,13 +125,24 @@ public int getWarningCount() {
return warningCount;
}

public void addTreeChangedListener(Runnable listener) {
treeChangedListeners.add(listener);
}

private void notifyListeners() {
for (Runnable listener : treeChangedListeners) {
listener.run();
}
}

//region ICStepThroughAssembler.EventReceiver
@Override
public void onStepAdded(ICStepThroughAssembler.AssemblerStepDescriptor descriptor) {
CompileTreeNode node = compileTree.findOrCreateNode(descriptor.getTreePath());
node.step = descriptor.getStepType();

sendNodeAdded(node, descriptor.getTreePath());
notifyListeners();
}

@Override
Expand All @@ -144,6 +158,7 @@ public void onStepExecuted(ICStepThroughAssembler.AssemblerStepResult result) {
completedSteps++;

sendNodeExecuted(node, result.getTreePath());
notifyListeners();
}
//endregion

Expand All @@ -162,20 +177,11 @@ public void addProblem(CompileProblem problem) {
//region Packet handling
public void readLogStream(MCDataInput in, int key) {
switch (key) {
case KEY_COMPILER_LOG_CLEARED:
clear();
break;
case KEY_COMPILER_LOG_NODE_ADDED:
readNodeAdded(in);
break;
case KEY_COMPILER_LOG_NODE_EXECUTED:
readNodeExecuted(in);
break;
case KEY_COMPILER_LOG_PROBLEM_ADDED:
readProblemAdded(in);
break;
default:
throw new IllegalArgumentException("Unknown compiler stream key: " + key);
case KEY_COMPILER_LOG_CLEARED -> clear();
case KEY_COMPILER_LOG_NODE_ADDED -> readNodeAdded(in);
case KEY_COMPILER_LOG_NODE_EXECUTED -> readNodeExecuted(in);
case KEY_COMPILER_LOG_PROBLEM_ADDED -> readProblemAdded(in);
default -> throw new IllegalArgumentException("Unknown compiler stream key: " + key);
}
}
//endregion
Expand Down Expand Up @@ -215,6 +221,7 @@ private void addProblemInternal(CompileProblem problem) {
case WARNING -> warningCount++;
case ERROR -> errorCount++;
}
notifyListeners();
}
//endregion

Expand All @@ -227,6 +234,7 @@ private void readNodeAdded(MCDataInput in) {
}
CompileTreeNode node = compileTree.findOrCreateNode(path);
node.step = ICStepThroughAssembler.AssemblerStepType.values()[in.readUByte()];
notifyListeners();
}

private void readNodeExecuted(MCDataInput in) {
Expand All @@ -241,6 +249,7 @@ private void readNodeExecuted(MCDataInput in) {
currentPath.clear();
currentPath.addAll(path);
completedSteps++;
notifyListeners();
}

private void readProblemAdded(MCDataInput in) {
Expand All @@ -253,6 +262,10 @@ public List<CompileTreeNode> getCurrentStack() {
return compileTree.getStack(currentPath);
}

public List<CompileTreeNode> getRootNodes() {
return compileTree.rootNodes;
}

public int getProgressScaled(int scale) {
int size = compileTree.size();
return size == 0 ? 0 : completedSteps * scale / size;
Expand Down Expand Up @@ -399,6 +412,46 @@ protected void readDesc(MCDataInput in) {
children.add(child);
}
}

public int countRegIdsInSubtree() {
//TODO cache
int count = registerIds.size();
for (CompileTreeNode child : children) {
count += child.countRegIdsInSubtree();
}
return count;
}

public int countGateIdsInSubtree() {
//TODO cache
int count = gateIds.size();
for (CompileTreeNode child : children) {
count += child.countGateIdsInSubtree();
}
return count;
}

public int countRemapsInSubtree() {
//TODO cache
int count = registerRemaps.size();
for (CompileTreeNode child : children) {
count += child.countRemapsInSubtree();
}
return count;
}

public boolean isEmpty() {
return registerIds.isEmpty() && gateIds.isEmpty() && registerRemaps.isEmpty();
}

public void getPositionsInTree(List<TileCoord> pList) {
if (!isEmpty()) {
pList.addAll(tileCoords);
for (CompileTreeNode child : children) {
child.getPositionsInTree(pList);
}
}
}
}

public static class CompileTree {
Expand Down

0 comments on commit 3d055ed

Please sign in to comment.