Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: Splitting the tick: The science of build order  (Read 9202 times)

Nil Eyeglazed

  • Bay Watcher
    • View Profile
Splitting the tick: The science of build order
« on: March 18, 2012, 01:20:46 pm »

Recently, I've been doing a lot of research on build order.  Because this stuff is tl;dr for a lot of folks, I'm going to start with the practical stuff:

Screw pumps pump in the reverse order in which they were built.  This is probably the most useful finding for most people.  By building top to bottom, you can maximize fluid throughput of a pump stack-- fluid climbing the stack will take z ticks to climb a stack built bottom-to-top, but only a single tick to climb a stack of any height built top-to-bottom.  You can also use this to make improved mist generators.  By building a climbing loop in the direction of water travel, you can guarantee that water spends a single tick in every tile of a mist generator-- to return to its reservoir tile and fall once again into the intake tile of the initial screw pump.

The gist of the theory is that buildings are evaluated from most recently built to first built.  Each building has its own routine it calls during its part of the tick.  The cool part is that all buildings do this.  By paying attention to build order, you can, for instance, pump water into a tile with a pressure plate, trigger that pressure plate with water, and then pump water back out of that tile, all in a single tick.

When you build a pressure plate before a bridge, the pressure plate evaluates its trigger conditions earlier in the tick than the bridge looks for an open signal, and so you get an open in 100 ticks.  When you build a pressure plate after a bridge, the bridge looks for the open signal, doesn't see one, and only later in the same tick does the plate send an open signal, leading to a 1 tick delay in the open signal.

There are some interesting oddities involved in this that I want to detail:

Hatches and doors don't evaluate their own open signals.  Unlike with other furniture, the opening of doors and hatches is not something affected by build order.  Instead, the triggering device opens the door/hatch itself.

The timing of a lever is determined by the 'build order' of the dwarf pulling it, not by the build order of the lever.  Mostly, this doesn't matter, because all dwarves are evaluated before any furniture is evaluated.  However, there's one very interesting experiment that I've done, that you can recreate.  Take two dwarves, and have them take turns pulling a lever to drop the other via the hatch.  One of the dwarves will consistently take 6 ticks to fall, while the other will take 7 ticks.  Why?  Because the hatch is opening before the first dwarf checks to see if he should fall, but after the second dwarf thinks about falling!  I think this is just so cool.  Dwarves, like furniture, appear to be evaluated in reverse order.

Gear assemblies appear to be unaffected by build order, but the actual delivery of power is affected by build order.  This is one of the weird ones.  If you build two gear assemblies, one built before and one after a toggling pressure plate, both gears will change from 'engaged' to 'disengaged' and vice versa on the same tick.  However, the engaged gear assembly built after the pressure plate will not actually deliver power on that tick, whereas the engaged gear assembly built before the pressure plate will!

I realize this kind of stuff isn't very interesting to very many people on the forums, but it's so interesting to me that I felt like I had to share.  If you want to about the various experiments I did to figure this out, I've been keeping an experiment journal at my wiki page.
« Last Edit: March 18, 2012, 02:07:13 pm by Nil Eyeglazed »
Logged
He he he.  Yeah, it almost looks done...  alas...  those who are in your teens, hold on until your twenties...  those in your twenties, your thirties...  others, cling to life as you are able...<P>It should be pretty fun though.

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Splitting the tick: The science of build order
« Reply #1 on: March 18, 2012, 01:29:20 pm »

I'm most curious about the fluid dynamics here.  If I'm reading this right, you can deliver a tile of magma from the bottom of the sea to the top of your pump stack in exactly 1 tick.  To do so, you'd need a "spiral staircase" design, building the top pump first and then each below it.  The issue is, you can't have a traditional forward-back stack this way, as each higher-level pump is built atop the one below it.  Although you could do a pump stack on solid flooring with a line of gear assemblies running down the whole length...

Regardless, if true, that allows for instant travel of fluids over great heights.  The only remaining question is "does it still calculate temperature for every stage?"  If yes, then you'll get a temperature change on each level.  If no, then your magma will zip straight to the top of the map and only perform a temperature check at the highest level.

