Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#ActualNightCreature83

Posted 12 June 2013 - 03:51 PM

How about you create a resource which is passed to the object on construction. This resource contains pointers/references to all managers in the game and accessors to get them. The object stores a reference to this object and all you need to do is care for the fact that all pointers in the resource need to outlive the objects it is passed into, which should be the case anyway as the system pointers it contains needs the objects to work.

If you then use transient interfaces that take a reference to this resource pointer you can hide away all the nasty manager access code in an interface that gets initialised:
class Resource; //Holds all manager pointers/references

class SimpleInterface
{
public:
    SimpleInterface() {}
    ~SimpleInterface() {}

    bool initialise(const Resource* resource); //This can take more paramater like the indexes or resource references needed

    //Add accessor members here to get the data you want
    const std::string getPlayerName()
    {
        if (m_resource->getPlayerManager())
        {
            return m_resource->getPlayerManager().getPlayer().getName();        
        }

        return "Player One";
    }
private:
    Resource* m_resource;
};

class System
{
public:
    void Update()
    {
        SimpleInterface simpleInterface;
        if (simpleInterface.initialise(m_resource) )
        {
            std::string playerName = simpleInterface.getPlayerName();
        }
    }
};
This way all your glue code doesn't have to touch most of the actual functioning code.

#3NightCreature83

Posted 12 June 2013 - 03:27 PM

How about you create a resource which is passed to the object on construction. This resource contains pointers/references to all managers in the game and accessors to get them. The object stores a reference to this object and all you need to do is care for the fact that all pointers in the resource need to outlive the objects it is passed into, which should be the case anyway as the system pointers it contains needs the objects to work.

If you then use transient interfaces that take a reference to this resource pointer you can hide away all the nasty manager access code in an interface that gets initialised:
class Resource; //Holds all manager pointers/references

class SimpleInterface
{
public:
    SimpleInterface() {}
    ~SimpleInterface() {}

    bool initialise(const Resource* resource); //This can take more paramater like the indexes or resource references needed

    //Add accessor members here to get the data you want
    const std::string getPlayerName()
    {
        if (m_resource->getPlayerManager())
        {
            return m_resource->getPlayerManager().getPlayer().getName();        
        }

        return "Player One";
    }
private:
    Resource* m_resource;
};

class System
{
public:
    void Update()
    {
        SimpleInterface simpleInterface;
        if (simpleInterface(m_resource) )
        {
            std::string playerName = simpleInterface.getPlayerName();
        }
    }
};
This way all your glue code doesn't have to touch most of the actual functioning code.

#2NightCreature83

Posted 12 June 2013 - 03:27 PM

How about you create a resource which is passed to the object on construction. This resource contains pointers/references to all managers in the game and accessors to get them. The object stores a reference to this object and all you need to do is care for the fact that all pointers in the resource need to outlive the objects it is passed into, which should be the case anyway as the system pointers it contains needs the objects to work.

If you then use transient interfaces that take a reference to this resource pointer you can hide away all the nasty manager access code in an interface that gets initialised:
class Resource; //Holds all manager pointers/references

class SimpleInterface
{
public:
    SimpleInterface() {}
    ~SimpleInterface() {}

    bool initialise(const Resource* resource); //This can take more paramater like the indexes or resource references needed

    //Add accessor members here to get the data you want
    const std::string getPlayerName()
    {
        if (m_resource->getPlayerManager())
        {
            return m_resource->getPlayerManager().getPlayer().getName();        
        }

        return "Player One";
    }
private:
    Resource* m_resource;
};

class System
{
public:
    void Update()
    {
        SimpleInterface simpleInterface;
        if (simpleInterface(m_resource) )
        {
            std::string playerName = simplerInterface.getPlayerName();
        }
    }
};
This way all your glue code doesn't have to touch most of the actual functioning code.

#1NightCreature83

Posted 12 June 2013 - 03:26 PM

How about you create a resource which is passed to the object on construction. This resource contains pointers/references to all managers in the game and accessors to get them. The object stores a reference to this object and all you need to do is care for the fact that all pointers in the resource need to outlive the objects it is passed into, which should be the case anyway as the system pointers it contains needs the objects to work.

If you then use transient interfaces that take a reference to this resource pointer you can hide away all the nasty manager access code in an interface that gets initialised:
class Resource; //Holds all manager pointers/references

class SimpleInterface
{
public:
    SimpleInterface() {}
    ~SimplerInterface() {}

    bool initialise(const Resource* resource); //This can take more paramater like the indexes or resource references needed

    //Add accessor members here to get the data you want
    const std::string getPlayerName()
    {
        if (m_resource->getPlayerManager())
        {
            return m_resource->getPlayerManager().getPlayer().getName();        
        }

        return "Player One";
    }
private:
    Resource* m_resource;
};

class System
{
public:
    void Update()
    {
        SimpleInterface simpleInterface;
        if (simpleInterface(m_resource) )
        {
            std::string playerName = simplerInterface.getPlayerName();
        }
    }
};

PARTNERS