mdjarv / assettocorsasharedmemory

Assetto Corsa Shared Memory library written in C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reading Physics

VictorCasadoZ opened this issue · comments

Hello, I have succesfuly implemented the example code of the Static Data, but I have no idea of how to implement the Physics Data.

`using AssettoCorsaSharedMemory;
using System;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AssettoCorsa ac = new AssettoCorsa();
ac.StaticInfoInterval = 5000; // Get StaticInfo updates ever 5 seconds
ac.StaticInfoUpdated += ac_StaticInfoUpdated; // Add event listener for StaticInfo
ac.Start(); // Connect to shared memory and start interval timers

        Console.ReadKey();
    }

    static void ac_StaticInfoUpdated(object sender, StaticInfoEventArgs e)
    {
        // Print out some data from StaticInfo
        Console.WriteLine("StaticInfo");
        Console.WriteLine("  Car Model: " + e.StaticInfo.CarModel);
        Console.WriteLine("  Track:     " + e.StaticInfo.Track);
        Console.WriteLine("  Max RPM:   " + e.StaticInfo.MaxRpm);
    }
}

}`

That is the example code for Static Data, How should I implement the Physics Data to monitoring?

Thank you so much!

You need to add an event listener to ac.PhysicsUpdated, I believe the setup would be something like this (I've written this code directly in this comment so it is untested):

        static void Main(string[] args)
        {
            AssettoCorsa ac = new AssettoCorsa();
            ac.StaticInfoInterval = 5000; // Get StaticInfo updates ever 5 seconds
            ac.StaticInfoUpdated += ac_StaticInfoUpdated; // Add event listener for StaticInfo
            ac.PhysicsUpdated += ac_PhysicsUpdated; //  Add event listener for Physics
            ac.Start(); // Connect to shared memory and start interval timers

            Console.ReadKey();
        }

And then add the event function similarly to the ac_StaticInfoUpdated(...):

        static void ac_PhysicsUpdated(object sender, PhysicsEventArgs e)
        {
            // Print out some data from StaticInfo
            Console.WriteLine("Physics");
            Console.WriteLine("  Rpms: " + e.Physics.Rpms);
        }

This is may be an estupid question, but.... where I can find the AssettoCorsa library?

This is may be an estupid question, but.... where I can find the AssettoCorsa library?

There's a pre-compiled DLL under Releases if you don't want to build it from source: https://github.com/mdjarv/assettocorsasharedmemory/releases

Thanks for the quickly answer, I'm gonna try it right now.