Public Group

#### Archived

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

# Yet another structures question

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

## 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 on other sites
quote:
Original post by de_matt
Yep, structures again.

How does every one arrange thier complicated structures?

struct Die_Info{float x,y,z; //Translationfloat fMoveTime; // float time value for rolling;// 0.0 is begining, 1.0 is endingbool 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;//Verticieslist<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:

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 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.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633663
• Total Posts
3013232
×