Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6979 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Feb 2, 2006, 12:29:27 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: GraphicsEffects are BaseObject Lists now

Location:
trunk/src/lib/graphics
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/effects/graphics_effect.cc

    r6977 r6979  
    3737  this->setClassID(CL_GRAPHICS_EFFECT, "GraphicsEffect");
    3838  this->bActivated = false;
    39 
    40   this->bActivated = GraphicsEngine::getInstance()->loadGraphicsEffect(this);
    4139}
    4240
     
    4745GraphicsEffect::~GraphicsEffect()
    4846{
    49   if( this->bActivated)
    50     GraphicsEngine::getInstance()->unloadGraphicsEffect(this);
     47
    5148}
    5249
  • trunk/src/lib/graphics/graphics_engine.cc

    r6978 r6979  
    4646#include "load_param.h"
    4747#include "factory.h"
     48#include "class_list.h"
    4849
    4950#ifdef __WIN32__
    50  #include "class_list.h"
    5151 #include "static_model.h"
    5252#endif
     
    8585  this->hwExtensions = NULL;
    8686
    87   // initialize the TextEngine
     87  // initialize the Modules
    8888  TextEngine::getInstance();
     89  this->graphicsEffects = NULL;
     90
    8991}
    9092
     
    115117
    116118  SDL_QuitSubSystem(SDL_INIT_VIDEO);
    117 //   if (this->screen != NULL)
    118 //     SDL_FreeSurface(this->screen);
     119  //   if (this->screen != NULL)
     120  //     SDL_FreeSurface(this->screen);
    119121
    120122  GraphicsEngine::singletonRef = NULL;
     
    128130void GraphicsEngine::loadParams(const TiXmlElement* root)
    129131{
    130   LoadParamXML(root, "GraphicsEffect", this, GraphicsEngine, loadGraphicsEffectXML)
    131       .describe("loads a graphics effect");
     132  LoadParamXML(root, "GraphicsEffect", this, GraphicsEngine, loadGraphicsEffects)
     133  .describe("loads a graphics effect");
    132134}
    133135
     
    169171  this->initVideo(atoi(resolution.getString(0)), atoi(resolution.getString(1)), 16);
    170172
    171 //   GraphicsEffect* fe = new FogEffect(NULL);
    172 //   this->loadGraphicsEffect(fe);
    173 //   fe->activate();
    174 //   PRINTF(0)("--------------------------------------------------------------\n");
     173  //   GraphicsEffect* fe = new FogEffect(NULL);
     174  //   this->loadGraphicsEffect(fe);
     175  //   fe->activate();
     176  //   PRINTF(0)("--------------------------------------------------------------\n");
    175177
    176178  //LenseFlare* ge = new LenseFlare();
     
    203205  {
    204206    PRINTF(1)("could not initialize SDL Video\n");
    205       //      return -1;
     207    //      return -1;
    206208  }
    207209  // initialize SDL_GL-settings
     
    214216  const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo ();
    215217  if( videoInfo == NULL)
    216     {
    217       PRINTF(1)("Failed getting Video Info :%s\n", SDL_GetError());
    218       SDL_Quit ();
    219     }
     218  {
     219    PRINTF(1)("Failed getting Video Info :%s\n", SDL_GetError());
     220    SDL_Quit ();
     221  }
    220222  if( videoInfo->hw_available)
    221223    this->videoFlags |= SDL_HWSURFACE;
     
    226228    VideoFlags |= SDL_HWACCEL;
    227229  */
    228     // setting up the Resolution
     230  // setting up the Resolution
    229231  this->setResolution(resX, resY, bbp);
    230232
     
    293295  const char* extensions = (const char*) glGetString(GL_EXTENSIONS);
    294296
    295 //  printf("%s %s %s\n %s", renderer, vendor, version, extensions);
     297  //  printf("%s %s %s\n %s", renderer, vendor, version, extensions);
    296298
    297299  if (this->hwRenderer == NULL && renderer != NULL)
     
    348350    SDL_FreeSurface(screen);
    349351  if((this->screen = SDL_SetVideoMode(this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags | this->fullscreenFlag)) == NULL)
    350     {
    351       PRINTF(1)("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags, SDL_GetError());
    352       //    SDL_Quit();
    353       //    return -1;
    354     }
    355     glViewport(0, 0, width, height);                     // Reset The Current Viewport
     352  {
     353    PRINTF(1)("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags, SDL_GetError());
     354    //    SDL_Quit();
     355    //    return -1;
     356  }
     357  glViewport(0, 0, width, height);                     // Reset The Current Viewport
    356358
    357359#ifdef __WIN32__
    358     // REBUILDING TEXTURES (ON WINDOWS CONTEXT SWITCH)
    359     const std::list<BaseObject*>* texList = ClassList::getList(CL_TEXTURE);
    360     if (texList != NULL)
    361     {
    362       std::list<BaseObject*>::const_iterator reTex;
    363       for (reTex = texList->begin(); reTex != texList->end(); reTex++)
    364         dynamic_cast<Texture*>(*reTex)->rebuild();
    365     }
    366     // REBUILDING MODELS
    367     const std::list<BaseObject*>* modelList = ClassList::getList(CL_STATIC_MODEL);
    368     if (texList != NULL)
    369     {
    370       std::list<BaseObject*>::const_iterator reModel;
    371       for (reModel = modelList->begin(); reModel != modelList->end(); reModel++)
    372         dynamic_cast<StaticModel*>(*reModel)->rebuild();
    373     }
     360  // REBUILDING TEXTURES (ON WINDOWS CONTEXT SWITCH)
     361  const std::list<BaseObject*>* texList = ClassList::getList(CL_TEXTURE);
     362  if (texList != NULL)
     363  {
     364    std::list<BaseObject*>::const_iterator reTex;
     365    for (reTex = texList->begin(); reTex != texList->end(); reTex++)
     366      dynamic_cast<Texture*>(*reTex)->rebuild();
     367  }
     368  // REBUILDING MODELS
     369  const std::list<BaseObject*>* modelList = ClassList::getList(CL_STATIC_MODEL);
     370  if (texList != NULL)
     371  {
     372    std::list<BaseObject*>::const_iterator reModel;
     373    for (reModel = modelList->begin(); reModel != modelList->end(); reModel++)
     374      dynamic_cast<StaticModel*>(*reModel)->rebuild();
     375  }
    374376#endif /* __WIN32__ */
    375377}
     
    444446{
    445447#if DEBUG < 3
    446    if (steal)
    447      SDL_WM_GrabInput(SDL_GRAB_ON);
    448    else
    449      SDL_WM_GrabInput(SDL_GRAB_OFF);
     448  if (steal)
     449    SDL_WM_GrabInput(SDL_GRAB_ON);
     450  else
     451    SDL_WM_GrabInput(SDL_GRAB_OFF);
    450452#endif
    451453}
     
    457459bool GraphicsEngine::isStealingEvents()
    458460{
    459    if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON)
    460      return true;
    461    else
    462      return false;
     461  if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON)
     462    return true;
     463  else
     464    return false;
    463465};
    464466
     
    539541
    540542  /* Check is there are any modes available */
    541   if(this->videoModes == (SDL_Rect **)0){
     543  if(this->videoModes == (SDL_Rect **)0)
     544  {
    542545    PRINTF(1)("No modes available!\n");
    543546    exit(-1);
     
    545548
    546549  /* Check if our resolution is restricted */
    547   if(this->videoModes == (SDL_Rect **)-1){
     550  if(this->videoModes == (SDL_Rect **)-1)
     551  {
    548552    PRINTF(2)("All resolutions available.\n");
    549553  }
    550   else{
     554  else
     555  {
    551556    /* Print valid modes */
    552557    PRINT(0)("Available Resoulution Modes are\n");
     
    592597
    593598#ifndef NO_TEXT
    594       char tmpChar1[20];
    595       sprintf(tmpChar1, "Current:  %4.0f", this->currentFPS);
    596       this->geTextCFPS->setText(tmpChar1);
    597       char tmpChar2[20];
    598       sprintf(tmpChar2, "Max:    %4.0f", this->maxFPS);
    599       this->geTextMaxFPS->setText(tmpChar2);
    600       char tmpChar3[20];
    601       sprintf(tmpChar3, "Min:    %4.0f", this->minFPS);
    602       this->geTextMinFPS->setText(tmpChar3);
     599    char tmpChar1[20];
     600    sprintf(tmpChar1, "Current:  %4.0f", this->currentFPS);
     601    this->geTextCFPS->setText(tmpChar1);
     602    char tmpChar2[20];
     603    sprintf(tmpChar2, "Max:    %4.0f", this->maxFPS);
     604    this->geTextMaxFPS->setText(tmpChar2);
     605    char tmpChar3[20];
     606    sprintf(tmpChar3, "Min:    %4.0f", this->minFPS);
     607    this->geTextMinFPS->setText(tmpChar3);
    603608#endif /* NO_TEXT */
    604609
     
    608613
    609614  // tick the graphics effects
    610   list<GraphicsEffect*>::iterator it;
    611   for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++)
    612     (*it)->tick(dt);
     615  if (this->graphicsEffects != NULL || (this->graphicsEffects = ClassList::getList(CL_GRAPHICS_EFFECT)) != NULL)
     616  {
     617    std::list<BaseObject*>::const_iterator it;
     618    for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++)
     619      dynamic_cast<GraphicsEffect*>(*it)->tick(dt);
     620  }
    613621}
    614622
     
    625633  Shader::restoreShader();
    626634
    627   //draw the graphics effects
    628   list<GraphicsEffect*>::const_iterator it;
    629   for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++)
    630     (*it)->draw();
     635  if (this->graphicsEffects != NULL)
     636  {
     637    //draw the graphics effects
     638    list<BaseObject*>::const_iterator it;
     639    for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++)
     640      dynamic_cast<GraphicsEffect*>(*it)->draw();
     641  }
    631642}
    632643
     
    648659#ifndef NO_TEXT
    649660  if( display )
    650 {
    651   if (this->geTextCFPS == NULL)
    652   {
    653     this->geTextCFPS = new Text("fonts/arial_black.ttf", 15);
    654     this->geTextCFPS->setName("curFPS");
    655     this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);
    656     this->geTextCFPS->setAbsCoor2D(5, 0);
    657   }
    658   if (this->geTextMaxFPS == NULL)
    659   {
    660     this->geTextMaxFPS = new Text("fonts/arial_black.ttf", 15);
    661     this->geTextMaxFPS->setName("MaxFPS");
    662     this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);
    663     this->geTextMaxFPS->setAbsCoor2D(5, 20);
    664   }
    665   if (this->geTextMinFPS == NULL)
    666   {
    667     this->geTextMinFPS = new Text("fonts/arial_black.ttf", 15);
    668     this->geTextMinFPS->setName("MinFPS");
    669     this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);
    670     this->geTextMinFPS->setAbsCoor2D(5, 40);
    671   }
    672 }
    673 else
    674 {
    675   delete this->geTextCFPS;
    676   this->geTextCFPS = NULL;
    677   delete this->geTextMaxFPS;
    678   this->geTextMaxFPS = NULL;
    679   delete this->geTextMinFPS;
    680   this->geTextMinFPS = NULL;
    681 }
     661  {
     662    if (this->geTextCFPS == NULL)
     663    {
     664      this->geTextCFPS = new Text("fonts/arial_black.ttf", 15);
     665      this->geTextCFPS->setName("curFPS");
     666      this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);
     667      this->geTextCFPS->setAbsCoor2D(5, 0);
     668    }
     669    if (this->geTextMaxFPS == NULL)
     670    {
     671      this->geTextMaxFPS = new Text("fonts/arial_black.ttf", 15);
     672      this->geTextMaxFPS->setName("MaxFPS");
     673      this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);
     674      this->geTextMaxFPS->setAbsCoor2D(5, 20);
     675    }
     676    if (this->geTextMinFPS == NULL)
     677    {
     678      this->geTextMinFPS = new Text("fonts/arial_black.ttf", 15);
     679      this->geTextMinFPS->setName("MinFPS");
     680      this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);
     681      this->geTextMinFPS->setAbsCoor2D(5, 40);
     682    }
     683  }
     684  else
     685  {
     686    delete this->geTextCFPS;
     687    this->geTextCFPS = NULL;
     688    delete this->geTextMaxFPS;
     689    this->geTextMaxFPS = NULL;
     690    delete this->geTextMinFPS;
     691    this->geTextMinFPS = NULL;
     692  }
    682693  this->bDisplayFPS = display;
    683694#else
     
    695706  switch (event.type)
    696707  {
    697     case EV_VIDEO_RESIZE:
     708      case EV_VIDEO_RESIZE:
    698709      this->resolutionChanged(event.resize);
    699710      break;
     
    705716 * @param root The XML-element to load GraphicsEffects from
    706717 */
    707 void GraphicsEngine::loadGraphicsEffectXML(const TiXmlElement* root)
     718void GraphicsEngine::loadGraphicsEffects(const TiXmlElement* root)
    708719{
    709720  LOAD_PARAM_START_CYCLE(root, element);
     
    714725  LOAD_PARAM_END_CYCLE(element);
    715726}
    716 
    717 
    718 /**
    719  * loads a GraphicsEffect into the engine
    720  * @param effect the GraphicsEffect to add
    721  */
    722 bool GraphicsEngine::loadGraphicsEffect(GraphicsEffect* effect)
    723 {
    724   list<GraphicsEffect*>::iterator it;
    725   for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++)
    726     if( (*it) == effect)
    727       return false;
    728 
    729   this->graphicsEffects.push_back(effect);
    730 
    731   return true;
    732 }
    733 
    734 
    735 /**
    736  * unloads a GraphicsEffect from the engine
    737  * @param effect the GraphicsEffect to remove
    738  */
    739 bool GraphicsEngine::unloadGraphicsEffect(GraphicsEffect* effect)
    740 {
    741   list<GraphicsEffect*>::iterator it;
    742   for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++)
    743   {
    744     if( (*it) == effect)
    745     {
    746       this->graphicsEffects.erase(it);
    747       return true;
    748     }
    749   }
    750 
    751   return false;
    752 }
    753 
  • trunk/src/lib/graphics/graphics_engine.h

    r6815 r6979  
    8686    void process(const Event  &event);
    8787
    88     void loadGraphicsEffectXML(const TiXmlElement* root);
    89     bool loadGraphicsEffect(GraphicsEffect* effect);
    90     bool unloadGraphicsEffect(GraphicsEffect* effect);
     88    void loadGraphicsEffects(const TiXmlElement* root);
    9189
    9290
     
    134132    float                      minFPS;             //!< minimal frame rate we ever got since start.
    135133
    136     std::list<GraphicsEffect*> graphicsEffects;    //!< list of graphics effects
     134    const std::list<BaseObject*>* graphicsEffects; //!< list of graphics effects
    137135
    138136
Note: See TracChangeset for help on using the changeset viewer.