Jump to content

questions on entity preloader in C++


drarem
 Share

Recommended Posts

I took the plunge and steam-purchased both lua and c++ versions. BTW running x64 Linux LXDE (Ubuntu). So far pretty neat stuff.

 

Is there a better option to my idea of creating a preloader for something like this in c++? I found the code below in the forum, and perhaps want to enhance it so I don't have to loop through all the entities to find the one I want to make an impact to.

 

    list<Entity*>::iterator iter;
    for (iter = world->entities.begin(); iter != world->entities.end(); ++iter){
	  Entity* currEnt = (*iter);
 //	    cout << "Entity loaded: " + currEnt->GetKeyValue("name") << endl;
	  if (currEnt->GetKeyValue("name") == "barrel1"){
	   currEnt->Turn(0,0,1);
	  }

 

In psuedo, here's what I'm thinking of doing..

 

enum { bear, pot, pan, knife, gun, gold piece };
class Entities;
Entities entities = new Entities[255];  // up to 255 'objects'
    list<Entity*>::iterator iter;
    for (iter = world->entities.begin(); iter != world->entities.end(); ++iter){
	  Entity* currEnt = (*iter);
	  if (currEnt->GetKeyValue("name") == "bear1"){
		 entities[bear].entity = currEnt;
	  }
	  if (currEnt->GetKeyValue("name") == "pot"){
		 entities[bear].entity = currEnt;
 }
..
..
  // now i know how to move or kill the bear for example
  // or pick up the gold piece, only if i can figure out how to check for collisions in c++

Link to comment
Share on other sites

I think your question might be related to mine. Basically you have entities in the map that you wish to use c++ code with.

 

http://www.leadwerks.com/werkspace/topic/11361-inheritance-and-entity-objects/

 

Here is the solution that I came up with.

 

Create classes in C++ for your entity. Have the classes use Hooks http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/object/

 

Using ToLua++, you can create a Lua function to assign your entity to a class that has an entity property.

http://lua-users.org/wiki/BindingCodeToLua

Link to comment
Share on other sites

Correct, how to use entities with C++. I'm trying it this way, so far except for maintenance when i add a new object I want to manipulate, it seems ok. What I want to do is only update the enum, change the enum item to a string so I can match it automatically in the pre-loader function. Perhaps something like this or with the hooks, could be implemented in the leadwerks engine, where you can manipulate the object as named in the editor.

 

 

enum { none, barrel, cardboardbox, ship1 }

 

entities *ents;

ents = new entities(world, 255); // up to 255 objects

 

 

ents->turn(cardboardbox, 0.1, 0, 0); // rotate cardboardbox entity

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