Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11581 for code


Ignore:
Timestamp:
Nov 20, 2017, 4:21:26 PM (7 years ago)
Author:
remartin
Message:

Doesn-t freeze any more. Asteroids and the pickup seem to collide with things they shouldn-t.

Location:
code/branches/AsteroidMining_HS17
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw

    r11561 r11581  
    9797    <AsteroidMinable size=15 position="0,-500,0" />
    9898    <AsteroidMinable size=5 position="100,-500,100" />
     99    <AsteroidMinable size=50 position="500,-500, 500" />
    99100
    100101   
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc

    r11561 r11581  
    4444
    4545KNACKPUNKTE:
    46 o Collision Shape-Problem (Funktioniert nur, wenn im Konstruktor)
     46o Collision Shape-Problem (Funktioniert nur, wenn im Konstruktor) -> Mit Factory-Methode oder so basteln.
    4747o Maximale Hitpunkte = 200?
    4848
    4949o Neue Asteroiden generieren -> Absturz
    50 ---> Weil Elterndings zerstoert wird?
    51 ---> Nicht moeglich, zur Laufzeit zu generieren?
    52 
    53 o Pickups: setMaxSpawned funktioniert nicht
     50--> Kollidiert sofort mit irgendetwas, death() wird mehrfach aufgerufen.
     51--> Funktioniert der Test in den hit()-Methoden?
     52--> Welcher Aufruf loest die death()-Methode auf?
     53
    5454
    5555
     
    7272o Dynamische Definition -> putStuff-Methode, Werte noch nicht durchgesickert.
    7373o Error-Nachricht: Einfach Argumente leer lassen.
     74o Pickups: setMaxSpawned funktioniert nicht -> Bastelloesung: Auf 2 statt eins setzen, erstes wird wohl direkt zerstoert.
    7475*/
    7576
     
    123124        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
    124125        this->bAlive_ = true;
     126
    125127        this->bVulnerable_ = true;
     128        this->enableCollisionCallback();
    126129
    127130        // Default Values
    128         this->generateSmaller = true;
     131        this->generateSmaller = true;
     132        //this->setHealth(50);
    129133        this->size = 10; // customSize
    130134        this->context = context;
    131135        this->initialised = false;
    132136        //this->roll = rand()*5; //etwas Drehung. richtige Variable
    133 
     137//this = new AsteroidMinable()
    134138
    135139
     
    145149        // Old from Pawn
    146150        this->registerVariables();
     151
     152        orxout() << "AsteroidMining:: Konstruktor passiert!" << endl;
    147153
    148154    }
     
    171177
    172178
    173         this->initialised=true;
     179        this->initialised=true;
     180
     181        orxout() << "AsteroidMining:: Initialisierung abgeschlosssssen." << endl;
     182
    174183    }
    175184
     
    232241    {
    233242
    234         // Stuff that can be harvested.
    235         PickupSpawner* thingy = new PickupSpawner(this->context);
    236 
    237         // OFFEN: more precise size relation in custom resource pickup.
    238         char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
    239         if(this->size <= 5){
    240             strcat(tname, "smallmunitionpickup");
    241         }else if(this->size <= 20){
    242             strcat(tname, "mediummunitionpickup");
    243         }else{
    244             strcat(tname, "hugemunitionpickup");
    245         }
    246         //orxout() << "Zeugsname:" << tname << endl;
    247         thingy->setPickupTemplateName(tname);
    248         thingy->setPosition(this->getPosition());
    249         //thingy->setMaxSpawnedItems(1); // Somehow doesn-t work yet.
    250         thingy->setRespawnTime(0.1f);// instantly
    251        
    252         orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;
    253 
    254 
    255 
     243        orxout() << "AsteroidMinable::Death() aufgerufen." << endl;
     244
     245        // OFFEN: Sauber kapputten
     246        // just copied other stuff:
     247        // this->setHealth(1);
     248        this->bAlive_ = false;
     249        this->destroyLater();
     250        this->setDestroyWhenPlayerLeft(false);
     251        // pawn -> addExplosionPart
     252        // this->goWithStyle();
     253
     254
     255        // // Stuff that can be harvested.
     256        // PickupSpawner* thingy = new PickupSpawner(this->context);
     257
     258        // // OFFEN: more precise size relation in custom resource pickup.
     259        // char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
     260        // if(this->size <= 5){
     261        //     strcat(tname, "smallmunitionpickup");
     262        // }else if(this->size <= 20){
     263        //     strcat(tname, "mediummunitionpickup");
     264        // }else{
     265        //     strcat(tname, "hugemunitionpickup");
     266        // }
     267        // thingy->setPickupTemplateName(tname);
     268        // thingy->setPosition(this->getPosition());
     269        // thingy->setMaxSpawnedItems(2); // The first somehow gets destroyed immediately.
     270        // thingy->setRespawnTime(0.5f);
     271
     272        // orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;
    256273
    257274
     
    265282
    266283
    267         // OFFEN: Sauber kapputten
    268         // just copied other stuff:
    269         this->setHealth(1);
    270         this->bAlive_ = false;
    271         this->destroyLater();
    272         this->setDestroyWhenPlayerLeft(false);
    273 
    274 
    275         // pawn -> addExplosionPart
    276         // this->goWithStyle();
     284
     285
     286
    277287        orxout() << "Wieder retour in death() geschafft. " << endl;
    278288
     
    291301void AsteroidMinable::spawnChildren(){
    292302   
     303    if (this->size <=1){return;} // Absicherung trivialer Fall
     304
     305
     306
    293307    // Spawn smaller Children
    294308    int massRem = this->size-1; //some mass is lost
     
    300314
    301315
    302     orxout() << "Number of Children: " << num << endl;
    303 
    304 
    305     for(int fisch=num; fisch>=1; fisch--){
     316    //orxout() << "Number of Children: " << num << endl;
     317
     318
     319    for(int fisch=num; fisch>=1; --fisch){
    306320        // to distribute remaining mass
     321
     322        //orxout() << "AsteroidMining::spawnChildren(): Fisch-Variable: " << fisch << endl;
     323
    307324        if(fisch==1){
    308325            extra = massRem;
     
    313330        }
    314331
    315         orxout() << "Mass chosen: " << extra+1 << endl;
    316 
    317         orxout() << "AsteroidMining::spawnChildren(): Inside for-loop." << endl;
     332        //orxout() << "Mass chosen: " << extra+1 << endl;
     333
     334        //orxout() << "AsteroidMining::spawnChildren(): Inside for-loop." << endl;
    318335
    319336        //Spawn this child  Game crashes!
     
    323340        // Position zu spaet gesetzt? Tick nicht atomar -> falsche Groesse evtl?
    324341
    325             if(child == nullptr){
    326                 orxout(internal_error, context::pickups) << "Weird, can't create new AsteroidMinable." << endl;
    327             }
    328 
    329             child->setSize(extra + 1);
     342        if(child == nullptr){
     343            orxout(internal_error, context::pickups) << "Weird, can't create new AsteroidMinable." << endl;
     344        }
     345
     346        child->setSize(extra + 1);
    330347               
    331348            //OFFEN:Kollision der Kinder verhindern
     
    333350            //Typ position:rand()*Vektoriwas?
    334351            //pawn->getWorldPosition() + Vector3(30,0,-30);
    335             child->setPosition(this->getPosition() + Vector3(num*5, 0, 0));
    336 
    337 
    338         orxout() << "Done: Creating new Asteroid" << endl;
     352        child->setPosition(this->getPosition() + Vector3(num*5, 0, 0));
     353        //child->setPosition(Vector3(0,0,0));
     354
     355        //orxout() << "Done: Creating new Asteroid" << endl;
    339356
    340357        // }
     
    355372
    356373
     374    void AsteroidMinable::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage){
     375
     376        orxout() << "AsteroidMining::Hit(Variante 1) Dings aufgerufen. " << endl;
     377
     378        // Kollision mit anderem Asteroid oder Pickup (OFFEN: evtl. Spawner oder irgendwas?) verhindern. In diesem Fall einfach nichts tun.
     379        // Wird staending aufgerufen -> Rechenleistung?
     380        if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;}
     381        this->damage(damage, healthdamage, shielddamage, originator, cs);
     382        this->setVelocity(this->getVelocity() + force);
     383
     384
     385
     386        // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator))// && (!this->getController() || !this->getController()->getGodMode()) )
     387        // {
     388        //     this->damage(damage, healthdamage, shielddamage, originator, cs);
     389        //     this->setVelocity(this->getVelocity() + force);
     390        // }
     391    }
     392
     393    void AsteroidMinable::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage){
     394
     395        orxout() << "AsteroidMining::Hit(Variante 2) Dings aufgerufen. " << endl;
     396        // Kollision mit anderem Asteroid oder Pickup (OFFEN: evtl. Spawner oder irgendwas?) verhindern. In diesem Fall einfach nichts tun.
     397        // Wird staending aufgerufen -> Rechenleistung?
     398        if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;}
     399
     400
     401
     402        this->damage(damage, healthdamage, shielddamage, originator, cs);
     403
     404
     405
     406
     407        // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator))// && (!this->getController() || !this->getController()->getGodMode()) )
     408        // {
     409        //     this->damage(damage, healthdamage, shielddamage, originator, cs);
     410
     411        //     //if ( this->getController() )
     412        //     //    this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
     413        // }
     414    }
     415
     416
     417
     418
     419            // Cast-Test aus movableEntity():
     420            // Pawn* victim = orxonox_cast<Pawn*>(otherObject);
     421            // if (victim)
     422
     423
     424
     425
     426//Pawn:
     427    // void Pawn::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
     428    // {
     429    //     if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
     430    //     {
     431    //         this->damage(damage, healthdamage, shielddamage, originator, cs);
     432    //         this->setVelocity(this->getVelocity() + force);
     433    //     }
     434    // }
     435
     436    // void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
     437    // {
     438    //     if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
     439    //     {
     440    //         this->damage(damage, healthdamage, shielddamage, originator, cs);
     441
     442    //         if ( this->getController() )
     443    //             this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
     444    //     }
     445    // }
     446
     447
     448
     449
     450            // /**
     451            // @brief
     452            //     Virtual function that gets called when this object collides with another.
     453            // @param otherObject
     454            //     The object this one has collided into.
     455            // @param ownCollisionShape
     456            //     The collision shape of the other object
     457            // @param contactPoint
     458            //     Contact point provided by Bullet. Holds more information and can me modified. See return value.
     459            // @return
     460            //     Returning false means that no modification to the contactPoint has been made. Return true otherwise!
     461            // @note
     462            //     Condition is that enableCollisionCallback() was called.
     463            // */
     464            // virtual inline bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
     465            //     { return false; } /* With false, Bullet assumes no modification to the collision objects. */
     466
     467            // //! Enables the collidesAgainst(.) function. The object doesn't respond to collision otherwise!
     468            // inline void enableCollisionCallback()
     469            //     { this->bCollisionCallbackActive_ = true; this->collisionCallbackActivityChanged(); }
     470
     471
     472
     473            // //! Disables the collidesAgainst(.) function. @see enableCollisionCallback()
     474            // inline void disableCollisionCallback()
     475            //     { this->bCollisionCallbackActive_ = false; this->collisionCallbackActivityChanged(); }
     476
     477
     478            // //! Tells whether there could be a collision callback via collidesAgainst(.)
     479            // inline bool isCollisionCallbackActive() const
     480            //     { return this->bCollisionCallbackActive_; }
     481
     482            // //! Enables or disables collision response (default is of course on)
     483            // inline void setCollisionResponse(bool value)
     484            //     { this->bCollisionResponseActive_ = value; this->collisionResponseActivityChanged(); }
     485
     486
     487            // //! Tells whether there could be a collision response
     488            // inline bool hasCollisionResponse()
     489            //     { return this->bCollisionResponseActive_; }
    357490
    358491
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h

    r11551 r11581  
    5656            virtual void tick(float dt) override;
    5757
     58            // Overwrite to prevet 'self-collision' of generated stuff
     59            virtual void hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
     60            virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
     61
     62
     63
    5864            virtual void setSize(float f);
    5965            virtual float getSize();
     66
     67
     68
    6069
    6170
Note: See TracChangeset for help on using the changeset viewer.