From f4c4fc6bf58cb093eac2eda54281f2d460cff4eb Mon Sep 17 00:00:00 2001 From: madbad Date: Mon, 11 Jul 2016 18:50:12 +0000 Subject: [PATCH] Force Feedback: add initial implementation of engineRevvingEffect. also only play effects if enabled in configuration. git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6451 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 11ce0b30c415667dc0bdeab1ffbdd9a8fcbe117c Former-commit-id: 358f47662782b446c962b42193e28d9bea77d9a6 --- src/libs/tgfclient/forcefeedback.cpp | 64 ++++++++++++++++++++++++++-- src/libs/tgfclient/forcefeedback.h | 1 + 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/libs/tgfclient/forcefeedback.cpp b/src/libs/tgfclient/forcefeedback.cpp index 88a08f3f6..ed269224b 100644 --- a/src/libs/tgfclient/forcefeedback.cpp +++ b/src/libs/tgfclient/forcefeedback.cpp @@ -27,6 +27,11 @@ #include "tgfclient.h" #include "forcefeedback.h" +bool timeLogged = false; +clock_t effectStart = std::clock(); +clock_t effectCurTime = std::clock(); + + int filterPositiveNumbers (int number){ if (number > 0){ return number; @@ -180,10 +185,18 @@ void ForceFeedbackManager::saveConfiguration(){ } int ForceFeedbackManager::updateForce(tCarElt* car, tSituation *s){ - //calculate autocenter - this->force = this->autocenterEffect(car, s); - GfLogInfo("After autocenter: (%i)\n", this->force); - + //calculate autocenter if enabled + if (this->effectsConfig["autocenterEffect"]["enabled"]){ + this->force = this->autocenterEffect(car, s); + GfLogInfo("After autocenter: (%i)\n", this->force); + } + + //calculate engine revving if enabled + if (this->effectsConfig["engineRevvingEffect"]["enabled"]){ + this->force += this->engineRevvingEffect(car, s); + GfLogInfo("After engineRevving: (%i)\n", this->force); + } + //calculate bump //this->force += this->bumpsEffect(car, s); //GfLogInfo("After bump: (%i)\n", this->force); @@ -329,6 +342,49 @@ int ForceFeedbackManager::bumpsEffect(tCarElt* car, tSituation *s){ */ return effectForce; +} + +int ForceFeedbackManager::engineRevvingEffect(tCarElt* car, tSituation *s){ + + int effectForce; + double changeTimeInterval = 20; + + if(timeLogged != true){ + effectStart = std::clock(); + timeLogged = true; + GfLogInfo("StartTime: (%f)\n",(double)effectStart); + GfLogInfo("###############new time\n"); + GfLogInfo("StartTime: (%f)\n",(double)effectStart); + + } + effectCurTime = std::clock(); + + double timeDiff = (((double)effectCurTime - (double)effectStart )) / CLOCKS_PER_SEC * 1000; + + GfLogInfo("CurTime: (%f)\n", (double)effectCurTime); + GfLogInfo("StartTime: (%f)\n",(double)effectStart); + GfLogInfo("TimeDiff: (%f)\n", timeDiff); + + if (timeDiff > 40){ + if( this->effectsConfig["engineRevvingEffect"]["previousSign"] > 0 ){ + this->effectsConfig["engineRevvingEffect"]["previousSign"] = -1; + }else{ + this->effectsConfig["engineRevvingEffect"]["previousSign"] = 1; + } + + effectStart = std::clock(); + } + + GfLogInfo("Sign: (%i)\n", this->effectsConfig["engineRevvingEffect"]["previousSign"]); + + //force acting on the front wheels + effectForce = 50000 / (int)car->_enginerpm * 2 * this->effectsConfig["engineRevvingEffect"]["previousSign"]; + + GfLogInfo("RPM: (%i)\n", (int)car->_enginerpm); + GfLogInfo("Efect: (%i)\n", effectForce); + + return effectForce; + } //initialize the force feedback TGFCLIENT_API ForceFeedbackManager forceFeedback; diff --git a/src/libs/tgfclient/forcefeedback.h b/src/libs/tgfclient/forcefeedback.h index beadce1bb..01447b220 100644 --- a/src/libs/tgfclient/forcefeedback.h +++ b/src/libs/tgfclient/forcefeedback.h @@ -83,6 +83,7 @@ class TGFCLIENT_API ForceFeedbackManager { std::clock_t animationRestStartTime; //when the animation started int autocenterEffect(tCarElt* car, tSituation *s); + int engineRevvingEffect(tCarElt* car, tSituation *s); int bumpsEffect(tCarElt* car, tSituation *s); int globalMultiplier;