PDA

View Full Version : Efficiency


Scenario
17/01/2012, 02:32 AM
I wanted some additional opinions about this, perhaps a few sensible people could give me some help!

I currently have this code:

stock bool:IsTruckerSkin(skinid)
{
switch(skinid)
{
case 4, 5, 24, 34, 73, 129 .. 134, 159, 161, 162, 182, 191, 196 .. 198, 201, 202: return true;
}
}

Would it be better to use this, or perhaps make an array of such skin ID's?

EDIT: And if I were to make an array, how would I use it? Probably an idiot question, but my mind isn't working right tonight!

2KY
17/01/2012, 02:37 AM
I'm assuming an array would be much better than a switch, however, I could be wrong in this area. You could code both options and use GetTickCount (http://wiki.sa-mp.com/wiki/GetTickCount) to figure out the quicker way of doing things. If you do end up doing so, please show the results here as I'm curious myself.

Lorenc_
17/01/2012, 02:46 AM
You're creating a 32 bit array once doing so, the current code you have is MORE efficient then having to create a array and do all the stuff inside there.

Just keep with that code, should be more faster as well.

2KY
17/01/2012, 02:47 AM
You're creating a 32 bit array once doing so, the current code you have is MORE efficient then having to create a array and do all the stuff inside there.

Just keep with that code, should be more faster as well.

I suppose we learn new things every day. Thanks for that bit of information.

Scenario
17/01/2012, 02:48 AM
You're creating a 32 bit array once doing so, the current code you have is MORE efficient then having to create a array and do all the stuff inside there.

Just keep with that code, should be more faster as well.

I was thinking this was more efficient (and possibly faster), but just wasn't sure. Thanks! By the way, say I were to put this into an array. How would I use the array as if it were a stock function?

EDIT: And if I were to make an array, how would I use it? Probably an idiot question, but my mind isn't working right tonight!

Lorenc_
17/01/2012, 02:56 AM
I was thinking this was more efficient (and possibly faster), but just wasn't sure. Thanks! By the way, say I were to put this into an array. How would I use the array as if it were a stock function?

One way:

new
bool: g_validskins[ 300 char ]
;

SetValidSkins( 4, 5, 24, 34, 73, 129, 130, 131, 132, 133 134, 159, 161, 162, 182, 191, 196, 197 198, 201, 202 );//gamemodeinit

stock SetValidSkins( ... )
{
new
iArgs = numargs( )
;

for( new i; i < iArgs; i++ )
{
g_validskins{ getarg( i ) } = true;
}
}

stock bool: IsTruckerSkin( skinid )
{
if( g_validskins{ skinid } == true ) return true;
return false;
}

-Prodigy-
17/01/2012, 02:56 AM
Nvm.

Scenario
17/01/2012, 03:17 AM
Oh nice. Thanks!

Kar
17/01/2012, 03:45 AM
You guys are speaking of Memory Saving, not actual efficiency..

Why do you even care about the array with if checks vs the stock + switch case?

Just compare them.

Scenario
17/01/2012, 03:50 AM
You guys are speaking of Memory Saving, not actual efficiency..

Why do you even care about the array with if checks vs the stock + switch case?

Just compare them.

Like I said, my mind isn't functioning properly tonight. :D

Babul
17/01/2012, 05:11 AM
iam happy with an array:

new InvalidSkinID[300];
public OnGameModeInit(){
//...
InvalidSkinID={
0,0,0,1,1,1,1,0,1,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,1,0,0,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,0,
0,0,0,0,0,1,0,0,0,0,
0,0,0,0,1,0,0,0,0,0,
0,0,0,0,0,0,1,0,0,0,
0,1,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,1,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,1,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,1,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,1,
0,0,0,0,0,0,0,0,0,0
};
//...
for (new s=0;s<299;s++)
{
if(InvalidSkinID[s]==0)
{
AddPlayerClass(s,1728.9382,1899.8223,10.8203,270.0 000,0,0,0,0,0,0);
}
}
//...

this is the outdated 0.3c array. i am too lazy to update it with the new skins ><
imo a simple check like InvalidSkinID[s] is more convenient than switch/case.. oh, you can modify the array ingame, thats impossible with switch/case, coz it (case{}) needs constant values :)