[Orxonox-commit 6960] r11581 - in code/branches/AsteroidMining_HS17: data/levels src/modules/asteroidmining
remartin at orxonox.net
remartin at orxonox.net
Mon Nov 20 16:21:27 CET 2017
Author: remartin
Date: 2017-11-20 16:21:26 +0100 (Mon, 20 Nov 2017)
New Revision: 11581
Modified:
code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h
Log:
Doesn-t freeze any more. Asteroids and the pickup seem to collide with things they shouldn-t.
Modified: code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw
===================================================================
--- code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw 2017-11-20 15:19:40 UTC (rev 11580)
+++ code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw 2017-11-20 15:21:26 UTC (rev 11581)
@@ -96,6 +96,7 @@
<AsteroidMinable size=15 position="0,-500,0" />
<AsteroidMinable size=5 position="100,-500,100" />
+ <AsteroidMinable size=50 position="500,-500, 500" />
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc 2017-11-20 15:19:40 UTC (rev 11580)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc 2017-11-20 15:21:26 UTC (rev 11581)
@@ -43,14 +43,14 @@
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
KNACKPUNKTE:
-o Collision Shape-Problem (Funktioniert nur, wenn im Konstruktor)
+o Collision Shape-Problem (Funktioniert nur, wenn im Konstruktor) -> Mit Factory-Methode oder so basteln.
o Maximale Hitpunkte = 200?
o Neue Asteroiden generieren -> Absturz
----> Weil Elterndings zerstoert wird?
----> Nicht moeglich, zur Laufzeit zu generieren?
+--> Kollidiert sofort mit irgendetwas, death() wird mehrfach aufgerufen.
+--> Funktioniert der Test in den hit()-Methoden?
+--> Welcher Aufruf loest die death()-Methode auf?
-o Pickups: setMaxSpawned funktioniert nicht
OFFEN:
@@ -71,6 +71,7 @@
o Dummes fisch-- statt fisch++ , Endlosschleife!
o Dynamische Definition -> putStuff-Methode, Werte noch nicht durchgesickert.
o Error-Nachricht: Einfach Argumente leer lassen.
+o Pickups: setMaxSpawned funktioniert nicht -> Bastelloesung: Auf 2 statt eins setzen, erstes wird wohl direkt zerstoert.
*/
@@ -122,18 +123,21 @@
this->setRadarObjectShape(RadarViewable::Shape::Dot);
this->setCollisionType(WorldEntity::CollisionType::Dynamic);
this->bAlive_ = true;
+
this->bVulnerable_ = true;
+ this->enableCollisionCallback();
// Default Values
- this->generateSmaller = true;
+ this->generateSmaller = true;
+ //this->setHealth(50);
this->size = 10; // customSize
this->context = context;
this->initialised = false;
//this->roll = rand()*5; //etwas Drehung. richtige Variable
+//this = new AsteroidMinable()
-
// DELETE if other stuff works! (wrong size etc.)
SphereCollisionShape* cs = new SphereCollisionShape(this->context);
cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien
@@ -145,6 +149,8 @@
// Old from Pawn
this->registerVariables();
+ orxout() << "AsteroidMining:: Konstruktor passiert!" << endl;
+
}
AsteroidMinable::~AsteroidMinable()
@@ -170,7 +176,10 @@
this->attachCollisionShape(cs);
- this->initialised=true;
+ this->initialised=true;
+
+ orxout() << "AsteroidMining:: Initialisierung abgeschlosssssen." << endl;
+
}
void AsteroidMinable::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -231,30 +240,38 @@
void AsteroidMinable::death() //ueberschreiben
{
- // Stuff that can be harvested.
- PickupSpawner* thingy = new PickupSpawner(this->context);
+ orxout() << "AsteroidMinable::Death() aufgerufen." << endl;
- // OFFEN: more precise size relation in custom resource pickup.
- char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
- if(this->size <= 5){
- strcat(tname, "smallmunitionpickup");
- }else if(this->size <= 20){
- strcat(tname, "mediummunitionpickup");
- }else{
- strcat(tname, "hugemunitionpickup");
- }
- //orxout() << "Zeugsname:" << tname << endl;
- thingy->setPickupTemplateName(tname);
- thingy->setPosition(this->getPosition());
- //thingy->setMaxSpawnedItems(1); // Somehow doesn-t work yet.
- thingy->setRespawnTime(0.1f);// instantly
-
- orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;
+ // OFFEN: Sauber kapputten
+ // just copied other stuff:
+ // this->setHealth(1);
+ this->bAlive_ = false;
+ this->destroyLater();
+ this->setDestroyWhenPlayerLeft(false);
+ // pawn -> addExplosionPart
+ // this->goWithStyle();
+ // // Stuff that can be harvested.
+ // PickupSpawner* thingy = new PickupSpawner(this->context);
+ // // OFFEN: more precise size relation in custom resource pickup.
+ // char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
+ // if(this->size <= 5){
+ // strcat(tname, "smallmunitionpickup");
+ // }else if(this->size <= 20){
+ // strcat(tname, "mediummunitionpickup");
+ // }else{
+ // strcat(tname, "hugemunitionpickup");
+ // }
+ // thingy->setPickupTemplateName(tname);
+ // thingy->setPosition(this->getPosition());
+ // thingy->setMaxSpawnedItems(2); // The first somehow gets destroyed immediately.
+ // thingy->setRespawnTime(0.5f);
+ // orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;
+
// Smaller Parts = 'Children'
if(this->generateSmaller){
this->spawnChildren();
@@ -264,16 +281,9 @@
- // OFFEN: Sauber kapputten
- // just copied other stuff:
- this->setHealth(1);
- this->bAlive_ = false;
- this->destroyLater();
- this->setDestroyWhenPlayerLeft(false);
- // pawn -> addExplosionPart
- // this->goWithStyle();
+
orxout() << "Wieder retour in death() geschafft. " << endl;
// if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
@@ -290,6 +300,10 @@
void AsteroidMinable::spawnChildren(){
+ if (this->size <=1){return;} // Absicherung trivialer Fall
+
+
+
// Spawn smaller Children
int massRem = this->size-1; //some mass is lost
int num = round((massRem-1)*(double)rand() / (double)RAND_MAX)+1; // random number of children, at least one // Tweak towards bigger junks?
@@ -299,11 +313,14 @@
int extra = 0;
- orxout() << "Number of Children: " << num << endl;
+ //orxout() << "Number of Children: " << num << endl;
- for(int fisch=num; fisch>=1; fisch--){
+ for(int fisch=num; fisch>=1; --fisch){
// to distribute remaining mass
+
+ //orxout() << "AsteroidMining::spawnChildren(): Fisch-Variable: " << fisch << endl;
+
if(fisch==1){
extra = massRem;
}else{
@@ -312,9 +329,9 @@
}
- orxout() << "Mass chosen: " << extra+1 << endl;
+ //orxout() << "Mass chosen: " << extra+1 << endl;
- orxout() << "AsteroidMining::spawnChildren(): Inside for-loop." << endl;
+ //orxout() << "AsteroidMining::spawnChildren(): Inside for-loop." << endl;
//Spawn this child Game crashes!
AsteroidMinable* child = new AsteroidMinable(this->context);
@@ -322,21 +339,21 @@
// Position zu spaet gesetzt? Tick nicht atomar -> falsche Groesse evtl?
- if(child == nullptr){
- orxout(internal_error, context::pickups) << "Weird, can't create new AsteroidMinable." << endl;
- }
+ if(child == nullptr){
+ orxout(internal_error, context::pickups) << "Weird, can't create new AsteroidMinable." << endl;
+ }
- child->setSize(extra + 1);
+ child->setSize(extra + 1);
//OFFEN:Kollision der Kinder verhindern
//Relativ zu Elternteil automatisch?
//Typ position:rand()*Vektoriwas?
//pawn->getWorldPosition() + Vector3(30,0,-30);
- child->setPosition(this->getPosition() + Vector3(num*5, 0, 0));
+ child->setPosition(this->getPosition() + Vector3(num*5, 0, 0));
+ //child->setPosition(Vector3(0,0,0));
+ //orxout() << "Done: Creating new Asteroid" << endl;
- orxout() << "Done: Creating new Asteroid" << endl;
-
// }
@@ -354,8 +371,124 @@
}
+ void AsteroidMinable::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage){
+ orxout() << "AsteroidMining::Hit(Variante 1) Dings aufgerufen. " << endl;
+ // Kollision mit anderem Asteroid oder Pickup (OFFEN: evtl. Spawner oder irgendwas?) verhindern. In diesem Fall einfach nichts tun.
+ // Wird staending aufgerufen -> Rechenleistung?
+ if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;}
+ this->damage(damage, healthdamage, shielddamage, originator, cs);
+ this->setVelocity(this->getVelocity() + force);
+
+
+
+ // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator))// && (!this->getController() || !this->getController()->getGodMode()) )
+ // {
+ // this->damage(damage, healthdamage, shielddamage, originator, cs);
+ // this->setVelocity(this->getVelocity() + force);
+ // }
+ }
+
+ void AsteroidMinable::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage){
+
+ orxout() << "AsteroidMining::Hit(Variante 2) Dings aufgerufen. " << endl;
+ // Kollision mit anderem Asteroid oder Pickup (OFFEN: evtl. Spawner oder irgendwas?) verhindern. In diesem Fall einfach nichts tun.
+ // Wird staending aufgerufen -> Rechenleistung?
+ if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;}
+
+
+
+ this->damage(damage, healthdamage, shielddamage, originator, cs);
+
+
+
+
+ // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator))// && (!this->getController() || !this->getController()->getGodMode()) )
+ // {
+ // this->damage(damage, healthdamage, shielddamage, originator, cs);
+
+ // //if ( this->getController() )
+ // // this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
+ // }
+ }
+
+
+
+
+ // Cast-Test aus movableEntity():
+ // Pawn* victim = orxonox_cast<Pawn*>(otherObject);
+ // if (victim)
+
+
+
+
+//Pawn:
+ // void Pawn::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
+ // {
+ // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
+ // {
+ // this->damage(damage, healthdamage, shielddamage, originator, cs);
+ // this->setVelocity(this->getVelocity() + force);
+ // }
+ // }
+
+ // void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
+ // {
+ // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
+ // {
+ // this->damage(damage, healthdamage, shielddamage, originator, cs);
+
+ // if ( this->getController() )
+ // this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
+ // }
+ // }
+
+
+
+
+ // /**
+ // @brief
+ // Virtual function that gets called when this object collides with another.
+ // @param otherObject
+ // The object this one has collided into.
+ // @param ownCollisionShape
+ // The collision shape of the other object
+ // @param contactPoint
+ // Contact point provided by Bullet. Holds more information and can me modified. See return value.
+ // @return
+ // Returning false means that no modification to the contactPoint has been made. Return true otherwise!
+ // @note
+ // Condition is that enableCollisionCallback() was called.
+ // */
+ // virtual inline bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
+ // { return false; } /* With false, Bullet assumes no modification to the collision objects. */
+
+ // //! Enables the collidesAgainst(.) function. The object doesn't respond to collision otherwise!
+ // inline void enableCollisionCallback()
+ // { this->bCollisionCallbackActive_ = true; this->collisionCallbackActivityChanged(); }
+
+
+
+ // //! Disables the collidesAgainst(.) function. @see enableCollisionCallback()
+ // inline void disableCollisionCallback()
+ // { this->bCollisionCallbackActive_ = false; this->collisionCallbackActivityChanged(); }
+
+
+ // //! Tells whether there could be a collision callback via collidesAgainst(.)
+ // inline bool isCollisionCallbackActive() const
+ // { return this->bCollisionCallbackActive_; }
+
+ // //! Enables or disables collision response (default is of course on)
+ // inline void setCollisionResponse(bool value)
+ // { this->bCollisionResponseActive_ = value; this->collisionResponseActivityChanged(); }
+
+
+ // //! Tells whether there could be a collision response
+ // inline bool hasCollisionResponse()
+ // { return this->bCollisionResponseActive_; }
+
+
}
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h 2017-11-20 15:19:40 UTC (rev 11580)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h 2017-11-20 15:21:26 UTC (rev 11581)
@@ -55,10 +55,19 @@
virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) override;
virtual void tick(float dt) override;
+ // Overwrite to prevet 'self-collision' of generated stuff
+ virtual void hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
+ virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
+
+
+
virtual void setSize(float f);
virtual float getSize();
+
+
+
protected:
// Da neue Argumente reinstellen
//float asteroidVersion; // Bodenstrich-Konvention?,
More information about the Orxonox-commit
mailing list