Skip to content

Incomplete analysis of MCBE redstone system operation (2)

Arie edited this page Feb 13, 2022 · 59 revisions

Redstone circuit and directed graph

Directed graph

In principle, the signal calculation and update of a stable Redstone system that does not increase or decrease the original has nothing to do with the Redstone line. In order to figure out what the Redstone circuit looks like and to facilitate subsequent analysis, the concept of a directed graph must be introduced first.

A directed graph is to connect some nodes with arrows. These arrows can be bidirectional or unidirectional. The following figure is a simple directed graph. The circles in the figure are called nodes, and the arrows indicate directed edges.




Specifically for the Redstone circuit, we use nodes to represent the original Redstone, such as Redstone blocks, comparators, pistons, etc... and use node A to point to B to indicate that A is a signal source of B (see box 1 for what is a signal source). of course, we can define a directed edge that represents the distance between the signal source a and B numbers on the original Redstone Block (figure above is 8) .A->Bdistance.

Note that the directed edges are only logical connections and have nothing to do with the Redstone line.

Look at the circuit as shown in the example:

Example circuit

It can be converted into such a directed graph:

Example circuit

Then the circuit is very clear, the piston has two signal sources: Redstone block and pulls rod, and the distance is 2. The Redstone lamp does not have any signal source, so its signal is 0. This pile of Redstone wires has the same signal source, that is, the rod and the Redstone block. The Redstone line is useless in the directed graph, so I won’t draw it below.

A digression, the Redstone system in MCBE is a directed weighted graph, stored in adjacency tables

Redstone circuit relationship construction

The only function of the Redstone line is reflected here. When you place the original Redstone, the game will search for the circuit and add a signal source to the original. To reflect in the directed graph is to draw a circle in the graph, and then add and Arrows related to this circle. The charging characteristics, connection characteristics, or activation characteristics that are often heard are reflected in this process. For example, in the following example, the left side is weak powering, and the right side is strong powering. The difference in the game is whether the Redstone powder in front of the wool can search for the signal source behind the wool (there is no on the left, and the repeater can be searched on the right) The problem

Strong and weak powering

As to how the search is not the point here, people do not really look at the signal source circuit it, would not it does it (But if you really want to visualize it. It's possible with my plugin and after enabling the plugin, you can right-click the original Redstone with a wooden stick and you can see some things that you can't normally observe, including signal source, signal strength, etc...) [This is not about Reddust]

Talk about the producers and consumers, again...

After the above explanation, it is not difficult to find out that:

  • Some nodes only have arrows pointing to themselves. In the performance game, they can only receive signals, such as pistons, transmitters, and so on. This has another name inside some called consumers (the Redstone line can also be called consumers to a certain extent).
  • Some nodes only have arrows pointing to other nodes, which can only output signals in the game, such as Redstone blocks, levers, etc..., such originals are called producers.
  • Some originals have arrows pointing to themselves and arrows pointing to other nodes, which can be used to input and output signals in the game, such as Redstone torches and comparators, which are called capacitors.

To sum it up, the entire Redstone circuit is such a weighted directed graph: the Redstone signal flows between nodes along a directed edge, and the value on the edge represents the energy loss of this flow; some nodes are responsible In the production of Redstone signals, some nodes are responsible for enhancement, transmission, delay, turnover, and storage of Redstone signals, and some originals are only responsible for responding to Redstone signals. It smells like a computer system (fog).

Abstract representation of Redstone circuit

Game running process in one single game tick

The following figure is the update sequence table in every MCBE game tick, since now: gt will be standing for game tick

Game running process in single gt

The following points are mainly emphasized here:

  • It is +1 until 8 game ticks. When analyzing Redstone, you can use 9 as the starting point of 1gt and 24 as the endpoint, because 1-8 does not affect the Redstone operation.

Then talk about a few incidents related to Redstone:

  • 12 Here is the execution of the plan. For details, see my previous column. Here are the places and buttons for the observer to update the signal, and the pressure plate to update the internal timer. This means that if you let the block appear to be updated Delay will cause the signal duration of the button to increase.

  • 14 is when the block entity is updated (or called in response to the Redstone signal), that is when the piston, hopper, dropper, dispenser, funnel, and moving block entity (MovingBlock or Tile) are updated.

  • 15 This is a non-physical block signal in response to Redstone place, including rendering lines and Redstone Redstone lights, gate, trap-door switch animation, etc...

  • 17 is the place to detect the player's behavior (here to be determined), that is, the detection of the player's interaction with the world is here. For example, if you pull the lever, the signal of the lever will be set to 15.

  • 22-24 are the three phases of the Redstone system signal update. This phase is executed only for each Redstone carving. The previous column is about this, and I will talk about it in more detail below.

Redstone signal calculation

After understanding the composition of the Redstone circuit before, you can guess why Mojang designed such a calculation method:

Producers and consumers have only inputs or only outputs, so they can be calculated and set directly, but the capacitors are different (to put it aside, the Redstone circuit is more like a state machine in a sense) because of each capacitor. There is no fixed order for the signal calculation. If you directly calculate and set the value, the state of some capacitors will be calculated based on the value of the previous 1gt, and some capacitors may be calculated based on the updated capacitor. It's messed up.

So Mojang divides the signal update of the entire circuit into two steps, each original has 1-2 (in fact, Mojang also has a lock check step, which is specially designed for repeaters, not in the general):

  • The first one is to calculate and set the signal evaluate()
  • The second is to calculate a new signal and temporarily store it cacheValues()

