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.

Dark GDK / Using std::vector or similar to update animations with Mirebens animation class (dbPlayObject broken))

Author
Message
Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 10th Jun 2012 02:16 Edited at: 10th Jun 2012 03:17
I am using Mirebens animation class and wanted to have it automaticlly update the animations without me having to call the class for every object. I am currently using std:: vector like this:


But it takes to long to loop through more than 30 objects, making the game slow down and objects to animate out of sync with each other, I was wondering if anyone had any input on how to improve performance or a better way to achieve this.

Here is the animation class I am using:



EDIT:
Nevermind, I used the fastbone shader from this thread: http://forum.thegamecreators.com/?m=forum_view&t=127395&b=1 and I could animate the same amount of objects at a solid 60 fps.

The objects still don't animate at the same time, there is a slight but visible delay, the animations go out of sync. I think the either the for loop is to slow, or, more likely, vector isn't fast enough at accessing elements, any input is appreciated.
Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 10th Jun 2012 06:12 Edited at: 10th Jun 2012 06:12
Quote: "The objects still don't animate at the same time, there is a slight but visible delay, the animations go out of sync. I think the either the for loop is to slow, or, more likely, vector isn't fast enough at accessing elements, any input is appreciated."

It's the functions within the for-loop, not the vector. Probably the dbSetObjectFrame function call combined with the while loop(if it's a full wrap-around of a long animation, it can be enough to be noticeable above 30 different objects) within the CObject::animateObject function.

Some small optimizations I can make right now though:



If it's still not fast enough, then dbSetObjectFrame is the bottleneck. That's all the tricks I know.

Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 10th Jun 2012 06:44 Edited at: 10th Jun 2012 06:45
Thanks, it didn't make a noticeable difference, but I don't think it will matter all that much anyway (I learned that you can use [] to access the class ). I am having one more problem. My app throws a "std::bad_alloc" error when I load more than 25 or so classes with models into the vector. I am pretty sure it is because I run out of contiguous memory, I was wondering if there was a way to split up the classes in the vector to "spread out" in memory or something so I can actually populate the vector with a usable amount of models.
Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 10th Jun 2012 21:17
You could try using std::deque instead of std::vector.
Have you tried catching the std::bad_alloc exception and seeing what the message is? Usually it has some small detail that can help.

Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 11th Jun 2012 02:22
It throws "bad allocation", I tried deque but it failed after loading 21 objects, the same as vector.
Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 11th Jun 2012 03:05
Instead of doing "std::vector<CObject> olst(35,CObject());"
try doing something like this:


I've never had it crash with a bad_alloc this way.

Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 11th Jun 2012 05:30
It got up to 42 objects that time. When the vector gets too large could I make it so it splits up into smaller vectors?
Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 11th Jun 2012 06:22 Edited at: 11th Jun 2012 06:23
Hmmm...that's strange. I suppose you could, but you'd have to update each of them manually.

One last try at getting it all into one vector(requires VS2010):

This version only stores pointers, not whole objects.

If this doesn't work, you might not have enough memory to do what you need to do. Can I see where this code within your project?

Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 11th Jun 2012 10:18 Edited at: 11th Jun 2012 10:20
I was looking at the model, and it is 26Mb, multiply that by 42 objects in the vector and you get somewhat over 1Gb of memory needed to allocate. I feel... for not looking at that early on.

With that in mind, using your above example, could I have one CObject class with a model loaded then create pointers to that class without having to reload the model. It would be like instancing but I would have control over each model individually.
Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 11th Jun 2012 15:35
Quote: "With that in mind, using your above example, could I have one CObject class with a model loaded then create pointers to that class without having to reload the model. It would be like instancing but I would have control over each model individually."

If you want animation, I'd suggest you clone the objects instead of putting together a pseudo-instancing deal. The majority of the model's size is from the animations, so just have the clones share the animation data of the original object.

Wana7262
12
Years of Service
User Offline
Joined: 23rd Nov 2011
Location:
Posted: 18th Jun 2012 09:25
hi, i have an model reload.x its animating while pressing and holding 'R' how can i make it to complete one loop of animation while just pressing 'R' once, not holding 'R' here is code


Help Please
Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 18th Jun 2012 18:22 Edited at: 18th Jun 2012 18:24
You have to make the animation update through the class, here, I modified the object class to play and loop animations like GDK used to.

CObject.h


CObject.cpp


It uses a struct to holsd info about the model it is using. It is far from complete but the play and loop animation fuctions should work. You have to call animateObject(curTime) in the loop.

EDIT: It uses Techlords object ID management class, so you will have to modify the class to make it work for you. (Plus some other custom functions).
Wana7262
12
Years of Service
User Offline
Joined: 23rd Nov 2011
Location:
Posted: 3rd Jul 2012 19:57
Any example how to use this class???

what i have tried
i created CObject.h included in my main.cpp as header
and copied the CObject.cpp content into my main.cpp
after that i created the Object for the class in void DarkGDK ( void )
like this

and in main Loop i called animateObject(curTime) like this

But i got these Errors


where i m wrong please help... i m noob
Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 3rd Jul 2012 20:37
Tht is why I posted:

Quote: "It uses Techlords object ID management class, so you will have to modify the class to make it work for you. (Plus some other custom functions)."


Remove the "ObjectResource" stuff and replace it with something that gives you unique ID's (
)

And you can remove the "SetAniostropicFilteringOn", that should make it work.

Login to post a reply

Server time is: 2024-11-19 00:41:52
Your offset time is: 2024-11-19 00:41:52