0 people like it.

FerramDebug ver. 1

  1: 
  2: 
  3: 
  4: 
  5: 
  6: 
  7: 
  8: 
  9: 
 10: 
 11: 
 12: 
 13: 
 14: 
 15: 
 16: 
 17: 
 18: 
 19: 
 20: 
 21: 
 22: 
 23: 
 24: 
 25: 
 26: 
 27: 
 28: 
 29: 
 30: 
 31: 
 32: 
 33: 
 34: 
 35: 
 36: 
 37: 
 38: 
 39: 
 40: 
 41: 
 42: 
 43: 
 44: 
 45: 
 46: 
 47: 
 48: 
 49: 
 50: 
 51: 
 52: 
 53: 
 54: 
 55: 
 56: 
 57: 
 58: 
 59: 
 60: 
 61: 
 62: 
 63: 
 64: 
 65: 
 66: 
 67: 
 68: 
 69: 
 70: 
 71: 
 72: 
 73: 
 74: 
 75: 
 76: 
 77: 
 78: 
 79: 
 80: 
 81: 
 82: 
 83: 
 84: 
 85: 
 86: 
 87: 
 88: 
 89: 
 90: 
 91: 
 92: 
 93: 
 94: 
 95: 
 96: 
 97: 
 98: 
 99: 
100: 
101: 
102: 
103: 
104: 
105: 
106: 
107: 
108: 
// **** **** **** **** **** **** **** **** **** **** **** **** ****
// **  Copyright (c) 2017, Robert Nielsen. All rights reserved.  **
// **** **** **** **** **** **** **** **** **** **** **** **** ****

namespace Rodhern.FerramDebug

open System
open System.Collections.Generic
open UnityEngine


