can be used in:
x-fader dialog, for pos
row dialog? for val
master dialog, for all except damping?
Saturday, July 23, 2005
Friday, July 22, 2005
line width: DC pen optimization
Don't re-select the DC pen when it's already selected: the GetStockObject and SelectObject calls are considerably more expensive than the test that avoids them.
Benchmark comparing wide-line version to original (default patch, total time spent in Draw function, 1000 calls) reveals that the wide-line version takes 0.06% longer:
old way:
1.3425
1.3459
1.3457
1.3393
1.3419
1.3411
1.3449
AVG = 1.3430
new way:
1.3433
1.3453
1.3428
1.3405
1.3467
1.3431
1.3456
AVG = 1.3439
another test, using Pinwheel but with # sides set to 20 and no LFO, 2500 samples
new 21.6328
old 21.5634
0.32% slower
again:
new 21.6226
old 21.5317
0.42% slower
Benchmark comparing wide-line version to original (default patch, total time spent in Draw function, 1000 calls) reveals that the wide-line version takes 0.06% longer:
old way:
1.3425
1.3459
1.3457
1.3393
1.3419
1.3411
1.3449
AVG = 1.3430
new way:
1.3433
1.3453
1.3428
1.3405
1.3467
1.3431
1.3456
AVG = 1.3439
#include "benchmark.h"
#define MAXSAMPS 1000
double samp[MAXSAMPS];
int samps;
bool done;
void CWhorldView::Draw(HDC dc)
{
Benchmark b;
...
if (samps < MAXSAMPS) {
samp[samps++] = b.Elapsed();
} else {
if (!done) {
FILE *fp = fopen("test.txt", "w");
double sum = 0;
for (int i = 0; i < samps; i++) {
fprintf(fp, "%f\n", samp[i]);
sum += samp[i];
}
fclose(fp);
done = 1;
CString s;
s.Format("%f", sum);
AfxMessageBox(s);
}
}
another test, using Pinwheel but with # sides set to 20 and no LFO, 2500 samples
new 21.6328
old 21.5634
0.32% slower
again:
new 21.6226
old 21.5317
0.42% slower
line width
creating a 1-pixel wide CPen and selecting it takes 85 micros (avg)
best case is around 8 micros, worst case is 850 to nearly 1000 (!)
setting DC pen color and selecting DC pen takes 2 micros (avg)
best case is 1 micro, worst case is 5
CPen way is anywhere from 2 to 1000 times slower
it's worth it to branch if you plan on doing a lot of 1-pixel wide lines
best case is around 8 micros, worst case is 850 to nearly 1000 (!)
m_Pen.DeleteObject();
m_Pen.CreatePen(PS_SOLID, 1, rp.Color);
SelectObject(dc, m_Pen);
setting DC pen color and selecting DC pen takes 2 micros (avg)
best case is 1 micro, worst case is 5
CPen way is anywhere from 2 to 1000 times slower
it's worth it to branch if you plan on doing a lot of 1-pixel wide lines
Wednesday, July 20, 2005
Monday, July 18, 2005
Alt (menu) key
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
// in full screen mode, ignore the Menu key, so we don't go modal
if (pMsg->message == WM_SYSKEYDOWN && pMsg->wParam == VK_MENU && m_IsFullScreen)
return(TRUE);
return CFrameWnd::PreTranslateMessage(pMsg);
}
Friday, July 08, 2005
zoom
zoom can position origin off-canvas, resulting in no rings
in SetNormOrigin, must clamp:
in SetNormOrigin, must clamp:
m_Origin.x = CLAMP(round(m_Size.cx * m_st.NormOrg.x), m_Canvas.left, m_Canvas.right - 1);
m_Origin.y = CLAMP(round(m_Size.cy * m_st.NormOrg.y), m_Canvas.top, m_Canvas.bottom - 1);
Tuesday, July 05, 2005
Optimizing message order in a message map is useless
MFC caches the most frequently used messages anyway, to avoid repeated table searching.
Saturday, July 02, 2005
mouse damping
Zone rings does damping from the timer hook: It repeatedly computes the difference between the origin and the mouse cursor, multiplies the difference by a normalized damping factor, and adds the result to the origin. The damping factor ranges from 0..1, 0 = maximum damping, 1 = no damping. At damping = 1, the result is always equal to the entire distance between origin and cursor, so the origin jumps immediately to the cursor position. At damping = 0, the origin would never move at all. Maybe the damping factor is kept above zero to prevent this.
Subscribe to:
Posts (Atom)