Version 5 (modified by bensch, 20 years ago) (diff) |
---|
Module Description
How to use certain modules in the Orxonox Framework [br] Currently we have following modules descriptions here:
- list (list.h)
- ResourceManager (resource_manager.h)
list
There is a list template called "tList" use it as follows:
Use in Functions without Global Reference
It you just want to create a new list and just quickly use it make it as follows:
#include "list.h" /* include the header */ #include "debug.h" /* for use of PRINTF */ . . . tList<char>* nameList = new tList<char>(); /* create the new list*/ nameList->add("Pumba"); /* add some elements*/ nameList->add("Mogli"); nameList->add("Timon"); tIterator<char>* nameIterator = nameList->getIterator(); /* get the iterator - JAVA style */ char name* = nameIterator->nextElement(); /* this returns the FIRST element */ while( name != NULL) /* nextElement() will return NULL at the end */ { PRINTF(3)("found name: %s in list\n", name); name = nameIterator->nextElement(); /* give back the next element or NULL if last */ } delete nameIterator; /* don't forget to delete the iterator reference again . .
This code will have an output like this:
found name: Pumpa in list found name: Mogli in list found name: Timon in list
You can make lists of whatever you want eg also from WorldEntities:
#include "list.h" . . tList<WorldEntity>* entityList = new tList<WorldEntity>(); /* crete new list*/ entityList->add(new WorldEntity()); /* just adds an new entity */ . .
And you can make Lists of Lists
#include "list.h" . . tList<char>* nameList = new tList<char>(); tList<tList<char> >* nameListList = new tList<tList<char> >(); /* don't forget the space (_): >_> otherwhise it will be interpreted as an operator */ . .
Now I hear you screem: "ENOUGH"! And you are right…
Use in Header Files
If you want a list as a class attribute you have to make a forward declaration of the list:
#inlcude "list.h" /* include the header of the list */ template<class T> class tList; /* forward declaration of the list */ class ExampleClass { private: tList<> };
Resource Manager
There is a filehandler, that loades stores and unloades resources, like .obj-models, wav's, ogg's, textures and so on
usage in a WorldEntity like the Player
#include "resource_manager.h" /* includes the headers of the ResourceManager */ Player::Player() /* in the initialisation we load the module */ { . . . /* the following loads an OBJ-file named models/reaplow.obj * The type is OBJ (if no type is specified the model will try to determine it for itself) * RP_CAMPAIGN tells the ResourceManager when, and if it will be allowed to delete the Model */ this->model = (Model*)ResourceManager::load("models/reaplow.obj", OBJ, RP_CAMPAIGN); } Player::~Player() { /* here we would unload the Resource, that we allocated, but because WorldEntity * is doing it anyway, we do not have to concern ourselves with this. * But one could do something like: ResourceManager::unload(this->model); to do it */ } /* and thats it */
settings
As we see in the Player::Player() example, there are some options to be considered when allocating a resource:
RESOURCE TYPES: different types known to the resourceManager
/** OBJ: a .obj-file PRIM: a Model primitive (CUBE, CYLINDER, SPHERE and so on...) WAV: a wave-file OGG: i think you get it */ enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, IMAGE};
RESOURCE PRIORITIES: different unload-stages
/** RP_NO: will be unloaded on request RP_LEVEL: will be unloaded at the end of a Level RP_CAMPAIGN: will be unloaded at the end of a Campaign RP_GAME: will be unloaded at the end of the whole Game (when exiting orxonox) */ enum ResourcePriority {RP_NO = 0, RP_LEVEL = 1, RP_CAMPAIGN = 2, RP_GAME = 3};