[< KSPAddon(KSPAddon.Startup.EditorSPH, false) >]
type FerramDebugger () =
  inherit MonoBehaviour ()
  
  /// Check if object reference is null.
  let unassigned o =
    obj.ReferenceEquals (o, null)
  
  /// Get value from named instance field.
  let (.>) (o: obj) (name: string) =
    if unassigned o then null else
    let bindingflags = Reflection.BindingFlags.Instance ||| Reflection.BindingFlags.Public ||| Reflection.BindingFlags.NonPublic
    match (o.GetType ()).GetMember (name, bindingflags) with
    | [| :? Reflection.FieldInfo as fieldinfo |] -> fieldinfo.GetValue o
    | _ -> null
  
  /// Return all parts of the vessel in the editor.
  let allEditorParts () =
    let rec inclusiveChildren (parts: Part seq) =
      seq { for part in parts
             do yield part
                yield! inclusiveChildren part.children }
    seq { match EditorLogic.RootPart with
          | root when unassigned root -> ()
          | root -> yield root }
    |> inclusiveChildren
  
  /// Pick the "FARWingAerodynamicModel" module from those parts that have one.
  let listWingMods (partseq: Part seq) =
    [ for part in partseq
       do if (part.Modules.Contains "FARWingAerodynamicModel")
           then yield part.Modules.["FARWingAerodynamicModel"] ]
  
  /// Output text to trace listeners and the Unity debug log.
  let log s =
    System.Diagnostics.Trace.WriteLine s
    Debug.Log s
  
  /// Output 'influence' values for particular part module to debug log.
  let writePartModInfluences (partmodlist: PartModule list) (partmodidx: int) =
    
    let asList (o: obj) =
      [ for i in o :?> System.Collections.ICollection do yield i ]
    
    let getIdx (o: obj) =
      let mutable idx = -1
      List.tryFindIndex (fun pmod -> obj.ReferenceEquals (o, pmod)) partmodlist
      
    let printInfluence (s: string) (d: obj) (reflist: obj) (dlist: obj) =
      let d = d :?> double
      let reflist = reflist |> asList
      let dlist = dlist |> asList
      log <| sprintf "   %s exposure %f (%d nearby wing modules)." s d reflist.Length
      if reflist.Length <> dlist.Length
       then log <| sprintf "   CAUTION: %s nearby list length mis-match; %d <> %d." s reflist.Length dlist.Length
      
      for j = 0 to (min reflist.Length dlist.Length) - 1
       do match getIdx reflist.[j] with
          | None -> "no match"
          | Some k -> sprintf "match idx %d" k
          |> sprintf "      influence= %f (%s)." (dlist.[j] :?> double)
          |> log
    
    let partmod = partmodlist.[partmodidx]
    do log <| sprintf " Part '%s' (idx= %d; x= %f; y= %f; z= %f)." partmod.part.name partmodidx partmod.part.attPos.x partmod.part.attPos.y partmod.part.attPos.z
    let wingInteraction = partmod.> "wingInteraction"
    
    let forwardExposure = wingInteraction.> "forwardExposure"
    let nearbyWingModulesForwardList = wingInteraction.> "nearbyWingModulesForwardList"
    let nearbyWingModulesForwardInfluence = wingInteraction.> "nearbyWingModulesForwardInfluence"
    do printInfluence "forward" forwardExposure nearbyWingModulesForwardList nearbyWingModulesForwardInfluence

    let backwardExposure = wingInteraction.> "backwardExposure"
    let nearbyWingModulesBackwardList = wingInteraction.> "nearbyWingModulesBackwardList"
    let nearbyWingModulesBackwardInfluence = wingInteraction.> "nearbyWingModulesBackwardInfluence"
    do printInfluence "backward" backwardExposure nearbyWingModulesBackwardList nearbyWingModulesBackwardInfluence

    let leftwardExposure = wingInteraction.> "leftwardExposure"
    let nearbyWingModulesLeftwardList = wingInteraction.> "nearbyWingModulesLeftwardList"
    let nearbyWingModulesLeftwardInfluence = wingInteraction.> "nearbyWingModulesLeftwardInfluence"
    do printInfluence "leftward" leftwardExposure nearbyWingModulesLeftwardList nearbyWingModulesLeftwardInfluence

    let rightwardExposure = wingInteraction.> "rightwardExposure"
    let nearbyWingModulesRightwardList = wingInteraction.> "nearbyWingModulesRightwardList"
    let nearbyWingModulesRightwardInfluence = wingInteraction.> "nearbyWingModulesRightwardInfluence"
    do printInfluence "rightward" rightwardExposure nearbyWingModulesRightwardList nearbyWingModulesRightwardInfluence
  
  member public dbg.Update () =
    if not (Input.GetKeyDown KeyCode.F1) then () else
    log " -- FAR Wing Interaction Influences --"
    let allparts = allEditorParts ()
    let allmods = listWingMods allparts
    log <| sprintf " %d vessel parts including %d wing modules." (Seq.length allparts) (List.length allmods)
    for j = 0 to allmods.Length - 1
     do writePartModInfluences allmods j
    log " -- ----- ----- -- - -- ----- ----- --"
    ScreenMessages.PostScreenMessage "Data listed in log output." |> ignore
namespace System
namespace System.Collections
namespace System.Collections.Generic
Multiple items
type FerramDebugger =
  inherit obj
  new : unit -> FerramDebugger
  member Update : unit -> 'a

Full name: Rodhern.FerramDebug.FerramDebugger

--------------------
new : unit -> FerramDebugger
type obj = Object

Full name: Microsoft.FSharp.Core.obj
Object.ReferenceEquals(objA: obj, objB: obj) : bool
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
Multiple items
namespace System.Reflection

--------------------
namespace Microsoft.FSharp.Reflection
type BindingFlags =
  | Default = 0
  | IgnoreCase = 1
  | DeclaredOnly = 2
  | Instance = 4
  | Static = 8
  | Public = 16
  | NonPublic = 32
  | FlattenHierarchy = 64
  | InvokeMethod = 256
  | CreateInstance = 512
  ...

