Author Topic: Normalizing Speedometer values across scripts  (Read 2811 times)

0 Members and 1 Guest are viewing this topic.

Offline DeathCobra

  • Veteran Member
  • Posts: 5008
    • View Profile
Normalizing Speedometer values across scripts
« on: July 14, 2022, 04:09:00 PM »
After playing with a bunch of different speedo/stats scripts, it's become pretty annoying trying to describe runup speeds to other people that are likely using a different tool. Some of them calculate and display speed differently, so you can get values in ranges from 0-90, up to 0-320, depending on the script you use. Some are very raw speed values, others convert roughly to kmph or mph, but not particularly intelligently.

However it seems like Dannye did a pretty smart thing with USCM 7b, in which he checks if the game is in Imperial or Metric, and converts speed appropriately.

The initial 'speed' value from the game comes from opcode 02E3, which I guess queries the car handling manager. This returns a float value, that for a PCJ, should be somewhere between 0-90 in normal circumstances.

Code: [Select]
02E3: 2@ = car 4@ speed                                                             // Speed1.  Get current speed in 'map points (~ meters) per second'
This is the same opcode that at least some existing CLEO speedos use, although perhaps not all.

Then check if the game is Metric/Imperial, and convert that handling value appropriately:

Code: [Select]
0013: 2@ *= 3.6                                                                     // Speed2.  Convert to km/h
00D6: if
8424:  not metric
004D: jump_if_false @LABEL_SHOW_STATS_CONTINUE
0017: 2@ /= 1.609                                                                   // Speed2b. Convert to mp/h (if approp)

Finally convert to int for display:

Code: [Select]
0092: 6@ = float_to_integer 2@                                                      // Speed3.  Convert to int
The key thing here is that, providing the speedo you use is using the 02E3 opcode, it's pretty simple to normalize the values for others to reference.

- Convert 02E3 to kmph by multiplying by 3.6. Convert kmph to 02E3 by dividing by 3.6.
- Convert kmph to mph by dividing by 1.609. Convert mph to kmph by multiplying by 1.609.

The simplest way to normalize, I guess, is to just default to using Dannye's car stats via the USCM. But if you're using a CLEO speedo or other, the multipliers above should ensure that we're functionally still talking about the same speed values - even if they're in different units.

(Maybe this is common knowledge idk, just thought it worth posting as a point of reference)

Offline Demo00n

  • Posts: 254
  • ``````````````````````````````````````````````````
    • View Profile
Re: Normalizing Speedometer values across scripts
« Reply #1 on: July 15, 2022, 02:57:33 AM »
First

Offline Rainbow

  • Senior Member
  • Posts: 7375
  • Coeur de taxi
    • View Profile
    • http://www.youtube.com/Rainbowstunting
Re: Normalizing Speedometer values across scripts
« Reply #2 on: July 15, 2022, 03:52:43 AM »
Is there a way to check if your speedo is using that opcode? Outside of driving the same run-up twice to see if it matches some other tool.

But since Dannye implemented the speedo into the USCM I don't see a reason anymore to use any other speedometers, if only for the fact we can be sure it doesn't alter anything else in the game when installed. I never used one because it would just prove I'm slower than everyone else  :euro: But just having one standard so comparison is easy can only be a good thing. Thanks for the more detailed explanation.

Offline DeathCobra

  • Veteran Member
  • Posts: 5008
    • View Profile
Re: Normalizing Speedometer values across scripts
« Reply #3 on: July 15, 2022, 05:19:18 AM »
Is there a way to check if your speedo is using that opcode? Outside of driving the same run-up twice to see if it matches some other tool.

But since Dannye implemented the speedo into the USCM I don't see a reason anymore to use any other speedometers, if only for the fact we can be sure it doesn't alter anything else in the game when installed. I never used one because it would just prove I'm slower than everyone else  :euro: But just having one standard so comparison is easy can only be a good thing. Thanks for the more detailed explanation.

Yeah I think using Dannye's is the easiest option for most. Although I'm not sure how easy it is to customize the position/colour etc of the stats display, when compared to a CLEO script. I was already using a CLEO speedo, and have customized it a bit in that respect. So I'll probably just convert it to mph using the above calculations. That way it has parity with the mph that USCM will give people.

I know Jason has customized the USCM display though, so it's definitiely doable.

