Revision: 2497
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2497&view=rev
Author:   ulteq
Date:     2012-05-04 00:57:07 +0000 (Fri, 04 May 2012)
Log Message:
-----------
merged theshark's cruise control patch - thanks

Modified Paths:
--------------
    trunk/source/main/gameplay/RoRFrameListener.cpp
    trunk/source/main/physics/Beam.cpp
    trunk/source/main/physics/Beam.h
    trunk/source/main/physics/BeamData.h
    trunk/source/main/utils/InputEngine.cpp
    trunk/source/main/utils/InputEngine.h

Modified: trunk/source/main/gameplay/RoRFrameListener.cpp
===================================================================
--- trunk/source/main/gameplay/RoRFrameListener.cpp     2012-05-03 20:59:40 UTC 
(rev 2496)
+++ trunk/source/main/gameplay/RoRFrameListener.cpp     2012-05-04 00:57:07 UTC 
(rev 2497)
@@ -1849,11 +1849,75 @@
                        }
                }
        }
-#endif // MYGUI
+#endif //USE_MYGUI
 }
 
+void updateCruiseControl(Beam* curr_truck, float dt)
+{
+       if (INPUTENGINE.getEventValue(EV_TRUCK_BRAKE) > 0.05 || 
INPUTENGINE.getEventValue(EV_TRUCK_MANUAL_CLUTCH) > 0.05 || 
(curr_truck->parkingbrake && curr_truck->engine->getGear() > 0))
+       {
+               curr_truck->cruisecontrolToggle();
+               return;
+       }
 
+       if (curr_truck->engine->getGear() > 0)
+       {
+               // Try to maintain the target speed
+               if (curr_truck->cc_target_speed > curr_truck->WheelSpeed)
+               {
+                       float accl = (curr_truck->cc_target_speed - 
curr_truck->WheelSpeed);
+                       accl = std::min(accl, 1.0f);
+                       accl = 
std::max(INPUTENGINE.getEventValue(EV_TRUCK_ACCELERATE), accl);
+                       curr_truck->engine->setAcc(accl);
+               }
+       } else if (curr_truck->engine->getGear() == 0) // out of gear
+       {
+               // Try to maintain the target rpm
+               if (curr_truck->cc_target_rpm > curr_truck->engine->getRPM())
+               {
+                       float accl = (curr_truck->cc_target_rpm - 
curr_truck->engine->getRPM()) * 0.01;
+                       accl = std::min(accl, 1.0f);
+                       accl = 
std::max(INPUTENGINE.getEventValue(EV_TRUCK_ACCELERATE), accl);
+                       curr_truck->engine->setAcc(accl);
+               }
+       }
 
+       if (INPUTENGINE.getEventBoolValue(EV_TRUCK_CRUISE_CONTROL_ACCL))
+       {
+               if (curr_truck->engine->getGear() > 0)
+               {
+                       curr_truck->cc_target_speed += 5 * dt;
+               } else if (curr_truck->engine->getGear() == 0) // out of gear
+               {
+                       curr_truck->cc_target_rpm += 1000.0f * dt;
+               }
+       }
+       if (INPUTENGINE.getEventBoolValue(EV_TRUCK_CRUISE_CONTROL_DECL))
+       {
+               if (curr_truck->engine->getGear() > 0)
+               {
+                       curr_truck->cc_target_speed -= 5 * dt;
+               } else if (curr_truck->engine->getGear() == 0) // out of gear
+               {
+                       curr_truck->cc_target_rpm -= 1000.0f * dt;
+               }
+       }
+       if (INPUTENGINE.getEventBoolValue(EV_TRUCK_CRUISE_CONTROL_READJUST))
+       {
+               curr_truck->cc_target_speed = curr_truck->WheelSpeed;
+               curr_truck->cc_target_rpm   = curr_truck->engine->getRPM();
+       }
+
+#if 0
+       if (curr_truck->WheelSpeed > curr_truck->cc_target_speed + 0.5f && 
!INPUTENGINE.getEventValue(EV_TRUCK_ACCELERATE))
+       {
+               float brake = (curr_truck->WheelSpeed - 
curr_truck->cc_target_speed) * 0.5;
+               brake = std::min(brake, 1.0f);
+               curr_truck->brake = curr_truck->brakeforce * brake;
+       }
+#endif
+}
+
 bool RoRFrameListener::updateEvents(float dt)
 {
        if (dt==0.0f) return true;
@@ -2580,6 +2644,17 @@
                                        {
                                                if (curr_truck->tc_present && 
!curr_truck->tc_notoggle) curr_truck->tractioncontrolToggle();
                                        }
+
+                                       if 
(INPUTENGINE.getEventBoolValueBounce(EV_TRUCK_CRUISE_CONTROL))
+                                       {
+                                               
curr_truck->cruisecontrolToggle();
+                                       }
+                                       if(curr_truck->cc_mode)
+                                       {
+
+                                               
updateCruiseControl(curr_truck,dt);
+                                       }
+                                       
                                }
                                if (curr_truck->driveable==AIRPLANE)
                                {

Modified: trunk/source/main/physics/Beam.cpp
===================================================================
--- trunk/source/main/physics/Beam.cpp  2012-05-03 20:59:40 UTC (rev 2496)
+++ trunk/source/main/physics/Beam.cpp  2012-05-04 00:57:07 UTC (rev 2497)
@@ -369,6 +369,7 @@
        else
                driveable=NOT_DRIVEABLE;
        previousGear = 0;
+       cc_mode = cc_target_rpm = cc_target_speed = 0;
        alb_ratio = alb_minspeed = 0.0f;
        alb_mode = 0;
        tc_ratio = tc_fade = tc_wheelslip = 0.0f;
@@ -3451,7 +3452,7 @@
                        if (trucks[i]->state==DESACTIVATED && 
trucks[i]->importcommands) trucks[i]->lightsToggle();
                }
        }
-       lights=!lights;
+       lights = !lights;
        if(cablight && cablightNode && isInside)
                cablightNode->setVisible((lights!=0));
        if (!lights)
@@ -3872,7 +3873,7 @@
        cparticle_mode = !cparticle_mode;
        for (int i=0; i<free_cparticle; i++)
        {
-               cparticles[i].active=!cparticles[i].active;
+               cparticles[i].active = !cparticles[i].active;
                for (int j=0; j<cparticles[i].psys->getNumEmitters(); j++)
                {
                        
cparticles[i].psys->getEmitter(j)->setEnabled(cparticles[i].active);
@@ -4820,7 +4821,7 @@
 
 void Beam::parkingbrakeToggle()
 {
-       parkingbrake=!parkingbrake;
+       parkingbrake = !parkingbrake;
 
 #ifdef USE_OPENAL
        if (parkingbrake)
@@ -4835,14 +4836,29 @@
 
 void Beam::antilockbrakeToggle()
 {
-       alb_mode=!alb_mode;
+       alb_mode = !alb_mode;
 }
 
 void Beam::tractioncontrolToggle()
 {
-       tc_mode=!tc_mode;
+       tc_mode = !tc_mode;
 }
 
+void Beam::cruisecontrolToggle()
+{
+       cc_mode = !cc_mode;
+
+       if (cc_mode)
+       {
+               cc_target_speed = WheelSpeed;
+               cc_target_rpm   = engine->getRPM();
+       } else
+       {
+               cc_target_speed = 0;
+               cc_target_rpm   = 0;
+       }
+}
+
 void Beam::beaconsToggle()
 {
        bool enableLight = true;
@@ -4851,7 +4867,7 @@
        if(flaresMode==1)
                enableLight=false;
        int i;
-       beacon=!beacon;
+       beacon = !beacon;
        for (i=0; i<free_prop; i++)
        {
                if (props[i].beacontype=='b')

Modified: trunk/source/main/physics/Beam.h
===================================================================
--- trunk/source/main/physics/Beam.h    2012-05-03 20:59:40 UTC (rev 2496)
+++ trunk/source/main/physics/Beam.h    2012-05-04 00:57:07 UTC (rev 2497)
@@ -124,6 +124,7 @@
        void parkingbrakeToggle();
        void antilockbrakeToggle();
        void tractioncontrolToggle();
+       void cruisecontrolToggle();
        void beaconsToggle();
        void setReplayMode(bool rm);
        int savePosition(int position);

Modified: trunk/source/main/physics/BeamData.h
===================================================================
--- trunk/source/main/physics/BeamData.h        2012-05-03 20:59:40 UTC (rev 
2496)
+++ trunk/source/main/physics/BeamData.h        2012-05-04 00:57:07 UTC (rev 
2497)
@@ -865,7 +865,7 @@
        bool disable_default_sounds;
        int detacher_group_state; // current detacher group for the next beam 
generated
 
-       //antilockbrakes+tractioncontrol
+       // Antilockbrake + Tractioncontrol
        bool slopeBrake;
        float slopeBrakeFactor;
        float slopeBrakeAttAngle;
@@ -891,6 +891,11 @@
        int tractioncontrol;
        float animTimer;
 
+       // Cruise Control
+       int cc_mode;
+       float cc_target_rpm;
+       float cc_target_speed;
+
        float beam_creak;
        char uniquetruckid[256];
        int categoryid;
@@ -974,10 +979,10 @@
 
        int proped_wheels;
        int braked_wheels;
-       //for inter-diffential locking
+       //for inter-differential locking
        int proppairs[MAX_WHEELS];
 
-       //! try to connect slidenodes directly after spawning
+       //! try to connect slide-nodes directly after spawning
        bool slideNodesConnectInstantly;
 
        //! Stores all the available RailGroups for this truck

Modified: trunk/source/main/utils/InputEngine.cpp
===================================================================
--- trunk/source/main/utils/InputEngine.cpp     2012-05-03 20:59:40 UTC (rev 
2496)
+++ trunk/source/main/utils/InputEngine.cpp     2012-05-04 00:57:07 UTC (rev 
2497)
@@ -1084,13 +1084,37 @@
                "Keyboard EXPL+SHIFT+B",
                _L("toggle antilock brake")
        },
-               {
+       {
                "TRUCK_TRACTION_CONTROL",
                EV_TRUCK_TRACTION_CONTROL,
                "Keyboard EXPL+SHIFT+T",
                _L("toggle traction control")
        },
        {
+               "TRUCK_CRUISE_CONTROL",
+               EV_TRUCK_CRUISE_CONTROL,
+               "Keyboard EXPL+SPACE",
+               _L("toggle cruise control")
+       },
+       {
+               "TRUCK_CRUISE_CONTROL_READJUST",
+               EV_TRUCK_CRUISE_CONTROL_READJUST,
+               "Keyboard EXPL+SHIFT+SPACE",
+               _L("match target speed / rpm with current truck speed / rpm")
+       },
+       {
+               "TRUCK_CRUISE_CONTROL_ACCL",
+               EV_TRUCK_CRUISE_CONTROL_ACCL,
+               "Keyboard EXPL+SHIFT+R",
+               _L("increase target speed / rpm")
+       },
+       {
+               "TRUCK_CRUISE_CONTROL_DECL",
+               EV_TRUCK_CRUISE_CONTROL_DECL,
+               "Keyboard EXPL+SHIFT+F",
+               _L("decrease target speed / rpm")
+       },
+       {
                "TRUCK_SHIFT_DOWN",
                EV_TRUCK_SHIFT_DOWN,
                "Keyboard Z",

Modified: trunk/source/main/utils/InputEngine.h
===================================================================
--- trunk/source/main/utils/InputEngine.h       2012-05-03 20:59:40 UTC (rev 
2496)
+++ trunk/source/main/utils/InputEngine.h       2012-05-04 00:57:07 UTC (rev 
2497)
@@ -254,6 +254,10 @@
        EV_TRUCK_PARKING_BRAKE, //!< toggle parking brake
        EV_TRUCK_ANTILOCK_BRAKE, //!< toggle antilockbrake system
        EV_TRUCK_TRACTION_CONTROL, //!< toggle antilockbrake system
+       EV_TRUCK_CRUISE_CONTROL, //!< toggle cruise control
+       EV_TRUCK_CRUISE_CONTROL_READJUST, //!< match target speed / rpm with 
current truck speed / rpm
+       EV_TRUCK_CRUISE_CONTROL_ACCL,//!< increase target speed / rpm
+       EV_TRUCK_CRUISE_CONTROL_DECL,//!< decrease target speed / rpm
        EV_TRUCK_SHIFT_DOWN, //!< shift one gear down in manual transmission 
mode
        EV_TRUCK_SHIFT_NEUTRAL, //!< shift to neutral gear in manual 
transmission mode
        EV_TRUCK_SHIFT_UP, //!< shift one gear up in manual transmission mode

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Rigsofrods-devel mailing list
Rigsofrods-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to