Skip to content

Zondulus/WindAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WindAPI Documentation

Overview

WindAPI serves as a compatibility layer between Ferram Aerospace Research (FAR) and mods that add wind or atmospheric currents to Kerbal Space Program.

Previously, only one mod could control FAR's wind system at a time. WindAPI hooks into FAR and acts as a multiplexer, allowing multiple mods (providers) to apply wind vectors simultaneously. It sums the vectors from all registered providers and passes the result to FAR.

Installation for Developers

  1. Add WindAPI.dll as a reference in your Visual Studio/IDE project.
  2. Ensure WindAPI is included in your GameData folder for testing.

Implementing a Wind Provider

To add wind to the game, create a class that implements WindAPI.IWindProvider.

using UnityEngine;
using WindAPI;

public class MyWindMod : IWindProvider
{
    public string ProviderID => "MyWindMod";

    public Vector3 GetWind(CelestialBody body, Part part, Vector3 position)
    {
        // 1. Check valid body (optional)
        if (body.name != "Kerbin") return Vector3.zero;

        // 2. Calculate wind vector in World Coordinates
        // Example: A constant updraft of 5m/s
        return Vector3.up * 5.0f;
    }
}

Important Implementation Notes

  • Coordinate System: The returned Vector3 must be in World Coordinates, not local vessel coordinates.
  • Null Parts: The part parameter may be null. This occurs when trajectory mods or other systems query wind at a point in space where no physical part exists. Always check for null before accessing part fields.
  • Performance: GetWind is called every physics frame for every active part. Keep calculations lightweight.
  • Exception Safety: If your provider throws an unhandled exception, WindAPI will disable it for the remainder of the flight session to preserve game performance.

Registering Your Provider

You must register your provider with the WindManager singleton. The recommended place to do this is in the Start() method of a MonoBehaviour running in the Flight scene.

[KSPAddon(KSPAddon.Startup.Flight, once: false)]
public class MyModController : MonoBehaviour
{
    private MyWindMod windMod;

    void Start()
    {
        windMod = new MyWindMod();
        
        // Check if WindAPI is installed
        if (WindManager.Instance != null)
        {
            WindManager.Instance.RegisterProvider(windMod);
        }
    }

    void OnDestroy()
    {
        if (WindManager.Instance != null)
        {
            WindManager.Instance.DeregisterProvider(windMod);
        }
    }
}

Advanced Usage

Ignoring Specific Providers

If your mod needs to calculate wind but wants to exclude specific providers (e.g., a slope lift mod that needs to know the ambient wind before slope effects are added), use GetWindAtLocation with the optional ignoreProvider parameter.

Vector3 ambientWind = WindManager.Instance.GetWindAtLocation(body, part, position, this);

Legacy Support

WindAPI automatically detects and wraps older wind mods that use reflection to overwrite the FAR delegate directly (e.g., Kerbal Wind Continued). No additional steps are required to support these mods; they are treated as a base wind layer.

About

Modding utility for handling complex wind simulation in Kerbal Space Program and Ferram Aerospace Research

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages