Any advice on multiple animations within a view? |
|
Author |
Message |
RGRussSCCAudio

|
Posted: Thu May 03 11:30:04 CDT 2007 |
Top |
MFC >> Any advice on multiple animations within a view?
Hi,
I have an app where the main view (CView-derived) displays a background
image and has multiple child windows running animations. I initially
decided on a separate child window for every animation. Each animation
window occupies anywhere from 1/8 to 1/4 of the view. Having separate
windows simplified some things like management of timers, automatic clipping
while painting the view's background (animations do not cover the entire
view), etc.
I'm now wondering if this is the most efficient way. I'm considering
getting rid of child windows and doing animations within the view. My main
concern is painting of the background without affecting regions occupied by
the animations. What is the best way of doing it?
Can someone please let me know pros and cons for the above approaches?
Thanks,
Bogdan
Visual Studio136
|
|
|
|
 |
Joseph

|
Posted: Thu May 03 11:30:04 CDT 2007 |
Top |
MFC >> Any advice on multiple animations within a view?
First, it is critical to define what you mean by "efficiency". Without a definition of
what you hope to achieve, AND NUMBERS TO BACK IT UP, issues about "efficiency" are largely
meaningless discussions.
If for some reason you can actually determine that the alternate solution *is* "more
efficient" (whatever that might mean), then all you need to do is create a clipping region
and call SetClipRegion to establish it.
Unless you are having a detectable performance issue (and have some evidence to suggest
that an alternative implementation would improve performance), there is no particular
reason to change what you are doing.
joe
>Hi,
>
>I have an app where the main view (CView-derived) displays a background
>image and has multiple child windows running animations. I initially
>decided on a separate child window for every animation. Each animation
>window occupies anywhere from 1/8 to 1/4 of the view. Having separate
>windows simplified some things like management of timers, automatic clipping
>while painting the view's background (animations do not cover the entire
>view), etc.
>
>I'm now wondering if this is the most efficient way. I'm considering
>getting rid of child windows and doing animations within the view. My main
>concern is painting of the background without affecting regions occupied by
>the animations. What is the best way of doing it?
>
>Can someone please let me know pros and cons for the above approaches?
>
>Thanks,
>Bogdan
>
>
Joseph M. Newcomer [MVP]
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
|
|
|
|
 |
MrAsm

|
Posted: Thu May 03 11:45:30 CDT 2007 |
Top |
MFC >> Any advice on multiple animations within a view?
On Thu, 03 May 2007 12:30:04 -0400, Joseph M. Newcomer
>First, it is critical to define what you mean by "efficiency". Without a definition of
>what you hope to achieve, AND NUMBERS TO BACK IT UP, issues about "efficiency" are largely
>meaningless discussions.
>Unless you are having a detectable performance issue (and have some evidence to suggest
>that an alternative implementation would improve performance), there is no particular
>reason to change what you are doing.
I do agree with Joe's points.
Moreover, if you are doing your animations using GDI (it seems to me
that you did not specify that in your original post), you might
consider switching to OpenGL (or DirectGraphics) to take advantage of
the accelerated 3D hardware for the animation rendering.
MrAsm
|
|
|
|
 |
bogdan

|
Posted: Thu May 03 13:55:00 CDT 2007 |
Top |
MFC >> Any advice on multiple animations within a view?
I agree that 'efficiency' was not the best word to describe what I was
after. I think that I should've used 'performance' instead.
Anyway, I'm looking for ways to improve the app's performance on the
presentation side. This is not a huge concern to me and I can live with
what I've got now. Still, if there is a relatively simple way to improve it
then I'll go for it.
To clarify my previous post...
Can I expect any improvements in rendering if I do all animations in a
single window? If I do that I'd limit the number of resources used -
timers, message queues, graphics contexts, etc. Is this even worth the
trouble? On average, my app runs about 5 animations at a time.
The code that deals with presentation is just a tiny fraction of the whole
app so I don't want (and can't afford) to do a major re-write (e.g. moving
from GDI to OpenGL or DirectDraw).
BTW, is SetClipRegion part of SDK or is it only available in .NET? How do I
clip a region consisting of multiple rectangular areas?
Thanks,
Bogdan
> First, it is critical to define what you mean by "efficiency". Without a
> definition of
> what you hope to achieve, AND NUMBERS TO BACK IT UP, issues about
> "efficiency" are largely
> meaningless discussions.
>
> If for some reason you can actually determine that the alternate solution
> *is* "more
> efficient" (whatever that might mean), then all you need to do is create a
> clipping region
> and call SetClipRegion to establish it.
>
> Unless you are having a detectable performance issue (and have some
> evidence to suggest
> that an alternative implementation would improve performance), there is no
> particular
> reason to change what you are doing.
> joe
>
>
>>Hi,
>>
>>I have an app where the main view (CView-derived) displays a background
>>image and has multiple child windows running animations. I initially
>>decided on a separate child window for every animation. Each animation
>>window occupies anywhere from 1/8 to 1/4 of the view. Having separate
>>windows simplified some things like management of timers, automatic
>>clipping
>>while painting the view's background (animations do not cover the entire
>>view), etc.
>>
>>I'm now wondering if this is the most efficient way. I'm considering
>>getting rid of child windows and doing animations within the view. My
>>main
>>concern is painting of the background without affecting regions occupied
>>by
>>the animations. What is the best way of doing it?
>>
>>Can someone please let me know pros and cons for the above approaches?
>>
>>Thanks,
>>Bogdan
>>
>>
> Joseph M. Newcomer [MVP]
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
|
|
|
|
 |
