Wednesday, January 11, 2012

CAOS Notes: WOLF

From the CAOS documentation:

WOLF (integer) kanga_mask (integer) eeyore_mask (integer)
Provides various functions to distort space-time and otherwise help with wolfing runs. Set an AND and an EOR mask, to control the following bits:
1 - Display rendering. Turning it off speeds the game up.
2 - Fastest ticks. The game usually runs at a maximum of 20 frames per second. If this is set, it instead runs as fast as it can.
4 - Refresh display at end of tick. If set, then the display is updated at the end of the tick, and the flag is cleared.
8 - Autokill. If set, agents which generate run errors are automatically killed, as the command line option.

This can be a pretty confusing command to understand. It seems, just by glancing at the bits that this would work something like ATTR, wherein, say, if you wanted to have both autokill and fast ticks on, it would total to 10. But knowing that, where do these "kanga" and "eeyore" masks come in?

It's a little complex, but once you get the hang of how this works, it's really pretty neat. In fact, I kind of wish ATTR and BHVR worked this way-- you could accomplish more in fewer lines of code.

The thing about WOLF is that it's an integer, not a command. You can't set WOLF by just entering WOLF 8 or whatever, like you would with ATTR and BHVR. You have to actually set it as though it were a variable to alter it.

To find out what your game's WOLF currently is, open the command line and enter outv wolf 15 0. Why 15 and 0? We'll get to that.

Depending on your autokill status, your game probably returned 1 or 9. 1 being on for display rendering, and 8 being added to that if your autokill is on.

So here's a bit of mental review; WOLF only has four traits to worry about, so it's easy to take an output value and do the math in your head. So if your WOLF returned 15, what traits would be "on"? What if it returned 12? 7? 0? You'll have to have a decent grasp on this to understand how WOLF works.

15 would mean, yes, that all four traits, Display (1), Fast Ticks (+2), Refresh (+4), and Autokill (+8) are on. 12 would mean only Refresh (4) and Autokill (+8) are on, and 7 means Display (1), Fast Ticks (+2), and Refresh (+4) are on. 0 implies that no traits are on at all. This might be elementary to you by now from working with similar constructs in ATTR and BHVR.

Bear with me-- let's repeat the exercise looking for different answers. If WOLF returned 15, what traits would be "off"? What of 12, 7, or 0?

I'm sure you're clever enough to figure out the answers are the opposite of the above-- if a trait isn't on, it's obviously off. So 15 would have no "off" traits, 12 would have Display and Fast Ticks off, 7 means Autokill is off, and 0 means that all four traits are off.

I hope this exercises aren't totally fruitless-- the point that when you glance at a WOLF number, you need to think of it in terms of both what traits are off, as well on.

So now that your WOLF deciphering muscles are working, let's dive into the hard stuff: The masks.

These four "rules" here are all you need to know to decipher what your AND ("Kanga") and OR ("Eeyore") masks need to be:

1. If a trait is off in the AND mask and on in the OR mask, the resulting trait will be on.
2. If a trait is off in the AND mask and off in the OR mask, the resulting trait will be off.
3. If a trait is on in the AND mask and off in the OR mask, the resulting trait will be the same.
4. If a trait is on in the AND mask and on in the OR mask, the resulting trait will be the opposite.


Using these masks, then, you will essentially be able to, in one line, set your wolf controls any way you want them, even taking into account what they already are.

Let's go back to the line we used: outv wolf 15 0.
In this case, 15 is the AND mask, and 0 is the OR mask. That means that all the traits are on in the AND mask and off in the OR mask, which, according to rule 3, the traits will remain the same, unchanged, and the output will be the current WOLF value.

But let's say we wanted to turn all the traits on. To turn a train on, we have to follow rule 1, and make sure all the traits are off in the AND mask (making it 0) and on in the OR mask (making it 15). So we would outv wolf 0 15, which should return 15 and, depending on your computer, may make your world look like it's in super-speed mode (due to both fast ticks and rendering being on).

