Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

neurokaotix

Question regarding making classes that accept a variable...

This topic is 5617 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

Currently, in my engine when you want to create a new light object for instance you would type: this->Engine->sceneManager->sceneNode->nodeLight->createLight("Light1"); This is kinda long but what my parter in the project suggested we do is something along the lines of this: this->Engine->sceneManager("Level1")->createLight("Light1"); Now, how do I make it so I can pass sceneManager the name of the level and then be able to select which function I want? I really have no idea... Any help would be greatly appreciated :D Join the World Wide Revolution:

Share this post


Link to post
Share on other sites
Advertisement
You could make it like this:

  
class Engine {
Engine() {
m_sceneMap["Level1"] = new SceneManager(plahplahplah);
m_sceneMap["Level2"] = new SceneManager(blehblehbleh);
}

~Engine() {
//TODO: release mem yo lazy bum

}

SceneManager* getScene(const std::string& sceneName) {
assert(m_sceneMap.find(sceneName) != m_sceneMap.end());
return m_sceneMap[sceneName];
}

std::map<std::string, SceneManager*> m_sceneMap;
};

//now you can do:


Engine e;
e->getScene("Level1")->sceneNode->nodeLight->createLight("Light1");

So just make a function that returns a pointer to some other object and use a map to look-up the correct object (or preferably hash_map if you have one)

Share this post


Link to post
Share on other sites
Wait a sec I think I kinda misunderstood the question..

But anyway. If you want to call
getScene("Level1")->xxx;
where xxx can be just about anything, you have no choice but to make a new class that indirects the function calls to the real functions (such as sceneNode->nodeLight->createLight()), and then getScene returns an instance of this auxiliary class.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
maybe something like this..

Engine->AddLight("Level","Light1";

Engine::AddLight(...)
{
// do stuff here
sceneManager->createLight(...) // or what ever..
}

So you hide as much as possible of the stuff that
is goining on.

<Oze>

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!