parallel_do And Parameter Passing

parallel_do And Parameter Passing

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

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);
[sectionbody]Here's my "Body" object. It's Error free currently, though I can't pass it a variable from outside[/sectionbody]

class DrawList
	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 

[sectionbody]Of course, I might be barking up the wrong tree trying to use parallel_do. Correct me if I'm wrong..[/sectionbody][sectionbody]

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

How about passing just m_Drawlist, without the parentheses...

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?

I think I need to create a mute or semaphore out of the HWND - having only one sprite on the screen showed no flickering

Or, more logically, a barrier the size of the number of elements in the vector before drawing... :PThat sounds good right?

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.

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...

Leave a Comment

Please sign in to add a comment. Not a member? Join today