Before I go any further I need to address something odd before all sorts of questions come up. WOLF is a little bit odd in that 1 (Display) and 4 (Refresh) cannot be on at the same time. If the game is displaying rendering, there's obviously then no reason to refresh the display as it's already being refreshed. So if you set WOLF to 15, 5, 7, or any value that sets both Display and Refresh to on, the engine will automatically turn refresh back off after setting it. So even if you use outv wolf 0 15 to set the WOLF to 15, if you enter outv wolf 15 0 to check it, you'll get back 11, since refresh has been turned off. As far as I can tell, Display always overrides Refresh, not vice versa.

Anyway, now that that's out of the way.

Quiz time again: What would outv wolf 0 0 do?

Since all traits are off in both AND and OR masks, we would look to rule 2, which tells us all the traits will be off. Thus the above command would set your WOLF to 0. It will also sort of freeze up your game, since Display is off-- opening and closing Wolf Control will reset it to normal.

But let's get down to practical information now-- if you're coding something interesting, chances are you're not looking to turn everything on and off at once. Let's try a line that toggles fast ticks on and off. This will really only be apparent on machines that are fast enough to benefit from fast ticks with the display still running-- you might want to try it in a clean and undocked DS world if you're not seeing the difference.

outv wolf 15 2

Enter that once and watch your game spaz out. Enter it again and watch it return to normal.
Can you decipher why this works? This table might help explain exactly what's going on in this command:

AND OR Rule Result
Value 15 2 * *
1 - Display ON OFF 3 Same
2 - Fast Ticks ON ON 4 Opposite
4 - Refresh ON OFF3Same
8 - Autokill ON OFF 3 Same

So setting up the masks this way allows for all the other traits to stay the way they are, while fast ticks is set to toggle (turn off if it was already on, turn on if it was off). In fact, you could use this table as a tool to work backwards from to find the masks for virtually anything you want to accomplish.

Say you want to make a switch that turns Display on, toggles Fast Ticks, turns Refresh off, and leaves Autokill the way it is. You would start with a table like this, putting in your own desired results.

AND OR Rule Result
Value ? ? * *
1 - Display ? ? ? On
2 - Fast Ticks ? ? ? Opposite
4 - Refresh ? ??Off
8 - Autokill ? ? ? Same

Next you look at the rules that would give you those desired results. I'm going to paste them again so you don't have to scroll all the way back up:

1. If a trait is off in the AND mask and on in the OR mask, the resulting trait will be on.
2. If a trait is off in the AND mask and off in the OR mask, the resulting trait will be off.
3. If a trait is on in the AND mask and off in the OR mask, the resulting trait will be the same.
4. If a trait is on in the AND mask and on in the OR mask, the resulting trait will be the opposite.

So if you want Display to be on, you'll have to find the rule that gives you the on result. Since that is rule one, you'll want to follow it, setting the trait off in the AND mask and on in the OR mask:

AND OR Rule Result
Value ? ? * *
1 - Display OFF ON 1 On
2 - Fast Ticks ? ? ? Opposite
4 - Refresh ? ??Off
8 - Autokill ? ? ? Same

Now just fill in the rest of the chart, following the rules reversely.
To get opposite fast ticks, follow rule 4 and set both masks to on
To turn refresh off, follow rule 2 and set both masks to off.
Finally, to keep autokill the same, follow rule 3 to set AND to on and OR to off.
In the end, you should have something like this:

AND OR Rule Result
Value ? ? * *
1 - Display OFF ON 1 On
2 - Fast Ticks ON ON 4 Opposite
4 - Refresh OFF OFF2Off
8 - Autokill ON OFF 3 Same

What does that leave? Just adding up the values of your on traits. Fast ticks (2) and Autokill (8) are on in your AND mask, totally to 10, while Display (1) and Fast Ticks (2) are on in your OR mask, totaling 3.

AND OR Rule Result
Value 10 3 * *
1 - Display OFF ON 1 On
2 - Fast Ticks ON ON 4 Opposite
4 - Refresh OFF OFF2Off
8 - Autokill ON OFF 3 Same

And that means, to set these values via the command line, outv wolf 10 3.

And that, my friends, is how you spend 14 hours using WOLF to set some settings you will probably never use.

You're probably going to pull your eyes out of your head and cry when I reveal the absolutely trivial purpose I have behind working all this out.

TL;DR:
I don't blame you. Screw it, I'll just write up a WOLF calculator someday.

1 comment: