YesNoOk
avatar

The best way to economize Vars (Bit-flag) (Read 11846 times)

Started by Dr.Chapatín, November 02, 2014, 05:06:48 pm
Share this topic:
The best way to economize Vars (Bit-flag)
#1  November 02, 2014, 05:06:48 pm
  • avatar
  • ****
  • Ya me dio cosa...
    • Mexico
"Simple Megaman example"

[_1_][_2_][_3_]
[_4_][_0_][_5_]
[_6_][_7_][_8_]

States 1000-1999 -> Ringman's stuff
Code:
...
[Statedef 1999]; Get equipped with
type=S

[State 1]
type=Varadd
trigger1 = !Time
v=1
value = 2 ** 1 ;<--[_1_]
...

States 2000-2999 -> Diveman's stuff
Code:
...
[Statedef 2999]; Get equipped with
type=S

[State 2]
type=Varadd
trigger1 = !Time
v=1
value = 2 ** 2 ;<--[_2_]
...

States 3000-3999 -> Skullman's stuff
Code:
...
[Statedef 3999]; Get equipped with
type=S

[State 3]
type=Varadd
trigger1 = !Time
v=1
value = 2 ** 3 ;<--[_3_]
...

States 4000-4999 -> Pharaohman's stuff
Code:
...
[Statedef 4999]; Get equipped with
type=S

[State 4]
type=Varadd
trigger1 = !Time
v=1
value = 2 ** 4 ;<--[_4_]
...

States 5000-5999 -> Brightman's stuff
Code:
...
[Statedef 5999]; Get equipped with
type=S

[State 5]
type=Varadd
trigger1 = !Time
v=1
value = 2 ** 5 ;<--[_5_]
...

States 6000-6999 -> Toadman's stuff
Code:
...
[Statedef 1999]; Get equipped with
type=S

[State 6]
type=Varadd
trigger1 = !Time
v=1
value = 2 ** 6 ;<--[_6_]
...

States 7000-7999 -> Drillman's stuff
Code:
...
[Statedef 7999]; Get equipped with
type=S

[State 7]
type=Varadd
trigger1 = !Time
v=1
value = 2 ** 7 ;<--[_7_]
...

States 8000-8999 -> Dustman's stuff
Code:
...
[Statedef 8999]; Get equipped with
type=S

[State 8]
type=Varadd
trigger1 = !Time
v=1
value = 2 ** 8 ;<--[_8_]
...

States 10000-10999 -> Painel
Code:
...
[Statedef 10000] ;Show the weapons
type=S

[State 1]; Ringman
type=Explod
triggerall=!Time
trigger1 = ( Var(1) > = 2 ** 1 )  ;Must have this value [_1_]
trigger1 = ( Var(1) % ( 2*(2 ** 1) ) >=( 2 ** 1 ) ) ;Study ;p
anim=801
...
[State 2]; Diveman
type=Explod
triggerall=!Time
trigger1 = ( Var(1) > = 2 ** 2 )  ;Must have this value [_2_]
trigger1 = ( Var(1) % ( 2*(2 ** 2) ) >=( 2 ** 2 ) ) ;Study ;p
anim=802
...
[State 3]; Skullman
type=Explod
triggerall=!Time
trigger1 = ( Var(1) > = 2 ** 3 )  ;Must have this value [_3_]
trigger1 = ( Var(1) % ( 2*(2 ** 3) ) >=( 2 ** 3 ) ) ;Study ;p
anim=803
...
[State 4]; Pharaohman
type=Explod
triggerall=!Time
trigger1 = ( Var(1) > = 2 ** 4 )  ;Must have this value [_4_]
trigger1 = ( Var(1) % ( 2*(2 ** 4) ) >=( 2 ** 4 ) ) ;Study ;p
anim=804
...
[State 5]; Brightman
type=Explod
triggerall=!Time
trigger1 = ( Var(1) > = 2 ** 5 )  ;Must have this value [_5_]
trigger1 = ( Var(1) % ( 2*(2 ** 5) ) >=( 2 ** 5 ) ) ;Study ;p
anim=805
...
[State 6]; Toadman
type=Explod
triggerall=!Time
trigger1 = ( Var(1) > = 2 ** 6 )  ;Must have this value [_6_]
trigger1 = ( Var(1) % ( 2*(2 ** 6) ) >=( 2 ** 6 ) ) ;Study ;p
anim=806
...
[State 7]; Drillman
type=Explod
triggerall=!Time
trigger1 = ( Var(1) > = 2 ** 7 )  ;Must have this value [_7_]
trigger1 = ( Var(1) % ( 2*(2 ** 7) ) >=( 2 ** 7 ) ) ;Study ;p
anim=807
...
[State 8]; Dustlman
type=Explod
triggerall=!Time
trigger1 = ( Var(1) > = 2 ** 8 )  ;Must have this value [_8_]
trigger1 = ( Var(1) % ( 2*(2 ** 8) ) >=( 2 ** 8 ) ) ;Study ;p
anim=808
...

Whatever the order... The values are save correctly.

Used in this projects:  ;)



cya
Re: The best way to economize Vars (Bit-flag)
#2  November 02, 2014, 10:07:21 pm
  • ****
  • Target Acquired.
    • Ukraine
    • mugencoder.com
I'm not sure why I'd want to do this. You're still setting the same var with a static number, so it's really just over complicating the hard-coding of simple values. Vars can hold up to the maximum size of a 32-bit integer, so this seems kind of counter-intuitive.

-[Все слова это только слова.]-
Re: The best way to economize Vars (Bit-flag)
#3  November 03, 2014, 12:43:28 am
  • ******
  • Loyal to the Game
    • USA
    • http://jesuszilla.trinitymugen.net/
