Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5447 in orxonox.OLD for trunk/src/world_entities


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/world_entities/weapons
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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.