bckobayashimaru.de

Bridge Commander Kobayashi Maru Project
It is currently Tue Jun 25, 2019 3:24 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Tue Jan 16, 2007 11:01 am 
Offline
Cadet 2nd Year
Cadet 2nd Year
User avatar

Joined: Sun Jun 26, 2005 3:56 pm
Posts: 45
Location: Netherlands
It's been a while since I had a technical question regarding BC, but this is the one thing (so far found) that is keeping a new release of BP Core (and related things).

It's the Animated Texture Maps. These maps are scripted animated maps, and it's original implementation was correct, but performance wise totally unacceptable. And it had a dependency with FoundationTechnologies (not a bad thing, but it's not widely used) which was optional (that aspect simply didn't work otherwise:P).

The new approach is way better, performance wise. No noticeable lag on my machine, at least, no additional. :lol: My BC is a bit bloated. ^_^'



Ok, back to the problem at hand.

When animated maps are called, it starts swapping them from within the scripts, the current approach is to use a sequence for this. Looping is achieved by reconstructing the sequence at it's end. This works, and isn't really important here.

What does work, correctly, is stopping them. Sure the animation is stopped (btw, if anyone knows a fool proof way to stop a sequence without crashing BC, it would be appreciated, the current system simply lets the sequence die off by earlier outing (this too will need to be thinked a bit through, mostlikely an extra identifier, more on this later, I think).

But it doesn't leave the map system in a state where it functions properly.
The map system works by storing the new texture name under the original texture name.
The texture name is different from the texture path.
For instance, this texture path:
Data/Models/Sets/EBridge/High/A_Particular.Map.tga
This is valid. This is it's name:
A_Particular.Map

The function that does this is called DistillNewMapName, and you see it in the functions below here and there.

If the map "A_OriginalMap" is swapped by A_Particular.Map then it needs to store the new name in the Map System, otherwise, subsequent swaps wouldn't know where to swap it. So they all refer to A_OriginalMap, but in fact, they change the real map name underneath and swap it with that.


Back to the problem at hand, the animation system doesn't leave the map system in a continual state (ie. other maps can successfully swap new maps). But if you rerun the sequence it works fine, but not directly. It's almost as if it doesn't set the right map.



You can be sure of that these functions are correctly called.

First possible function, SwitchAnimatedMaps, this function is called when the texture swap mechanism detects an animated texture. The list is stored, so that the Texture swap mechanism can detect it later on (so that it's also stopped). It basically sets stuff up and sets things in motion.
Code:
def SwitchAnimatedMaps(sOldMap, lNewMaps):
   global oBridgeInfo
   if oBridgeInfo.dTextureAnimations.has_key(sOldMap):
      #print "Animation already present"
      StopAnimatedMaps(sOldMap)

   oBridgeInfo.Maps["CurrentMaps"][sOldMap] = lNewMaps

   bLooping = 0
   dTrack = {}

   if type(lNewMaps) == types.ListType:
      bLooping = lNewMaps[0]
      dTrack = lNewMaps[-1]
   else:
      if not lNewMaps.has_key("dTrack"):
         dTrack = lNewMaps
      else:
         bLooping = lNewMaps.get("bLooping", 0)
         dTrack = lNewMaps["dTrack"]

   dAnimation = {}
   oBridgeInfo.dTextureAnimations[sOldMap] = dAnimation

   lMapNames = []
   for value in dTrack.values():
      lMapNames.append(DistillNewMapName(value))

   dAnimation["MapNames"] = lMapNames
   dAnimation["MapPaths"] = dTrack.values()
   dAnimation["dTrack"] = dTrack
   dAnimation["bLooping"] = bLooping
   dAnimation["CurrentIndex"] = 0
   dAnimation["Length"] = len(lMapNames)
   dAnimation["sOldMap"] = ""+sOldMap
   dAnimation["AniName"] = sOldMap

   ConstructSeqFromDict(dAnimation)


Also not the issue, I think. But it starts the sequence.
Code:
def ConstructSeqFromDict(dAnimation):

   # Construct a sequence of texture switches
   pSequence = App.TGSequence_Create()
   pSequence.SetSkippable(1)
   dAnimation["Sequence"] = pSequence
   iSub = 0
   for index, map in dAnimation["dTrack"].items():
      pSequence.AddAction(App.TGScriptAction_Create(__name__, "SwitchAniMapsAction", dAnimation["AniName"]), App.TGAction_CreateNull(), index)
      iSub = index
   pSequence.Play()


The function that does things. Not sure if it's causing it or not, but unlikely, since it successfully swaps maps.
Code:
def SwitchAniMapsAction(pAction, sName):
   global oBridgeInfo
   if not oBridgeInfo.dTextureAnimations.has_key(sName):
      return 0
   dAnimation = oBridgeInfo.dTextureAnimations[sName]

   index = dAnimation["CurrentIndex"] + 1
   sOldMap = dAnimation["sOldMap"]
   if index+1 == dAnimation["Length"]:
      if dAnimation["bLooping"]:
         dAnimation["CurrentIndex"] = 0
         ConstructSeqFromDict(dAnimation)
         return 0
      # Now I need to write the last map back
      StopAnimatedMaps(sName)
      return 0
   sNewMap = dAnimation["MapPaths"][index]
   DirectSwitchMaps(sOldMap, sNewMap)
   dAnimation["CurrentIndex"] = index
   dAnimation["sOldMap"] = DistillNewMapName(sNewMap)
   return 0


This function is mostlikely the cause. Since this function is responsible for setting the map system right again.
Code:
def StopAnimatedMaps(sKey):
   #print "Stopping", sKey
   global oBridgeInfo
   if not oBridgeInfo.dTextureAnimations.has_key(sKey):
      return
   dAnimation = oBridgeInfo.dTextureAnimations[sKey]
   print dAnimation["sOldMap"]
   oBridgeInfo.CurrentMaps[sKey] = dAnimation["sOldMap"]
   del oBridgeInfo.dTextureAnimations[sKey]
   return



And here is an issue I mentioned above, just thought of it. Dangling sequences.
If a sequence is aborted then it becomes what I like to call a "dangling sequence", it isn't referred to anymore, and it, shouldn't, do(esn't) any more work. Now, if you quickly stop and start a sequence, before the sequence can run out, then it creates a dangling sequence (in the current method) because it doesn't actually abort/stop the sequence (I haven't been able to do that without crashing BC). The symptoms of this (in this system) is fast(er) texture changes, since each step is basicly done twice (especially noticable in looping animations).

Now, 2 sollutions, find a way to stop/abort/skip the sequence (if you know a way, it should be possible, but haven't been able to do it). This way is preferable.
The other, is to assign id's to sequences, and use that instead of the "name" (sName in the action function).



I hope you the reader has made it until this (not fallen asleep:P), and have seen the problem.
Please post it if you do!


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 17, 2007 5:37 am 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
MLeo wrote:
I hope you the reader has made it until this (not fallen asleep:P), and have seen the problem.
Please post it if you do!

Well have read the first 2 and last lines, and you want to repeat something a lot if times and the option to stop it, right? Have you thought about replacing the sequence with the PythonMethodProcess-class-loop?

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 17, 2007 8:26 am 
Offline
Cadet 2nd Year
Cadet 2nd Year
User avatar

Joined: Sun Jun 26, 2005 3:56 pm
Posts: 45
Location: Netherlands
Defiant wrote:
MLeo wrote:
I hope you the reader has made it until this (not fallen asleep:P), and have seen the problem.
Please post it if you do!

Well have read the first 2 and last lines, and you want to repeat something a lot if times and the option to stop it, right? Have you thought about replacing the sequence with the PythonMethodProcess-class-loop?

How would I go about using that?
And does it have the same effect as a timer/sequence?
Meaning, that you won't stay in a while loop (on the script side)?

A quick google turns up a thread on BCU as only result.:P

Also, what's the performance of it?
Since a timer (a single timer) had disasterous results, lag, memory leaks, etc, etc.

The sequence I'm currently using has so far no detectable side effects (in terms of lag and performance).


Btw, got one thing mixed up, the memory leaks were caused by JediFX (flames and similar on the bridge) since it reloaded every sound each time it was used.


[EDIT] The sequence stuff is actually a minor issue, the real issue is the map system not being updated correctly, it's what is keeping BP Core from release!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jan 19, 2007 2:47 pm 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
Hmm. Your really problem is that you need to stop the sequence correctly, right?

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jan 19, 2007 2:58 pm 
Offline
Cadet 2nd Year
Cadet 2nd Year
User avatar

Joined: Sun Jun 26, 2005 3:56 pm
Posts: 45
Location: Netherlands
Defiant wrote:
Hmm. Your really problem is that you need to stop the sequence correctly, right?

No, not at all actually.


I haven't given that problem much thought because there is a bigger problem.


When the animation is stopped (in whatever way) it doesn't leave map system in a correct state.

The problem lies in one of those functions I posted above (that's all there is to the animated map system anyway).

The reason I posted here is because I've been trying to fix it for ages and I haven't been successfull. :(


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jan 19, 2007 3:06 pm 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
? why don't you call a function to set the maps into the correct state after stopping the animation?

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jan 19, 2007 3:09 pm 
Offline
Cadet 2nd Year
Cadet 2nd Year
User avatar

Joined: Sun Jun 26, 2005 3:56 pm
Posts: 45
Location: Netherlands
Defiant wrote:
? why don't you call a function to set the maps into the correct state after stopping the animation?

That's the purpose of the StopAnimation function, which btw, I'll be splitting in 2, a stop animation, and a clean up part.

The stop animation calls the clean up.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jan 19, 2007 3:10 pm 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
hmm ok. Could you prepare something I can run?
(With a tiny short information what it should do)

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jan 19, 2007 3:53 pm 
Offline
Cadet 2nd Year
Cadet 2nd Year
User avatar

Joined: Sun Jun 26, 2005 3:56 pm
Posts: 45
Location: Netherlands
I will have to do it next week then, I need to finnish my report before monday. :(


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jan 22, 2007 11:20 pm 
Offline
Cadet 2nd Year
Cadet 2nd Year
User avatar

Joined: Sun Jun 26, 2005 3:56 pm
Posts: 45
Location: Netherlands
I had a little time debugging it, and I think I know the cause of the problem.

I do this:

oBridgeInfo.CurrentMaps[sKey] = dAnimation["sOldMap"]


But in the end, it didn't change it.

Of course, dAnimation is going to be deleted, but how could it store it's previous value?


Also, dAnimation["sOldMap"] points to the right map, otherwise the entire system wouldn't work.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 23, 2007 10:31 am 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
What type is dAnimation["sOldMap"]?

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 23, 2007 10:46 am 
Offline
Cadet 2nd Year
Cadet 2nd Year
User avatar

Joined: Sun Jun 26, 2005 3:56 pm
Posts: 45
Location: Netherlands
Defiant wrote:
What type is dAnimation["sOldMap"]?

String.

The type in oBridgeInfo.CurrentMaps[sKey] is either a list, a dictionary or a tuple. It's used to distinguish between normal texture swap and animation.


But, after a little talk with Dasher I came up with the idea to use a mark for it (namely ?, since that character will never be used in a texture name, since it's an illegal filesystem character on Windows).
He also said that the mixing of the 2 types might cause problems. So now it shall simply be a string (and the performance will also be higher).


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group