Skip to content

Commit 8181057

Browse files
authored
MaterialDebugAppState: format code (#2200)
MaterialDebugAppState: format code
1 parent 80c2577 commit 8181057

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

jme3-core/src/main/java/com/jme3/util/MaterialDebugAppState.java

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2021 jMonkeyEngine
2+
* Copyright (c) 2009-2024 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -98,9 +98,8 @@ public class MaterialDebugAppState extends AbstractAppState {
9898
private RenderManager renderManager;
9999
private AssetManager assetManager;
100100
private InputManager inputManager;
101-
final private List<Binding> bindings = new ArrayList<>();
102-
final private Map<Trigger,List<Binding>> fileTriggers = new HashMap<> ();
103-
101+
private final List<Binding> bindings = new ArrayList<>();
102+
private final Map<Trigger, List<Binding>> fileTriggers = new HashMap<>();
104103

105104
@Override
106105
public void initialize(AppStateManager stateManager, Application app) {
@@ -119,20 +118,18 @@ public void initialize(AppStateManager stateManager, Application app) {
119118
* @param spat the spatial to reload
120119
*/
121120
public void registerBinding(Trigger trigger, final Spatial spat) {
122-
if(spat instanceof Geometry){
123-
GeometryBinding binding = new GeometryBinding(trigger, (Geometry)spat);
121+
if (spat instanceof Geometry) {
122+
GeometryBinding binding = new GeometryBinding(trigger, (Geometry) spat);
124123
bindings.add(binding);
125124
if (isInitialized()) {
126125
bind(binding);
127126
}
128-
}else if (spat instanceof Node){
129-
for (Spatial child : ((Node)spat).getChildren()) {
127+
} else if (spat instanceof Node) {
128+
for (Spatial child : ((Node) spat).getChildren()) {
130129
registerBinding(trigger, child);
131130
}
132131
}
133132
}
134-
135-
136133

137134
/**
138135
* Will reload the filter's materials whenever the trigger is fired.
@@ -146,7 +143,6 @@ public void registerBinding(Trigger trigger, final Filter filter) {
146143
bind(binding);
147144
}
148145
}
149-
150146

151147
/**
152148
* Will reload the filter's materials whenever the shader file is changed
@@ -174,7 +170,7 @@ private void bind(final Binding binding) {
174170
if (binding.getTrigger() instanceof FileChangedTrigger) {
175171
FileChangedTrigger t = (FileChangedTrigger) binding.getTrigger();
176172
List<Binding> b = fileTriggers.get(t);
177-
if(b == null){
173+
if (b == null) {
178174
t.init();
179175
b = new ArrayList<Binding>();
180176
fileTriggers.put(t, b);
@@ -186,7 +182,7 @@ private void bind(final Binding binding) {
186182
@Override
187183
public void onAction(String name, boolean isPressed, float tpf) {
188184
if (actionName.equals(name) && isPressed) {
189-
//reloading the material
185+
// reloading the material
190186
binding.reload();
191187
}
192188
}
@@ -197,42 +193,41 @@ public void onAction(String name, boolean isPressed, float tpf) {
197193
}
198194

199195
public Material reloadMaterial(Material mat) {
200-
//clear the entire cache, there might be more clever things to do, like clearing only the matdef, and the associated shaders.
196+
// clear the entire cache, there might be more clever things to do, like
197+
// clearing only the matdef, and the associated shaders.
201198
assetManager.clearCache();
202199

203-
//creating a dummy mat with the mat def of the mat to reload
200+
// creating a dummy mat with the mat def of the mat to reload
204201
// Force the reloading of the asset, otherwise the new shader code will not be applied.
205202
Material dummy = new Material(assetManager, mat.getMaterialDef().getAssetName());
206203

207204
for (MatParam matParam : mat.getParams()) {
208205
dummy.setParam(matParam.getName(), matParam.getVarType(), matParam.getValue());
209206
}
210-
211-
dummy.getAdditionalRenderState().set(mat.getAdditionalRenderState());
212207

213-
//creating a dummy geom and assigning the dummy material to it
208+
dummy.getAdditionalRenderState().set(mat.getAdditionalRenderState());
209+
210+
// creating a dummy geom and assigning the dummy material to it
214211
Geometry dummyGeom = new Geometry("dummyGeom", new Box(1f, 1f, 1f));
215212
dummyGeom.setMaterial(dummy);
216213

217214
try {
218-
//preloading the dummyGeom, this call will compile the shader again
215+
// preloading the dummyGeom, this call will compile the shader again
219216
renderManager.preloadScene(dummyGeom);
220217
} catch (RendererException e) {
221-
//compilation error, the shader code will be output to the console
222-
//the following code will output the error
223-
//System.err.println(e.getMessage());
218+
// compilation error, the shader code will be output to the console
219+
// the following code will output the error
224220
Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, e.getMessage());
225221
return null;
226222
}
227223

228224
Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.INFO, "Material successfully reloaded");
229-
//System.out.println("Material successfully reloaded");
230225
return dummy;
231226
}
232227

233228
@Override
234229
public void update(float tpf) {
235-
super.update(tpf); //To change body of generated methods, choose Tools | Templates.
230+
super.update(tpf);
236231
for (Trigger trigger : fileTriggers.keySet()) {
237232
if (trigger instanceof FileChangedTrigger) {
238233
FileChangedTrigger t = (FileChangedTrigger) trigger;
@@ -243,7 +238,7 @@ public void update(float tpf) {
243238
}
244239
}
245240
}
246-
}
241+
}
247242
}
248243

249244
private interface Binding {
@@ -263,23 +258,21 @@ private class GeometryBinding implements Binding {
263258
public GeometryBinding(Trigger trigger, Geometry geom) {
264259
this.trigger = trigger;
265260
this.geom = geom;
266-
267261
}
268262

269263
@Override
270264
public void reload() {
271265
Material reloadedMat = reloadMaterial(geom.getMaterial());
272-
//if the reload is successful, we re setup the material with its params and reassign it to the box
266+
// if the reload is successful, we re setup the material with its params and
267+
// reassign it to the box
273268
if (reloadedMat != null) {
274-
// setupMaterial(reloadedMat);
275269
geom.setMaterial(reloadedMat);
276270
}
277271
}
278272

279273
@Override
280274
public String getActionName() {
281275
return geom.getName() + "Reload";
282-
283276
}
284277

285278
@Override
@@ -319,12 +312,11 @@ public void reload() {
319312
} else {
320313
field.set(filter, mat);
321314
}
322-
323315
}
324316
if (field.getType().isInstance(p)) {
325317
field.setAccessible(true);
326318
p = (Filter.Pass) field.get(filter);
327-
if (p!= null && p.getPassMaterial() != null) {
319+
if (p != null && p.getPassMaterial() != null) {
328320
Material mat = reloadMaterial(p.getPassMaterial());
329321
if (mat == null) {
330322
return;
@@ -352,7 +344,6 @@ public void reload() {
352344
} catch (IllegalArgumentException | IllegalAccessException ex) {
353345
Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex);
354346
}
355-
356347
}
357348

358349
@Override

0 commit comments

Comments
 (0)