Question about optimization - 100-1000+ moving objects.

A place for tutorials on how to get the most out of Flash

Question about optimization - 100-1000+ moving objects.

Postby OwnerOfSuccuby » Tue Mar 12, 2013 7:45 pm

Hello every one. Have a little one strange question.

How to make better perfomance in this situation. Is there some new abilities in AS3 after it is new CS6 ?

For example - i have a lot of objects that a located randomly have different size and rotation but all of them ar the same movie clip object that plays.

I have for example 100+ or even 1000+ on the stage.

Is it a way to make it work faster and eat less CPU ? May be some body see any of this problems before ?
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Question about optimization - 100-1000+ moving objects.

Postby GoRepeat » Wed Mar 13, 2013 2:36 am

You could try playing around with some 3rd party toolkits that are designed specifically for it... like that one bird one... sparrow? I forget the name :(

Other than that, just try to use compressed bitmaps without any actual object data.
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass

Re: Question about optimization - 100-1000+ moving objects.

Postby BlueLight » Wed Mar 13, 2013 5:37 am

threads might help? ya i have no clue.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Question about optimization - 100-1000+ moving objects.

Postby IrrelevantComment » Sun Mar 24, 2013 11:03 pm

BlueLight Wrote:threads might help? ya i have no clue.

I loled at the idea of Flash supporting threading

Why would you possibly need 1000+ objects on stage at once? Maybe you should rethink what you are trying to do, rather than optimise it. Still, suggestions: if by on the stage you simply mean in the display list and not on screen, then consider removing objects that are off screen from the stage. Alternatively, try removing objects that are covered up by others. Last thing I can think of is to reduce the frame rate.
IrrelevantComment
 
Joined: Tue Mar 15, 2011 7:46 pm

Re: Question about optimization - 100-1000+ moving objects.

Postby dirtyc101 » Mon Mar 25, 2013 2:39 am

Could you group the objects together, so that it looks like 1000 items, but it is really much less? For example, Put 100 copies of the item on a single master object, and then you only need to move 10 master objects rather than 1000 individual ones. Saw something like this done with raindrops. Might help here, might not.
DirtyC101
dirtyc101
 
Joined: Fri May 21, 2010 10:18 pm

Re: Question about optimization - 100-1000+ moving objects.

Postby OwnerOfSuccuby » Mon Mar 25, 2013 12:28 pm

It is for water and the same object animation. A want to try to make water looks more realistic :mrgreen: . If i take as much moving small parts and make it moves a little random than more realistic water looks - but more lugs.

But in other way you right - human can not remember if to many objects move so there movment will look different for him if to make not short animation - so may be make it radomly move is not nesessary. And if group it to less number of playing objects with more parts it will use less CPU.

Thank you for idea i will try it ;)
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Question about optimization - 100-1000+ moving objects.

Postby rpgmaker » Sun Apr 21, 2013 5:50 am

Maybe convert to bitmap? You will "lose" the option to resize in vector, but if you know the final resolution you want your animation to be, it would drastically reduce any lag and make the animation a lot faster/smoother. Give it a try!

Let us know if it worked. (Can we see a preview of that huge project? :D)

RP
rpgmaker
 
Joined: Thu Apr 18, 2013 2:36 am

Re: Question about optimization - 100-1000+ moving objects.

Postby jerkface » Thu Jun 06, 2013 11:20 am

The problem with simulating large amounts of physics objects is thus: checking collision between objects is an n-squared problem. Meaning if you have n objects you need to do n^2 collision checks. The simplest way to resolve this is to simply not check collision between the objects you're using. This is what you do for a particle system where you're trying to get a fountain or flame effect or the like. There should be no issue- even in Actionscript- in updating the position of an object from force, acceleration and velocity a thousand times per frame.


If you must have collision between the objects you need what is known as a broad phase. This is basically a general sweep of your physics objects to see which ones are likely colliding and then doing more complicated checks on those objects who look like they might. The two most common ways to do a broad phase are:

1) This is the simple version. Simply do a very cheap collision test between each pair of physics objects, if they are flagged as colliding in that test then you do the more expensive collision test. The test used for this is called AABB collision. I won't go into it here because you can look it up pretty easily. But in all honesty you should only be using AABB collision for a simple flash project. The only other thing I can imagine you doing is using sphere collision for everything. This is terrible because it requires the use of a square root function which is very CPU intensive. "But my objects are spheres!" You say. Well, it doesn't matter because humans are terrible at determining if two objects have collided by just looking at them. If it looks funky, just make the bounding box smaller than the graphical part of the sprite and it's solved. A C++ implementation of this can simulate several hundred physics objects simultaneously.

2) Spatial partitioning. This is hard. You need a 2D array that represents every n units of your physics space where n is a little over the maximum dimension (height, width, depth) of your largest physics object. Then you put every physics object in that array based on it's center point. Then you look at every physics object and all the physics objects in the same slot of that array and all the physics objects in every neighboring slot (diagonals too!) and cue up a collision test for those objects. Once all this work is done, *then* you can do the actual collision tests. This will result in the largest speed-up but it has a few issues: it requires actual programming knowledge to pull off, it isn't very effective if the objects are radically different sizes and, oh god you're using Actionscript so it's gonna be slow as balls and I have no idea how much speed you can actually milk out of it. A C++ implementation of this can simulate around ten thousand physics objects simultaneously.

EDIT:
Now that I've written all of that out I remembered that there is an even simpler fix: Just integrate the Flash version of Box2D into your project. Congratulations! You now have the best Flash-based physics engine currently in existence. If anything in Flash can handle that many colliding objects it's Box2D.
User avatar
jerkface
 
Joined: Thu Jun 06, 2013 10:16 am

Re: Question about optimization - 100-1000+ moving objects.

Postby FMPraxis » Thu Jun 13, 2013 9:09 pm

I'm not sure exactly what you're looking for in your water, but have you looked at BitmapData.perlinNoise ?
FMPraxis
 
Joined: Mon Jun 25, 2012 10:14 am

Re: Question about optimization - 100-1000+ moving objects.

Postby jerkface » Fri Jun 14, 2013 11:11 am

FMPraxis Wrote:I'm not sure exactly what you're looking for in your water, but have you looked at BitmapData.perlinNoise ?


That made me laugh out loud at my own stupidity.
...I need to reevaluate what is going on here.

Regardless of what you're trying to accomplish, stop trying to play animations on your water particles. You get almost no benefit from it and it eats processing time like mad.

Are you trying to use water as a game mechanic? If so, see my post above.

Are you just trying to just make a nice water animation? Look up "particle effects" and see if there are any pre-made systems in Flash to make it happen. It isn't an easy problem and it requires more programming knowledge than can be conveyed in a simple forum post. Or you can fake it.
User avatar
jerkface
 
Joined: Thu Jun 06, 2013 10:16 am


Return to Tutorials



Who is online

Users browsing this forum: No registered users