ForceFeedback: add saveConfiguration method to ForceFeedback manager and update readConfiguration
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6422 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: f32172f1794775b89b8ca5c277dc6c3044bc7db8 Former-commit-id: 529de546a9d8855ec2e2a3426ee548a197d9893d
This commit is contained in:
parent
6c7c291047
commit
1a8897cbbc
3 changed files with 86 additions and 19 deletions
|
@ -745,6 +745,10 @@ void HumanDriver::new_race(int index, tCarElt* car, tSituation *s)
|
|||
}//KEYBOARD
|
||||
|
||||
}//for i
|
||||
|
||||
|
||||
//initialize the force feedback
|
||||
forceFeedback.readConfiguration(car->_carName);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1167,10 +1171,12 @@ static void common_drive(const int index, tCarElt* car, tSituation *s)
|
|||
|
||||
car->_steerCmd = leftSteer + rightSteer;
|
||||
|
||||
|
||||
/*
|
||||
//this is done on driver initilization
|
||||
if(!forceFeedback.initialized){
|
||||
forceFeedback.readConfiguration(car);
|
||||
forceFeedback.readConfiguration(car->_carName);
|
||||
}
|
||||
*/
|
||||
force = forceFeedback.updateForce(car, s);
|
||||
|
||||
/* Force feedback hack
|
||||
|
|
|
@ -45,11 +45,12 @@ ForceFeedbackManager::ForceFeedbackManager(){
|
|||
ForceFeedbackManager::~ForceFeedbackManager(){
|
||||
|
||||
}
|
||||
void ForceFeedbackManager::readConfiguration(tCarElt* car){
|
||||
void ForceFeedbackManager::readConfiguration(std::string carName){
|
||||
//use the user specified configuration for the specified car
|
||||
//or use the user specified global configuration
|
||||
//or use the default configuration for the car
|
||||
//or use the default global configuration
|
||||
this->carName = carName;
|
||||
|
||||
std::string configFileUrl = GfLocalDir();
|
||||
configFileUrl.append("/drivers/human/preferences.xml");
|
||||
|
@ -57,10 +58,11 @@ void ForceFeedbackManager::readConfiguration(tCarElt* car){
|
|||
std::string effectsSectionPathDefault = "forceFeedback/default/effectsConfig";
|
||||
|
||||
std::string effectsSectionPathSpecific = "forceFeedback/";
|
||||
effectsSectionPathSpecific.append(car->_carName);
|
||||
//effectsSectionPathSpecific.append(car->_carName);
|
||||
effectsSectionPathSpecific.append(carName);
|
||||
effectsSectionPathSpecific.append("/effectsConfig");
|
||||
|
||||
//remove the previous stored configuration
|
||||
//remove the previous stored configuration (if any)
|
||||
this->effectsConfig.clear();
|
||||
|
||||
//add some needed default configuration
|
||||
|
@ -112,6 +114,71 @@ void ForceFeedbackManager::readConfigurationFromFileSection(std::string configFi
|
|||
} while (GfParmListSeekNext(paramHandle, effectsSectionPath.c_str()) == 0);
|
||||
}
|
||||
|
||||
}
|
||||
void ForceFeedbackManager::saveConfiguration(){
|
||||
|
||||
std::string configFileUrl = GfLocalDir();
|
||||
configFileUrl.append("/drivers/human/preferences.xml");
|
||||
|
||||
std::string effectsSectionPathSpecific = "/forceFeedback/";
|
||||
effectsSectionPathSpecific.append(carName);
|
||||
|
||||
//open the file
|
||||
void *paramHandle = GfParmReadFile(configFileUrl.c_str(), GFPARM_RMODE_STD);
|
||||
|
||||
|
||||
//delette the current car specific section if it exist
|
||||
if(GfParmExistsSection(paramHandle, effectsSectionPathSpecific.c_str())){
|
||||
//delette the section
|
||||
//GfParmListRemoveElt (void *handle, const char *path, const char *key)
|
||||
GfParmListClean(paramHandle, effectsSectionPathSpecific.c_str());
|
||||
}
|
||||
|
||||
|
||||
effectsSectionPathSpecific.append("/effectsConfig");
|
||||
//now recreate the whole car section
|
||||
//GfParmSetNum(void *handle, const char *path, const char *key, const char *unit, tdble val)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
addSection
|
||||
|
||||
addParam
|
||||
|
||||
insertParam
|
||||
|
||||
GfParmSetStr
|
||||
*/
|
||||
|
||||
|
||||
// iterate on the first map
|
||||
typedef std::map<std::string, std::map<std::string, int> >::iterator it_type;
|
||||
for(it_type iterator = this->effectsConfig.begin(); iterator != this->effectsConfig.end(); iterator++) {
|
||||
// iterator->first = key (effect type name)
|
||||
// iterator->second = value (second map)
|
||||
|
||||
// now iterate on the second map
|
||||
typedef std::map<std::string, int>::iterator it_type2;
|
||||
for(it_type2 iterator2 = iterator->second.begin(); iterator2 != iterator->second.end(); iterator2++) {
|
||||
// iterator2->first = key (effect parameter name)
|
||||
// iterator2->second = value (effect value)
|
||||
|
||||
std::string effectPath = effectsSectionPathSpecific;
|
||||
effectPath.append("/");
|
||||
effectPath.append(iterator->first.c_str());
|
||||
|
||||
//remove the first slash
|
||||
effectPath.erase(0,1);
|
||||
|
||||
GfParmSetNum(paramHandle, effectPath.c_str(), iterator2->first.c_str(), "", iterator2->second);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//write changes
|
||||
GfParmWriteFile(NULL,paramHandle,"preferences");
|
||||
|
||||
}
|
||||
int ForceFeedbackManager::updateForce(tCarElt* car, tSituation *s){
|
||||
|
||||
|
@ -152,21 +219,14 @@ int ForceFeedbackManager::autocenterEffect(tCarElt* car, tSituation *s){
|
|||
int effectForce;
|
||||
|
||||
//force acting on the front wheels
|
||||
effectForce = car->_steerTq;
|
||||
effectForce = car->_steerTq * this->effectsConfig["autocenterEffect"]["frontwheelsmultiplier"] / 1000;
|
||||
|
||||
//force action on the back wheels
|
||||
//effectForce += car->_wheelFy(REAR_RGT);
|
||||
//effectForce += car->_wheelFy(REAR_LFT);
|
||||
|
||||
|
||||
// GfLogInfo("Autocenter tq: (%i)\n", effectForce);
|
||||
|
||||
//multiply
|
||||
effectForce = effectForce * this->effectsConfig["autocenterEffect"]["multiplier"] / 1000;
|
||||
// GfLogInfo("Autocenter multipli: (%i)\n", effectForce);
|
||||
effectForce += -1 * car->_wheelFy(REAR_RGT) * this->effectsConfig["autocenterEffect"]["rearwheelsmultiplier"] / 1000 ;
|
||||
effectForce += -1 * car->_wheelFy(REAR_LFT) * this->effectsConfig["autocenterEffect"]["rearwheelsmultiplier"] / 1000;
|
||||
|
||||
//smooth
|
||||
effectForce = (effectForce + (this->effectsConfig["autocenterEffect"]["previousValue"] * this->effectsConfig["autocenterEffect"]["multiplier"] / 1000)) / ((this->effectsConfig["autocenterEffect"]["multiplier"]/1000)+1);
|
||||
effectForce = (effectForce + (this->effectsConfig["autocenterEffect"]["previousValue"] * this->effectsConfig["autocenterEffect"]["smoothing"] / 1000)) / ((this->effectsConfig["autocenterEffect"]["smoothing"]/1000)+1);
|
||||
// GfLogInfo("Autocenter smooth: (%i)\n", effectForce);
|
||||
|
||||
//remember the current value for the next run
|
||||
|
|
|
@ -53,12 +53,15 @@ struct forceFeedBackEffect_t {
|
|||
class ForceFeedbackManager {
|
||||
|
||||
public:
|
||||
void readConfiguration(tCarElt* car);
|
||||
void readConfiguration(std::string carName);
|
||||
void saveConfiguration();
|
||||
int updateForce(tCarElt* car, tSituation *s);
|
||||
bool initialized;
|
||||
int force;
|
||||
int reversed;
|
||||
std::vector<std::string> effects;
|
||||
std::map< std::string, std::map<std::string, int> > effectsConfig;
|
||||
std::string carName;
|
||||
|
||||
//constructor
|
||||
ForceFeedbackManager();
|
||||
|
@ -73,8 +76,6 @@ class ForceFeedbackManager {
|
|||
|
||||
std::clock_t lastExecTime; //the current time
|
||||
|
||||
std::map< std::string, std::map<std::string, int> > effectsConfig;
|
||||
|
||||
void* menuXMLDescHdle;
|
||||
|
||||
std::clock_t animationStartTime; //when the animation started
|
||||
|
|
Loading…
Reference in a new issue