Jump to content

CommNet notes for modders


Recommended Posts

Hi, I figure I can post my notes about KSP's CommNet, given the namespace of CommNet is sort of large to sift through and no one has posted on CommNet yet.

Organisation of KSP CommNet

  • The entire CommNet feature is mainly consisted of CommNetUI, CommNetwork and CommNetVessel, along with a bunch of support classes and data structures
  • CommNetUI is the user interface where a player is seeing and interacting with. This class has the method of interest, UpdateDisplay(), which draws every connection and shows/hides some or all connections, depending on the mode (FirstHop, VesselLinks, Network etc) the player selected.
  • CommNetwork is subclass of the abstract class, Net, which is data-oriented class itself with multiple lists of different types, such as Link, Data and Occluder. This CommNetwork class manages and operates a global network of all CommNode (vessels) and CommLink (connections) objects. For example, the potential connectivity of a pair of two vessels is tested by SetNodeConnection() according to the connection and range rules.
  • Every vessel (Debris, Rover, Flag etc) has the variable 'connection' of CommNetVessel class. This class has a number of methods that are releated to the vessel itself. For example, the class's CalculatePlasmaMult() calculates the multipler of the radio blackout of the reentrying vessel.
  • CommNetScenario is responsible for starting up the CommNetwork and CommNetUI and disabling/enabling CommNet according to Game's settings.

 

Support CommNet class

  • CommNetNetwork seems to be a service layer where vessel and body data are added to and removed from CommNetork. It regularly fires a chain of health-check events for the CommNet.

 

Relevant data structures of the CommNet

  • CommNetHome is a ground station, whose data includes the body, alt, lat and lon.
  • CommNetBody is a celestial body, whose occluder is supplied for CommNetwork to check if the connection is occluded between two vessels.
  • CommNetVessel is a data structure attached to every vessel, even a debris (of course it is null). It has an unused variable of signalDelay, presumed a little gift for a certain mod. It also has a number of network-processing methods you can override: OnNetworkInitialized(), OnNetworkPostUpdate(), OnNetworkPreUpdate() and UpdateComm().
  • CommNode is analogous to a node of a graph. It has some information about antennas, remote-control capability. It is stored in the CommNetwork. The class conveniently provides a comparer, IEqualityComparer<CommNode>.
  • Likewise, CommLink is analogous to an edge of a graph. It contains some information about the vessel-pair connection, such as the signal strength, relay capability of each node.
  • CommPath, implied by its name, is a order-sequence of CommLink.

 

How to substitute KSP's CommNet for your own CommNet

  • Subclass CommNetUI to write your interface
  • Subclass CommNetwork to create your own connection rules
  • Subclass CommNetScenario to replace the KSP's stock CommNetwork and CommNetUI instances with your own subclasses above. You can also override OnLoad and OnSave for your CommNet data. You will need the KSPScenario tag to let KSP know it should run your CommNetScenario subclass instead of the stock CommNetScenario. 
  • Subclass CommNetVessel to write your communication behaviour for each vessel. KSP will automatically substitute the stock CommNetVessel for yours.
  • Bug (Squad is aware of this now): CommNetNetwork class has the hard-coded CommNetwork instance in ResetNetwork() so subclass this class to fix it and then replace it in your CommNetScenario subclass (via reflection, singleton or FindObjectOfType)
Edited by TaxiService
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...