active rendering

Hi, I created a game engine as an abstract class
created a game class that extends it.
I want to use active rendering.
I use a frame and canvas.

I used mvc and repaint using swing for my tetris game, now I want to try active rendering.
And I’m a litlle confused if I want to use events and mvc again, because Active rendering is putting drawing methods in the main game class right?
I capped my fps to 60 so It’s constantly drawing, so every render I need to draw what do I put in my render loop? in the game class, I don’t mean what functions
but where to put the draw methods.

#1 fpsDraw()
#2 gameCanvas.fpsDraw() => then the game class will need a attribute gameCanvas…
#3 or an event, an event that is triggered loop after loop 60 times/sec :s

I think I still want to devide logic from drawing so #1,2 is ruled out
I think calling events is a waste of resources with this config?
I do think alot :slight_smile:
Please advise, Stef

Take a look at the active rendering framework in Killer Game Programming in Java… It should answer your questions and more… The chapters are also available online for free too. http://fivedots.coe.psu.ac.th/~ad/jg/ch1/index.html

Hi, On chapter3 I found an active rendering class, and It’s like every object has it’s own render method? so I 'm using #2

directly available in the javadoc http://java.sun.com/javase/6/docs/api/java/awt/image/BufferStrategy.html :wink:

I know to use the buffered strategy,… Just wanted to know where to put all my drawing/rendering in.

And I gues I go for each class each own rendering and painting methods, altought I’ve read that passing a graphic object around isn’t smart?

I would use it like

render(Graphics g) {
obj1.render(g)
obj2.render(g)
etc
}
Stef

exactly !

Ok great, and if I would use mvc all drawing code goes into my canvas and the model doesn’t see the view so my code changes to

render(Graphics g) {
fireGameChangeEvent(this, State.CHANGE);
}

  private void fireGameChangeEvent(Map map, GameAction action) {
    // Generate the event.
    final BoardEvent event = new GameEvent(map, action);

    // Now tell everyone.
    for (int i=0; i < gameListeners.size(); i++) {
      GameListener bList = gameListeners.get(i);
      bList.gameChange(event);
    }
  }

My question will this be possible, and won’t it be overkill?
atm this will create 500 obj / sec with my 2 ms loop

what are the type of your 500 obj’s ? Can you serialize them to a file quickly ? Is there a cleanup action, too ? 500 obj/sec is really big…

Well I tought I would need an event but I then called the controller directly wich solved that.