Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.






C++0x as per VS2010

Posted by phantom, 13 March 2010 · 136 views

So, I've come to a conclusion about C++0x; I do love the lambda stuff [grin]


float multiplier[] = { -1, 1};
int i = 0;
int j = 0;
std::for_each(dataPoints.begin(), dataPoints.end(), [&](PointAffinity dataPoint)
{
pData[i].m_driveValue = bands[dataPoint.side][j] * multiplier[sourceSelect] * 7.0f;
pData[i].position = dataPoint.position;
i++;
if(i % 2 == 0)
j++;
}
);




Something about being able to write that inline is rather nice [smile]

Then there is always this little bit of fun;

int counter = 0;
float multiplier = 1.0f;
std::for_each(dataPoints.begin(), dataPoints.end(), [&](PointAffinity &point)
{
point.incAmount *= multiplier;
if(point.side == 0)
{
++counter;
}
if(counter % 2)
{
multiplier += 0.2f;
}
});




And having 'bind' as part of the std namespace is nice as well;

struct ID3D11CommandList;
struct ID3D11DeviceContext;

typedef std::function<void (ID3D11DeviceContext*)> deferredFunction_t;

struct RendererCommand
{
RendererCommand() : cmdID(EDrawingCommand_NOP), cmd(NULL), time(0) {};
RendererCommand(DrawingCommandType cmdID, ID3D11CommandList * cmd, DWORD time);
RendererCommand(DrawingCommandType cmdID, const deferredFunction_t &function, DWORD time);
RendererCommand(const RendererCommand &rhs);
~RendererCommand();

DrawingCommandType cmdID;
ID3D11CommandList * cmd;
deferredFunction_t deferredFunction;
DWORD time;
};

RendererCommand DeferredComputeWrapper(const std::function<void (ID3D11DeviceContext*)> &func, ID3D11DeviceContext * context)
{
func(context);
ID3D11CommandList * command = NULL;
context->FinishCommandList(FALSE, &command);
return RendererCommand(EDrawingCommand_Render, command, 0);
}

RendererCommand computeCmd = DeferredComputeWrapper(std::bind(UpdateCompute, width, height,_1), g_pDeferredContext);
Concurrency::send(commandList, computeCmd);
// or even
Concurrency::send(commandList, RendererCommand(EDrawingCommand_Function, std::bind(UpdateCompute, width, height, _1), 2));



Yeah, I think me and VS2010 + C++0x are going to get along just fine... [grin]




Recent Entries

Recent Comments

PARTNERS