Making a plugin survive driver swaps

Discussion in 'Plugins' started by cosimo, Oct 6, 2015.

  1. Euskotracks

    Euskotracks Registered

    Joined:
    Nov 29, 2013
    Messages:
    1,092
    Likes Received:
    191
    @Marcel Offermans
    Would it be possible that Studio397 explained how this should be dealt?

    I understand it would save a lot of trial and error.
     
  2. Martin Vindis

    Martin Vindis Registered

    Joined:
    Apr 15, 2014
    Messages:
    144
    Likes Received:
    97
    I also check against ScoringInfoV01.mVehicle.mIsPlayer every update as I think you might be in mInRealTime when you're a passenger waiting for a change or when you're pass the car to another player.


    long playerSlot = 0;

    void VHUD::UpdateScoring(const ScoringInfoV01& info)
    {
    inRealtime = info.mInRealtime;
    isPlayer = IsPlayer(info);

    if (!inRealtime || !isPlayer)
    return;

    // Your code here
    }

    bool VHUD::IsPlayer(const ScoringInfoV01 & info)
    {

    //If the player connects as a spectator to a empty server
    if (info.mNumVehicles < 1)
    return false;

    //Our vehicle most likely have the same index once we got it so let's look there first
    if (info.mVehicle[playerSlot].mIsPlayer)
    return true;

    //Loop through the whole grid looking for the player's vehicle
    for (long i = 0; i < info.mNumVehicles; ++i)
    {
    if (info.mVehicle.mIsPlayer)
    {
    playerSlot = i;
    return true;
    }
    }

    //Player's vehicle not found
    return false;
    }
     
    Last edited: Feb 22, 2017
  3. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    @Lazza do you think shared memory plugin should expose both versions of mInRealtime, for example, mInRealtime set by function call and mInRealtimeScoringUpdate set via ScoringInfo, so that users have more information available? I could also try to combine both into one variable.

    EDIT: actually I have been thinking about this and I will expose both variables via shared memory. This will give clients most flexiblility to decide how to respond.
     
    Last edited: Feb 22, 2017
  4. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,345
    Likes Received:
    6,572
    @The Iron Wolf yeah, both sounds best for transparency.

    I changed my plugin as described earlier, a quick SP test seemed to work as normal, so when I get a chance I'll do a test build and see if anyone can test a swap with it. Darn work getting in the way.
     
    Josh.H and The Iron Wolf like this.
  5. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    Hopefully, one day we'll see source of DAMPlugin, would be great to learn from your experience, instead of reinventing the wheel :)

    I'll expose those variables in the next couple of weeks, luckily I am the only user atm, so I can not bother with compatibility :)

    work in a way of modding, sounds familiar :)
     
    Last edited: Feb 23, 2017
  6. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,345
    Likes Received:
    6,572
    @The Iron Wolf 2 reasons you won't see my source code... first, I'm an ugly programmer (not just behind the keyboard!) and I don't want to embarrass myself. Second, what I've worked out could be used to compete directly with Motec products, which I don't want to encourage or support.

    Anyway, I've just built a test version of my DAMPlugin to see if it works any better with driver swaps. Can anyone try it out at some point? Thanks :)

    https://forum.studio-397.com/index.php?threads/damplugin-for-rf2.49363/page-10#post-880298
     
  7. ebeninca

    ebeninca Registered

    Joined:
    Sep 7, 2016
    Messages:
    737
    Likes Received:
    524
    I hope that studio397 give attention to this topic, because using spectator mode to make driverswap is a workaround that is causing this kind of problems. Ideally, the driverswap should be done entering as a driver.
     
    Last edited: Feb 25, 2017
  8. stonec

    stonec Registered

    Joined:
    Jun 19, 2012
    Messages:
    3,399
    Likes Received:
    1,488
    It's not a workaround, it's almost necessary, otherwise you'd be having carmodels loading in and out of memory all the time during the race, so you would either race against a lot of "temporary cars" or experience lags as the new cars load.
     
    ebeninca likes this.
  9. ebeninca

    ebeninca Registered

    Joined:
    Sep 7, 2016
    Messages:
    737
    Likes Received:
    524
    sry about lack of precision in my argument, what i'm trying to say, is that we need a team system, at point that when a driver enter the race, the simulator knows if the player car is already in the track. Like iRacing does in Team Racing.
     
    Will Mazeo likes this.
  10. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,345
    Likes Received:
    6,572
    Ok, it looks like my change in approach will work fine, I just have a strange bug in my DAMPlugin code and need to track down the culprit. But the data was all generated correctly, indicating the plugin activated and deactivated itself properly during driver swaps (both when taking control, and yielding it).

    In summary:
    - Don't rely solely on EnterRealtime and ExitRealtime; they don't get called in driver swap situations.
    - Don't just check .mIsPlayer, check whether .mControl is 0 (and/or 1, if local AI control is acceptable). (I'm not 100% sure this is necessary, the video earlier suggests .mIsPlayer works fine, but it shouldn't hurt)

    I suspect my remaining bug might be due to ScoringInfoV01.mInRealtime being true before the vehicle's .mControl changes to 0 (or .mIsPlayer changing to true). Guessing it might indicate realtime as soon as you jump into the car in spectate mode?

    Big big thanks to @Josh.H for promptly testing and providing some clear logs to look at.
     
    Jego and Josh.H like this.
  11. Rinussie

    Rinussie Registered

    Joined:
    Jan 11, 2012
    Messages:
    75
    Likes Received:
    9
    hi peeps how is it coming with this solution(s) ???
     
  12. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Well, the solution is the one Martin indicated:
    So EnterRealtime() and ExitRealtime() update the state, but also UpdateScoring() has to, by way of ScoringInfoV01.mInRealtime.

    Thanks Martin!
     
    adamfarmer likes this.

Share This Page