| Эта статья нуждается в переработке.
Причина: требуется перевод
|Часть серии статей о|
|Логика: животная • существ • жидкостная • механическая • вагонеточная|
|Компоненты: Сумматор • Память • Повторитель|
Память используется для сложения чисел и состояний в дварфийской компьютерной системе. Обычно используется бинарная память, но это не обязательно. Здесь показаны различные способы создания клетки памяти, в зависимости от того, что вы используете, будь то механическую логику, жидкостную логику, логику существ, или вагонеточную логику. С бинарной памятью, каждая клетка будет иметь два состояния — 0 и 1, или же ложь и истина.
Триггеры против защёлок[править]
Наиболее базовая характеристика памяти в Dwarf Fortress заключается в том, что что она действует как разделитель сигналов: даётся серия on-off сигнальных циклов, и выходит серией переменных on или off сигналов. Память, действующая по такой, и только такой, схеме, работает как триггер: каждый раз вы воздействуете на ячейку памяти, она меняет состояние. Такая память идеально подходит для таких устройств, как счетчики. Тем не менее, обычно хочется иметь возможность непосредственно изменять состояние памяти вместо того, чтобы переключать его, т. е. писать либо истину или ложь в память самому, без знания текущего состояния памяти. Это можно описать таблицей, в которой значение памяти возвращается обратно в себя:
|Вход||Состояние защёлок||Выход||Новое состояние защёлок|
Memory systems in a dwarf fortress, thankfully, are very good at maintaining their value (in the absence of any trolls), but they are still plagued by problems with latency and long refractory periods. Latency refers to the length of time before which a change in value will register, and the refractory period refers to the period after writing to memory during which one cannot reliably write to it a second time. Because of the delays involved with pressure plates, latency and refractory period for a given memory cell often depend on which state the memory is being changed to. For instance, the mechanical hybrid cell below has nearly no latency when being written as true, but around 100 ticks of latency when being written as false.
Some designs can trade simplicity or material needs for costs in performance.
Simple fluid logic latches rely on an infinite source and infinite drain, storing information in the form of the presence or absence of water in a particular location.
In this design, water flows from an infinite source
~ over an output pressure plate
^ toward an infinite drain
~. Its flow is controlled by two floodgates,
X, linked to two separate inputs. When
X is open and
X closed , water will cover
^ and remains so, regardless of the state of
X is opened while
X is closed, water will leave
^ and the tile will remain empty of water until
X opens again.
This design has relatively high latency, because of the 100 tick delay associated with floodgates. Replacing the floodgates with doors, which have no reaction delay, greatly accelerates the response of the latch, but the overall performance is still limited by the reset period of pressure plates. Given careful enough design and sufficient water pressure, the latency of a write to true can approach 10, with the latency of a write to false around 110.
In this circuit, a creature placed between in the middle seeks its pathing goal
p but is constrained by the hatches
¢, each linked to the pressure plate
^ of the same color. When the door
+ is opened, the creature can move to the left (false)
^, and when the door
+ is opened, the creature can move to the right (true)
^, thus outputting to anything linked to that pressure plate. This is an example of memory for which it is possible to write a particular state, rather than just toggling, which allows for simpler design for some applications. Note also that rather than writing on a single on or off signal, it depends on an on-off cycle.
This design has good latency for creature logic systems, resulting in on signals around 40 ticks after writes and off signals around 150 ticks after writes. It has a 110 tick refractory period, representing the time necessary for the hatch covers to close.
A gear assembly can function all on its own as a memory cell, being either active or disengaged. However, some complicated applications suggest the use of hybrid mechanical-fluid memory.
In this design, two separately powered pump stacks,
%, are placed over each other-- the lower one, pumping to the right, and the higher one pumping to the left. When the water
~ is lying in the rightmost (true) cell, it activates a pressure plate
^. To write true to the memory, one triggers the lower gear assembly
☼, activating the lower pump, and to write false, one activates the higher gear assembly
☼ and pump stack. Like the creature logic memory above, this cell can be written as specifically true or false, and depends on an on-off cycle as input.
This design has very good latency (from almost nothing for a write as true to 100 ticks for a write as false) and no real refractory period-- it can be written to immediately following a previous write, although it does depend on the completion of the previous write signal (receiving the off component of the signal) before writing again.
Memory versus Power-to-signal[править]
It can be tricky to differentiate memory from power to signal conversion. Through feedback, power-to-signal devices can often be changed into memory cells, and powered memory devices can be adapted into power-to-signal. Previous to the introduction of minecarts, the most common power-to-signal device bore strong resemblance to the memory cell described above. There is, however, a large difference between memory and power-to-signal. While memory designs receive on-off signal cycles and output discrete on or off signals in return, power-to-signal converters translate one type of binary information (power on/off) into another (signal on/off). That is, a signalling device that receives then loses power should return a full on-off signal cycle.
There are numerous ways for minecarts to hold information. Some memory designs use movement or the absence of movement; others use just the position of a minecart. Advanced designs could use the weight or direction of movement of a minecart. The following powered minecart design by Bloodbeard is the smallest memory circuit currently known to dwarvenkind:
Key: O O Wall [#0:0][@6:0][%254][#2:1][@][%15] [#0:0][@6:0][%254][#@] Copper minecart [#0:0][@7:0][%254][#@] [#0:0][@7:0][%254][#@] Iron minecart [#7:1][@][%207][#2:0][%15][#] [#2:1][%15][#2:0][%15][#] Gears O [#7:1][%207][#] Rollers [#5:1]^[#] Pressure plate O [#7:1][%186][#] Minecart tracks [#7:1][%207][#2:1][@][%15] [#7:1][%210] [%208][#] Track ends [#5:1]^ [#7:1][%207][#2:0][%15][#] O O [#7:1][%210][#2:1][@][%15] [#7:1][%186] [%208][#2:0][%15][#] O
The diagram shows the minecart layer at the top, the roller/furniture layer in the middle, and finally the track layer at the bottom. When the northern gear assembly is activated, powering the northern roller, a heavy minecart (copper, in this example) is pushed southwards. This pushes a lighter minecart (iron here) south, and triggers a pressure plate that is built to only signal on the weight of a copper minecart, and not on the weight of the lighter iron minecart. With the activation of the southern gear assembly, the situation reverses. The iron minecart pushes on to the pressure plate, and an off signal is sent.
In complicated designs, one may wish to use a memory cell abstractly-- to represent any number of different values. To use multiple such abstract cells, it's necessary to specify exactly which memory cell one wishes to read from or write to at any given moment.
This is simplest in mechanical logic. A grid of gear assemblies can represent rows and columns, and by disengaging control gears for all but the cell that lies at that particular row/column intersection, one can easily refer to a specific cell. Strict fluid logic can do something similar, by controlling the input of water to memory cells, although this involves long delays. With the creature logic design, one can use additional doors to restrict writes to any cells not referenced.
Because most memory is used for a specific application, there is no single best design. It is not uncommon to see functionality built into memory circuits-- a simple circuit that increments contains its own memory. Alternate designs are important when memory needs to be written to in various ways (toggle versus specific value) or when latency and refractory period are unimportant compared to resource requirements such as space.