title: Best way to separate game logic from rendering for a fast-paced game for Android with OpenGL?
body: <p>I've been studying and making little games for a while, and I have decided lately that I would try to develop games for Android.</p>
  
  <p>For me, jumping from native C++ code to Android Java wasn't that hard, but it gives me headaches to think about how could I maintain the logic separate from the rendering.</p>
  
  <p>I've been reading around here and on other sites that:</p>
  
  <blockquote>
    <p>It is better to not create another thread for it, just because
    Android will for sure have no problems for processing.</p>
  </blockquote>
  
  <p>Meaning the code would be something like this:</p>
  
  <pre><code>public void onDrawFrame(GL10 gl) {
      doLogicCalculations();
      clearScreen();
      drawSprites();
  }
  </code></pre>
  
  <p>But I'm not sure if that would be the best approach. Since I don't think I like how it will look like if I put my logic inside the <code>GLRenderer::onDrawFrame</code> method. As far as I know, this method is meant to just draw, and I may slow down the frames if I put logic there. Not to mention that it hurts the concepts of POO in my understanding.</p>
  
  <p>I think that using threads might be the way, this is how I was planning:</p>
  
  <p>Main Activity:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      //set fullscreen, etc
  
      GLSurfaceView view = new GLSurfaceView(this);
      //Configure view
  
      GameManager game = new GameManager();
      game.start(context, view);
  
      setContentView(view);
  }
  </code></pre>
  
  <p>GameManager:</p>
  
  <pre><code>OpenGLRenderer renderer;
  Boolean running;
  public void start(Context context, GLSurfaceView view) {
      this.renderer = new OpenGLRenderer(context);
      view.setRenderer(this.renderer);
  
      //create Texturelib, create sound system...
  
      running = true;
      //create a thread to run GameManager::update()
  }
  
  public void update(){
      while(running){
          //update game logic here
          //put, edit and remove sprites from renderer list
          //set running to false to quit game
      }
  }
  </code></pre>
  
  <p>and finally, OpenGLRenderer:</p>
  
  <pre><code>ListOrMap toDraw;
  public void onDrawFrame(GL10 gl) {
      for(sprite i : toDraw)
      {
          i.draw();
      }
  }
  </code></pre>
  
  <p>This is a rough idea, not fully complete.
  This pattern would keep it all separated and would look a little better, but is it the best for performance?</p>
  
  <p>As long as I researched, most examples of threaded games use canvas or surfaceview, those won't fit my case, because I'm using OpenGLES.</p>
  
  <p>So here are my questions: </p>
  
  <blockquote>
    <p>Which is the best way to separate my
    game logic from the rendering when using OpenGLES? Threading my
    application? Put the logic in a separate method and just call it from
    the draw method?</p>
  </blockquote>