Shared Memory API

Discussion in 'Community Workshop' started by Mikael Hermansson, Jun 7, 2015.

  1. Sascha Brandenburg

    Sascha Brandenburg Well-Known Member

    Joined:
    Feb 17, 2015
    Ratings:
    +56 / 0 / -0
    Not Really to improve maybe a downgrade to the race07 logs would be perfect :D Dont know if its possible to get logs which the race07 dedis saved.
     
  2. mr_belowski

    mr_belowski Well-Known Member Beta tester

    Joined:
    Apr 23, 2015
    Ratings:
    +1,307 / 0 / -0
    For each car (including the player) I'd like driver name, car and car class, world position, isInPitLane (or is on limiter), last lap time, is current lap valid, current tyre type, laps completed, outstanding penalties, current sector, current lap distance, and maybe some other stuff.

    I'd also like the track name and layout. Or a look up for these
     
  3. Gil Ritter

    Gil Ritter Well-Known Member

    Joined:
    Feb 26, 2015
    Ratings:
    +91 / 0 / -0
    Not really. These were plain text files with some structure. Parsing was possible but not the best way. The new json-format is considerable better. But we need more information in it.

    Here is a list of necessary data fields:
    • Overall race time
    • Lap Count per driver
    • Race status (fnished, dnf etc.)
    • Quali best lap/result
    • R3E names and not the Steam names.

    I would also take more but these are essential.
     
    • Like Like x 1
  4. Robert Holm

    Robert Holm KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +162 / 0 / -0
    So.. I'll aim to add these for each car (did I miss something?):

    typedef struct
    {
    r3e_u8char name;
    r3e_int32 car_number;
    r3e_int32 class_id;
    r3e_int32 model_id;
    r3e_int32 team_id;
    r3e_int32 livery_id;
    r3e_int32 manufacturer_id;
    r3e_int32 class_performance_index;
    } r3e_driver_info;

    typedef struct
    {
    r3e_driver_info driver_info;
    r3e_int32 place;
    r3e_float32 lap_distance;
    r3e_vec3_f32 position;
    r3e_int32 track_sector;
    r3e_int32 completed_laps;
    r3e_int32 current_lap_valid;
    r3e_float32 lap_time_current_self;
    r3e_float32 lap_time_previous_self;
    r3e_float32 lap_time_best_self;
    r3e_float32 lap_time_delta_leader;
    r3e_float32 sector_time_previous_self[3];
    r3e_float32 time_delta_front;
    r3e_float32 time_delta_behind;
    r3e_int32 in_pitlane;
    r3e_int32 num_pitstops;
    r3e_int32 num_penalties;
    r3e_float32 car_speed;
    r3e_int32 tire_type;
    } r3e_driver_data_1;

    @mr_belowski : what do you mean by Car Status?
     
    • Like Like x 2
  5. Stefan Mizzi

    Stefan Mizzi Well-Known Member

    Joined:
    Feb 6, 2015
    Ratings:
    +625 / 0 / -0
    Thank you Robert!!!

    Are the car world positions x, y, z available so that I can draw the track and cars? They don't really have to be World positions, but at least some coordinates.

    Cheers
    Stefan
     
  6. Robert Holm

    Robert Holm KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +162 / 0 / -0
    yep; r3e_vec3_f32 position;
     
    • Like Like x 1
    • Winner Winner x 1
  7. mr_belowski

    mr_belowski Well-Known Member Beta tester

    Joined:
    Apr 23, 2015
    Ratings:
    +1,307 / 0 / -0
    I didn't ask for car status - that was Stefan. Not sure what it means either :)

    For the penalties, can we split into cut track, stop go, time deduction, and drive through? Can we also have a value indicating whether this car has completed its mandatory pitstop (another enum I guess - not_needed, to_be_done, completed). Or something like that.

    This will be utterly brilliant for my app :)


    Oh, and the X/Y/Z co-ordinates, are these cartesian and in metres? I can use that to make the spotter do proper left / right differentiation, assuming the orientation of the opponent car is fairly similar to the orientation of the player's car. Doesn't really matter where the origin is as long as the player's car as a similar set of co-ordinates relative to the same origin
     
    Last edited: Sep 25, 2015
  8. mr_belowski

    mr_belowski Well-Known Member Beta tester

    Joined:
    Apr 23, 2015
    Ratings:
    +1,307 / 0 / -0
    Oh, and won't the r3e_driver_data struct need an identifier for that driver too? Just an int32 SlotID or something

    I had a chat with Mikel (if I remember correctly) about the noise in the data - we were wondering if it might be worth introducing a shared mutex locked before R3E starts writing one tick's worth of data, and unlocked when that's complete. The client apps could (if they wanted to) block until R3E had finished writing all the data for that tick
     
  9. Robert Holm

    Robert Holm KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +162 / 0 / -0
    ah sorry, asking Stefan then :) @Stefan Mizzi Car Status? do you mean like DQ, DNF?

    i'll look into penalties and pitstop status.

    x/y/z are world coordinates, and I guess you can pinpoint relative positions with existing data (orientation).

    you could find current car in array by comparing position/place, but perhaps it'd be better adding slotId.

    Mikael is gonna look into mutex lock to prevent jitter.
     
  10. Stefan Mizzi

    Stefan Mizzi Well-Known Member

    Joined:
    Feb 6, 2015
    Ratings:
    +625 / 0 / -0
    Yes exactly thanks!

    I agree with Jim, SlotID/CarID/DriverID (whatever it is) will be very helpful!

    Damn, I'm getting so excited....hope the wife does not invent any outings this weekend (so that I prepare the framework) :p
     
    Last edited: Sep 25, 2015
  11. mr_belowski

    mr_belowski Well-Known Member Beta tester

    Joined:
    Apr 23, 2015
    Ratings:
    +1,307 / 0 / -0
    Need to be careful that whatever mutex approach you take, you can obtain the lock at your end even if my app is behaving badly and not releasing it in a timely manner. Not that it would ;)
     
  12. mr_belowski

    mr_belowski Well-Known Member Beta tester

    Joined:
    Apr 23, 2015
    Ratings:
    +1,307 / 0 / -0
    I was a naughty boy over the last couple of weeks and ported Crew Chief to Project Cars, decoupling it from the R3E shared memory format. PCars has driver names, car positions, and other stuff in its shared memory. This means that my app is only a short hack away from being able to use much this planned new data for R3E.

    I'd better get recording more driver names - once this is in for R3E I'll record some of the R3E AI drivers' names, and I'll need a list of everyone's R3E online names to add to the nearly 600 AI names I already done for PCars :D
     
    • Like Like x 2
    • Wonderful Wonderful x 1
    • Creative Creative x 1
  13. Robert Holm

    Robert Holm KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +162 / 0 / -0
    think I've got it all in there, looks like this now:

    typedef struct
    {
    r3e_u8char name[64];
    r3e_int32 car_number;
    r3e_int32 class_id;
    r3e_int32 model_id;
    r3e_int32 team_id;
    r3e_int32 livery_id;
    r3e_int32 manufacturer_id;
    r3e_int32 slot_id;
    r3e_int32 class_performance_index;
    } r3e_driver_info;

    typedef struct
    {
    r3e_driver_info driver_info;
    r3e_finish_status finish_status;
    r3e_int32 place;
    r3e_float32 lap_distance;
    r3e_vec3_f32 position;
    r3e_int32 track_sector;
    r3e_int32 completed_laps;
    r3e_int32 current_lap_valid;
    r3e_float32 lap_time_current_self;
    r3e_float32 lap_time_previous_self;
    r3e_float32 lap_time_best_self;
    r3e_float32 lap_time_delta_leader;
    r3e_float32 sector_time_previous_self[3];
    r3e_float32 time_delta_front;
    r3e_float32 time_delta_behind;
    r3e_pitstop_status pitstop_status;
    r3e_int32 in_pitlane;
    r3e_int32 num_pitstops;
    r3e_cut_track_penalties penalties;
    r3e_float32 car_speed;
    r3e_int32 tire_type;
    } r3e_driver_data_1;
     
    • Like Like x 6
  14. mr_belowski

    mr_belowski Well-Known Member Beta tester

    Joined:
    Apr 23, 2015
    Ratings:
    +1,307 / 0 / -0
    r3e_cut_track_penalties - should that be r3e_penalties? What's in that struct?
     
  15. Robert Holm

    Robert Holm KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +162 / 0 / -0
    typedef struct
    {
    r3e_int32 drive_through;
    r3e_int32 stop_and_go;
    r3e_int32 pit_stop;
    r3e_int32 time_deduction;
    r3e_int32 slow_down;
    } r3e_cut_track_penalties;

    you can only have one of each currently, so can be considered booleans
     
  16. mr_belowski

    mr_belowski Well-Known Member Beta tester

    Joined:
    Apr 23, 2015
    Ratings:
    +1,307 / 0 / -0
  17. pixeljetstream

    pixeljetstream Well-Known Member Beta tester

    Joined:
    Jan 29, 2015
    Ratings:
    +412 / 0 / -0
    Looks great indeed, will we also get a trackID?

    as for mutex, with two incarnation counters, we can also detect if data was written during copy. r3e would increment one counter at begin-edit, and one at end-edit. By definiton these writes are happening atomically (32-bit) on x86. Only the compiler has to be instructed to strictly order the writes to those variables.

    The third party app copying from shared can then test the counters for consistency of the data. It doesn't prevent inconsistent blocks, but one will be able to ignore them.
     
    Last edited: Sep 27, 2015
  18. Robert Holm

    Robert Holm KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +162 / 0 / -0
    yes, track- and layout id as well. (..and tyre dirt per wheel, and rps per wheel, and pitlimiter active/inactive for current car)
     
    • Like Like x 2
  19. rbn

    rbn Well-Known Member

    Joined:
    May 31, 2015
    Ratings:
    +69 / 0 / -0
    Can you please add pitlimiter enabled 0 / 1 also?
     
  20. Robert Holm

    Robert Holm KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +162 / 0 / -0