Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4330 in orxonox.OLD for orxonox/branches/physics/src


Ignore:
Timestamp:
May 27, 2005, 12:31:47 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/physics: more threading capabilities

Location:
orxonox/branches/physics/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/physics/src/lib/graphics/particles/particle_system.cc

    r4293 r4330  
    115115  this->particleType = particleType;
    116116  this->dialectCount = count;
    117   if (glID != NULL)
    118     delete glID;
    119 
    120   glID = new GLuint[count];
    121   for (int i = 0; i< count; i++)
    122     glID[i] = 0;
    123 
    124   glID[0] = glGenLists(count);
    125  
    126   material = new Material("transperencyMap");
    127   material->setDiffuseMap("pictures/radialTransparency.png");
    128   //  material->setTransparency(.5);
    129 
    130   glNewList(glID[0], GL_COMPILE);
    131   glBegin(GL_TRIANGLE_STRIP);
    132   glTexCoord2f(1, 1);
    133   glVertex3f(0.0, .5, .5);
    134   glTexCoord2f(1, 0);
    135   glVertex3f(0.0, -.5, .5);
    136   glTexCoord2f(0, 1);
    137   glVertex3f(0.0, .5, -.5);
    138   glTexCoord2f(0, 0);
    139   glVertex3f(0.0, -.5, -.5);
    140   glEnd();
    141   glEndList();
     117  //  if (glID != NULL)
     118  //    delete glID;
     119
     120  //  glID = new GLuint[count];
     121  //  for (int i = 0; i< count; i++)
     122  //    glID[i] = 0;
     123
     124  //  glID[0] = glGenLists(count);
     125  if (material)
     126    delete material;
     127  material = NULL;
     128
     129  if (particleType == PARTICLE_SPRITE)
     130    {
     131      material = new Material("transperencyMap");
     132      material->setDiffuseMap("pictures/radialTransparency.png");
     133      //  material->setTransparency(.5);
     134    }
    142135}
    143136
  • orxonox/branches/physics/src/subprojects/particles/Makefile.in

    r4316 r4330  
    6767        particles-null_parent.$(OBJEXT) particles-gui_gtk.$(OBJEXT)
    6868particles_OBJECTS = $(am_particles_OBJECTS)
    69 particles_DEPENDENCIES = $(MAINSRCDIR)/lib/physics/libORXphysics.a
     69am__DEPENDENCIES_1 =
     70particles_DEPENDENCIES = $(MAINSRCDIR)/lib/physics/libORXphysics.a \
     71        $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
    7072DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
    7173depcomp = $(SHELL) $(top_srcdir)/depcomp
     
    213215MAINSRCDIR = ../..
    214216AM_CXXFLAGS = -I$(MAINSRCDIR) -I$(MAINSRCDIR)/world_entities -I$(MAINSRCDIR)/story_entities -I$(MAINSRCDIR)/lib -I$(MAINSRCDIR)/lib/coord -I$(MAINSRCDIR)/lib/data -I$(MAINSRCDIR)/lib/graphics -I$(MAINSRCDIR)/lib/graphics/importer -I$(MAINSRCDIR)/lib/graphics/particles -I$(MAINSRCDIR)/lib/gui -I$(MAINSRCDIR)/lib/gui/gui -I$(MAINSRCDIR)/lib/lang -I$(MAINSRCDIR)/lib/util -I$(MAINSRCDIR)/lib/math -I$(MAINSRCDIR)/lib/physics -I$(MAINSRCDIR)/lib/physics/fields -I$(MAINSRCDIR)/lib/tinyxml -I$(MAINSRCDIR)/defs -I$(MAINSRCDIR)/font -I$(MAINSRCDIR)/network -I$(MAINSRCDIR)/glmenu -I$(MAINSRCDIR)/ai -I$(MAINSRCDIR)/util -I$(MAINSRCDIR)/util/animation -I$(MAINSRCDIR)/util/common -I$(MAINSRCDIR)/util/loading -I$(MAINSRCDIR)/util/track -I$(MAINSRCDIR)/subprojects
    215 AM_LDFLAGS = $(MWINDOWS) \
    216            $(GTK2_LIBS) $(GTHREAD_LIBS) $(CURL_LIBS)
    217 
    218 particles_LDADD = $(MAINSRCDIR)/lib/physics/libORXphysics.a
     217particles_LDADD = $(MAINSRCDIR)/lib/physics/libORXphysics.a \
     218                  $(GTK2_LIBS) $(GTHREAD_LIBS) $(CURL_LIBS) \
     219                  -lpthread
     220
    219221particles_CPPFLAGS = $(GTK2_CFLAGS) $(GTHREAD_CFLAGS) $(CURL_CFLAGS) $(MSBITFIELDS)
    220222particles_SOURCES = framework.cc \
  • orxonox/branches/physics/src/subprojects/particles/framework.cc

    r4327 r4330  
    3333int verbose;
    3434
     35pthread_mutex_t mutex;
     36
     37
     38
    3539void Framework::initModule()
    3640{
     
    5256}
    5357
    54 bool Framework::mainLoop()
    55 {
     58void* Framework::mainLoop(void* tmp)
     59{
     60  Framework* framework = Framework::getInstance();
    5661  while(true)
    5762    {
    5863      // keyhandler returns false if sdl gets quit by some event
    59       if (!this->keyHandler())
    60         return false;
     64      if (!framework->keyHandler())
     65        pthread_exit(NULL);
    6166
    6267      // tick the scene
    63       float dt = this->tick();
     68      float dt = framework->tick();
    6469
    6570      // Draw the scene
    66       this->draw(dt);
     71      pthread_mutex_lock (&mutex);
     72      framework->draw(dt);
     73      pthread_mutex_unlock (&mutex);
    6774    }
    6875}
     
    174181            this->printHelp();
    175182            break;
    176 
    177           case SDLK_1:
    178             {
    179               ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1);
    180               if (tmpEmit)
    181                 {
    182                   tmpEmit->setEmissionRate(tmpEmit->getEmissionRate() +1.0);
    183                   PRINT(3)("emissionRate set to %f\n", tmpEmit->getEmissionRate());
    184                 }
    185             }
    186             break;
    187           case SDLK_2:
    188             {
    189               ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1);
    190               if (tmpEmit)
    191                 {
    192                   tmpEmit->setEmissionRate(tmpEmit->getEmissionRate() -1.0);
    193                   PRINT(3)("emissionRate set to %f\n", tmpEmit->getEmissionRate());
    194                 }
    195             }
    196             break;
    197           case SDLK_3:
    198             {
    199               ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1);
    200               if (tmpEmit)
    201                 {
    202                   tmpEmit->setEmissionVelocity(tmpEmit->getEmissionVelocity() -.01);
    203                   PRINT(3)("emissionVelocity set to %f\n", tmpEmit->getEmissionVelocity());
    204                 }
    205             }
    206             break;
    207           case SDLK_4:
    208             {
    209               ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1);
    210               if (tmpEmit)
    211                 {
    212                   tmpEmit->setEmissionVelocity(tmpEmit->getEmissionVelocity() + .01);
    213                   PRINT(3)("emissionVelocity set to %f\n", tmpEmit->getEmissionVelocity());
    214                 }
    215             }
    216             break;
    217           case SDLK_5:
    218             {
    219               ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1);
    220               if (tmpEmit)
    221                 {
    222                   tmpEmit->setSpread(tmpEmit->getSpread() +.1);
    223                   PRINT(3)("emissionSpreadAngle set to %f\n", tmpEmit->getSpread());
    224                 }
    225             }
    226             break;
    227           case SDLK_6:
    228             {
    229               ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1);
    230               if (tmpEmit)
    231                 {
    232                   tmpEmit->setSpread(tmpEmit->getSpread() -.1);
    233                   PRINT(3)("emissionSpreadAngle set to %f\n", tmpEmit->getSpread());
    234                 }
    235             }
    236             break;
    237           case SDLK_7:
    238             {
    239               ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1);
    240               if (tmpEmit)
    241                 {
    242                   tmpEmit->setSize(tmpEmit->getSize() - 1.0);
    243                   PRINT(3)("EmitterSize set to %f\n", tmpEmit->getSize());
    244                 }
    245             }
    246             break;
    247           case SDLK_8:
    248             {
    249               ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1);
    250               if (tmpEmit)
    251                 {
    252                   tmpEmit->setSize(tmpEmit->getSize() +1.0);
    253                   PRINT(3)("EmitterSize set to %f\n", tmpEmit->getSize());
    254                 }
    255             }
    256             break;
    257           case SDLK_9:
    258             {
    259               ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1);
    260               if (tmpEmit)
    261                 {
    262                   if (tmpEmit->getType() == EMITTER_DOT)
    263                     tmpEmit->setType(EMITTER_PLANE);
    264                   else if (tmpEmit->getType() == EMITTER_PLANE)
    265                     tmpEmit->setType(EMITTER_CUBE);
    266                   else if (tmpEmit->getType() == EMITTER_CUBE)
    267                     tmpEmit->setType(EMITTER_DOT);
    268                   PRINT(3)("EmitterType set to %d\n", tmpEmit->getType());
    269                 }
    270             }
    271             break;
    272 
    273183          }
    274184        break;
     
    347257  PRINT(0)("h - print thisHelp\n");
    348258  PRINT(0)("i - state Information\n\n");
    349   PRINT(0)("Emitter Properties\n");
    350   PRINT(0)("1,2 - increase/decrease emissionRate\n");
    351   PRINT(0)("3,4 - increase/decrease emission velocity\n");
    352   PRINT(0)("5,6 - increase/decrease spread angle\n");
    353   PRINT(0)("7,8 - increase-decrease emitter-size\n");
    354   PRINT(0)("9 - swap emitterType\n");
    355259  PRINT(0)("\n");
    356260
     
    358262}
    359263
    360 int changeOption(GtkWidget* nonInterest, void* widget)
     264int emitterChange(GtkWidget* nonInterest, void* widget)
    361265{
    362266  Option* option = (Option*) widget;
     
    399303        }
    400304    }
     305  delete valueC;
     306}
     307
     308
     309int systemChange(GtkWidget* nonInterest, void* widget)
     310{
     311  Option* option = (Option*) widget;
     312  const char* name = option->getTitle();
     313  char* valueC = option->save();
     314  float value = atof(valueC);
    401315
    402316  ParticleSystem* tmpSys = ParticleEngine::getInstance()->getSystemByNumber(1);
     
    435349            tmpSys->setType(PARTICLE_SPRITE);
    436350
    437           PRINT(3)("ParticleType set to %f\n", valueC);
     351          PRINT(3)("ParticleType set to %s\n", valueC);
    438352        }
    439353
     
    445359
    446360    }
    447 
    448361  delete valueC;
    449362}
    450363
     364
     365int quitGui(GtkWidget* widget, void* data)
     366{
     367#ifdef HAVE_GTK2
     368  gtk_main_quit();
     369  while(gtk_events_pending()) gtk_main_iteration();
     370#endif /* HAVE_GTK2 */
     371}
    451372
    452373void* Framework::initGui(void* argv)
     
    466387          emitterBox->fill(new Label("EmissionRate"));
    467388          Slider* EmissionRate = new Slider("EmissionRate", 0, 1000);
    468           EmissionRate->connectSignal("value_changed", (void*)EmissionRate, changeOption );
     389          EmissionRate->connectSignal("value_changed", (void*)EmissionRate, emitterChange );
    469390          emitterBox->fill(EmissionRate);
    470391         
     
    472393          Slider* velocity = new Slider("Velocity", 0, 2);
    473394          velocity->setExactness(3);
    474           velocity->connectSignal("value_changed", (void*)velocity, changeOption );
     395          velocity->connectSignal("value_changed", (void*)velocity, emitterChange );
    475396          emitterBox->fill(velocity);
    476397         
     
    478399          Slider* SpreadAngle = new Slider("SpreadAngle", 0, M_PI);
    479400          SpreadAngle->setExactness(3);
    480           SpreadAngle->connectSignal("value_changed", (void*)SpreadAngle, changeOption );
     401          SpreadAngle->connectSignal("value_changed", (void*)SpreadAngle, emitterChange );
    481402          emitterBox->fill(SpreadAngle);
    482403
     
    486407          EmitterType->addItem("EMITTER_PLANE");
    487408          EmitterType->addItem("EMITTER_CUBE");
    488           EmitterType->connectSignal("changed", (void*)EmitterType, changeOption );       
     409          EmitterType->connectSignal("changed", (void*)EmitterType, emitterChange );     
    489410          emitterBox->fill(EmitterType);
    490411
     
    492413          Slider* EmitterSize = new Slider("EmitterSize", 0, 100);
    493414          EmitterSize->setExactness(1);
    494           EmitterSize->connectSignal("value_changed", (void*)EmitterSize, changeOption );
     415          EmitterSize->connectSignal("value_changed", (void*)EmitterSize, emitterChange );
    495416          emitterBox->fill(EmitterSize);
    496417        }
     
    506427          Slider* StartRadius = new Slider("StartRadius", 0, 10);
    507428          StartRadius->setExactness(3);
    508           StartRadius->connectSignal("value_changed", (void*)StartRadius, changeOption );
     429          StartRadius->connectSignal("value_changed", (void*)StartRadius, systemChange );
    509430          systemBox->fill(StartRadius);
    510431
     
    512433          Slider* EndRadius = new Slider("EndRadius", 0, 10);
    513434          EndRadius->setExactness(3);
    514           EndRadius->connectSignal("value_changed", (void*)EndRadius, changeOption );
     435          EndRadius->connectSignal("value_changed", (void*)EndRadius, systemChange );
    515436          systemBox->fill(EndRadius);
    516437
     
    518439          Slider* LifeSpan = new Slider("LifeSpan", 0, 10);
    519440          LifeSpan->setExactness(3);
    520           LifeSpan->connectSignal("value_changed", (void*)LifeSpan, changeOption );
     441          LifeSpan->connectSignal("value_changed", (void*)LifeSpan, systemChange );
    521442          systemBox->fill(LifeSpan);
    522443         
     
    524445          Slider* ConserveFactor = new Slider("ConserveFactor", 0, 1);
    525446          ConserveFactor->setExactness(3);
    526           ConserveFactor->connectSignal("value_changed", (void*)ConserveFactor, changeOption );
     447          ConserveFactor->connectSignal("value_changed", (void*)ConserveFactor, systemChange );
    527448          systemBox->fill(ConserveFactor);
    528449
     
    532453          ParticleType->addItem("PARTICLE_SPARK");
    533454          ParticleType->addItem("PARTICLE_SPRITE");
    534           ParticleType->connectSignal("changed", (void*)ParticleType, changeOption );     
     455          ParticleType->connectSignal("changed", (void*)ParticleType, systemChange );     
    535456          systemBox->fill(ParticleType);
    536457         
     
    538459          Slider* InheritSpeed = new Slider("InheritSpeed", 0, 1);
    539460          InheritSpeed->setExactness(3);
    540           InheritSpeed->connectSignal("value_changed", (void*)InheritSpeed, changeOption );
     461          InheritSpeed->connectSignal("value_changed", (void*)InheritSpeed, systemChange );
    541462          systemBox->fill(InheritSpeed);
    542463
     
    549470      Button* quitButton = new Button("quit");
    550471     
     472      quitButton->connectSignal("clicked", NULL, quitGui);
     473      //  Window::mainWindow->connectSignal("remove", this, GuiExec::quitGui);
     474      Window::mainWindow->connectSignal("destroy", NULL, quitGui);
    551475     
    552476      windowBox->fill(quitButton);
     
    556480  Window::mainWindow->showall();
    557481  Window::mainWindow->setSize(300, 500);
     482}
     483
     484void* Framework::mainloopGui(void* tmp)
     485{
    558486  mainloopGUI();
    559487}
     
    565493  verbose = 3;
    566494  pthread_t guiThread;
     495  pthread_t openglThread;
     496  pthread_attr_t attr;
     497  int status;
     498 
     499  pthread_mutex_init(&mutex, NULL);
     500 
     501  /* Create threads to perform the dotproduct  */
     502  pthread_attr_init(&attr);
     503  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
     504
     505
     506
    567507
    568508  Framework* framework = Framework::getInstance();
    569509
    570   pthread_create(&guiThread, NULL, Framework::initGui,(void*) argv);
     510  framework->initGui((void*)argv);
     511  pthread_create(&guiThread, &attr, Framework::mainloopGui ,(void*) argv);
    571512  //  framework->initGui(argv);
    572513
    573   framework->mainLoop();
     514  pthread_create(&openglThread, &attr, Framework::mainLoop, NULL);
     515
     516  pthread_attr_destroy(&attr);
     517
     518  pthread_join( guiThread, (void **)&status);   
     519  pthread_join( openglThread, (void **)&status);       
    574520
    575521  delete framework;
  • orxonox/branches/physics/src/subprojects/particles/framework.h

    r4317 r4330  
    3333
    3434  void initModule();
    35   bool mainLoop();
     35  static void* mainLoop(void* tmp);
    3636  bool draw(float dt);
    3737  float tick();
    3838  bool keyHandler();
    3939
    40   static void* initGui(void* argv);
     40  void* initGui(void* argv);
     41  static void* mainloopGui(void* tmp);
    4142
    4243  void printHelp(void) const;
    4344};
     45
    4446#endif /* _FRAMEWORK_H */
Note: See TracChangeset for help on using the changeset viewer.