PiBoSo Official Forum

GP Bikes => Mods => Plugins => Topic started by: HornetMaX on May 17, 2016, 07:57:53 PM

Title: Suggestion for RaceData ?
Post by: HornetMaX on May 17, 2016, 07:57:53 PM
Many RaceData structures reference a vehicle via its m_iRaceNum. Data relative to a vehicle is kept into an array of SPluginsRaceAddEntry_t.

So a plugin must keep track of all the entries (i.e. duplicate the SPluginsRaceAddEntry_t structures and keep them in sync with the one in the game every time  RaceAddEntry() and RaceRemoveEntry() happen) and each time it has to "search" for the m_iRaceNum in the stored structures, which is bad.

Wouldn't it be easier if referencing was done directly, like this (I take SPluginsRaceVehicleData_t as an example):


typedef struct
{
/* int m_iRaceNum; */
        const SPluginsRaceAddEntry_t  *m_psRaceEntry;                 /* pointer to const SPluginsRaceAddEntry_t structure */
int m_iActive;
float m_fRPM; /* engine RPM */
int m_iGear; /* 0 = Neutral */
float m_fSpeedometer; /* meters/second */
float m_fThrottle; /* 0 to 1 */
float m_fFrontBrake; /* 0 to 1 */
} SPluginsRaceVehicleData_t;


The same could be done for SPluginsRaceLap_t, SPluginsRaceSplit_t, SPluginsRaceSpeed_t, SPluginsRaceCommunication_t, SPluginsRaceClassificationEntry_t and SPluginsRaceTrackPosition_t.

In fact, I think you could even get rid of RaceAddEntry() and RaceRemoveEntry() calls completely if referencing was done as I suggest.
Title: Re: Suggestion for RaceData ?
Post by: HornetMaX on May 24, 2016, 10:53:06 AM
Good ? Not good ? Bad ?

I'd just hate to write down code that looks for a give iRaceNum into the array of SPluginsRaceAddEntry_t, or even use an hash table (std::map) for the lookup, when in fact just using a pointer will avoid all that :)
Title: Re: Suggestion for RaceData ?
Post by: PiBoSo on May 24, 2016, 12:38:43 PM

There is no permanent structure with the plugins data on the simulator side, so unfortunately it will not be done.
Title: Re: Suggestion for RaceData ?
Post by: HornetMaX on May 24, 2016, 12:49:00 PM
Quote from: PiBoSo on May 24, 2016, 12:38:43 PM
There is no permanent structure with the plugins data on the simulator side, so unfortunately it will not be done.
You mean you recreate the vector of race entries at each plugin call ?! That sounds very inefficient (even if the cost is probably zero, compared to the rest).
The client/server definitely has the information permanently stored somewhere ...

Anyway, I can live with the current design, it just makes using the whole RaceData stuff unnecessarily convoluted.
Title: Re: Suggestion for RaceData ?
Post by: PiBoSo on May 24, 2016, 04:21:38 PM
Quote from: HornetMaX on May 24, 2016, 12:49:00 PM
Quote from: PiBoSo on May 24, 2016, 12:38:43 PM
There is no permanent structure with the plugins data on the simulator side, so unfortunately it will not be done.
You mean you recreate the vector of race entries at each plugin call ?! That sounds very inefficient (even if the cost is probably zero, compared to the rest).
The client/server definitely has the information permanently stored somewhere ...

Anyway, I can live with the current design, it just makes using the whole RaceData stuff unnecessarily convoluted.

Data is saved internally in a very different format, with a lot more variables.
The way data is sent to the plugins is not efficient, however game programming is often a compromise, especially for features that are added later in development. Routines are optimized only if they start to take more than a tenth of millisecond each frame.
Title: Re: Suggestion for RaceData ?
Post by: HornetMaX on May 24, 2016, 04:34:54 PM
Understood. I agree the current plugin interface is the son of incremental evolutions and hence carries on some not-so-nice design.
Just for you to keep a mental note somewhere about that: as the interface is common across all your (current) sims, maybe one day, rethinking this part ...

Thx for the explanations.