Raised This Month: $ Target: $400
 0% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Lo6idZe
Member
Join Date: May 2008
Old 08-10-2008 , 14:00   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #51

Thanks... Other opinions ?
Lo6idZe is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-10-2008 , 14:07   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #52

To do a countdown, set_task is perfectly fine. Though, the way how you do the thing is badly coded.
__________________
Arkshine is offline
Lo6idZe
Member
Join Date: May 2008
Old 08-10-2008 , 14:17   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #53

Mmm... Can you edit it , please ?
Lo6idZe is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-10-2008 , 14:19   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #54

That's not the right forum to ask requests.
__________________
Arkshine is offline
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 08-10-2009 , 07:14   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #55

I just got around to using an entity instead of a "b" flag set_task for the first time...

Considering the reason behind switching to an entity is for optimization, I find the following code segment somewhat troubling in concept:

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

new g_Classname[] = "roflmao"

public plugin_init()
{
    
register_plugin("ROFL","1.0","Hawk552")
    
    new 
Ent engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
    
set_pev(Ent,pev_classname,g_Classname)
    
set_pev(Ent,pev_nextthink,20.0)
    
    
register_forward(FM_Think,"ForwardThink")
}

public 
ForwardThink(Ent)
{
    static 
Classname[33]
    
pev(Ent,pev_classname,Classname,32)
    
    if(!
equal(Classname,g_Classname))
        return 
FMRES_IGNORED
    
    log_amx
("ROFLMAO thinks.")
    
    
set_pev(Ent,pev_nextthink,20.0+halflife_time())
    
  return 
FMRES_IGNORED

We check a string on every call.

I chose to do it a different way, and I haven't had problems with it yet, but I'd like to know if there's something wrong with the way I'm doing it, because for replacing a "b" flag set_task, this seems a lot more logical.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

new g_thinker

public plugin_init()
{
    
register_plugin("255kwaH","0.1","LFOR")
    
    
g_thinker=engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
    
set_pev(g_thinker,pev_classname,"doesntmatter")
    
set_pev(g_thinker,pev_nextthink,20.0)
    
    
register_forward(FM_Think,"ForwardThink")
}

public 
ForwardThink(Ent)
{
    if(
Ent!=g_thinker)
        return 
FMRES_IGNORED
    
    log_amx
("ROFLMAO thinks.")
    
    
set_pev(Ent,pev_nextthink,20.0+halflife_time())
    
  return 
FMRES_IGNORED

But still, I don't think I've ever understood why using an entity would be more efficient than a set_task. Does anyone care to explain?
__________________

Last edited by Bad_Bud; 08-10-2009 at 07:38.
Bad_Bud is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 08-10-2009 , 07:24   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #56

Because setting a task with flag "b" aka LOOP, have some random delays, like if you set a task with 1.0 delay will have delays like -> 0.8, 0.9, 1.1,...a fix for this will be to not set flag "b" but to call task everytime in that public. Also set_task is a native, making a ent and make it think is faster that native.
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 08-10-2009 , 08:43   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #57

Oh, that's cool. Thanks.
__________________
Bad_Bud is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-10-2009 , 14:09   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #58

Use register_think and register your custom entity classname, so only that ent will call the handler.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-27-2010 , 11:27   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #59

@Hawk552 :

Sorry to bump an old thread but connor was saying me he has a big lag when a vote appears from the mapchooser ( or galileo or timeleft plugin, etc) plugin and set_task might be the cause. You say :
Quote:
What few people know is that it is a very expensive operation, the CPU has to literally check every cycle if it is time for the set_task to be executed.
Checking the Amxx source code, you have a check done in StartFrame() with g_task_time to make sure g_tasksMngr.startFrame(); is called each 0.1 second, not every cycle. Next, CTaskMngr::startFrame() will still loop anyway all the time through all the registered tasks, then executing executeIfRequired() to check if a task can be executed.

My point is : I don't think few more checks (such simple checks and of course multiplied by the number of registered tasks) will add a significant change in the cpu consumption when you have already much forwards in Amxx or others modules called very often with many checks. I would assume that using set_task is perfectly fine even when using the "b" flag and you would use an entity only when you need to control a precise and <0.1 think time.

About the connor's problem, having a lag (it appears not always) when a set_task is executed, I don't know enough the C++ to say if the problem is really from there (though I don't see anywhere what it can be the cause), and that's not like he has searched throughly, so I can't give much informations.

Anyway, if you don't mind, I would like to hear your thoughts.
__________________
Arkshine is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-28-2010 , 11:31   Re: [TUT/INFO] set_tasks: when they are and when they aren't necessary
Reply With Quote #60

I saw a big decrease in transfer time (file sent much faster) with my FTP include when I changed from set_task w\ flag "b" to thinking entity (using 0.1 interval for both) . I will try to dig up the older copy and re-test to make sure something else was not causing this.
__________________

Last edited by Bugsy; 12-29-2010 at 10:25.
Bugsy 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 08:22.


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