Discussion:
Display portion of my code starved
(too old to reply)
Jack
2010-03-23 08:16:13 UTC
Permalink
Hi,

First, Thank you guys for the previous replies on my previous questions.

int CAStar::Step(int &sx, int& sy)
{
// ... //
[snip]
D3DXVECTOR2 vec2(m_pBest->x, m_pBest->y);
g_finalArray.push_back(vec2);
RECT rect;
GetClientRect(g_hWndMain, &rect);
InvalidateRect(g_hWndMain, &rect, FALSE);

// ... //
[snip]
}

/////////////////////////////////
The display "code" never gets executed, or executed just a few times, there
was no time slot for me to check the output.

long CALLBACK WndProc(...)
{
//...//
case WM_PAINT:
if (g_finalArray.size() >= 0)
{
DrawRoute(hDC);
}
// ... //
}

void DrawRoute()
{
std::vector<D3DXVECTOR2>::iterator it;
for (it = g_finalArray.begin(); ....
SetPixel(hDC, it->x, it->y, RGB(255,0,255));
}

Does this mean I have to use multi-threading so that
the path (in pixels) can be displayed in the window which shows the results
as soon as it is generated in other part of my program?
Thanks
Jack
David Lowndes
2010-03-23 09:52:17 UTC
Permalink
Post by Jack
int CAStar::Step(int &sx, int& sy)
{
// ... //
[snip]
D3DXVECTOR2 vec2(m_pBest->x, m_pBest->y);
g_finalArray.push_back(vec2);
RECT rect;
GetClientRect(g_hWndMain, &rect);
InvalidateRect(g_hWndMain, &rect, FALSE);
You'd normally just call InvalidateRect with a NULL rect pointer to
invalidate the whole area.
Post by Jack
/////////////////////////////////
The display "code" never gets executed, or executed just a few times, there
was no time slot for me to check the output.
How frequently is your Step method called? i.e. is it swamping the
message queue so that there's no free time for WM_PAINT to get
handled?

Dave
Victor Bazarov
2010-03-23 12:04:46 UTC
Permalink
Post by David Lowndes
Post by Jack
int CAStar::Step(int &sx, int& sy)
{
// ... //
[snip]
D3DXVECTOR2 vec2(m_pBest->x, m_pBest->y);
g_finalArray.push_back(vec2);
RECT rect;
GetClientRect(g_hWndMain, &rect);
InvalidateRect(g_hWndMain, &rect, FALSE);
You'd normally just call InvalidateRect with a NULL rect pointer to
invalidate the whole area.
Post by Jack
/////////////////////////////////
The display "code" never gets executed, or executed just a few times, there
was no time slot for me to check the output.
How frequently is your Step method called? i.e. is it swamping the
message queue so that there's no free time for WM_PAINT to get
handled?
I believe a call to 'UpdateWindow' will force processing of any pending
repaints.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jack
2010-03-23 12:37:49 UTC
Permalink
Thanks Victor,
It is working.
And David, thanks for your input....
See you next question.
Jack
Jack
2010-03-23 12:08:37 UTC
Permalink
Post by David Lowndes
Post by Jack
The display "code" never gets executed, or executed just a few times, there
was no time slot for me to check the output.
How frequently is your Step method called? i.e. is it swamping the
message queue so that there's no free time for WM_PAINT to get
handled?
It all starts out with the WM_COMMAND button,
After pushing it, the program will be looping
like
while (ret == false)
{
ret = Step(sx, sy);
}

Usually, the results would be displayed after the loop has finished. But
there are currently some bugs with my code so that the loop never exits. But
I do want
to look at where its up to on the map, it is a pathfinding project....
Thanks
Jack
David Lowndes
2010-03-23 14:03:10 UTC
Permalink
Post by Jack
It all starts out with the WM_COMMAND button,
After pushing it, the program will be looping
like
while (ret == false)
{
ret = Step(sx, sy);
}
Usually, the results would be displayed after the loop has finished. But
there are currently some bugs with my code so that the loop never exits.
That'll certainly explain why it's never updating :)

If you need to see some animation effect of the steps you might want
to rework that area to make the steps timer driven. That way you
should have free time to get the paint messages without needing to
resort to UpdateWindow.

Dave
Victor Bazarov
2010-03-23 16:02:00 UTC
Permalink
Post by David Lowndes
Post by Jack
It all starts out with the WM_COMMAND button,
After pushing it, the program will be looping
like
while (ret == false)
{
ret = Step(sx, sy);
}
Usually, the results would be displayed after the loop has finished. But
there are currently some bugs with my code so that the loop never exits.
That'll certainly explain why it's never updating :)
If you need to see some animation effect of the steps you might want
to rework that area to make the steps timer driven.
...or WM_IDLE-driven. One of the idiomatic ways to do that is to
perform a few fixed iterations on every idle message until ready. Make
sure to update your UI to indicate that some operation hasn't finished
yet, and update it again when it has finished.

Another idiom is to start a second (worker) thread and perform the
operations there, while the UI thread responds to WM_TIMER (or some
other trigger, possibly coming from the worker thread itself) and paints
the portion that has been calculated so far. This way is more difficult
because you have to set up some kind of communication between threads.
Use WM_IDLE if you're not so confident in making your app multithreaded.

Good luck!
Post by David Lowndes
That way you
should have free time to get the paint messages without needing to
resort to UpdateWindow.
Dave
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Loading...