Followers 0
• entries
455
639
• views
421498

More Particles

Followers 0

290 views

I spent a bit of the weekend, between Civ4 sessions and starting a reply of COD4:MW, working on getting a renderer hooked up to the particle system.

The practicle upshot of this was that I had to finish off said particle system and the logic to make it run... ok, so it still doesn't render (I'll be PIXing the hell out of it wednesday evening to figure out why) however it is now hooked up.

So, the setup is pretty simple;
Shard::colourModifierCollection colourMods;Shard::positionModifierCollection positionMods;Shard::rotationModifierCollection rotationMods;Shard::DefaultColour defaultColour = { 1.0f, 1.0f, 1.0f, 1.0f};											// life time in milliseconds therefore 16.6 * 60 = 1 second due to 16ms time steps in hardcoded useShard::EmitterDetails emitterDetails(5000,50,(16.6f*60.0f), 0.05f, defaultColour, 1.0f, positionMods, colourMods, rotationMods);Shard::ParticleEmitter emitter(emitterDetails);Scheduler particleScheduler;

An emitter can have modifiers for colour, position and rotation factors, these are basically std::vectors of function objects which take a few parameters, most of which are structures wrapping references to _m128 type variables due to the SSE underpinnings of the system.

EmitterDetails is a structure which holds information describing an emitter; the idea behind this was that you could construct such a thing in a script and then throw it at the particle system to build your emitter.

Finally the emitter itself is constructed using these emitterDetails; it makes a local copy so one details block can be used to setup multiple emitters.

The last object created in that list is a Scheduler object which is used to allow the queuing of functions to run.

As you might recall from the last update I was debating how to deal with block updating the particle system to spread the load over threads.

In the end I settled for supplying a ISchedular interface which had a simple function to queue tasks.
struct IScheduler{	virtual void ProcessTaskQueue(float) = 0;	virtual void QueueTask(const UpdateFuncType &updateFunc) = 0;};

In this instance its a very simple class indeed;
struct Scheduler : public IScheduler{	Concurrency::task_group group;	Concurrency::concurrent_vector taskVector;		Scheduler()	{			};	void ProcessTaskQueue(float time)	{		if(taskVector.empty())			return;		std::for_each(taskVector.begin(), taskVector.end(), [this,time](UpdateFuncType &task)			{				this->group.run(std::bind(task, time));		});		taskVector.clear();		group.wait();	};	void QueueTask(const UpdateFuncType &updateFunc)	{		taskVector.push_back(updateFunc);	};};

Each task is queued into a vector then, at a later point, a single thread will call the process function which will, in this instance, tell a Concurrency Runtime task group to execute the tasks. We then empty the task queue and wait for them to finish before moving on.

All of which has changed Emitter's PreUpdate function to
        void ParticleEmitter::PreUpdate(IScheduler &taskQueue, float deltaTime)	{		// Services any required trigger calls		while(!queuedTriggers.empty())		{			const EmitterPosition & position = queuedTriggers.front();			if(details.maxParticleCount > usedParticles) 			{				usedParticles += EmitParticles(position);			}			queuedTriggers.pop();		}		// then work out block sizes and schedule those blocks for updates		//TODO: figure out what kind of task interface this is going to use		if(usedParticles > 0 && usedParticles <= 500) 		{			taskQueue.QueueTask(std::bind(&ParticleEmitter::Update, this, _1, 0, usedParticles));		}		else		{			int total = usedParticles;			int start = 0;			while(total > 0)			{				int size = (start + 500 > usedParticles) ? usedParticles - start : 500;				taskQueue.QueueTask(std::bind(&ParticleEmitter::Update, this, _1, start, start + size));				total -= size;				start += size;			}		}         }

The numbers used for division of work are pretty random right now; I'm considering doing something based on cache line size instead to try and improve the work load. This would have a natural knock on to the update functions as well which could probably be changed to do some prefetch work, certainly in the case of the larger update function segments.

Finally, the usage of the Emitter is pretty simple. First we grab a trigger point (technically optional but its a good test)
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){	if(msg.message == WM_LBUTTONUP)	{		int xPos = GET_X_LPARAM(msg.lParam); 		int yPos = GET_Y_LPARAM(msg.lParam);		emitter.Trigger(xPos, yPos);	}	TranslateMessage(&msg);	DispatchMessage(&msg);}

Then, in the update loop (which is currently fixed time step) we do the following;

emitter.PreUpdate(particleScheduler,16.0f);particleScheduler.ProcessTaskQueue(16.0f);emitter.PostUpdate();

And finally rendering is currently done via the deferred context system (which I need to change in order to PIX it later...);
RendererCommand particlePreRendercmd = DeferredWrapper(std::bind(&Shard::ParticleEmitter::PreRender, emitter, _1 ), g_pDeferredContext, width, height);RendererCommand particleRendercmd = DeferredWrapper(std::bind(&Shard::ParticleEmitter::Render, emitter, _1 ), g_pDeferredContext, width, height);Concurrency::send(commandList, particlePreRendercmd);Concurrency::send(commandList, particleRendercmd);

And there you have it, a hooked up, if not yet rendering, particle system.

The next job will be, as I mentioned, to get it rendering so hopefully next update will have some (unimpressive at first I dare say) images to go with it.

After that I'll try to get some decent effects going and figure out how I'm going to video it in action.
And, as I discovered, I'm also going to need a 'material' and 'renderable' system at some point as my Emitter has an annoying amount of D3D11 stuff directly in it.

Well, until next time...

0
Followers 0

There are no comments to display.

Create an account

Register a new account