Jump to content

  • Log In with Google      Sign In   
  • Create Account


Chris_J_H

Member Since 21 May 2011
Offline Last Active Mar 17 2014 03:26 AM
-----

Topics I've Started

Help with Polymorphic Class Design

24 May 2013 - 02:39 AM

Hi - apologies if this is a bit vague but I am trying to understand the consequences of some base class design choices in my game engine. Below are 2 simplified Process classes that are designed to be used as Base Classes. It seems to me on the face of it Process1 is a better design choice as it demands way less of clients' derived classes - eg, having to remember to invoke Process1::VPause() - although I guess there is a loss of flexibility... In Derived2 for example the client could choose not to pause the process if some condition is met.
 
Insight/Advice appreciated - is there a better way? I really hate the routine requirement to invoke the base class VPause()... it seems to be asking for trouble.

 


class Process1

{

public:

    virtual ~Process1();

 

    bool GetPaused() const {return m_bPaused;}

    void SetPause(bool b) {if (b!=GetPaused()) {m_bPaused = b; VPause(b);}}

 

protected:

    virtual void VPause(bool b) { }

 

private:

    bool m_bPaused;

};

 

class Derived1 : public Process1

{

//...

   void VPause(bool b) override { /* do something - no need to worry about m_bPaused, invoking Process1::VPause() etc*/}

};

 

// --------------------------------------------------------------------------------

 

class Process2

{

public:

   virtual ~Process2();

 

   bool GetPaused() const {return m_bPaused;}

   virtual void VPause(bool b) {m_bPaused = b;}

 

private:

   bool m_bPaused;

};

 

class Derived2 : public Process2

{

//...

   void VPause(bool b) override {

   if (b!=GetPaused()) {

      //...

   }

   Process2::VPause(b);}

};

 


Managing Overlapping Multiple Viewports

09 April 2013 - 04:26 AM

Hi - I am having a bit of difficulty getting my head around how I should be approaching the following problem in D3D11:

 

My (simple) 3D game has 2 players, split screen showing the main forward views. Overwriting each of the 2 main views there are 2 smaller rectangles with the left & right side views. So in total: 2 main (non-overlapping) views and then 4 additional sub-views (overlapping). In D3D9 it was no problem I could clear the DepthStencilBuffer for each view's view-port and keep rendering to the back buffer in my swap chain. Not so easy in D3D11: I cannot seem to easily partially clear the DepthStencil Buffer.

 

I have a skybox effect that I can employ with a depthbuffer overwrite which, if I render first, should do the job... but is this the best way? - what if I have no sky...

 

This must be a common problem, and have seen some discussion in the forums on related issues but don't seem to have a clear understanding of alternative approaches. Insight appreciated.


Scene Lighting : Passing structs of arrays of structs via cbuffer

05 April 2013 - 08:39 AM

Hi, I have a variable number of spotlights in my scene and would like to pass in all my lighting info via a single cbuffer update. Ideally something that would look like this:

 

// hlsl --------------------------------------------------

struct DirectionalLight
{
    float4         ambient;
    //...
};

struct SpotLight
{
    float3        pos;
    //...
};

 

cbuffer LightingBuffer            : register (b0)
{
    DirectionalLight   gDirectionalLight;

    SpotLight           gSpotLight[4];
    int                     gNumActiveSpotLights;
};

 

// c++ -----------------------------------------------------

struct DirectionalLight
{
    XMFLOAT4         ambient;
    //...
};

struct SpotLight
{
    XMFLOAT3        pos;
    //...
};

 

struct LightingBuffer

{

   DirectionalLight    directionalLight;

   SpotLight            spotLight[4];

   int                      gNumActiveSpotLights;

};

 

Does the system tolerate the nested structs and struct arrays? - if so, could you give me guidelines to ensure that the packing will match? (4 is the maximum number of active spotLights allowed). Is there a better way of doing this? Thanks.


xnacollision structure general transform function versions

21 January 2013 - 06:51 AM

Help! - I've been busy replacing my custom collision volumes with the xnacollison.h versions to make use of the xnamath.h SIMD functionality... and only just noticed that it doesn't provide the general transform functions for these volumes (ie. passing in a CXMMATRIX instead of the broken down contributions: translation, rotations etc. I now read that the directxcollision library has these functions but I am running on Windows 7 (DirectX June10 SDK) so cannot access it. The 4 functions I need are the (c++) equivalents of:

xnacollision.h : TransformSphere(), TransformAxisAlignedBox(), TransformOrientedBox(), TransformFrustum()

Does anyone have the source for general transform versions of these functions handy that they could let me have - to save me reinventing the wheel (and probably a lot less efficiently...)?


Understanding XMVECTOR parameter passing to own functions

11 January 2013 - 03:35 AM

Hi - I am having a bit of difficulty understanding exactly what the documentation is telling me on this... I am using Visual C++ 2010 express compiling for 32 or 64 bit implementation (Windows 7). I am using the XNA Math library (xnamath.h) and wish to write some of my own functions to handle more complex collision detection where I pass XMVECTOR parameters (going further than xnacollision.h). As I understand it, to achieve reasonable optimization, I should:

1) inline the functions

      ** This is because standard function call conventions are not great at allowing register passing of SIMD registers, so call overhead best avoided if poss...?**

2) specify _fastcall in function declaration.

3) pass FXMVECTOR for 1st 3 args and CXMVECTOR thereafter.

      ** 2 & 3 give the best chance of an optimal transfer of values within the SIMD registers if the inline is ignored by the compiler? **

      ** For x64 the docs seem to imply no possibility of SIMD register passing in a function call - so I have to hope it inlines... is that right? **

Thanks for any comments/explanations/insight.


PARTNERS