Jump to content

View more

Image of the Day

Working on an auto spawn system. #gamedev #indiedev #screenshotsaturday https://t.co/Mm2kfekz7b
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Call for Design Comments

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 greenvertex   Members   

510
Like
0Likes
Like

Posted 08 November 2012 - 11:58 AM

I'd really like some opinions on the following idea:

struct DXBundle {
  ID3D11Device* device;
  ID3D11DeviceContext* context;
  D3D_FEATURE_LEVEL* featureLevel;
 
  DXBundle() {
    UINT createFlags = 0;
#if _DEBUG
    createFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
    return D3D11CreateDevice(
	  0, D3D_DRIVER_TYPE_HARDWARE, 0, createFlags,
	  0, 0, D3D11_SDK_VERSION, device, featureLevel, context);
  }
  ~DXBundle() {
	  if(context) {
	    context->ClearState();
	    context->Flush();
	    context->Release();
	  }
	  if(device) {
	    device->Release();
	  }
  }
};

There's a couple places I could see using this, the above example is a simple one that appears fairly convenient. Automatic construction and release at the cost of a dot operator seems like a fair trade. Anyone know of any reasons to avoid creating little "construction wrappers" like this?

Note: I've left out copy and copy assign intentionally for readability, that and the jury's still out on how I want to handle them in this particular instance...

#2 incertia   Members   

787
Like
0Likes
Like

Posted 12 November 2012 - 09:40 PM

If it's personal code and you understand everything that is going on, then sure.

However, if other people are reading your code or if you may forget why you did it like that, then I suggest you you wrap everything in a nice class with functions that can change how you want the device to be created.
what




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.