Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / set object frame causes massive lag

Author
Message
Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 11th Sep 2011 22:27
Perhaps this is a known problem or perhaps I am missing something. But this piece of code causes massive lag:



When I comment out the second to last line (SET OBJECT FRAME) it runs smoothly. Also, the slowdown only occurs if the objects are on screen. If I set the object frame off screen it runs fine. I find this confusing because it would appear to be an insufficient graphics card. But with the ability to run Oblivion at full graphics with no lag, I doubt that have 25-50 animated objects on an empty matrix would be too much for the GPU.

Any ideas? Thanks

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Sep 2011 02:41
What is that line doing exactly? The Help file doesn't say what effect a final value of zero has.

Quote: "Description

The object number should be specified using an integer value. The frame number should be specified using a real number. A Recalculate Bounds Flag value of one will regenerate the bounds of the current frame, a value of two will regenerate the bounds of all the animation frames. A value of three will generate all the animation frame bounds, but will not shift the object bound based on the frame zero offset which is the default behaviour."


What do you think it does?
Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 12th Sep 2011 06:55
GG Thanks for the response... I read the help file and tried the other flags. The zero is the remains of my attempt at trying to turn off recalculation of bounds completely (wondering if this recalculation was causing the lag). The effect was the same as leaving the flag at its default value.

Thanks again

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Sep 2011 12:29
But why have you included the flag on that line at all? You haven't got it on the first one.
Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 12th Sep 2011 12:51
like i said it was left there from my trial and error process. i thought maybe setting the flag to 0 would completely shut of the recalculation and eliminate the FPS drop. but it didnt so i removed it

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Sep 2011 12:23
Quote: "but it didnt so i removed it"


But not from your snippet?

Anyway, if you post a complete simple demo of the problem (no exe file please) I'll look into it.
Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 13th Sep 2011 14:34
correct...
I'll see if I can reproduce it in a quick demo since my actual code is approaching 1k lines with a lot of media.

I was wondering if it would have anything to do with me using FPSC character models for some reason. I used the ones labeled low poly but it didnt seem to help. I also tried leaving them untextured and that didnt help either. It led me to believe the problem was in the code somewhere.

thanks

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Sep 2011 00:34
Quote: "I'll see if I can reproduce it in a quick demo"


Yes please. I sometimes find that problems get solved when that's done - because the task of simplifying the code sometimes draws attention to a coding error.

Is there a reason for using the set object frame command - or could you just use this version of the play object command?

Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 14th Sep 2011 12:13


attached is the model I used. Hold spacebar to see what I mean.

Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 14th Sep 2011 12:15
forgot to mention, when the objects arent animated I get 60-75 FPS, as soon as I press space it drops to about 5-7 FPS. Any help would be great, thanks.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Sep 2011 13:04 Edited at: 14th Sep 2011 13:20
Thanks for the demo.

I've just tried it and the results are a bit odd. Without the spacebar I get a steady 15 fps (). When I press and hold the spacebar the fps gradually drops. I kept it pressed for a few minutes and got bored after about 4 minutes by which time the fps had dropped to 5. Surprisingly it stayed at that level when I released the space bar.

