Raised This Month: $ Target: $400
 0% 

Question about loop.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 02-15-2013 , 11:11   Question about loop.
Reply With Quote #1

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?
.Dare Devil. is offline
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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