Arithmetic optimization: what does it mean in MUGEN and does it matter? (Read 3672 times)

Started by Jesuszilla, March 22, 2017, 05:31:15 am

Jesuszilla

Arithmetic optimization: what does it mean in MUGEN and does it matter?
#1  March 22, 2017, 05:31:15 am
• Loyal to the Game

• Online
First, let me give you a little bit of context as to what the following simplified buffering helper snippet does:
Code:
`[State 10380, Charge Back]type = VarAddtriggerall = var(24) = [256,255+48]trigger1 = p2dist X >= 0trigger1 = command = "holdback"trigger2 = p2dist X < 0trigger2 = command = "holdfwd"var(24) = -1`

Now if you don't know why I'm starting at 256, read my previous tutorial on binary logic. But basically, I'm using the lower 8 bits to store the buffer time, meaning I can store a buffer time of up to 255 ticks. Powers of 2 are easier to align but I digress.

Four years ago, I would've gone "Don't make the machine do unnecessary work! Just type:"
Code:
`triggerall = var(24) = (255,303]`

But years of experience has taught me one thing: who gives a shit? Computers certainly don't. Addition is typically one assembly instruction. Has been for a long time. Hell, so is multiplication. What's really tough for computers is division, but unless you're 3D modeling or performing complex matrix operations (which I challenge you to try in MUGEN, and I'm not just being a smartass, it would legitimately be interesting to see something as cool as Bia's Bézier curves again), it really doesn't matter. This is MUGEN, after all.

We hear a lot about optimization in MUGEN, as we do in all of computing. However, what many seem to misunderstand is that optimization in MUGEN is less about time performance and more about readability and using as few variables as possible. The latter is why many of creators use bitwise operators. But this can make readability a bit of a pain.... to people who don't know much about computing. Which is nearly everyone, even if they've been doing MUGEN creation for several years.

So we have to compensate for this usage with readability. This is why even statements such as:
Code:
`[State 10380, Charge Back]type = VarAddtriggerall = var(24) = [256,255+48] ; 48 tickstrigger1 = p2dist X >= 0trigger1 = (var(3)&68) > 0  ; holdbacktrigger2 = p2dist X < 0trigger2 = (var(3)&136) > 0 ; holdfwdvar(24) = -1`

... are actually much more readable than statements like:
Code:
`[State 10380, Charge Back]type = VarAddtriggerall = var(24) = [256,303]trigger1 = p2dist X >= 0trigger1 = command = "holdback"trigger2 = p2dist X < 0trigger2 = command = "holdfwd"var(24) = -1`

And guess what? They have minimal, if any effect, on performance! Even though MUGEN is a scripting language, its parser isn't that bad. Just get over it, it's easier to modify and understand in this context.

Good for you. But it's much more readable when I tell you exactly how many ticks are being used, and it's clearer when I show this with using the exact number of ticks from the base value. And it costs your processor nothing.

"But the binary statements for commands are scary!"
I tell you what they are and it's clear what they do. It's just like reading "command = whatever." You'd be surprised how quickly you can memorize (and how long you can retain) numbers! Besides, you don't have to do this, nor do I recommend it if you don't understand it completely (when Warusaki switched to using bitwise operators, I didn't switch immediately either; it wasn't until I took university courses that I fully understood the use of these functions).

Jango

Re: Arithmetic optimization: what does it mean in MUGEN and does it matter?
#2  March 22, 2017, 02:30:05 pm
• Double-Crosser
• I'm not standing out. This isn't weird at all.
To an outsider, those commands look nothing alike unless you just happen to know that the "easy" one references your command buffering system, and if someone just takes your word for it and just copy-pastes it without implementing said system, they'll find their attack doesn't work.

ink

Re: Arithmetic optimization: what does it mean in MUGEN and does it matter?
#3  March 22, 2017, 03:16:07 pm
• inktrebuchet
"But the binary statements for commands are scary!"
I tell you what they are and it's clear what they do. It's just like reading "command = whatever." You'd be surprised how quickly you can memorize (and how long you can retain) numbers! Besides, you don't have to do this, nor do I recommend it if you don't understand it completely (when Warusaki switched to using bitwise operators, I didn't switch immediately either; it wasn't until I took university courses that I fully understood the use of these functions).
This is me. No matter how many times I have read through those topics, I still can not wrap my head around this idea. It's just over my head at this point and it drives me crazy! I think I may need those university courses too...

Odb718

Re: Arithmetic optimization: what does it mean in MUGEN and does it matter?
#4  March 22, 2017, 09:25:10 pm
• Shame on you!
This reminds me a lot of the 6502 stuff I was working with on my Metroid.nes hack. I was working with 8bits to control the title screen's effects.

