Where to start with an RTS Entity Class?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Distorion
Posts: 12
Joined: Thu Jul 19, 2012 1:58 am
Location: Canberra, Australia

Where to start with an RTS Entity Class?

Post by Distorion »

Hey,
I am working on an RTS and i am having trouble figureing out where to start with an Entity class. I need the entity to be associated with its scene node at all times for unit Selection/picking. I was thinking about makeing a custom scene node and adding additional functionality to that for an entity class. Thou i am still not sure, At the moment i have an entity class that loads a model and texture then attaches its self to the scene manager but its a bit to seperated for my needs.

Any idea's would be great. Thanks!
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Where to start with an RTS Entity Class?

Post by Seven »

you should get lots of opinions on this one.

for me, I set the ID of the scenenode (and the name) to a unique identifier.

node->setId(id);
node->setName(stringc(id));

when picking, I get the scenenode, grab it's id, and then convert that to my object class.

Code: Select all

 
    void CSObject::setIdRecursive(ISceneNode* node, int id)
    {
        if (node)
        {
            // set the data
            node->setID(id);
            node->setName(intToStringc(id));
 
            // set all the children also
            list<ISceneNode*> list = node->getChildren();
            core::list<ISceneNode*>::Iterator Iterator;
            for (Iterator = list.begin(); Iterator != list.end(); ++Iterator)
            {
                setIdRecursive((*Iterator),id);
            }
 
        }
 
    }
 
    void CSObject::setId(int id)
    {
        m_Id = id;
        if (getPrimarySceneNode()) setIdRecursive(getPrimarySceneNode(), id);
    }
 

Code: Select all

 
    // pick a node using the mouse cursor location 
    ISceneNode* CSLevel::selectNode(int screenX,int screenY,long objectflags)
    {
        // attempt to select a node. use the passed in mask
        ISceneNode* node = getCollMan()->getSceneNodeFromScreenCoordinatesBB(position2d<s32>(screenX,screenY),objectflags,true); 
        return node;
    }
 
    void CSLevel::setSelectedNode(ISceneNode* node)
    {
        m_SelectedNode = node;
        CSObject* obj = getObjectFromNode(node);
        if (obj) setSelectedObject(obj->getId());
    }
 
    CSObject* CSLevel::getObjectFromNode(ISceneNode* node)
    {
        if (!node) return NULL;
        int id = atoi(node->getName());
        if (id) { CS_LOG2("getobjectfromnode() ",stringc(id)); }
        return getFactory()->getObjectPointer(id);              
    }
 

this is just one way of doing it, I am sure there are different methods.
rubenwardy
Posts: 91
Joined: Mon Mar 05, 2012 4:51 pm
Location: Bristol, UK
Contact:

Re: Where to start with an RTS Entity Class?

Post by rubenwardy »

You could have an entity class, with a model value and than cycle through finding when class->model == SelectedModel
Post Reply