Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 5 and Version 6 of code/doc/ModulesDescription


Ignore:
Timestamp:
Apr 17, 2005, 4:42:05 PM (19 years ago)
Author:
bensch
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/ModulesDescription

    v5 v6  
    11= Module Description =
    22How to use certain modules in the Orxonox Framework
    3 [br]
     3[[br]]
    44Currently we have following modules descriptions here:
    5  * list (list.h)
     5 * GenList (list.h)
    66 * ResourceManager (resource_manager.h)
    77
    8 == list ==
    9 There is a list template called "tList" use it as follows:
    10 
    11 === Use in Functions without Global Reference ===
    12 It you just want to create a new list and just quickly use it make it as follows:
    13 {{{
    14 #include "list.h"                           /* include the header */
    15 #include "debug.h"                          /* for use of PRINTF */
    16 .
    17 .
    18 .
    19 tList<char>* nameList = new tList<char>(); /* create the new list*/
    20 
    21 nameList->add("Pumba");                     /* add some elements*/
    22 nameList->add("Mogli");
    23 nameList->add("Timon");
    24 
    25 tIterator<char>* nameIterator = nameList->getIterator(); /* get the iterator - JAVA style */
    26 char name* = nameIterator->nextElement();   /* this returns the FIRST element */
    27 while( name != NULL)                        /* nextElement() will return NULL at the end */
    28 {
    29   PRINTF(3)("found name: %s in list\n", name);
    30   name = nameIterator->nextElement();       /* give back the next element or NULL if last */
    31 }
    32 delete nameIterator;                        /* don't forget to delete the iterator reference again
    33 .
    34 .
    35 }}}
    36 This code will have an output like this:
    37 {{{
    38 found name: Pumpa in list
    39 found name: Mogli in list
    40 found name: Timon in list
    41 }}}
    42 You can make lists of whatever you want eg also from WorldEntities:
    43 {{{
    44 #include "list.h"
    45 .
    46 .
    47 tList<WorldEntity>* entityList = new tList<WorldEntity>();  /* crete new list*/
    48 entityList->add(new WorldEntity());                         /* just adds an new entity */
    49 .
    50 .
    51 }}}
    52 And you can make Lists of Lists :))
    53 {{{
    54 #include "list.h"
    55 .
    56 .
    57 tList<char>* nameList = new tList<char>();
    58 tList<tList<char> >* nameListList = new tList<tList<char> >(); /* don't forget the space (_): >_>
    59                                                                   otherwhise it will be interpreted
    60                                                                   as an operator
    61                                                                */
    62 .
    63 .
    64 }}}
    65 Now I hear you screem: "ENOUGH"! And you are right...:)
    66 
    67 === Use in Header Files ===
    68 If you want a list as a class attribute you have to make a forward declaration of the list:
    69 {{{
    70 
    71 #inlcude "list.h"                 /* include the header of the list */
    72 
    73 template<class T> class tList;    /* forward declaration of the list */
    74 
    75 class ExampleClass
    76 {
    77  private:
    78   tList<>
    79 };
    80 
    81 }}}
    82 
    83 == Resource Manager ==
    84 There is a filehandler, that loades stores and unloades resources, like .obj-models, wav's, ogg's, textures and so on
    85 
    86 == usage in a WorldEntity like the Player ==
    87 {{{
    88 #include "resource_manager.h"     /* includes the headers of the ResourceManager */
    89 
    90 Player::Player()         /* in the initialisation we load the module */
    91 {
    92   .
    93   .
    94   .
    95   /* the following loads an OBJ-file named models/reaplow.obj
    96    * The type is OBJ (if no type is specified the model will try to determine it for itself)
    97    * RP_CAMPAIGN tells the ResourceManager when, and if it will be allowed to delete the Model
    98   */
    99   this->model = (Model*)ResourceManager::load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
    100 }
    101 
    102 Player::~Player()
    103 {
    104    /* here we would unload the Resource, that we allocated, but because WorldEntity
    105     * is doing it anyway, we do not have to concern ourselves with this.
    106     * But one could do something like: ResourceManager::unload(this->model); to do it
    107    */
    108 }
    109 
    110 /* and thats it */
    111 }}}
    112 
    113 == settings ==
    114 As we see in the Player::Player() example, there are some options to be considered when
    115 allocating a resource:
    116 
    117 __RESOURCE TYPES__: different types known to the resourceManager
    118 {{{
    119 /**
    120    OBJ: a .obj-file
    121    PRIM: a Model primitive (CUBE, CYLINDER, SPHERE and so on...)
    122    WAV: a wave-file
    123    OGG: i think you get it
    124 */
    125 enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, IMAGE};
    126 }}}
    127 
    128 __RESOURCE PRIORITIES__: different unload-stages
    129 {{{
    130 /**
    131    RP_NO: will be unloaded on request
    132    RP_LEVEL: will be unloaded at the end of a Level
    133    RP_CAMPAIGN: will be unloaded at the end of a Campaign
    134    RP_GAME: will be unloaded at the end of the whole Game (when exiting orxonox)
    135 */
    136 enum ResourcePriority {RP_NO = 0, RP_LEVEL = 1, RP_CAMPAIGN = 2, RP_GAME = 3};
    137 }}}
    138