Advertisement Jump to content
Sign in to follow this  
Keyeszx

Few questions about the game engine article.

This topic is 1824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.
}
Edited by dejaime

Share this post


Link to post
Share on other sites


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!