void plLinkEffectsTriggerPrepMsg::SetTrigger(plLinkEffectsTriggerMsg *msg)
{
    if (fTrigger)
        hsRefCnt_SafeUnRef(fTrigger);

    hsRefCnt_SafeRef(msg);
    fTrigger = msg;
}
示例#2
0
hsGMaterial* pl3DPipeline::PushOverrideMaterial(hsGMaterial* mat)
{
    hsGMaterial* ret = GetOverrideMaterial();
    hsRefCnt_SafeRef(mat);
    fOverrideMat.Push(mat);
    fForceMatHandle = true;

    return ret;
}
示例#3
0
plRenderRequestMsg::plRenderRequestMsg(plKey sender, plRenderRequestBase* req)
:   plMessage(sender, nil, nil),
    fReq(req)
{
    plUoid oid( kClient_KEY );      // from plFixedKey.h
    plKey key = hsgResMgr::ResMgr()->FindKey(oid);
    AddReceiver(key);

    hsRefCnt_SafeRef(fReq);
}
示例#4
0
void    pfGUIControlMod::SetColorScheme( pfGUIColorScheme *newScheme )
{
    if( fColorScheme != nil )
    {
        hsRefCnt_SafeUnRef( fColorScheme );
        fColorScheme = nil;
    }

    fColorScheme = newScheme;
    if( fColorScheme != nil )
        hsRefCnt_SafeRef( fColorScheme );
}
示例#5
0
// CTOR (animName, drivable, reversible)
// this construct is typically used when you want to create a one-shot task as part of a sequence
// of tasks
// it's different than the message-based constructor in that fDetachAnimation and fMoveHandle default to false
plAvOneShotTask::plAvOneShotTask(const plString &animName, bool drivable, bool reversible, plOneShotCallbacks *callbacks)
{
    InitDefaults();

    fDrivable = drivable;
    fReversible = reversible;
    fCallbacks = callbacks;
    
    // we're going to use this sometime in the future, better ref it so someone else doesn't release it
    hsRefCnt_SafeRef(fCallbacks);
    fAnimName = animName;
}
hsKeyedObject::~hsKeyedObject()
{ 
    if( fpKey && fpKey->ObjectIsLoaded() )
    {
        // If our key is pointing to an object (presumably back to us),
        // then UnRegister will call SetObjectPtr(nil) will unregister the key (and us), which will
        // decrement our RefCnt. Unfortunately, we are here because of a call
        // to our destructor, in which case we don't want to go back into our
        // destructor again. So we'll just up the RefCnt, plKey::UnRegister will dec it back to 1.
        hsRefCnt_SafeRef(fpKey->ObjectIsLoaded());
    }
    UnRegister(); 
}
示例#7
0
// CTOR (plAvOneShotMsg, plArmatureMod)
// this constructor is typically used when we're doing a classic, isolated one-shot
// fDetachAnimation and fMoveHandle both default to *true*
plAvOneShotTask::plAvOneShotTask (plAvOneShotMsg *msg, plArmatureMod *avatar, plArmatureBrain *brain)
{
    InitDefaults();

    fDrivable = msg->fDrivable;
    fReversible = msg->fReversible;
    fCallbacks = msg->fCallbacks;
    fDetachAnimation = true;
    fMoveHandle = true;

    // we're going to use this sometime in the future, better ref it so someone else doesn't release it
    hsRefCnt_SafeRef(fCallbacks);
    fAnimName = msg->fAnimName;
}
示例#8
0
void    plGBufferGroup::SetIndexBufferRef( uint32_t index, hsGDeviceRef *ib ) 
{
    hsAssert( index < fIndexBufferRefs.size() + 1, "Index buffers must be assigned linearly!" );

    if(index > fIndexBufferRefs.size() - 1)
    {
        fIndexBufferRefs.push_back( ib );
        hsRefCnt_SafeRef( ib );
    }
    else
    {
        hsRefCnt_SafeAssign( fIndexBufferRefs[ index ], ib );
    }

}
示例#9
0
void    plGBufferGroup::SetIndexBufferRef( uint32_t index, hsGDeviceRef *ib ) 
{
    hsAssert( index < fIndexBufferRefs.GetCount() + 1, "Index buffers must be assigned linearly!" );

    if( (int)index > (int)fIndexBufferRefs.GetCount() - 1 )
    {
        fIndexBufferRefs.Append( ib );
        hsRefCnt_SafeRef( ib );
    }
    else
    {
        hsRefCnt_SafeAssign( fIndexBufferRefs[ index ], ib );
    }

}
示例#10
0
void    plInputInterfaceMgr::IAddInterface( plInputInterface *iface )
{
    int     i;


    for( i = 0; i < fInterfaces.GetCount(); i++ )
    {
        if( fInterfaces[ i ]->GetPriorityLevel() < iface->GetPriorityLevel() )
            break;
    }

    fInterfaces.Insert( i, iface );
    hsRefCnt_SafeRef( iface );
    iface->Init( this );
    iface->ISetMessageQueue( &fMessageQueue );
}
void plMsgForwarder::IForwardMsg(plMessage *msg)
{
    // Back up the message's original receivers
    hsTArray<plKey> oldKeys;
    for (int i = 0; i < msg->GetNumReceivers(); i++)
        oldKeys.Append((plKey)msg->GetReceiver(i));

    // Set to our receivers and send
    hsRefCnt_SafeRef(msg);
    msg->ClearReceivers();
    msg->AddReceivers(fForwardKeys);
    msg->Send();

    // Reset back to the original receivers.  This is so we don't screw up objects
    // who reuse their messages
    msg->ClearReceivers();
    msg->AddReceivers(oldKeys);
}
示例#12
0
// MSGRECEIVE
bool plOneShotMod::MsgReceive(plMessage* msg)
{
    plOneShotMsg *oneShotMsg = plOneShotMsg::ConvertNoRef(msg);
    if (oneShotMsg)
    {
        // Send a one shot task request to the given target, which darn well better have an avatar modifier on it.
        plKey myKey = GetKey();
        plKey objKey = GetTarget(0)->GetKey();
        plKey avKey = oneShotMsg->fPlayerKey;
        hsAssert(avKey,"The avatar key is missing in the one shot!");

        if ( avKey )
        {
            plSceneObject *avObj = (plSceneObject *)avKey->ObjectIsLoaded();
            if(avObj)
            {
                const plArmatureMod *avMod = (plArmatureMod*)avObj->GetModifierByType(plArmatureMod::Index());

                if(avMod)
                {
                    ST::string animName = avMod->MakeAnimationName(fAnimName);

                    plAvOneShotMsg *avOSmsg = new plAvOneShotMsg(myKey, oneShotMsg->fPlayerKey, objKey,
                                                                 fSeekDuration, (bool)fSmartSeek, animName, fDrivable,
                                                                 fReversable);

                    avOSmsg->fNoSeek = fNoSeek;
                    avOSmsg->SetBCastFlag(plMessage::kPropagateToModifiers);
                    hsRefCnt_SafeRef(oneShotMsg->fCallbacks);
                    avOSmsg->fCallbacks = oneShotMsg->fCallbacks;
                    plgDispatch::MsgSend(avOSmsg);
                }
            }

        }
        return true;
    }
    return plMultiModifier::MsgReceive(msg);
}
void plCameraRegionDetector::ISendSavedTriggerMsgs()
{
    if (fSavingSendMsg)
    {
        for (size_t i = 0; i < fMessages.size(); ++i)
        {   
            hsRefCnt_SafeRef(fMessages[i]);
            if (fSavedMsgEnterFlag)
            {
                fMessages[i]->SetCmd(plCameraMsg::kEntering);
                DetectorLog("Entering cameraRegion: %s - Evals=%d -msg %d of %d\n", GetKeyName().c_str(),fNumEvals,i+1,fMessages.size());
                fIsInside = true;
            }
            else
            {
                fMessages[i]->ClearCmd(plCameraMsg::kEntering);
                DetectorLog("Exiting cameraRegion: %s - Evals=%d -msg %d of %d\n", GetKeyName().c_str(),fNumEvals,i+1,fMessages.size());
                fIsInside = false;
            }
            plgDispatch::MsgSend(fMessages[i]);
        }
    }
    fSavingSendMsg = false;
}
示例#14
0
void plLinkEffectsMgr::IAddLink(plLinkEffectsTriggerMsg *msg)
{
    hsRefCnt_SafeRef(msg);
    fLinks.Append(msg);
}
示例#15
0
plMessage* plResponderModifier::IGetFastForwardMsg(plMessage* msg, bool python)
{
    if (!msg)
        return nil;

    if (plAnimCmdMsg* animMsg = plAnimCmdMsg::ConvertNoRef(msg))
    {
        if (animMsg->Cmd(plAnimCmdMsg::kContinue) ||
            animMsg->Cmd(plAnimCmdMsg::kAddCallbacks))
        {
            plAnimCmdMsg* newAnimMsg = new plAnimCmdMsg;
            newAnimMsg->fCmd                = animMsg->fCmd;
            newAnimMsg->fBegin              = animMsg->fBegin;
            newAnimMsg->fEnd                = animMsg->fEnd;
            newAnimMsg->fLoopEnd            = animMsg->fLoopEnd;
            newAnimMsg->fLoopBegin          = animMsg->fLoopBegin;
            newAnimMsg->fSpeed              = animMsg->fSpeed;
            newAnimMsg->fSpeedChangeRate    = animMsg->fSpeedChangeRate;
            newAnimMsg->fTime               = animMsg->fTime;
            newAnimMsg->SetAnimName(animMsg->GetAnimName());
            newAnimMsg->SetLoopName(animMsg->GetLoopName());

            // Remove the callbacks
            newAnimMsg->fCmd.SetBit(plAnimCmdMsg::kAddCallbacks, false);

            if (newAnimMsg->Cmd(plAnimCmdMsg::kContinue))
            {
                newAnimMsg->fCmd.SetBit(plAnimCmdMsg::kContinue, false);
                newAnimMsg->fCmd.SetBit(plAnimCmdMsg::kFastForward, true);
            }

            for (int i = 0; i < animMsg->GetNumReceivers(); i++)
                newAnimMsg->AddReceiver(animMsg->GetReceiver(i));

            ResponderLog(ILog(plStatusLog::kWhite, "FF Animation Play Msg"));
            return newAnimMsg;
        }

        ResponderLog(ILog(plStatusLog::kWhite, "FF Animation Non-Play Msg"));
        hsRefCnt_SafeRef(msg);
        return msg;
    }
    else if(plSoundMsg *soundMsg = plSoundMsg::ConvertNoRef(msg))
    {
        if( fFlags & kSkipFFSound )
        {
            return nil;
        }
        if(soundMsg->Cmd(plSoundMsg::kPlay) ||
            soundMsg->Cmd(plSoundMsg::kToggleState)  ||
            soundMsg->Cmd(plAnimCmdMsg::kAddCallbacks))
        {
            plSoundMsg *newSoundMsg = new plSoundMsg;
            newSoundMsg->fCmd = soundMsg->fCmd;
            newSoundMsg->fBegin = soundMsg->fBegin;
            newSoundMsg->fEnd = soundMsg->fEnd;
            newSoundMsg->fLoop = soundMsg->fLoop;
            newSoundMsg->fSpeed = soundMsg->fSpeed;
            newSoundMsg->fTime = soundMsg->fTime;
            newSoundMsg->fIndex = soundMsg->fIndex;
            newSoundMsg->fRepeats = soundMsg->fRepeats;
            newSoundMsg->fPlaying = soundMsg->fPlaying;
            newSoundMsg->fNameStr = soundMsg->fNameStr;
            newSoundMsg->fVolume = soundMsg->fVolume;

            // Remove the callbacks
            newSoundMsg->fCmd.SetBit(plSoundMsg::kAddCallbacks, false);

            if(newSoundMsg->Cmd(plSoundMsg::kPlay))
            {
                newSoundMsg->fCmd.SetBit(plSoundMsg::kPlay, false);
                newSoundMsg->fCmd.SetBit(plSoundMsg::kFastForwardPlay);
                ResponderLog(ILog(plStatusLog::kWhite, "FF Sound Play Msg"));
            }
            else if(newSoundMsg->Cmd(plSoundMsg::kToggleState))
            {
                newSoundMsg->fCmd.SetBit(plSoundMsg::kToggleState, false);
                newSoundMsg->fCmd.SetBit(plSoundMsg::kFastForwardToggle);
                ResponderLog(ILog(plStatusLog::kWhite, "FF Sound Toggle State Msg"));
            }
            for (int i = 0; i < soundMsg->GetNumReceivers(); i++)
                newSoundMsg->AddReceiver(soundMsg->GetReceiver(i));

            return newSoundMsg;
        }
        ResponderLog(ILog(plStatusLog::kWhite, "FF Sound Non-Play/Toggle Msg"));
        hsRefCnt_SafeRef(msg);
        return msg;
    }
    else if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plExcludeRegionMsg))
    {
        ResponderLog(ILog(plStatusLog::kWhite, "FF Exclude Region Msg"));
        hsRefCnt_SafeRef(msg);
        return msg;
    }
    else if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plEnableMsg))
    {
        ResponderLog(ILog(plStatusLog::kWhite, "FF Visibility/Detector Enable Msg"));
        hsRefCnt_SafeRef(msg);
        return msg;
    }
    else if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plResponderEnableMsg))
    {
        ResponderLog(ILog(plStatusLog::kWhite, "FF Responder Enable Msg"));
        hsRefCnt_SafeRef(msg);
        return msg;
    }
    else if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plSimSuppressMsg))
    {
        ResponderLog(ILog(plStatusLog::kWhite, "FF Physical Enable Msg"));
        hsRefCnt_SafeRef(msg);
        return msg;
    }

    return nil;
}
示例#16
0
bool plResponderModifier::IContinueSending()
{
    // If we haven't been started, exit
    if (fCurCommand == int8_t(-1))
        return false;

    plResponderState& state = fStates[fCurState];

    while (fCurCommand < state.fCmds.Count())
    {
        plMessage *msg = state.fCmds[fCurCommand].fMsg;
        if (msg)
        {
            // If this command needs to wait, and it's condition hasn't been met yet, exit
            int8_t wait = state.fCmds[fCurCommand].fWaitOn;
            if (wait != -1 && !fCompletedEvents.IsBitSet(wait))
            {
                ResponderLog(ILog(plStatusLog::kWhite, "Command %d is waiting for command %d(id:%d)", int8_t(fCurCommand)+1, ICmdFromWait(wait)+1, wait));
                return false;
            }

            if (!(fNotifyMsgFlags & plMessage::kNetNonLocal)|| !IIsLocalOnlyCmd(msg))
            {
                // make sure outgoing msgs inherit net flags as part of cascade
                uint32_t msgFlags = msg->GetAllBCastFlags();
                plNetClientApp::InheritNetMsgFlags(fNotifyMsgFlags, &msgFlags, true);
                msg->SetAllBCastFlags(msgFlags);

                // If this is a responder message, let it know which player triggered this
                if (plResponderMsg* responderMsg = plResponderMsg::ConvertNoRef(msg))
                {
                    responderMsg->fPlayerKey = fPlayerKey;
                }
                else if (plNotifyMsg* notifyMsg = plNotifyMsg::ConvertNoRef(msg))
                {
                    bool foundCollision = false;

                    // If we find a collision event, this message is meant to trigger a multistage
                    for (int i = 0; i < notifyMsg->GetEventCount(); i++)
                    {
                        proEventData* event = notifyMsg->GetEventRecord(i);
                        if (event->fEventType == proEventData::kCollision)
                        {
                            proCollisionEventData* collisionEvent = (proCollisionEventData*)event;
                            collisionEvent->fHitter = fPlayerKey;
                            foundCollision = true;
                        }
                    }

                    // No collision event, this message is for notifying the triggerer
                    if (!foundCollision)
                    {
                        notifyMsg->ClearReceivers();
                        notifyMsg->AddReceiver(fTriggerer);
                    }

                    notifyMsg->SetSender(GetKey());
                }
                else if (plLinkToAgeMsg* linkMsg = plLinkToAgeMsg::ConvertNoRef(msg))
                {
                    if (linkMsg->GetNumReceivers() == 0)
                    {
                        plUoid netUoid(kNetClientMgr_KEY);
                        plKey netKey = hsgResMgr::ResMgr()->FindKey(netUoid);
                        hsAssert(netKey,"NetClientMgr not found");
                        linkMsg->AddReceiver(netKey);
                    }
                }
                else if (plArmatureEffectStateMsg* stateMsg = plArmatureEffectStateMsg::ConvertNoRef(msg))
                {
                    stateMsg->ClearReceivers();
                    stateMsg->AddReceiver(fPlayerKey);
                    stateMsg->fAddSurface = fEnter;
                }
                else if (plSubWorldMsg* swMsg = plSubWorldMsg::ConvertNoRef(msg))
                {
                    plArmatureMod *avatar = plAvatarMgr::GetInstance()->GetLocalAvatar();
                    if(avatar)
                    {
                        swMsg->AddReceiver(avatar->GetKey());
                    }
                }

                // If we're in anim debug mode, check if this is an anim play
                // message so we can put up the cue
                if (fDebugAnimBox)
                {
                    plAnimCmdMsg* animMsg = plAnimCmdMsg::ConvertNoRef(msg);
                    if (animMsg && animMsg->Cmd(plAnimCmdMsg::kContinue))
                        IDebugPlayMsg(animMsg);
                }


                if (plTimerCallbackMsg *timerMsg = plTimerCallbackMsg::ConvertNoRef(msg))
                {
                    hsRefCnt_SafeRef(timerMsg);
                    plgTimerCallbackMgr::NewTimer(timerMsg->fTime, timerMsg);
                }
                else
                {
                    hsRefCnt_SafeRef(msg);
                    plgDispatch::MsgSend(msg);
                }
            }
        }

        fCurCommand++;
        DirtySynchState(kSDLResponder, 0);
    }

    // Make sure all callbacks we need to wait on are done before allowing a state switch or restart
    for (int i = 0; i < state.fNumCallbacks; i++)
    {
        if (!fCompletedEvents.IsBitSet(i))
        {
            ResponderLog(ILog(plStatusLog::kWhite, "Can't reset, waiting for command %d(id:%d)", ICmdFromWait(i)+1, i));
            return false;
        }
    }

    ResponderLog(ILog(plStatusLog::kGreen, "Reset"));

    fCurCommand = -1;
    ISetResponderState(state.fSwitchToState);
    DirtySynchState(kSDLResponder, 0);
    
    return true;
}
示例#17
0
 plMsgWrap(plMessage* msg) : fMsg(msg) { hsRefCnt_SafeRef(msg); }
