diff --git a/src/com/sheepit/client/Configuration.java b/src/com/sheepit/client/Configuration.java index ffd8be1..cd58bc2 100644 --- a/src/com/sheepit/client/Configuration.java +++ b/src/com/sheepit/client/Configuration.java @@ -54,6 +54,7 @@ public class Configuration { private String extras; private boolean autoSignIn; private String UIType; + private int tileSize; public Configuration(File cache_dir_, String login_, String password_) { this.login = login_; @@ -73,6 +74,7 @@ public class Configuration { this.extras = ""; this.autoSignIn = false; this.UIType = null; + this.tileSize = -1; // ie not set } public String toString() { @@ -215,6 +217,14 @@ public class Configuration { return this.UIType; } + public void setTileSize(int size) { + this.tileSize = size; + } + + public int getTileSize() { + return this.tileSize; + } + public void cleanWorkingDirectory() { this.cleanDirectory(this.workingDirectory); this.cleanDirectory(this.storageDirectory); diff --git a/src/com/sheepit/client/Job.java b/src/com/sheepit/client/Job.java index 5fbd21e..e523954 100644 --- a/src/com/sheepit/client/Job.java +++ b/src/com/sheepit/client/Job.java @@ -633,14 +633,17 @@ public class Job { return Type.OK; } - private int getTileSize() { - int size = 32; // CPU - GPUDevice gpu = this.config.getGPUDevice(); - if (getUseGPU() && this.config.getGPUDevice() != null) { - // GPU - // if the vram is lower than 1G reduce the size of tile to avoid black output - size = (gpu.getMemory() > 1073741824L) ? 256 : 128; + public int getTileSize() { + if (config.getTileSize() == -1) { // not set + int size = 32; // CPU + GPUDevice gpu = this.config.getGPUDevice(); + if (getUseGPU() && gpu != null) { + return gpu.getRecommandedTileSize(); + } + return size; + } + else { + return config.getTileSize(); } - return size; } } diff --git a/src/com/sheepit/client/SettingsLoader.java b/src/com/sheepit/client/SettingsLoader.java index 9d82f59..c9b1fc5 100644 --- a/src/com/sheepit/client/SettingsLoader.java +++ b/src/com/sheepit/client/SettingsLoader.java @@ -30,6 +30,7 @@ public class SettingsLoader { private String cacheDir; private String autoSignIn; private String ui; + private String tileSize; public SettingsLoader() { path = getDefaultFilePath(); @@ -39,7 +40,7 @@ public class SettingsLoader { path = path_; } - public SettingsLoader(String login_, String password_, String proxy_, ComputeType computeMethod_, GPUDevice gpu_, int cores_, String cacheDir_, boolean autoSignIn_, String ui_) { + public SettingsLoader(String login_, String password_, String proxy_, ComputeType computeMethod_, GPUDevice gpu_, int cores_, String cacheDir_, boolean autoSignIn_, String ui_, String tileSize_) { path = getDefaultFilePath(); login = login_; password = password_; @@ -47,6 +48,7 @@ public class SettingsLoader { cacheDir = cacheDir_; autoSignIn = String.valueOf(autoSignIn_); ui = ui_; + tileSize = tileSize_; if (cores_ > 0) { cores = String.valueOf(cores_); } @@ -114,6 +116,10 @@ public class SettingsLoader { prop.setProperty("ui", ui); } + if (tileSize != null) { + prop.setProperty("tile-size", tileSize); + } + prop.store(output, null); } catch (IOException io) { @@ -155,6 +161,7 @@ public class SettingsLoader { this.cacheDir = null; this.autoSignIn = null; this.ui = null; + this.tileSize = null; if (new File(path).exists() == false) { return; @@ -201,6 +208,10 @@ public class SettingsLoader { if (prop.containsKey("ui")) { this.ui = prop.getProperty("ui"); } + + if (prop.containsKey("tile-size")) { + this.tileSize = prop.getProperty("tile-size"); + } } catch (IOException io) { io.printStackTrace(); @@ -265,6 +276,10 @@ public class SettingsLoader { config.setUIType(ui); } + if (config.getTileSize() == -1 && tileSize != null) { + config.setTileSize(Integer.valueOf(tileSize)); + } + config.setAutoSignIn(Boolean.valueOf(autoSignIn)); } diff --git a/src/com/sheepit/client/hardware/gpu/GPUDevice.java b/src/com/sheepit/client/hardware/gpu/GPUDevice.java index 5c78388..5cd803d 100644 --- a/src/com/sheepit/client/hardware/gpu/GPUDevice.java +++ b/src/com/sheepit/client/hardware/gpu/GPUDevice.java @@ -59,5 +59,11 @@ public class GPUDevice { public String toString() { return "GPUDevice [model=" + model + ", memory=" + memory + ", cudaName=" + cudaName + "]"; } + + public int getRecommandedTileSize() { + // GPU + // if the vram is lower than 1G reduce the size of tile to avoid black output + return (getMemory() > 1073741824L) ? 256 : 128; + } } diff --git a/src/com/sheepit/client/standalone/GuiSwing.java b/src/com/sheepit/client/standalone/GuiSwing.java index d851d0d..852cb4f 100644 --- a/src/com/sheepit/client/standalone/GuiSwing.java +++ b/src/com/sheepit/client/standalone/GuiSwing.java @@ -184,6 +184,24 @@ public class GuiSwing extends JFrame implements Gui { client = cli; } + public JLabel addPaddingReturn(int x, int y, int width, int height) { + GridBagConstraints constraints = new GridBagConstraints(); + JLabel label = new JLabel(""); + return label; + } + + public GridBagConstraints addPaddingConstraints(int x, int y, int width, int height) { + GridBagConstraints constraints = new GridBagConstraints(); + constraints.fill = GridBagConstraints.BOTH; + constraints.weightx = 1.0; + constraints.weighty = 1.0; + constraints.gridwidth = width; + constraints.gridheight = height; + constraints.gridx = x; + constraints.gridy = y; + return constraints; + } + public void addPadding(int x, int y, int width, int height) { GridBagConstraints constraints = new GridBagConstraints(); JLabel label = new JLabel(""); diff --git a/src/com/sheepit/client/standalone/swing/activity/Settings.java b/src/com/sheepit/client/standalone/swing/activity/Settings.java index d24bbff..0702192 100644 --- a/src/com/sheepit/client/standalone/swing/activity/Settings.java +++ b/src/com/sheepit/client/standalone/swing/activity/Settings.java @@ -57,6 +57,11 @@ public class Settings implements Activity { private boolean haveAutoStarted; + private JLabel tileSizePadding; + private JTextField tileSizeValue; + private JLabel tileSizeLabel; + private JCheckBox customTileSize; + public Settings(GuiSwing parent_) { parent = parent_; cacheDir = null; @@ -245,6 +250,42 @@ public class Settings implements Activity { ++currentRow; } + customTileSize = new JCheckBox("Custom render tile size", config.getTileSize() != -1); + constraints.gridx = 2; + constraints.gridy = currentRow; + parent.getContentPane().add(customTileSize, constraints); + customTileSize.addActionListener(new TileSizeChange()); + + tileSizePadding = parent.addPaddingReturn(1, ++currentRow, columns - 2, 1); + parent.getContentPane().add(tileSizePadding, parent.addPaddingConstraints(1, ++currentRow, columns - 2, 1)); + ++currentRow; + + tileSizeLabel = new JLabel("Tile Size:"); + constraints.gridwidth = columns - 3; + constraints.gridx = 1; + constraints.gridy = currentRow; + parent.getContentPane().add(tileSizeLabel, constraints); + + tileSizeValue = new JTextField(); + int fromConfig = parent.getConfiguration().getTileSize(); + if (fromConfig == -1) { + if (parent.getConfiguration().getGPUDevice() != null) { + fromConfig = parent.getConfiguration().getGPUDevice().getRecommandedTileSize(); + } + else { + fromConfig = 32; + } + } + tileSizeValue.setText(Integer.toString(fromConfig)); + constraints.gridx = 2; + constraints.gridy = currentRow; + parent.getContentPane().add(tileSizeValue, constraints); + + parent.addPadding(1, ++currentRow, columns - 2, 1); + ++currentRow; + + hideCustomTileSize(config.getTileSize() != -1, false); + saveFile = new JCheckBox("Save settings", true); constraints.gridwidth = columns - 3; constraints.gridx = 2; @@ -281,7 +322,6 @@ public class Settings implements Activity { parent.addPadding(0, 0, 1, currentRow + 1); parent.addPadding(columns - 1, 0, 1, currentRow + 1); - if (haveAutoStarted == false && config.getAutoSignIn() && checkDisplaySaveButton()) { // auto start haveAutoStarted = true; @@ -289,6 +329,15 @@ public class Settings implements Activity { } } + public void hideCustomTileSize(boolean hidden, boolean displayWarning) { + tileSizePadding.setVisible(hidden); + tileSizeValue.setVisible(hidden); + tileSizeLabel.setVisible(hidden); + if (customTileSize.isSelected() == true && displayWarning) { + JOptionPane.showMessageDialog(parent.getContentPane(), "These settings should only be changed if you are an advanced user.
Improper settings may lead to invalid and slower renders!", "Warning: Advanced Users Only!", JOptionPane.WARNING_MESSAGE); + } + } + public boolean checkDisplaySaveButton() { boolean selected = useCPU.isSelected(); for (JCheckBoxGPU box : useGPUs) { @@ -299,6 +348,15 @@ public class Settings implements Activity { if (login.getText().isEmpty() || password.getPassword().length == 0 || Proxy.isValidURL(proxy.getText()) == false) { selected = false; } + + if (customTileSize.isSelected()) { + try { + Integer.parseInt(tileSizeValue.getText().replaceAll(",", "")); + } + catch (NumberFormatException e) { + selected = false; + } + } saveButton.setEnabled(selected); return selected; } @@ -348,6 +406,15 @@ public class Settings implements Activity { } } + class TileSizeChange implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + boolean custom = customTileSize.isSelected(); + hideCustomTileSize(custom, true); + } + } + class SaveAction implements ActionListener { @Override @@ -416,6 +483,19 @@ public class Settings implements Activity { } } + String tile = null; + if (customTileSize.isSelected() && tileSizeValue != null) { + try { + tile = tileSizeValue.getText().replaceAll(",", ""); + config.setTileSize(Integer.parseInt(tile)); + } + catch (NumberFormatException e1) { + System.err.println("Error: wrong tile format"); + System.err.println(e); + System.exit(2); + } + } + parent.setCredentials(login.getText(), new String(password.getPassword())); String cachePath = null; @@ -424,7 +504,7 @@ public class Settings implements Activity { } if (saveFile.isSelected()) { - new SettingsLoader(login.getText(), new String(password.getPassword()), proxyText, method, selected_gpu, cpu_cores, cachePath, autoSignIn.isSelected(), GuiSwing.type).saveFile(); + new SettingsLoader(login.getText(), new String(password.getPassword()), proxyText, method, selected_gpu, cpu_cores, cachePath, autoSignIn.isSelected(), GuiSwing.type, tile).saveFile(); } else { try {