A class concerning entities (objects) drawed in the engine.
If you derive classes from that, you need to call the base constructor and set the class name in the constructor.
They will add themselves to a list on creation (with new) and will be removed from that list with delete.
If you delete
the entity, it gets removed from the list and its node gets removed from the scene manager if it is of class or derived from qNodeEntity
type.
If you derive your own entities from that class, you maybe need to write new serialize and deserialize functions.
You need to call the serialize / deserialize
function of your base class
first in that functions.
You need to catch your own classes in OnGetEntityToLoad
in your qClickReceiver
derivate, create an entity with it and return it.
That function gets the class name as parameter.
You don't have to concern about the entity classes from the engine (qEntity, qNodeEntity, qNavEntity), only about your own classes.
Pointer to the engine singleton so we can use it directly.
Pointer to the video driver to be used in OnDraw for drawing stuff.
The class name which you must set in the constructor of your derived class. It is needed for saving and loading scenes.
Base constructor which has to be called from each derived class.
like this:
myclass(qString name) : qEntity(name)
{classname="myclass";} // set the class name in the constructor
Returns the list with all the registered entities in it.
Entities will be registered in the list when calling new
and moved out of the list by calling delete
.
Remember to create mesh node entities with engine->createNodeEntity()
, not with new
.
Removes all entities from all lists and deletes them.
Resets the ID-counter to 0.
Returns the first entity with the given name.
Use engine->getEntityByName(name)
, not this one.
Returns the internal ID of this entity.
Returns the name of the entity. Note that more than one entity can have the same name.
Returns the position of this entity. It's virtual because some entities have other position variables than the base one. (node->getPosition() in qMeshNodeEntity for instance.)
Sets the position of the entity. It's virtual because position could be another variable than the base entity one.
Adds pos
to the current position of this entity.
Loads the values of an entity from a file.
See in serialize
how to use it.
Save the entity to a file stream.
When you overwrite that function, you need to call the serialize
function of the base class.
Also you need to catch the entity on loading in the OnGetEntityLoaded
function in your qEventReceiver
derivate.
In your class:
class MyClass : public qEntity
{
public:
qString mytextline;
// create a constructor, pass the name and set the class name.
MyClass(std::string name): qEntity(name) {classname="MyClass";}
// save your values
virtual void serialize(std::ofstream& file)
{
// first call the serialize of YOUR base class.
qEntity::serialize(file);
// then write your own values
file<<this->mytextline<<^\n';
file<<this->getMyValue()<<'\n';
...
}
// load your values.
virtual void deserialize(std::ifstream& file)
{
qString nope;
int mynumber;
// read your own values,
// in the same order as you wrote them.
std::getline(file,this->mytextline);
file>>mynumber;
// if you read values and have an endline,
// you need to call getline after loading the values.
std::getline(file, nope);
...
// don't forget to set the values on your entity
this->setMyNumber(mynumber) // example
}
...
};
Then the receiver:
class rcvr : public qClickReceiver
{
virtual qEntity* OnGetEntityToLoad(std::string classname)
{
if(classname=="MyClass")
return new MyClass("name will be loaded later");
return NULL;
}
}