• Welcome to PiBoSo Official Forum. Please login or sign up.
 
March 28, 2024, 04:53:19 PM

News:

World Racing Series beta14 available! :)


Suggestion for RaceData ?

Started by HornetMaX, May 17, 2016, 07:57:53 PM

Previous topic - Next topic

HornetMaX

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.

HornetMaX

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 :)

PiBoSo


There is no permanent structure with the plugins data on the simulator side, so unfortunately it will not be done.
"La perfezione non è il nostro obiettivo, è la nostra tendenza".

HornetMaX

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.

PiBoSo

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.
"La perfezione non è il nostro obiettivo, è la nostra tendenza".

HornetMaX

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.