No it's not. It's basically making one var hold a lot of booleans because all you need is 1 bit for a boolean, so there's no need to waste an entire variable on it.


This is the exact same thing as bitwise variables, so this is old news.
Re: The best way to economize Vars (Bit-flag)
#4  November 03, 2014, 01:36:47 am
  • ******
  • [E]
    • Mexico
op also needs to memorize the powers of 2. any programmer worth it's salt knows them by memory.
Re: The best way to economize Vars (Bit-flag)
#5  November 03, 2014, 01:38:47 pm
  • ****
  • Target Acquired.
    • Ukraine
    • mugencoder.com
No it's not. It's basically making one var hold a lot of booleans because all you need is 1 bit for a boolean, so there's no need to waste an entire variable on it.
Yes, but that's for booleans. Just set one variables to a bunch of different numbers and you have exactly the same result without the mess.

Code:
var(1):=1
var(1):=2
var(1):=3

var(1) = 1 ; Do something
var(1) = 2 ; Do something else
var(1) = 3 ; Do something entirely different.

He's still hard-coding values regardless of being boolean or not. It's easier on the engine to do less calculations, so just go down the traditional route above and you'll be fine. There's no need to try bringing extra programming concepts like this into mugen. It's not actually any faster. In terms of convenience, I've done bitwise operations as well, but it was actually used in a way that couldn't be replicated in any other way with the same simplicity. This over-complicates things.

-[Все слова это только слова.]-
Re: The best way to economize Vars (Bit-flag)
#6  November 05, 2014, 10:10:41 pm
  • avatar
  • ****
  • Ya me dio cosa...
    • Mexico
Re: The best way to economize Vars (Bit-flag)
#7  November 05, 2014, 10:25:08 pm
  • ****
  • it's me
  • Maybe something different
    • Chile
    • koakoa@jabber.org
    • Skype - koakumadevil69
    • cowabungamugenteam.weebly.com
It's easier on the engine to do less calculations

which is why the bitwise operators &, | and ^ exist, they simplify their triggers, for example if I wanted to check toadman's ability I'd just use "trigger1 = var(1)&64" instead of what was indicated by OP and to set that same flag I'd use var(1):=(var(1)|64) and to turn it off I'd use var(1):=(var(1)^64)
Re: The best way to economize Vars (Bit-flag)
#8  November 06, 2014, 12:32:02 am
  • ******
  • Video Game Veteran
  • Can you do it? SUREYOUCAN!
    • USA
    • gcnmario.free.fr
Why are you using states that are used for more common states like getting hit (5000-5999) and so forth?

Some of this doesn't make sense to me. But I haven't messed with Mugen in months. So I donno. XP

"You must defeat my flaming
dragon punch to stand a chance."
Re: The best way to economize Vars (Bit-flag)
#9  November 06, 2014, 01:21:13 pm
  • ****
  • Target Acquired.
    • Ukraine
    • mugencoder.com
In this case you set only one value each time.
But you are doing the same thing as well. Setting one value each time. You might be using the bits of an int, but you're not really doing it quicker. It's not saving any time or speeding up the engine's processing using your method. Please explain to me how you think your method is any different than setting one value each time? By nature, vars can only hold one value.

which is why the bitwise operators &, | and ^ exist, they simplify their triggers, for example if I wanted to check toadman's ability I'd just use "trigger1 = var(1)&64" instead of what was indicated by OP and to set that same flag I'd use var(1):=(var(1)|64) and to turn it off I'd use var(1):=(var(1)^64)
Exactly.


-[Все слова это только слова.]-
Re: The best way to economize Vars (Bit-flag)
#10  November 09, 2014, 06:54:01 am
  • ******
  • Loyal to the Game
    • USA
    • http://jesuszilla.trinitymugen.net/
This has nothing to do with speed. It has to do with getting around MUGEN's variable limit because if you move all your booleans into one variable, then you have more room in other variables to do other calculations.


And again, this is nothing new. Winane outlined it and I did a more in-depth explanation to help people understand what's going on.
Re: The best way to economize Vars (Bit-flag)
#11  November 12, 2014, 10:10:26 pm
  • ******
  • Hedgehog Whisperer
  • Red Bull addict
    • Spain
    • xgargoyle.mgbr.net
Helpers have their own set of variables, so if you run out of variables, just spawn a helper and you'll instantly get an additional 60 ints and 40 floats.

Also, you can use other methods as a substitute to variables, especially for those ON/OFF stuff. Create an Explod or a Helper and use it's ID as a boolean flag. You can even use Animation numbers on a Helper to trigger specific conditions, instead of a variable.




XGargoyle: Battle posing since 1979
http://xgargoyle.mgbr.net
http://www.pandorabots.com/pandora/talk?botid=e71c0d43fe35093a  <-- Please click that link
http://paypal.me/XGargoyle  <-- Donations welcome!
Re: The best way to economize Vars (Bit-flag)
#12  November 12, 2014, 10:28:59 pm
  • ******
  • Loyal to the Game
    • USA
    • http://jesuszilla.trinitymugen.net/
Use projectiles before you resort to helpers for flags. Much less memory consumption.
Re: The best way to economize Vars (Bit-flag)
#13  November 12, 2014, 10:34:45 pm
  • ******
  • [E]
    • Mexico
Helpers have their own set of variables, so if you run out of variables, just spawn a helper and you'll instantly get an additional 60 ints and 40 floats.

Also, you can use other methods as a substitute to variables, especially for those ON/OFF stuff. Create an Explod or a Helper and use it's ID as a boolean flag. You can even use Animation numbers on a Helper to trigger specific conditions, instead of a variable.
agreed, those methods should be used after the bitflag one, tho.