One thing that's not really explained is the "&"
trigger2 = (var(3)&136) > 0 ; holdfwd

[State -2, Powers of Two]
trigger1 = !(Var(4)&2)
var(4) = 2

But it still doesn't really explain what & does.
vVv Wheat Stage Released vVv

Jesuszilla

Re: Arithmetic optimization: what does it mean in MUGEN and does it matter?
#5  March 23, 2017, 01:33:11 am
• Loyal to the Game

• Online

ARMOR CAGE

Re: Arithmetic optimization: what does it mean in MUGEN and does it matter?
#6  March 26, 2017, 12:24:07 am
I do not care hehe, but seriously arithmetic optimization is one of the optimizations that can be made.
Does it matter? - only if you are doing something more complicated than what Mugen was created for.

Jesuszilla

Re: Arithmetic optimization: what does it mean in MUGEN and does it matter?
#7  March 29, 2017, 11:38:42 pm
• Loyal to the Game

• Online
That's exactly what I'm saying, you really shouldn't care about optimizing something that doesn't need it. In programming languages that are actually compiled, the compiler usually does that for you, so it's better to have readable code.

ARMOR CAGE

Re: Arithmetic optimization: what does it mean in MUGEN and does it matter?
#8  March 30, 2017, 01:00:32 am
But I will admit that I mix a bit in the code, sometimes, and sometimes you will notice some speed drops, but rather on a weak computer, I noticed this on a computer where I sometimes had problems with full HD add-ons. So Mugen, despite the complexity of the code, somehow does well. So You can play it a bit, Especially today.
Code:
`[State 0, VarSet]type = VarSettriggerall = Var(14) = 0 && helper(4),Vel Y > 0triggerall = helper(4),RootDist Y - helper(4),Const(size.ground.front) - helper(4),Vel Y < RootDist Y + Const(size.height)triggerall = helper(4),RootDist X*-1 + (helper(4),Const(size.height)/2) > RootDist X*-1triggerall = helper(4),RootDist X*-1 - (helper(4),Const(size.height)/2) < RootDist X*-1 + Const(size.ground.front)trigger1 = helper(4),RootDist X*-1 < RootDist X*-1 + (Const(size.ground.front)/2)trigger1 = helper(4),RootDist Y > RootDist Y + Const(size.height) - ( (Const(size.height)/Const(size.ground.front))*(helper(4),RootDist X*-1 - RootDist X*-1) )trigger2 = helper(4),RootDist X*-1 >= RootDist X*-1 + (Const(size.ground.front)/2)trigger2 = helper(4),RootDist Y > RootDist Y + Const(size.height) - ( (Const(size.height)/Const(size.ground.front))*(RootDist X*-1 + Const(size.ground.front) - helper(4),RootDist X*-1) )v = 14value = 2[State 300, blok kierunku w dol]type = VarSettrigger1 = 1;root,command = "holddown"v = 3value = helper(16),Var(2)+helper(17),Var(2)+helper(18),Var(2)+helper(19),Var(2)+helper(20),Var(2)+helper(21),Var(2)+helper(22),Var(2)+helper(23),Var(2)+helper(24),Var(2)+helper(25),Var(2)+helper(26),Var(2)+helper(27),Var(2)+helper(28),Var(2)+helper(29),Var(2)+helper(30),Var(2)+helper(31),Var(2)+helper(32),Var(2)+helper(33),Var(2)+helper(34),Var(2)+helper(35),Var(2)+helper(36),Var(2)+helper(37),Var(2)+helper(38),Var(2)+helper(39),Var(2)+helper(40),Var(2)+helper(41),Var(2)+helper(42),Var(2)+helper(43),Var(2)+helper(44),Var(2)+helper(45),Var(2)+helper(46),Var(2)+helper(47),Var(2)+helper(48),Var(2)+helper(49),Var(2)+helper(50),Var(2)[State 401, 13 pocisk leci Y]type = VarSettriggerall = Var(22) != 0trigger1 = (Var(22)-(floor(Var(22)/10)*10)) = 3 || (Var(22)-(floor(Var(22)/10)*10)) = 6 || (Var(22)-(floor(Var(22)/10)*10)) = 7fv = 25value = fVar(25) + ( root,const(velocity.run.fwd.x) * IfElse(((Var(22)-(floor(Var(22)/10)*10)) > 4),0.7,1) )`

Posted: March 30, 2017, 10:15:18 pm
Here is an example to check if anyone would like to look

https://www.sendspace.com/file/co0w2b

Jesuszilla

Re: Arithmetic optimization: what does it mean in MUGEN and does it matter?
#9  March 31, 2017, 07:47:29 pm
• Loyal to the Game