Esempio n. 1
0
void GameStateModule::update()
{
    // Check comm input last so we can reset button toggles.
    if (buttonPressInput.message().toggle() != last_button)
    {
        last_button = !last_button;
        if (!commInput.message().have_remote_gc()
            || latest_data.state() == STATE_PLAYING)
        {
            advanceState();
        }
    }
    if (initialStateInput.message().toggle() != last_initial)
    {
        last_initial = !last_initial;
        if (!commInput.message().have_remote_gc())
            reset();
    }
    if (switchTeamInput.message().toggle() != last_team)
    {
        last_team = !last_team;
        if (!commInput.message().have_remote_gc()
            && latest_data.state() == STATE_INITIAL)
            switchTeam();
    }
    if (switchKickOffInput.message().toggle() != last_kickoff)
    {
        last_kickoff = !last_kickoff;
        if (!commInput.message().have_remote_gc()
            && latest_data.state() == STATE_INITIAL)
            switchKickOff();
    }
    if (commInput.message().have_remote_gc())
    {
        latest_data = commInput.message();
        if (latest_data.state() != STATE_PLAYING)
        {
            keep_time = false;
        }
        else
        {
            keep_time = true;
        }
    }
    if (keep_time)
    {
        // @TODO: keep track of secs remaining if we have no comm.
    }
}
Esempio n. 2
0
void GameStateModule::update()
{
    // Check comm input last so we can reset button toggles.
    if (buttonPressInput.message().toggle() != last_button)
    {
        last_button = !last_button;
        if (!commInput.message().have_remote_gc()
            || latest_data.state() == STATE_PLAYING)
        {
            advanceState();
        }
    }
    if (initialStateInput.message().toggle() != last_initial)
    {
        last_initial = !last_initial;
        if (!commInput.message().have_remote_gc())
            reset();
    }
    if (switchTeamInput.message().toggle() != last_team)
    {
        last_team = !last_team;
        if (!commInput.message().have_remote_gc()
            && latest_data.state() == STATE_INITIAL)
            switchTeam();
    }
    if (switchKickOffInput.message().toggle() != last_kickoff)
    {
        last_kickoff = !last_kickoff;
        if (!commInput.message().have_remote_gc()
            && latest_data.state() == STATE_INITIAL)
            switchKickOff();
    }
    if (commInput.message().have_remote_gc())
    {
        latest_data = commInput.message();
        if (latest_data.state() != STATE_PLAYING)
        {
            keep_time = false;
            start_time = 0;
        }
        else
        {
            keep_time = true;
            if (!start_time)
            {
                start_time = realtime_micro_time();
            }
        }
        // Did GC get our message yet??
        for (int i = 0; i < latest_data.team_size(); ++i)
        {
            messages::TeamInfo* team = latest_data.mutable_team(i);
            if (team->team_number() == team_number)
            {
                messages::RobotInfo* player = team->mutable_player(player_number-1);
                if (response_status == GAMECONTROLLER_RETURN_MSG_MAN_PENALISE)
                {
                    if(player->penalty())
                    {
                        response_status = GAMECONTROLLER_RETURN_MSG_ALIVE;
                    }
                }
                else if (response_status == GAMECONTROLLER_RETURN_MSG_MAN_UNPENALISE)
                {
                    if(!player->penalty())
                    {
                        response_status == GAMECONTROLLER_RETURN_MSG_ALIVE;
                    }
                }
            }
        }
    }
    if (keep_time && commInput.message().have_remote_gc())
    {
        long long diff_time = realtime_micro_time() - start_time;
        latest_data.set_secs_remaining(600 -
            static_cast<unsigned int>(diff_time/MICROS_PER_SECOND));
        //TODO keep track of penalty times
    }
}
Esempio n. 3
0
/**
 * Processes the data in the scratch buffer based on the current state.
 *
 * @returns VBox status code.
 */
int USBProxyBackendUsbIp::processData()
{
    int rc = VINF_SUCCESS;

    switch (m->enmRecvState)
    {
        case kUsbIpRecvState_Hdr:
        {
            /* Check that the reply matches our expectations. */
            if (   RT_N2H_U16(m->Scratch.RetDevList.u16Version) == USBIP_VERSION
                && RT_N2H_U16(m->Scratch.RetDevList.u16Cmd) == USBIP_REQ_RET_DEVLIST
                && RT_N2H_U32(m->Scratch.RetDevList.u32Status) == USBIP_STATUS_SUCCESS)
            {
                /* Populate the number of exported devices in the list and go to the next state. */
                m->cDevicesLeft = RT_N2H_U32(m->Scratch.RetDevList.u32DevicesExported);
                if (m->cDevicesLeft)
                    advanceState(kUsbIpRecvState_ExportedDevice);
                else
                    advanceState(kUsbIpRecvState_None);
            }
            else
            {
                LogRelMax(10, ("USB/IP: Host sent an invalid reply to the list exported device request (Version: %#x Cmd: %#x Status: %#x)\n",
                               RT_N2H_U16(m->Scratch.RetDevList.u16Version), RT_N2H_U16(m->Scratch.RetDevList.u16Cmd),
                               RT_N2H_U32(m->Scratch.RetDevList.u32Status)));
                rc = VERR_INVALID_STATE;
            }
            break;
        }
        case kUsbIpRecvState_ExportedDevice:
        {
            /* Create a new device and add it to the list. */
            usbProxyBackendUsbIpExportedDeviceN2H(&m->Scratch.ExportedDevice);
            rc = addDeviceToList(&m->Scratch.ExportedDevice);
            if (RT_SUCCESS(rc))
            {
                m->cInterfacesLeft = m->Scratch.ExportedDevice.bNumInterfaces;
                if (m->cInterfacesLeft)
                    advanceState(kUsbIpRecvState_DeviceInterface);
                else
                {
                    m->cDevicesLeft--;
                    if (m->cDevicesLeft)
                        advanceState(kUsbIpRecvState_ExportedDevice);
                    else
                        advanceState(kUsbIpRecvState_None);
                }
            }
            break;
        }
        case kUsbIpRecvState_DeviceInterface:
        {
            /*
             * If all interfaces for the current device were received receive the next device
             * if there is another one left, if not we are done with the current request.
             */
            m->cInterfacesLeft--;
            if (m->cInterfacesLeft)
                advanceState(kUsbIpRecvState_DeviceInterface);
            else
            {
                m->cDevicesLeft--;
                if (m->cDevicesLeft)
                    advanceState(kUsbIpRecvState_ExportedDevice);
                else
                    advanceState(kUsbIpRecvState_None);
            }
            break;
        }
        case kUsbIpRecvState_None:
        default:
            AssertMsgFailed(("Invalid USB/IP receive state %d\n", m->enmRecvState));
            return VERR_INVALID_STATE;
    }

    return rc;
}