Last active
December 17, 2015 08:28
-
-
Save bwrsandman/5579843 to your computer and use it in GitHub Desktop.
Comparison between two functions that do the same thing. One is writen out in regular form with a lot of repition, the other uses function pointers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Ogre::DotSceneLoader::processEnvironment(TiXmlElement *XMLNode) | |
{ | |
const String attrNames [] = {"fog", "skyBox", "skyDome", "skyPlane", "clipping"}; | |
void (Ogre::DotSceneLoader::*funcNames[]) (TiXmlElement*) = { | |
&Ogre::DotSceneLoader::processFog, | |
&Ogre::DotSceneLoader::processSkyBox, | |
&Ogre::DotSceneLoader::processSkyDome, | |
&Ogre::DotSceneLoader::processSkyPlane, | |
&Ogre::DotSceneLoader::processClipping}; | |
TiXmlElement *pElement; | |
for(uint i = 0; i < 5; ++i) | |
if(pElement = XMLNode->FirstChildElement(attrNames[i])) | |
(this->*funcNames[i])(pElement); | |
if(pElement = XMLNode->FirstChildElement("colourAmbient")) | |
mSceneMgr->setAmbientLight(parseColour(pElement)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Ogre::DotSceneLoader::processEnvironment(TiXmlElement *XMLNode) | |
{ | |
TiXmlElement *pElement; | |
if(pElement = XMLNode->FirstChildElement("fog");) | |
processFog(pElement); | |
if(pElement = XMLNode->FirstChildElement("skyBox");) | |
processSkyBox(pElement); | |
if(pElement = XMLNode->FirstChildElement("skyDome");) | |
processSkyDome(pElement); | |
if(pElement = XMLNode->FirstChildElement("skyPlane");) | |
processSkyPlane(pElement); | |
if(pElement = XMLNode->FirstChildElement("clipping");) | |
processClipping(pElement); | |
if(pElement = XMLNode->FirstChildElement("colourAmbient");) | |
mSceneMgr->setAmbientLight(parseColour(pElement)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment