[REL] Delta Best plugin for rFactor 2

Discussion in 'Other' started by cosimo, Apr 20, 2014.

  1. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Hi all,

    I'm spending some free time programming plugins for rFactor 2 these days :)
    I put together this proof of concept for a Delta Best or Delta Time plugin.

    This is the implementation of the iRacing Delta Bar for rFactor 2.



    Download here:

    I made this plugin for my own enjoyment and I decided to offer it to everyone else for free.
    If you use the plugin and would like to show your appreciation and support, use this Paypal donation link.

    Have fun!

    ____________________________________________________________

    List of changes for v25/WEC - 2017/04/16

    • Fixed plugin for driver swaps! Finally the DeltaBest plugin should work fine after taking over a car with a driver swap. The plugin should automatically start when entering realtime mode (clicking the "Race" button) when in spectate mode and should start indicating the delta time as soon as a best lap is loaded or recorded and a new timed lap starts.

      It took me a long time to figure out how to make plugins survive driver swaps! Here's the solution in case you are wondering:

      https://forum.studio-397.com/index....survive-driver-swaps.50312/page-2#post-886329

    ____________________________________________________________

    List of changes for v24/Nola

    • Fixed a cosmetic bug in how the best lap time is displayed when a session is loaded or when a new best lap is saved. A laptime of "2:02.058" would be displayed as "2:2.058".
    ____________________________________________________________

    List of changes for v23/Anderstorp

    (v21 and v22 were just test versions with limited distribution)

    • Fixed a few logic mistakes in how the best lap is saved. Now the best lap time should be saved more accurately.
    • Added a chat message when a best lap is restored from file, so you will know what is your best time in the same car/track combination.
    • Changed how the Delta info is shown. Now it's never shown when the player is in the pits, and should be there from the first timed lap whenever you already have a saved lap from before.
    • other minor fixes.
    ____________________________________________________________

    List of changes for v19Nords

    • Plugin should now work after a restart. Previously it stopped working when race was restarted. This possibly means that it will work after a driver swap as well, but I haven't tested that yet.

    List of changes for v18/Targa (v17 was never released publicly)

    ____________________________________________________________

    • Best laps are now saved persistently to disk into the "rFactor2\Userdata\player\Settings\DeltaBest" folder. The format is "<TrackName>_<CarClass>.lap". For now this feature can not be disabled, but read the ResetKey entry below.
    • Plugin should now work fine with the Targa Florio track. Previously there was a hard limit of 50km long tracks.
    • Delta time is now displayed beyond the session end time. This typically impacted qualify sessions. When the session timer reached 0:00, the delta time disappeared. Now it continues to work until the session is closed.
    • It is now possible to reset the best lap of the session through CTRL + Z. I realise this shortcut may not suit everyone, so you can customize it through the DeltaBest.ini file. In the "[Keyboard]" section, the "ResetKey" entry will allow you to redefine the ResetKey.

    ____________________________________________________________

    List of changes for v16/Sebring

    • Inverted negative and positive delta bars. When you're below your best timed lap (improving) the bar with go towards the right now, instead of left. This might be confusing, but it's the same as iRacing does. I'm convinced it's better from a perception point of view, as in "you're behind your best lap" or "you're ahead of your best lap".

    List of changes for v15/Modena

    • Finally fixed the track/car lap times mismatch bug! Now when you record a best lap, then exit the session, load up another track and/or car, your previously saved best lap will be properly reset. The previous best lap won't count for a new session with a different car or track (or even the same one for that matter).

    ____________________________________________________________

    List of changes for v14/Nardò

    • Now requires build 798+ of rFactor2. This is because the path to plugins changed from "Plugins" to "Bin32/Plugins" or "Bin64/Plugins". Version 14 will not work with older rF2 builds. You have been warned.
    • Improved display of delta time when flapping around zero, so that it doesn't change at high frequency between -0.01, 0 and 0.01.
    • Implemented an experimental new option in the INI file called "HiresUpdates", by default enabled. If you disable it, the delta time will be updated less often. This is something that was requested by one or two of you, but I'm not convinced it's worth it, and it's definitely not recommended. YMMV. This option could go away anytime in the future. Example INI file was updated with an example of this new option.
    • Fixed incorrect location of "DeltaBestBackground.png" file after rF2 build 798 that caused the grey background/bars to not display. I think a few users interpreted this as bar being disabled, and they wondered why the delta time was moving around. Remember, to disable the bar, copy the provided example ini file into "DeltaBest.ini" and then in the "[Bar]" section, change the "Enabled" property to zero. This will disable the bar and keep the delta time centered at all times.

    ____________________________________________________________

    List of changes for v13
    • Fixed a crash-to-desktop problem when going in reverse gear (!) due to 64-bit and compiler changes.

    ____________________________________________________________

    List of changes for v11 (forget v12)
    • Added DeltaBest_x64.dll for the upcoming 64-bit builds of rFactor2

    ____________________________________________________________

    List of changes for v9 and v10:
    • iRacing-style dynamicly colored bar is fully working now, with a slightly better layout
    • Plugin layout and visuals are completely configurable via the INI file (an annotated example in included in the zip archive)
    • Turn on/off either the colored bar or the delta time text
    • Change position, width and height of either the bar or the time text
    • Modify font face or size of the time text
    • Change shortcut key (default is CTRL+D) to toggle the display of the plugin
    • (v10) Debug logging was accidentally turned on, now it's turned off.
     

    Attached Files:

    Last edited: Apr 16, 2017
  2. Adrianstealth

    Adrianstealth Registered

    Joined:
    May 28, 2012
    Messages:
    4,578
    Likes Received:
    1,071
    great, looking forward to this, it's a great tool
     
  3. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    I forgot one thing. While I figure out how to calculate the delta best time...
    if you have ideas on how to do it, please let me know, I'm all ears :)
     
  4. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Early WIP plugin is now attached as zip file to the first post.
     
  5. GTClub_wajdi

    GTClub_wajdi Registered

    Joined:
    Feb 28, 2012
    Messages:
    3,238
    Likes Received:
    572
    I have this function with DashMeter Pro in My tablet!
     
  6. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Yes, I do have DashMeter too, so I know it's possible to calculate a delta best time.

    However, I can't keep my tablet where I want to place this delta best time, which is exactly where iRacing places it, in the middle of the screen, always clearly visible.
    That's the key to being useful, at least for me. In other words, on my tablet is not good enough because I have to look away from the track.

    You have immediate and realtime feedback even, if you are not looking at it, via the color. Very simple and very effective.
     
  7. GTClub_wajdi

    GTClub_wajdi Registered

    Joined:
    Feb 28, 2012
    Messages:
    3,238
    Likes Received:
    572
    OK, ora ho capito! good luck:)
     
  8. Mydriaz

    Mydriaz Registered

    Joined:
    Jan 16, 2012
    Messages:
    968
    Likes Received:
    47
    Nice project !
    Keep up the good work.
     
  9. GauchoRS

    GauchoRS Registered

    Joined:
    Nov 23, 2011
    Messages:
    471
    Likes Received:
    9
    its certainly very useful, keep going !

    I personally would like to hear the voice from race engineer saying ``ok, well done, you are quite faster than last lap`` or ``unbelievable, you set a new best lap time`` and so on ....

    please consider it to implement this kind of immersion enhancement
     
    Last edited by a moderator: Apr 21, 2014
  10. Jamie Shorting

    Jamie Shorting Registered

    Joined:
    Sep 11, 2013
    Messages:
    2,628
    Likes Received:
    3
    Good luck Cosimo, great idea!!! Thanks for the work so far.
     
  11. Gerald Jacobson

    Gerald Jacobson Registered

    Joined:
    Jan 26, 2013
    Messages:
    827
    Likes Received:
    18
    Here what i would try:
    Use VehicleScoringInfoV01
    - collect the pair : mLapDist & mLapStartET
    --- find a good balance between frequency and response time.
    - keep in memory the all pairs of the best lap.
    --- then regularly, take the current mLapDist, and find the corresponding mLapDist (or the two mLapDist - interval) of the best lap
    ------ then if you find two mLapDist in the best lap, simply interpolate (linear) the mLapStartET corresponding to the exact current mLapDist
    ------ then compute the difference between this interpolated mLapStartET and the current mLapStartET, and you should have the DeltaBest.
     
  12. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Thanks Gerald!
     
  13. DimebagDK

    DimebagDK Registered

    Joined:
    Feb 19, 2011
    Messages:
    5
    Likes Received:
    0
    How I did it in iRacing (before they exposed their "real" delta-values in the API) :

    Collected laptime and lapdistance on every physics-tick (put the laptime in an array having the size = tracks length in meters)
    Interpolated missing values in between the last update and the current update.

    Thats it, really.
    Deltatime is extremely simple to lookup/calculate with that structure (CurrentLapTime at X meters - LapTime in BestLapArray at X meters)

    With rf2 updating at 90hz, you should be able to pick up a laptime/distance for each single meter around the track (for cars going slower than 324km/h anyways)

    I haven't looked into if it's even possible with rf2's currently available data in the internals-plugin, but I would suspect so...
     
  14. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,346
    Likes Received:
    6,572
    100Hz :cool:

    (yeah, seriously, that's all I've got to add... I can't add anything to what these guys have suggested, both cover what I'd do if I were doing such a plugin)
     
  15. John.Persson

    John.Persson Registered

    Joined:
    Oct 17, 2011
    Messages:
    944
    Likes Received:
    13
    Been missing this function from iracing. I liked their bar thingy, but numbers are nice to!
     
  16. gabriel666

    gabriel666 Registered

    Joined:
    Jan 15, 2012
    Messages:
    204
    Likes Received:
    0
    Thanks cosimo great plugin!!!!
     
  17. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    OMG I got it working :)

    It's looking great so far, but I can't give you a download yet, because my testing found that the delta best calculation logic is incorrect.
    That is, it appears to be working fine but it fails miserably when you stop on the track :)

    I know why, I just need to sleep now.
    I feel that I'm very close. Expect news soon :)
     
  18. rene-xmg

    rene-xmg Registered

    Joined:
    Jan 20, 2012
    Messages:
    228
    Likes Received:
    2
    good news! i really miss that function in rf2... in iracing i mostly use the realtime-delta against my optimal lap in practise session
     
  19. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    First working version uploaded, and first post updated!
     
  20. Adrianstealth

    Adrianstealth Registered

    Joined:
    May 28, 2012
    Messages:
    4,578
    Likes Received:
    1,071
    Will try this tomorrow night, I'll report back too

    Thanks for sharing the result of your efforts!
     

Share This Page