示例#18
0
void plLinkEffectsMgr::IAddPsuedo(plPseudoLinkEffectMsg *msg)
{
    hsRefCnt_SafeRef(msg);
    fPseudolist.Append(msg);
}
示例#19
0
void plLinkEffectsMgr::IAddDead(plLinkEffectsTriggerMsg *msg)
{
    hsRefCnt_SafeRef(msg);
    fDeadlist.Append(msg);
}
示例#20
0
void plLinkEffectsMgr::IAddWait(plLinkEffectsTriggerMsg *msg)
{
    hsRefCnt_SafeRef(msg);
    fWaitlist.Append(msg);
}
hsBool plAxisAnimModifier::MsgReceive(plMessage* msg)
{
    plEventCallbackMsg* pCall = plEventCallbackMsg::ConvertNoRef(msg);
    if (pCall)
    {
        // Send our notification to whomever cares;
        float time = 0.0f;
        if (pCall->fEvent == kEnd)
            time = 1.0f;
        fNotify->ClearEvents();
        fNotify->SetSender(fNotificationKey); // so python can handle it.
        fNotify->AddCallbackEvent( pCall->fEvent );
        fNotify->SetState(1.0f);
        fNotify->AddActivateEvent(true);
        fNotify->AddClickDragEvent(GetTarget()->GetKey(), plNetClientApp::GetInstance()->GetLocalPlayerKey(), time);
        hsRefCnt_SafeRef(fNotify);
        plgDispatch::MsgSend( fNotify );
        return true;
    }
        
    plNotifyMsg* pNMsg = plNotifyMsg::ConvertNoRef(msg);
    if (pNMsg)
    {
        for (int i = 0; i < pNMsg->GetEventCount(); i++)
        {
            if (pNMsg->GetEventRecord(i)->fEventType == proEventData::kActivate)
            {
                if( ( (proActivateEventData *)pNMsg->GetEventRecord(i) )->fActivate )
                {
                    fActive = true;
                    fXPos = plMouseDevice::Instance()->GetCursorX();
                    fYPos = plMouseDevice::Instance()->GetCursorY();

                    // Insert our input interface onto the input stack
                    plInputIfaceMgrMsg *msg = new plInputIfaceMgrMsg( plInputIfaceMgrMsg::kAddInterface );
                    msg->SetIFace( fInputIface );
                    plgDispatch::MsgSend( msg );
                }
                else
                {
/*                  if (fActive)
                    {
                        fActive = false;

                        // Remove our input interface from the input stack
                        plInputIfaceMgrMsg *msg = new plInputIfaceMgrMsg( plInputIfaceMgrMsg::kRemoveInterface );
                        msg->SetIFace( fInputIface );
                        plgDispatch::MsgSend( msg );
                    }
*/              }
                break;
            }
        }
        return true;
    }
    
    plMouseEventMsg* pMMsg = plMouseEventMsg::ConvertNoRef(msg);
    if (pMMsg)
    {
        if (fXAnim && pMMsg->GetDX() != 0.0f)
        {
            if (pMMsg->GetDX() > 0.05f)
                return true;
            plAnimCmdMsg* pMsg = new plAnimCmdMsg;
            pMsg->AddReceiver(fXAnim);
            pMsg->SetAnimName(fAnimLabel);
        //  pMsg->SetAnimName()
            if (fXPos < pMMsg->GetXPos())
            {
                pMsg->SetCmd(plAnimCmdMsg::kIncrementForward);
            }
            else
            {
                pMsg->SetCmd(plAnimCmdMsg::kIncrementBackward);
            }
            plgDispatch::MsgSend(pMsg);
            fXPos = pMMsg->GetXPos();
        }
        if (fYAnim && pMMsg->GetDY() != 0.0f)
        {
        
            if (pMMsg->GetDY() > 0.05f)
                return true;
            plAnimCmdMsg* pMsg = new plAnimCmdMsg;
            pMsg->AddReceiver(fYAnim);
            pMsg->SetAnimName(fAnimLabel);
            if (fYPos > pMMsg->GetYPos())
            {
                if (fAllOrNothing)
                {
                    pMsg->SetCmd(plAnimCmdMsg::kContinue);
                    pMsg->SetCmd(plAnimCmdMsg::kSetForewards);
                    fActive = false;

                    // Remove our input interface from the input stack
                    plInputIfaceMgrMsg *msg = new plInputIfaceMgrMsg( plInputIfaceMgrMsg::kRemoveInterface );
                    msg->SetIFace( fInputIface );
                    plgDispatch::MsgSend( msg );
                    plInputManager::SetRecenterMouse(false);
                }
                else
                {
                    pMsg->SetCmd(plAnimCmdMsg::kIncrementForward);
                }
            }
            else
            {
                if (fAllOrNothing)
                {
                    pMsg->SetCmd(plAnimCmdMsg::kContinue);
                    pMsg->SetCmd(plAnimCmdMsg::kSetBackwards);
                    fActive = false;

                    // Remove our input interface from the input stack
                    plInputIfaceMgrMsg *msg = new plInputIfaceMgrMsg( plInputIfaceMgrMsg::kRemoveInterface );
                    msg->SetIFace( fInputIface );
                    plgDispatch::MsgSend( msg );

                    plInputManager::SetRecenterMouse(false);
                }
                else
                {
                    pMsg->SetCmd(plAnimCmdMsg::kIncrementBackward);
                }
            }
            plgDispatch::MsgSend(pMsg);
            fYPos = pMMsg->GetYPos();
        }
        
        return true;
    }

    plCmdIfaceModMsg* pCMsg = plCmdIfaceModMsg::ConvertNoRef(msg);
    if (pCMsg && pCMsg->Cmd(plCmdIfaceModMsg::kIndexCallback))
    {
        fIface = pCMsg->fIndex;
        return true;
    }

    plGenRefMsg* pRefMsg = plGenRefMsg::ConvertNoRef(msg);
    if (pRefMsg)
    {
        if (pRefMsg->GetContext() == plRefMsg::kOnCreate )
        {
            if (pRefMsg->fType == kTypeX)
            {   
                fXAnim = pRefMsg->GetRef()->GetKey();

                // add callbacks for beginning and end of animation
                plEventCallbackMsg* pCall1 = new plEventCallbackMsg;
                pCall1->fEvent = kBegin;
                pCall1->fRepeats = -1;
                pCall1->AddReceiver(GetKey());
                
                plEventCallbackMsg* pCall2 = new plEventCallbackMsg;
                pCall2->fEvent = kEnd;
                pCall2->fRepeats = -1;
                pCall2->AddReceiver(GetKey());

                plAnimCmdMsg* pMsg = new plAnimCmdMsg;
                pMsg->SetCmd(plAnimCmdMsg::kAddCallbacks);
                pMsg->AddCallback(pCall1);
                pMsg->AddCallback(pCall2);
                pMsg->SetAnimName(fAnimLabel);
                pMsg->AddReceiver( fXAnim );

                hsRefCnt_SafeUnRef( pCall1 );
                hsRefCnt_SafeUnRef( pCall2 );

                plgDispatch::MsgSend(pMsg);
            }
            else 
            if (pRefMsg->fType == kTypeY)
            {
                fYAnim = pRefMsg->GetRef()->GetKey();
                
                // add callbacks for beginning and end of animation
                plEventCallbackMsg* pCall1 = new plEventCallbackMsg;
                pCall1->fEvent = kBegin;
                pCall1->fRepeats = -1;
                pCall1->AddReceiver(GetKey());
                
                plEventCallbackMsg* pCall2 = new plEventCallbackMsg;
                pCall2->fEvent = kEnd;
                pCall2->fRepeats = -1;
                pCall2->AddReceiver(GetKey());

                plAnimCmdMsg* pMsg = new plAnimCmdMsg;
                pMsg->SetCmd(plAnimCmdMsg::kAddCallbacks);
                pMsg->AddCallback(pCall1);
                pMsg->AddCallback(pCall2);
                pMsg->AddReceiver( fYAnim );
                pMsg->SetAnimName(fAnimLabel);

                hsRefCnt_SafeUnRef( pCall1 );
                hsRefCnt_SafeUnRef( pCall2 );

                plgDispatch::MsgSend(pMsg);     
            }
            else 
            if (pRefMsg->fType == kTypeLogic)
            {
                SetNotificationKey(pRefMsg->GetRef());
            }
        }
        else
        if (pRefMsg->GetContext() == plRefMsg::kOnDestroy )
        {
            if (pRefMsg->fType == kTypeX)
                fXAnim = nil;
            else 
            if (pRefMsg->fType == kTypeY)
                fYAnim = nil;
            else 
            if (pRefMsg->fType == kTypeLogic)
                fNotificationKey = nil;
        }
        return true;    
    }
    
    return plSingleModifier::MsgReceive(msg);
}
示例#22
0
bool plCameraModifier1::MsgReceive(plMessage* msg)
{
    if (GetBrain())
        GetBrain()->MsgReceive(msg);
        
    plCameraMsg* pCamMsg = plCameraMsg::ConvertNoRef(msg);
    if (pCamMsg)
    {
        if (pCamMsg->Cmd(plCameraMsg::kAddFOVKeyframe))
        {
            hsRefCnt_SafeRef(msg);
            fFOVInstructions.Append(pCamMsg);
            return true;
        }
        else
        if (pCamMsg->Cmd(plCameraMsg::kSetAnimated))
        {
            fAnimated = true;
            return true;
        }
    }
    plEventCallbackMsg* pEventMsg = plEventCallbackMsg::ConvertNoRef(msg);
    if (pEventMsg)
    {
        double time = (double)fFOVInstructions[pEventMsg->fIndex]->GetConfig()->fAccel;
        double time2 = (double)pEventMsg->fEventTime;
        time = hsABS(time - time2);
        float h = fFOVInstructions[pEventMsg->fIndex]->GetConfig()->fFOVh;
        if (GetBrain())
            GetBrain()->SetFOVGoal(h, time);
    }

    plAnimCmdMsg* pAnimMsg = plAnimCmdMsg::ConvertNoRef(msg);
    if (pAnimMsg)
    {
        hsRefCnt_SafeRef(msg);
        msg->ClearReceivers();
        msg->AddReceiver(msg->GetSender());
        fMessageQueue.Append(msg);
        return true;
    }
    plGenRefMsg* pRefMsg = plGenRefMsg::ConvertNoRef(msg);
    if (pRefMsg )
    {
        if( pRefMsg->GetContext() & (plRefMsg::kOnCreate | plRefMsg::kOnRequest) )
        {
            if (pRefMsg->fType == kRefBrain)
            {
                plCameraBrain1* pBrain = plCameraBrain1::ConvertNoRef(pRefMsg->GetRef());
                if (pBrain)
                {
                    pBrain->SetCamera(this);
                    fBrain = pBrain;
                    if (fSubObj)
                        fBrain->SetSubject(fSubObj);
                }
            }
            else
            if (pRefMsg->fType == kRefCallbackMsg && fMessageQueue[pRefMsg->fWhich] != nil)
            {
                
                plgDispatch::MsgSend(fMessageQueue[pRefMsg->fWhich]);
                fMessageQueue[pRefMsg->fWhich] = nil;
            }
        }
        else if( pRefMsg->GetContext() & (plRefMsg::kOnDestroy | plRefMsg::kOnRemove) )
        {
            plCameraBrain1* pBrain = (plCameraBrain1*)(pRefMsg->GetRef());
            if (fBrain == pBrain)
                fBrain = nil;
        }
        return true;
     }
    return plSingleModifier::MsgReceive(msg);
}
示例#23
0
pyGameScore::pyGameScore(pfGameScore * score) 
    : fScore(score)
{
    hsRefCnt_SafeRef(score);
}
hsBool plMsgForwarder::IForwardCallbackMsg(plMessage *msg)
{
    // Only process as a callback message if it is one, AND it has callbacks
    plMessageWithCallbacks *callbackMsg = plMessageWithCallbacks::ConvertNoRef(msg);
    if (callbackMsg && callbackMsg->GetNumCallbacks() > 0)
    {
        for (int i = 0; i < callbackMsg->GetNumCallbacks(); i++)
        {
            plEventCallbackMsg *event = callbackMsg->GetEventCallback(i);
            hsAssert(event, "Message forwarder only supports event callback messages");
            if (event)
            {
                plForwardCallback *fc = new plForwardCallback;
                fc->fNumCallbacks = fForwardKeys.Count();

                // Turn off net propagate the callbacks to us will all be local.  Only the
                // callback we send will go over the net
                fc->fNetPropogate = (event->HasBCastFlag(plMessage::kNetPropagate) != 0);
                event->SetBCastFlag(plMessage::kNetPropagate, false);

                for (int j = 0; j < event->GetNumReceivers(); j++)
                    fc->fOrigReceivers.Append((plKey)event->GetReceiver(j));

                event->ClearReceivers();
                event->AddReceiver(GetKey());

                fCallbacks[event] = fc;

#if 0
                hsStatusMessageF("Adding CBMsg, eventSender=%s, eventRemoteMsg=%d\n",                   
                    event->GetSender() ? event->GetSender()->GetName() : "nil", fc->fNetPropogate);
#endif
            }
        }
#if 0
        hsStatusMessageF("Fwding CBMsg, sender=%s, remoteMsg=%d",
            msg->GetSender() ? msg->GetSender()->GetName() : "nil", msg->HasBCastFlag(plMessage::kNetNonLocal));
#endif
        IForwardMsg(callbackMsg);
        
        return true;
    }

    // Callback from one of our forward keys.  Don't send the final callback to the original
    // requester until all forward keys have reported in.
    plEventCallbackMsg *eventMsg = plEventCallbackMsg::ConvertNoRef(msg);
    if (eventMsg)
    {
        CallbackMap::const_iterator it = fCallbacks.find(eventMsg);
        if (it != fCallbacks.end())
        {
            plForwardCallback *fc = it->second;
            if (--fc->fNumCallbacks == 0)
            {
                hsStatusMessageF("plEventCallbackMsg received, erasing, sender=%s, remoteMsg=%d\n",
                    msg->GetSender() ? msg->GetSender()->GetName().c_str() : "nil", msg->HasBCastFlag(plMessage::kNetNonLocal));

                fCallbacks.erase(eventMsg);

                plUoid uoid = GetKey()->GetUoid();
                hsBool locallyOwned = (plNetClientApp::GetInstance()->IsLocallyOwned(uoid) != plSynchedObject::kNo);

                // If the callback was originally net propagated, and we own this forwarder, net propagate the callback
                if (fc->fNetPropogate && locallyOwned)
                    eventMsg->SetBCastFlag(plMessage::kNetPropagate);

                eventMsg->ClearReceivers();
                eventMsg->AddReceivers(fc->fOrigReceivers);
                eventMsg->SetSender(GetKey());
                hsRefCnt_SafeRef(eventMsg);
                eventMsg->Send();

                delete fc;
            }
        }
        else
        {
            hsStatusMessageF("! Unknown plEventCallbackMsg received, sender=%s, remoteMsg=%d\n",
                msg->GetSender() ? msg->GetSender()->GetName().c_str() : "nil", msg->HasBCastFlag(plMessage::kNetNonLocal));
            hsAssert(0, "Unknown plEventCallbackMsg received");
        }
        return true;
    }

    return false;
}