I also tried using play object instead with much the same results (you'd probably need to adjust the speed or something if you want to use that).

I've no idea what should cause a gradual slowdown like that unless one of the commands has a memory leak - and I can't recall how to check that.

I also tried using sync with my native desktop resolution but other than getting much cleaner objects the results were the same. Here's the final code I tried:



As a final experiment I tried using fixed numbers in the play object command like this:



When I do that I get no lag if I set the fixed value to 0, a fall from 15 to 13 fps when I use 100 (as in the snippet), to 12 fps when I use 200 and so on.

This is a pure guess but it makes me wonder whether DBPro is somehow looping through all the frames till it finds the one you specify in the set object frame or play object commands. That would explain the gradual slowdown. If that is the case then it seems as if you need to make sure you use those commands sparingly, i.e. only when the animation sequence has changed. You would then get a lag in just the sync when the change occurs and shouldn't be noticeable.

However, that theory doesn't explain why the lag persists when you release the space bar. That makes me wonder whether this "behind the scenes" looping takes place every sync. In the following snippet, for example, the frame number seems to increase as the FPS drops till the frame reaches 500 when the objects are reset to frame 0 and the fps returns to its original value.

Perhaps someone with more experience of animations has a suggestion.



Sorry about the lengthy post.

Edit The only suggestion I can think of is to use lower poly objects if you need that many on screen at once. I don't know for certain whether that would reduce the problem though.
Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 14th Sep 2011 15:41
Thanks for such a detailed post (no sarcasm )

I will try the play object command as you described and see if I can improve my results. All evidence seems to point at insufficient GPU power but I find this very hard to believe since it is a relatively few number of objects and they are pretty low poly. (unscale the object and you can tell)

Very puzzling....

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Sep 2011 15:49
Quote: "and they are pretty low poly. (unscale the object and you can tell)"


But you had 100 of them. Anyway, I tested your demo with a smaller number and the problem is still there but with higher fps values.

There definitely seems to be some behind the scenes looping going on. If I find out more about that I'll post back.

Quote: "I will try the play object command as you described"


But as I said later in my post that didn't seem to change the problem (I was thinking aloud in that post hence the changes of mind ).
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 14th Sep 2011 16:19 Edited at: 14th Sep 2011 16:59
Hi Suicidal Sledder

I saw your trouble so I figured I would help you out.

I noticed you have over 2,500 frames in that object! lol.
So I set the last frame at 2,500. If it has more frames than that just change it to the last frame you have in that animation. You might have to add a delay to slow the animation down.

Try this code out. You should be above 60 fps and it doesn't drop.


darkvee
Suicidal Sledder
21
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 14th Sep 2011 17:10
unfortunately the problem does not exist for you since you are instancing rather than cloning. The difference is that instanced objects will have the same frame as the source object which is fine for the demo but in my game they need to have their own frames

Thanks though

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Sep 2011 17:20 Edited at: 14th Sep 2011 17:23
That shows the advantages of instancing versus cloning but doesn't address the main problem. What if you had 100 different animated objects?

The key questions are, I believe, (1) why does the lag increase as you set the frame number higher and (2) can anything be done about it (without instancing)?

Obviously if instancing is possible then it should be used.

Edit Suicidal Sledder, you posted while I was messing about with mine.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th Sep 2011 17:27 Edited at: 14th Sep 2011 17:28
Those are nice animations! All I can suggest is that you split all of the animations up into different models. maybe that way, the search for the right frame might be quicker internally. Maybe just make a test with two animations, and see if it is faster.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Sep 2011 17:33
I was thinking of suggesting that too.

Connoisseurs of windows might be interested in this:

multiple copies of task manager

That happened while testing the clone object version on my laptop . The instance object version posted by darkvee ran at a consistent 18 fps.
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 14th Sep 2011 17:37 Edited at: 14th Sep 2011 18:35
Hi Suicidal Sledder np

Ya I put a delay of 100 milliseconds on it and it keeps going down there has to be a memory leak.

This might help you out. You know 100 models on the screen is a lot.
If a game uses 100 on the screen at once there using directx 10 doing a one draw call that can do what you wanting with no fps dropped.

However there is a different way. Do you know how to make 100 models and make them into one object?

This trick you need is to be able to combine them into one model. then using vertex data commands getting the vertexs that go to that certain object in the whole model to pick which object you have in that whole model and animate it.

I say work on combing objects in 1 model since there is a problem with cloning the object then you will be ready to render a lot of stuff without any problems. I hope that helps.

darkvee
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Sep 2011 22:47
You can check out the code to see where some of the issues are.
1. There's a lot of fairly heavy maths in there - 2 vector/matrix multiplies per vertex, plus a matrix/matrix multiplication per bone.
2. There's memory allocated and freed for each mesh being animated (oops!).
3. There appears to be a few small bugs in the code (DBOMesh.cpp, lines 2736 & 2753), their effects are probably not noticeable as bugs, but do cause unnecessary work to be carried out.
4. It triggers a vertex buffer refresh every frame (not unavoidable).

There are probably a few opportunities for optimisation there, but also a good chance of breaking things too.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Sep 2011 01:46
Quote: "You know 100 models on the screen is a lot."


Yes, but the problem persists with fewer models.

Quote: "it keeps going down there has to be a memory leak."


I'm not convinced it is a memory leak. The lag is specifically associated with using a high frame number in my tests and the higher the frame number the greater the lag - and it's reversible when you switch to a lower frame number.

@IanM Yes, there's a lot of math involved in animated models. However, the issue here is that there's an increasing lag the higher the frame number you choose. Is that because the animation is "run from scratch" each sync when you set the frame number and stopped when the specified frame number has been reached? If not, why does the lag increase?
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 15th Sep 2011 05:52 Edited at: 15th Sep 2011 05:55
Hi I got your poly count from your model which is 96 polys each. I put a different 3d model in there that is 680 polys and has only 20 frames in it.

So I then load 101 models with 20 frames works fine runs at over 60 fps and no fps drop at all. That's using the clone object too. I guess Green Gandalf is right about using low frames.

So the next thing you need to do is find out exactly which frame is the highest you can go before it starts causing problems. I hope that helps. I attached a file showing it works with the model.

darkvee
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Sep 2011 00:31 Edited at: 16th Sep 2011 00:32
@GG,
Quote: "Is that because the animation is "run from scratch" each sync"

Disclaimer: I don't pretend to fully understand bone animation, so the following analysis may not be fully accurate.

The actual code that carries out the recalculation of the mesh data shouldn't get slower the longer it runs, unless those memory allocations fragment memory too much, which I can't see happening this quickly.

The only other place that I see potentially substantial loops are in the function DBOFormat.cpp:UpdateAllFrameData, which if the object's 'bAnimManualSlerp' is set (which it is if you call SET OBJECT FRAME) appears to apply interpolation to the animation transformation matrices. Deeper in the code, it appears to be carrying out linear searches to locate the correct data (position, scale, rotation etc) for the specified keyframe, which it then applies the interpolation to. It does several of these linear searches, so the inefficiency of this search method is multiplied, and if you have a lot of keyframes then I'd imagine that this could have quite an impact.

So no, it's not run from scratch each time, but as you get further through the animation, each of these linear searches will take longer. After only a cursory read of the code, it seems that all of these linear searches could be replaced with binary searches fairly simply.

The code for the functions containing these linear searches is in DBOFormat.cpp, lines 97 through to 284.

darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 16th Sep 2011 00:46 Edited at: 16th Sep 2011 00:47
Ya binary search sounds good. A linear with 100 elements in the array takes 50.5 comparisons. While an binary search takes 7.72 So there is a big difference in search algorithms. The smallest comparison is what you want. If you added that in what is the largest frame you could have before it started having problems or would this just fix the problem? Anyways sounds good IanM.

darkvee
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Sep 2011 02:09
Quote: "The actual code that carries out the recalculation of the mesh data shouldn't get slower the longer it runs, unless those memory allocations fragment memory too much, which I can't see happening this quickly."


I don't think memory fragmentation explains why the lag disappears when you reset the frame number to a low value as in one of my demos earlier.

Quote: "Deeper in the code, it appears to be carrying out linear searches to locate the correct data (position, scale, rotation etc) for the specified keyframe, which it then applies the interpolation to. It does several of these linear searches, so the inefficiency of this search method is multiplied, and if you have a lot of keyframes then I'd imagine that this could have quite an impact."


That explanation fits all the facts. I'd put money on that being the cause. A binary search sounds much more sensible - except why is a search needed anyway?

I'm unlikely to have much to say over the next few weeks as I'll be on holiday - but "I'll be back".
Broken_Code
15
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 18th Sep 2011 08:39
I don't mean to sound stupid but are you on about the interpolation between frames or is it deeper in the code?
If it's the interpolation between frames would this command help?

SET OBJECT INTERPOLATION Object Number, Interpolation

Thanks,
BC
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 18th Sep 2011 09:45 Edited at: 18th Sep 2011 09:49
nevermind, frame drop still there!

Your signature has been erased by a mod please reduce it to 600 x 120.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Sep 2011 16:02
Quote: "I don't mean to sound stupid but are you on about the interpolation between frames or is it deeper in the code?"

It's not a stupid question at all.

The linear searches I mention happen every display-frame - they search for the animation-frame to base the interpolation on, so aren't affected by this SET OBJECT INTERPOLATION command.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Sep 2011 02:28
But why is a search required?

Isn't it rather like looking up a specific array location and then doing interpolation between adjacent entries?

I could understand it if the animation data was cumulative so you had to pass through all the earlier steps to get the final position for a specific frame - but then it wouldn't be a search but rather more like an iteration. Is something like that going on?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Sep 2011 16:06
Because when you issue a SET OBJECT FRAME command, you could literally be specifying any frame within the animation - you have to search for the correct interval. Animation frames are specified in time ranges (more specifically, by their start time, with an implied finish time which is specified by the next frame), not by frame numbers, and the time ranges do not have to be identically sized.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Sep 2011 02:08
Quote: "and the time ranges do not have to be identically sized."


I hadn't realised they could vary within an animation. Thanks for the explanation. Makes more sense now - although wouldn't a simple lookup table created at load time be better than a search each time?
Broken_Code
15
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 11th Oct 2011 11:16
Is this something that only occurs with 'SET OBJECT FRAME' or does it happen with all animations?

I have run into this problem with PLAY ANIMATION when there is a number of objects on-screen (a noticeable drop with >3 animated obejcts on-screen) and would like to know if it's the same problem or just a rubbish computer?

Thanks,,
BC
Xystus
22
Years of Service
User Offline
Joined: 2nd Sep 2003
Location:
Posted: 1st Nov 2011 16:41
I have the same problem with FPS creator models and lag, but FPS Creator can play a lot of diferent models without lag.

how it does it?
Broken_Code
15
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 21st Dec 2011 12:09
Not sure if anyone's still watching this thread but I've come accross a solution that might help:

http://forum.thegamecreators.com/?m=forum_view&t=192382&b=1

Thanks,
BC

Login to post a reply

Server time is: 2026-07-09 21:18:49
Your offset time is: 2026-07-09 21:18:49