Changeset 1596 for code/branches/core3
- Timestamp:
- Jun 12, 2008, 10:53:51 PM (16 years ago)
- Location:
- code/branches/core3/src
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core3/src/core/ConfigValueContainer.cc
r1505 r1596 59 59 this->sectionname_ = identifier->getName(); 60 60 this->varname_ = varname; 61 this->callback_ = 0; 61 62 62 63 this->value_ = defvalue; … … 98 99 this->update(); 99 100 } 101 } 102 103 /** 104 @brief Destructor: Deletes the callback object if necessary. 105 */ 106 ConfigValueContainer::~ConfigValueContainer() 107 { 108 if (this->callback_) 109 delete this->callback_; 100 110 } 101 111 … … 335 345 @param description The description 336 346 */ 337 voidConfigValueContainer::description(const std::string& description)347 ConfigValueContainer& ConfigValueContainer::description(const std::string& description) 338 348 { 339 349 if (!this->bAddedDescription_) … … 343 353 this->bAddedDescription_ = true; 344 354 } 355 return (*this); 345 356 } 346 357 -
code/branches/core3/src/core/ConfigValueContainer.h
r1505 r1596 55 55 namespace orxonox 56 56 { 57 class ConfigValueCallbackBase 58 { 59 public: 60 virtual void call(void* object) = 0; 61 inline virtual ~ConfigValueCallbackBase() {} 62 }; 63 64 template <class T> 65 class ConfigValueCallback: public ConfigValueCallbackBase 66 { 67 public: 68 inline ConfigValueCallback(void (T::*function) (void)) : function_(function) {} 69 inline virtual ~ConfigValueCallback() {} 70 inline virtual void call(void* object) 71 { (((T*)object)->*this->function_)(); } 72 73 private: 74 void (T::*function_) (void); 75 }; 76 77 57 78 //! The ConfigValuecontainer contains all needed informations about a configurable variable. 58 79 /** … … 76 97 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue); 77 98 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue); 78 79 /** @brief Returns the configured value. @param value This is only needed to determine the right type. @return The value */ 80 template <typename T> 81 inline ConfigValueContainer& getValue(T* value) 82 { this->value_.getValue(value); return *this; } 83 template <typename T> 84 inline ConfigValueContainer& getValue(std::vector<T>* value) 85 { 86 value->clear(); 87 for (unsigned int i = 0; i < this->valueVector_.size(); i++) 88 value->push_back(this->valueVector_[i]); 99 ~ConfigValueContainer(); 100 101 /** @brief Returns the configured value. @param value A pointer to the variable to store the value. @return The ConfigValueContainer */ 102 template <typename T, class C> 103 ConfigValueContainer& getValue(T* value, C* object) 104 { 105 if (this->callback_ && object) 106 { 107 T temp = *value; 108 this->value_.getValue(value); 109 if ((*value) != temp) 110 this->callback_->call(object); 111 } 112 else 113 { 114 this->value_.getValue(value); 115 } 116 return *this; 117 } 118 119 /** @brief Returns the configured vector. @param value A pointer to the vector to store the values. @return The ConfigValueContainer */ 120 template <typename T, class C> 121 ConfigValueContainer& getValue(std::vector<T>* value, C* object) 122 { 123 if (this->callback_ && object) 124 { 125 std::vector<T> temp = *value; 126 127 value->clear(); 128 for (unsigned int i = 0; i < this->valueVector_.size(); ++i) 129 value->push_back(this->valueVector_[i]); 130 131 if (value->size() != temp.size()) 132 { 133 this->callback_->call(object); 134 } 135 else 136 { 137 for (unsigned int i = 0; i < value->size(); ++i) 138 { 139 if ((*value)[i] != temp[i]) 140 { 141 this->callback_->call(object); 142 break; 143 } 144 } 145 } 146 } 147 else 148 { 149 value->clear(); 150 for (unsigned int i = 0; i < this->valueVector_.size(); ++i) 151 value->push_back(this->valueVector_[i]); 152 } 89 153 return *this; 90 154 } … … 104 168 { return this->valueVector_.size(); } 105 169 106 voiddescription(const std::string& description);170 ConfigValueContainer& description(const std::string& description); 107 171 const std::string& getDescription() const; 172 173 template <class T> 174 inline ConfigValueContainer& callback(void (T::*function) (void)) 175 { 176 if (!this->callback_) 177 this->callback_ = new ConfigValueCallback<T>(function); 178 return (*this); 179 } 108 180 109 181 bool set(const MultiTypeMath& input); … … 142 214 bool bAddedDescription_; //!< True if a description was added 143 215 LanguageEntryLabel description_; //!< The description 216 ConfigValueCallbackBase* callback_; //!< A callback function to call after getValue if the value changed 144 217 }; 145 218 } -
code/branches/core3/src/core/ConfigValueIncludes.h
r1543 r1596 48 48 */ 49 49 #define SetConfigValue(varname, defvalue) \ 50 orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \ 50 static orxonox::Identifier* identifier##varname = this->getIdentifier(); \ 51 orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \ 51 52 if (!container##varname) \ 52 53 { \ 53 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, varname = defvalue); \54 this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \54 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, varname = defvalue); \ 55 identifier##varname->addConfigValueContainer(#varname, container##varname); \ 55 56 } \ 56 container##varname->getValue(&varname )57 container##varname->getValue(&varname, this) 57 58 58 59 /** … … 63 64 */ 64 65 #define SetConfigValueGeneric(classname, varname, defvalue) \ 65 orxonox::ConfigValueContainer* container##varname = ClassIdentifier<classname>::getIdentifier()->getConfigValueContainer(#varname); \ 66 static orxonox::Identifier* identifier##varname = ClassIdentifier<classname>::getIdentifier(); \ 67 orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \ 66 68 if (!container##varname) \ 67 69 { \ 68 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, ClassIdentifier<classname>::getIdentifier(), #varname, varname = defvalue); \69 ClassIdentifier<classname>::getIdentifier()->addConfigValueContainer(#varname, container##varname); \70 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, varname = defvalue); \ 71 identifier##varname->addConfigValueContainer(#varname, container##varname); \ 70 72 } \ 71 container##varname->getValue(&varname )73 container##varname->getValue(&varname, this) 72 74 73 75 /** … … 77 79 */ 78 80 #define SetConfigValueVector(varname, defvalue) \ 79 orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \ 81 static orxonox::Identifier* identifier##varname = this->getIdentifier(); \ 82 orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \ 80 83 if (!container##varname) \ 81 84 { \ … … 83 86 for (unsigned int i = 0; i < defvalue.size(); i++) \ 84 87 temp.push_back(MultiTypeMath(defvalue[i])); \ 85 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, temp); \88 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, temp); \ 86 89 container##varname->setVectorType(varname); \ 87 this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \90 identifier##varname->addConfigValueContainer(#varname, container##varname); \ 88 91 } \ 89 container##varname->getValue(&varname )92 container##varname->getValue(&varname, this) 90 93 91 94 /** … … 98 101 { \ 99 102 container##varname##reset->reset(); \ 100 container##varname##reset->getValue(&varname ); \103 container##varname##reset->getValue(&varname, this); \ 101 104 } \ 102 105 else \ … … 115 118 { \ 116 119 container##varname##modify##modifier->modifier(__VA_ARGS__); \ 117 container##varname##modify##modifier->getValue(&varname ); \120 container##varname##modify##modifier->getValue(&varname, this); \ 118 121 } \ 119 122 else \ -
code/branches/core3/src/core/Core.cc
r1586 r1596 96 96 void Core::setConfigValues() 97 97 { 98 SetConfigValue(softDebugLevelConsole_, 3).description("The maximal level of debug output shown in the console"); 99 SetConfigValue(softDebugLevelLogfile_, 3).description("The maximal level of debug output shown in the logfile"); 100 SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell"); 101 98 SetConfigValue(softDebugLevelConsole_, 3).description("The maximal level of debug output shown in the console").callback(&Core::debugLevelChanged); 99 SetConfigValue(softDebugLevelLogfile_, 3).description("The maximal level of debug output shown in the logfile").callback(&Core::debugLevelChanged); 100 SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(&Core::debugLevelChanged); 101 SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(&Core::languageChanged); 102 } 103 104 /** 105 @brief Callback function if the debug level has changed. 106 */ 107 void Core::debugLevelChanged() 108 { 102 109 // softDebugLevel_ is the maximum of the 3 variables 103 110 this->softDebugLevel_ = this->softDebugLevelConsole_; … … 111 118 OutputHandler::setSoftDebugLevel(OutputHandler::LD_Logfile, this->softDebugLevelLogfile_); 112 119 OutputHandler::setSoftDebugLevel(OutputHandler::LD_Shell, this->softDebugLevelShell_); 113 114 std::string temp = this->language_; 115 SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text");116 117 if (this->language_ != temp)118 {119 // Read the translation file after the language was configured120 Language::getLanguage().readTranslatedLanguageFile();121 }120 } 121 122 /** 123 @brief Callback function if the language has changed. 124 */ 125 void Core::languageChanged() 126 { 127 // Read the translation file after the language was configured 128 Language::getLanguage().readTranslatedLanguageFile(); 122 129 } 123 130 -
code/branches/core3/src/core/Core.h
r1586 r1596 52 52 static bool& isCreatingCoreSettings(); 53 53 void setConfigValues(); 54 void debugLevelChanged(); 55 void languageChanged(); 54 56 55 57 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); -
code/branches/core3/src/core/Identifier.cc
r1592 r1596 39 39 #include "ConsoleCommand.h" 40 40 #include "CommandExecutor.h" 41 #include "Iterator.h"42 #include "ObjectList.h"43 #include "OrxonoxClass.h"44 41 #include "XMLPort.h" 45 42 … … 198 195 199 196 /** 200 @brief Updates the config-values of all existing objects of this class by calling their setConfigValues() function.201 */202 void Identifier::updateConfigValues() const203 {204 for (BaseIterator it = this->getObjects()->begin(); it; ++it)205 (*it)->setConfigValues();206 }207 208 /**209 197 @brief Tells the container to which Identifier it belongs to. 210 198 */ -
code/branches/core3/src/core/Identifier.h
r1592 r1596 61 61 62 62 #include "MetaObjectList.h" 63 #include " ObjectListBase.h"63 #include "Iterator.h" 64 64 #include "util/Debug.h" 65 65 #include "util/String.h" … … 112 112 void setName(const std::string& name); 113 113 114 v oid updateConfigValues() const;114 virtual void updateConfigValues(bool updateChildren = true) const = 0; 115 115 116 116 /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */ … … 301 301 static bool isFirstCall(); 302 302 void addObject(T* object); 303 304 void updateConfigValues(bool updateChildren = true) const; 303 305 304 306 XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname); … … 417 419 COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl; 418 420 object->getMetaList().add(this->objects_, this->objects_->add(new ObjectListElement<T>(object))); 421 } 422 423 /** 424 @brief Updates the config-values of all existing objects of this class by calling their setConfigValues() function. 425 */ 426 template <class T> 427 void ClassIdentifier<T>::updateConfigValues(bool updateChildren) const 428 { 429 if (!this->hasConfigValues()) 430 return; 431 432 for (ObjectListIterator<T> it = ObjectList<T>::begin(); it; ++it) 433 it->setConfigValues(); 434 435 if (updateChildren) 436 for (std::set<const Identifier*>::const_iterator it = this->getChildrenBegin(); it != this->getChildrenEnd(); ++it) 437 (*it)->updateConfigValues(false); 419 438 } 420 439 -
code/branches/core3/src/core/ObjectListIterator.h
r1591 r1596 36 36 37 37 Usage: 38 for ( Iterator<myClass> it = ObjectList<myClass>::begin(); it != ObjectList<myClass>::end(); ++it)38 for (ObjectListIterator<myClass> it = ObjectList<myClass>::begin(); it != ObjectList<myClass>::end(); ++it) 39 39 { 40 40 it->someFunction(...); -
code/branches/core3/src/core/OrxonoxClass.cc
r1574 r1596 44 44 this->parents_ = 0; 45 45 this->metaList_ = new MetaObjectList(); 46 47 this->setConfigValues();48 46 } 49 47 -
code/branches/core3/src/core/Shell.cc
r1594 r1596 90 90 void Shell::setConfigValues() 91 91 { 92 SetConfigValue(maxHistoryLength_, 100) ;93 SetConfigValue(historyOffset_, 0) ;92 SetConfigValue(maxHistoryLength_, 100).callback(&Shell::commandHistoryLengthChanged); 93 SetConfigValue(historyOffset_, 0).callback(&Shell::commandHistoryOffsetChanged); 94 94 SetConfigValueVector(commandHistory_, std::vector<std::string>()); 95 95 } 96 97 void Shell::commandHistoryOffsetChanged() 98 { 96 99 if (this->historyOffset_ >= this->maxHistoryLength_) 97 100 this->historyOffset_ = 0; 101 } 102 103 void Shell::commandHistoryLengthChanged() 104 { 105 this->commandHistoryOffsetChanged(); 98 106 99 107 while (this->commandHistory_.size() > this->maxHistoryLength_) -
code/branches/core3/src/core/Shell.h
r1586 r1596 67 67 68 68 virtual void setConfigValues(); 69 void commandHistoryOffsetChanged(); 70 void commandHistoryLengthChanged(); 69 71 70 72 void registerListener(ShellListener* listener); -
code/branches/core3/src/core/input/InputManager.cc
r1586 r1596 340 340 getIdentifier()->addConfigValueContainer("CoeffPos", cont); 341 341 } 342 cont->getValue(&coeffPos );342 cont->getValue(&coeffPos, this); 343 343 344 344 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); … … 348 348 getIdentifier()->addConfigValueContainer("CoeffNeg", cont); 349 349 } 350 cont->getValue(&coeffNeg );350 cont->getValue(&coeffNeg, this); 351 351 352 352 cont = getIdentifier()->getConfigValueContainer("Zero"); … … 356 356 getIdentifier()->addConfigValueContainer("Zero", cont); 357 357 } 358 cont->getValue(&zero );358 cont->getValue(&zero, this); 359 359 360 360 // copy values to our own variables -
code/branches/core3/src/core/input/KeyBinder.cc
r1586 r1596 234 234 void KeyBinder::setConfigValues() 235 235 { 236 SetConfigValue Generic(KeyBinder,analogThreshold_, 0.05f) .description("Threshold for analog axes until which the state is 0.");237 SetConfigValue Generic(KeyBinder,mouseSensitivity_, 1.0f) .description("Mouse sensitivity.");238 SetConfigValue Generic(KeyBinder,bDeriveMouseInput_, false).description("Whether or not to derive moues movement for the absolute value.");239 SetConfigValue Generic(KeyBinder,derivePeriod_, 0.05f).description("Accuracy of the mouse input deriver. The higher the more precise, but laggier.");240 SetConfigValue Generic(KeyBinder,mouseSensitivityDerived_, 1.0f).description("Mouse sensitivity if mouse input is derived.");241 SetConfigValue Generic(KeyBinder,bClipMouse_, true).description("Whether or not to clip absolute value of mouse in non derive mode.");236 SetConfigValue(/*Generic(KeyBinder, */analogThreshold_, 0.05f) .description("Threshold for analog axes until which the state is 0."); 237 SetConfigValue(/*Generic(KeyBinder, */mouseSensitivity_, 1.0f) .description("Mouse sensitivity."); 238 SetConfigValue(/*Generic(KeyBinder, */bDeriveMouseInput_, false).description("Whether or not to derive moues movement for the absolute value."); 239 SetConfigValue(/*Generic(KeyBinder, */derivePeriod_, 0.05f).description("Accuracy of the mouse input deriver. The higher the more precise, but laggier."); 240 SetConfigValue(/*Generic(KeyBinder, */mouseSensitivityDerived_, 1.0f).description("Mouse sensitivity if mouse input is derived."); 241 SetConfigValue(/*Generic(KeyBinder, */bClipMouse_, true).description("Whether or not to clip absolute value of mouse in non derive mode."); 242 242 243 243 float oldThresh = buttonThreshold_; 244 SetConfigValue Generic(KeyBinder,buttonThreshold_, 0.80f).description("Threshold for analog axes until which the button is not pressed.");244 SetConfigValue(/*Generic(KeyBinder, */buttonThreshold_, 0.80f).description("Threshold for analog axes until which the button is not pressed."); 245 245 if (oldThresh != buttonThreshold_) 246 246 for (unsigned int i = 0; i < nHalfAxes_s; i++) … … 272 272 } 273 273 std::string old = button.bindingString_; 274 cont->getValue(&button.bindingString_ );274 cont->getValue(&button.bindingString_, this); 275 275 276 276 // keybinder stuff -
code/branches/core3/src/orxonox/GraphicsEngine.cc
r1591 r1596 97 97 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 98 98 99 unsigned int old = this->detailLevelParticle_; 100 SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high"); 101 102 if (this->detailLevelParticle_ != old) 103 for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it) 104 it->detailLevelChanged(this->detailLevelParticle_); 99 SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high").callback(&GraphicsEngine::detailLevelParticleChanged); 100 } 101 102 void GraphicsEngine::detailLevelParticleChanged() 103 { 104 for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it) 105 it->detailLevelChanged(this->detailLevelParticle_); 105 106 } 106 107 -
code/branches/core3/src/orxonox/GraphicsEngine.h
r1563 r1596 56 56 public: 57 57 void setConfigValues(); 58 void detailLevelParticleChanged(); 58 59 bool setup(); 59 60 bool declareRessourceLocations(); -
code/branches/core3/src/orxonox/Settings.cc
r1535 r1596 68 68 void Settings::setConfigValues() 69 69 { 70 SetConfigValue(dataPath_, "../../Media/").description("Relative path to the game data."); 70 SetConfigValue(dataPath_, "../../Media/").description("Relative path to the game data.").callback(&Settings::dataPathChanged); 71 } 72 73 /** 74 @brief Callback function if the datapath has changed. 75 */ 76 void Settings::dataPathChanged() 77 { 71 78 if (dataPath_ != "" && dataPath_[dataPath_.size() - 1] != '/') 72 79 { -
code/branches/core3/src/orxonox/Settings.h
r1535 r1596 48 48 public: 49 49 void setConfigValues(); 50 void dataPathChanged(); 50 51 51 52 static const std::string& getDataPath(); -
code/branches/core3/src/orxonox/objects/ParticleProjectile.cc
r1563 r1596 32 32 #include "SpaceShip.h" 33 33 #include "core/CoreIncludes.h" 34 34 #include "core/ConfigValueIncludes.h" 35 35 namespace orxonox 36 36 { … … 52 52 this->particles_ = 0; 53 53 } 54 55 this->setConfigValues(); 54 56 } 55 57 … … 60 62 } 61 63 64 void ParticleProjectile::setConfigValues() 65 { 66 SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback(&ParticleProjectile::speedChanged); 67 } 68 69 void ParticleProjectile::speedChanged() 70 { 71 Projectile::speed_s = this->speed_; 72 if (this->owner_) 73 this->setVelocity(this->owner_->getInitialDir() * this->speed_); 74 } 75 62 76 void ParticleProjectile::changedVisibility() 63 77 { -
code/branches/core3/src/orxonox/objects/ParticleProjectile.h
r1558 r1596 44 44 virtual ~ParticleProjectile(); 45 45 virtual void changedVisibility(); 46 void setConfigValues(); 47 void speedChanged(); 46 48 47 49 private: -
code/branches/core3/src/orxonox/objects/Projectile.cc
r1592 r1596 44 44 namespace orxonox 45 45 { 46 float Projectile::speed_ = 5000;46 float Projectile::speed_s = 5000; 47 47 48 48 Projectile::Projectile(SpaceShip* owner) : owner_(owner) … … 74 74 SetConfigValue(damage_, 15.0).description("The damage caused by the projectile"); 75 75 SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive"); 76 SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second"); 76 SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback(&Projectile::speedChanged); 77 } 77 78 79 void Projectile::speedChanged() 80 { 81 Projectile::speed_s = this->speed_; 78 82 if (this->owner_) 79 83 this->setVelocity(this->owner_->getInitialDir() * this->speed_); -
code/branches/core3/src/orxonox/objects/Projectile.h
r1552 r1596 42 42 virtual ~Projectile(); 43 43 void setConfigValues(); 44 void speedChanged(); 44 45 void destroyObject(); 45 46 virtual void tick(float dt); 46 47 47 48 static float getSpeed() 48 { return Projectile::speed_ ; }49 { return Projectile::speed_s; } 49 50 50 51 protected: … … 55 56 std::string explosionTemplateName_; 56 57 std::string smokeTemplateName_; 57 static float speed_; 58 protected: 59 static float speed_s; 60 float speed_; 61 private: 58 62 float lifetime_; 59 63 float damage_; -
code/branches/core3/src/orxonox/objects/RotatingProjectile.cc
r1584 r1596 65 65 void RotatingProjectile::setConfigValues() 66 66 { 67 SetConfigValue(colour_, ColourValue(1.0, 0.0, 0.0)); 67 SetConfigValue(colour_, ColourValue(1.0, 0.0, 0.0)).callback(&RotatingProjectile::colourChanged); 68 } 68 69 70 void RotatingProjectile::colourChanged() 71 { 69 72 if (this->isInitialized()) 70 73 { -
code/branches/core3/src/orxonox/objects/RotatingProjectile.h
r1558 r1596 14 14 virtual ~RotatingProjectile(); 15 15 void setConfigValues(); 16 void colourChanged(); 16 17 virtual void tick(float dt); 17 18 virtual void changedVisibility();
Note: See TracChangeset
for help on using the changeset viewer.