1
\$\begingroup\$

Issue: How is the best way to update my units position on the oct-tree, I'm struggling with the logic, specifically when It changes oct, tree, I want it to pop itself of its previous oct-tree, and it it to its new oct tree, but only if it has changed since last frame-

update is called every frame, Is there a way to call it only when it knows the oct-tree of the current unit has changed,instead of doing comparison every second, as this throws exception error because can only pop it off the list once?

void EntityUnit::updateoct(worldspace &gameworldspace)
{
    int store = current_oct;
    for (auto a = gameworldspace.wspace.begin(); a<gameworldspace.wspace.end(); ++a)
    {
        if (checkwithinbounds(CVector3{unit_x,unit_y,unit_z}, (*a).w_origin, (*a).w_sideLen))
        {
            current_oct = (*a).num;
            //if oct-tree has changed since last call execute this
            // push this onto (a*).cObjs
            for (auto i = gameworldspace.wspace[current_oct].cObjs.begin(); i <  gameworldspace.wspace[current_oct].cObjs.end(); ++i)
            {
                if ((*i) == this)
                {
                    // Pop this off the last oct-tree object list
                }
            }
        }
    }
}



   void EntityUnit::update(float updateTime, worldspace &gameworldspace)
{
    int aliveswitch = unit_alive;
    if (this->UnitModel != nullptr)
    {
        (*UnitModel)->SetPosition(unit_x, unit_y, unit_z);
        (*UnitModel)->LookAt(0, 0, 0);
        (*UnitModel)->Scale(unit_model_scale);
        (*UnitModel)->ScaleZ(0.1);
        // << "current oct :" << current_oct << endl;
    }
    switch (aliveswitch)
    {
    case (0):

        break;
    case (1):

        move(updateTime);
        updateoct(gameworldspace);
        //cout << "Hit" << endl;
        break;

    default:;
    }





}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.