Full name: System.Reflection.BindingFlags
field Reflection.BindingFlags.Instance = 4
field Reflection.BindingFlags.Public = 16
field Reflection.BindingFlags.NonPublic = 32
type FieldInfo =
  inherit MemberInfo
  member Attributes : FieldAttributes
  member Equals : obj:obj -> bool
  member FieldHandle : RuntimeFieldHandle
  member FieldType : Type
  member GetHashCode : unit -> int
  member GetOptionalCustomModifiers : unit -> Type[]
  member GetRawConstantValue : unit -> obj
  member GetRequiredCustomModifiers : unit -> Type[]
  member GetValue : obj:obj -> obj
  member GetValueDirect : obj:TypedReference -> obj
  ...

Full name: System.Reflection.FieldInfo
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------
type seq<'T> = IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>
val log : value:'T -> 'T (requires member Log)

Full name: Microsoft.FSharp.Core.Operators.log
namespace System.Diagnostics
type Trace =
  static member Assert : condition:bool -> unit + 2 overloads
  static member AutoFlush : bool with get, set
  static member Close : unit -> unit
  static member CorrelationManager : CorrelationManager
  static member Fail : message:string -> unit + 1 overload
  static member Flush : unit -> unit
  static member Indent : unit -> unit
  static member IndentLevel : int with get, set
  static member IndentSize : int with get, set
  static member Listeners : TraceListenerCollection
  ...

Full name: System.Diagnostics.Trace
Diagnostics.Trace.WriteLine(value: obj) : unit
Diagnostics.Trace.WriteLine(message: string) : unit
Diagnostics.Trace.WriteLine(value: obj, category: string) : unit
Diagnostics.Trace.WriteLine(message: string, category: string) : unit
type 'T list = List<'T>

Full name: Microsoft.FSharp.Collections.list<_>
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
type ICollection =
  member CopyTo : array:Array * index:int -> unit
  member Count : int
  member IsSynchronized : bool
  member SyncRoot : obj

Full name: System.Collections.ICollection
Multiple items
type List<'T> =
  new : unit -> List<'T> + 2 overloads
  member Add : item:'T -> unit
  member AddRange : collection:IEnumerable<'T> -> unit
  member AsReadOnly : unit -> ReadOnlyCollection<'T>
  member BinarySearch : item:'T -> int + 2 overloads
  member Capacity : int with get, set
  member Clear : unit -> unit
  member Contains : item:'T -> bool
  member ConvertAll<'TOutput> : converter:Converter<'T, 'TOutput> -> List<'TOutput>
  member CopyTo : array:'T[] -> unit + 2 overloads
  ...
  nested type Enumerator

Full name: System.Collections.Generic.List<_>

--------------------
List() : unit
List(capacity: int) : unit
List(collection: IEnumerable<'T>) : unit
val tryFindIndex : predicate:('T -> bool) -> list:'T list -> int option

Full name: Microsoft.FSharp.Collections.List.tryFindIndex
Multiple items
val double : value:'T -> double (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.double

--------------------
type double = Double

Full name: Microsoft.FSharp.Core.double
val sprintf : format:Printf.StringFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
val min : e1:'T -> e2:'T -> 'T (requires comparison)

Full name: Microsoft.FSharp.Core.Operators.min
union case Option.None: Option<'T>
union case Option.Some: Value: 'T -> Option<'T>
member FerramDebugger.Update : unit -> 'a

Full name: Rodhern.FerramDebug.FerramDebugger.Update
val not : value:bool -> bool

Full name: Microsoft.FSharp.Core.Operators.not
module Seq

from Microsoft.FSharp.Collections
val length : source:seq<'T> -> int

Full name: Microsoft.FSharp.Collections.Seq.length
val length : list:'T list -> int

Full name: Microsoft.FSharp.Collections.List.length
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
Raw view Test code New version

More information

Link:http://fssnip.net/7Td
Posted:6 years ago
Author:
Tags: