C ++派生类丢失范围(上下文)

时间:2015-06-06 03:06:01

标签: c++ inheritance derived

我正在编写一个特定于客户端的游戏,我遇到派生类和继承问题。我使用的代码似乎丢失了上下文,因此屏幕正在被删除,包括UI。我通过

呼叫各州
    myDerivedStates.push_back(new ExistenceClientStateLogin(context_))

主标题是(ExistenceClient.h)

/// This first example, maintaining tradition, prints a "Hello World" message.
/// Furthermore it shows:
///     - Using the Sample / Application classes, which initialize the Urho3D engine and run the main loop
///     - Adding a Text element to the graphical user interface
///     - Subscribing to and handling of update events
class ExistenceClient : public ExistenceApp
{
    /// friend the other classes - Temporary
    friend class ExistenceClientStateSingleton;
    friend class ExistenceClientStateAccount;
    friend class ExistenceClientStateProgress;
    friend class ExistenceClientStateGameMode;
    friend class ExistenceClientStateLogin;
    friend class ExistenceClientStatePlayer;
    friend class ExistenceClientStateMainScreen;

    OBJECT(ExistenceClient);

    /// Construct.
    ExistenceClient(Context* context);
    virtual ~ExistenceClient();

    /// Setup after engine initialization and before running the main loop.
    virtual void Start();

    /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.https://github.com/urho3d/Urho3D/tree/master/Source/Samples
    virtual String GetScreenJoystickPatchString() const
    {
        return
            "<patch>"
            "    <add sel=\"/element/element[./attribute[@name='Name' and @value='Hat0']]\">"
            "        <attribute name=\"Is Visible\" value=\"false\" />"
            "    </add>"
            "</patch>";
    }

    /// Diaplay login screen
    void SetupScreenViewport(void);
    void SetupScreenUI(void);

    /// Get subsubsystems
    Renderer * GetRenderSubsystems(void) const;
    UI * GetUISubsystems(void) const;
    Graphics * GetGraphicsSubsystems(void) const;
    ResourceCache * GetResourceCacheSubsystems(void) const;

    Window * GetSharedWindow(void) const;



protected:


    /// Urho3D window shared pointers
    SharedPtr<Window> window_;
    SharedPtr<Window> window2_;

    /// Urho3D UIelement root, viewport, and render path
    SharedPtr<UIElement> uiRoot_;
    SharedPtr<Viewport> viewport;

    SharedPtr<RenderPath> effectRenderPath;

    /// Urho3D Shared pointer for input
    SharedPtr<Input> input_;

    /// Existence Weak pointer for a single character
    WeakPtr<Character> character_;

    /// Existence Game State Handler Pointer for Game State
    GameStateHandler * ExistenceGameState;

    /// Existence class and variable declaration for alien race alliance information
    vector<string> aliensarray;
    vector<string> tempaliensarray;

    /// This is temoporarily the necessary code
    bool accountexist;

    /// Server connection related
    bool ServerConnection;

private:

};


/// Login State
class ExistenceClientStateSingleton: public ExistenceClient
{
    OBJECT(ExistenceClientStateSingleton);
public:
    ExistenceClientStateSingleton(Context * context);
    virtual ~ExistenceClientStateSingleton();
    virtual void Enter();
    virtual void Exit();
    virtual void OnUpdate(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData );
private:
    void Singleton(void);
protected:

};

/// Login State
class ExistenceClientStateLogin : public ExistenceClientStateSingleton
{
    OBJECT(ExistenceClientStateLogin);
public:
    ExistenceClientStateLogin(Context * context);
    virtual ~ExistenceClientStateLogin();
    virtual void Enter();
    virtual void Exit();
    virtual void OnUpdate(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData );
private:
    void LoginScreen(void);
    void LoginScreenUI(void);
    void LoginScreenUINewAccountHandleClosePressed(StringHash eventType, VariantMap& eventData);
    void LoginScreenUILoginHandleClosePressed(StringHash eventType, VariantMap& eventData);

protected:

};

游戏处理程序头是(GameStateHandler.h)

using namespace Urho3D;

/// fw declaration
class ExistenceClient;
class ExistenceClientStateSingleton;

class GameStateHandler : public Urho3D::Object
{
    OBJECT(GameStateHandler);
public:
    ///costructor
    GameStateHandler(Context * context);
    /// Destruct.
    virtual  ~GameStateHandler();
    /// start point
    void Start(void);
    // handler events
    void onStateChange(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData );
    /// Get last state
    String getCurrentState(void);
    // Register object factory and attributes.
    static void RegisterObject(Context* context);


private:

    /// register all states
    void RegisterGameStates();
    /// create  state  classname
    void createState( Urho3D::String newState );
    /// change state

    void changeState2(ExistenceClientStateSingleton * State);
    /// exit and remove last state.
    void RemoveLastState();

    /// Not used at the moment
    /// holder
    ExistenceClientStateSingleton * GameState;

    /// Vector Array - Derived States
    std::vector< ExistenceClientStateSingleton *> myDerivedStates;

/// Added flags
    int consolestate;
    int uistate;
    int cameramode;
    int debughud;


};

我花了好几个小时观看有关类继承,多态和派生类的视频以及测试,但无论我做什么,它都无法正常工作。

https://github.com/vivienneanthony/Urho3D-Mastercurrent-Existence/tree/development/Source/ExistenceApps/ExistenceClient是源代码位置。

主要文件是ExistenceClient.h GameStateHandler.xxx和ExistenceClientStateLogin.xxx。

感谢任何帮助。

利德

0 个答案:

没有答案