Skip to content

Commit f6aa3ef

Browse files
committed
refactor
1 parent c7c70f1 commit f6aa3ef

File tree

10 files changed

+355
-394
lines changed

10 files changed

+355
-394
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip

src/main/java/SunflowGUI.java

Lines changed: 289 additions & 352 deletions
Large diffs are not rendered by default.

src/main/java/org/sunflow/core/ParameterList.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ public enum InterpolationType {
3636
* Creates an empty ParameterList.
3737
*/
3838
public ParameterList() {
39-
list = new FastHashMap<String, Parameter>();
39+
list = new FastHashMap<>();
4040
numVerts = numFaces = numFaceVerts = 0;
4141
}
4242

4343
/**
44-
* Clears the list of all its members. If some members were never used, a
44+
* Clears the list of all its members.If some members were never used, a
4545
* warning will be printed to remind the user something may be wrong.
46+
* @param showUnused
4647
*/
4748
public void clear(boolean showUnused) {
4849
if (showUnused) {

src/main/java/org/sunflow/core/PhotonStore.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public interface PhotonStore {
1919
/**
2020
* Initialize this object for the specified scene size.
2121
*
22+
* @param options
2223
* @param sceneBounds scene bounding box
2324
*/
2425
void prepare(Options options, BoundingBox sceneBounds);

src/main/java/org/sunflow/core/accel/BoundingIntervalHierarchy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class BoundingIntervalHierarchy implements AccelerationStructure {
1717
private int[] objects;
1818
private PrimitiveList primitives;
1919
private BoundingBox bounds;
20-
private int maxPrims;
20+
private final int maxPrims;
2121

2222
public BoundingIntervalHierarchy() {
2323
maxPrims = 2;

src/main/java/org/sunflow/image/writers/EXRBitmapWriter.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,36 @@ public EXRBitmapWriter() {
4848
@Override
4949
public final void configure(final String option, String value) {
5050
if (option.equals(COMPRESSION)) {
51-
if (value.equals("none")) {
52-
compression = NO_COMPRESSION;
53-
} else if (value.equals("rle")) {
54-
compression = RLE_COMPRESSION;
55-
} else if (value.equals("zip")) {
56-
compression = ZIP_COMPRESSION;
57-
} else {
58-
UI.printWarning(Module.IMG, "EXR - Compression type was not recognized - defaulting to zip");
59-
compression = ZIP_COMPRESSION;
51+
switch (value) {
52+
case "none":
53+
compression = NO_COMPRESSION;
54+
break;
55+
case "rle":
56+
compression = RLE_COMPRESSION;
57+
break;
58+
case "zip":
59+
compression = ZIP_COMPRESSION;
60+
break;
61+
default:
62+
UI.printWarning(Module.IMG, "EXR - Compression type was not recognized - defaulting to zip");
63+
compression = ZIP_COMPRESSION;
64+
break;
6065
}
6166
} else if (option.equals("channeltype")) {
62-
if (value.equals("float")) {
63-
channelType = FLOAT;
64-
channelSize = FLOAT_SIZE;
65-
} else if (value.equals("half")) {
66-
channelType = HALF;
67-
channelSize = HALF_SIZE;
68-
} else {
69-
UI.printWarning(Module.DISP, "EXR - Channel type was not recognized - defaulting to float");
70-
channelType = FLOAT;
71-
channelSize = FLOAT_SIZE;
67+
switch (value) {
68+
case "float":
69+
channelType = FLOAT;
70+
channelSize = FLOAT_SIZE;
71+
break;
72+
case "half":
73+
channelType = HALF;
74+
channelSize = HALF_SIZE;
75+
break;
76+
default:
77+
UI.printWarning(Module.DISP, "EXR - Channel type was not recognized - defaulting to float");
78+
channelType = FLOAT;
79+
channelSize = FLOAT_SIZE;
80+
break;
7281
}
7382
}
7483
}

src/main/java/org/sunflow/image/writers/PNGBitmapWriter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@ public class PNGBitmapWriter implements BitmapWriter {
1414
private String filename;
1515
private BufferedImage image;
1616

17+
@Override
1718
public void configure(String option, String value) {
1819
}
1920

21+
@Override
2022
public void openFile(String filename) throws IOException {
2123
this.filename = filename;
2224
}
2325

26+
@Override
2427
public void writeHeader(int width, int height, int tileSize) throws IOException, UnsupportedOperationException {
2528
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
2629
}
2730

31+
@Override
2832
public void writeTile(int x, int y, int w, int h, Color[] color, float[] alpha) throws IOException {
2933
for (int j = 0, index = 0; j < h; j++) {
3034
for (int i = 0; i < w; i++, index++) {
@@ -33,6 +37,7 @@ public void writeTile(int x, int y, int w, int h, Color[] color, float[] alpha)
3337
}
3438
}
3539

40+
@Override
3641
public void closeFile() throws IOException {
3742
ImageIO.write(image, "png", new File(filename));
3843
}

src/main/java/org/sunflow/image/writers/TGABitmapWriter.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@ public class TGABitmapWriter implements BitmapWriter {
1515
private int width, height;
1616
private byte[] data;
1717

18+
@Override
1819
public void configure(String option, String value) {
1920
}
2021

22+
@Override
2123
public void openFile(String filename) throws IOException {
2224
this.filename = filename;
2325
}
2426

27+
@Override
2528
public void writeHeader(int width, int height, int tileSize) throws IOException, UnsupportedOperationException {
2629
this.width = width;
2730
this.height = height;
2831
data = new byte[width * height * 4]; // RGBA8
2932
}
3033

34+
@Override
3135
public void writeTile(int x, int y, int w, int h, Color[] color, float[] alpha) throws IOException {
3236
color = ColorEncoder.unlinearize(color); // gamma correction
3337
byte[] tileData = ColorEncoder.quantizeRGBA8(color, alpha);
@@ -43,21 +47,23 @@ public void writeTile(int x, int y, int w, int h, Color[] color, float[] alpha)
4347
}
4448
}
4549

50+
@Override
4651
public void closeFile() throws IOException {
47-
// actually write the file from here
48-
OutputStream f = new BufferedOutputStream(new FileOutputStream(filename));
4952
// no id, no colormap, uncompressed 32bpp RGBA
50-
byte[] tgaHeader = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
51-
f.write(tgaHeader);
52-
// then the size info
53-
f.write(width & 0xFF);
54-
f.write((width >> 8) & 0xFF);
55-
f.write(height & 0xFF);
56-
f.write((height >> 8) & 0xFF);
57-
// bitsperpixel and filler
58-
f.write(32);
59-
f.write(0);
60-
f.write(data); // write image data bytes (already in BGRA order)
61-
f.close();
53+
try ( // actually write the file from here
54+
OutputStream f = new BufferedOutputStream(new FileOutputStream(filename))) {
55+
// no id, no colormap, uncompressed 32bpp RGBA
56+
byte[] tgaHeader = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
57+
f.write(tgaHeader);
58+
// then the size info
59+
f.write(width & 0xFF);
60+
f.write((width >> 8) & 0xFF);
61+
f.write(height & 0xFF);
62+
f.write((height >> 8) & 0xFF);
63+
// bitsperpixel and filler
64+
f.write(32);
65+
f.write(0);
66+
f.write(data); // write image data bytes (already in BGRA order)
67+
}
6268
}
6369
}

src/main/java/org/sunflow/system/BenchmarkFramework.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
*/
99
public class BenchmarkFramework {
1010

11-
private Timer[] timers;
12-
private int timeLimit; // time limit in seconds
11+
private final Timer[] timers;
12+
private final int timeLimit; // time limit in seconds
1313

1414
public BenchmarkFramework(int iterations, int timeLimit) {
1515
this.timeLimit = timeLimit;

src/main/java/org/sunflow/system/RenderGlobalsPanel.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ private void initialize() {
6464

6565
/**
6666
* Auto-generated main method to display this JPanel inside a new JFrame.
67+
* @param args
6768
*/
6869
public static void main(String[] args) {
6970
JFrame frame = new JFrame();
@@ -181,9 +182,9 @@ private void initGUI() {
181182
jLabel5.setText("Min:");
182183
}
183184
{
184-
ComboBoxModel<String> minSamplingComboBoxModel = new DefaultComboBoxModel<String>(new String[]{
185+
ComboBoxModel<String> minSamplingComboBoxModel = new DefaultComboBoxModel<>(new String[]{
185186
"Item One", "Item Two"});
186-
minSamplingComboBox = new JComboBox<String>();
187+
minSamplingComboBox = new JComboBox<>();
187188
samplingPanel.add(minSamplingComboBox);
188189
minSamplingComboBox.setModel(minSamplingComboBoxModel);
189190
}
@@ -193,9 +194,9 @@ private void initGUI() {
193194
jLabel6.setText("Max:");
194195
}
195196
{
196-
ComboBoxModel<String> maxSamplingComboxBoxModel = new DefaultComboBoxModel<String>(new String[]{
197+
ComboBoxModel<String> maxSamplingComboxBoxModel = new DefaultComboBoxModel<>(new String[]{
197198
"Item One", "Item Two"});
198-
maxSamplingComboxBox = new JComboBox<String>();
199+
maxSamplingComboxBox = new JComboBox<>();
199200
samplingPanel.add(maxSamplingComboxBox);
200201
maxSamplingComboxBox.setModel(maxSamplingComboxBoxModel);
201202
}

0 commit comments

Comments
 (0)