Exemplo n.º 1
0
void KinectV2Classifier::eventSetPredicting(ofxControlButtonEventArgs & evt) {
    if (evt.value) {
        toRecord = false;
        toPredict = true;
        capturing = false;
        clock.stop();
        startCountdown();
    }
    else if (!evt.value && !recording) {
        clock.stop();
    }
}
Exemplo n.º 2
0
void Watchdog::startCountdownIfNeeded()
{
    if (!m_isStopped)
        return; // Already started.

    if (!isArmed())
        return; // Not executing JS script. No need to start.

    if (isEnabled()) {
        m_elapsedTime = std::chrono::microseconds::zero();
        m_startTime = currentCPUTime();
        startCountdown(m_limit);
    }
}
Exemplo n.º 3
0
InputEventSelectionDialog::InputEventSelectionDialog(QWidget* parent)
    : QDialog(parent)
    , ui(new Ui::InputEventSelectionDialog)
{
	ui->setupUi(this);
	ui->countdownlabel->setText(m_countingText.arg(COUNTDOWN_SECS));

	m_countdownTimer = new QTimer(this);
	connect(m_countdownTimer, SIGNAL(timeout()), this, SLOT(updateCountdown()));

	setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint);
	setFixedSize(size());

	// workaround to avoid direct thread ui access
	connect(this, SIGNAL(startCountdown(QString)), this, SLOT(handleStartCountdown(QString)));
	connect(this, SIGNAL(cancelCountdown()), this, SLOT(handleCancelCountdown()));
}
Exemplo n.º 4
0
bool Watchdog::didFire(ExecState* exec)
{
    if (m_didFire)
        return true;

    if (!m_timerDidFire)
        return false;
    m_timerDidFire = false;
    stopCountdown();

    auto currentTime = currentCPUTime();
    auto deltaTime = currentTime - m_startTime;
    auto totalElapsedTime = m_elapsedTime + deltaTime;
    if (totalElapsedTime > m_limit) {
        // Case 1: the allowed CPU time has elapsed.

        // If m_callback is not set, then we terminate by default.
        // Else, we let m_callback decide if we should terminate or not.
        bool needsTermination = !m_callback
            || m_callback(exec, m_callbackData1, m_callbackData2);
        if (needsTermination) {
            m_didFire = true;
            return true;
        }

        // The m_callback may have set a new limit. So, we may need to restart
        // the countdown.
        startCountdownIfNeeded();

    } else {
        // Case 2: the allowed CPU time has NOT elapsed.

        // Tell the timer to alarm us again when it thinks we've reached the
        // end of the allowed time.
        auto remainingTime = m_limit - totalElapsedTime;
        m_elapsedTime = totalElapsedTime;
        m_startTime = currentTime;
        startCountdown(remainingTime);
    }

    return false;
}
Exemplo n.º 5
0
void InputEventSelectionDialog::onInputEvent(const BINDINGTARGET& target, uint32 value)
{
	auto setSelection =
	    [this](CInputBindingManager::BINDINGTYPE bindingType, const auto& target) {
		    m_selectedTarget = target;
		    m_bindingType = bindingType;
		    m_state = STATE::SELECTED;
		    auto targetDescription = m_inputManager->GetTargetDescription(target);
		    startCountdown(QString::fromStdString(targetDescription));
	    };

	auto resetSelection =
	    [this]() {
		    m_selectedTarget = BINDINGTARGET();
		    m_state = STATE::WAITING;
		    m_bindingType = CInputBindingManager::BINDING_UNBOUND;
		    cancelCountdown();
	    };

	auto setSelectionSimulatedAxis =
	    [this](const auto& target) {
		    m_selectedTargetSimulatedAxis = target;
		    m_state = STATE::SIMULATEDAXIS_SELECTED;
		    auto targetDescription = m_inputManager->GetTargetDescription(target);
		    startCountdown(QString::fromStdString(targetDescription));
	    };

	auto resetSelectionSimulatedAxis =
	    [this]() {
		    m_selectedTargetSimulatedAxis = BINDINGTARGET();
		    m_state = STATE::SIMULATEDAXIS_WAITING;
		    cancelCountdown();
	    };

	switch(m_state)
	{
	case STATE::WAITING:
		//Check if we've pressed something
		if(PS2::CControllerInfo::IsAxis(m_button))
		{
			switch(target.keyType)
			{
			case BINDINGTARGET::KEYTYPE::BUTTON:
				if(value != 0)
				{
					setSelection(CInputBindingManager::BINDING_SIMULATEDAXIS, target);
				}
				break;
			case BINDINGTARGET::KEYTYPE::AXIS:
				if(!IsAxisIdle(value))
				{
					setSelection(CInputBindingManager::BINDING_SIMPLE, target);
				}
				break;
			}
		}
		else
		{
			switch(target.keyType)
			{
			case BINDINGTARGET::KEYTYPE::BUTTON:
				if(value != 0)
				{
					setSelection(CInputBindingManager::BINDING_SIMPLE, target);
				}
				break;
			case BINDINGTARGET::KEYTYPE::AXIS:
				if(!IsAxisIdle(value))
				{
					setSelection(CInputBindingManager::BINDING_SIMPLE, target);
				}
				break;
			case BINDINGTARGET::KEYTYPE::POVHAT:
				if(value < BINDINGTARGET::POVHAT_MAX)
				{
					m_bindingValue = value;
					setSelection(CInputBindingManager::BINDING_POVHAT, target);
				}
			}
		}
		break;
	case STATE::SELECTED:
		if(target != m_selectedTarget) break;
		switch(target.keyType)
		{
		case BINDINGTARGET::KEYTYPE::BUTTON:
			if(value == 0)
			{
				resetSelection();
			}
			break;
		case BINDINGTARGET::KEYTYPE::AXIS:
			if(IsAxisIdle(value))
			{
				resetSelection();
			}
			break;
		case BINDINGTARGET::KEYTYPE::POVHAT:
			if(m_bindingValue != value)
			{
				resetSelection();
			}
		}
		break;
	case STATE::SIMULATEDAXIS_WAITING:
		if((target.keyType == BINDINGTARGET::KEYTYPE::BUTTON) && (value != 0))
		{
			setSelectionSimulatedAxis(target);
		}
		break;
	case STATE::SIMULATEDAXIS_SELECTED:
		if(target != m_selectedTargetSimulatedAxis) break;
		if(value == 0)
		{
			resetSelectionSimulatedAxis();
		}
		break;
	}
}
Exemplo n.º 6
0
bool SynchronizationProtocol::notifyEventAsynchronous(Event* event)
{
    if (event->type != EVENT_TYPE_MESSAGE)
        return true;
    NetworkString data = event->data();
    if (data.size() < 10)
    {
        Log::warn("SynchronizationProtocol", "Received a message too short.");
        return true;
    }
    uint8_t talk_id = data.gui8();
    uint32_t token = data.gui32(1);
    uint32_t request = data.gui8(5);
    uint32_t sequence = data.gui32(6);

    std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers();
    assert(peers.size() > 0);

    if (m_listener->isServer())
    {
        if (talk_id > peers.size())
        {
            Log::warn("SynchronizationProtocol", "The ID isn't known.");
            return true;
        }
    }

    uint8_t peer_id = 0;
    for (unsigned int i = 0; i < peers.size(); i++)
    {
        if (peers[i]->isSamePeer(*event->peer))
        {
            peer_id = i;
        }
    }
    if (peers[peer_id]->getClientServerToken() != token)
    {
        Log::warn("SynchronizationProtocol", "Bad token from peer %d", talk_id);
        return true;
    }

    if (request)
    {
        NetworkString response;
        response.ai8(data.gui8(talk_id)).ai32(token).ai8(0).ai32(sequence);
        m_listener->sendMessage(this, peers[peer_id], response, false);
        Log::verbose("SynchronizationProtocol", "Answering sequence %u", sequence);
        if (data.size() == 14 && !m_listener->isServer()) // countdown time in the message
        {
            uint32_t time_to_start = data.gui32(10);
            Log::debug("SynchronizationProtocol", "Request to start game in %d.", time_to_start);
            if (!m_countdown_activated)
                startCountdown(time_to_start);
            else
                m_countdown = (double)(time_to_start/1000.0);
        }
        else
            Log::verbose("SynchronizationProtocol", "No countdown for now.");
    }
    else // response
    {
        if (sequence >= m_pings[peer_id].size())
        {
            Log::warn("SynchronizationProtocol", "The sequence# %u isn't known.", sequence);
            return true;
        }
        double current_time = StkTime::getRealTime();
        m_total_diff[peer_id] += current_time - m_pings[peer_id][sequence];
        Log::verbose("SynchronizationProtocol", "InstantPing is %u",
            (unsigned int)((current_time - m_pings[peer_id][sequence])*1000));
        m_successed_pings[peer_id]++;
        m_average_ping[peer_id] = (int)((m_total_diff[peer_id]/m_successed_pings[peer_id])*1000.0);

        Log::debug("SynchronizationProtocol", "Ping is %u", m_average_ping[peer_id]);
    }
    return true;
}
Exemplo n.º 7
0
void loop() {
    // Though counter-intuitive, game creation cannot be in setup because of varying arduino boot times and boot gibberish
    if (!gameCreated) {
        drawGUI();
        while(!waitUntil(JOYSTICK_BUTTON_PIN, false));
        if (!startNetwork()) {
            tft.fillScreen(ST7735_BLACK); // we must clear all conflicting messages from screen
            tft.setCursor(0,0);
            dualPrint("Network connection failed!");
            dualPrint("Please ensure:");
            dualPrint("1) both arduinos are connected");
            dualPrint("2) both parties pressed the joystick");
            dualPrint("If both are true, consult someone who");
            dualPrint("looks like he knows what he's talking about");
            dualPrint("Reset both Arduinos to try again");
            while(1);
        }
        /* Extensibility Goal:
         * Enable colour selection here, time permissible
         */
        gameCreated = true;
    }
    if (!gameStarted) {
        setSpawns(&player1, &player2);
        setColour(&player1, &player2);
        tft.fillScreen(ST7735_BLACK);
        startCountdown();
        gameStarted = true;
    }
    winner = gameOver(&player1.currentPosition, &player2.currentPosition);
    if (winner) {
        tft.setCursor(0, 80);
        String message;
        switch (winner) {
        case -1:
            message = "YOU SUPER TIE";
            break;
        case 1:
            message = "YOU SUPER WIN";
            player1.score++;
            break;
        case 2:
            message = "YOU SUPER LOSE";
            player2.score++;
            break;
        }
        tft.println(message);
        tft.println("SCORES:");
        tft.print("You: ");
        tft.print(player1.score);
        tft.print(" | Him: ");
        tft.println(player2.score);
        tft.println("Again? <Press Joystick>");
        waitUntil(JOYSTICK_BUTTON_PIN, LOW);
        memset(&wallPositions, 0, 2560); // 2560 is a magic number because size_ts were acting unexpectedly
        gameStarted = false;
        tft.fillScreen(ST7735_BLACK);
    } else {
        // add a wall ad draw car at current position
        addWallPosition(player1.currentPosition);
        addWallPosition(player2.currentPosition);
        tft.fillRect(player1.currentPosition.x, player1.currentPosition.y, 2, 2, player1.colour);
        tft.fillRect(player2.currentPosition.x, player2.currentPosition.y, 2, 2, player2.colour);
        movement_t newDirection = getJoystickInput();
        if (validInput(newDirection, player1.direction)) player1.direction = newDirection;
        sendDeltas(&player1.direction);
        receiveDeltas(&player2.direction);
        player1.currentPosition.x += player1.direction.x;
        player1.currentPosition.y += player1.direction.y;
        player2.currentPosition.x += player2.direction.x;
        player2.currentPosition.y += player2.direction.y;
        delay(75); // this is how we control the game speed
        /* Extensibility Goal:
         * Find a more efficient and reliable way of controlling game speed.
         * Implement it, and allow it to be customized
         */
    }
}