Jump to content

objects in world [ c++ ]


cassius
 Share

Recommended Posts

What I did awhile back was create a class with an array, loop through each entity and assign to the array. Then made a function to either find the 'player' and assign to array element. In the latter case I set up a #define and made it match it, so I could just do this:

 

#define player = 01

 

// --- find where player is as entity and

// --- set ent[player] = entity player

 

ent[player]->SetPosition(0,0,0);

 

Then I created methods to act on the entity such as setposition, getposition, etc. I wanted to keep everything in the class and portable, you may choose to handle it differently.

Link to comment
Share on other sites

Looping through all entities in the World

 

// used somewhere inside a class
// assuming you have a pointer to the world
for_each( world->entities.begin(),
		    world->entities.end(),
		   [this](Entity* e) // 'this' may be needed or not depending on what you will do with the 'e' entity
{
	 // e is pointer to current entity
    // do what you need to do
});

  • Upvote 1

AV MX Linux

Link to comment
Share on other sites

At the moment I place entities by code if I need to reference them. background objects are less important. I am debating now as to which is the most economical way to work,My existing method or one of the above.In le2 I used Blitzmax and that had a specific function for referencing entities placed in editor.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

auto just picks the type for you. You don't have to worry about knowing the type (like int, float, string, or if it's a class instance). It can just make it easier to type because you are telling the compiler to work that out for you while it compiles.

 

You can think of it as just being lazy :). The main idea with the for loop is doing the : list part because it saves you from having to worry about the stl stuff (.begin(), .end(), iterator stuff which makes teh code look more confusing.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...