You can check how the CLEO script (assuming it's a CLEO mod), by loading the .cs into a text or code editor. Then see how it's grabbing vehicle speed from the game. If it's not a CLEO script, I'm not sure what method it will be using.
« Last Edit: July 15, 2022, 05:21:06 AM by DeathCobra »

Offline Lex

  • Senior Member
  • Posts: 1336
  • No longer active
    • View Profile
Re: Normalizing Speedometer values across scripts
« Reply #4 on: July 15, 2022, 08:29:10 AM »
Is there a way to check if your speedo is using that opcode? Outside of driving the same run-up twice to see if it matches some other tool.

But since Dannye implemented the speedo into the USCM I don't see a reason anymore to use any other speedometers, if only for the fact we can be sure it doesn't alter anything else in the game when installed. I never used one because it would just prove I'm slower than everyone else  :euro: But just having one standard so comparison is easy can only be a good thing. Thanks for the more detailed explanation.

Wait whaat, I've never heard of this before

Offline VaNilla

  • next week m9
  • Veteran Member
  • Posts: 3809
    • View Profile
    • YouTube
Re: Normalizing Speedometer values across scripts
« Reply #5 on: July 15, 2022, 08:55:57 AM »
Is this consideration the same in SA? I don't know if Dannye added a speedometer to SA's USCM as well in the last few years, but presumably any given speedometer can transform the values from the game however it wants, so you would need to use the same one as everyone else to be absolutely sure that everything is comparable, even when they're matched to either MPH/KMH. In other words, should we avoid comparing values taken from the old speedometer overlay DLL that people used in the past to the digital speedometer CLEO script people use in SA these days?
« Last Edit: July 15, 2022, 09:03:21 AM by VaNilla »

Offline DeathCobra

  • Veteran Member
  • Posts: 5008
    • View Profile
Re: Normalizing Speedometer values across scripts
« Reply #6 on: July 15, 2022, 09:07:24 AM »
Is this consideration the same in SA? I don't know if Dannye added a speedometer to SA's USCM as well in the last few years, but presumably any given speedometer can transform the values from the game however it wants, so you would need to use the same one as everyone else to be absolutely sure that everything is comparable. In other words, should we avoid comparing values taken from the old speedometer overlay DLL that people used in the past to the digital speedometer CLEO script people use in SA these days?

The same opcode is used in v4 SA USCM, and the unit conversion is also the same.

Code: [Select]
00D6: if                                     // -- Current Vehicle Stats ----------------------------------------------
8039:  not 4@ == FALSE                                                              // IF currently in-vehicle, or on-foot w/ desired-vehicle available for use
004D: jump_if_false @LABEL_SHOW_STATS_DONE
02E3: 16@ = car 4@ speed                                                            // Speed1.  Get current speed in 'map points (~ meters) per second'
0013: 16@ *= 3.6                                                                    // Speed2.  Convert to km/h
00D6: if
8424:  not is_system_metric
004D: jump_if_false @LABEL_SHOW_STATS_CONTINUE
0017: 16@ /= 1.609                                                                  // Speed2b. Convert to mp/h (if approp)
:LABEL_SHOW_STATS_CONTINUE
0092: 26@ = float 16@ to_integer                                                    // Speed3.  Convert to int

So it would be trivial to convert any current CLEO speedo, that uses 02E3, to match. As for the DLL speedo - it would probably need a bit of investigating. I'm not sure if it would use opcodes or some other method of getting vehicle speed. But if it doesn't, or if it wasn't possible to find out, you could probably do some tests to see if the measured speeds match. Perhaps by using natural (no lean etc) maximum vehicle speeds. I.e. infernus max speed on flat terrain.

Offline VaNilla

  • next week m9
  • Veteran Member
  • Posts: 3809
    • View Profile
    • YouTube
Re: Normalizing Speedometer values across scripts
« Reply #7 on: July 15, 2022, 09:21:49 AM »
I'm thinking it would be best to standardise speedometers in VC and SA, by using Dannye's USCM as a base truth (a known suitable method), testing alternative speedometers with clearly viewable source code (like CLEO scripts) against it, and making a list of suitable options. That way, we wouldn't have to rely on video testing or screenshots to compare the results of different speedometers :euro:. I'm not able to help with that at the moment, so good luck to anyone who's interested :happy:.
« Last Edit: July 15, 2022, 09:24:31 AM by VaNilla »

Offline DeathCobra

  • Veteran Member
  • Posts: 5008
    • View Profile
Re: Normalizing Speedometer values across scripts
« Reply #8 on: July 15, 2022, 09:36:30 AM »
Yes Dannye's as 'truth' makes sense given it's ubiquitous. I know there's some that prefer to use older versions though, and for those I guess they use other speedos. Hence this thread.

Key thing to remember is 02E3 * 3.6 = KPH. (02E3 * 3.6)/1.609 = MPH. With that most other speedos should be comparable. For those that aren't, someone needs to test if they care.

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal