func UnregisterFlightLoopCallback(flightLoop FlightLoopFunc, ref interface{}) { for key, data := range callbacks { if data.funcPointerAsString == fmt.Sprint(flightLoop) && data.flightLoopData.Ref == ref { C.XPLMUnregisterFlightLoopCallback(C.XPLMFlightLoop_f(unsafe.Pointer(C.flightLoop)), unsafe.Pointer(data.flightLoopData)) delete(callbacks, key) } } }
func CreateFlightLoop(data *CreateFlightLoopData) FlightLoopId { id := C.CString(goplane.IdGenerator()) cRegData := C.XPLMCreateFlightLoop_t{} cRegData.structSize = C.int(unsafe.Sizeof(cRegData)) cRegData.phase = C.XPLMFlightLoopPhaseType(data.Phase) cRegData.callbackFunc = C.XPLMFlightLoop_f(unsafe.Pointer(C.flightLoop)) cRegData.refcon = unsafe.Pointer(id) callbacks[id] = regData{fmt.Sprint(data.Callback), data} flightLoopId := FlightLoopId(C.XPLMCreateFlightLoop(&cRegData)) return flightLoopId }
func SetFlightLoopCallbackInterval(flightLoop FlightLoopFunc, interval float32, relativeToNow bool, ref interface{}) { cRelativeToNow := 0 if relativeToNow { cRelativeToNow = 1 } for key, current := range callbacks { if current.funcPointerAsString == fmt.Sprint(flightLoop) { current.flightLoopData.Ref = ref C.XPLMSetFlightLoopCallbackInterval(C.XPLMFlightLoop_f(C.flightLoop), C.float(interval), C.int(cRelativeToNow), unsafe.Pointer(key)) } } }
func RegisterFlightLoopCallback(flightLoop FlightLoopFunc, interval float32, ref interface{}) { data := regData{fmt.Sprint(flightLoop), &CreateFlightLoopData{FlightLoop_Phase_BeforeFlightModel, flightLoop, ref}} id := C.CString(goplane.IdGenerator()) callbacks[id] = data C.XPLMRegisterFlightLoopCallback(C.XPLMFlightLoop_f(unsafe.Pointer(C.flightLoop)), C.float(interval), unsafe.Pointer(id)) }