Revision: 2614
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2614&view=rev
Author:   ulteq
Date:     2012-05-20 19:47:01 +0000 (Sun, 20 May 2012)
Log Message:
-----------
-Feature: Cruise Control (auto brake, speed limit)
+adjustable lower limit for the target speed
+braking feature, brakes if wheel speed > target speed
.truck file syntax: "cruisecontrol <lower limit for target speed> <auto brake 
if vehicle is too fast>"
Example: "cruisecontrol 5.0 0" -> lower target speed limit of 5 m/s and auto 
braking off

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

Modified: trunk/source/main/gameplay/RoRFrameListener.cpp
===================================================================
--- trunk/source/main/gameplay/RoRFrameListener.cpp     2012-05-20 18:48:17 UTC 
(rev 2613)
+++ trunk/source/main/gameplay/RoRFrameListener.cpp     2012-05-20 19:47:01 UTC 
(rev 2614)
@@ -1852,6 +1852,7 @@
 {
        if (INPUTENGINE.getEventValue(EV_TRUCK_BRAKE) > 0.05f ||
                INPUTENGINE.getEventValue(EV_TRUCK_MANUAL_CLUTCH) > 0.05f ||
+               (curr_truck->cc_target_speed < 
curr_truck->cc_target_speed_lower_limit) ||
                (curr_truck->parkingbrake && curr_truck->engine->getGear() > 0) 
||
                !curr_truck->engine->running ||
                !curr_truck->engine->contact)
@@ -1887,7 +1888,7 @@
                if (curr_truck->engine->getGear() > 0)
                {
                        curr_truck->cc_target_speed += 5.0f * dt;
-                       curr_truck->cc_target_speed  = std::max(0.0f, 
curr_truck->cc_target_speed);
+                       curr_truck->cc_target_speed  = 
std::max(curr_truck->cc_target_speed_lower_limit, curr_truck->cc_target_speed);
                        curr_truck->cc_target_speed  = 
std::min(curr_truck->cc_target_speed, curr_truck->sl_speed_limit);
                } else if (curr_truck->engine->getGear() == 0) // out of gear
                {
@@ -1900,7 +1901,7 @@
                if (curr_truck->engine->getGear() > 0)
                {
                        curr_truck->cc_target_speed -= 5.0f * dt;
-                       curr_truck->cc_target_speed  = std::max(0.0f, 
curr_truck->cc_target_speed);
+                       curr_truck->cc_target_speed  = 
std::max(curr_truck->cc_target_speed_lower_limit, curr_truck->cc_target_speed);
                } else if (curr_truck->engine->getGear() == 0) // out of gear
                {
                        curr_truck->cc_target_rpm -= 1000.0f * dt;
@@ -1910,17 +1911,19 @@
        if (INPUTENGINE.getEventBoolValue(EV_TRUCK_CRUISE_CONTROL_READJUST))
        {
                curr_truck->cc_target_speed = std::min(curr_truck->WheelSpeed, 
curr_truck->sl_speed_limit);
+               curr_truck->cc_target_speed = 
std::max(curr_truck->cc_target_speed_lower_limit, curr_truck->cc_target_speed);
                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))
+       if (curr_truck->cc_can_brake)
        {
-               float brake = (curr_truck->WheelSpeed - 
curr_truck->cc_target_speed) * 0.5f;
-               brake = std::min(brake, 1.0f);
-               curr_truck->brake = curr_truck->brakeforce * brake;
+               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.5f;
+                       brake = std::min(brake, 1.0f);
+                       curr_truck->brake = curr_truck->brakeforce * brake;
+               }
        }
-#endif
 }
 
 void checkSpeedlimit(Beam* curr_truck, float dt)

Modified: trunk/source/main/physics/Beam.cpp
===================================================================
--- trunk/source/main/physics/Beam.cpp  2012-05-20 18:48:17 UTC (rev 2613)
+++ trunk/source/main/physics/Beam.cpp  2012-05-20 19:47:01 UTC (rev 2614)
@@ -201,8 +201,10 @@
        cablightNode = 0;
 
        cc_mode = false;
+       cc_can_brake = false;
        cc_target_rpm = 0.0f;
        cc_target_speed = 0.0f;
+       cc_target_speed_lower_limit = 0.0f;
 
        debugVisuals = 0;
 

Modified: trunk/source/main/physics/BeamData.h
===================================================================
--- trunk/source/main/physics/BeamData.h        2012-05-20 18:48:17 UTC (rev 
2613)
+++ trunk/source/main/physics/BeamData.h        2012-05-20 19:47:01 UTC (rev 
2614)
@@ -893,8 +893,10 @@
 
        // Cruise Control
        bool cc_mode;
+       bool cc_can_brake;
        float cc_target_rpm;
        float cc_target_speed;
+       float cc_target_speed_lower_limit;
 
        // Speed Limiter
        float sl_speed_limit;

Modified: trunk/source/main/physics/input_output/SerializedRig.cpp
===================================================================
--- trunk/source/main/physics/input_output/SerializedRig.cpp    2012-05-20 
18:48:17 UTC (rev 2613)
+++ trunk/source/main/physics/input_output/SerializedRig.cpp    2012-05-20 
19:47:01 UTC (rev 2614)
@@ -851,6 +851,18 @@
                                }
                                continue;
                        }
+                       if (c.line.size() > 13 && c.line.substr(0, 13) == 
"cruisecontrol")
+                       {
+                               parse_args(c, args, 3);
+                               cc_target_speed_lower_limit = 
PARSEREAL(args[1]);
+                               cc_can_brake = PARSEINT(args[2]) != 0;
+                               if (cc_target_speed_lower_limit <= 0.0f)
+                               {
+                                       parser_warning(c, "CruiseControl: First 
parameter must be a decimal and greater than zero (e.g. 5.6)");
+                                       continue;
+                               }
+                               continue;
+                       }
                        if (c.line.size() > 12 && c.line.substr(0, 12) == 
"speedlimiter")
                        {
                                parse_args(c, args, 2);

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
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to