Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 31

Thread: Sharing variables between plugin sections

  1. #21
    Senior Member
    Join Date
    Oct 2010
    Location
    Australia
    Posts
    423

  2. #22
    Senior Member
    Join Date
    Oct 2010
    Location
    Jacksonville, FL
    Posts
    435
    Ha

  3. #23
    I have found that checking for all temps to be equal, the tire load checking for 0 ( up on jacks ), and wear equal to 1.0 is enough to determine a pit stop and tire change. I'm now wrestling with getting only ONE instance to print out, rather than 90hz of them. Even on the jacks, the telemetry still goes on, doesn't it. The other issue is getting it to ignore the time the car is sitting in the garage. It seems to be on the jacks in there too.

  4. #24
    Senior Member
    Join Date
    Oct 2010
    Location
    Jacksonville, FL
    Posts
    435
    You need to add code to slow it down for sure. If you run 90hz you will probably cause performance problems.

    This is how I did it in my plugin:
    Code:
    float telemUpdateInterval = 0.5f;
    
    void ExampleInternalsPlugin::UpdateTelemetry( const TelemInfoV2 &info )
    {
    	if(timeSinceLastUpdate < telemUpdateInterval){
    		timeSinceLastUpdate += info.mDeltaTime ;
    		return;
    	}
    	// Do some stuff
    	
    	timeSinceLastUpdate = 0.0f;
    }
    So you have a global for your update interval. In the example it is set to 0.5f (500ms or a half a second). Then when UpdateTelemetry is called it first checks to see if it has been 500ms since the last update, if it hasn't, it increments the timer and the returns without doing anything else. If it has been a 500ms+ then it does your work and then at the end of your work it resets your timer to 0.

  5. #25
    Senior Member
    Join Date
    Oct 2010
    Location
    Australia
    Posts
    423
    Quote Originally Posted by JohnW63 View Post
    I have found that checking for all temps to be equal, the tire load checking for 0 ( up on jacks ), and wear equal to 1.0 is enough to determine a pit stop and tire change. I'm now wrestling with getting only ONE instance to print out, rather than 90hz of them. Even on the jacks, the telemetry still goes on, doesn't it. The other issue is getting it to ignore the time the car is sitting in the garage. It seems to be on the jacks in there too.
    Noel's given a good example to help, but I think you're still making this more complicated than it needs to be.

    Those figures you're checking are probably fairly foolproof (wear should be 1.0 on at least the update after the tyre is changed, load will probably be ~0.0 during a pitstop - equal temps sounds slightly dodgy, may well work all the time but since they start cooling the moment they're fitted you do run the risk of a 0.000001 difference for whatever reason) but as you're finding you'll have entire seconds where testing those conditions will return TRUE. You're better off using something that will only trigger once per tyre change.

    Assuming you'll always have tyre wear on when using this plugin, the simplest method I can see is to store your previous wear. Using something like this: (note: I don't have the source here... some function names are bound to be wrong)

    Code:
    float prevRLWear;
    (rear-left; a driven tyre will absolutely ensure some wear, you could also get the _min() of front and rear on one side, or even all 4 tyres, but every tyre's wear will drop to 0.99999 pretty much as soon as you move)

    In RealtimeEntered(), set prevRLWear to the starting value (1.0), and then in UpdateTelemetry() you need only check if the current RL wear is greater than prevRLWear. If it is, the tyre has been changed, so you can do your output or whatever. Finally, you set prevRLWear to the current RL wear (regardless of whether it was changed) for checking next time around.

    This will run your output code once per tyrechange, and never in-between.

    Also, if you want to avoid output or testing while in the garage/monitor, use a variable:

    Code:
    bool inCar = false;
    In RealtimeEntered(), set it to true. In RealtimeExited() (or whatever it's called ) set it to false. Then the first thing you do in UpdateTelemetry is

    Code:
    if (inCar) {
       // test for tyrechange
       ...
    }
    and no testing will happen at the monitor.

    If your series/mod allows tyres to be changed independently (left side, right side, front or rear, vs all 4 all the time) you might need 2 or 4 vars to check for tyre changes, but it'll still work the same way for each.

  6. #26
    Lazza,

    But isn't the inCar variable part of the UpdateScoring section, rather than the Update Telemetry section ? My C++ knowledge is too old to get the darn syntax correct to access one part from another.

    I think I understand what you are suggesting. I need to write it down and check it out. My current thought is to check for the tire change and store the temp. If there car hasn't moved, I don't override the stored temp. If I could store it and not allow an over write until the inPits variable changed to false, that would work, I think .

  7. #27
    Senior Member
    Join Date
    Oct 2010
    Location
    Australia
    Posts
    423
    Quote Originally Posted by JohnW63 View Post
    But isn't the inCar variable part of the UpdateScoring section, rather than the Update Telemetry section ? My C++ knowledge is too old to get the darn syntax correct to access one part from another.
    Nope, inCar is a variable I'm suggesting to declare as a global within the .cpp file.

    Just throw
    bool inCar = false;
    near the top of the file somewhere, and you can access it from any function.

    This is the simple, ugly, C way of doing it. MaXyM obviously isn't a fan, but it works...

    You set it to false by default because you don't start in the car. When you enter the car, EnterRealtime() is called, so put inCar = true; in there. Whenever you exit the car (back to the monitor), ExitRealtime() is called, so put inCar = false; into that.

    Now you can check the value of inCar (true or false) from any function (UpdateTelemetry(), UpdateScoring(), ...).

    You can do exactly the same thing (declaring a global variable and accessing it from anywhere) with tyre temps, wear, current laps completed, ... anything you want. You just need to work out what you need to know at a given time (be it some telemetry data when you're processing a scoring update, or vice versa, or comparing current data to some previous ones) and store it as necessary.

    I'm not giving you 'complete' example code because it won't help you understand what you're doing. You're just a bit stuck on this being a DLL at the moment, once you get past that you can concentrate on having your code actually do what you want.

  8. #28
    Another simple question:

    While the example files use different files for output for each section, can I have both the scoring and telemetry classes open and output to the same text file ? That way, all the data I am looking for would be in one file.

  9. #29
    Senior Member
    Join Date
    Oct 2010
    Location
    Australia
    Posts
    423
    Yes, the UpdateTelemetry and UpdateScoring functions (not 'classes') contain code to append to an existing file ("a" in the fopen() call). So if you give the same filename in both functions they will append to the same file.

  10. #30
    That's how I assumed it would work, but I didn't know if the file was "locked" while one was writing to it.

Similar Threads

  1. Need to Paint certain sections of Walls and Guardrails
    By Holt in forum Modding - Tracks
    Replies: 3
    Last Post: 05-24-2015, 04:19 PM
  2. Spotter Plugin
    By muzarati in forum rFactor 1 General Discussion
    Replies: 12
    Last Post: 07-29-2013, 12:32 AM
  3. RFE Plugin Series 1.1 is now available
    By Slow Motion in forum rFactor 1 Modding
    Replies: 0
    Last Post: 11-09-2012, 07:35 PM
  4. variables in the Hardware Control function
    By dlecoutre in forum rFactor 1 Technical Support
    Replies: 0
    Last Post: 02-16-2012, 06:31 PM
  5. HDV FRONT WING, REAR WING, DIFFUSER sections help
    By JoshJ81 in forum Modding - Cars
    Replies: 7
    Last Post: 04-21-2011, 05:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •