Page 1 of 1

Where to start with an RTS Entity Class?

Posted: Sat Aug 03, 2013 11:11 am
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!

Re: Where to start with an RTS Entity Class?

Posted: Sat Aug 03, 2013 12:58 pm
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.

Re: Where to start with an RTS Entity Class?

Posted: Fri Aug 09, 2013 3:18 pm
by rubenwardy
You could have an entity class, with a model value and than cycle through finding when class->model == SelectedModel