 |
Bridge Commander Universe ...welcome to the new world.
|
View previous topic :: View next topic |
|
Author |
Message |
Defiant
Free "as in Free Speech" Engineer Admiral


Age: 26
Zodiac: 
Joined: 27 Jan 2003
Posts: 2337
Location: Hamburg, Germany

|
|
|

|
|
|
Most of you scripters probably noticed, that if you do many AddName()/RemoveName() calls to the friendly or enemy group, the game starts to lag.
Well I found the problem.
Well after searching 90 minutes - my poor afternoon :( - I finally, yes, I finally found the problem.
Best of it, is the comment, that the Author made:
Code: |
# Hopefully this won't be too painfully slow:
|
- I really like this comment (I would like to kill the Author for that)
Anyway the file is scripts/Conditions/ConditionInRange.py
Near line 132 you'll find this:
Code: |
self.pObjects.SetEventFlag( App.ObjectGroup.GROUP_CHANGED )
App.g_kEventManager.AddBroadcastPythonMethodHandler(App.ET_OBJECT_GROUP_CHANGED, self.pEventHandler, "GroupChanged", self.pObjects)
|
Put a '#' before both lines and you are done.
We should probably also comment the other lines with Enter and Exit Set, but they do not seem to painfull.
Now whats happenning?
Well its pretty easy: For every Group change, the GroupChanged method is called more and more times.
Why this?
To be honest, I'm not sure right now. There seems to be no reason.
I'ld say it would be much easier to just modify the existing ObjectGroup.
But I won't look into this. At least not today.
What does the rest of you think?
|
_________________ BC Modification Kobayashi Maru
--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain
|
|
Back to top |
|
 |
Sim Rex
Moderator


Age: 26
Zodiac: 
Joined: 11 Apr 2002
Posts: 1714

|
|
|

|
|
|
Defiant wrote: | Most of you scripters probably noticed, that if you do many AddName()/RemoveName() calls to the friendly or enemy group, the game starts to lag.
Well I found the problem.
Well after searching 90 minutes - my poor afternoon - I finally, yes, I finally found the problem.
Best of it, is the comment, that the Author made:
Code: |
# Hopefully this won't be too painfully slow:
|
- I really like this comment (I would like to kill the Author for that)
Anyway the file is scripts/Conditions/ConditionInRange.py
Near line 132 you'll find this:
Code: |
self.pObjects.SetEventFlag( App.ObjectGroup.GROUP_CHANGED )
App.g_kEventManager.AddBroadcastPythonMethodHandler(App.ET_OBJECT_GROUP_CHANGED, self.pEventHandler, "GroupChanged", self.pObjects)
|
Put a '#' before both lines and you are done.
We should probably also comment the other lines with Enter and Exit Set, but they do not seem to painfull.
Now whats happenning?
Well its pretty easy: For every Group change, the GroupChanged method is called more and more times.
Why this?
To be honest, I'm not sure right now. There seems to be no reason.
I'ld say it would be much easier to just modify the existing ObjectGroup.
But I won't look into this. At least not today.
What does the rest of you think? |
I'm a little perplexed... I've been out of the loop for a while, I admit, but wouldn't this just mean that every time there's a change to a group, the GroupChanged function is called once? Surely that can't be a source of too much slowdown?
As I say, I might just not be thinking about it properly...
|
_________________ "Could it be it's the end of our world? All the things that we cherish and love
Nothing left but to face this all on my own, cause I am the chosen one!"
-- The Fallen Angel - Iron Maiden(Smith/Harris)
For beginner scripters - The BCU Mission Scripting Lessons
|
|
Back to top |
|
 |
Defiant
Free "as in Free Speech" Engineer Admiral


Age: 26
Zodiac: 
Joined: 27 Jan 2003
Posts: 2337
Location: Hamburg, Germany

|
|
|

|
|
|
Quote: |
Now whats happenning?
Well its pretty easy: For every Group change, the GroupChanged method is called more and more times.
|
Yeah ok, this explanation wasn't very good. I'll try a better one.
I admit I havn't checked what really happens, but my guess is:
Well everytime the GroupChange() method is called a new handler is created to call the GroupChange() method on GroupChange():
The first time the GroupChange() method is called once.
Then a second Handler is added, so
the second time the GroupChange() method is called twice.
Two new Handlers are added.
So the third time the GroupChange() method is called 2^2 times
And so on.
Now guess what you have after 50 changes.
I would also start to lag...
As I said I havn't fully tested yet. I'm happy enough that it stopped lagging.
|
_________________ BC Modification Kobayashi Maru
--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain
|
|
Back to top |
|
 |
Sim Rex
Moderator


Age: 26
Zodiac: 
Joined: 11 Apr 2002
Posts: 1714

|
|
|

|
|
|
OK, I see now... Didn't realise that GroupChanged called SetObjects in a little loop like that.
But now that handler isn't being created at all... Isn't that going to have an effect on AI and things?
|
_________________ "Could it be it's the end of our world? All the things that we cherish and love
Nothing left but to face this all on my own, cause I am the chosen one!"
-- The Fallen Angel - Iron Maiden(Smith/Harris)
For beginner scripters - The BCU Mission Scripting Lessons
|
|
Back to top |
|
 |
Defiant
Free "as in Free Speech" Engineer Admiral


Age: 26
Zodiac: 
Joined: 27 Jan 2003
Posts: 2337
Location: Hamburg, Germany

|
|
|

|
|
|
Sim Rex wrote: | OK, I see now... Didn't realise that GroupChanged called SetObjects in a little loop like that.
But now that handler isn't being created at all... Isn't that going to have an effect on AI and things? |
I'm not sure.
Anyway I do have another fix now, which seems to be cleaner:
Code: |
def GroupChanged(self, pEvent):
#debug("GroupChanged for %s" % self)
# An object has been added to or removed from our self.pObjects group.
# We'll need to update the proximity sphere for the changed group.
# Hopefully this won't be too painfully slow:
#apply(self.SetObjects, (self.sObject1, self.pObjects))
# by Defiant: and why don't we just call the Proximity function instead of getting the game to lag?
self.SetupProximitySphere()
|
and
Code: |
def SetTarget(self, sTarget):
#debug("SetTarget for " + str(self))
# Change self.sObject1.
if self.sObject1 != sTarget:
#debug("Changing target from %s to %s" % (self.sObject1, sTarget))
#apply(self.SetObjects, (sTarget, self.pObjects))
self.pSingleObjectGroup.RemoveName(self.sObject1)
self.sObject1 = sTarget
self.pSingleObjectGroup.AddName(self.sObject1)
# Setup the proximity sphere.
self.SetupProximitySphere()
|
Did not had any problems with this change yet. I've uploaded the change to KMcur. The file should be online tomorrow. I'll then link to it from here.
Btw, the script that is loading this Condition, that really is causing the lags is the DynamicMusic.py
|
_________________ BC Modification Kobayashi Maru
--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain
|
|
Back to top |
|
 |
Defiant
Free "as in Free Speech" Engineer Admiral


Age: 26
Zodiac: 
Joined: 27 Jan 2003
Posts: 2337
Location: Hamburg, Germany

|
|
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
Bridge Commander Universe is a Nightsoft
company. All rights reserved.
|