package com.nucleus.android;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView.Renderer;

import com.nucleus.renderer.NucleusRenderer;

/**
 * Base implementation for Android renderer used with GLSurfaceView
 * This will handle the most common situations for rendering and reading input events.
 * 
 * @author Richard Sahlin
 */
public class AndroidRenderer implements Renderer {

    public final static String ANDROID_RENDERER_TAG = "AndroidRenderer";
    private final static String NULL_RENDERER_ERROR = "NucleusRenderer is null";
    NucleusRenderer renderer;

    /**
     * Creates a new Android renderer using the specified BaseRenderer implementation
     * 
     * @param renderer
     * @param appListener Call when each frame shall be drawn.
     * @throws IllegalArgumentException If renderer is null.
     */
    public AndroidRenderer(NucleusRenderer renderer) {
        if (renderer == null) {
            throw new IllegalArgumentException(NULL_RENDERER_ERROR);
        }
        this.renderer = renderer;
    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        renderer.getViewFrustum().setViewPort(0, 0, width, height);
        renderer.GLContextCreated(width, height);
    }

    @Override
    public void onDrawFrame(GL10 gl) {
        float deltaTime = renderer.beginFrame();
        renderer.updateFrame(deltaTime);
        renderer.endFrame();
    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        renderer.init();
    }

}

@@ -192,32 +192,121 @@
 eus.
-renderer.NucleusRenderer
+opengl.GLException;%0Aimport com.nucleus.renderer.NucleusRenderer;%0Aimport com.nucleus.renderer.ProcessFrameRunnable
 ;%0A%0A/
@@ -732,16 +732,83 @@
 enderer;
+%0A    ProcessFrameRunnable frameRunnable;%0A    Thread runnableThread;
 %0A%0A    /*
@@ -1266,295 +1266,1092 @@
     
-%7D%0A%0A    @Override%0A    public void onSurfaceChanged(GL10 gl, int width, int height) %7B%0A        renderer.getViewFrustum().setViewPort(0, 0, width, height);%0A        renderer.GLContextCreated(width, height);%0A    %7D%0A%0A    @Override%0A    public void onDrawFrame(GL10 gl) %7B%0A        float deltaTime =
+    frameRunnable = new ProcessFrameRunnable(renderer);%0A        if (Runtime.getRuntime().availableProcessors() %3E 1) %7B%0A            System.out.println(%22Started extra process for logic processing, number of processors: %22%0A                    + Runtime.getRuntime().availableProcessors());%0A            runnableThread = new Thread(frameRunnable);%0A        %7D else %7B%0A            System.out.println(%22Running everything on one thread.%22);%0A        %7D%0A%0A    %7D%0A%0A    @Override%0A    public void onSurfaceChanged(GL10 gl, int width, int height) %7B%0A        renderer.getViewFrustum().setViewPort(0, 0, width, height);%0A        renderer.GLContextCreated(width, height);%0A    %7D%0A%0A    @Override%0A    public void onDrawFrame(GL10 gl) %7B%0A        renderer.beginFrame();%0A        try %7B%0A            if (runnableThread != null) %7B%0A                if (!runnableThread.isAlive()) %7B%0A                    runnableThread.start();%0A                %7D else %7B%0A                    synchronized (frameRunnable) %7B%0A                        frameRunnable.notify();%0A                    %7D%0A                %7D%0A            %7D else %7B%0A               
  ren
@@ -2348,37 +2348,39 @@
        renderer.
-begin
+process
 Frame();%0A       
@@ -2384,40 +2384,136 @@
     
-renderer.updateFrame(deltaTime);
+    %7D%0A            renderer.renderScene();%0A        %7D catch (GLException e) %7B%0A            throw new RuntimeException(e);%0A        %7D
 %0A   

Use runnable to drive logic processing if more than one core is available