Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

de_matt

Yet another structures question

This topic is 5482 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Yep, structures again. How does every one arrange thier complicated structures? Should I leave DirectX specific types such as vectors and matrices out of structures and declare them by them? Constructors - when do you use a constructor on a global variable?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
quote:
Original post by de_matt
Yep, structures again.

How does every one arrange thier complicated structures?



struct Die_Info{
float x,y,z; //Translation

float fMoveTime; // float time value for rolling;

// 0.0 is begining, 1.0 is ending

bool bFalling;
bool bRising;
bool bMoving;
bool bNewDie; //Tells to fill with verticies if none exist;

int iMoveDirection; //Direction that the die is moving;

// 0-3 (only 4 directions possible);

int iYaw; // valid values are 0-3 Governs which rotation to use;

int iRoll;// valid values are 0-3 Governs which rotation to use;

int iFaceValue; //Current face up;

int cell; // current cell number;


//Verticies

list<Vertex> verticies;
};


quote:

Should I leave DirectX specific types such as vectors and matrices out of structures and declare them by them?


No reason to exclude them.

Also, it''s worth noting that if you intend to use large structures, that you should make them either class members of a class that contains all of the methods to modify them (in an STL conatiner) or pass a reference or pointer to the structures to functions that use them. Example:

Bad:
Function( Die_Info Die);

Good:
Function( Die_Info& Die );
Better:
Function( const Die_info& Die);

Good, but complicated:
Function( Die_Info* Die);

Really, just put the & operator after the typename and you will never know any difference other than performance increase.

ie:
Function( Die_Info& Die );

Share this post


Link to post
Share on other sites
de_matt - complicated structures are often symtomatic of a bad design. Step back and think about what you are doing. Is this structure trying to do/be everything?

If you feel the need to have a complicated structure at least consider breaking it into several smaller, simpler, focused structures and aggregate them into a structure. i.e.


struct Model { ... }
struct Physics { ... }
struct Graphics { ... }

struct FullRepresentation
{
Model m;
Physics p;
Graphics g;
}


Not a great example but it should get the point across.

I don''t think worry any specific rules about what types can go into a structure unless there''s a design constraints like making your physics code dependent on graphics types/code.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!