parallel_do And Parameter Passing

parallel_do And Parameter Passing

Bild des Benutzers giarknot

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
{
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 
	}
};

[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]

7 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers Raf Schietekat
Best Reply

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

Bild des Benutzers giarknot

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?

Bild des Benutzers giarknot

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

Bild des Benutzers giarknot

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

Bild des Benutzers Raf Schietekat

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.

Bild des Benutzers giarknot

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

Melden Sie sich an, um einen Kommentar zu hinterlassen.