You may have stumbled upon a lagless pumpstack.  Science?  Or, on a rare occasion for the forums, ‼Science‼ is a legitimate way to describe the science of magma.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: Splitting the tick: The science of build order
« Reply #2 on: March 18, 2012, 01:34:03 pm »

I'm most curious about the fluid dynamics here.  If I'm reading this right, you can deliver a tile of magma from the bottom of the sea to the top of your pump stack in exactly 1 tick.  To do so, you'd need a "spiral staircase" design, building the top pump first and then each below it.  The issue is, you can't have a traditional forward-back stack this way, as each higher-level pump is built atop the one below it.  Although you could do a pump stack on solid flooring with a line of gear assemblies running down the whole length...

Regardless, if true, that allows for instant travel of fluids over great heights.  The only remaining question is "does it still calculate temperature for every stage?"  If yes, then you'll get a temperature change on each level.  If no, then your magma will zip straight to the top of the map and only perform a temperature check at the highest level.

You may have stumbled upon a lagless pumpstack.  Science?  Or, on a rare occasion for the forums, ‼Science‼ is a legitimate way to describe the science of magma.
Those pump stacks indeed are intresting.
You'll need alot more gears, but i usually have enough idling dwarfs to fulfill that :P
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Nil Eyeglazed

  • Bay Watcher
    • View Profile
Re: Splitting the tick: The science of build order
« Reply #3 on: March 18, 2012, 01:38:12 pm »

I'm most curious about the fluid dynamics here.  If I'm reading this right, you can deliver a tile of magma from the bottom of the sea to the top of your pump stack in exactly 1 tick.  To do so, you'd need a "spiral staircase" design, building the top pump first and then each below it.  The issue is, you can't have a traditional forward-back stack this way, as each higher-level pump is built atop the one below it.  Although you could do a pump stack on solid flooring with a line of gear assemblies running down the whole length...

The pumps stacks that I'm familiar with (the ones I use) use alternating single tiles of flooring to support the pumps, and this style could be built from top-to-bottom.  Additionally, by building from top-to-bottom, you eliminate any risk of spilling-- it all goes there in one tick.

Quote
Regardless, if true, that allows for instant travel of fluids over great heights.  The only remaining question is "does it still calculate temperature for every stage?"  If yes, then you'll get a temperature change on each level.  If no, then your magma will zip straight to the top of the map and only perform a temperature check at the highest level.

I'm not totally sure, but the game does appear to evaluate flow (with dwarves) earlier than it evaluates any buildings.  (The validating experiment is that flow triggers a pressure plate on the tick it covers that plate, not the next.)  I would be really, really surprised if temperature was evaluated in the middle of evaluating buildings, so I would expect you would see no temperature variation in the middle of the pump stack.  I think you still need magma safe materials for every pump stack, but I would not expect temperature to ever, for instance, melt any items sitting in any intake/output tiles in the middle of the stack.
Logged
He he he.  Yeah, it almost looks done...  alas...  those who are in your teens, hold on until your twenties...  those in your twenties, your thirties...  others, cling to life as you are able...<P>It should be pretty fun though.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: Splitting the tick: The science of build order
« Reply #4 on: March 18, 2012, 01:45:58 pm »

I'm most curious about the fluid dynamics here.  If I'm reading this right, you can deliver a tile of magma from the bottom of the sea to the top of your pump stack in exactly 1 tick.  To do so, you'd need a "spiral staircase" design, building the top pump first and then each below it.  The issue is, you can't have a traditional forward-back stack this way, as each higher-level pump is built atop the one below it.  Although you could do a pump stack on solid flooring with a line of gear assemblies running down the whole length...

The pumps stacks that I'm familiar with (the ones I use) use alternating single tiles of flooring to support the pumps, and this style could be built from top-to-bottom.  Additionally, by building from top-to-bottom, you eliminate any risk of spilling-- it all goes there in one tick.

