Few questions about the game engine article.

Started by
2 comments, last by jbadams 10 years, 2 months ago

The article.

http://www.gamedev.net/page/resources/_/technical/game-programming/making-a-game-engine-core-design-principles-r3210

So I was wondering a few things about this. What's a singleton? I'm not sure I understand what the person means for scene. When they describe it makes sense but I kind of get loss looking at their code.

How does the scene know what game object to add to the scene?

Advertisement

You could ask that with a comment on the article, as most people here didn't read it and probably doesn't understand the scene->object relationship (as I didn't).

But answering to your first question, the one I can answer, a Singleton is a design pattern that forbids the instantiation of more than one object of a given "singleton class". In other words, if you have a Display class in your game, and want to make sure only one Display object is created at a time, you can make your Display class a singleton. So you'll avoid problems like creating two different game windows, in this example.

This is one way to do this:


public class Display {
public:
    static Display getInstance() { //This is what you use on your game.
        return SingleInstance;
    }

private:
    private Display(); //This is your constructor, private
                                    //It is private so no one can create new objects
                                    //  but the first one.

    static final Display SingleInstance = new Display(); // The only Display instance.
}
The Scenes are likely a somewhat simpler version of what I call Spaces. Here's a talk I gave to game engineering students two years ago on Spaces and their utility:


https://github.com/EngineArchitectureClub/TalkSlides/tree/master/2012/12-Spaces-SeanMiddleditch

Sean Middleditch – Game Systems Engineer – Join my team!


a Singleton is a design pattern that forbids the instantiation of more than one object of a given "singleton class"

That's one of the two requirements for a singleton. The other is that there must be a global point of access to the object.

Unless both requirements are met -- that is, it would be an error for more than one instance to be created, and you require global access -- a singleton is probably not the best choice. smile.png

- Jason Astle-Adams

This topic is closed to new replies.

Advertisement