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

Solved Benefits of using a thinking entity?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 02-06-2020 , 08:28   Benefits of using a thinking entity?
Reply With Quote #1

What is the key difference between registering a thinking entity and calling a function with set_task repeatedly in intervals? Separate threads? Interrupts? Why would one (or whether would one) choose one method over another?

Last edited by redivcram; 02-06-2020 at 19:07.
redivcram is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 02-06-2020 , 10:08   Re: Benefits of using a thinking entity?
Reply With Quote #2

im using entity over set task when i need task to repeat with less that 0.1 sec, otherwise i guess its totally the same
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-06-2020 , 13:28   Re: Benefits of using a thinking entity?
Reply With Quote #3

using set_task is better because it doesn't consume entities since the entities in the game are limited. beside you can also pass parameters to the task...

basically entity think is for entities to assign them certain tasks such as movements, effects, etc...

for example NPC's, lasers, rockets, etc...


so the answer is use what you need for the job to get done.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-06-2020 at 13:35.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
thEsp
BANNED
Join Date: Aug 2017
Old 02-06-2020 , 14:39   Re: Benefits of using a thinking entity?
Reply With Quote #4

I did a basic test and seems that tasks are faster, tho I am unsure if I did it correctly or not because:
  • There is a check in "thinkRepeat" forward.
  • Server performance depends on the number of entities created (I tested it in a local game, 0 other third-party plugins).
Code:
#include <amxmodx> #include <engine> new g_dummyEntity; new Float:g_iEntityTime, Float:g_iTaskTime, g_szMessage[8]; public plugin_init() {     register_think("info_target", "thinkRepeat");     set_task(0.1, "taskRepeat", .flags = "b");     g_dummyEntity = create_entity("info_target");     entity_set_float(g_dummyEntity, EV_FL_nextthink, 0.1);     entity_set_string(g_dummyEntity, EV_SZ_message, "dummy");     register_clcmd("say /perftest", "cmdPerfomanceTest"); } public thinkRepeat(ent) {     entity_get_string(ent, EV_SZ_message, g_szMessage, charsmax(g_szMessage));     if (!equal(g_szMessage, "dummy"))         return;     g_iEntityTime = get_gametime();     entity_set_float(ent, EV_FL_nextthink, 0.1); } public taskRepeat() {     g_iTaskTime = get_gametime(); } public cmdPerfomanceTest(id) {     client_print(id, print_chat, "PerfTest: Task = %f <<->> Entity = %f", g_iTaskTime, g_iEntityTime); }
Code:
Output:

PerfTest: Task = 117.940032 <<->> Entity = 117.990051
PerfTest: Task = 129.233001 <<->> Entity = 129.233001
PerfTest: Task = 134.867950 <<->> Entity = 134.891281
PerfTest: Task = 152.870132 <<->> Entity = 152.967751
Counting on some knowledgeable guy to state his opinion.
thEsp is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-06-2020 , 18:16   Re: Benefits of using a thinking entity?
Reply With Quote #5

Here's some threads on the topic. Seems like it doesn't really matter, difference comes in when you need it to repeat faster than 0.1 interval since set_task() is clamped at that. I've personally been using thinking entities when I need something to constantly run, not sure if it's 100% ideal from a performance perspective, but I think it's cleaner.

https://forums.alliedmods.net/showthread.php?t=43049
https://forums.alliedmods.net/showthread.php?p=2577003
__________________

Last edited by Bugsy; 02-06-2020 at 18:17.
Bugsy is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 02-06-2020 , 19:06   Re: Benefits of using a thinking entity?
Reply With Quote #6

Thanks for the replies.
redivcram 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 16:12.


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