Quote
Regardless, if true, that allows for instant travel of fluids over great heights.  The only remaining question is "does it still calculate temperature for every stage?"  If yes, then you'll get a temperature change on each level.  If no, then your magma will zip straight to the top of the map and only perform a temperature check at the highest level.

I'm not totally sure, but the game does appear to evaluate flow (with dwarves) earlier than it evaluates any buildings.  (The validating experiment is that flow triggers a pressure plate on the tick it covers that plate, not the next.)  I would be really, really surprised if temperature was evaluated in the middle of evaluating buildings, so I would expect you would see no temperature variation in the middle of the pump stack.  I think you still need magma safe materials for every pump stack, but I would not expect temperature to ever, for instance, melt any items sitting in any intake/output tiles in the middle of the stack.
Only one way to find out.
(actually, two, but it seems much more easy to build a pumpstack then to decompile and find the code, then determine if that is the right code :P)
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Splitting the tick: The science of build order
« Reply #5 on: March 18, 2012, 01:49:04 pm »

I can personally confirm the screw pump build order stuff - I actually discovered it back in 40d and used it in several of my fortresses. Some of the other parts have been detailed elsewhere (including the pressureplate/bridge timing stuff which was relevant to some repeater designs), but it's nice to have this all in a single forum post.
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Kofthefens

  • Bay Watcher
  • Keep calm and OH GOD CAPYBARAS
    • View Profile
    • Marshland Games
Re: Splitting the tick: The science of build order
« Reply #6 on: March 18, 2012, 01:52:07 pm »

Well !!scienced!!
Logged
I don't care about your indigestion-- How are you is a greeting, not a question.

The epic of Îton Sákrith
The Chronicles of HammerBlaze
My website - Free games

Nil Eyeglazed

  • Bay Watcher
    • View Profile
Re: Splitting the tick: The science of build order
« Reply #7 on: March 18, 2012, 02:04:01 pm »

I can personally confirm the screw pump build order stuff - I actually discovered it back in 40d and used it in several of my fortresses. Some of the other parts have been detailed elsewhere (including the pressureplate/bridge timing stuff which was relevant to some repeater designs), but it's nice to have this all in a single forum post.

Yeah, I ought to give credit where it's due.  In my case, I first discovered the idea that build order affects pump operation on Hussell's wiki page.  All I've done are confirming experiments, as well as, maybe, put together a somewhat cohesive theory of build order.  The theory was probably obvious to some people.  To me, though, build order used to be a collection of disparate facts, and now I feel like I understand it as a unified thing.
Logged
He he he.  Yeah, it almost looks done...  alas...  those who are in your teens, hold on until your twenties...  those in your twenties, your thirties...  others, cling to life as you are able...<P>It should be pretty fun though.

Sphalerite

  • Bay Watcher
    • View Profile
    • Drew's Robots and stuff
Re: Splitting the tick: The science of build order
« Reply #8 on: March 18, 2012, 02:51:03 pm »

In some of my own experiments with computing devices, I use a rotation sensor which consists of a screw pump with a pressure plate under its inlet.  When the pump is running, water is pulled out of the inlet space, which triggers the pressure plate which is set to trigger when no water is on it.  I have found that it is critical that the pressure plate be built before the screw pump in order for it to work reliably.
Logged
Any intelligent fool can make things bigger and more complex... It takes a touch of genius --- and a lot of courage to move in the opposite direction.

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Splitting the tick: The science of build order
« Reply #9 on: March 18, 2012, 03:58:31 pm »

I'm now curious if you could design an instant-function computer of sorts.  Have a line of in-sequence pumps, and you can instantly trigger all the plates there at once.  The only issue is that there's no actual computing involved, just triggers.  You could link it with an AND gate, but all the methods I can think to do that would slow it down to regular computing speed...

Nil Eyeglazed

  • Bay Watcher
    • View Profile
Re: Splitting the tick: The science of build order
« Reply #10 on: March 18, 2012, 04:13:48 pm »

