Sign in to follow this  
ajm113

Entity Values C++

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this