unthrottle eventAttacked()

For AI and campaign script related discussions and questions
Post Reply
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

unthrottle eventAttacked()

Post by NoQ »

Per wrote:eventAttacked() is throttled, so do not worry too much about it being called too many times.
I just ran a few tests with eventAttacked not being unthrottled on the code side:

Code: Select all

--- a/src/cluster.cpp
+++ b/src/cluster.cpp
@@ -556,11 +556,11 @@ void clustObjectSeen(BASE_OBJECT *psObj, BASE_OBJECT *psViewer)
 // tell the cluster system that an object has been attacked
 void clustObjectAttacked(BASE_OBJECT *psObj)
 {
+       triggerEventAttacked(psObj, g_pProjLastAttacker);
        if ((aClusterAttacked[psObj->cluster] + ATTACK_CB_PAUSE) < gameTime)
        {
                psScrCBTarget = psObj;
                eventFireCallbackTrigger((TRIGGER_TYPE)CALL_ATTACKED);
-               triggerEventAttacked(psObj, g_pProjLastAttacker);
 
                switch (psObj->type)
                {
I believe it allows to significantly improve the AI's combat micromanagement, while not really having too much performance decrease (in my case this event is relatively lightweight). I can easily throttle it the way i want on the script side if i find it necessary.

Alternatively, i could use a new event that is called, for example, eventAttackedUnthrottled(victim, attacker), so that not break existing scripts (if any).
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: unthrottle eventAttacked()

Post by aubergine »

I think having the extra event would be the best approach - if a script is running slowly, the developer can compare performance between the two events to quickly assess the performance impact of using the unthrottled event.

As we've seen from NullBot, performance issues tend to arise elsewhere, often in unexpected places (like searching for oil).
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: unthrottle eventAttacked()

Post by Per »

Ok, unthrottled in master. Be careful though, or you'll create stuttering when people start thermite bombing! :)

I hope to soon look into spreading events over multiple frames, if they start to queue up.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: unthrottle eventAttacked()

Post by NoQ »

Oops, now someone needs to fix the attack warning sound (:
P.S. I already like the way it goes (:
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: unthrottle eventAttacked()

Post by Per »

NoQ wrote:Oops, now someone needs to fix the attack warning sound (:
Fixed. Can now be adjusted through rules.js
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: unthrottle eventAttacked()

Post by NoQ »

Hmm, now that i think of it ... how about we still have some throttling on the code side, but of a different sort.
For instance, don't call the event too often for any particular victim object, while still calling it often if multiple objects were just attacked.

We can rely on psVictim->timeLastHit property in eventAttacked to handle that.
But this property is set to current game time before calling eventAttacked.
So we need to call eventAttacked before setting this variable.

Probably something like that:
Attachments
throttle.patch
(2.72 KiB) Downloaded 238 times
Last edited by NoQ on 29 May 2012, 08:52, edited 2 times in total.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: unthrottle eventAttacked()

Post by aubergine »

So then you'd have effectively a clusterAttackedThrottled() and a objectAttackedThrottled()?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: unthrottle eventAttacked()

Post by NoQ »

What the hell did i post as a patch? >_<
Fixed the message above.
Still interested in some feedback.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: unthrottle eventAttacked()

Post by Per »

Looks good. Will commit (a slightly modified version).
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: unthrottle eventAttacked()

Post by NoQ »

Yay (:
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: unthrottle eventAttacked()

Post by NoQ »

Oops i think we're having a typo in triggerEventAttacked:

Code: Select all

-	if (gameTime - psVictim->timeLastHit < ATTACK_THROTTLE)
+	if (gameTime - lastHit < ATTACK_THROTTLE)
(because of that, eventAttacked isn't called at all right now in master)
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: unthrottle eventAttacked()

Post by Per »

NoQ wrote:Oops i think we're having a typo in triggerEventAttacked:

Code: Select all

-	if (gameTime - psVictim->timeLastHit < ATTACK_THROTTLE)
+	if (gameTime - lastHit < ATTACK_THROTTLE)
(because of that, eventAttacked isn't called at all right now in master)
My bad. Fixed. :oops:
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: unthrottle eventAttacked()

Post by NoQ »

Emm sry ... i still don't see that typo fixed yet after a git pull, and a relevant commit isn't present in the timeline.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: unthrottle eventAttacked()

Post by Per »

NoQ wrote:Emm sry ... i still don't see that typo fixed yet after a git pull, and a relevant commit isn't present in the timeline.
I forgot to push it :?
Post Reply