I'm now curious if you could design an instant-function computer of sorts.  Have a line of in-sequence pumps, and you can instantly trigger all the plates there at once.  The only issue is that there's no actual computing involved, just triggers.  You could link it with an AND gate, but all the methods I can think to do that would slow it down to regular computing speed...

You can do instant computing, and it's being talked about here.  The problem is that it's very difficult to create many kinds of gates using only screw pumps.  If somebody manages to create several good types of pump-only gate, then any number of computations could be completed in a single tick.

Some kinds of computing can already be improved immeasurably by means of paying attention to build order.  Consider a 8-bit bit rotation, which is important for some programmable tasks.  Classic computing means using an intermediary byte to hold transferred values, waiting for all transfers to complete, then writing back to your original byte.  This is two read accesses and two write accesses.  By using carefully ordered pumps, you can instead complete this operation in a single tick.  Technology to do so already exists, because the only thing you need is identity.

Another example is a ripple-carry adder.  Ripple carries are slow, and an 8 bit ripple carry will probably take a classic DF computer about a day to complete.  If you can make a good XOR and a good AND (a NOT simplifies things immensely), you could complete a ripple carry add, of any length, in a single tick.

This isn't really new, because load-based mechanical logic has always been capable of instantaneous computation.  Load-based mechanical logic isn't very intuitive though, and it requires some bizarre power setups.  You can't just make a reactor and link to your system, you have to link separate reactors to each gate.

DF computation isn't important to very many people though-- I think there's probably about 10 of us in the world :)
Logged
He he he.  Yeah, it almost looks done...  alas...  those who are in your teens, hold on until your twenties...  those in your twenties, your thirties...  others, cling to life as you are able...<P>It should be pretty fun though.

Frogwarrior

  • Bay Watcher
    • View Profile
Re: Splitting the tick: The science of build order
« Reply #11 on: March 18, 2012, 05:39:41 pm »

Hm, sounds like similar to how doors and hatches are updated by the trigger mechanism itself, so are gearboxes; then power delivery updates when the gearbox does.
Logged
Lately, I'm proud of MAGMA LANDMINES:
http://www.bay12forums.com/smf/index.php?topic=91789.0
And been a bit smug over generating a world with an elephant monster that got 87763 sentient kills.
http://www.bay12forums.com/smf/index.php?topic=104354.0

Nil Eyeglazed

  • Bay Watcher
    • View Profile
Re: Splitting the tick: The science of build order
« Reply #12 on: March 20, 2012, 08:57:04 pm »

So, I did a bit of testing on 0-tick magma-- magma that's moved into a tile and moved back out during the same tick.

Flammable things in the tile the magma moves through catch fire.  Adjacent stone heats up, just like regular magma.

But dwarves can move through the tile perfectly safely.  They don't get covered with magma, their clothes don't catch fire, they don't get wounded, etc.  I've got a dwarf removing a construction from a tile that magma is popping through (about every 30 ticks or so, probably) and no problems.
Logged
He he he.  Yeah, it almost looks done...  alas...  those who are in your teens, hold on until your twenties...  those in your twenties, your thirties...  others, cling to life as you are able...<P>It should be pretty fun though.

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Splitting the tick: The science of build order
« Reply #13 on: March 20, 2012, 08:58:52 pm »

So to confirm, 0-tick magma stacks still incur an FPS penalty of temperature updates?

Nil Eyeglazed

  • Bay Watcher
    • View Profile
Re: Splitting the tick: The science of build order
« Reply #14 on: March 20, 2012, 09:13:19 pm »

Used hack/probe to determine temperature.  Not sure what the temperature1 / temperature2 distinction is.  Zero-tick magma tile shows 11450/10015, compared to 10015/10015 for control tile and 12000/12000 for the magma.

So to confirm, 0-tick magma stacks still incur an FPS penalty of temperature updates?

Probably does still incur that penalty, yes.
Logged
He he he.  Yeah, it almost looks done...  alas...  those who are in your teens, hold on until your twenties...  those in your twenties, your thirties...  others, cling to life as you are able...<P>It should be pretty fun though.
Pages: [1] 2