<commit_before>package com.stickycoding.rokon;

import javax.microedition.khronos.opengles.GL10;

/**
 * Layer.java
 * A Layer is contained inside a Scene, and are drawn in ascending order
 * Each Layer has a many DrawableObjects and one DrawQueue
 * @author Richard
 *
 */
public class Layer {
	
	protected Scene parentScene;
	protected FixedSizeArray<DrawableObject> drawableObjects;	
	protected int maximumDrawableObjects;
	protected DrawQueue drawQueue;
	
	public Layer(Scene parentScene, int maximumDrawableObjects) {
		this.parentScene = parentScene;
		this.maximumDrawableObjects = maximumDrawableObjects;
		drawQueue = new DrawQueue();
		drawableObjects = new FixedSizeArray<DrawableObject>(maximumDrawableObjects);
	}
	
	/**
	 * Returns a DrawableObject from this layer
	 * 
	 * @param index position in the array
	 * @return NULL if not found
	 */
	public DrawableObject getDrawableObject(int index) {
		return drawableObjects.get(index);
	}
	
	/**
	 * @return the current DrawQueue object for this Scene
	 */
	public DrawQueue getDrawQueue() {
		return drawQueue;
	}
	
	/**
	 * Sets the DrawQueue method
	 * Defaults to DrawQueue.FASTEST if unset
	 * @param type Taken from the constants in DrawQueue
	 */
	public void setDrawQueueType(int type) {
		if(type < 0 || type > 4) {
			Debug.warning("Scene.setDrawQueueType", "Tried setting DrawQueue type to " + type + ", defaulting to 0");
			drawQueue.method = DrawQueue.FASTEST;
			return;
		}
		drawQueue.method = type;
	}
	
	/**
	 * Clears all the DrawableObjects off this Layer
	 */
	public void clear() {
		drawableObjects.clear();
	}
	
	/**
	 * Adds a DrawableObject to this Layer
	 * 
	 * @param drawableObject a valid DrawableObject
	 */
	public void add(DrawableObject drawableObject) {
		if(drawableObject == null) {
			Debug.warning("Layer.add", "Tried adding an invalid DrawableObject");
			return;
		}
		if(drawableObjects.getCount() == drawableObjects.getCapacity()) {
			Debug.warning("Layer.add", "Tried adding to a Layer which is full, maximum=" + maximumDrawableObjects);
			return;
		}
		drawableObjects.add(drawableObject);
		drawableObject.onAdd(this);
	}
	
	protected void onDraw(GL10 gl) {
		for(int i = 0; i < drawableObjects.getCapacity(); i++) {
			if(drawableObjects.get(i) != null) {
				while(drawableObjects.get(i).killNextUpdate) {
					if(drawableObjects.get(i).body != null) {
						Debug.print("removing from physics");
						parentScene.world.destroyBody(drawableObjects.get(i).body);
						Debug.print("removing from scene");
						drawableObjects.get(i).body = null;
					}
					drawableObjects.remove(i);
				}
				drawableObjects.get(i).onUpdate();
				if(drawableObjects.get(i).isOnScreen()) {
					drawableObjects.get(i).onDraw(gl);
				}
			}
		}
	}
	
}<commit_msg>Final fix for physics, thanks to Mario from libgdx - who spent hours finding out what the problem was. See http://apistudios.com/hosted/marzec/badlogic/wordpress/?p=679 for details. Demo now runs > 50fps for 30 mins<commit_after>package com.stickycoding.rokon;

import javax.microedition.khronos.opengles.GL10;

/**
 * Layer.java
 * A Layer is contained inside a Scene, and are drawn in ascending order
 * Each Layer has a many DrawableObjects and one DrawQueue
 * @author Richard
 *
 */
public class Layer {
	
	protected Scene parentScene;
	protected FixedSizeArray<DrawableObject> drawableObjects;	
	protected int maximumDrawableObjects;
	protected DrawQueue drawQueue;
	
	public Layer(Scene parentScene, int maximumDrawableObjects) {
		this.parentScene = parentScene;
		this.maximumDrawableObjects = maximumDrawableObjects;
		drawQueue = new DrawQueue();
		drawableObjects = new FixedSizeArray<DrawableObject>(maximumDrawableObjects);
	}
	
	/**
	 * Returns a DrawableObject from this layer
	 * 
	 * @param index position in the array
	 * @return NULL if not found
	 */
	public DrawableObject getDrawableObject(int index) {
		return drawableObjects.get(index);
	}
	
	/**
	 * @return the current DrawQueue object for this Scene
	 */
	public DrawQueue getDrawQueue() {
		return drawQueue;
	}
	
	/**
	 * Sets the DrawQueue method
	 * Defaults to DrawQueue.FASTEST if unset
	 * @param type Taken from the constants in DrawQueue
	 */
	public void setDrawQueueType(int type) {
		if(type < 0 || type > 4) {
			Debug.warning("Scene.setDrawQueueType", "Tried setting DrawQueue type to " + type + ", defaulting to 0");
			drawQueue.method = DrawQueue.FASTEST;
			return;
		}
		drawQueue.method = type;
	}
	
	/**
	 * Clears all the DrawableObjects off this Layer
	 */
	public void clear() {
		drawableObjects.clear();
	}
	
	/**
	 * Adds a DrawableObject to this Layer
	 * 
	 * @param drawableObject a valid DrawableObject
	 */
	public void add(DrawableObject drawableObject) {
		if(drawableObject == null) {
			Debug.warning("Layer.add", "Tried adding an invalid DrawableObject");
			return;
		}
		if(drawableObjects.getCount() == drawableObjects.getCapacity()) {
			Debug.warning("Layer.add", "Tried adding to a Layer which is full, maximum=" + maximumDrawableObjects);
			return;
		}
		drawableObjects.add(drawableObject);
		drawableObject.onAdd(this);
	}
	
	protected void onDraw(GL10 gl) {
		for(int i = 0; i < drawableObjects.getCapacity(); i++) {
			if(drawableObjects.get(i) != null) {
				while(drawableObjects.get(i).killNextUpdate) {
					if(drawableObjects.get(i).body != null) {
						parentScene.world.destroyBody(drawableObjects.get(i).body);
						drawableObjects.get(i).body = null;
					}
					drawableObjects.remove(i);
				}
				drawableObjects.get(i).onUpdate();
				if(drawableObjects.get(i).isOnScreen()) {
					drawableObjects.get(i).onDraw(gl);
				}
			}
		}
	}
	
}
{'fraction_non_alphanumeric': 0.10910379029401346, 'fraction_numerical': 0.004073680481756996, 'mean_word_length': 3.8934142114384747, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6185889', 'n_tokens_mistral': 1999, 'n_tokens_neox': 1692, 'n_words': 450}