Beispiel #1
0
void ZActorAnimation::Set(ZA_ANIM_STATE nAnim, bool bReset)
{
	if ((!bReset) && (GetCurrState() == nAnim)) return;

	ZBrain* pBrain = m_pBody->GetBrain();

	if (pBrain)
	{
		pBrain->OnBody_AnimExit(m_nCurrState);
	}

	if (m_pBody->m_pVMesh)
	{
		if (m_pBody->m_pVMesh->SetAnimation(ani_mode_lower, m_AnimationTable[nAnim].szName, m_AnimationTable[nAnim].bEnableCancel))
		{
			m_nCurrState = nAnim;
		}
	}
	else
	{
		_ASSERT(0);
	}

	if (pBrain) pBrain->OnBody_AnimEnter(m_nCurrState);
}
Beispiel #2
0
HRESULT CDIL_CAN_STUB::CAN_GetCntrlStatus(const HANDLE& /*hEvent*/, UINT& unCntrlStatus)
{
    HRESULT hResult = S_OK;
    //EnterCriticalSection(&sg_CSBroker);
    switch (GetCurrState())
    {
        case STATE_CONNECTED:
        {
            unCntrlStatus = NORMAL_ACTIVE;
        }
        break;
        case STATE_INITIALISED:
        {
            unCntrlStatus = INITIALISED;
        }
        break;
        case STATE_REGISTERED:
        {
            unCntrlStatus = RESET_STATE;
        }
        break;
        case STATE_PRIMORDIAL:
        case STATE_RESET:
        default:
        {
            hResult = S_FALSE;
        }
        break;
    }
    //LeaveCriticalSection(&sg_CSBroker);

    return hResult;
}
Beispiel #3
0
HRESULT CDIL_CAN_STUB::CAN_SetAppParams(HWND hWndOwner, Base_WrapperErrorLogger* pILog)
{
    HRESULT hResult = S_FALSE;

    if (GetCurrState() == STATE_PRIMORDIAL) // Only now this operation makes sense
    {
        if ((pILog != NULL))
        {
            sg_hOwnerWnd = hWndOwner;       // Owner window handle
            sg_pIlog = pILog;               // Log interface pointer
            vInitialiseAllData();           // Initialise other data

            SetCurrState(STATE_RESET);      // Reset state from primordial
            hResult = S_OK;                 // All okey
        }
        else
        {
            strcpy(sg_acErrStr, "Null argument value(s) in SetAppParams");
        }
    }
    else
    {
        strcpy(sg_acErrStr, "Improper current state to call SetAppParams");
    }

    return hResult;
}
Beispiel #4
0
HRESULT Worker_Disconnect(ISimENG* /*pISimENGLoc*/, Base_WrapperErrorLogger* pIlogLoc)
{
    if (GetCurrState() == STATE_PRIMORDIAL)
    {
        strcpy(sg_acErrStr, "CAN_STUB_DeselectHwInterface called at STATE_PRIMORDIAL");
        return S_FALSE;
    }
    else if (GetCurrState() == STATE_RESET)
    {
        pIlogLoc->vLogAMessage(__FILE__, __LINE__, 
            ("CAN_STUB_DeselectHwInterface called at improper state"));
        return S_FALSE;
    }

    // Close the message reading thread
    sg_sParmRThreadStub.bTerminateThread();

    return S_OK;
}
Beispiel #5
0
HRESULT Worker_StartHardware(ISimENG* pISimENGLoc, Base_WrapperErrorLogger* pIlogLoc)
{
    HRESULT hResult = S_FALSE;
    if ((GetCurrState() == STATE_INITIALISED) || (GetCurrState() == STATE_REGISTERED))
    {
        for (UINT i = 0; i < sg_unClientCnt; i++)
        {
            hResult = pISimENGLoc->ConnectNode((USHORT)sg_asClientToBufMap[i].dwClientID);
        }
        if (hResult == S_OK)
        {
            SetCurrState(STATE_CONNECTED);
        }
    }
    else
    {
        pIlogLoc->vLogAMessage(__FILE__, __LINE__, 
            ("CAN_STUB_StartHardware called at improper state"));
    }

    return hResult;
}
Beispiel #6
0
HRESULT Worker_Connect(ISimENG* pISimENGLoc, Base_WrapperErrorLogger* pIlogLoc)
{
    if (GetCurrState() == STATE_PRIMORDIAL)
    {
        strcpy(sg_acErrStr, "CAN_STUB_Connect called at STATE_PRIMORDIAL");
        return S_FALSE;
    }
    else if (GetCurrState() != STATE_INITIALISED)
    {
        sg_pIlog->vLogAMessage(__FILE__, __LINE__, 
            ("CAN_STUB_Connect called at improper state"));
        return S_FALSE;
    }

    sg_sParmRThreadStub.m_unActionCode = INVOKE_FUNCTION;
	if (sg_sParmRThreadStub.bStartThread(FlexMsgReadThreadProc_Stub) == FALSE)
	{
        sg_sParmRThreadStub.m_hActionEvent = NULL;
        // Unregister from the simulation engine
        for (UINT i = 0; i < sg_unClientCnt; i++)
        {
            sg_ushTempClientID  = (USHORT)sg_asClientToBufMap[i].dwClientID;
            sg_hTmpClientHandle = sg_asClientToBufMap[i].hClientHandle;
            sg_hTmpPipeHandle   = sg_asClientToBufMap[i].hPipeFileHandle;
            Worker_UnregisterClient(pISimENGLoc, pIlogLoc);
            sg_asClientToBufMap[i].dwClientID = 0;
            sg_asClientToBufMap[i].hClientHandle = NULL;
            sg_asClientToBufMap[i].hPipeFileHandle = NULL;
        }
    	sg_pIlog->vLogAMessage(__FILE__, __LINE__,
                    ("Unable to start the reading thread"));
        return S_FALSE;
    }

    // Reaching upto this point means all the necessary activities are over
    SetCurrState(STATE_REGISTERED);
    
    return S_OK;
}
Beispiel #7
0
HRESULT CDIL_CAN_STUB::CAN_SetConfigData(PCHAR /*ConfigFile*/, int /*Length*/)
{
    switch (GetCurrState())
    {
        case STATE_REGISTERED:
        case STATE_CONNECTED:
        case STATE_INITIALISED:
        break;
        case STATE_PRIMORDIAL:
        case STATE_RESET:
        default:
        {
            strcpy(sg_acErrStr, "CAN_STUB_SetConfigData called at improper state");
            return S_FALSE;
        }
        break;
    }

    // First disconnect the node
    CAN_StopHardware();
    return S_OK;
}
Beispiel #8
0
HRESULT Worker_StopHardware(ISimENG* pISimENGLoc, Base_WrapperErrorLogger* pIlogLoc)
{
    HRESULT hResult = S_FALSE;
    if (GetCurrState() == STATE_CONNECTED)
    {
        // Just disconnect the node from the bus simulation
        for (UINT i = 0; i < sg_unClientCnt; i++)
        {
            hResult = pISimENGLoc->DisconnectNode((USHORT)sg_asClientToBufMap[i].dwClientID);
        }        
        if (hResult == S_OK)
        {
            SetCurrState(STATE_INITIALISED);
        }
    }
    else
    {
		if ( pIlogLoc )
        pIlogLoc->vLogAMessage(__FILE__, __LINE__, 
            ("CAN_STUB_StopHardware called at improper state"));
    }

    return hResult;
}
Beispiel #9
0
bool CNetClient::HandleMessage(CNetMessage* message)
{
	// Handle non-FSM messages first

	Status status = m_Session->GetFileTransferer().HandleMessageReceive(message);
	if (status == INFO::OK)
		return true;
	if (status != INFO::SKIPPED)
		return false;

	if (message->GetType() == NMT_FILE_TRANSFER_REQUEST)
	{
		CFileTransferRequestMessage* reqMessage = (CFileTransferRequestMessage*)message;

		// TODO: we should support different transfer request types, instead of assuming
		// it's always requesting the simulation state

		std::stringstream stream;

		LOGMESSAGERENDER("Serializing game at turn %u for rejoining player", m_ClientTurnManager->GetCurrentTurn());
		u32 turn = to_le32(m_ClientTurnManager->GetCurrentTurn());
		stream.write((char*)&turn, sizeof(turn));

		bool ok = m_Game->GetSimulation2()->SerializeState(stream);
		ENSURE(ok);

		// Compress the content with zlib to save bandwidth
		// (TODO: if this is still too large, compressing with e.g. LZMA works much better)
		std::string compressed;
		CompressZLib(stream.str(), compressed, true);

		m_Session->GetFileTransferer().StartResponse(reqMessage->m_RequestID, compressed);

		return true;
	}

	// Update FSM
	bool ok = Update(message->GetType(), message);
	if (!ok)
		LOGERROR("Net client: Error running FSM update (type=%d state=%d)", (int)message->GetType(), (int)GetCurrState());
	return ok;
}