Jump to content

[c++] How create object in editor on base of c++ classes?


GoldNotch
 Share

Recommended Posts

The editor doesn't know anything about what you do in C++. If you want your classes to be associated with entities in the editor you will have to loop over all entities after you load the map in C++ and then assign them yourself. You'll most likely want some kind of system to make that link yourself but because this is C++ and not very dynamic it'll be some hard coding going on.

 

For example, you could make a lua script that has a Script property and in it's Start() function you assign whatever value you typed into it to the entity key/value system (self.entity:SetKeyValue("type", self.Type)). Then in C++ after you load your map loop over all entities and get the "type" key and use it's value against some hardcoded string's to C++ classes

 

foreach(auto e in world->entities)
{
  string key = e->GetKeyValue("type")

  if(key == "Player")
     player = new Player(e);
  if(key == "Enemy")
     enemy = new Enemy(e)
}

 

The above is just some pseudo code example on how you could do this.

  • Upvote 1
Link to comment
Share on other sites

What you can do as well is to create empty pivots in the scene and name them something like SPAWN_ENEMY. Then you can have a C++ class that does something like this:

 

// Pre-define variables we need
bool foundNewPivot = false;
Entity *e = NULL;

// Start the search for every pivot named "SPAWN_ENEMY"
do
{
foundNewPivot = false; // Default on 'not found'
e = world->FindEntity("SPAWN_ENEMY"); // Find a pivot named like this

if (e != NULL) // If it exists
{
/* Create an object, in this case an enemy.
It is recommended to store enemy in a list (like a vector) so you can update it later */
Enemy *enemy = new Enemy(args);
enemy->SetPosition( e->GetPosition() );
enemy->SetRotation( e->GetRotation() );
// enemies.push_back(enemy); // Like this, assuming you made std::vector<Enemy*> enemies before

e->SetKeyValue("name", "SPAWN_ENEMY_PROCESSED"); // You can also store this in an array/vector for later use (like respawning).
// The reason you need to rename the pivot is that it cannot be found anymore during this loop.

foundNewPivot = true; // Keep searching for spawns
}
}
while (foundNewPivot == true); // End this while loop when no new pivot was found

 

You can use this for units, pickups, respawns or anything else you want to do with it.

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

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