コード例 #1
0
ファイル: socket.cpp プロジェクト: maekitalo/cxxtools
bool Socket::onOutput(StreamBuffer& sb)
{
    log_trace("onOutput");

    log_debug("send data to " << getPeerAddr());

    try
    {
        sb.endWrite();

        if ( sb.out_avail() )
        {
            sb.beginWrite();
        }
        else
        {
            if (sb.in_avail())
                onInput(sb);
            else
                sb.beginRead();
        }
    }
    catch (const std::exception& e)
    {
        log_warn("exception occured when processing request: " << e.what());
        close();
        return false;
    }

    return true;
}
コード例 #2
0
ファイル: ui_mainwindow.cpp プロジェクト: idx0/Sabre
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    QVBoxLayout* vbox = new QVBoxLayout;
    QWidget *widge = new QWidget;
    QFont ft("Courier New", 10);

    m_output = new Sabre::Output;

    m_btnDataDirectory = new QPushButton(tr("Choose Data Directory ..."), this);
    m_result = new QTextEdit(this);
    m_input = new QLineEdit(this);

    connect(m_btnDataDirectory, SIGNAL(clicked()), this, SLOT(onChangeDataDirectory()));

    m_result->setLineWrapMode(QTextEdit::NoWrap);
    m_result->setWordWrapMode(QTextOption::NoWrap);
    m_result->setAlignment(Qt::AlignTop | Qt::AlignLeft);
    m_result->setReadOnly(true);
    m_result->setFont(ft);

    vbox->addWidget(m_btnDataDirectory);
    vbox->addWidget(m_input);
    vbox->addWidget(m_result);

    widge->setLayout(vbox);

    restoreSettings();

    connect(m_input, SIGNAL(returnPressed()), this, SLOT(onInput()));
    connect(m_output, SIGNAL(textChanged(QString)), this, SLOT(onOutputChanged(QString)));

    setCentralWidget(widge);
}
コード例 #3
0
void GamePlayScene::updateScene(){
	
	
	///Physics world step
	world->Step(timeStep, velocityIterations, positionIterations);

	
	///Process Input
	onInput();
	m_player->update(m_game->m_InputManager, world);
	
	checkCollision();

	///update score
	hud->updateScore();

	///Update Game Elements
	bg->update(bgSpeed * 2);
	mg->update(bgSpeed);
	fg->update(bgSpeed);
	
	if (m_player->getPlayerState() == EPlayerState::SLIDING) {
		///Update Game Elements
		bg->update(bgSpeed * 4);
		mg->update(bgSpeed * 2);
		fg->update(bgSpeed * 2);

	}
	///update enemy and coin positions
	Spawner::GetInstance()->update();
	
}
コード例 #4
0
ファイル: client.cpp プロジェクト: mzijlstra/Hover-Tank-Racer
//------------------------------------------------------------------------------
// Main game loop inside the onExecute() method
//------------------------------------------------------------------------------
int Client::onExecute() {
    if(onInit() == false) {
        return -1;
    }

    SDL_Event event;
	Uint32 fps = 60;
	Uint32 frametime = 1000 / fps;
	Uint32 starttime, exectime;

    while(running) {
		starttime = SDL_GetTicks();

		// start by checking for OpenGL error
		GLenum error;
		while ((error = glGetError()) != GL_NO_ERROR) {
			printf("Error: %s\n", gluErrorString(error));
		}

		// check for input events
        while(SDL_PollEvent(&event)) {
            onEvent(&event);
        }

		// act on input events
        onInput();

		// TODO more game state updates here,
		// like applying velocity, gravity, etc
		p1->onUpdate();
		if (follow) {
			setXView(p1->getX());
			setYView(p1->getY());
		}

		// draw the screen
        onRender();

		// sleep time to make fps
		exectime = SDL_GetTicks() - starttime;
		if (exectime < frametime) {
			//SDL_Delay(SDL_GetTicks() % frametime);
			SDL_Delay(frametime - exectime);
		}
    }

    onCleanup();

    return 0;
}
コード例 #5
0
ファイル: socket.cpp プロジェクト: 913862627/cxxtools
bool Socket::onOutput(StreamBuffer& sb)
{
    log_trace("onOutput");

    log_debug("send data to " << getPeerAddr());

    try
    {
        sb.endWrite();

        if ( sb.out_avail() )
        {
            sb.beginWrite();
            _timer.start(_server.writeTimeout());
        }
        else
        {
            bool keepAlive = _request.header().keepAlive()
                          && _reply.header().keepAlive();

            if (keepAlive)
            {
                log_debug("do keep alive");
                _timer.start(_server.keepAliveTimeout());
                _request.clear();
                _reply.clear();
                _parser.reset(false);
                if (sb.in_avail())
                    onInput(sb);
                else
                    _stream.buffer().beginRead();
            }
            else
            {
                log_debug("don't do keep alive");
                close();
                return false;
            }
        }
    }
    catch (const std::exception& e)
    {
        log_warn("exception occured when processing request: " << e.what());
        close();
        timeout(*this);
        return false;
    }

    return true;
}
コード例 #6
0
/**
@brief 接受连接上的到达数据
@param [in] handle 连接的handle
@return -1:关闭的连接; 0:接收数据成功
*/
int CwxAppHandler4Channel::handle_event(int event, CWX_HANDLE)
{
    if (CWX_CHECK_ATTR(event, CwxAppHandler4Base::WRITE_MASK))
    {
        if (0 != onOutput()) return -1;
    }
    if (CWX_CHECK_ATTR(event, CwxAppHandler4Base::READ_MASK))
    {
        if (0 != onInput()) return -1;
    }
    if (CWX_CHECK_ATTR(event, CwxAppHandler4Base::TIMEOUT_MASK))
    {
        if (0 != onTimeout( channel()->getCurTime())) return -1;
    }
    return 0;
}
コード例 #7
0
ファイル: process.cpp プロジェクト: boundarydevices/qtbrowser
void process_t::fdReady(childProcess_t *child, int fd) {
	emit onInput((int)child->getpid(), fd);
}
コード例 #8
0
	void Window::process(const InputState &state) {
		Window *popup = nullptr;
		m_is_focused = true;

		for(int n = 0; n < (int)m_children.size(); n++) {
			m_children[n]->m_is_focused = false;
			m_children[n]->m_is_mouse_over = false;

			if(m_children[n]->m_is_closing) {
				PWindow window = m_children[n];
				m_children.erase(m_children.begin() + n);
				sendEvent(window.get(), Event::window_closed, m_children[n]->m_closing_value); 
				n--;
			}
			else if(m_children[n]->m_is_popup)
				popup = m_children[n].get();
		}

		if(popup) {
			popup->process(state);
			return;
		}

		int2 mouse_pos = state.mousePos();
		int2 local_mouse_pos = mouse_pos - m_clipped_rect.min;
		int finished_dragging = 0;
		bool escape = state.isKeyDown(InputKey::esc);

		InputButton button_map[3] = { InputButton::left, InputButton::right, InputButton::middle };

		if(m_dragging_mode) {
			if(!state.isMouseButtonPressed(button_map[m_dragging_mode - 1]) || escape)
				finished_dragging = escape? -1 : 1;
		}
		else {
			for(int k = 0; k < 3; k++) {
				if(state.isMouseButtonDown(button_map[k])) {
					m_dragging_mode = k + 1;
					m_drag_start = local_mouse_pos;
					break;
				}
			}
		}


		int2 focus_point = m_dragging_mode? m_drag_start : local_mouse_pos;
		bool is_handled = false;

		for(int n = (int)m_children.size() - 1; n >= 0; n--) {
			Window *child = m_children[n].get();
			if(child->isVisible() && m_has_hard_focus == child->m_has_hard_focus) {
				if(m_has_hard_focus || child->rect().isInside(focus_point)) {
					child->m_is_mouse_over = child->clippedRect().isInside(mouse_pos);
					child->process(state);
					is_handled = true;
					break;
				}
			}
		}

		if(!is_handled) {
			if(m_dragging_mode && !is_handled) {
				if(m_has_inner_rect && m_dragging_mode - 1 == 2) {
					setInnerRect(m_inner_rect + state.mouseMove());
					is_handled = true;
				}
				if(!is_handled)
					is_handled = onMouseDrag(state, m_drag_start, local_mouse_pos, m_dragging_mode - 1, finished_dragging);
				if(!is_handled)
					is_handled = onMouseClick(state, local_mouse_pos, m_dragging_mode - 1, finished_dragging);
			}
			if(!is_handled) {
				if(m_has_inner_rect) {
					int wheel = state.mouseWheelMove();
					int2 vector(0, 0);

					if(wheel)
						vector.y += wheel * rect().height() / 8;
					if(state.isKeyDownAuto(InputKey::pageup, 2))
						vector.y += rect().height();
					if(state.isKeyDownAuto(InputKey::pagedown, 2))
						vector.y -= rect().height();

					setInnerRect(m_inner_rect + vector);
				}

				onInput(state);
			}
		}
		
		if(escape && (!m_parent || m_is_popup) && !m_dragging_mode) // sending Event::escape only from main window
			sendEvent(this, Event::escape); //TODO: send only to focused windows

		if(finished_dragging)
			m_dragging_mode = 0;
	}