AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Question about loop. (https://forums.alliedmods.net/showthread.php?t=208601)

.Dare Devil. 02-15-2013 11:11

Question about loop.
 
Hello!

Im making here my dynamic hud but have a question.
PHP Code:

new dhud_enable[192]

// i did skip code parts what have anything to do with my question, i also have few other things there right now...

// here is how i create dynamic hud
stock add_dynamichud()
{
new 
a
for(0192a++)
{
    if( !
dhud_enable[a] ) return a

}
}

// here is how i remove 
dhud_enable[dhudid] = 0

here is dynamic hud thinking
public f_think_25fps()
{
     static 

     
for(0192a++) if( dhud_enable[a] ) dhud_think(a)
}

dhud_think(dhudID)
{
// here come some dynamic effects :)


with this code in f_think_25fps() loop does useless checks
example if i have only 25 dynamic hud messages right now, loop will check 192 what is maximum number of dhuds.
but i cant also create variable what count dhud count and then but it into loop line like this
PHP Code:

for(0dhud_counta++) 

there will be always small or even big holes.

so i took a new way.
creating variable that holds dhud_enable[this number].

example in the variable dhud_enable :
{
1,
0,
0,
1,
1,
0,
1,
0,
0,
0,
...
}

you see 0 is a hole, no needed thing. all 0-s must be in the end but cant do this with one variable so new variable help.

inside of new variable:
{
0,
3,
4,
6,
-1,
-1,
-1,
...
}

this variable tell the system where are 1-s in dhud_enable

new code:
PHP Code:

new ab
for(0dhudcounta++)
{
    
newvariabledhud_think(b


using way 2 make things more complex ( for me not for cpu : ) )
here comes my question, do i really need to use that new way or the first way is not that bad and does not take so many cpu by doing useless checking? :)


All times are GMT -4. The time now is 20:39.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.