[Orxonox-commit 3724] r8404 - code/branches/spaceboundaries/src/orxonox/worldentities
kmaurus at orxonox.net
kmaurus at orxonox.net
Thu May 5 16:14:07 CEST 2011
Author: kmaurus
Date: 2011-05-05 16:14:07 +0200 (Thu, 05 May 2011)
New Revision: 8404
Modified:
code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
Log:
some adaptations and improvements
Modified: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc 2011-05-05 14:02:40 UTC (rev 8403)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc 2011-05-05 14:14:07 UTC (rev 8404)
@@ -49,6 +49,7 @@
this->setWarnDistance(2000);
this->setShowDistance(2500);
this->setHealthDecrease(1);
+ this->setReaction(0);
RegisterObject(SpaceBoundaries);
@@ -61,11 +62,6 @@
{
delete this->centerRadar_;
- if(this->boundary_ != NULL)
- {
- delete this->boundary_;
- }
-
this->pawnsIn_.clear();
for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++)
@@ -105,7 +101,7 @@
if( current == this->billboards_.end() )
{
Billboard *tmp = new Billboard(this);
- setBillboardOptions( tmp );
+ this->setBillboardOptions( tmp );
tmp->setPosition(position);
billboardAdministration tmp2 = { true, tmp };
this->billboards_.push_back( tmp2 );
@@ -170,6 +166,15 @@
{
return this->healthDecrease_;
}
+
+ void SpaceBoundaries::setReaction(int mode)
+ {
+ this->reaction_ = mode;
+ }
+ int SpaceBoundaries::getReaction()
+ {
+ return this->reaction_;
+ }
void SpaceBoundaries::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
@@ -178,52 +183,53 @@
XMLPortParam(SpaceBoundaries, "maxDistance", setMaxDistance, getMaxDistance, xmlelement, mode);
XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode);
XMLPortParam(SpaceBoundaries, "healthDecrease", setHealthDecrease, getHealthDecrease, xmlelement, mode);
+ XMLPortParam(SpaceBoundaries, "reactionMode", setReaction, getReaction, xmlelement, mode);
}
void SpaceBoundaries::tick(float dt)
{
+ this->checkWhoIsIn();
this->removeAllBillboards();
COUT(0) << "Groesse der Liste: " << (int) pawnsIn_.size() << std::endl;
float distance;
bool humanItem;
- for( std::list<Pawn*>::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ )
+ for( std::list<WeakPtr<Pawn> >::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ )
{
- Pawn* currentPawn = *current;
- distance = this->computeDistance(currentPawn);
- humanItem = this->isHumanPlayer(currentPawn);
- COUT(0) << "Distanz:" << distance << std::endl; // message for debugging
- if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
+ Pawn* currentPawn = current->get();
+ if( currentPawn && currentPawn->getNode() )
{
- COUT(0) << "You are leaving the area" << std::endl; // message for debugging
- if(humanItem)
+ distance = this->computeDistance(currentPawn);
+ humanItem = this->isHumanPlayer(currentPawn);
+ COUT(0) << "Distanz:" << distance << std::endl; // message for debugging
+ if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
{
- COUT(0) << "humanItem ist true" << std::endl;
- this->displayWarning("Attention! You are leaving the area!");
- } else {
-
+ COUT(0) << "You are near by the boundaries!" << std::endl; // message for debugging
+ if(humanItem)
+ {
+ COUT(0) << "humanItem ist true" << std::endl;
+ this->displayWarning("Attention! You are near by the boundaries!");
+ }
}
- }
- if( (this->maxDistance_ - distance) < this->showDistance_)
- {
- // Zeige Grenze an!
- this->displayBoundaries(currentPawn);
- }
- if(distance > this->maxDistance_)
- {
- if(humanItem)
+ if( (this->maxDistance_ - distance) < this->showDistance_ )
{
- COUT(0) << "Health should be decreasing!" << std::endl;
- this->displayWarning("You are out of the area now!");
- currentPawn->removeHealth( (distance - maxDistance_) * this->healthDecrease_);
- } else {
-
+ this->displayBoundaries(currentPawn); // Zeige Grenze an!
}
-
- this->bounceBack(currentPawn);
+ if(distance > this->maxDistance_ && (this->reaction_ == 1) )
+ {
+ if( humanItem )
+ {
+ COUT(0) << "Health should be decreasing!" << std::endl;
+ this->displayWarning("You are out of the area now!");
+ }
+ currentPawn->removeHealth( (distance - this->maxDistance_) * this->healthDecrease_);
+ }
+ if( (this->reaction_ == 0) && (distance + 100 > this->maxDistance_)) // Annahme: Ein Pawn kann von einem Tick bis zum nächsten nicht mehr als 100 Distanzeinheiten zurücklegen.
+ {
+ this->conditionalBounceBack(currentPawn, distance, dt);
+ }
}
}
- this->checkWhoIsIn();
}
float SpaceBoundaries::computeDistance(WorldEntity *item)
@@ -253,15 +259,18 @@
this->positionBillboard(boundaryPosition);
}
- void SpaceBoundaries::bounceBack(Pawn *item)
+ void SpaceBoundaries::conditionalBounceBack(Pawn *item, float currentDistance, float dt)
{
Vector3 normal = item->getPosition() - this->getPosition();
- if( item->getVelocity().dotProduct(normal) > 0 ) // Greife nur ein, falls sich das Pawn nach Aussen bewegt.
+ normal.normalise();
+ Vector3 velocity = item->getVelocity();
+ float normalSpeed = item->getVelocity().dotProduct(normal);
+
+ /* Checke, ob das Pawn innerhalb des nächsten Ticks, das erlaubte Gebiet verlassen würde.
+ Falls ja: Spicke es zurück. */
+ if( currentDistance + normalSpeed * dt > this->maxDistance_ )
{
float dampingFactor = 0.5;
-
- normal.normalise();
- Vector3 velocity = item->getVelocity();
velocity = velocity.reflect(normal);
Vector3 acceleration = item->getAcceleration();
acceleration = acceleration.reflect(normal);
Modified: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h 2011-05-05 14:02:40 UTC (rev 8403)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h 2011-05-05 14:14:07 UTC (rev 8404)
@@ -26,25 +26,21 @@
*
*/
- /* TODO: - Sobald Bots im Spiel sind, stürzt das Programm relativ bald ab!!!
+ /* TODO: - Textmessages und Billboards sollen teils nur bei einem humanPlayer angezeigt werden, nicht bei allen (vgl. Netzwerk-Spiel mit mehreren humanPlayers)
+ beachte hierzu folgende statische Funktion: 'static unsigned int Host::getPlayerID()'
+ (file:///home/kmaurus/orxonox/spaceBoundaries/build/doc/api/html/classorxonox_1_1_host.html#9c1e3b39e3b42e467dfbf42902911ce2)
+
+ - Kommentieren (Betrachte als Beispiel/Vorbild 'libraries/core/WeakPtr.h')
+
+ - Wiki-SpaceBoundaries-Eintrag aktualisieren
*/
-
-
- /* REALISIERUNGSIDEEN:
-
- Mehrere Instanzen:
- Im Konstruktor schauen, wer innerhalb der eigenen Grenzen ist und diese in eine Liste geben, die in jeder tick-Funktion
- durchgearbeitet wird.
- Moeglichkeit bereitstellen, ein Pawn durch ein Portal einer anderen Instanz von SpaceBoundaries zuzuweisen.
- Schauen, wie es zu handhaben ist, wenn ein neuer Spieler oder Bot nachtraeglich ins Spiel kommt.
-
- */
#ifndef _SpaceBoundaries_H__
#define _SpaceBoundaries_H__
-/* Einige, spezifische include-Statements */
+
#include "core/CoreIncludes.h"
+#include "core/WeakPtr.h"
#include "tools/interfaces/Tickable.h"
#include "interfaces/RadarViewable.h"
#include "worldentities/StaticEntity.h"
@@ -55,21 +51,24 @@
#include <map>
#include <vector>
+namespace orxonox
+{
+
/**
- at brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area.
+ at brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area (until now this area is a ball).
Five attributes can/should be defined in the XML-File:
- - 'position' : absolute position of the SpaceBoundaries class. 'warnDistance' and 'maxDistance' refer to this 'position'.
- 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to
inform the player that he'll soon be leaving the allowed area.
- 'maxDistance' : defines the area, where a pawn is allowed to be (radius of a ball).
- 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown.
- - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area.
- Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung)
+ - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area (unnecessary if 'reactionMode' == 0).
+ Recommended values: 0.1 (slow health decrease) to 5 (very fast health decrease)
+ - 'reactionMode' : Integer-Value. Defines what effect appears if a space ship has crossed the boundaries.
+ 0: Reflect the space ship (default).
+ 1: Decrease Health of the space ship after having left the allowed area.
*/
-namespace orxonox
-{
class _OrxonoxExport SpaceBoundaries : public StaticEntity, public Tickable
{
public:
@@ -78,9 +77,9 @@
void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.
- void positionBillboard(const Vector3 position);
+ void positionBillboard(const Vector3 position); //!< Display a Billboard at the position 'position'.
void setBillboardOptions(Billboard *billy);
- void removeAllBillboards();
+ void removeAllBillboards(); //!< Hide all all elements of '*billboard_' and set their attribute 'usedYet' to 0.
void setMaxDistance(float r);
float getMaxDistance();
@@ -93,6 +92,9 @@
void setHealthDecrease(float amount);
float getHealthDecrease();
+
+ void setReaction(int mode);
+ int getReaction();
void XMLPort(Element& xmlelement, XMLPort::Mode mode);
@@ -101,10 +103,11 @@
private:
struct billboardAdministration{ bool usedYet; Billboard* billy; };
- std::list<Pawn*> pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle.
+ std::list<WeakPtr<Pawn> > pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle.
std::vector<billboardAdministration> billboards_;
+ int reaction_; //!< Werte: 0, 1. 0: Reflektion an Boundaries (Standard). 1: Health-Abzug-Modus.
float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'.
float warnDistance_; //!< Entfernung von 'this->getPosition()', ab der eine Warnung angezeigt wird, dass man bald das zulaessige Areal verlaesst.
float showDistance_; //!< Definiert, wann die Grenzen visualisiert werden sollen.
@@ -112,14 +115,12 @@
float healthDecrease_; //!< Mass fuer die Anzahl Health-Points, die nach ueberschreiten der Entfernung 'maxDistance_' von 'this->getPosition()' abgezogen werden.
//!< Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung)
- Billboard *boundary_;
-
RadarViewable* centerRadar_; //!< Repraesentation von SpaceBoundaries auf dem Radar.
float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'this->getPosition()' bezogen.
void displayWarning(const std::string warnText);
void displayBoundaries(Pawn *item);
- void bounceBack(Pawn *item);
+ void conditionalBounceBack(Pawn *item, float currentDistance, float dt);
bool isHumanPlayer(Pawn *item);
};
More information about the Orxonox-commit
mailing list