/** * Returns the comparator strength for a corporea request that corporea crystal cubes and retainers use, following the usual "each step up requires double the items" formula. */ public static int signalStrengthForRequestSize(int requestSize) { if(requestSize <= 0) return 0; else if (requestSize >= 16384) return 15; else return Math.min(15, MathHelper.log2(requestSize) + 1); } }
public static <T extends Comparable<T>> void makePropertyInfo(IProperty<T> property) { if (propertyWidths.containsKey(property)) { return; } Collection<T> allowedValues = property.getAllowedValues(); // Calculate width of the property's number in the bit field propertyWidths.put(property, MathHelper.log2(allowedValues.size()) + 1); // Fill the 'number -> value' and 'value -> number' maps int i = 0; for (T value : allowedValues) { numberToValue.put(new Pair<>(property, i), value); valueToNumber.put(new Pair<>(property, value), i); i++; } }
/** Set the pixel-to-block ratio, maintaining the current center of the screen with additional offset. */ private void setMapScale(double scale, int addOffsetX, int addOffsetY) { double oldScale = mapScale; mapScale = Math.min(Math.max(scale, SettingsConfig.userInterface.minScale), SettingsConfig.userInterface.maxScale); // Scaling not needed if (oldScale == mapScale) { return; } if (mapScale >= MIN_SCALE_THRESHOLD) { tileHalfSize = (int)Math.round(8 * mapScale); tile2ChunkScale = 1; } else { tileHalfSize = (int)Math.round(8 * MIN_SCALE_THRESHOLD); tile2ChunkScale = (int)Math.round(MIN_SCALE_THRESHOLD / mapScale); } // Times 2 because the contents of the Atlas are rendered at resolution 2 times smaller: scaleBar.setMapScale(mapScale * 2); mapOffsetX = (int) ((mapOffsetX + addOffsetX) * (mapScale / oldScale)); mapOffsetY = (int) ((mapOffsetY + addOffsetY) * (mapScale / oldScale)); dragMapOffsetX *= mapScale / oldScale; dragMapOffsetY *= mapScale / oldScale; // 2^13 = 8192 scaleClipIndex = MathHelper.log2((int)(mapScale * 8192)) + 1 - 13; zoomLevel = -scaleClipIndex + zoomLevelOne; scaleAlpha = 255; if (followPlayer && (addOffsetX != 0 || addOffsetY != 0)) { followPlayer = false; btnPosition.setEnabled(true); } }
NumericalBlockState.makePropertyInfo(property); propertyOffsets.put(property, offset); offset += MathHelper.log2(property.getAllowedValues().size()) + 1;