views:

42

answers:

2

Hi,

Well I'm having a hell of a time trying to get my CPU down under 45% when running my current application. I've tried all sorts of optimization tricks and tips with little success and I'm at a point now where I need a fundamentally different approach.

Problem and Current Approach

In the main view of my application I have a single enterframe handler. I have my frame rate down as low as 10 fps. This handler notifies 16 seperate movie clips to draw wedges of varying angles using Lee Brimelow's wedge class.

So, 16 times every enterframe, I have 16 movieclip graphic clear, begin fill, draw wedge, endfill all being co-ordinated by my single enterframe handler.

Doing this is bumping my cpu up to between 40-50% :o

Possible Alternative?

I had one idea of just having a movie clip that was 360 frames long and revealing segments of a circle using a mask but I'm not an animator and have no idea how to make such a mask.

Question

So, I guess my method just isn't going to cut it. Can anybody suggest a better method for trying to accomplish my goal?

I don't see how drawing 16 wedges per frame = such a high cpu, so I must be doing something fundamentally wrong.

Any ideas?

MAIN EVENT FUNCTION

private function updatePadProgress(e:Event):void
        {

            viewStackContainer.remixscreen.padUIManager.updatePadArcs2(this.model.audioEngine._channels)
        }

Looping through all circles Passing values

public function updatePadArcs2(channels:Vector.<Channel>):void
        {
            var pc:PadContainer;
            var input:Input
            var c:int=0;
            var p:int=0;
            var pct:Number;
            var cc:Channel
            var position:int=0
            var len:int=0


            for (var i:int=0; i < pads.length; ++i)
            {
                pc=pads[i];
                c=pc.channelassign;
                p=pc.padassign;

                input=channels[c].inputs[p];

                if (input.currentState == Input.ACTIVE)
                {

                    position=input.inputAudio.samples.position
                    len=input.inputAudio.samples.length
                    pct= position/len 
                    pc.drawProgress(pct)

                }

            }


        }

The Drawing Function

public function drawProgress(pct:Number):void
        {
            pad.drawOn.graphics.clear()
            pad.drawOn.graphics.beginFill(0x000000)
            Wedge.draw(pad.drawOn,0,0,10,360,0)
            pad.drawOn.graphics.endFill()
        }
A: 

I suppose this can be caused by the fact, that the whole screen needs to be repainted a lot. Does it perform better, if you cut down the size or omit the fill?

edit: the code for drawing the wedges looks good. Drawing 1000s of lines should not really cause a big performance hit. Filling big areas may however. If you hit the same pixel 16 times, there are chances it is actually drawn 16 times (optimizing drawing of arbitrary shapes is not so obvious).

greetz
back2dos

back2dos
Thanks for the reply.Are you suggesting that reducing the size of the circle could improve performance?Currently each circle has a radius of 10 pixels.
dubbeat
@dubbeat: ok, than that's hardly the problem. try omitting different parts of the app to isolate the performancekiller. how well does it run if you use an empty `drawProgress`-routine?
back2dos
if i use an empty drawprogress routine the cpu drops down to 20 %
dubbeat
+1  A: 

The solution that worked for me was to set any asset on stage that doesnt need to be updated every frame to be cached as a bitmap.

It dropped my CPU down to 20%

dubbeat