19
19
import aurelienribon .tweenengine .TweenCallback ;
20
20
import aurelienribon .tweenengine .TweenEquation ;
21
21
import box2dLight .*;
22
+ import com .badlogic .gdx .Gdx ;
22
23
import com .badlogic .gdx .graphics .Color ;
23
24
import com .badlogic .gdx .graphics .OrthographicCamera ;
24
25
import com .badlogic .gdx .graphics .g2d .Batch ;
25
26
import com .badlogic .gdx .math .Vector2 ;
27
+ import com .badlogic .gdx .utils .Disposable ;
26
28
import de .bitbrain .braingdx .tweens .ColorTween ;
27
29
import de .bitbrain .braingdx .tweens .SharedTweenManager ;
28
30
35
37
* @author Miguel Gonzalez Sanchez
36
38
* @version 1.0.0
37
39
*/
38
- public class LightingManager {
40
+ public class LightingManager implements Disposable {
39
41
40
42
private static final int DEFAULT_RAYS = 80 ;
41
43
private final RayHandler handler ;
@@ -48,6 +50,8 @@ public class LightingManager {
48
50
private Color ambientLightColor = Color .WHITE .cpy ();
49
51
private int rays ;
50
52
53
+ private boolean disposed = false ;
54
+
51
55
public LightingManager (RayHandler rayHandler , OrthographicCamera camera ) {
52
56
this (rayHandler , camera , new LightFactory () {
53
57
@@ -154,40 +158,52 @@ public ConeLight addConeLight(String id, float x, float y, float distance, float
154
158
return light ;
155
159
}
156
160
157
- public boolean removePointLight (String id ) {
158
- PointLight light = pointLights .remove (id );
159
- if (light != null ) {
160
- light .remove ();
161
- return true ;
162
- }
163
- return false ;
161
+ public void removePointLight (final String id ) {
162
+ Gdx .app .postRunnable (new Runnable () {
163
+ @ Override
164
+ public void run () {
165
+ PointLight light = pointLights .remove (id );
166
+ if (light != null ) {
167
+ light .remove ();
168
+ }
169
+ }
170
+ });
164
171
}
165
172
166
- public boolean removeDirectionalLight (String id ) {
167
- DirectionalLight light = dirLights .remove (id );
168
- if (light != null ) {
169
- light .remove ();
170
- return true ;
171
- }
172
- return false ;
173
+ public void removeDirectionalLight (final String id ) {
174
+ Gdx .app .postRunnable (new Runnable () {
175
+ @ Override
176
+ public void run () {
177
+ DirectionalLight light = dirLights .remove (id );
178
+ if (light != null ) {
179
+ light .remove ();
180
+ }
181
+ }
182
+ });
173
183
}
174
184
175
- public boolean removeChainLight (String id ) {
176
- ChainLight light = chainLights .remove (id );
177
- if (light != null ) {
178
- light .remove ();
179
- return true ;
180
- }
181
- return false ;
185
+ public void removeChainLight (final String id ) {
186
+ Gdx .app .postRunnable (new Runnable () {
187
+ @ Override
188
+ public void run () {
189
+ ChainLight light = chainLights .remove (id );
190
+ if (light != null ) {
191
+ light .remove ();
192
+ }
193
+ }
194
+ });
182
195
}
183
196
184
- public boolean removeConeLight (String id ) {
185
- ConeLight light = coneLights .remove (id );
186
- if (light != null ) {
187
- light .remove ();
188
- return true ;
189
- }
190
- return false ;
197
+ public void removeConeLight (final String id ) {
198
+ Gdx .app .postRunnable (new Runnable () {
199
+ @ Override
200
+ public void run () {
201
+ ConeLight light = coneLights .remove (id );
202
+ if (light != null ) {
203
+ light .remove ();
204
+ }
205
+ }
206
+ });
191
207
}
192
208
193
209
public void clear () {
@@ -198,11 +214,17 @@ public void clear() {
198
214
handler .removeAll ();
199
215
}
200
216
201
- void render (Batch batch , float delta ) {
217
+ void render () {
218
+ if (disposed ) {
219
+ return ;
220
+ }
202
221
handler .renderOnly ();
203
222
}
204
223
205
224
void beforeRender () {
225
+ if (disposed ) {
226
+ return ;
227
+ }
206
228
handler .setAmbientLight (ambientLightColor );
207
229
handler .setCombinedMatrix (camera );
208
230
handler .update ();
@@ -213,6 +235,14 @@ void resize(int width, int height) {
213
235
handler .resizeFBO (width , height );
214
236
}
215
237
238
+ @ Override
239
+ public void dispose () {
240
+ if (!disposed ) {
241
+ handler .dispose ();
242
+ disposed = true ;
243
+ }
244
+ }
245
+
216
246
public static interface LightFactory {
217
247
PointLight newPointLight (RayHandler handler , int rays , Color color , float distance , float x , float y );
218
248
0 commit comments