Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5447 in orxonox.OLD


Ignore:
Timestamp:
Oct 29, 2005, 1:14:24 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Explosions on Collision (—HACK—)
also made the FastFactory faster, not turning through the GarbageCollector, as it is not necessary. FastFactory also implements a Static Memeber subscriptor-Macro now
last but not least: new Functions in The ParticleEngine, and some revisited

Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/lang/base_object.cc

    r5439 r5447  
    5252  //  delete []this->className;
    5353  if (this->objectName)
    54     delete[] this->objectName;}
     54    delete[] this->objectName;
     55}
    5556
    5657/**
  • trunk/src/lib/particles/particle_engine.cc

    r5445 r5447  
    1818#include "particle_engine.h"
    1919
    20 #include "particle_system.h"
    21 #include "particle_emitter.h"
     20#include "class_list.h"
    2221
    2322#include "list.h"
     
    120119}
    121120
    122 #include "class_list.h"
    123121/**
    124122* @brief Connects a ParticleSystem to a ParticleSystem thus emitting Particles.
     
    216214}
    217215
     216
     217/**
     218 *  removes a Connection between an Emitter and a System
     219 * @param connection the connection to remove
     220 *
     221 * \see bool ParticleEngine::breakConnection(ParticleEmitter* emitter, ParticleSystem* system)
     222 */
     223bool ParticleEngine::breakConnection(ParticleConnection* connection)
     224{
     225  this->connectionList->remove(connection);
     226  return true;
     227}
     228
    218229/**
    219230 *  removes a Connection between an Emitter and a System
     
    221232 * @param system The system of the connection to remove
    222233 * @returns true, if the connection was broken, false if the conntection was not found
    223 
    224    only if both system and emitter are in the connection the Connection will be broken
     234 *
     235 * only if both system and emitter are in the connection the Connection will be broken
    225236*/
    226237bool ParticleEngine::breakConnection(ParticleEmitter* emitter, ParticleSystem* system)
     
    245256/**
    246257 *  removes a Connection between an Emitter and a System
    247  * @param connection the connection to remove
    248 
    249    \see bool ParticleEngine::breakConnection(ParticleEmitter* emitter, ParticleSystem* system)
    250 */
    251 bool ParticleEngine::breakConnection(ParticleConnection* connection)
    252 {
    253   this->connectionList->remove(connection);
    254   return true;
    255 }
    256 
     258 * @param emitter The emitter of the connections to remove
     259 * @returns the count of connections that were broken, 0 if no conntection was not found
     260 */
     261unsigned int ParticleEngine::breakConnections(ParticleEmitter* emitter)
     262{
     263  unsigned int retVal = 0;
     264  // look, if we have already added this connection
     265  tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
     266  ParticleConnection* tmpConnection = tmpConIt->firstElement();
     267  while(tmpConnection)
     268  {
     269    if (tmpConnection->emitter == emitter)
     270    {
     271      this->breakConnection(tmpConnection);
     272      retVal++;
     273    }
     274    tmpConnection = tmpConIt->nextElement();
     275  }
     276  delete tmpConIt;
     277  return retVal;
     278}
     279
     280
     281/**
     282 *  removes a Connection between an Emitter and a System
     283 * @param system The system of the connections to remove
     284 * @returns the count of connections that were broken, 0 if no conntection was not found
     285 */
     286unsigned int ParticleEngine::breakConnections(ParticleSystem* system)
     287{
     288  unsigned int retVal = 0;
     289  // look, if we have already added this connection
     290  tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
     291  ParticleConnection* tmpConnection = tmpConIt->firstElement();
     292  while(tmpConnection)
     293  {
     294    if (tmpConnection->system == system)
     295    {
     296      this->breakConnection(tmpConnection);
     297      retVal++;
     298    }
     299    tmpConnection = tmpConIt->nextElement();
     300  }
     301  delete tmpConIt;
     302  return retVal;
     303}
    257304
    258305/**
     
    406453
    407454}
     455
  • trunk/src/lib/particles/particle_engine.h

    r5445 r5447  
    5050  bool removeSystem(ParticleSystem* system);
    5151  bool removeEmitter(ParticleEmitter* emitter);
     52  bool breakConnection(ParticleConnection* connection);
    5253  bool breakConnection(ParticleEmitter* emitter, ParticleSystem* system);
    53   bool breakConnection(ParticleConnection* connection);
     54  unsigned int breakConnections(ParticleEmitter* emitter);
     55  unsigned int breakConnections(ParticleSystem* system);
    5456
    5557   ParticleSystem* getSystemByNumber(unsigned int number) const;
  • trunk/src/story_entities/world.cc

    r5429 r5447  
    129129
    130130  // delete all the initialized Engines.
     131  FastFactory::flushAll(true);
    131132  delete LightManager::getInstance();
    132133  delete TrackManager::getInstance();
     
    138139  SoundEngine::getInstance()->flushAllBuffers();
    139140  SoundEngine::getInstance()->flushAllSources();
    140   FastFactory::flushAll(true);
    141141
    142142
  • trunk/src/util/fast_factory.h

    r5357 r5447  
    2929 */
    3030#define CREATE_FAST_FACTORY(CLASS_NAME, CLASS_ID) \
    31   tFastFactory<CLASS_NAME>* global_##CLASS_NAME##_FastFactory = tFastFactory<CLASS_NAME>::getFastFactory(CLASS_ID, #CLASS_NAME)
     31  FastFactory* global_##CLASS_NAME##_FastFactory = tFastFactory<CLASS_NAME>::getFastFactory(CLASS_ID, #CLASS_NAME)
     32/**
     33 * Creates a FastFactory for a Class' static function named ClassName::fastFactory.
     34 * @param CLASS_NAME the name of the Class to create the fast-factory for.
     35 * @param CLASS_ID the ID of the class to create the fast-factory for @see "class_id.h"
     36 *
     37 * notice, that the Class to be called, must implement:
     38 * static FastFactory*         fastFactory;
     39 */
     40#define CREATE_FAST_FACTORY_STATIC(CLASS_NAME, CLASS_ID) \
     41  FastFactory* CLASS_NAME::fastFactory = tFastFactory<CLASS_NAME>::getFastFactory(CLASS_ID, #CLASS_NAME)
    3242
    3343//! A struct, that holds Lists of Objects of a certain type.
  • trunk/src/world_entities/weapons/projectile.h

    r5443 r5447  
    2222
    2323#include "world_entity.h"
    24 #include "vector.h"
     24
     25class FastFactory;
    2526
    2627class Projectile : public WorldEntity
  • trunk/src/world_entities/weapons/test_bullet.cc

    r5446 r5447  
    1818#include "test_bullet.h"
    1919
    20 #include "model.h"
    21 #include "vector.h"
    22 #include "garbage_collector.h"
    2320#include "fast_factory.h"
    2421
     
    3431using namespace std;
    3532
    36 CREATE_FAST_FACTORY(TestBullet, CL_TEST_BULLET);
     33CREATE_FAST_FACTORY_STATIC(TestBullet, CL_TEST_BULLET);
    3734
    3835/**
     
    5148  this->lifeSpan = 5;
    5249
    53   this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 0.01);
     50  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
    5451  this->emitter->setParent(this);
    55   this->emitter->setEmissionRate(20);
    56 
    5752  this->emitter->setSpread(M_2_PI);
    5853}
     
    6762
    6863  /* this is normaly done by World.cc by deleting the ParticleEngine */
     64  if (TestBullet::trailParticles != NULL && ClassList::getList(CL_TEST_BULLET)->getSize() <= 1)
     65  {
     66    if (ClassList::exists(TestBullet::trailParticles, CL_PARTICLE_SYSTEM))
     67      delete TestBullet::trailParticles;
     68    TestBullet::trailParticles = NULL;
     69  }
    6970  if (TestBullet::explosionParticles != NULL && ClassList::getList(CL_TEST_BULLET)->getSize() <= 1)
    7071  {
     
    7677}
    7778
     79ParticleSystem* TestBullet::trailParticles = NULL;
    7880ParticleSystem* TestBullet::explosionParticles = NULL;
    79 
    8081
    8182void TestBullet::activate()
    8283{
    8384  State::getWorldEntityList()->add(this);
     85  if (unlikely(TestBullet::trailParticles == NULL))
     86  {
     87    TestBullet::trailParticles = new ParticleSystem(1000, PARTICLE_SPRITE);
     88    TestBullet::trailParticles->setName("TestBulletTrailParticles");
     89    TestBullet::trailParticles->setLifeSpan(.5, .3);
     90    TestBullet::trailParticles->setRadius(0.0, .5);
     91    TestBullet::trailParticles->setRadius(0.5, 2.0);
     92    TestBullet::trailParticles->setRadius(1.0, 5.0);
     93    TestBullet::trailParticles->setColor(0.0, 1,0,0,.7);
     94    TestBullet::trailParticles->setColor(0.5, .8,.8,0,.5);
     95    TestBullet::trailParticles->setColor(1.0, .7,.7,.7,.0);
     96  }
    8497  if (unlikely(TestBullet::explosionParticles == NULL))
    8598  {
    86     ClassList::debug(3, CL_PARTICLE_SYSTEM);
    8799    TestBullet::explosionParticles = new ParticleSystem(1000, PARTICLE_SPRITE);
    88     TestBullet::explosionParticles->setName("TestBulletTrailParticles");
     100    TestBullet::explosionParticles->setName("TestBulletExplosionParticles");
    89101    TestBullet::explosionParticles->setLifeSpan(.5, .3);
    90     TestBullet::explosionParticles->setRadius(0.0, .5);
    91     TestBullet::explosionParticles->setRadius(0.5, 2.0);
    92     TestBullet::explosionParticles->setRadius(1.0, 5.0);
    93     TestBullet::explosionParticles->setColor(0.0, 1,0,0,.7);
     102    TestBullet::explosionParticles->setRadius(0.0, 10);
     103    TestBullet::explosionParticles->setRadius(.5, 20.0);
     104    TestBullet::explosionParticles->setRadius(1.0, 3.0);
     105    TestBullet::explosionParticles->setColor(0.0, 0,1,0,.7);
    94106    TestBullet::explosionParticles->setColor(0.5, .8,.8,0,.5);
    95     TestBullet::explosionParticles->setColor(1.0, .7,.7,.7,.0);
     107    TestBullet::explosionParticles->setColor(1.0, 1,1,1,.0);
    96108  }
    97109
    98   ParticleEngine::getInstance()->addConnection(this->emitter, TestBullet::explosionParticles);
     110  ParticleEngine::getInstance()->addConnection(this->emitter, TestBullet::trailParticles);
     111
     112  this->emitter->setEmissionRate(20.0);
     113  this->emitter->setEmissionVelocity(10.0);
    99114}
    100115
     
    102117void TestBullet::deactivate()
    103118{
    104   ParticleEngine::getInstance()->breakConnection(this->emitter, TestBullet::explosionParticles);
     119  ParticleEngine::getInstance()->breakConnections(this->emitter);
     120  this->lifeCycle = 0.0;
    105121
    106   GarbageCollector::getInstance()->collect(this);
    107   this->lifeCycle = 0.0;
     122//  GarbageCollector::getInstance()->collect(this);
     123  State::getWorldEntityList()->remove(this);
     124  TestBullet::fastFactory->kill(this);
    108125}
    109126
     
    111128void TestBullet::collidesWith(WorldEntity* entity, const Vector& location)
    112129{
    113 
     130  if (this->hitEntity != entity && entity->isA(CL_NPC))
     131    this->destroy();
     132  this->hitEntity = entity;
    114133}
    115134
     
    125144
    126145  this->lifeCycle += time/this->lifeSpan;
    127   if( this->lifeCycle >= 1)
     146  if( this->lifeCycle >= 1.0)
    128147    {
    129148      PRINTF(5)("FINALIZE==========================\n");
    130149      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
    131150      PRINTF(5)("FINALIZE===========================\n");
    132 //      this->finalize();
     151
    133152      this->deactivate();
    134153    }
     
    140159void TestBullet::destroy ()
    141160{
    142   this->deactivate();
     161  printf("DESTROY TestBullet\n");
     162  this->lifeCycle = .95;
     163  ParticleEngine::getInstance()->breakConnection(this->emitter, TestBullet::trailParticles);
     164  ParticleEngine::getInstance()->addConnection(this->emitter, TestBullet::explosionParticles);
    143165
    144 
    145   GarbageCollector::getInstance()->collect(this);
     166  this->emitter->setEmissionRate(1000.0);
     167  this->emitter->setEmissionVelocity(50.0);
     168//  this->deactivate();
    146169
    147170}
  • trunk/src/world_entities/weapons/test_bullet.h

    r5443 r5447  
    1313class ParticleSystem;
    1414class ParticleEmitter;
     15class FastFactory;
    1516
    1617class TestBullet : public Projectile
     
    3334
    3435  private:
    35     static ParticleSystem*     explosionParticles;
    36     ParticleEmitter*           emitter;
     36    static FastFactory*               fastFactory;
     37    static ParticleSystem*            trailParticles;
     38    static ParticleSystem*            explosionParticles;
     39
     40    ParticleEmitter*                  emitter;
     41
     42
     43    WorldEntity* hitEntity; // FIXME TEMPORARY
    3744
    3845};
Note: See TracChangeset for help on using the changeset viewer.