Game objects

So I wanted to make a stage-based engine with game objects.

Basically every “stage” contains a render, tick, and init method. They also contain one game object, called root object.
Game objects contain a array list of game objects called “children”. Then, when the’re rendered, they draw everything in their children.

Also, during the render of every stage, it just renders all the “root objects” children.

Is this a good way to handle things? I needed a easy way to implement shaders by drawing everything from one method.

I don’t quite understand the benefit from combining so many things together, you’ll end up making more complex logic a lot harder on yourself having to deal with different kinds of entities.

Just make it, and when it doesn’t work out change it that is the great thing, in my opinion about coding.

Yes, but I need some way to do multiple shader passes. Meaning everything has to be able to be ran from one “render all” method.

Still don’t get then why you need to put everything together, you can just have all of the same objects together then have something along the lines of… pseudo-code



Object object
Player player
Barrier[] barriers


public void render(Graphics g){

   object.render(g)
   player.render(g)

   for(barrier b : barriers){
       b.render(g)
   }
}


Sounds like you are reinventing a scene graph. For more information, see jMonkey Engine.

A scenegraph is something very specific. A rigid body model where nodes of the DAG are linear transformed from their parent.

Thanks for the reply, but I meant something like lights, you need it to be globally lit for all objects.



for(Light l : lights){
   
   lightShader.bind();

   //Setup uniforms (In simple form)
   glUniform(l.programID, "lightLocation" l.loc.x, l.loc.y);
   glUniform(l.programID, "lightColor" l.color.x, l.color.y, l.color.z);

   //Sure, I can render a VBO the size of the screen here,
   //but I need a way for the shaders to pass over the objects, lighting them.
   screen.bind();
    glDrawArrays(GL_TRIANGLE, 0, 6);
   screen.unbind();

   lightShader.unbind();
}


I confess I have no idea what a DAG is, but I’ve always understood a scene graph to be a tree of nodes where you can move all the nodes on a branch togethger, or render a subtree to a viewport, choose to render or not render groups of objects and so on…

Damn, seems like some complicated stuff. Is there any way to fix this in a simpler way?

(I mean the global-lighting thing)

Well for the lighting, if you’re going for more advanced effects with good performance, take a look at deferred shading. It has a few downsides, but it’s undeniably one of the faster techniques for lighting.
For the scenegraph, you’re going to want to have a class called Node or something along those lines (using jMonkeyEngine as an example). This class contains an object of its parent node, and an array or List of the children Nodes. Then in the update method, render method, or whatever other update thing you use, update all the children. This makes it all rather recursive (that isn’t the exact definition or real recursion I think but you get it).

Sorry I wasn’t specific, but I’m using 2D, so Deffered Shading is going to be a bit harder to do. What I have set up now is a VBO the size of the display, shaded to look like it has lights.

No recursion…you’re walking a graph.