According to the above analysis, it is easy to know that every gt consumer and producer only has the process, and the capacitor has both, and in fact Mojang does this evaluate() The strict order is this:

  1. Capacitor and Redstone wire cacheValues()
  2. Capacitor and producer (only the setting of the capacitor is not calculated, the previous calculation has been done) evaluate evaluate()
  3. Consumers and Redstone Line cachevalue()

This sequence also led to the creation of a zero-delay capacitor.

A signal analysis without capacitors

This is mainly to clarify the player interaction and the startup delay of each consumer

First, go to the circuit:

Example circuit

The screenshot of the single-step operation will not be put, it takes up too much space, and a schematic diagram of a single gt is put below:

Note: The blue one is red stone carving, the white one is ordinary carving

Micro timing analysis

Note:

  1. There are two different events in 4, MB becomes a Redstone block and is completed in stage 14, and the calculation of the Redstone line is completed at 22, so here can be completed with 1gt for these two events
  2. The above picture also shows that the piston's half-extended state must be carved in Redstone. The same is true for some other phenomena. This picture does not appear to be shifted by 1gt to the left or right.

The above figure has clearly illustrated the delay of each original.

Capacitor zero delay

This phenomenon has already been discussed in the previous column and will not be elaborated on. The specific analysis of various circuit delays is not the focus here. I have the opportunity to elaborate on it in the future.

Burning torches, half pulse, and consumer judgment

Torches are the root of all evil

The torch is not a simple torch, but a capacitor with many parameters and special judgments.

Torch regular update

The calculation method of the new value of the torch is a bit different, so its signal source is always the block to which it is attached. If it is not attached to a Redstone block, it is not its direct signal source that participates in the calculation, but it. The signal source of the signal source, that is, the source of the square to which it is attached, is reasonable, such as the following circuit:max(signal- distance)

Example torch circuit

Here the only signal source of the torch is wool, and the only signal source of wool is the repeater, so the torch calculation signal is calculated by using the repeater as the signal. When it detects the source of the source, it provides the maximum value of the signal When it is greater than 0, it reverses itself and resets its burn value (the burn value is a parameter inside the torch, and the default is 0).

The directed graph corresponding to the torch circuit

To be honest, this is reasonable, but the key is here.

Torch Special Sentence

Since the torch is a capacitor, is it possible that the source of the torch is itself? The answer is completely possible, so please come out the famous torch circuit and comparison circuit:

Circuit that "burns torches"

Circuits that will not "burn" torches

Directed graph

The signal source of the torch in the left picture is itself, the signal source of torch 1 in the right picture is itself, and torch 2, and 2 are the same as 1. Then the question is, why does the left side burn but the right side does not Burn it?

Mojang made a special judgment for the circuit described below:

  • The signal source of the torch has one or more signal sources
  • The original that provides the greatest signal to the torch is itself

The torch Mojang Such signal is called herein a temporary half pulse represents halfPulse()

In Figure 1, when torch 1 has only one source, it must be itself that provides the signal. Therefore, the torch is judged as a half pulse. The same is true when 1rt is calculated again. It will always be Determined as a half-pulse circuit. Figure 2 is different. The source of the source that provides the largest signal to torch 1 is alternately 1 and 2 (the two torches are actually measured to turn on and off alternately, and other metaphysical situations have not been encountered ) 2 is the same, so this circuit The torch will be judged to generate a half pulse every 1rt (redstone tick)

Half pulse brings many characteristics:

If the torch is half-pulse, it will increase its burning value by +1, and when it is increased to 16, the clock will go out and no longer respond to external signals. This is the well-known phenomenon of torch burning.

If it is not a half pulse, clear the burn value to zero. Therefore, the burning value of the torch in Figure 2 has been jumping between 0 and 1, and the torch will not burn.

Fun fact: If Mojang changes <= to <when ​​looking for the source of the largest source in the code, then the torch circuit will no longer exist, which shows that this is the intention of MJ

Consumer response to half impulse

Do you think the torch is over? In fact, it is not. This half pulse is not useless. In the game, mojang gave the following five redstone originals a special half pulse treatment:

  • Door and Trap door
  • Dropper ?
  • Dispenser
  • Skull ????????

If you don't make a special judgment, according to the original logic, half pulse is useless at all. It can make all original ghosts like ordinary 2rt pulses, but Mojang has made another special judgment:

If the consumers who receive the half pulse are not the above five, they will force their signal source signal to be constant 15 to achieve the purpose of constant activation, but the Redstone line does not have this special judgment, so you can see the Redstone normally The line flickers, but you can’t see the light flickering and the piston pushing and pulling, as shown in the circuit below, the upper parts are not especially judged, the signal is forcibly set to 15-distance, and the root does not consider the strength of the signal source, so Often activated, but the following four especially judged originals are normal.

The observer’s face-to-face is not half-pulse. The constant light is the characteristic of the light. There are still 0-x signals in the light alternately.

The only half-pulse circuit that can be found at present is the one mentioned above. If you don't use this circuit, this article will no longer exist.

Looking at the behavior of the torch, I have to wonder whether Mojang has eaten too much or made another move. But what is certain is that the above analysis is not the full picture of the torch, because after various tests, the execution timing of the other part of the code is not found, and it is impossible to analyze, so the above features are sufficient in most cases

To be continued in 3.

source by hhhxiao