Community
cancel
Showing results for 
Search instead for 
Did you mean: 
giarknot
Beginner
32 Views

parallel_do And Parameter Passing

Jump to solution
Hi there.
I'm trying to speed up a Drawing routine in my GameEngine which traverses accross an std::vector of "Sprites"
The issue I have is that the Draw function that the Sprites can execute requires a parameter, a windows HDC in order to work properly, but I've not found a way of allowing that in without an error.
The final parameter in parallel_do is the problem:
"
error C2064: term does not evaluate to a function taking 0 arguments
[cpp]void GameEngine::DrawSprites(HDC hDC) { // Create a new instance of DrawList DrawList m_DrawList; m_DrawList.m_hDC = hDC; // me trying to plug the HDC in... // Draw the sprites in the sprite vector vector::iterator siSprite; tbb::parallel_do(m_vSprites.begin(), m_vSprites.end(), m_DrawList()); // for (siSprite = m_vSprites.begin(); siSprite != m_vSprites.end(); siSprite++) // (*siSprite)->Draw(hDC); }[/cpp][sectionbody]Here's my "Body" object. It's Error free currently, though I can't pass it a variable from outside[/sectionbody]
[cpp]class DrawList
{
public:
	HDC m_hDC;   // My attempt at storing the HDC, and passing it into 
                     // the class seperately in GameEngine::DrawSprites
	DrawList() {};
	void operator() (Sprite* siSprite) const {    //siSprite comes from vector container
		(siSprite)->Draw(m_hDC); //need to pass the HDC in order to work 
	}
};[/cpp] 
[sectionbody]Of course, I might be barking up the wrong tree trying to use parallel_do. Correct me if I'm wrong..[/sectionbody][sectionbody]
[/sectionbody]
0 Kudos
1 Solution
RafSchietekat
Black Belt
32 Views
How about passing just m_Drawlist, without the parentheses...

View solution in original post

6 Replies
RafSchietekat
Black Belt
33 Views
How about passing just m_Drawlist, without the parentheses...

View solution in original post

giarknot
Beginner
32 Views
Ah, thanks. That works now.
However, the sprites on screen are all flickering now. I suppose I need to figure out how to make things wait for all of them to be drawn?
giarknot
Beginner
32 Views
I think I need to create a mute or semaphore out of the HWND - having only one sprite on the screen showed no flickering
giarknot
Beginner
32 Views
Or, more logically, a barrier the size of the number of elements in the vector before drawing... :P
That sounds good right?
RafSchietekat
Black Belt
32 Views
I don't know, but make sure you have enough work per task not to drown in parallel overhead, or in overhead related to multiple drawing instructions if a single call could be used instead.
giarknot
Beginner
32 Views
I'm using the boost barrier. But have an issue with the whole "Function Object" system.
I've got a pointer to a barrier in the DrawList function object, and set the count to the current size of my Sprites Vector.
However, I end up with a deadlock issue...
Reply