• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
  • entries
    455
  • comments
    639
  • views
    421498

More Particles

Sign in to follow this  
Followers 0
_the_phantom_

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 use
Shard::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
Sign in to follow this  
Followers 0


0 Comments


There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now