Raised This Month: $51 Target: $400
 12% 

[TUT/INFO] set_tasks: when they are and when they aren't necessary


Post New Thread Reply   
 
Thread Tools Display Modes
_Master_
Senior Member
Join Date: Dec 2006
Old 10-06-2007 , 06:20   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #21

Quote:
If it's used more than once in the script, the data only appears in memory once. If you use the define, the memory is allocated for each time it's referenced.
It's optimized for memory consumption not for speed.
The macros are replaced at compile-time so even if the same data is held multiple times, it resides in the same segment thus improving RT efficiency.

I do believe that in terms of HL scripting optimizations should be done for speed rather than memory consumption.
_Master_ is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 10-06-2007 , 10:36   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #22

AFAIK it's the same speed, just less overhead. I don't know where you got that it's slower, but I'm reasonably sure that it's not (although I can't back it).

The define is almost definitely not slower, but I imagine that they're the same speed.

Then again, there's one major advantage: if someone is stupid and tries to change the define to another type (say it's 20.0 and they change it to 15), the compiler will yell at them for having a tag mismatch there. It's even better for an array because it just won't compile at all. Of course you'd get errors later on even if you didn't use this (unless multiple tags is allowed for a section), but the error right up front helps diagnosis.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Podunk
Senior Member
Join Date: Nov 2005
Location: Florida
Old 10-06-2007 , 17:24   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #23

thanks, I'll read the TUT when I get some time
__________________
Check out my website at http://matthewmiller.info
Podunk is offline
Send a message via MSN to Podunk
kp_uparrow
Penalized Member
Join Date: Jun 2006
Location: 192.168.0.1
Old 10-07-2007 , 22:18   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #24

hawk fix ur code, its suppose to be halflife_time()+20.0 or somethin or else its gonna be called every frame
__________________
I USED A SECOND ACCOUNT TO DO MORE KARMA UPS AND DOWNS UNTIL GREENTRYST CAUGHT ME
kp_uparrow is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 10-08-2007 , 00:07   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #25

I already said I'd add that in but the stupid editor is broken. I'm too lazy to change my settings.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
purple_pixie
Veteran Member
Join Date: Jun 2007
Location: Winchester, England
Old 10-08-2007 , 07:19   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #26

It's not a lot of effort ...

And it makes editing a lot easier.

I can happily edit my posts now, and the code still comes out fine.

EDIT: Is there a notice anywhere that says "btw, if you want to be able to edit posts with tags in them, you have to change your settings to the flat text editor" or are we all meant to work that out?
purple_pixie is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 10-08-2007 , 15:03   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #27

Aren't we getting a bit off-topic ?
_Master_ is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 11-13-2007 , 10:58   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #28

How does engine know when it is the time to call Think on specified entity? It must check time sometimes, but how often?

I escaped usage of set_task with "b" flag by counting server frames. When frames counter reach certain value then time is checked, so I can determine how many frames must pass until certain time will pass (if average server fps will not change much).

example code:
PHP Code:
#include <amxmodx>
#include <fakemeta>

#define UPDATE_TIME 1.0

new g_check_frame 100
new g_f2_exec_frame 100
new Float:g_f2_interval 0.3

public plugin_init(){
    
register_plugin"test""1.0""Sylwester")
    
register_forward(FM_StartFrame"fwd_StartFrame")
}

public 
fwd_StartFrame(){
    static 
Float:current_time
    
static Float:last_time
    
static frames_counter
    
static frames_counter2
    
    frames_counter
++
    if(
frames_counter g_check_frame){
        
current_time get_gametime()
        
g_check_frame floatround(g_check_frame*UPDATE_TIME/(current_time-last_time))+1
        g_f2_exec_frame 
floatround(g_check_frame/UPDATE_TIME g_f2_interval)
        
last_time current_time
        frames_counter 
1
        func1
()
    }

    
frames_counter2++
    if(
frames_counter2 g_f2_exec_frame){
        
frames_counter2 1
        func2
()
    }
}

func1(){
//func1 will be executed every about 1 second
}

func2(){
//func2 will be executed every about 0.3 second

This method is not 100% accurate. Time between two function calls may differ little from desired time, but in some cases you don't need it to be so accurate.

Which method takes more CPU power? This one or method with setting next think on entity?

btw I copied first post to txt file...
Attached Files
File Type: txt first_post.txt (5.1 KB, 174 views)
__________________
Impossible is Nothing
Sylwester is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 11-13-2007 , 17:41   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #29

Totally useless. I used this in my "Game Status HUD Display" plugin, but it's terrible for measuring time intervals. Please, I urge no one to use this unless their task is extremely insensitive to time.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
kp_uparrow
Penalized Member
Join Date: Jun 2006
Location: 192.168.0.1
Old 11-13-2007 , 19:49   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #30

server frames fluctuates like crazy
__________________
I USED A SECOND ACCOUNT TO DO MORE KARMA UPS AND DOWNS UNTIL GREENTRYST CAUGHT ME
kp_uparrow is offline
Reply



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 06:51.


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