Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6693 in orxonox.OLD for branches/network/src


Ignore:
Timestamp:
Jan 25, 2006, 2:19:46 PM (19 years ago)
Author:
patrick
Message:

branches: removed spaceshipcontrol branche

Location:
branches/network/src
Files:
1 deleted
39 edited
10 copied

Legend:

Unmodified
Added
Removed
  • branches/network/src/defs/class_id.h

    r6678 r6693  
    179179  CL_SPAWNING_POINT             =    0x0000020c,
    180180  CL_MD2_CREATURE               =    0x0000020d,
     181  CL_HOVER                      =    0x0000020e,
    181182
    182183  CL_TURRET_POWER_UP            =    0x00000211,
     
    209210
    210211  CL_WEAPON_MANAGER             =    0x00000503,
     212  CL_AMMO_CONTAINER             =    0x00000504,
    211213  CL_HUD                        =    0x00000520,
    212214
  • branches/network/src/lib/graphics/importer/material.cc

    r6622 r6693  
    8181    ResourceManager::getInstance()->unload(this->diffuseTexture);
    8282  if (m.diffuseTexture != NULL)
    83     this->diffuseTexture = m.diffuseTexture; /// HACK shoudl be:(Texture*)ResourceManager::getInstance()->load();
     83    this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture);
    8484  this->ambientTexture = NULL; /// FIXME
    8585  this->specularTexture = NULL; /// FIXME
     
    303303  //! @todo Textures from .mtl-file need special care.
    304304  if (dMap != NULL)
    305     this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (void*)&target);
     305    this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);
    306306  else
    307307    this->diffuseTexture = NULL;
  • branches/network/src/lib/graphics/importer/md2Model.cc

    r6222 r6693  
    7878{
    7979  /* this creates the data container via ressource manager */
    80   this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, (void*)skinFileName);
     80  this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName);
    8181  if( unlikely(this->data == NULL))
    8282    PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n");
  • branches/network/src/lib/graphics/shader.cc

    r5390 r6693  
    106106Shader* Shader::getShader(const char* vertexShaderFile, const char* fragmentShaderFile)
    107107{
    108   return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER,  RP_LEVEL, (void*)fragmentShaderFile);
     108  return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER,  RP_LEVEL, fragmentShaderFile);
    109109}
    110110
  • branches/network/src/lib/graphics/text_engine/text.cc

    r6349 r6693  
    9292  if (fontFile != NULL)
    9393  {
    94     tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, &fontSize);
     94    tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize);
    9595    if (tmpFont != NULL)
    9696      this->font = tmpFont;
  • branches/network/src/lib/lang/base_object.cc

    r6634 r6693  
    1313   ### File Specific:
    1414   main-programmer: Patrick Boenzli
    15    co-programmer: ...
     15   co-programmer: Benjamin Grauer
    1616*/
    1717#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE
  • branches/network/src/lib/particles/Makefile.am

    r6629 r6693  
    1111                        spark_particles.cc \
    1212                        model_particles.cc \
     13                        dot_particles.cc \
    1314                        \
    1415                        quick_animation.cc
     
    2223                        spark_particles.h \
    2324                        model_particles.h \
     25                        dot_particles.h \
    2426                        \
    2527                        quick_animation.h
  • branches/network/src/lib/particles/model_particles.cc

    r6629 r6693  
    6161*/
    6262ModelParticles::~ModelParticles()
    63 {
    64   // deleting all the living Particles
    65   while (this->particles)
    66   {
    67     Particle* tmpDelPart = this->particles;
    68     this->particles = this->particles->next;
    69     delete tmpDelPart;
    70   }
    71 
    72   // deleting all the dead particles
    73   while (this->deadList)
    74   {
    75     Particle* tmpDelPart = this->deadList;
    76     this->deadList = this->deadList->next;
    77     delete tmpDelPart;
    78   }
    79 }
     63{ }
    8064
    8165/**
  • branches/network/src/lib/particles/spark_particles.cc

    r6629 r6693  
    6060*/
    6161SparkParticles::~SparkParticles()
    62 {
    63   // deleting all the living Particles
    64   while (this->particles)
    65   {
    66     Particle* tmpDelPart = this->particles;
    67     this->particles = this->particles->next;
    68     delete tmpDelPart;
    69   }
    70 
    71   // deleting all the dead particles
    72   while (this->deadList)
    73   {
    74     Particle* tmpDelPart = this->deadList;
    75     this->deadList = this->deadList->next;
    76     delete tmpDelPart;
    77   }
    78 }
     62{ }
    7963
    8064/**
  • branches/network/src/lib/particles/sprite_particles.cc

    r6628 r6693  
    6161*/
    6262SpriteParticles::~SpriteParticles()
    63 {
    64   // deleting all the living Particles
    65   while (this->particles)
    66   {
    67     Particle* tmpDelPart = this->particles;
    68     this->particles = this->particles->next;
    69     delete tmpDelPart;
    70   }
    71 
    72   // deleting all the dead particles
    73   while (this->deadList)
    74   {
    75     Particle* tmpDelPart = this->deadList;
    76     this->deadList = this->deadList->next;
    77     delete tmpDelPart;
    78   }
    79 }
     63{ }
    8064
    8165/**
     
    125109  GLboolean checkLight = false;
    126110  glGetBooleanv(GL_LIGHTING, &checkLight);
    127   if (checkLight == GL_TRUE)
    128     glDisable(GL_LIGHTING);
     111//  if (checkLight == GL_TRUE)
     112//    glDisable(GL_LIGHTING);
    129113  glMatrixMode(GL_MODELVIEW);
    130114  glDepthMask(GL_FALSE);
  • branches/network/src/lib/util/executor/executor.cc

    r6222 r6693  
    6060  {
    6161    int type = va_arg(parameterList, int);
    62     this->defaultValue[i].setType(type);
     62    this->defaultValue[i].setType((MT_Type)type);
    6363  }
    6464}
  • branches/network/src/lib/util/multi_type.cc

    r5660 r6693  
    122122
    123123/**
     124 * @brief checks if the two Multitypes match
     125 * @param mt MultiType to check against this one
     126 * @returns true on match. false otherwise
     127 *
     128 * Two MultiType match if and only if
     129 *  1. the internal Type is the same
     130 *  2. the stored values match
     131 */
     132bool MultiType::operator==(const MultiType& mt) const
     133{
     134  if (this->type != mt.type)
     135    return false;
     136
     137  switch (this->type)
     138  {
     139    case MT_NULL:
     140      return true;
     141    case MT_BOOL:
     142      return (this->value.Bool == mt.value.Bool);
     143    case MT_INT:
     144      return (this->value.Int == mt.value.Int);
     145    case MT_CHAR:
     146      return (this->value.Char == mt.value.Char);
     147    case MT_FLOAT:
     148      return (this->value.Float == mt.value.Float);
     149    case MT_STRING:
     150      if (this->value.String != NULL && mt.value.String != NULL)
     151        return (!strcmp(this->value.String, mt.value.String));
     152      else
     153        return (this->value.String == NULL && mt.value.String == NULL);
     154  }
     155}
     156
     157/**
     158 * @brief checks if the internal value matches the boolean value.
     159 * @param value to check against this one
     160 * @returns true on match. false otherwise
     161 *
     162 * Two MultiType match if and only if
     163 *  1. the stored values match the given Value
     164 */
     165bool MultiType::operator==(const char* value) const
     166{
     167  if (this->value.String != NULL && value != NULL)
     168    return (!strcmp(this->value.String, value));
     169  else
     170    return (this->value.String == NULL && value == NULL);
     171}
     172
     173
     174/**
    124175 * initializes the MultiType
    125176 */
     
    136187 * @param type the new Type
    137188 */
    138 void MultiType::setType(int type)
     189void MultiType::setType(MT_Type type)
    139190{
    140191  if (this->type != type)
    141     this->type = (MT_Type)type;
     192    this->type = type;
    142193}
    143194
  • branches/network/src/lib/util/multi_type.h

    r5659 r6693  
    3131 */
    3232class MultiType {
    33 
    3433  public:
    3534    MultiType();
     
    4241    virtual ~MultiType();
    4342
    44     MultiType& operator= (const MultiType& mt);
     43    MultiType& operator=(const MultiType& mt);
     44    MultiType& operator=(bool value) { this->setBool(value); return *this; };
     45    MultiType& operator=(int value) { this->setInt(value); return *this; };
     46    MultiType& operator=(float value) { this->setFloat(value); return *this; };
     47    MultiType& operator=(char value) { this->setChar(value); return *this; };
     48    MultiType& operator=(const char* value) { this->setString(value); return *this; };
    4549
    46     void setType(int type);
     50    bool operator==(const MultiType& mt) const;
     51    bool operator==(bool value) const { return (this->getBool() == value); };
     52    bool operator==(int value) const { return (this->getInt() == value); };
     53    bool operator==(float value) const { return (this->getFloat() ==  value); };
     54    bool operator==(char value) const { return (this->getChar() == value); };
     55    bool operator==(const char* value) const;
     56    bool operator==(MT_Type type) const { return (this->type == type); }
     57    bool operator!=(MT_Type type) const { return (this->type != type); }
     58
     59    void setType(MT_Type type);
    4760
    4861    void setBool(bool value);
     
    5265    void setString(const char* value);
    5366
     67    // for your convenience.
    5468    inline void setValue(bool value) { this->setBool(value); };
    5569    inline void setValue(int value) { this->setInt(value); };
     
    8195
    8296  private:
    83 
    8497    union MultiTypeValue
    8598    {
  • branches/network/src/lib/util/substring.h

    r5656 r6693  
    1616  ~SubString();
    1717
     18  const char* operator[](unsigned int i) { return this->getString(i); };
     19
    1820  inline unsigned int getCount() { return this->splittersCount; };
    1921  const char* getString(unsigned int i);
  • branches/network/src/subprojects/importer/Makefile.am

    r6631 r6693  
    66importer_LDFLAGS = $(MWINDOWS)
    77
    8 bin_PROGRAMS = importer \
    9                multitex \
    10                                                          movie_player_test
     8bin_PROGRAMS =  \
     9                importer \
     10                multitex \
     11                movie_player_test
    1112
    1213importer_LDADD = \
     
    1718                $(MAINSRCDIR)/lib/shell/libORXshell.a \
    1819                $(MAINSRCDIR)/lib/sound/libORXsound.a \
    19                 $(MAINSRCDIR)/lib/graphics/importer/libORXimporter.a
     20                $(MAINSRCDIR)/lib/graphics/importer/libORXimporter.a \
     21                $(MAINSRCDIR)/lib/graphics/importer/libtc.a
    2022
    21 importer_SOURCES= ../framework.cc \
    22                   importer.cc \
    23                   tc.cc \
    24                   $(MAINSRCDIR)/util/state.cc \
    25                   $(MAINSRCDIR)/world_entities/camera.cc \
    26                   $(MAINSRCDIR)/lib/lang/base_object.cc \
    27                   $(MAINSRCDIR)/lib/lang/class_list.cc \
    28                   $(MAINSRCDIR)/lib/math/vector.cc \
    29                   $(MAINSRCDIR)/lib/math/quaternion.cc \
    30                   $(MAINSRCDIR)/util/loading/resource_manager.cc \
    31                   $(MAINSRCDIR)/lib/parser/ini_parser/ini_parser.cc \
    32                   $(MAINSRCDIR)/lib/coord/p_node.cc \
    33                   $(MAINSRCDIR)/util/loading/load_param.cc \
    34                   $(MAINSRCDIR)/util/loading/load_param_description.cc \
    35                   $(MAINSRCDIR)/lib/util/helper_functions.cc \
    36                   $(MAINSRCDIR)/lib/util/substring.cc \
    37                   $(MAINSRCDIR)/lib/util/color.cc \
    38                   $(MAINSRCDIR)/lib/util/multi_type.cc \
    39                   $(MAINSRCDIR)/lib/util/executor/executor.cc \
    40                   $(MAINSRCDIR)/util/loading/factory.cc
     23importer_SOURCES= \
     24                ../framework.cc \
     25                importer.cc \
     26                $(MAINSRCDIR)/util/state.cc \
     27                $(MAINSRCDIR)/world_entities/camera.cc \
     28                $(MAINSRCDIR)/lib/lang/base_object.cc \
     29                $(MAINSRCDIR)/lib/lang/class_list.cc \
     30                $(MAINSRCDIR)/lib/math/vector.cc \
     31                $(MAINSRCDIR)/lib/math/quaternion.cc \
     32                $(MAINSRCDIR)/util/loading/resource_manager.cc \
     33                $(MAINSRCDIR)/lib/parser/ini_parser/ini_parser.cc \
     34                $(MAINSRCDIR)/lib/coord/p_node.cc \
     35                $(MAINSRCDIR)/util/loading/load_param.cc \
     36                $(MAINSRCDIR)/util/loading/load_param_description.cc \
     37                $(MAINSRCDIR)/lib/util/helper_functions.cc \
     38                $(MAINSRCDIR)/lib/util/substring.cc \
     39                $(MAINSRCDIR)/lib/util/color.cc \
     40                $(MAINSRCDIR)/lib/util/multi_type.cc \
     41                $(MAINSRCDIR)/lib/util/executor/executor.cc \
     42                $(MAINSRCDIR)/util/loading/factory.cc
    4143
    4244
    4345
    44 multitex_LDADD = $(MAINSRCDIR)/lib/event/libORXevent.a \
    45                  $(MAINSRCDIR)/lib/network/libORXnet.a \
    46                  $(MAINSRCDIR)/lib/parser/tinyxml/libtinyxml.a \
    47                  $(MAINSRCDIR)/lib/graphics/libORXgraphics.a \
    48                  $(MAINSRCDIR)/lib/shell/libORXshell.a \
    49                  $(MAINSRCDIR)/lib/sound/libORXsound.a \
    50                  $(MAINSRCDIR)/lib/graphics/importer/libORXimporter.a
     46multitex_LDADD = \
     47                $(MAINSRCDIR)/lib/event/libORXevent.a \
     48                $(MAINSRCDIR)/lib/network/libORXnet.a \
     49                $(MAINSRCDIR)/lib/parser/tinyxml/libtinyxml.a \
     50                $(MAINSRCDIR)/lib/graphics/libORXgraphics.a \
     51                $(MAINSRCDIR)/lib/shell/libORXshell.a \
     52                $(MAINSRCDIR)/lib/sound/libORXsound.a \
     53                $(MAINSRCDIR)/lib/graphics/importer/libORXimporter.a
    5154
    52 multitex_SOURCES= ../framework.cc \
    53                   multitex.cc \
    54                   $(MAINSRCDIR)/util/state.cc \
    55                   $(MAINSRCDIR)/world_entities/camera.cc \
    56                   $(MAINSRCDIR)/lib/lang/base_object.cc \
    57                   $(MAINSRCDIR)/lib/lang/class_list.cc \
    58                   $(MAINSRCDIR)/lib/math/vector.cc \
    59                   $(MAINSRCDIR)/lib/math/quaternion.cc \
    60                   $(MAINSRCDIR)/util/loading/resource_manager.cc \
    61                   $(MAINSRCDIR)/lib/parser/ini_parser/ini_parser.cc \
    62                   $(MAINSRCDIR)/lib/coord/p_node.cc \
    63                   $(MAINSRCDIR)/util/loading/load_param.cc \
    64                   $(MAINSRCDIR)/util/loading/load_param_description.cc \
    65                   $(MAINSRCDIR)/lib/util/helper_functions.cc \
    66                   $(MAINSRCDIR)/lib/util/substring.cc \
    67                   $(MAINSRCDIR)/lib/util/color.cc \
    68                   $(MAINSRCDIR)/lib/util/multi_type.cc \
    69                   $(MAINSRCDIR)/lib/util/executor/executor.cc \
    70                   $(MAINSRCDIR)/util/loading/factory.cc
     55multitex_SOURCES= \
     56                ../framework.cc \
     57                multitex.cc \
     58                $(MAINSRCDIR)/util/state.cc \
     59                $(MAINSRCDIR)/world_entities/camera.cc \
     60                $(MAINSRCDIR)/lib/lang/base_object.cc \
     61                $(MAINSRCDIR)/lib/lang/class_list.cc \
     62                $(MAINSRCDIR)/lib/math/vector.cc \
     63                $(MAINSRCDIR)/lib/math/quaternion.cc \
     64                $(MAINSRCDIR)/util/loading/resource_manager.cc \
     65                $(MAINSRCDIR)/lib/parser/ini_parser/ini_parser.cc \
     66                $(MAINSRCDIR)/lib/coord/p_node.cc \
     67                $(MAINSRCDIR)/util/loading/load_param.cc \
     68                $(MAINSRCDIR)/util/loading/load_param_description.cc \
     69                $(MAINSRCDIR)/lib/util/helper_functions.cc \
     70                $(MAINSRCDIR)/lib/util/substring.cc \
     71                $(MAINSRCDIR)/lib/util/color.cc \
     72                $(MAINSRCDIR)/lib/util/multi_type.cc \
     73                $(MAINSRCDIR)/lib/util/executor/executor.cc \
     74                $(MAINSRCDIR)/util/loading/factory.cc
    7175
    72 movie_player_test_LDADD = $(MAINSRCDIR)/lib/event/libORXevent.a \
     76movie_player_test_LDADD = \
     77                $(MAINSRCDIR)/lib/event/libORXevent.a \
    7378                $(MAINSRCDIR)/lib/network/libORXnet.a \
    74                         $(MAINSRCDIR)/lib/parser/tinyxml/libtinyxml.a \
    75                                                         $(MAINSRCDIR)/lib/graphics/libORXgraphics.a \
    76                                                         $(MAINSRCDIR)/lib/shell/libORXshell.a \
    77                                                         $(MAINSRCDIR)/lib/sound/libORXsound.a \
    78                                                         $(MAINSRCDIR)/lib/graphics/importer/libORXimporter.a
     79                $(MAINSRCDIR)/lib/parser/tinyxml/libtinyxml.a \
     80                $(MAINSRCDIR)/lib/graphics/libORXgraphics.a \
     81                $(MAINSRCDIR)/lib/shell/libORXshell.a \
     82                $(MAINSRCDIR)/lib/sound/libORXsound.a \
     83                $(MAINSRCDIR)/lib/graphics/importer/libORXimporter.a
    7984
    80 movie_player_test_SOURCES= ../framework.cc \
    81                                                  movie_player_test.cc \
    82                                                  $(MAINSRCDIR)/util/state.cc \
    83                                                  $(MAINSRCDIR)/world_entities/camera.cc \
    84                                                  $(MAINSRCDIR)/lib/lang/base_object.cc \
    85                                                                                                          $(MAINSRCDIR)/lib/lang/class_list.cc \
    86                                                                                                          $(MAINSRCDIR)/lib/math/vector.cc \
    87                                                                                                          $(MAINSRCDIR)/util/loading/resource_manager.cc \
    88                                                                                                          $(MAINSRCDIR)/lib/parser/ini_parser/ini_parser.cc \
    89                                                                                                          $(MAINSRCDIR)/lib/coord/p_node.cc \
    90                                                                                                          $(MAINSRCDIR)/lib/coord/null_parent.cc \
    91                                                                                                          $(MAINSRCDIR)/util/loading/load_param.cc \
    92                                                                                                          $(MAINSRCDIR)/util/loading/load_param_description.cc \
    93                                                                                                          $(MAINSRCDIR)/lib/util/helper_functions.cc \
    94                                                                                                          $(MAINSRCDIR)/lib/util/substring.cc \
    95                                                                                                          $(MAINSRCDIR)/lib/util/color.cc \
    96                                                                                                          $(MAINSRCDIR)/lib/util/multi_type.cc \
    97                                                                                                          $(MAINSRCDIR)/lib/util/executor/executor.cc \
    98                                                                                                          $(MAINSRCDIR)/util/loading/factory.cc
     85movie_player_test_SOURCES= \
     86                ../framework.cc \
     87                movie_player_test.cc \
     88                $(MAINSRCDIR)/util/state.cc \
     89                $(MAINSRCDIR)/world_entities/camera.cc \
     90                $(MAINSRCDIR)/lib/lang/base_object.cc \
     91                $(MAINSRCDIR)/lib/lang/class_list.cc \
     92                $(MAINSRCDIR)/lib/math/vector.cc \
     93                $(MAINSRCDIR)/util/loading/resource_manager.cc \
     94                $(MAINSRCDIR)/lib/parser/ini_parser/ini_parser.cc \
     95                $(MAINSRCDIR)/lib/coord/p_node.cc \
     96                $(MAINSRCDIR)/lib/coord/null_parent.cc \
     97                $(MAINSRCDIR)/util/loading/load_param.cc \
     98                $(MAINSRCDIR)/util/loading/load_param_description.cc \
     99                $(MAINSRCDIR)/lib/util/helper_functions.cc \
     100                $(MAINSRCDIR)/lib/util/substring.cc \
     101                $(MAINSRCDIR)/lib/util/color.cc \
     102                $(MAINSRCDIR)/lib/util/multi_type.cc \
     103                $(MAINSRCDIR)/lib/util/executor/executor.cc \
     104                $(MAINSRCDIR)/util/loading/factory.cc
  • branches/network/src/util/hud.cc

    r6512 r6693  
    126126    {
    127127      weapon->getEnergyWidget()->show();
    128       weapon->getLoadedEnergyWidget()->show();
    129128      this->weaponsWidgets.push_back(weapon->getEnergyWidget());
    130       this->weaponsWidgets.push_back(weapon->getLoadedEnergyWidget());
    131129    }
    132130  }
  • branches/network/src/util/loading/resource_manager.cc

    r6467 r6693  
    1818#include "resource_manager.h"
    1919
     20#include "substring.h"
    2021#include "debug.h"
    2122
    2223#include <algorithm>
     24#include <assert.h>
    2325
    2426// different resource Types
     
    5052
    5153/**
    52  * standard constructor
     54 * @brief standard constructor
    5355*/
    5456ResourceManager::ResourceManager ()
     
    6668
    6769/**
    68  * standard destructor
     70 * @brief standard destructor
    6971*/
    7072ResourceManager::~ResourceManager ()
     
    7880  // deleting the Directorie Lists
    7981  while (!this->imageDirs.empty())
    80     {
    81       delete[] this->imageDirs.front();
    82       this->imageDirs.pop_front();
    83     }
     82  {
     83    delete[] this->imageDirs.back();
     84    this->imageDirs.pop_back();
     85  }
    8486
    8587  delete[] this->dataDir;
     
    8991
    9092/**
    91  * sets the data main directory
     93 * @brief sets the data main directory
    9294 * @param dataDir the DataDirectory.
    9395 */
     
    122124
    123125/**
    124  * sets the data main directory
     126 * @brief sets the data main directory
    125127 * @param dataDir the DataDirectory.
    126128 *
     
    153155
    154156
    155 
    156 /**
    157  * checks for the DataDirectory, by looking if
     157/**
     158 * @brief checks for the DataDirectory, by looking if
    158159 * @param fileInside is iniside of the given directory.
    159160*/
     
    162163  bool retVal;
    163164  if (!isDir(this->dataDir))
    164     {
    165       PRINTF(1)("%s is not a directory\n", this->dataDir);
    166       return false;
    167     }
     165  {
     166    PRINTF(1)("%s is not a directory\n", this->dataDir);
     167    return false;
     168  }
    168169
    169170  char* testFile = new char[strlen(this->dataDir)+strlen(fileInside)+1];
     
    176177#ifndef NO_TEXTURES
    177178/**
    178  * adds a new Path for Images
     179 * @brief adds a new Path for Images
    179180 * @param imageDir The path to insert
    180181 * @returns true, if the Path was well and injected (or already existent within the list)
     
    201202  // check if the param is a Directory
    202203  if (isDir(newDir))
    203     {
    204       // check if the Directory has been added before
    205       std::list<char*>::const_iterator imageDir;
    206       for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
     204  {
     205    // check if the Directory has been added before
     206    std::vector<char*>::const_iterator imageDir;
     207    for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
     208    {
     209      if (!strcmp(*imageDir, newDir))
    207210      {
    208          if (!strcmp(*imageDir, newDir))
    209          {
    210            PRINTF(3)("Path %s already loaded\n", newDir);
    211            delete[] newDir;
    212            return true;
    213          }
     211        PRINTF(3)("Path %s already loaded\n", newDir);
     212        delete[] newDir;
     213        return true;
    214214      }
    215       // adding the directory to the List
    216       this->imageDirs.push_back(newDir);
    217       return true;
    218     }
    219   else
    220     {
    221       PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", newDir);
    222       delete[] newDir;
    223       return false;
    224     }
     215    }
     216    // adding the directory to the List
     217    this->imageDirs.push_back(newDir);
     218    return true;
     219  }
     220  else
     221  {
     222    PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", newDir);
     223    delete[] newDir;
     224    return false;
     225  }
    225226}
    226227#endif /* NO_TEXTURES */
    227228
    228229/**
    229  * loads resources
     230 * @brief loads resources
    230231 * @param fileName: The fileName of the resource to load
    231232 * @param prio: The ResourcePriority of this resource (will only be increased)
     233 * @param param0: an additional option to parse (see the constuctors for more help)
    232234 * @param param1: an additional option to parse (see the constuctors for more help)
    233235 * @param param2: an additional option to parse (see the constuctors for more help)
    234  * @param param3: an additional option to parse (see the constuctors for more help)
    235236 * @returns a pointer to a desired Resource.
    236237*/
    237 BaseObject* ResourceManager::load(const char* fileName, ResourcePriority prio, void* param1, void* param2, void* param3)
     238BaseObject* ResourceManager::load(const char* fileName, ResourcePriority prio,
     239                                  const MultiType& param0, const MultiType& param1, const MultiType& param2)
    238240{
    239241  if (fileName == NULL)
     
    258260#endif
    259261#define __IF_OK
    260   if (!strncasecmp(fileName+(strlen(fileName)-4), ".wav", 4))
    261     tmpType = WAV;
    262   else if (!strncasecmp(fileName+(strlen(fileName)-4), ".mp3", 4))
    263     tmpType = MP3;
    264   else if (!strncasecmp(fileName+(strlen(fileName)-4), ".ogg", 4))
    265     tmpType = OGG;
     262    if (!strncasecmp(fileName+(strlen(fileName)-4), ".wav", 4))
     263      tmpType = WAV;
     264    else if (!strncasecmp(fileName+(strlen(fileName)-4), ".mp3", 4))
     265      tmpType = MP3;
     266    else if (!strncasecmp(fileName+(strlen(fileName)-4), ".ogg", 4))
     267      tmpType = OGG;
    266268#endif /* NO_AUDIO */
    267269#ifndef NO_TEXT
    268270#ifdef __IF_OK
    269   else
     271    else
    270272#endif
    271273#define __IF_OK
    272  if (!strncasecmp(fileName+(strlen(fileName)-4), ".ttf", 4))
    273     tmpType = TTF;
     274      if (!strncasecmp(fileName+(strlen(fileName)-4), ".ttf", 4))
     275        tmpType = TTF;
    274276#endif /* NO_TEXT */
    275277#ifndef NO_SHADERS
    276278#ifdef __IF_OK
    277   else
     279      else
    278280#endif
    279281#define __IF_OK
    280  if (!strncasecmp(fileName+(strlen(fileName)-5), ".vert", 5))
    281     tmpType = SHADER;
     282        if (!strncasecmp(fileName+(strlen(fileName)-5), ".vert", 5))
     283          tmpType = SHADER;
    282284#endif /* NO_SHADERS */
    283285#ifndef NO_TEXTURES
    284286#ifdef __IF_OK
    285   else
     287        else
    286288#else
    287289  if
    288290#endif
    289    tmpType = IMAGE;
     291          tmpType = IMAGE;
    290292#endif /* NO_TEXTURES */
    291293#undef __IF_OK
    292   return this->load(fileName, tmpType, prio, param1, param2, param3);
    293 }
    294 
    295 /**
    296  * loads resources
     294  return this->load(fileName, tmpType, prio, param0, param1, param2);
     295}
     296
     297/**
     298 * @brief caches a Resource
     299 *
     300 * @see load;
     301 *
     302 * @brief returns true if ok, false otherwise.
     303 * This function loads a Resource without applying it to an Object.
     304 * This is for loading purposes, e.g, when the user is loading a Resource
     305 * during the initialisation instead of at Runtime.
     306 */
     307bool ResourceManager::cache(const char* fileName, ResourceType type, ResourcePriority prio,
     308                            const MultiType& param0, const MultiType& param1, const MultiType& param2)
     309{
     310  assert(fileName != NULL);
     311
     312  // searching if the resource was loaded before.
     313  Resource* tmpResource;
     314  // check if we already loaded this Resource
     315  tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2);
     316  // otherwise load it
     317  if (tmpResource == NULL)
     318    tmpResource = this->loadResource(fileName, type, prio, param0, param1, param2);
     319  // return cached pointer.
     320  if (tmpResource != NULL) // if the resource was loaded before.
     321  {
     322    if(tmpResource->prio < prio)
     323      tmpResource->prio = prio;
     324    return true;
     325  }
     326  else
     327    return false;
     328}
     329
     330/**
     331 * tells the ResourceManager to generate a Copy of the Resource.
     332 * @brief resourcePointer: The Pointer to the resource to copy
     333 * @returns the Resource pointed to resourcePointer.
     334 */
     335BaseObject* ResourceManager::copy(BaseObject* resourcePointer)
     336{
     337  Resource* tmp = locateResourceByPointer(resourcePointer);
     338  if (tmp!=NULL)
     339  {
     340    tmp->count++;
     341    return tmp->pointer;
     342  }
     343  else
     344    return NULL;
     345}
     346
     347
     348/**
     349 * @brief loads resources
    297350 * @param fileName: The fileName of the resource to load
    298351 * @param type: The Type of Resource to load.
    299352 * @param prio: The ResourcePriority of this resource (will only be increased)
     353 * @param param0: an additional option to parse (see the constuctors for more help)
    300354 * @param param1: an additional option to parse (see the constuctors for more help)
    301355 * @param param2: an additional option to parse (see the constuctors for more help)
    302  * @param param3: an additional option to parse (see the constuctors for more help)
    303356 * @returns a pointer to a desired Resource.
    304357*/
    305358BaseObject* ResourceManager::load(const char* fileName, ResourceType type, ResourcePriority prio,
    306                             void* param1, void* param2, void* param3)
    307 {
    308   if (fileName == NULL)
     359                                  const MultiType& param0, const MultiType& param1, const MultiType& param2)
     360{
     361  assert(fileName != NULL);
     362
     363  // searching if the resource was loaded before.
     364  Resource* tmpResource;
     365  // check if we already loaded this Resource
     366  tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2);
     367  // otherwise load it
     368  if (tmpResource == NULL)
     369  {
     370    tmpResource = this->loadResource(fileName, type, prio, param0, param1, param2);
     371  }
     372  // return cached pointer.
     373  if (tmpResource != NULL) // if the resource was loaded before.
     374  {
     375    tmpResource->count++;
     376    if(tmpResource->prio < prio)
     377      tmpResource->prio = prio;
     378
     379    return tmpResource->pointer;
     380  }
     381  else
    309382    return NULL;
    310 
    311   // searching if the resource was loaded before.
    312   Resource* tmpResource = this->locateResourceByInfo(fileName, type, param1, param2, param3);
    313   if (tmpResource != NULL) // if the resource was loaded before.
    314     {
    315       PRINTF(4)("not loading cached resource %s\n", tmpResource->name);
    316       tmpResource->count++;
    317       if(tmpResource->prio < prio)
    318         tmpResource->prio = prio;
    319     }
    320   else
    321     {
    322       // Setting up the new Resource
    323       tmpResource = new Resource;
    324       tmpResource->count = 1;
    325       tmpResource->type = type;
    326       tmpResource->prio = prio;
    327       tmpResource->pointer = NULL;
    328       tmpResource->name = new char[strlen(fileName)+1];
    329       strcpy(tmpResource->name, fileName);
    330 
    331       // creating the full name. (directoryName + FileName)
    332       char* fullName = ResourceManager::getFullName(fileName);
    333       // Checking for the type of resource \see ResourceType
    334       switch(type)
    335         {
     383}
     384
     385
     386/**
     387 * @brief loads resources for internal purposes
     388 * @param fileName: The fileName of the resource to load
     389 * @param type: The Type of Resource to load.
     390 * @param prio: The ResourcePriority of this resource (will only be increased)
     391 * @param param0: an additional option to parse (see the constuctors for more help)
     392 * @param param1: an additional option to parse (see the constuctors for more help)
     393 * @param param2: an additional option to parse (see the constuctors for more help)
     394 * @returns a pointer to a desired Resource.
     395 */
     396Resource* ResourceManager::loadResource(const char* fileName, ResourceType type, ResourcePriority prio,
     397                                        const MultiType& param0, const MultiType& param1, const MultiType& param2)
     398{
     399  // Setting up the new Resource
     400  Resource* tmpResource = new Resource;
     401  tmpResource->count = 0;
     402  tmpResource->type = type;
     403  tmpResource->prio = prio;
     404  tmpResource->pointer = NULL;
     405  tmpResource->name = new char[strlen(fileName)+1];
     406  strcpy(tmpResource->name, fileName);
     407
     408  // creating the full name. (directoryName + FileName)
     409  char* fullName = ResourceManager::getFullName(fileName);
     410  // Checking for the type of resource \see ResourceType
     411  switch(type)
     412  {
    336413#ifndef NO_MODEL
    337         case OBJ:
    338           if (param1)
    339             tmpResource->modelSize = *(float*)param1;
    340           else
    341             tmpResource->modelSize = 1.0;
    342 
    343           if(ResourceManager::isFile(fullName))
    344             tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize);
    345           else
    346             {
    347               PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName, dataDir);
    348               tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, &tmpResource->modelSize);
    349             }
    350           break;
    351         case PRIM:
    352           if (param1)
    353             tmpResource->modelSize = *(float*)param1;
    354           else
    355             tmpResource->modelSize = 1.0;
    356 
    357           if (!strcmp(tmpResource->name, "cube"))
    358             tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->modelSize);
    359           else if (!strcmp(tmpResource->name, "sphere"))
    360             tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->modelSize);
    361           else if (!strcmp(tmpResource->name, "plane"))
    362             tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->modelSize);
    363           else if (!strcmp(tmpResource->name, "cylinder"))
    364             tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->modelSize);
    365           else if (!strcmp(tmpResource->name, "cone"))
    366             tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->modelSize);
    367           break;
    368         case MD2:
    369           if(ResourceManager::isFile(fullName))
    370             {
    371               if (param1 != NULL)
    372                 {
    373                   tmpResource->secFileName = new char[strlen((const char*)param1)+1];
    374                   strcpy(tmpResource->secFileName, (const char*) param1);
    375                 }
    376               else
    377                 tmpResource->secFileName = NULL;
    378                 tmpResource->pointer = new MD2Data(fullName, tmpResource->secFileName);
    379 //               tmpResource->pointer = new MD2Model(fullName, tmpResource->secFileName);
    380 
    381             }
    382               break;
     414    case OBJ:
     415      if (param0.getType() != MT_NULL)
     416        tmpResource->param[0] = param0;
     417      else
     418        tmpResource->param[0] = 1.0f;
     419
     420      if(ResourceManager::isFile(fullName))
     421        tmpResource->pointer = new OBJModel(fullName, tmpResource->param[0].getFloat());
     422      else
     423      {
     424        PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName, dataDir);
     425        tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, tmpResource->param[0].getFloat());
     426      }
     427      break;
     428    case PRIM:
     429      if (param0 != MT_NULL)
     430        tmpResource->param[0] = param0;
     431      else
     432        tmpResource->param[0] = 1.0f;
     433
     434      if (!strcmp(tmpResource->name, "cube"))
     435        tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->param[0].getFloat());
     436      else if (!strcmp(tmpResource->name, "sphere"))
     437        tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->param[0].getFloat());
     438      else if (!strcmp(tmpResource->name, "plane"))
     439        tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->param[0].getFloat());
     440      else if (!strcmp(tmpResource->name, "cylinder"))
     441        tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->param[0].getFloat());
     442      else if (!strcmp(tmpResource->name, "cone"))
     443        tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->param[0].getFloat());
     444      break;
     445    case MD2:
     446      if(ResourceManager::isFile(fullName))
     447      {
     448        tmpResource->param[0] = param0;
     449        tmpResource->pointer = new MD2Data(fullName, tmpResource->param[0].getString());
     450        //               tmpResource->pointer = new MD2Model(fullName, tmpResource->secFileName);
     451
     452      }
     453      break;
    383454#endif /* NO_MODEL */
    384455#ifndef NO_TEXT
    385         case TTF:
    386             if (param1 != NULL)
    387               tmpResource->ttfSize = *(unsigned int*)param1;
    388             else
    389               tmpResource->ttfSize = FONT_DEFAULT_RENDER_SIZE;
    390 
    391           if(isFile(fullName))
    392             tmpResource->pointer = new Font(fullName, tmpResource->ttfSize);
    393           else
    394             PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName, this->dataDir);
    395           break;
     456    case TTF:
     457      if (param0 != MT_NULL)
     458      {
     459        assert(param0.getInt() >= 0);
     460        tmpResource->param[0] = param0;
     461      }
     462      else
     463        tmpResource->param[0] = FONT_DEFAULT_RENDER_SIZE;
     464
     465      if(isFile(fullName))
     466        tmpResource->pointer = new Font(fullName, (unsigned int) tmpResource->param[0].getInt());
     467      else
     468        PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName, this->dataDir);
     469      break;
    396470#endif /* NO_TEXT */
    397471#ifndef NO_AUDIO
    398         case WAV:
    399           if(isFile(fullName))
    400             tmpResource->pointer = new SoundBuffer(fullName);
    401           break;
    402         case OGG:
    403           if (isFile(fullName))
    404             tmpResource->pointer = new OggPlayer(fullName);
    405           break;
     472    case WAV:
     473      if(isFile(fullName))
     474        tmpResource->pointer = new SoundBuffer(fullName);
     475      break;
     476    case OGG:
     477      if (isFile(fullName))
     478        tmpResource->pointer = new OggPlayer(fullName);
     479      break;
    406480#endif /* NO_AUDIO */
    407481#ifndef NO_TEXTURES
    408         case IMAGE:
    409           if (param1 != NULL)
    410             tmpResource->texTarget = *(GLenum*)param1;
    411           else
    412             tmpResource->texTarget = GL_TEXTURE_2D;
    413           if(isFile(fullName))
    414             {
    415               PRINTF(4)("Image %s resides to %s\n", fileName, fullName);
    416               tmpResource->pointer = new Texture(fullName);
    417             }
    418           else
    419             {
    420               std::list<char*>::iterator imageDir;
    421               for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
    422                 {
    423                   char* imgName = new char[strlen(*imageDir)+strlen(fileName)+1];
    424                   sprintf(imgName, "%s%s", *imageDir, fileName);
    425                   if(isFile(imgName))
    426                     {
    427                       PRINTF(4)("Image %s resides to %s\n", fileName, imgName);
    428                       tmpResource->pointer = new Texture(imgName, tmpResource->texTarget);
    429                       delete[] imgName;
    430                       break;
    431                     }
    432                   delete[] imgName;
    433                 }
    434             }
    435           if(!tmpResource)
    436              PRINTF(2)("!!Image %s not Found!!\n", fileName);
    437           break;
     482    case IMAGE:
     483      if (param0 != MT_NULL)
     484        tmpResource->param[0] = param0;
     485      else
     486        tmpResource->param[0] = GL_TEXTURE_2D;
     487      if(isFile(fullName))
     488      {
     489        PRINTF(4)("Image %s resides to %s\n", fileName, fullName);
     490        tmpResource->pointer = new Texture(fullName);
     491      }
     492      else
     493      {
     494        std::vector<char*>::iterator imageDir;
     495        for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
     496        {
     497          char* imgName = new char[strlen(*imageDir)+strlen(fileName)+1];
     498          sprintf(imgName, "%s%s", *imageDir, fileName);
     499          if(isFile(imgName))
     500          {
     501            PRINTF(4)("Image %s resides to %s\n", fileName, imgName);
     502            tmpResource->pointer = new Texture(imgName, tmpResource->param[0].getInt());
     503            delete[] imgName;
     504            break;
     505          }
     506          delete[] imgName;
     507        }
     508      }
     509      if(!tmpResource)
     510        PRINTF(2)("!!Image %s not Found!!\n", fileName);
     511      break;
    438512#endif /* NO_TEXTURES */
    439513#ifndef NO_SHADERS
    440           case SHADER:
    441             if(ResourceManager::isFile(fullName))
    442             {
    443               if (param1 != NULL)
    444               {
    445                 char* secFullName = ResourceManager::getFullName((const char*)param1);
    446                 if (ResourceManager::isFile(secFullName))
    447                 {
    448                   tmpResource->secFileName = new char[strlen((const char*)param1)+1];
    449                   strcpy(tmpResource->secFileName, (const char*) param1);
    450                   tmpResource->pointer = new Shader(fullName, secFullName);
    451                 }
    452                 delete[] secFullName;
    453               }
    454               else
    455               {
    456                 tmpResource->secFileName = NULL;
    457                 tmpResource->pointer = new Shader(fullName, NULL);
    458               }
    459             }
    460             break;
     514    case SHADER:
     515      if(ResourceManager::isFile(fullName))
     516      {
     517        if (param0 != MT_NULL)
     518        {
     519          MultiType param = param0; /// HACK
     520          char* secFullName = ResourceManager::getFullName(param.getString());
     521          if (ResourceManager::isFile(secFullName))
     522          {
     523            tmpResource->param[0] = secFullName;
     524            tmpResource->pointer = new Shader(fullName, secFullName);
     525          }
     526          delete[] secFullName;
     527        }
     528        else
     529        {
     530          tmpResource->param[0] = param0;
     531          tmpResource->pointer = new Shader(fullName, NULL);
     532        }
     533      }
     534      break;
    461535#endif /* NO_SHADERS */
    462         default:
    463           tmpResource->pointer = NULL;
    464           PRINTF(1)("No type found for %s.\n   !!This should not happen unless the Type is not supported yet. JUST DO IT!!\n", tmpResource->name);
    465           break;
    466         }
    467       if (tmpResource->pointer != NULL)
    468         this->resourceList.push_back(tmpResource);
    469       delete[] fullName;
    470     }
     536    default:
     537      tmpResource->pointer = NULL;
     538      PRINTF(1)("No type found for %s.\n   !!This should not happen unless the Type is not supported yet. JUST DO IT!!\n", tmpResource->name);
     539      break;
     540  }
    471541  if (tmpResource->pointer != NULL)
    472     return tmpResource->pointer;
    473   else
    474     {
    475       PRINTF(2)("Resource %s could not be loaded\n", fileName);
    476       delete[] tmpResource->name;
    477       delete tmpResource;
    478       return NULL;
    479     }
    480 }
    481 
    482 /**
    483  * unloads a Resource
     542    this->resourceList.push_back(tmpResource);
     543  delete[] fullName;
     544
     545
     546  if (tmpResource->pointer != NULL)
     547    return tmpResource;
     548  else
     549  {
     550    PRINTF(2)("Resource %s could not be loaded\n", fileName);
     551    delete[] tmpResource->name;
     552    delete tmpResource;
     553    return NULL;
     554  }
     555}
     556
     557/**
     558 * @brief unloads a Resource
    484559 * @param pointer: The pointer to free
    485560 * @param prio: the PriorityLevel to unload this resource
    486561 * @returns true if successful (pointer found, and deleted), false otherwise
    487562*/
    488 bool ResourceManager::unload(void* pointer, ResourcePriority prio)
     563bool ResourceManager::unload(BaseObject* pointer, ResourcePriority prio)
    489564{
    490565  if (pointer == NULL)
     
    502577
    503578/**
    504  * unloads a Resource
     579 * @brief unloads a Resource
    505580 * @param resource: The resource to unloade
    506581 * @param prio the PriorityLevel to unload this resource
     
    515590
    516591  if (resource->prio <= prio)
    517     {
    518       if (resource->count == 0)
    519         {
    520           // deleting the Resource
    521           switch(resource->type)
    522             {
     592  {
     593    if (resource->count == 0)
     594    {
     595      // deleting the Resource
     596      switch(resource->type)
     597      {
    523598#ifndef NO_MODEL
    524             case OBJ:
    525             case PRIM:
    526               delete (Model*)resource->pointer;
    527               break;
    528             case MD2:
    529               delete (MD2Data*)resource->pointer;
    530               break;
     599        case OBJ:
     600        case PRIM:
     601          delete (Model*)resource->pointer;
     602          break;
     603        case MD2:
     604          delete (MD2Data*)resource->pointer;
     605          break;
    531606#endif /* NO_MODEL */
    532607#ifndef NO_AUDIO
    533             case WAV:
    534               delete (SoundBuffer*)resource->pointer;
    535               break;
    536             case OGG:
    537               delete (OggPlayer*)resource->pointer;
    538               break;
     608        case WAV:
     609          delete (SoundBuffer*)resource->pointer;
     610          break;
     611        case OGG:
     612          delete (OggPlayer*)resource->pointer;
     613          break;
    539614#endif /* NO_AUDIO */
    540615#ifndef NO_TEXT
    541             case TTF:
    542               delete (Font*)resource->pointer;
    543               break;
     616        case TTF:
     617          delete (Font*)resource->pointer;
     618          break;
    544619#endif /* NO_TEXT */
    545620#ifndef NO_TEXTURES
    546             case IMAGE:
    547               delete (Texture*)resource->pointer;
    548               break;
     621        case IMAGE:
     622          delete (Texture*)resource->pointer;
     623          break;
    549624#endif /* NO_TEXTURES */
    550625#ifndef NO_SHADERS
    551             case SHADER:
    552               delete (Shader*)resource->pointer;
    553               break;
     626        case SHADER:
     627          delete (Shader*)resource->pointer;
     628          break;
    554629#endif /* NO_SHADERS */
    555             default:
    556               PRINTF(2)("NOT YET IMPLEMENTED !!FIX FIX!!\n");
    557               return false;
    558               break;
    559             }
    560           // deleting the List Entry:
    561           PRINTF(4)("Resource %s safely removed.\n", resource->name);
    562           delete[] resource->name;
    563           std::list<Resource*>::iterator resourceIT = std::find(this->resourceList.begin(), this->resourceList.end(), resource);
    564           this->resourceList.erase(resourceIT);
    565           delete resource;
    566         }
    567       else
    568         PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name, resource->count);
    569     }
     630        default:
     631          PRINTF(2)("NOT YET IMPLEMENTED !!FIX FIX!!\n");
     632          return false;
     633          break;
     634      }
     635      // deleting the List Entry:
     636      PRINTF(4)("Resource %s safely removed.\n", resource->name);
     637      delete[] resource->name;
     638      std::vector<Resource*>::iterator resourceIT = std::find(this->resourceList.begin(), this->resourceList.end(), resource);
     639      this->resourceList.erase(resourceIT);
     640      delete resource;
     641    }
     642    else
     643      PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name, resource->count);
     644  }
    570645  else
    571646    PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name);
     
    575650
    576651/**
    577  * unloads all alocated Memory of Resources with a pririty lower than prio
     652 * @brief unloads all alocated Memory of Resources with a pririty lower than prio
    578653 * @param prio The priority to delete
    579654*/
    580655bool ResourceManager::unloadAllByPriority(ResourcePriority prio)
    581656{
    582   std::list<Resource*>::iterator resource, pre;
    583   pre = --this->resourceList.end();
    584657  unsigned int removeCount;
    585658  for (unsigned int round = 0; round < 3; round++)
    586659  {
     660    int index = this->resourceList.size() - 1;
    587661    removeCount = 0;
    588     while (pre != resourceList.end())
    589     {
    590       resource = pre;
    591       pre--;
    592         if ((*resource)->prio <= prio)
     662    while (index >= 0)
     663    {
     664      if (this->resourceList[index]->prio <= prio)
     665      {
     666        if (this->resourceList[index]->count == 0)
     667          unload(this->resourceList[index], prio);
     668        else
    593669        {
    594           if ((*resource)->count == 0)
    595             unload((*resource), prio);
    596           else
    597           {
     670          if (round == 3)
    598671            PRINTF(2)("unable to unload %s because there are still %d references to it\n",
    599                      (*resource)->name, (*resource)->count);
    600             removeCount++;
    601           }
     672                      this->resourceList[index]->name, this->resourceList[index]->count);
     673          removeCount++;
    602674        }
    603      }
    604      if (removeCount == 0) break;
    605   }
    606 }
    607 
    608 
    609 /**
    610  * Searches for a Resource by some information
     675      }
     676      index--;
     677    }
     678    if (removeCount == 0) break;
     679  }
     680}
     681
     682
     683/**
     684 * @brief Searches for a Resource by some information
    611685 * @param fileName: The name to look for
    612686 * @param type the Type of resource to locate.
     687 * @param param0: an additional option to parse (see the constuctors for more help)
    613688 * @param param1: an additional option to parse (see the constuctors for more help)
    614689 * @param param2: an additional option to parse (see the constuctors for more help)
    615  * @param param3: an additional option to parse (see the constuctors for more help)
    616690 * @returns a Pointer to the Resource if found, NULL otherwise.
    617691*/
    618692Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type,
    619                                                 void* param1, void* param2, void* param3) const
    620 {
    621   std::list<Resource*>::const_iterator resource;
     693    const MultiType& param0, const MultiType& param1, const MultiType& param2) const
     694{
     695  std::vector<Resource*>::const_iterator resource;
    622696  for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)
    623697  {
    624698    if ((*resource)->type == type && !strcmp(fileName, (*resource)->name))
    625         {
    626           bool match = false;
    627 
    628           switch (type)
    629             {
     699    {
     700      bool match = false;
     701      switch (type)
     702      {
    630703#ifndef NO_MODEL
    631             case PRIM:
    632             case OBJ:
    633               if (!param1)
    634                 {
    635                   if ((*resource)->modelSize == 1.0)
    636                     match = true;
    637                 }
    638               else if ((*resource)->modelSize == *(float*)param1)
    639                 match = true;
    640               break;
    641             case MD2:
    642               if (!param1)
    643                 {
    644                   if ((*resource)->secFileName == NULL)
    645                     match = true;
    646                 }
    647               else if (!strcmp((*resource)->secFileName, (const char*)param1))
    648                 match = true;
    649               break;
     704        case PRIM:
     705        case OBJ:
     706          if (param0 == MT_NULL)
     707          {
     708            if ((*resource)->param[0] == 1.0f)
     709              match = true;
     710          }
     711          else if ((*resource)->param[0] == param0.getFloat())
     712            match = true;
     713          break;
     714        case MD2:
     715          if (param0 == MT_NULL)
     716          {
     717            if ((*resource)->param[0] == "")
     718              match = true;
     719          }
     720          else if ((*resource)->param[0] == ((MultiType)param0).getString())
     721            match = true;
     722          break;
    650723#endif /* NO_MODEL */
    651724#ifndef NO_TEXT
    652             case TTF:
    653               if (param1 == NULL)
    654                 {
    655                   if ((*resource)->ttfSize == FONT_DEFAULT_RENDER_SIZE)
    656                     match = true;
    657                 }
    658               else if ((*resource)->ttfSize == *(unsigned int*)param1)
    659                 match = true;
    660               break;
     725        case TTF:
     726          if (param0 == MT_NULL)
     727          {
     728            if ((*resource)->param[0] == FONT_DEFAULT_RENDER_SIZE)
     729              match = true;
     730          }
     731          else if ((*resource)->param[0] == param0.getInt())
     732            match = true;
     733          break;
    661734#endif /* NO_TEXT */
    662735#ifndef NO_SHADERS
    663               case SHADER:
    664                 if (!param1)
    665                 {
    666                   if ((*resource)->secFileName == NULL)
    667                     match = true;
    668                 }
    669                 else if (!strcmp((*resource)->secFileName, (const char*)param1))
    670                   match = true;
     736        case SHADER:
     737          if (param0 == MT_NULL)
     738          {
     739            if ((*resource)->param[0] == "")
     740              match = true;
     741          }
     742          else if ((*resource)->param[0] == ((MultiType)param0).getString())
     743            match = true;
    671744#endif /* NO_SHADERS */
    672745#ifndef NO_TEXTURES
    673               case IMAGE:
    674                 if (!param1)
    675                 {
    676                   if ((*resource)->texTarget == GL_TEXTURE_2D)
    677                     match = true;
    678                 }
    679                 else if ((*resource)->texTarget ==  *(GLenum*)param1)
    680                   match = true;
     746        case IMAGE:
     747          if (param0 == MT_NULL)
     748          {
     749            if ((*resource)->param[0] == GL_TEXTURE_2D)
     750              match = true;
     751          }
     752          else if ((*resource)->param[0] ==  param0.getInt())
     753            match = true;
    681754#endif /* NO_TEXTURES */
    682             default:
    683               match = true;
    684               break;
    685             }
    686           if (match)
    687             {
    688               return (*resource);
    689             }
    690         }
    691     }
     755        default:
     756          match = true;
     757          break;
     758      }
     759      if (match)
     760      {
     761        return (*resource);
     762      }
     763    }
     764  }
    692765  return NULL;
    693766}
    694767
    695768/**
    696  * Searches for a Resource by Pointer
     769 * @brief Searches for a Resource by Pointer
    697770 * @param pointer the Pointer to search for
    698771 * @returns a Pointer to the Resource if found, NULL otherwise.
    699 */
     772 */
    700773Resource* ResourceManager::locateResourceByPointer(const void* pointer) const
    701774{
    702775  //  Resource* enumRes = resourceList->enumerate();
    703   std::list<Resource*>::const_iterator resource;
     776  std::vector<Resource*>::const_iterator resource;
    704777  for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)
    705778    if (pointer == (*resource)->pointer)
    706         return (*resource);
     779      return (*resource);
    707780  return NULL;
    708781}
    709782
    710 /**
    711  * Checks if it is a Directory
     783char* ResourceManager::toResourcableString(unsigned int i)
     784{
     785  int len = strlen(ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));
     786  len += strlen(this->resourceList[i]->name);
     787  if (this->resourceList[i]->param[0].getString()) len += strlen(this->resourceList[i]->param[0].getString()) +1;
     788  if (this->resourceList[i]->param[1].getString()) len += strlen(this->resourceList[i]->param[1].getString()) +1;
     789  if (this->resourceList[i]->param[2].getString()) len += strlen(this->resourceList[i]->param[2].getString()) +1;
     790  len += 10;
     791  char* tmp = new char[len];
     792  tmp[0] = '\0';
     793  strcat( tmp, ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));
     794  strcat(tmp,",");
     795  strcat (tmp, this->resourceList[i]->name);
     796  if (this->resourceList[i]->param[0].getString() && this->resourceList[i]->param[0].getString() != '\0')
     797  {
     798    strcat(tmp,",");
     799    strcat( tmp, this->resourceList[i]->param[0].getString());
     800  }
     801  if (this->resourceList[i]->param[1].getString() && this->resourceList[i]->param[1].getString() != '\0')
     802  {
     803    strcat(tmp,",");
     804    strcat( tmp, this->resourceList[i]->param[1].getString());
     805  }
     806  if (this->resourceList[i]->param[2].getString() && this->resourceList[i]->param[2].getString() != '\0')
     807  {
     808    strcat(tmp,",");
     809    strcat( tmp, this->resourceList[i]->param[2].getString());
     810  }
     811  return tmp;
     812}
     813
     814/**
     815 * @brief caches a Resource from a ResourceableString created with the toResourcableString-function
     816 * @param resourceableString the String to cache the resource from.
     817 */
     818bool ResourceManager::fromResourceableString(const char* resourceableString)
     819{
     820  SubString splits(resourceableString, ',');
     821  splits.debug();
     822  if (splits.getCount() == 2)
     823    this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),
     824                RP_LEVEL);
     825  else if (splits.getCount() == 3)
     826    return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),
     827                RP_LEVEL, splits[2]);
     828  else if (splits.getCount() == 4)
     829    return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),
     830                RP_LEVEL, splits[2], splits[3]);
     831  else if (splits.getCount() == 5)
     832    return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),
     833                RP_LEVEL, splits[2], splits[3], splits[4]);
     834}
     835
     836
     837/**
     838 * @brief Checks if it is a Directory
    712839 * @param directoryName the Directory to check for
    713840 * @returns true if it is a directory/symlink false otherwise
     
    724851  if (directoryName[strlen(directoryName)-1] == '/' ||
    725852      directoryName[strlen(directoryName)-1] == '\\')
    726     {
    727       tmpDirName = new char[strlen(directoryName)];
    728       strncpy(tmpDirName, directoryName, strlen(directoryName)-1);
    729       tmpDirName[strlen(directoryName)-1] = '\0';
    730     }
    731   else
    732     {
    733       tmpDirName = new char[strlen(directoryName)+1];
    734       strcpy(tmpDirName, directoryName);
    735     }
     853  {
     854    tmpDirName = new char[strlen(directoryName)];
     855    strncpy(tmpDirName, directoryName, strlen(directoryName)-1);
     856    tmpDirName[strlen(directoryName)-1] = '\0';
     857  }
     858  else
     859  {
     860    tmpDirName = new char[strlen(directoryName)+1];
     861    strcpy(tmpDirName, directoryName);
     862  }
    736863
    737864  if(!stat(tmpDirName, &status))
    738     {
    739       if (status.st_mode & (S_IFDIR
     865  {
     866    if (status.st_mode & (S_IFDIR
    740867#ifndef __WIN32__
    741                             | S_IFLNK
     868                          | S_IFLNK
    742869#endif
    743                             ))
    744         {
    745           delete[] tmpDirName;
    746           return true;
    747         }
    748       else
    749         {
    750           delete[] tmpDirName;
    751           return false;
    752         }
    753     }
     870                         ))
     871    {
     872      delete[] tmpDirName;
     873      return true;
     874    }
     875    else
     876    {
     877      delete[] tmpDirName;
     878      return false;
     879    }
     880  }
    754881  else
    755882  {
     
    760887
    761888/**
    762  * Checks if the file is either a Regular file or a Symlink
     889 * @brief Checks if the file is either a Regular file or a Symlink
    763890 * @param fileName the File to check for
    764891 * @returns true if it is a regular file/symlink, false otherwise
     
    772899  struct stat status;
    773900  if (!stat(tmpFileName, &status))
    774     {
    775       if (status.st_mode & (S_IFREG
     901  {
     902    if (status.st_mode & (S_IFREG
    776903#ifndef __WIN32__
    777                             | S_IFLNK
     904                          | S_IFLNK
    778905#endif
    779                             ))
    780         {
    781           delete[] tmpFileName;
    782           return true;
    783         }
    784       else
    785         {
    786           delete[] tmpFileName;
    787           return false;
    788         }
    789     }
    790   else
     906                         ))
     907    {
     908      delete[] tmpFileName;
     909      return true;
     910    }
     911    else
    791912    {
    792913      delete[] tmpFileName;
    793914      return false;
    794915    }
    795 }
    796 
    797 /**
    798  * touches a File on the disk (thereby creating it)
     916  }
     917  else
     918  {
     919    delete[] tmpFileName;
     920    return false;
     921  }
     922}
     923
     924/**
     925 * @brief touches a File on the disk (thereby creating it)
    799926 * @param fileName The file to touch
    800927*/
     
    806933  FILE* stream;
    807934  if( (stream = fopen (tmpName, "w")) == NULL)
    808     {
    809       PRINTF(1)("could not open %s fro writing\n", fileName);
    810       delete[] tmpName;
    811       return false;
    812     }
     935  {
     936    PRINTF(1)("could not open %s fro writing\n", fileName);
     937    delete[] tmpName;
     938    return false;
     939  }
    813940  fclose(stream);
    814941
     
    817944
    818945/**
    819  * deletes a File from disk
     946 * @brief deletes a File from disk
    820947 * @param fileName the File to delete
    821948*/
     
    840967  char* retName;
    841968  if (!strncmp(name, "~/", 2))
    842     {
    843       char tmpFileName[500];
     969  {
     970    char tmpFileName[500];
    844971#ifdef __WIN32__
    845       strcpy(tmpFileName, getenv("USERPROFILE"));
     972    strcpy(tmpFileName, getenv("USERPROFILE"));
    846973#else
    847       strcpy(tmpFileName, getenv("HOME"));
     974    strcpy(tmpFileName, getenv("HOME"));
    848975#endif
    849       retName = new char[strlen(tmpFileName)+strlen(name)];
    850       sprintf(retName, "%s%s", tmpFileName, name+1);
    851     }
    852   else
    853     {
    854       retName = new char[strlen(name)+1];
    855       strcpy(retName, name);
    856     }
     976    retName = new char[strlen(tmpFileName)+strlen(name)];
     977    sprintf(retName, "%s%s", tmpFileName, name+1);
     978  }
     979  else
     980  {
     981    retName = new char[strlen(name)+1];
     982    strcpy(retName, name);
     983  }
    857984  return retName;
    858985}
     
    8741001    return retName;
    8751002  else
    876     {
    877       delete[] retName;
    878       return NULL;
    879     }
    880 }
    881 
    882 
    883 /**
    884  * checks wether a file is in the DataDir.
     1003  {
     1004    delete[] retName;
     1005    return NULL;
     1006  }
     1007}
     1008
     1009
     1010/**
     1011 * @brief checks wether a file is in the DataDir.
    8851012 * @param fileName the File to check if it is in the Data-Dir structure.
    8861013 * @returns true if the file exists, false otherwise
     
    8931020  bool retVal = false;
    8941021  char* checkFile = new char[strlen(ResourceManager::getInstance()->getDataDir())
    895       + strlen(fileName) + 1];
     1022                             + strlen(fileName) + 1];
    8961023  sprintf(checkFile, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName);
    8971024
     
    9061033
    9071034/**
    908  * outputs debug information about the ResourceManager
    909 */
     1035 * @brief outputs debug information about the ResourceManager
     1036 */
    9101037void ResourceManager::debug() const
    9111038{
     
    9171044  PRINT(0)(" Data-Directory is: %s\n", this->dataDir);
    9181045  PRINT(0)(" List of Image-Directories: ");
    919   std::list<char*>::const_iterator imageDir;
     1046  std::vector<char*>::const_iterator imageDir;
    9201047  for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
    921       PRINT(0)("%s ", (*imageDir));
     1048    PRINT(0)("%s ", (*imageDir));
    9221049  PRINT(0)("\n");
    9231050
    9241051  PRINT(0)("List of all stored Resources:\n");
    925   std::list<Resource*>::const_iterator resource;
     1052  std::vector<Resource*>::const_iterator resource;
    9261053  for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)
    9271054
    928     {
    929       PRINT(0)("-----------------------------------------\n");
    930       PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name, (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type));
    931 
    932       PRINT(0)("gets deleted at ");
    933       switch((*resource)->prio)
    934         {
    935         default:
    936         case RP_NO:
    937           PRINT(0)("first posibility (0)\n");
    938           break;
    939         case RP_LEVEL:
    940           PRINT(0)("the end of the Level (1)\n");
    941           break;
    942         case RP_CAMPAIGN:
    943           PRINT(0)("the end of the campaign (2)\n");
    944           break;
    945         case RP_GAME:
    946           PRINT(0)("when leaving the game (3)\n");
    947           break;
    948         }
    949     }
     1055  {
     1056    PRINT(0)("-----------------------------------------\n");
     1057    PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name, (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type));
     1058
     1059    PRINT(0)("gets deleted at ");
     1060    switch((*resource)->prio)
     1061    {
     1062      default:
     1063      case RP_NO:
     1064        PRINT(0)("first posibility (0)\n");
     1065        break;
     1066      case RP_LEVEL:
     1067        PRINT(0)("the end of the Level (1)\n");
     1068        break;
     1069      case RP_CAMPAIGN:
     1070        PRINT(0)("the end of the campaign (2)\n");
     1071        break;
     1072      case RP_GAME:
     1073        PRINT(0)("when leaving the game (3)\n");
     1074        break;
     1075    }
     1076  }
    9501077
    9511078
     
    9561083
    9571084/**
    958  * converts a ResourceType into the corresponding String
     1085 * @brief converts a ResourceType into the corresponding String
    9591086 * @param type the ResourceType to translate
    9601087 * @returns the converted String.
     
    9621089const char* ResourceManager::ResourceTypeToChar(ResourceType type)
    9631090{
    964   switch (type)
     1091  return ResourceManager::resourceNames[type];
     1092}
     1093
     1094/**
     1095 * @brief converts a String into a ResourceType (good for loading)
     1096 * @param resourceType the name of the Type
     1097 * @returns the Number of the Type, or 0 (defautl) if not found.
     1098 */
     1099ResourceType ResourceManager::stringToResourceType(const char* resourceType)
     1100{
     1101  assert(resourceType != NULL);
     1102  for (unsigned int i = 0; i < RESOURCE_TYPE_SIZE; i++)
     1103    if (!strcmp(resourceType, ResourceManager::resourceNames[i]))
     1104      return (ResourceType)i;
     1105  return (ResourceType)0;
     1106}
     1107
     1108/**
     1109 * The Names of the ResourceTypes
     1110 */
     1111const char* ResourceManager::resourceNames[] =
    9651112  {
    9661113#ifndef NO_MODEL
    967     case OBJ:
    968       return "ObjectModel";
    969       break;
    970     case PRIM:
    971       return "PrimitiveModel";
    972       break;
    973     case MD2:
    974       return "MD2-Data";
    975       break;
     1114    "ObjectModel",
     1115    "PrimitiveModel",
     1116    "MD2-Data",
     1117#endif
     1118#ifndef NO_TEXT
     1119    "Font",
     1120#endif
     1121#ifndef NO_AUDIO
     1122    "Wav",
     1123    "mp3",
     1124    "ogg",
    9761125#endif
    9771126#ifndef NO_TEXTURES
    978     case IMAGE:
    979       return "ImageFile (Texture)";
    980       break;
    981 #endif
    982 #ifndef NO_AUDIO
    983     case WAV:
    984       return "SoundFile";
    985       break;
    986     case OGG:
    987       return "MusicFile";
    988       break;
    989 #endif
    990 #ifndef NO_TEXT
    991     case TTF:
    992       return "Font (TTF)";
    993       break;
     1127    "Texture",
    9941128#endif
    9951129#ifndef NO_SHADERS
    996     case SHADER:
    997       return "Shader";
    998       break;
     1130    "Shader",
    9991131#endif
    1000     default:
    1001       return "unknown Format";
    1002       break;
    1003   }
    1004 }
     1132
     1133  };
  • branches/network/src/util/loading/resource_manager.h

    r6633 r6693  
    1414    (NO_TEXT)
    1515    (NO_TEXTURES)
     16    (NO_SHADERS)
    1617*/
    1718
     
    2021
    2122#include "base_object.h"
     23#include "multi_type.h"
    2224
    23 
    24 #include <list>
     25#include <vector>
    2526
    2627//! An eumerator for different fileTypes the resourceManager supports
     
    4647  SHADER,               //!< openGL-shader program
    4748#endif /* NO_SHADERS */
     49  RESOURCE_TYPE_SIZE
    4850};
    4951
     
    7375  ResourcePriority  prio;              //!< The Priority of this resource. (This will only be increased)
    7476
    75   // more specific
    76   union {
    77 #ifndef NO_MODEL
    78   float             modelSize;         //!< the size of the model (OBJ/PRIM)
    79   char*             secFileName;       //!< a seconf fileName
    80 #endif /* NO_MODEL */
    81 #ifndef NO_TEXT
    82   unsigned int      ttfSize;           //!< the size of the ttf-font (TTF)
    83 #endif /* NO_TEXT */
    84 #ifndef NO_TEXTURES
    85   GLenum            texTarget;
    86 #endif /* NO_TEXTURES */
    87   };
     77  MultiType         param[3];          //!< The Parameters given to this Resource.
    8878};
    8979
     
    114104  bool verifyDataDir(const char* fileInside);
    115105  bool addImageDir(const char* imageDir);
     106
     107  bool cache(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO,
     108             const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
     109  BaseObject* copy(BaseObject* resourcePointer);
     110
    116111  BaseObject* load(const char* fileName, ResourcePriority prio = RP_NO,
    117                void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
     112                   const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
    118113  BaseObject* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO,
    119                void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
    120   bool unload(void* pointer, ResourcePriority prio = RP_NO);
     114                   const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
     115  bool unload(BaseObject* pointer, ResourcePriority prio = RP_NO);
    121116  bool unload(Resource* resource, ResourcePriority = RP_NO);
    122117  bool unloadAllByPriority(ResourcePriority prio);
    123118
    124   Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3) const;
     119  Resource* locateResourceByInfo(const char* fileName, ResourceType type,
     120                                 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()) const;
    125121  Resource* locateResourceByPointer(const void* pointer) const;
     122
     123  char* toResourcableString(unsigned int i);
     124  bool fromResourceableString(const char* resourceableString);
     125  /** @returns the Count of Resources the ResourceManager handles */
     126  unsigned int resourceCount() const { return this->resourceList.size(); }
    126127
    127128  void debug() const;
     
    138139
    139140  static const char* ResourceTypeToChar(ResourceType type);
    140 
     141  static ResourceType stringToResourceType(const char* resourceType);
    141142
    142143 private:
    143144  ResourceManager();
     145  Resource* loadResource(const char* fileName, ResourceType type, ResourcePriority prio,
     146                         const MultiType& param0, const MultiType& param1, const MultiType& param2);
    144147
    145148 private:
     
    147150
    148151  char*                    dataDir;            //!< The Data Directory, where all relevant Data is stored.
    149   std::list<Resource*>     resourceList;       //!< The List of Resources, that has already been loaded.
    150   std::list<char*>         imageDirs;          //!< A list of directories in which images are stored.
     152  std::vector<char*>       imageDirs;          //!< A list of directories in which images are stored.
    151153
     154  std::vector<Resource*>   resourceList;       //!< The List of Resources, that has already been loaded.
     155
     156  static const char*       resourceNames[RESOURCE_TYPE_SIZE];
    152157};
    153158
  • branches/network/src/world_entities/Makefile.am

    r6634 r6693  
    2727                  \
    2828                  world_entities/weapons/weapon_manager.cc \
     29                  world_entities/weapons/ammo_container.cc \
    2930                  world_entities/weapons/weapon.cc \
    3031                  world_entities/weapons/test_gun.cc \
     
    5152                  world_entities/space_ships/space_ship.cc \
    5253                  world_entities/space_ships/helicopter.cc \
     54                  world_entities/space_ships/hover.cc \
    5355                  world_entities/creatures/md2_creature.cc \
    5456                  \
     
    7880                 \
    7981                 world_entities/weapons/weapon_manager.h \
     82                 world_entities/weapons/ammo_container.h \
    8083                 world_entities/weapons/weapon.h \
    8184                 world_entities/weapons/test_gun.h \
     
    102105                 world_entities/space_ships/space_ship.h \
    103106                 world_entities/space_ships/helicopter.h \
     107                 world_entities/space_ships/hover.h \
    104108                 world_entities/creatures/md2_creature.h \
    105109                 \
  • branches/network/src/world_entities/environments/water.cc

    r6686 r6693  
    5454  this->rebuildGrid();
    5555  this->waterMaterial = new Material();
    56   this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, (void*)"shaders/water.frag");
     56  this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, "shaders/water.frag");
    5757
    5858  this->grid->height(this->grid->columns()/2,this->grid->rows()/2) = 100;
     
    7070
    7171  LoadParam(root, "size", this, Water, setSize)
    72       .describe("the size of the WaterSurface")
    73       .defaultValues(2, 1.0f, 1.0f);
     72  .describe("the size of the WaterSurface")
     73  .defaultValues(2, 1.0f, 1.0f);
    7474
    7575  LoadParam(root, "resolution", this, Water, setResolution)
    76       .describe("sets the resolution of the water surface")
    77       .defaultValues(2, 10, 10);
     76  .describe("sets the resolution of the water surface")
     77  .defaultValues(2, 10, 10);
    7878
    7979  LoadParam(root, "height", this, Water, setHeight)
    80       .describe("the height of the Waves")
    81       .defaultValues(1, 0.5f);
     80  .describe("the height of the Waves")
     81  .defaultValues(1, 0.5f);
    8282}
    8383
     
    9292  }
    9393
    94 //   WE DO NOT NEED THIS AS IT IS DONE IN WORLDENTITY->setModel();
    95 //   if (this->grid != NULL)
    96 //     this->grid = NULL;
     94  //   WE DO NOT NEED THIS AS IT IS DONE IN WORLDENTITY->setModel();
     95  //   if (this->grid != NULL)
     96  //     this->grid = NULL;
    9797
    9898  this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY);
     
    127127void Water::draw() const
    128128{
    129   //SkyBox::enableCubeMap();
    130 
    131   glBindTexture(GL_TEXTURE_2D, 15);
    132   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    133 
    134   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    135   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    136   glEnable(GL_TEXTURE_GEN_S);
    137   glEnable(GL_TEXTURE_GEN_T);
    138 
    139   glEnable(GL_BLEND);
    140   glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    141   // this->waterShader->activateShader();
    142 //  this->waterMaterial->select();
    143   WorldEntity::draw();
    144   //Shader::deactivateShader();
    145 
    146   SkyBox::disableCubeMap();
     129  if (this->grid != NULL)
     130  {
     131    //SkyBox::enableCubeMap();
     132    WorldEntity::draw();
     133    glBindTexture(GL_TEXTURE_2D, 15);
     134    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
     135
     136    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
     137    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
     138    glEnable(GL_TEXTURE_GEN_S);
     139    glEnable(GL_TEXTURE_GEN_T);
     140
     141    glEnable(GL_BLEND);
     142    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     143    // this->waterShader->activateShader();
     144    //  this->waterMaterial->select();
     145    //Shader::deactivateShader();
     146
     147    SkyBox::disableCubeMap();
     148  }
    147149}
    148150
    149151void Water::tick(float dt)
    150152{
    151 /*
    152     THE OLD USELESS ALGORITHM
    153   phase += dt *.1;
    154   for (unsigned int i = 0; i < this->grid->rows(); i++)
    155   {
    156     for (unsigned int j = 0; j < this->grid->columns(); j++)
     153  if (unlikely(this->velocities == NULL))
     154    return;
     155  /*
     156      THE OLD USELESS ALGORITHM
     157    phase += dt *.1;
     158    for (unsigned int i = 0; i < this->grid->rows(); i++)
    157159    {
    158       this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+
    159           this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0);
     160      for (unsigned int j = 0; j < this->grid->columns(); j++)
     161      {
     162        this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+
     163            this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0);
     164      }
    160165    }
    161   }
    162   this->grid->rebuildNormals(this->height);*/
     166    this->grid->rebuildNormals(this->height);*/
    163167
    164168
     
    168172  // wave/advection
    169173  // calc movement
    170   for(j = 1; j < this->grid->rows() - 1; j++) {
    171     for(i = 1; i < this->grid->columns() - 1; i++) {
     174  for(j = 1; j < this->grid->rows() - 1; j++)
     175  {
     176    for(i = 1; i < this->grid->columns() - 1; i++)
     177    {
    172178      u =  this->grid->height(i+1,j)+ this->grid->height(i-1, j) +
    173           this->grid->height(i, j+1) + this->grid->height(i, j-1) -
    174           4 * this->grid->height(i, j);
     179           this->grid->height(i, j+1) + this->grid->height(i, j-1) -
     180           4 * this->grid->height(i, j);
    175181      this->velocities[i][j] += dt * this->viscosity * this->viscosity * u / this->height;
    176182      this->grid->height(i, j) += dt * this->velocities[i][j];
    177183    }
    178184  }
    179 /*  // advect
    180   for(j = 1; j < this->grid->rows() - 1; j++) {
    181     for(i = 1; i < this->grid->columns() - 1; i++) {
    182       this->grid->height(i, j) += dt * this->velocities[i][j];
    183     }
    184   }*/
     185  // boundraries
     186  for (j = 0; j < this->grid->rows(); j++)
     187  {
     188    this->grid->height(0,j) = this->grid->height(1,j);
     189    this->grid->height(this->grid->rows()-1,j) = this->grid->height(this->grid->rows()-2, j);
     190  }
     191  for (i = 0; i < this->grid->rows(); i++)
     192  {
     193    this->grid->height(i,0) = this->grid->height(i,1);
     194    this->grid->height(i,this->grid->columns()-1) = this->grid->height(i, this->grid->columns()-2);
     195  }
     196  /*  // advect
     197    for(j = 1; j < this->grid->rows() - 1; j++) {
     198      for(i = 1; i < this->grid->columns() - 1; i++) {
     199        this->grid->height(i, j) += dt * this->velocities[i][j];
     200      }
     201    }*/
    185202  // bound
    186 //   unsigned int w = this->grid->columns - 1;
    187 //   for(i = 0; i < this->grid->columns; i++) {
    188 //     _map[i][0].u[1] = _map[i][1  ].u[1];
    189 //     _map[i][w].u[1] = _map[i][w-1].u[1];
    190 //     _map[0][i].u[1] = _map[1  ][i].u[1];
    191 //     _map[w][i].u[1] = _map[w-1][i].u[1];
    192 //   }
     203  //   unsigned int w = this->grid->columns - 1;
     204  //   for(i = 0; i < this->grid->columns; i++) {
     205  //     _map[i][0].u[1] = _map[i][1  ].u[1];
     206  //     _map[i][w].u[1] = _map[i][w-1].u[1];
     207  //     _map[0][i].u[1] = _map[1  ][i].u[1];
     208  //     _map[w][i].u[1] = _map[w-1][i].u[1];
     209  //   }
    193210
    194211  // diffusion
    195   for(j = 1; j < this->grid->rows() - 1; j++) {
    196     for(i = 1; i < this->grid->columns() - 1 ; i++) {
     212  for(j = 1; j < this->grid->rows() - 1; j++)
     213  {
     214    for(i = 1; i < this->grid->columns() - 1 ; i++)
     215    {
    197216      u = this->grid->height(i+1, j) + this->grid->height(i-1, j) +
    198217          this->grid->height(i, j+1) + this->grid->height(i, j-1) -
     
    203222
    204223  // calc normals
    205 //   float l[3];
    206 //   float m[3];
    207 //   for(j = 1; j < this->grid->rows() -1; j++) {
    208 //     for(i = 1; i < this->grid->columns() - 1; i++) {
    209 //       l[0] = this->grid->vertexG(i, j-1).x - this->grid->vertexG(i, j+1).x;
    210 //       l[1] = this->grid->vertexG(i, j-1).y - this->grid->vertexG(i, j+1).y;
    211 //       l[2] = this->grid->vertexG(i, j-1).z - this->grid->vertexG(i, j+1).z;
    212 //       m[0] = this->grid->vertexG(i-1,j).x - this->grid->vertexG(i+1, j).x;
    213 //       m[1] = this->grid->vertexG(i-1,j).y - this->grid->vertexG(i+1, j).y;
    214 //       m[2] = this->grid->vertexG(i-1,j).z - this->grid->vertexG(i+1, j).z;
    215 //       this->grid->normalG(i, j).x = l[1] * m[2] - l[2] * m[1];
    216 //       this->grid->normalG(i, j).y = l[2] * m[0] - l[0] * m[2];
    217 //       this->grid->normalG(i, j).z = l[0] * m[1] - l[1] * m[0];
    218 //     }
    219 //   }
     224  //   float l[3];
     225  //   float m[3];
     226  //   for(j = 1; j < this->grid->rows() -1; j++) {
     227  //     for(i = 1; i < this->grid->columns() - 1; i++) {
     228  //       l[0] = this->grid->vertexG(i, j-1).x - this->grid->vertexG(i, j+1).x;
     229  //       l[1] = this->grid->vertexG(i, j-1).y - this->grid->vertexG(i, j+1).y;
     230  //       l[2] = this->grid->vertexG(i, j-1).z - this->grid->vertexG(i, j+1).z;
     231  //       m[0] = this->grid->vertexG(i-1,j).x - this->grid->vertexG(i+1, j).x;
     232  //       m[1] = this->grid->vertexG(i-1,j).y - this->grid->vertexG(i+1, j).y;
     233  //       m[2] = this->grid->vertexG(i-1,j).z - this->grid->vertexG(i+1, j).z;
     234  //       this->grid->normalG(i, j).x = l[1] * m[2] - l[2] * m[1];
     235  //       this->grid->normalG(i, j).y = l[2] * m[0] - l[0] * m[2];
     236  //       this->grid->normalG(i, j).z = l[0] * m[1] - l[1] * m[0];
     237  //     }
     238  //   }
    220239  this->grid->rebuildNormals(this->height);
    221240}
  • branches/network/src/world_entities/movie_entity.cc

    r6678 r6693  
    1919#include "load_param.h"
    2020#include "factory.h"
    21 
    22 #include "network_game_manager.h"
    23 #include "converter.h"
    2421
    2522using namespace std;
  • branches/network/src/world_entities/projectiles/guided_missile.cc

    r6627 r6693  
    4343  this->setMaxEnergy(10);
    4444  this->lifeSpan = 10.0;
    45   this->agility = 500;
     45  this->agility = 5;
    4646  this->maxVelocity = 75;
    4747
  • branches/network/src/world_entities/projectiles/laser.cc

    r6654 r6693  
    1717
    1818#include "laser.h"
     19#include <assert.h>
     20
    1921
    2022#include "fast_factory.h"
     
    2628#include "particle_emitter.h"
    2729#include "sprite_particles.h"
     30#include <cassert>
    2831
    2932#include "assert.h"
  • branches/network/src/world_entities/space_ships/helicopter.cc

    r6512 r6693  
    117117  bFire = false;
    118118  xMouse = yMouse = 0;
    119   mouseSensitivity = 0.001;
    120   rotorspeed = 1;
    121   tailrotorspeed = 0;
    122 
    123   cycle = 0.0;
    124 
    125 
    126   travelSpeed = 15.0;
     119  mouseSensitivity = 0.05;
     120  //rotorspeed = 1;
     121  //tailrotorspeed = 0;
     122
     123  //cycle = 0.0;
     124
     125
     126  //travelSpeed = 15.0;
    127127  this->velocity = Vector(0.0,0.0,0.0);
    128128  this->velocityDir = Vector(1.0,0.0,0.0);
     
    134134
    135135  //add events to the eventlist
    136   registerEvent(SDLK_w);
    137   registerEvent(SDLK_s);
    138   registerEvent(SDLK_a);
    139   registerEvent(SDLK_d);
    140   registerEvent(SDLK_q);
     136  registerEvent(KeyMapper::PEV_UP);
     137  registerEvent(KeyMapper::PEV_DOWN);
     138  registerEvent(KeyMapper::PEV_LEFT);
     139  registerEvent(KeyMapper::PEV_RIGHT);
     140  //registerEvent(SDLK_q);
    141141  registerEvent(SDLK_e);
    142142  registerEvent(SDLK_c);
     
    144144  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
    145145  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
    146   registerEvent(SDLK_PAGEUP);
    147   registerEvent(SDLK_PAGEDOWN);
     146  //registerEvent(SDLK_PAGEUP);
     147  //registerEvent(SDLK_PAGEDOWN);
    148148  registerEvent(EV_MOUSE_MOTION);
    149149
     
    249249void Helicopter::tick (float time)
    250250{
     251  /*
    251252  tailrotorspeed += xMouse/20;
    252253  if (tailrotorspeed >= 0.07) tailrotorspeed = 0.07;
     
    256257  else if (tailrotorspeed < -0.0008) tailrotorspeed += 0.001;
    257258  if (tailrotorspeed <= 0.001 && tailrotorspeed >= -0.001) tailrotorspeed = 0;
    258 
     259  */
     260 
    259261  // spaceship controlled movement
    260262  this->calculateVelocity(time);
    261263
    262   Vector move = (velocity);
     264  Vector move = (velocity)*time;
    263265
    264266  // this is the air friction (necessary for a smooth control)
    265267  if(velocity.len() != 0) velocity -= velocity*0.1;
     268 
     269  //travelSpeed = velocity.len();
    266270
    267271  //physics: Gravity
    268   this->shiftCoor(Vector(0,-1,0));
     272  /*this->shiftCoor(Vector(0,-1,0));
    269273
    270274  this->shiftCoor(getAbsDirY()*rotorspeed);
    271 
     275  */
     276 
     277  /*
    272278  //hoover effect
    273279  cycle += time;
    274280  this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02);
     281  */
    275282
    276283  //readjust
     
    281288
    282289  this->shiftCoor (move);
    283   this->shiftDir(Quaternion(-M_PI/4*tailrotorspeed, Vector(0,1,0)));
     290  //this->shiftDir(Quaternion(-M_PI/4*tailrotorspeed, Vector(0,1,0)));
    284291
    285292  this->getWeaponManager()->tick(time);
     
    295302{
    296303  Vector accel(0.0, 0.0, 0.0);
    297   Vector rot(0.0, 0.0, 0.0);
    298   float rotVal = 0.0;
     304  float rotValX = 0.0;
     305  float rotValZ = 0.0;
    299306  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
    300307  /* calculate the direction in which the craft is heading  */
     
    304311     //this->shiftCoor(this->getAbsDirX());
    305312     //accel -= this->getAbsDirY();
    306      rot += Vector (0,0,1);
    307      rotVal -= time/5;
     313     
     314     accel += Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z);
     315     if((this->getAbsDirX()).y >= -0.1) rotValZ -= time;
    308316   }
    309317   else
    310318   {
    311        if(this->getAbsDirX().y < -.02) this->shiftDir(Quaternion(time/8, Vector(0,0,1)));
     319       if(this->getAbsDirX().y < -.02) this->shiftDir(Quaternion(time, Vector(0,0,1)));
    312320   }
    313321
     
    316324     //this->shiftCoor((this->getAbsDirX())*-1);
    317325     //accel -= this->getAbsDirY();
    318      rot += Vector (0,0,1);
    319      rotVal += time/5;
     326     
     327     accel -= Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z);
     328     rotValZ += time;
    320329   }
    321330   else
    322331   {
    323          if(this->getAbsDirX().y > 0.02) this->shiftDir(Quaternion(-time/8, Vector(0,0,1)));
     332         if(this->getAbsDirX().y > 0.02) this->shiftDir(Quaternion(-time, Vector(0,0,1)));
    324333   }
    325334
     
    329338    //accel -= this->getAbsDirY();
    330339    //velocityDir.normalize();
    331     rot += Vector(1,0,0);
    332     rotVal -= time/5;
     340   
     341    accel -= Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z);
     342    rotValX -= time;
    333343  }
    334344  else
    335345   {
    336          if(this->getAbsDirZ().y > 0.02) this->shiftDir(Quaternion(time/5, Vector(1,0,0)));
     346         if(this->getAbsDirZ().y > 0.02) this->shiftDir(Quaternion(time, Vector(1,0,0)));
    337347   }
    338348
     
    340350  {
    341351    //this->shiftDir(Quaternion(-time, Vector(0,1,0)));
    342     accel += this->getAbsDirY();
     352    //accel += this->getAbsDirY();
    343353    //velocityDir.normalize();
    344     rot += Vector(1,0,0);
    345     rotVal += time/5;
     354   
     355    accel += Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z);
     356    rotValX += time;
    346357  }
    347358  else
    348359   {
    349          if(this->getAbsDirZ().y < -0.02) this->shiftDir(Quaternion(-time/5, Vector(1,0,0)));
     360         if(this->getAbsDirZ().y < -0.02) this->shiftDir(Quaternion(-time, Vector(1,0,0)));
    350361   }
    351362
     
    371382    //this->shiftDir(Quaternion(time, Vector(0,0,1)));
    372383
    373     rotorspeed += 0.05;
    374     if (rotorspeed >= 2) rotorspeed = 2;
     384    accel += this->getAbsDirY();
     385    //rotorspeed += 0.05;
     386    //if (rotorspeed >= 2) rotorspeed = 2;
    375387    //velocityDir.normalize();
    376388    //rot += Vector(0,0,1);
     
    379391  else
    380392  {
    381     if(rotorspeed >= 1.05) rotorspeed -= 0.05;
     393    //if(rotorspeed >= 1.05) rotorspeed -= 0.05;
    382394  }
    383395
     
    386398    //this->shiftDir(Quaternion(-time, Vector(0,0,1)));
    387399
    388     rotorspeed -= 0.05;
    389     if (rotorspeed <= 0) rotorspeed = 0;
     400    accel -= this->getAbsDirY();
     401    //rotorspeed -= 0.05;
     402    //if (rotorspeed <= 0) rotorspeed = 0;
    390403    //velocityDir.normalize();
    391404    //rot += Vector(0,0,1);
     
    394407  else
    395408  {
    396     if(rotorspeed <= 0.05) rotorspeed += 0.05;
    397   }
    398 
    399   //velocity += accel;
    400   rot.normalize();
    401   this->shiftDir(Quaternion(rotVal, rot));
     409    //if(rotorspeed <= 0.05) rotorspeed += 0.05;
     410  }
     411
     412  velocity += accel*3;
     413  if((this->getAbsDirX()).y <= 0.3 && (this->getAbsDirX()).y >= -0.3) this->shiftDir(Quaternion(rotValZ, Vector(0,0,1)));
     414  if((this->getAbsDirZ()).y <= 0.3 && (this->getAbsDirZ()).y >= -0.3) this->shiftDir(Quaternion(rotValX, Vector(1,0,0)));
    402415}
    403416
     
    429442
    430443
    431   if( event.type == SDLK_a)
     444  if( event.type == KeyMapper::PEV_LEFT)
    432445      this->bLeft = event.bPressed;
    433   else if( event.type == SDLK_d)
     446  else if( event.type == KeyMapper::PEV_RIGHT)
    434447      this->bRight = event.bPressed;
    435448  else if( event.type == KeyMapper::PEV_FIRE1)
     
    443456  else if( event.type == SDLK_c)
    444457    this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0);
    445   else if( event.type == SDLK_w)
     458  else if( event.type == KeyMapper::PEV_UP)
    446459    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
    447   else if( event.type == SDLK_s)
     460  else if( event.type == KeyMapper::PEV_DOWN)
    448461    this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
    449462  else if( event.type == EV_MOUSE_MOTION)
     
    452465    this->yMouse = event.yRel*mouseSensitivity;
    453466
    454     //this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1)));
     467    this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))/*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1))*/);
    455468  }
    456469}
  • branches/network/src/world_entities/space_ships/helicopter.h

    r6512 r6693  
    5757    float                 xMouse;             //!< mouse moved in x-Direction
    5858    float                 yMouse;             //!< mouse moved in y-Direction
     59    int                   yInvert;
    5960    float                 mouseSensitivity;   //!< the mouse sensitivity
    60     float                 cycle;              //!< hovercycle
     61    //float                 cycle;              //!< hovercycle
    6162
    6263    Vector                velocity;           //!< the velocity of the player.
     
    6465    float                 travelSpeed;        //!< the current speed of the player (to make soft movement)
    6566    float                 acceleration;       //!< the acceleration of the player.
    66     float                 rotorspeed;         //!< the speed of the rotor.
    67     float                 tailrotorspeed;     //!< the relativ speed ot the tail rotor
     67    //float                 rotorspeed;         //!< the speed of the rotor.
     68    //float                 tailrotorspeed;     //!< the relativ speed ot the tail rotor
    6869
    6970    float                 airViscosity;
  • branches/network/src/world_entities/space_ships/space_ship.cc

    r6688 r6693  
    128128  this->addWeapon(cannon, 0, 6);
    129129
    130   //this->addWeapon(turret, 3, 0);
    131 
    132130  this->getWeaponManager()->changeWeaponConfig(1);
    133131
     
    137135  bFire = false;
    138136  xMouse = yMouse = 0;
     137  yInvert = 1;
    139138  mouseSensitivity = 0.001;
    140   airViscosity = 1.0;
    141   cycle = 0.0;
     139  airViscosity = 0.05;
     140  controlVelocityX = 25;
     141  controlVelocityY = 150;
     142  shipInertia = 0.5             ;
     143//  cycle = 0.0;
    142144
    143145  this->setMaxEnergy(100);
    144146  this->setEnergy(80);
    145147
    146   travelSpeed = 15.0;
    147   this->velocity = Vector(0.0,0.0,0.0);
     148  travelSpeed = 40.0;
     149  acceleration = 3;
     150  this->velocity = this->getAbsDirX()*travelSpeed;
    148151  this->mouseDir = this->getAbsDir();
     152  this->pitchDir = this->getAbsDir();
    149153
    150154//   GLGuiButton* button = new GLGuiPushButton();
     
    160164
    161165  //add events to the eventlist
    162   registerEvent(SDLK_w);
    163   registerEvent(SDLK_s);
    164   registerEvent(SDLK_a);
    165   registerEvent(SDLK_d);
    166   registerEvent(SDLK_q);
    167   registerEvent(SDLK_e);
     166  registerEvent(KeyMapper::PEV_UP);
     167  registerEvent(KeyMapper::PEV_DOWN);
     168  registerEvent(KeyMapper::PEV_LEFT);
     169  registerEvent(KeyMapper::PEV_RIGHT);
     170  //registerEvent(SDLK_q);
     171  //registerEvent(SDLK_e);
    168172  registerEvent(KeyMapper::PEV_FIRE1);
    169173  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
    170174  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
    171   registerEvent(SDLK_PAGEUP);
    172   registerEvent(SDLK_PAGEDOWN);
     175  //registerEvent(SDLK_PAGEUP);
     176  //registerEvent(SDLK_PAGEDOWN);
    173177  registerEvent(EV_MOUSE_MOTION);
    174178
     
    285289  this->weaponAction();
    286290
     291  if( xMouse != 0 || yMouse != 0)
     292   {
     293    if (xMouse > controlVelocityX) xMouse = controlVelocityX;
     294    else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX;
     295    if (yMouse > controlVelocityY) yMouse = controlVelocityY;
     296    else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY;
     297
     298    pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0)));
     299
     300    mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir);
     301    xMouse = yMouse = 0;
     302   }
     303
     304
    287305//   if( this != State::getPlayer()->getControllable())
    288306//     return;
     
    291309  this->calculateVelocity(time);
    292310
    293   Vector move = (velocity)*time;
     311  Vector move = velocity*time;
    294312
    295313  //orient the velocity in the direction of the spaceship.
     
    299317
    300318  //orient the spaceship in direction of the mouse
    301    rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)*3.0);
     319   rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)*shipInertia);
    302320   if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
    303321    this->setAbsDir( rotQuat);
     
    305323
    306324  // this is the air friction (necessary for a smooth control)
    307   if(velocity.len() != 0) velocity -= velocity*0.01;
     325  if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001;
     326  else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001;
     327
     328  //other physics (gravity)
     329  //if(travelSpeed < 120)
     330  //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time;
    308331
    309332  //hoover effect
     
    312335
    313336  //readjust
    314 
    315   /*
    316     In the game "Yager" the spaceship gets readjusted when the player moves the mouse.
    317     I (bknecht) go and check it out how they do it, we could probably use this also in Orxonox.
    318   */
    319   //if (xMouse != 0 && yMouse != 0)
    320 
    321337  //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0)));
    322338  //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0)));
     
    324340  //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
    325341
    326   this->shiftCoor (move);
     342  this->shiftCoor(move);
    327343
    328344
     
    343359  /* calculate the direction in which the craft is heading  */
    344360
    345   Plane plane(Vector(0,1,0), Vector(0,0,0));
     361  //Plane plane(Vector(0,1,0), Vector(0,0,0));
    346362
    347363  if( this->bUp )
    348364   {
    349365     //this->shiftCoor(this->getAbsDirX());
    350       accel += (this->getAbsDirX())*2;
    351 
    352       /* Heli-Steuerung
    353          accel += (this->getAbsDirX()*2;
    354          if(
    355       */
     366      //accel += (this->getAbsDirX())*2;
     367      accel += (this->getAbsDirX())*acceleration;
     368
    356369   }
    357370
     
    359372   {
    360373     //this->shiftCoor((this->getAbsDirX())*-1);
    361      accel -= (this->getAbsDirX())*2;
     374     //accel -= (this->getAbsDirX())*2;
     375     accel -= (this->getAbsDirX())*0.5*acceleration;
    362376   }
    363377
     
    383397  if( this->bRollL /* > -this->getRelCoor().z*2*/)
    384398  {
    385     mouseDir *= Quaternion(-time, Vector(1,0,0));
     399    mouseDir *= Quaternion(-time*2, Vector(1,0,0));
    386400//    accel -= rightDirection;
    387401    //velocityDir.normalize();
     
    391405  if( this->bRollR /* > this->getRelCoor().z*2*/)
    392406  {
    393     mouseDir *= Quaternion(time, Vector(1,0,0));
     407    mouseDir *= Quaternion(time*2, Vector(1,0,0));
    394408
    395409    //    accel += rightDirection;
     
    438452void SpaceShip::process(const Event &event)
    439453{
    440 
    441 
    442   if( event.type == SDLK_a)
     454  if( event.type == KeyMapper::PEV_LEFT)
    443455      this->bRollL = event.bPressed;
    444   else if( event.type == SDLK_d)
     456  else if( event.type == KeyMapper::PEV_RIGHT)
    445457      this->bRollR = event.bPressed;
    446458  else if( event.type == KeyMapper::PEV_FIRE1)
     
    452464  else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
    453465    this->previousWeaponConfig();
    454   else if( event.type == SDLK_w)
     466  else if( event.type == KeyMapper::PEV_UP)
    455467    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
    456   else if( event.type == SDLK_s)
     468  else if( event.type == KeyMapper::PEV_DOWN)
    457469    this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
    458470  else if( event.type == EV_MOUSE_MOTION)
    459471  {
    460     this->xMouse = event.xRel;
    461     this->yMouse = event.yRel;
    462     mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1)));
    463    // if( xMouse*xMouse + yMouse*yMouse < 0.9)
    464      //this->setAbsDir(mouseDir);
     472    this->xMouse += event.xRel;
     473    this->yMouse += event.yRel;
    465474  }
    466475}
  • branches/network/src/world_entities/space_ships/space_ship.h

    r6634 r6693  
    6565    float                 yMouse;             //!< mouse moved in y-Direction
    6666    float                 mouseSensitivity;   //!< the mouse sensitivity
    67     float                 cycle;              //!< hovercycle
     67    int                   yInvert;
     68    int                   controlVelocityX;
     69    int                   controlVelocityY;
     70//    float                 cycle;              //!< hovercycle
    6871
    6972    Vector                velocity;           //!< the velocity of the player.
    7073    Quaternion            mouseDir;           //!< the direction where the player wants to fly
     74    float                 shipInertia;        //!< the inertia of the ship(how fast the ship reacts to a mouse input)
    7175    Quaternion            rotQuat;
     76    Quaternion            pitchDir;
    7277    float                 travelSpeed;        //!< the current speed of the player (to make soft movement)
    7378    float                 acceleration;       //!< the acceleration of the player.
  • branches/network/src/world_entities/weapons/aim.cc

    r6512 r6693  
    7373  this->source = NULL;
    7474
     75  this->range = 0;
     76  this->angle = 0;
    7577  this->anim = new tAnimation<Aim>(this, &Aim::setSize);
    7678  this->anim->setInfinity(ANIM_INF_CONSTANT);
     
    101103}
    102104
    103 void Aim::searchTarget(float range)
     105void Aim::searchTarget()
    104106{
    105107  std::list<WorldEntity*>::iterator entity;
    106 
     108  Vector diffVec(0.0, 0.0, 0.0);
     109  diffVec = ( this->getAbsCoor() - this->source->getAbsCoor() );
     110
     111//only look for target if the aim hasn`t locked a target yet or if the actual target is out of range
     112  if( this == PNode::getNullParent() || diffVec.len() > range  || ( acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) ) > angle))
    107113  for (entity = State::getObjectManager()->getObjectList(OM_GROUP_00).begin();
    108114       entity != State::getObjectManager()->getObjectList(OM_GROUP_00).end();
    109115       entity ++)
    110116  {
    111     if (this->source->getAbsCoor().x < (*entity)->getAbsCoor().x && (this->source->getAbsCoor() - (*entity)->getAbsCoor()).len() < range)
     117    diffVec = ( (*entity)->getAbsCoor() - this->source->getAbsCoor() );
     118
     119    if ( diffVec.len() < range  &&  acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) ) < angle)
    112120    {
    113121      if (this->getParent() != (*entity))
     
    119127    }
    120128  }
    121 }
    122 
     129//if no target found:
     130  this->setParent(PNode::getNullParent());
     131}
    123132
    124133
     
    155164
    156165
    157   if (this->source->getAbsCoor().x > this->getAbsCoor().x )
    158     this->searchTarget(1000);
     166//  if (this->source->getAbsCoor().x > this->getAbsCoor().x )
     167     this->searchTarget();
    159168//   float z = 0.0f;
    160169//   glReadPixels ((int)this->getAbsCoor2D().x,
  • branches/network/src/world_entities/weapons/aim.h

    r6512 r6693  
    3838  inline PNode* getTarget(PNode* target) { return this->getParent(); };
    3939
    40   void searchTarget(float range);
     40  void searchTarget();
     41
     42  void setRange(float range){this->range = range;};
     43  void setAngle(float angle){this->angle = angle;};
    4144
    4245  void setSize(float size);
     
    5356   tAnimation<Aim>* anim;
    5457
     58   float            range;                //!<
     59   float            angle;                //!<
     60
    5561   PNode*           source;               //!< Where this Shot has come from.
    5662
  • branches/network/src/world_entities/weapons/aiming_turret.cc

    r6512 r6693  
    8686  this->setStateDuration(WS_DEACTIVATING, .4);
    8787
    88   this->setMaximumEnergy(10000, 50);
     88  this->setEnergyMax(10000);
    8989  this->increaseEnergy(100000);
    9090
     
    9898  this->target = new Aim(this);
    9999  this->target->setVisibility(false);
     100  this->target->setRange(100);
     101  this->target->setAngle(M_PI);
    100102}
    101103
     
    146148  pj->setAbsDir(this->getAbsDir());
    147149  pj->activate();
    148   this->target->searchTarget(100);
     150  this->target->searchTarget();
    149151}
    150152
  • branches/network/src/world_entities/weapons/cannon.cc

    r6517 r6693  
    8181  this->setStateDuration(WS_DEACTIVATING, .4);
    8282
    83   this->setMaximumEnergy(100, 20);
     83  this->setEnergyMax(100);
    8484  this->increaseEnergy(100);
    8585  //this->minCharge = 2;
  • branches/network/src/world_entities/weapons/targeting_turret.cc

    r6675 r6693  
    8181  this->setStateDuration(WS_DEACTIVATING, .4);
    8282
    83   this->setMaximumEnergy(10000, 50);
     83  this->setEnergyMax(10000);
    8484  this->increaseEnergy(100000);
    8585
     
    9393  this->target = new Aim(this);
    9494  this->target->setVisibility(false);
    95 
     95  this->target->setRange(100);
     96  this->target->setAngle(M_PI_4/2);
     97  this->lockedTime = 0;
     98  this->neededLockTime = 2;
     99  this->lockedTarget->setParent(PNode::getNullParent());
    96100  this->loadModel("models/guns/turret2.obj");
    97101
     
    120124void TargetingTurret::tick(float dt)
    121125{
     126  if( lockedTime >= neededLockTime )
     127   {
     128    lockedTarget = this->target->getParent();
     129    lockedTime = 0;
     130   }
    122131
    123132  this->target->tick(dt);
     133
     134  if(this->target->getParent() == PNode::getNullParent())
     135   lockedTime = 0;
     136  else
     137   lockedTime += dt;
     138
    124139}
    125140
     
    138153  pj->setAbsDir(this->getAbsDir());
    139154  pj->activate();
    140   this->target->searchTarget(100);
     155  this->target->searchTarget();
    141156}
    142157
  • branches/network/src/world_entities/weapons/targeting_turret.h

    r6512 r6693  
    3232
    3333  private:
    34     Aim*          target;
    35   };
     34    Aim*           target;
     35    PNode*         lockedTarget;
     36    float          lockedTime;
     37    float          neededLockTime;
     38  };
    3639
    3740#endif /* _TARGETING_TURRET_H */
  • branches/network/src/world_entities/weapons/test_gun.cc

    r6512 r6693  
    122122  this->setStateDuration(WS_DEACTIVATING, .4);
    123123
    124   this->setMaximumEnergy(1000, 100);
     124  this->setEnergyMax(1000);
    125125  this->increaseEnergy(1000);
    126126  //this->minCharge = 2;
  • branches/network/src/world_entities/weapons/turret.cc

    r6589 r6693  
    8686  this->setStateDuration(WS_DEACTIVATING, .4);
    8787
    88   this->setMaximumEnergy(100, 5);
     88  this->setEnergyMax(100);
    8989  this->increaseEnergy(100);
    9090  //this->minCharge = 2;
  • branches/network/src/world_entities/weapons/weapon.cc

    r6674 r6693  
    9595  this->maxCharge = 1.0;                           //< The maximum charge is also one unit.
    9696
    97   this->energyLoaded = .0;                         //< How much energy is loaded in the Gun. (Weapons must be charged befor usage)
    98   this->energyLoadedMax = 5.0;                     //< Each Weapon has a Maximum energy that can be charged onto it
    99   this->energy = .0;                               //< The secondary Buffer (before we have to reload)
     97  this->energy = 10;                               //< The secondary Buffer (before we have to reload)
    10098  this->energyMax = 10.0;                          //< How much energy can be carried
    10199  this->capability = WTYPE_ALL;                    //< The Weapon has all capabilities @see W_Capability.
    102100
    103101  this->energyWidget = NULL;
    104   this->energyLoadedWidget = NULL;
    105102
    106103  // set this object to be synchronized over network
     
    291288}
    292289
    293 
    294 GLGuiWidget* Weapon::getLoadedEnergyWidget()
    295 {
    296   if (this->energyLoadedWidget == NULL)
    297   {
    298     this->energyLoadedWidget = new GLGuiBar;
    299     //this->energyLoadedWidget->setParent2D(this->bar);
    300     this->energyLoadedWidget->setRelCoor2D(20,0);
    301     this->energyLoadedWidget->setSize2D(10,50);
    302     this->energyLoadedWidget->setMaximum(this->getLoadedEnergyMax());
    303   }
    304   return this->energyLoadedWidget;
    305 }
    306 
    307290void Weapon::updateWidgets()
    308291{
     
    311294    this->energyWidget->setMaximum(this->energyMax);
    312295    this->energyWidget->setValue(this->energy);
    313   }
    314   if (this->energyLoadedWidget != NULL)
    315   {
    316     this->energyLoadedWidget->setMaximum(this->energyLoadedMax);
    317     this->energyLoadedWidget->setValue(this->energyLoaded);
    318296  }
    319297}
     
    395373  switch (action)
    396374  {
    397     case WA_SHOOT:
    398       return this->fireW();
    399       break;
    400     case WA_CHARGE:
    401       return this->chargeW();
    402       break;
    403     case WA_RELOAD:
    404       return this->reloadW();
    405       break;
    406     case WA_DEACTIVATE:
    407       return this->deactivateW();
    408       break;
    409     case WA_ACTIVATE:
    410       return this->activateW();
    411       break;
     375  case WA_SHOOT:
     376    return this->fireW();
     377    break;
     378  case WA_CHARGE:
     379    return this->chargeW();
     380    break;
     381  case WA_RELOAD:
     382    return this->reloadW();
     383    break;
     384  case WA_DEACTIVATE:
     385    return this->deactivateW();
     386    break;
     387  case WA_ACTIVATE:
     388    return this->activateW();
     389    break;
    412390  }
    413391}
     
    457435bool Weapon::chargeW()
    458436{
    459   if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge)
     437  if ( this->currentState != WS_INACTIVE && this->energy >= this->minCharge)
    460438  {
    461439    // playing Sound
     
    481459{
    482460  //if (likely(this->currentState != WS_INACTIVE))
    483   if (this->minCharge <= this->energyLoaded)
     461  if (this->minCharge <= this->energy)
    484462  {
    485463    // playing Sound
     
    488466    this->updateWidgets();
    489467    // fire
    490     this->energyLoaded -= this->minCharge;
     468    this->energy -= this->minCharge;
    491469    this->fire();
    492470    // setting up for the next state
     
    507485{
    508486  PRINTF(4)("Reloading Weapon %s\n", this->getName());
    509   if (unlikely(this->energy + this->energyLoaded < this->minCharge))
     487  if (this->ammoContainer.get() != NULL &&
     488        unlikely(this->energy + this->ammoContainer->getStoredEnergy() < this->minCharge))
    510489  {
    511490    this->requestAction(WA_DEACTIVATE);
     
    514493  }
    515494
    516   float chargeSize = this->energyLoadedMax - this->energyLoaded;       //!< The energy to be charged
    517495
    518496  if (this->soundBuffers[WA_RELOAD] != NULL)
    519497    this->soundSource->play(this->soundBuffers[WA_RELOAD]);
    520498
    521   if (chargeSize > this->energy)
    522   {
    523     this->energyLoaded += this->energy;
    524     this->energy = 0.0;
    525     PRINT(5)("Energy depleted\n");
    526   }
    527   else
    528   {
    529     PRINTF(5)("Loaded %f energy into the Guns Buffer\n", chargeSize);
    530     this->energyLoaded += chargeSize;
    531     this->energy -= chargeSize;
    532   }
    533 
     499  if (this->ammoContainer.get() != NULL)
     500    this->ammoContainer->fillWeapon(this);
     501  else
     502  {
     503    this->energy = this->energyMax;
     504  }
    534505  this->updateWidgets();
    535506  this->reload();
     
    617588{
    618589  PRINT(0)("Weapon-Debug %s, state: %s (duration: %fs), nextAction: %s\n", this->getName(), Weapon::stateToChar(this->currentState), this->stateDuration, Weapon::actionToChar(requestedAction));
    619   PRINT(0)("Energy: max: %f; current: %f;  loadedMax: %f; loadedCurrent: %f; chargeMin: %f, chargeMax %f\n",
    620            this->energyMax, this->energy, this->energyLoadedMax, this->energyLoaded, this->minCharge, this->maxCharge);
     590  PRINT(0)("Energy: max: %f; current: %f; chargeMin: %f, chargeMax %f\n",
     591           this->energyMax, this->energy, this->minCharge, this->maxCharge);
    621592
    622593
     
    663634  switch (action)
    664635  {
    665     case WA_SHOOT:
    666       return "shoot";
    667       break;
    668     case WA_CHARGE:
    669       return "charge";
    670       break;
    671     case WA_RELOAD:
    672       return "reload";
    673       break;
    674     case WA_ACTIVATE:
    675       return "activate";
    676       break;
    677     case WA_DEACTIVATE:
    678       return "deactivate";
    679       break;
    680     case WA_SPECIAL1:
    681       return "special1";
    682       break;
    683     default:
    684       return "none";
    685       break;
     636  case WA_SHOOT:
     637    return "shoot";
     638    break;
     639  case WA_CHARGE:
     640    return "charge";
     641    break;
     642  case WA_RELOAD:
     643    return "reload";
     644    break;
     645  case WA_ACTIVATE:
     646    return "activate";
     647    break;
     648  case WA_DEACTIVATE:
     649    return "deactivate";
     650    break;
     651  case WA_SPECIAL1:
     652    return "special1";
     653    break;
     654  default:
     655    return "none";
     656    break;
    686657  }
    687658}
     
    726697  switch (state)
    727698  {
    728     case WS_SHOOTING:
    729       return "shooting";
    730       break;
    731     case WS_CHARGING:
    732       return "charging";
    733       break;
    734     case WS_RELOADING:
    735       return "reloading";
    736       break;
    737     case WS_ACTIVATING:
    738       return "activating";
    739       break;
    740     case WS_DEACTIVATING:
    741       return "deactivating";
    742       break;
    743     case WS_IDLE:
    744       return "idle";
    745       break;
    746     case WS_INACTIVE:
    747       return "inactive";
    748       break;
    749     default:
    750       return "none";
    751       break;
    752   }
    753 }
     699  case WS_SHOOTING:
     700    return "shooting";
     701    break;
     702  case WS_CHARGING:
     703    return "charging";
     704    break;
     705  case WS_RELOADING:
     706    return "reloading";
     707    break;
     708  case WS_ACTIVATING:
     709    return "activating";
     710    break;
     711  case WS_DEACTIVATING:
     712    return "deactivating";
     713    break;
     714  case WS_IDLE:
     715    return "idle";
     716    break;
     717  case WS_INACTIVE:
     718    return "inactive";
     719    break;
     720  default:
     721    return "none";
     722    break;
     723  }
     724}
  • branches/network/src/world_entities/weapons/weapon.h

    r6512 r6693  
    1616
    1717#include "world_entity.h"
     18#include "count_pointer.h"
     19#include "ammo_container.h"
    1820
    1921// FORWARD DECLARATION
     
    105107    inline void setCapability(long capabilities) { this->capability = capabilities; };
    106108    /** @returns the Capabilities of this Weapon */
    107     inline long getCapability() { return this->capability; };
     109    inline long getCapability() const { return this->capability; };
    108110    void setProjectileType(ClassID projectile);
    109111    void setProjectileType(const char* projectile);
     
    135137    inline WeaponState getCurrentState() const { return this->currentState; };
    136138
    137     /** @param energyMax the maximum energy the Weapon can have @param energyLoadedMax the maximum energy in the weapon buffers */
    138     inline void setMaximumEnergy(float energyMax, float energyLoadedMax) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; };
    139     inline float getLoadedEnergyMax() const { return this->energyLoadedMax; };
     139    /** @param energyMax the maximum energy the Weapon can have */
     140    inline void setEnergyMax(float energyMax) { this->energyMax = energyMax; };
     141    inline float getEnergy() const { return this->energy; };
    140142    inline float getEnergyMax() const { return this->energyMax; };
    141     inline float getEnergy() const { return this->energy; };
    142     inline float getLoadedEnergy() const { return this->energyLoaded; };
     143    inline void setAmmoContainer(const CountPointer<AmmoContainer>& ammoContainer) { this->ammoContainer = ammoContainer;}
    143144
    144145    void setActionSound(WeaponAction action, const char* soundFile);
     
    150151
    151152    GLGuiWidget* getEnergyWidget();
    152     GLGuiWidget* getLoadedEnergyWidget();
    153153
    154154    // FLOW
     
    198198
    199199    // it is all about energy
    200     float                energy;                           //!< The energy stored in the weapons secondary buffers (reserve)
    201     float                energyLoaded;                     //!< The energy stored in the weapons primary buffers (fire without reload)
     200    float                energy;                           //!< The energy stored in the weapons buffers
    202201    float                energyMax;                        //!< The maximal energy that can be stored in the secondary buffers (reserveMax)
    203     float                energyLoadedMax;                  //!< The maximal energy that can be stored in the primary buffers
     202    CountPointer<AmmoContainer> ammoContainer;             //!< Pointer to the AmmoContainer this weapon grabs Energy from.
    204203    //! @todo move this to projectile
    205204    float                minCharge;                        //!< The minimal energy to be loaded onto one projectile if chargeable otherwise the power consumed by one projectile
     
    207206
    208207    GLGuiBar*            energyWidget;
    209     GLGuiBar*            energyLoadedWidget;
    210208
    211209    ////////////
  • branches/network/src/world_entities/weapons/weapon_manager.cc

    r6568 r6693  
    217217bool WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID)
    218218{
     219  assert(weapon != NULL);
     220
    219221  if (unlikely(configID >= WM_MAX_CONFIGS || slotID >= (int)this->slotCount))
    220222  {
    221     PRINTF(2)("Slot %d of config %d is not availiabe (max: %d)\n", slotID, configID, this->slotCount);
     223    PRINTF(2)("Slot %d of config %d is not availiabe (max: %d) searching for suitable slot\n", slotID, configID, this->slotCount);
     224    if (configID >= WM_MAX_CONFIGS)
     225      configID = -1;
     226    if (slotID >= (int)this->slotCount)
     227      slotID = -1;
     228  }
     229  // if no ConfigID is supplied set to Current Config.
     230  if (configID <= -1)
     231    configID = this->currentConfigID;
     232  //
     233  if (configID > -1 && slotID == -1)
     234  {
     235    slotID = this->getNextFreeSlot(configID, weapon->getCapability());
     236    if (slotID == -1)
     237      configID = -1;
     238  }
     239
     240  if (configID > 0 && slotID > 0 && this->configs[configID][slotID] != NULL)
     241  {
     242    PRINTF(3)("Weapon-slot %d/%d of %s already poulated, remove weapon (%s::%s) first\n", configID, slotID, this->getName(), weapon->getClassName(), weapon->getName());
    222243    return false;
    223244  }
    224245
    225   if (this->configs[configID][slotID] != NULL && configID > 0 && slotID > 0)
    226     PRINTF(3)("Weapon-slot %d/%d of %s already poulated, overwriting\n", configID, slotID, this->getName());
    227 
    228   if (slotID == -1) // WM_FREE_SLOT
     246  if (slotID <= -1) // WM_FREE_SLOT
    229247  {
    230248    slotID = this->getNextFreeSlot(configID, weapon->getCapability());
     
    245263
    246264  //! @todo check if the weapon is already assigned to another config in another slot
     265  assert(this->configs[configID][slotID] == NULL);
     266
    247267  this->configs[configID][slotID] = weapon;
     268  weapon->setAmmoContainer(this->getAmmoContainer(weapon->getProjectileType()));
    248269  if (this->parent != NULL)
    249270  {
    250271    this->parent->addChild(weapon);
    251272  }
    252   PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);
     273  PRINTF(3)("Added a new Weapon (%s::%s) to the WeaponManager: config %i/ slot %i\n", weapon->getClassName(), weapon->getName(), configID, slotID);
    253274  return true;
    254275}
     
    420441/**
    421442 * private gets the next free slot in a certain weaponconfig
    422  * @param the selected weaponconfig
     443 * @param the selected weaponconfig -1 if none found
    423444 */
    424445int WeaponManager::getNextFreeSlot(int configID, long capability)
    425446{
    426   for( int i = 0; i < this->slotCount; ++i)
    427   {
    428     if( this->configs[configID][i] == NULL &&
    429         (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) &&
    430         (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS))
    431       return i;
     447  if (configID == -1)
     448  {
     449    for (configID = 0; configID < WM_MAX_CONFIGS; configID++)
     450      for( int i = 0; i < this->slotCount; ++i)
     451      {
     452        if( this->configs[configID][i] == NULL &&
     453            (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) &&
     454            (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS))
     455          return i;
     456    }
     457  }
     458  else
     459  {
     460    for( int i = 0; i < this->slotCount; ++i)
     461    {
     462      if( this->configs[configID][i] == NULL &&
     463          (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) &&
     464          (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS))
     465        return i;
     466    }
    432467  }
    433468  return -1;
    434469}
    435470
     471CountPointer<AmmoContainer>& WeaponManager::getAmmoContainer(ClassID projectileType)
     472{
     473  for (unsigned int i = 0; i < this->ammo.size(); i++)
     474  {
     475    if (this->ammo[i]->getProjectileType() == projectileType)
     476      return this->ammo[i];
     477  }
     478  this->ammo.push_back(CountPointer<AmmoContainer>(new AmmoContainer(projectileType)));
     479  return this->ammo.back();
     480}
    436481
    437482
  • branches/network/src/world_entities/weapons/weapon_manager.h

    r6561 r6693  
    1717#include "crosshair.h"
    1818#include "weapon.h"
     19
     20#include "count_pointer.h"
     21#include "ammo_container.h"
    1922
    2023// FORWARD DECLARATION
     
    7174    PNode* getParent() const { return this->parent; };
    7275
    73     bool addWeapon(Weapon* weapon);
    7476    bool addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
    7577    void removeWeapon(Weapon* weapon, int configID = -1);
     78
    7679    Weapon* getWeapon(int slotID) const { return (slotID >= 0 && slotID < this->slotCount)? this->currentSlotConfig[slotID].nextWeapon: NULL; };
    7780
     
    8285    void previousWeaponConfig();
    8386    void changeWeaponConfig(int weaponConfig);
     87
     88    float addAmmunition(ClassID projectileType, float ammo);
     89
    8490
    8591    /** @returns a fixed target namely the Crosshair's 3D position */
     
    97103 // private:
    98104    int getNextFreeSlot(int configID, long capability = WTYPE_ALL);
     105    CountPointer<AmmoContainer>& getAmmoContainer(ClassID projectileType);
    99106
    100107  private:
     
    112119    Crosshair*              crosshair;                                //!< an aim.
    113120    tAnimation<Crosshair>*  crossHairSizeAnim;                        //!< An animation for the crosshair (scaling)
     121
     122    std::vector<CountPointer<AmmoContainer> > ammo;                   //!< Containers
    114123};
    115124
Note: See TracChangeset for help on using the changeset viewer.