Jump to content
  • Advertisement
Sign in to follow this  
ajm113

Entity Values C++

This topic is 3717 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

I am working with a bunch of objects that I want too group when the user drags the mouse into left or right then it will select a group of objects where if the boxes are in row TOP then they will rotate. So I basically want to set up a programmed attribute settings for each "Entity" in my game using struct. I forgotten how to work with struct so I need help refreshing my memory. This is what I am thinking on doing for when my game create a new cube in the world is too set up attributes.
struct CubeName {

  int id;
};

struct Cube {
	enum Row {
	SG_LEFT = 0,
	SG_RIGHT,
	SG_MIDDLE;
	};

	enum Col {
	SC_TOP = 0,
	SC_MIDDLE,
	SC_BOTTOM
	};


    //What texture id goes too what face of the cube
	int top;
	int bottom;
	int front;
	int back;
	int left;
};

I want it too work like this: Object.432.Col = SC_TOP; Where the second param is the cube id then so forth.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by ajm113
I am working with a bunch of objects that I want to group when the user drags the mouse into left or right then it will select a group of objects where if the boxes are in row TOP then they will rotate.
That sentence doesn't compute for me...
Bunch of objects need: grouping.
Group when: user drags the mouse
User drags where: into left or right?
What happens after grouping: it will select a group of objects
What happens to the selected group: if they are in the rop row they will rotate
??
Quote:
I forgotten how to work with struct so I need help refreshing my memory.

Wikipedia has a detailed explanation, and C++.com has a tutorial.
Quote:
I want it to work like this:
Object.432.Col = SC_TOP;
Where the second param is the cube id then so forth.
I'll work backwards through your problems here:
1) "Col" is not a member variable of your structure, it's an enumerated set of possible values (like a list of hard-coded numbers). You've got to actually make a variable of the type "Col" inside your struct. Here I rename Col to ColType, and then make a variable named Col which is a ColType:
struct Cube {
enum ColType {//the enum is a list of values, not a variable
SC_TOP = 0,
SC_MIDDLE,
SC_BOTTOM
};
ColType Col;//this is the actual variable.
}
2) Object.432 isn't valid code. That's trying to access the variable named "432" inside variable named "Object".

What you probably want to do is have a map, which links id numbers to structures:

#include <map>
typedef int CubeName;

struct Cube {
enum ColType {//the enum is a list of values, not a variable
SC_TOP = 0,
SC_MIDDLE,
SC_BOTTOM
};
ColType Col;//this is the actual variable.

//...
};

typedef std::map<CubeName, Cube> CubeMap;

int main()
{
CubeMap objects;

//add a cube named 432, and set it's column to top
objects[432].Col = Cube::SC_TOP;

//set cube #500's column to top, only if it exists
if( objects.find(500) != objects.end() )
objects[500].Col = Cube::SC_TOP;

//erase cube #432
objects.erase(432);

//Alternate way of adding a cube named 432, and setting it's column to top
Cube tempCube;
tempCube.Col = Cube::SC_TOP;
objects.insert( std::make_pair(432,tempCube) );

//Alternate way of setting cube #500's column to top, only if it exists
CubeMap::iterator cube500 = objects.find(500);
if( cube500 != objects.end() )
cube500->second.Col = Cube::SC_TOP;
}

Share this post


Link to post
Share on other sites
Thanks, sorry for not being detailed and lazy with the sentances, but I am working on a rubex cube mini game so it's been a bit going back and forth on how it will work. I'll post again on here for any more questions about struct after I play around with the code you suggested on using.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!