Skip to content

Commit

Permalink
Moved code revision indicator from prefix to main part of reactor code.
Browse files Browse the repository at this point in the history
  • Loading branch information
MauveCloud committed Mar 22, 2019
1 parent f8b61cc commit 109141f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Ic2ExpReactorPlanner/Reactor.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void clearVentedHeat() {
* @return a code representing some ids for the components and arrangement. Passing the same code to setCode() should re-create an identical reactor setup, even if other changes have happened in the meantime.
*/
public String getCode() {
return "erpA=" + buildCodeString();
return "erp=" + buildCodeString();
}

/**
Expand All @@ -214,8 +214,8 @@ public void setCode(final String code) {
int[][] ids = new int[grid.length][grid[0].length];
char[][][] paramTypes = new char[grid.length][grid[0].length][MAX_PARAM_TYPES];
int[][][] params = new int[grid.length][grid[0].length][MAX_PARAM_TYPES];
if (code.startsWith("erpA=")) {
readCodeString(0, code.substring(5));
if (code.startsWith("erp=")) {
readCodeString(code.substring(4));
} else if (code.length() >= 108 && code.matches("[0-9A-Za-z(),|]+")) { //NOI18N
try {
for (int row = 0; row < grid.length; row++) {
Expand Down Expand Up @@ -490,9 +490,11 @@ private void handleTaloniusCode(String tempCode) throws HeadlessException {
}

// reads a Base64 code string for the reactor, after stripping the prefix.
private void readCodeString(final int codeRevision, final String code) {
private void readCodeString(final String code) {
BigintStorage storage = BigintStorage.inputBase64(code);
// read the grid first
// read the code revision from the code itself instead of making it part of the prefix.
int codeRevision = storage.extract(255);
// read the grid next
for (int row = 0; row < grid.length; row++) {
for (int col = 0; col < grid[row].length; col++) {
int componentId = 0;
Expand Down Expand Up @@ -527,7 +529,7 @@ private void readCodeString(final int codeRevision, final String code) {
maxSimulationTicks = storage.extract((int)5e6);
}

// builds a Base64 code string, not including the prefix that indicates the code revision.
// builds a Base64 code string, not including the prefix.
private String buildCodeString() {
BigintStorage storage = new BigintStorage();
// first, store the extra details, in reverse order of expected reading.
Expand All @@ -541,7 +543,7 @@ private String buildCodeString() {
storage.store(offPulse, (int)5e6);
storage.store(onPulse, (int)5e6);
storage.store((int)currentHeat, (int)120e3);
// grid is read first, so written last, and in reverse order
// grid is read (almost) first, so written (almost) last, and in reverse order
for (int row = grid.length - 1; row >= 0; row--) {
for (int col = grid[row].length - 1; col >= 0; col--) {
ReactorItem component = grid[row][col];
Expand All @@ -562,6 +564,8 @@ private String buildCodeString() {
}
}
}
// store the code revision, allowing values up to 255 (8 bits) before adjusting how it is stored in the code.
storage.store(0, 255);
return storage.outputBase64();
}

Expand Down

0 comments on commit 109141f

Please sign in to comment.