Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actualagentultra

Posted 12 February 2013 - 04:45 PM

Give scenes a reference to the App.

I'm trying to figure out the details of how to go about that. Right now I'm trying giving the Scene base class a public member that is declared as pointer-to-App. Then the App::runWithScene, App::pushScene, and App::replaceScene methods assign a reference to the pointer... but it's not quite working and I'm digging through documentation to figure out the proper way to do it.

 

// Scene.h

class Scene : public IEvent {
public:
    Scene();
    virtual ~Scene();

    virtual void onInit();
    virtual void onUpdate() = 0;
    virtual void onRender() = 0;
    virtual void onCleanup() = 0;
};

// Scene.cpp

Scene::Scene()
{
    app = NULL;
}

// App.cpp

int App::runWithScene(ScenePtr scene)
{
    current_scene = std::move(scene);
    current_scene->app = this;
    current_scene->onInit();

    return run();
}

 

Except that in my Scene subclass I'm referring to a method of the App instance and getting the error: "Member Acess into incomplete type 'App'

void BlankScene::onKeyDown(SDLKey key, SDLMod mod, Uint16 unicode)
{
    switch (key) {
        case SDLK_SPACE:
            app->pushScene(ScenePtr(new YellowScene()));
            break;
            
        default:
            break;
    }
}

 

So I'm looking into the pointer literature and trying to decrypt what this means. Any 'pointers' would be appreciated! smile.png


#1agentultra

Posted 12 February 2013 - 04:28 PM

Give scenes a reference to the App.

I'm trying to figure out the details of how to go about that. Right now I'm trying giving the Scene base class a public member that is declared as pointer-to-App. Then the App::runWithScene, App::pushScene, and App::replaceScene methods assign a reference to the pointer... but it's not quite working and I'm digging through documentation to figure out the proper way to do it.

 

// Scene.h

class Scene : public IEvent {
public:
    virtual ~Scene();

    virtual void onInit();
    virtual void onUpdate() = 0;
    virtual void onRender() = 0;
    virtual void onCleanup() = 0;
};

// App.cpp

int App::runWithScene(ScenePtr scene)
{
    current_scene = std::move(scene);
    current_scene->app = this;
    current_scene->onInit();

    return run();
}

 

Except that in my Scene subclass I'm referring to a method of the App instance and getting the error: "Member Acess into incomplete type 'App'

void BlankScene::onKeyDown(SDLKey key, SDLMod mod, Uint16 unicode)
{
    switch (key) {
        case SDLK_SPACE:
            app->pushScene(ScenePtr(new YellowScene()));
            break;
            
        default:
            break;
    }
}

 

So I'm looking into the pointer literature and trying to decrypt what this means. Any 'pointers' would be appreciated! :)


PARTNERS