My goal is to make an object with an attached light that moves around randomly. I couldn't decide whether I wanted to make an object that inherited off Entity, Node, or Light so I simply made an object that encloses them all. Since I want to create several of them I want an object that will take care of the code for creating the entity, node, and light automatically. Would this constructor work? Or is there some sort of problem like clashing names?
Big problems.
But none you can't overcome:
Put an ID, or generate a unique ID in the constructor or a utility class, and append it to the names of the scene node, entity and light.
/* Less noise. More signal. */ Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion. OgreAddons - the Ogre code suppository.
jacmoe wrote:Big problems.
But none you can't overcome:
Put an ID, or generate a unique ID in the constructor or a utility class, and append it to the names of the scene node, entity and light.
How do I autogenerate the names and assign them to the entity? I don't know how to phrase it in google to get good results...
Also what needs to be unique? Just the names of the node, entity, and light or the variable names of each of these as well?
#include <string>
/**
* \brief A utility class to generate unique names.
**/
class NameGenerator
{
public:
/**
* \brief Gets the next unique name.
**/
static std::string Next();
/**
* \brief Gets the next unique name for a given prefix.
**/
static String Next(const std::string& prefix);
/**
* \brief Counts the number of unique auto-generated names.
**/
static size_t Count();
/**
* \brief Counts the number of names generated for a given prefix.
* \param prefix The prefix of the generated names.
**/
static size_t Count(const std::string& prefix);
private:
NameGenerator(void);
~NameGenerator(void);
typedef std::map<std::string, uint32> NameCountMap;
static NameCountMap s_nameCount;
};
std::string autogenerated_name = NameGenerator::Next(); // Generates (from the above code) 'AutoGeneratedName_x', where x is a number
std::string new_entity_name = NameGenerator::Next("Entity"); // Generates 'Entity_x', where x is a number
Hope this solves your problem regarding generating unique names.
About the which ones should have unique names, all objects of a particular group should have unique names. Like every entity should have a unique name, which doesn't clash with another entity and the same goes for lights, scene nodes and so on. But between the groups they can have the same name, like an Entity can have the name "MyActor", while *a* scene node also has the same name.
std::string autogenerated_name = NameGenerator::Next(); // Generates (from the above code) 'AutoGeneratedName_x', where x is a number
std::string new_entity_name = NameGenerator::Next("Entity"); // Generates 'Entity_x', where x is a number
Hope this solves your problem regarding generating unique names.
About the which ones should have unique names, all objects of a particular group should have unique names. Like every entity should have a unique name, which doesn't clash with another entity and the same goes for lights, scene nodes and so on. But between the groups they can have the same name, like an Entity can have the name "MyActor", while *a* scene node also has the same name.
Alright so could I use it like this? Or would I have to declare a Namegenerator object explicitly?