User Tools

Site Tools


dev:proposals:new-ks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
dev:proposals:new-ks [2022-04-01 16:50]
ywang
dev:proposals:new-ks [2023-03-26 12:10] (current)
ywang
Line 1: Line 1:
 +====== Implementation: new-ks branch ======
 +//Please refer to the source code for implementation details and API documentation. This information is provided here. The filenames provided below are relative to ''[[http://git.bananach.space/advtrains.git/tree/advtrains_interlocking?h=new-ks|/advtrains_interlocking]]''.//
 +
 +  * The distant signaling API is implemented in ''[[http://git.bananach.space/advtrains.git/tree/advtrains_interlocking/distant.lua?h=new-ks|distant.lua]]''
 +  * Formspecs have been partially modified to support distant signaling. Some formspecs are now implemented in various ''*_ui.lua'' files.
 +  * Signal aspect accessors have been modified and are now found in ''[[http://git.bananach.space/advtrains.git/tree/advtrains_interlocking/signal_aspect_accessors.lua?h=new-ks|signal_aspect_accessors.lua]]''
 +  * A signal aspect API is introduced. This allows manipulating signal aspect objects (implemented using tables) and creating signal aspect groups, the latter of which makes it possible to create route signals. The relevant code can be found in ''[[http://git.bananach.space/advtrains.git/tree/advtrains_interlocking/aspect.lua?h=new-ks|aspect.lua]]''
 +  * A ''[[http://git.bananach.space/advtrains.git/tree/advtrains_interlocking/README.md?h=new-ks|README.md]]'' file is added that gives some information on working with the new signaling system.
 +
 +**The changes break a few minor things:**
 +
 +  * The signal aspect formspec uses dropdown indexing, which requires Minetest 5.4.0 or later.
 +  * ''advtrains.interlocking.signal_get_aspect'' and ''advtrains.interlocking.signal_set_aspect'' are changed:
 +    * The results are cached.
 +    * The signal aspect is "adjusted" before being passed to the signal, i.e., the signal aspect passed to the signal is not guaranteed to be the same as the one passed to ''advtrains.interlocking.signal_set_aspect''.
 +    * ''advtrains.interlocking.signal_get_real_aspect'' gets the aspect of the signal directly from the node definitions. Note that, especially for Ks signals, the result is not guaranteed to be constant.
 +    * There is no API for setting the signal aspect while bypassing the cache and signal aspect adjustments, as the latter is necessary for distant signaling. **Do not call the ''advtrains.set_aspect'' function in the node definitions directly as doing so is not guaranteed to give the expected result.**
 +    * ''advtrains.interlocking.signal_get_aspect'' returns signal aspect objects instead of plain tables.
 +  * When setting a field of the signal aspect object to ''nil'' while an aspect is named, the default value for the named aspect is used instead of ''false''. In particular, this may break certain shunt setups.
 +  * Certain features of signal aspect objects are implemented using metatables. These objects are therefore not suitable for serialization, and it is not recommended to use ''next''-related functions (e.g. ''pairs'') on these objects. If you want to get a plain table, call the ''plain'' method of these objects.
 +
 +It is planned to merge the newly introduced signal aspect cache with its counterpart in the routesetting system.
 +
 +Please refer to the source code (listed above) for details.
 ====== Proposal: Distant signaling (second draft) ====== ====== Proposal: Distant signaling (second draft) ======
-//This is currently a draft. Feel free to discuss the proposal here.//+//This draft has been supersededPlease refer to the actual implementation (mentioned above).//
  
 //This draft is mainly written to address the issues that appeared in the first draft. In particular, it addresses a request to implement route signaling.// //This draft is mainly written to address the issues that appeared in the first draft. In particular, it addresses a request to implement route signaling.//
Line 14: Line 38:
   * When a route is set, the distant signals along the route are assigned to the upcoming signal (i.e. the signal first signal a train should encounter after passing the TCB). These distant signals are then set correspondingly.   * When a route is set, the distant signals along the route are assigned to the upcoming signal (i.e. the signal first signal a train should encounter after passing the TCB). These distant signals are then set correspondingly.
   * When a train leaves a TCB, the distant signal, if assigned to another signal, is unassigned. This should, at least theoretically, be safe as no other train is, at the moment, allowed to pass the TCB that the distant signal is assigned to.   * When a train leaves a TCB, the distant signal, if assigned to another signal, is unassigned. This should, at least theoretically, be safe as no other train is, at the moment, allowed to pass the TCB that the distant signal is assigned to.
 +
 +===== Setting distant signals =====
 +  * When a signal aspect is set, the distant signals are set correspondingly.
 +  * When a distant signal is unassigned, its distant aspect is set to ''nil''.
  
 ===== API Changes ===== ===== API Changes =====
Line 40: Line 68:
 === Supported aspects === === Supported aspects ===
 The table of supported aspects should include the following fields: The table of supported aspects should include the following fields:
 +  * ''name'': A name identifying the signal aspect table. Note that this is //not// shown to the user
 +  * ''label'': The name of the signal aspect to show to the user (e.g. in a UI). The use of ''attrans'' is recommended here.
   * ''main'': A list of supported main aspects. An error is signaled if this list has less than two entries.   * ''main'': A list of supported main aspects. An error is signaled if this list has less than two entries.
   * ''dst'': A translation table where each key is the ''name'' field of the aspect and the value is a name that is passed to the set_aspect field of the distant signal.   * ''dst'': A translation table where each key is the ''name'' field of the aspect and the value is a name that is passed to the set_aspect field of the distant signal.
 +  * ''alt_translation'': A translation table where the key is the name of the table of supported aspects and the value is a table with key-value pairs of the original aspect name and the translated aspect name (as in the ''main'' field of the aspect)
 +
 +When registering, the signal should provide the following fields:
 +  * ''aspects'': The name of the table of supported aspects (see above).
   * ''is_dst'': A boolean indicating whether the current signal is a distant signal.   * ''is_dst'': A boolean indicating whether the current signal is a distant signal.
  
Line 51: Line 85:
  
 === Signal aspect translation === === Signal aspect translation ===
-  * When a distant signal defined with the alternative signal aspect definition table is assigned to a signal that is not defined with the same signal aspect table, the distant signal is always given the //n-1//th entry (with //n// being the number of defined main aspects of the distant signal) unless the main aspect of the upcoming signal is -1, in which case the distant signal is given the first entry of the defined main aspects of the distant signal.+  * When a distant signal defined with the alternative signal aspect definition table is assigned to a signal that is not defined with the same signal aspect table, the distant signal is always given the //n-1//th entry (with //n// being the number of defined main aspects of the distant signal) unless the main aspect of the upcoming signal is -1, in which case the distant signal is given the first entry of the defined main aspects of the distant signal, or an entry in the translation table can be used to determine the distant signal aspect.
   * When a distant signal defined with the current signal aspect definition table is assigned to a signal defined with the alternative current signal aspect definition table, the ''main'' field of the signal aspect is passed to the distant signal.   * When a distant signal defined with the current signal aspect definition table is assigned to a signal defined with the alternative current signal aspect definition table, the ''main'' field of the signal aspect is passed to the distant signal.
  
dev/proposals/new-ks.1648824659.txt.gz · Last modified: 2022-04-01 16:50 by ywang