User can set the number of cpu core for the render process from the swing ui
This commit is contained in:
@@ -20,6 +20,7 @@ public class SettingsLoader {
|
|||||||
private String password;
|
private String password;
|
||||||
private String computeMethod;
|
private String computeMethod;
|
||||||
private String gpu;
|
private String gpu;
|
||||||
|
private String cores;
|
||||||
private String cacheDir;
|
private String cacheDir;
|
||||||
private String autoSignIn;
|
private String autoSignIn;
|
||||||
private String ui;
|
private String ui;
|
||||||
@@ -32,13 +33,16 @@ public class SettingsLoader {
|
|||||||
path = path_;
|
path = path_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SettingsLoader(String login_, String password_, ComputeType computeMethod_, GPUDevice gpu_, String cacheDir_, boolean autoSignIn_, String ui_) {
|
public SettingsLoader(String login_, String password_, ComputeType computeMethod_, GPUDevice gpu_, int cores_, String cacheDir_, boolean autoSignIn_, String ui_) {
|
||||||
path = getDefaultFilePath();
|
path = getDefaultFilePath();
|
||||||
login = login_;
|
login = login_;
|
||||||
password = password_;
|
password = password_;
|
||||||
cacheDir = cacheDir_;
|
cacheDir = cacheDir_;
|
||||||
autoSignIn = String.valueOf(autoSignIn_);
|
autoSignIn = String.valueOf(autoSignIn_);
|
||||||
ui = ui_;
|
ui = ui_;
|
||||||
|
if (cores_ > 0) {
|
||||||
|
cores = String.valueOf(cores_);
|
||||||
|
}
|
||||||
|
|
||||||
if (computeMethod_ != null) {
|
if (computeMethod_ != null) {
|
||||||
try {
|
try {
|
||||||
@@ -79,6 +83,10 @@ public class SettingsLoader {
|
|||||||
prop.setProperty("compute-gpu", gpu);
|
prop.setProperty("compute-gpu", gpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cores != null) {
|
||||||
|
prop.setProperty("cpu-cores", cores);
|
||||||
|
}
|
||||||
|
|
||||||
if (login != null) {
|
if (login != null) {
|
||||||
prop.setProperty("login", login);
|
prop.setProperty("login", login);
|
||||||
}
|
}
|
||||||
@@ -143,6 +151,10 @@ public class SettingsLoader {
|
|||||||
this.gpu = prop.getProperty("compute-gpu");
|
this.gpu = prop.getProperty("compute-gpu");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prop.containsKey("cpu-cores")) {
|
||||||
|
this.cores = prop.getProperty("cpu-cores");
|
||||||
|
}
|
||||||
|
|
||||||
if (prop.containsKey("login")) {
|
if (prop.containsKey("login")) {
|
||||||
this.login = prop.getProperty("login");
|
this.login = prop.getProperty("login");
|
||||||
}
|
}
|
||||||
@@ -207,6 +219,9 @@ public class SettingsLoader {
|
|||||||
config.setUseGPU(device);
|
config.setUseGPU(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (config.getNbCores() == -1 && cores != null) {
|
||||||
|
config.setUseNbCores(Integer.valueOf(cores));
|
||||||
|
}
|
||||||
if (config.getUserSpecifiedACacheDir() == false && cacheDir != null) {
|
if (config.getUserSpecifiedACacheDir() == false && cacheDir != null) {
|
||||||
config.setCacheDir(new File(cacheDir));
|
config.setCacheDir(new File(cacheDir));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import java.awt.event.ActionListener;
|
|||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.KeyListener;
|
import java.awt.event.KeyListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -16,10 +15,12 @@ import javax.swing.JFileChooser;
|
|||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPasswordField;
|
import javax.swing.JPasswordField;
|
||||||
|
import javax.swing.JSlider;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import com.sheepit.client.Configuration;
|
import com.sheepit.client.Configuration;
|
||||||
import com.sheepit.client.Configuration.ComputeType;
|
import com.sheepit.client.Configuration.ComputeType;
|
||||||
import com.sheepit.client.SettingsLoader;
|
import com.sheepit.client.SettingsLoader;
|
||||||
|
import com.sheepit.client.hardware.cpu.CPU;
|
||||||
import com.sheepit.client.hardware.gpu.GPU;
|
import com.sheepit.client.hardware.gpu.GPU;
|
||||||
import com.sheepit.client.hardware.gpu.GPUDevice;
|
import com.sheepit.client.hardware.gpu.GPUDevice;
|
||||||
import com.sheepit.client.standalone.GuiSwing;
|
import com.sheepit.client.standalone.GuiSwing;
|
||||||
@@ -36,6 +37,7 @@ public class Settings implements Activity {
|
|||||||
private JFileChooser cacheDirChooser;
|
private JFileChooser cacheDirChooser;
|
||||||
private JCheckBox useCPU;
|
private JCheckBox useCPU;
|
||||||
private List<JCheckBoxGPU> useGPUs;
|
private List<JCheckBoxGPU> useGPUs;
|
||||||
|
private JSlider cpuCores;
|
||||||
|
|
||||||
private JCheckBox saveFile;
|
private JCheckBox saveFile;
|
||||||
private JCheckBox autoSignIn;
|
private JCheckBox autoSignIn;
|
||||||
@@ -165,6 +167,22 @@ public class Settings implements Activity {
|
|||||||
|
|
||||||
n += sep;
|
n += sep;
|
||||||
|
|
||||||
|
CPU cpu = new CPU();
|
||||||
|
if (cpu.cores() > 1) { // if only one core is available, no need to show the choice
|
||||||
|
cpuCores = new JSlider(1, cpu.cores());
|
||||||
|
cpuCores.setMajorTickSpacing(1);
|
||||||
|
cpuCores.setMinorTickSpacing(1);
|
||||||
|
cpuCores.setPaintTicks(true);
|
||||||
|
cpuCores.setPaintLabels(true);
|
||||||
|
cpuCores.setValue(config.getNbCores() != -1 ? config.getNbCores() : cpuCores.getMaximum());
|
||||||
|
JLabel coreLabel = new JLabel("CPU cores:");
|
||||||
|
coreLabel.setBounds(start_label_left, n, 170, size_height_label);
|
||||||
|
parent.getContentPane().add(coreLabel);
|
||||||
|
cpuCores.setBounds(start_label_right, n, end_label_right - start_label_right, size_height_label * 2);
|
||||||
|
parent.getContentPane().add(cpuCores);
|
||||||
|
n += sep + size_height_label;
|
||||||
|
}
|
||||||
|
|
||||||
saveFile = new JCheckBox("Save settings", true);
|
saveFile = new JCheckBox("Save settings", true);
|
||||||
saveFile.setBounds(start_label_right, n, end_label_right - start_label_right, size_height_label);
|
saveFile.setBounds(start_label_right, n, end_label_right - start_label_right, size_height_label);
|
||||||
parent.getContentPane().add(saveFile);
|
parent.getContentPane().add(saveFile);
|
||||||
@@ -295,6 +313,16 @@ public class Settings implements Activity {
|
|||||||
config.setUseGPU(selected_gpu);
|
config.setUseGPU(selected_gpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cpu_cores = -1;
|
||||||
|
CPU cpu = new CPU();
|
||||||
|
if (cpuCores != null && cpuCores.getValue() != cpu.cores()) { // max core <=> no config (-1)
|
||||||
|
cpu_cores = cpuCores.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cpu_cores > 0) {
|
||||||
|
config.setUseNbCores(cpu_cores);
|
||||||
|
}
|
||||||
|
|
||||||
parent.setCredentials(login.getText(), new String(password.getPassword()));
|
parent.setCredentials(login.getText(), new String(password.getPassword()));
|
||||||
|
|
||||||
String cachePath = null;
|
String cachePath = null;
|
||||||
@@ -303,7 +331,7 @@ public class Settings implements Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (saveFile.isSelected()) {
|
if (saveFile.isSelected()) {
|
||||||
new SettingsLoader(login.getText(), new String(password.getPassword()), method, selected_gpu, cachePath, autoSignIn.isSelected(), GuiSwing.type).saveFile();
|
new SettingsLoader(login.getText(), new String(password.getPassword()), method, selected_gpu, cpu_cores, cachePath, autoSignIn.isSelected(), GuiSwing.type).saveFile();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user