Пример #1
0
// A command was moved from oldIdx to newIdx.  Fix all the wait commands.
void ResponderWait::CmdMoved(IParamBlock2 *state, int oldIdx, int newIdx)
{
    int numCmds = state->Count(kStateCmdParams);

    // Moved forward
    if (oldIdx < newIdx)
    {
        // Patch up the commands that were ahead of this one
        for (int i = oldIdx; i < numCmds; i++)
        {
            if (i == newIdx)
                continue;

            IParamBlock2 *pb = GetWaitBlk(state, i);

            int who = pb->GetInt(kWaitWho);

            // If the command was waiting on the moved one, and is now behind it, invalidate it
            if (who == oldIdx && i < newIdx)
                pb->SetValue(kWaitWho, 0, -1);
            //
            else if (who == oldIdx)
                pb->SetValue(kWaitWho, 0, newIdx);
            // If it was waiting on one ahead of it, correct the index
            else if (who > oldIdx && who <= newIdx)
                pb->SetValue(kWaitWho, 0, who-1);
        }
    }
    // Moved backward
    else
    {
        // If this command was waiting on any of the commands now ahead of it, invalidate it
        IParamBlock2 *movedPB = GetWaitBlk(state, newIdx);
        int who = movedPB->GetInt(kWaitWho);
        if (who >= newIdx)
            movedPB->SetValue(kWaitWho, 0, -1);

        for (int i = newIdx+1; i < numCmds; i++)
        {
            // Is this command waiting on any of the commands it is moving in back of?
            IParamBlock2 *pb = GetWaitBlk(state, i);
            int who = pb->GetInt(kWaitWho);
            if (who == oldIdx)
                pb->SetValue(kWaitWho, 0, newIdx);
            if (who >= newIdx && who < oldIdx)
                pb->SetValue(kWaitWho, 0, who+1);
        }
    }
}
void plResponderComponent::ISetupDefaultWait(plMaxNode* node, plErrorMsg* pErrMsg,
                                             int state, CmdIdxs& cmdIdxs, int &numCallbacks)
{
    IParamBlock2 *statePB = (IParamBlock2*)fCompPB->GetReferenceTarget(kResponderState, 0, state);
    plResponderModifier *responder = IGetResponderMod(node);
    hsTArray<plResponderModifier::plResponderCmd>& cmds = responder->fStates[state].fCmds;

    int numCmds = cmds.Count();
    for (int i = 0; i < numCmds; i++)
    {
        IParamBlock2 *waitPB = GetWaitBlk(statePB, i);
        ResponderWait::FixupWaitBlock(waitPB);

        // If we're supposed to wait for this command, and it converted, create a callback
        if (ResponderWait::GetWaitOnMe(waitPB) && cmdIdxs.find(i) != cmdIdxs.end())
        {
            int convertedIdx = cmdIdxs[i];

            ResponderWaitInfo waitInfo;
            waitInfo.responderName = plString::FromUtf8(GetINode()->GetName());
            waitInfo.receiver = responder->GetKey();
            waitInfo.callbackUser = numCallbacks++;
            waitInfo.msg = cmds[convertedIdx].fMsg;
            waitInfo.point = plString::Null;

            IParamBlock2 *pb = (IParamBlock2*)statePB->GetReferenceTarget(kStateCmdParams, 0, i);
            plResponderCmd *cmd = plResponderCmd::Find(pb);

            cmd->CreateWait(node, pErrMsg, pb, waitInfo);
        }
    }
}
Пример #3
0
// Determine if any of the wait commands will be invalidated by this move
bool ResponderWait::ValidateCmdMove(IParamBlock2 *state, int oldIdx, int newIdx)
{
    // Moving forward
    if (oldIdx < newIdx)
    {
        // Are any of the commands ahead of this one waiting on it?
        for (int i = oldIdx+1; i <= newIdx; i++)
        {
            IParamBlock2 *pb = GetWaitBlk(state, i);

            if (pb->GetInt(kWaitWho) == oldIdx)
            {
                int ret = hsMessageBox("You are moving this command ahead of another command that waits on it.\nAre you sure you want to do that?", "Warning", hsMessageBoxYesNo);
                if (ret == hsMBoxYes)
                    return true;
                else
                    return false;
            }
        }
    }
    // Moving backward
    else
    {
        // Is this command waiting on any of the commands it is moving in back of?
        IParamBlock2 *pb = GetWaitBlk(state, oldIdx);

        int who = pb->GetInt(kWaitWho);
        if (who >= newIdx && who < oldIdx)
        {
            int ret = hsMessageBox("You are moving this command behind another command that it is waiting on.\nAre you sure you want to do that?", "Warning", hsMessageBoxYesNo);
            if (ret == hsMBoxYes)
                return true;
            else
                return false;
        }
    }

    return true;
}
Пример #4
0
void ResponderWait::CmdRemoved(IParamBlock2 *state, int delIdx)
{
    int numCmds = state->Count(kStateCmdParams);
    for (int i = delIdx; i < numCmds; i++)
    {
        IParamBlock2 *pb = GetWaitBlk(state, i);

        int who = pb->GetInt(kWaitWho);

        if (who == delIdx)
            pb->SetValue(kWaitWho, 0, -1);
        if (who > delIdx)
            pb->SetValue(kWaitWho, 0, who-1);
    }
}
void plResponderComponent::IConvertCmdWaits(plMaxNode* node, plErrorMsg* pErrMsg,
                                            int state, CmdIdxs& cmdIdxs, int &numCallbacks)
{
    IParamBlock2 *statePB = (IParamBlock2*)fCompPB->GetReferenceTarget(kResponderState, 0, state);
    plResponderModifier *responder = IGetResponderMod(node);
    hsTArray<plResponderModifier::plResponderCmd>& cmds = responder->fStates[state].fCmds;

    int numWaits = statePB->Count(kStateCmdWait);
    for (int i = 0; i < numWaits; i++)
    {
        IParamBlock2 *waitPB = GetWaitBlk(statePB, i);

        int wait = ResponderWait::GetWaitingOn(waitPB);

        // If the waiter and waitee both converted, create the callback
        if (cmdIdxs.find(wait) != cmdIdxs.end() && cmdIdxs.find(i) != cmdIdxs.end())
        {
            int convertedIdx = cmdIdxs[wait];

            ResponderWaitInfo waitInfo;
            waitInfo.responderName = plString::FromUtf8(GetINode()->GetName());
            waitInfo.receiver = responder->GetKey();
            waitInfo.callbackUser = numCallbacks++;
            waitInfo.msg = cmds[convertedIdx].fMsg;
            waitInfo.point = ResponderWait::GetWaitPoint(waitPB);

            responder->AddCallback(state, convertedIdx, waitInfo.callbackUser);
            cmds[cmdIdxs[i]].fWaitOn = waitInfo.callbackUser;

            IParamBlock2 *pb = (IParamBlock2*)statePB->GetReferenceTarget(kStateCmdParams, 0, wait);
            plResponderCmd *cmd = plResponderCmd::Find(pb);

            cmd->CreateWait(node, pErrMsg, pb, waitInfo);
        }
    }
}