Joseph

|
Posted: Thu May 03 15:54:28 CDT 2007 |
Top |
MFC >> Any advice on multiple animations within a view?
For animations, the key idea for performance enhancement has already been proposed: move
to DirectX/OpenGL. This will probably buy you an order of magnitude or so performance
improvement; the rewrite to multiple images will probably gain single-digit percentages,
or even be slower (no way to tell without numbers).
Define your performance problem. Is it frames-per-second time or what? What are you
using to trigger the animations (WM_TIMER is bad for anything that requires accurate
timing, since it kind-of-sort-of-relates to whatever time you set)
As to the detailed question, no. Rendering pixels takes the same amount of time. Timers
are not a limited resource. Message queues are not relevant to performance. Graphics
contexts have a minute impact (since they are so fast to create) but you could create
windows with the CS_OWNDC style which would keep the DC active across drawing activations
(remember to clean it up each time!)
It is not clear that you will see any significant performance improvement for 5 simple
animations.
In one case, I had some interesting problems with synchronization of animation effects,
since all timers were free-running. I solved this by putting one timer in the main frame
window and doing a SendMessageToDescendants to force a redraw. This kept everything
pretty much in sync, except for the skew of the WM_PAINT messages arriving at different
times. I fixed this by doing all the drawing directly, not in the OnPaint handler; so the
code was
void CMyWIndow::OnPaint()
{
CPaintDC dc(this);
DrawStuff(dc);
}
LRESULT CMyWindow::OnRequestRepaint(WPARAM, LPARAM)
{
CClientDC dc(this);
DrawStuff(dc);
return 0;
}
void CMyWindow::DrawStuff(CDC & dc)
{
... do drawing
}
so at any time if a WM_PAINT came in, everything worked, but I could force it to
explicitly draw if I needed to. But note also this was in WIn16, which ran on slow
machines and had a slow GDI. I wouldn't do this optimization today unless I saw the same
problems I did twelve years ago.
joe
>I agree that 'efficiency' was not the best word to describe what I was
>after. I think that I should've used 'performance' instead.
>
>Anyway, I'm looking for ways to improve the app's performance on the
>presentation side. This is not a huge concern to me and I can live with
>what I've got now. Still, if there is a relatively simple way to improve it
>then I'll go for it.
>
>To clarify my previous post...
>
>Can I expect any improvements in rendering if I do all animations in a
>single window? If I do that I'd limit the number of resources used -
>timers, message queues, graphics contexts, etc. Is this even worth the
>trouble? On average, my app runs about 5 animations at a time.
>
>The code that deals with presentation is just a tiny fraction of the whole
>app so I don't want (and can't afford) to do a major re-write (e.g. moving
>from GDI to OpenGL or DirectDraw).
>
>BTW, is SetClipRegion part of SDK or is it only available in .NET? How do I
>clip a region consisting of multiple rectangular areas?
>
>Thanks,
>Bogdan
>
>
>
>
>> First, it is critical to define what you mean by "efficiency". Without a
>> definition of
>> what you hope to achieve, AND NUMBERS TO BACK IT UP, issues about
>> "efficiency" are largely
>> meaningless discussions.
>>
>> If for some reason you can actually determine that the alternate solution
>> *is* "more
>> efficient" (whatever that might mean), then all you need to do is create a
>> clipping region
>> and call SetClipRegion to establish it.
>>
>> Unless you are having a detectable performance issue (and have some
>> evidence to suggest
>> that an alternative implementation would improve performance), there is no
>> particular
>> reason to change what you are doing.
>> joe
>>
>>
>>>Hi,
>>>
>>>I have an app where the main view (CView-derived) displays a background
>>>image and has multiple child windows running animations. I initially
>>>decided on a separate child window for every animation. Each animation
>>>window occupies anywhere from 1/8 to 1/4 of the view. Having separate
>>>windows simplified some things like management of timers, automatic
>>>clipping
>>>while painting the view's background (animations do not cover the entire
>>>view), etc.
>>>
>>>I'm now wondering if this is the most efficient way. I'm considering
>>>getting rid of child windows and doing animations within the view. My
>>>main
>>>concern is painting of the background without affecting regions occupied
>>>by
>>>the animations. What is the best way of doing it?
>>>
>>>Can someone please let me know pros and cons for the above approaches?
>>>
>>>Thanks,
>>>Bogdan
>>>
>>>
>> Joseph M. Newcomer [MVP]
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>
Joseph M. Newcomer [MVP]
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
|
|
|
|
 |
|
|