Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualagentultra

Posted 12 February 2013 - 12:13 PM

I have an App class that I would like to manage a stack of objects subclassed from Scene and the main game loop. The App class' purpose is to yield control of the main game loop to the currently active Scene object.

 

using namespace std;

typedef unique_ptr<Scene> ScenePtr

class App {
    ...
    stack<ScenePtr, vector<ScenePtr>> scene_stack;
    ScenePtr current_scene;
    ScenePtr next_scene;

    // Don't want to go through the trouble of managing a Singleton
    // but for basic safety, don't allow copies.
    App(App& other);

    int run();

public:
    App();
    ~App();

    ...

    void startWithScene(ScenePtr scene);
    void pushScene(ScenePtr scene);
    void popScene();
};
 

 

 

There's a bunch of other code in there for initializing the display, running the actual game loop, etc. What I'm having trouble with (and can't find a decent answer on SO for) is how I can pass a pointer to a dynamically allocated Scene subclass into startWithScene, pushScene, etc.

 

 

 

int App::startWithScene(ScenePtr scene)
{
    current_scene = std::move(scene);
    current_scene->init();
    return run();
} 

 

And what I'm trying to do in main() is:

 

 

...
#include "BlankScene.h"

int main(int argc, char *argvp[])
{
    App app = App();
    app.startWithScene(ScenePtr(new BlankScene()));
}

The idea is that the Scene base class is just an interface for the App to use. The subclass provides the implementation for any given scene in a game. The scene is responsible for all of its own entities, responding to the events it's interested in, rendering itself to the display, etc. This seems like a reasonable design to me and I'm just trying to get the minimum possible infrastructure in place to get it going.

 

However I'm getting an error that seems unrelated. On the line in main() where I create an instance of the App the compiler is telling me that I'm calling a private constructor of the class. It wasn't giving that error before I added the class members and methods to implement the scene management stuff.

 

I'm starting to wonder if I'm barking up the wrong tree here. I'm reading as much as I can about smart pointers in C++11 (very nice feature) but this error is throwing me for a loop. Are there more implicit constructors or something?

 

(And is this even a reasonable design?)


#1agentultra

Posted 12 February 2013 - 12:11 PM

I have an App class that I would like to manage a stack of objects subclassed from Scene and the main game loop. The App class' purpose is to yield control of the main game loop to the currently active Scene object.

 

using namespace std;

typedef unique_ptr<Scene> ScenePtr

class App {
...
stack<ScenePtr, vector<ScenePtr>> scene_stack;
ScenePtr current_scene;
ScenePtr next_scene;

// Don't want to go through the trouble of managing a Singleton
// but for basic safety, don't allow copies.
App(App& other);

int run();

public:
App();
~App();

...

void startWithScene(ScenePtr scene);
void pushScene(ScenePtr scene);
void popScene();
};
 

 

 

There's a bunch of other code in there for initializing the display, running the actual game loop, etc. What I'm having trouble with (and can't find a decent answer on SO for) is how I can pass a pointer to a dynamically allocated Scene subclass into startWithScene, pushScene, etc.

 

 

 

int App::startWithScene(ScenePtr scene)
{
current_scene = std::move(scene);
current_scene->init();
return run();
}

 

 

And what I'm trying to do in main() is:

 

 

...
#include "BlankScene.h"

int main(int argc, char *argvp[])
{
App app = App();
app.startWithScene(ScenePtr(new BlankScene()));
}
 

The idea is that the Scene base class is just an interface for the App to use. The subclass provides the implementation for any given scene in a game. The scene is responsible for all of its own entities, responding to the events it's interested in, rendering itself to the display, etc. This seems like a reasonable design to me and I'm just trying to get the minimum possible infrastructure in place to get it going.

 

However I'm getting an error that seems unrelated. On the line in main() where I create an instance of the App the compiler is telling me that I'm calling a private constructor of the class. It wasn't giving that error before I added the class members and methods to implement the scene management stuff.

 

I'm starting to wonder if I'm barking up the wrong tree here. I'm reading as much as I can about smart pointers in C++11 (very nice feature) but this error is throwing me for a loop. Are there more implicit constructors or something?

 

(And is this even a reasonable design?)


PARTNERS