Ejemplo n.º 1
0
void Client::afterContentReceived(IrrlichtDevice *device)
{
	//infostream<<"Client::afterContentReceived() started"<<std::endl;

	bool headless_optimize = g_settings->getBool("headless_optimize"); //device->getVideoDriver()->getDriverType() == video::EDT_NULL;
	//bool no_output = device->getVideoDriver()->getDriverType() == video::EDT_NULL;

	const wchar_t* text = wgettext("Loading textures...");

	// Clear cached pre-scaled 2D GUI images, as this cache
	// might have images with the same name but different
	// content from previous sessions.
	guiScalingCacheClear(device->getVideoDriver());

	// Rebuild inherited images and recreate textures
	infostream<<"- Rebuilding images and textures"<<std::endl;
	draw_load_screen(text,device, guienv, 0, 70);
	if (!headless_optimize)
	m_tsrc->rebuildImagesAndTextures();
	delete[] text;

	// Rebuild shaders
	infostream<<"- Rebuilding shaders"<<std::endl;
	text = wgettext("Rebuilding shaders...");
	draw_load_screen(text, device, guienv, 0, 71);
	if (!headless_optimize)
	m_shsrc->rebuildShaders();
	delete[] text;

	// Update node aliases
	infostream<<"- Updating node aliases"<<std::endl;
	text = wgettext("Initializing nodes...");
	draw_load_screen(text, device, guienv, 0, 72);
	m_nodedef->updateAliases(m_itemdef);
	std::string texture_path = g_settings->get("texture_path");
	if (texture_path != "" && fs::IsDir(texture_path))
		m_nodedef->applyTextureOverrides(texture_path + DIR_DELIM + "override.txt");
	m_nodedef->setNodeRegistrationStatus(true);
	m_nodedef->runNodeResolveCallbacks();
	delete[] text;

	if (!headless_optimize) {
	// Update node textures and assign shaders to each tile
	infostream<<"- Updating node textures"<<std::endl;
	TextureUpdateArgs tu_args;
	tu_args.device = device;
	tu_args.guienv = guienv;
	tu_args.last_time_ms = getTimeMs();
	tu_args.last_percent = 0;
	tu_args.text_base =  wgettext("Initializing nodes");
	m_nodedef->updateTextures(this, texture_update_progress, &tu_args);
	delete[] tu_args.text_base;
	}

	// Preload item textures and meshes if configured to
	if(!headless_optimize && g_settings->getBool("preload_item_visuals"))
	{
		verbosestream<<"Updating item textures and meshes"<<std::endl;
		text = wgettext("Item textures...");
		draw_load_screen(text, device, guienv, 0, 0);
		std::set<std::string> names = m_itemdef->getAll();
		size_t size = names.size();
		size_t count = 0;
		int percent = 0;
		for(std::set<std::string>::const_iterator
				i = names.begin(); i != names.end(); ++i)
		{
			// Asking for these caches the result
			m_itemdef->getInventoryTexture(*i, this);
			m_itemdef->getWieldMesh(*i, this);
			count++;
			percent = (count * 100 / size * 0.2) + 80;
			draw_load_screen(text, device, guienv, 0, percent);
		}
		delete[] text;
	}

	if (!headless_optimize) {
	// Start mesh update thread after setting up content definitions
		auto threads = !g_settings->getBool("more_threads") ? 1 : (Thread::getNumberOfProcessors() - (m_simple_singleplayer_mode ? 3 : 1));
		infostream<<"- Starting mesh update threads = "<<threads<<std::endl;
		m_mesh_update_thread.start(threads < 1 ? 1 : threads);
	}

	m_state = LC_Ready;
	sendReady();
	text = wgettext("Done!");
	draw_load_screen(text, device, guienv, 0, 100);
	//infostream<<"Client::afterContentReceived() done"<<std::endl;
	delete[] text;
}
Ejemplo n.º 2
0
GUIChatConsole::GUIChatConsole(
		gui::IGUIEnvironment* env,
		gui::IGUIElement* parent,
		s32 id,
		ChatBackend* backend,
		Client* client
):
	IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
			core::rect<s32>(0,0,100,100)),
	m_chat_backend(backend),
	m_client(client),
	m_screensize(v2u32(0,0)),
	m_animate_time_old(0),
	m_open(false),
	m_close_on_return(false),
	m_height(0),
	m_desired_height(0),
	m_desired_height_fraction(0.0),
	m_height_speed(5.0),
	m_open_inhibited(0),
	m_cursor_blink(0.0),
	m_cursor_blink_speed(0.0),
	m_cursor_height(0.0),
	m_background(NULL),
	m_background_color(255, 0, 0, 0),
	m_font(NULL),
	m_fontsize(0, 0)
{
	m_animate_time_old = getTimeMs();

	// load background settings
	s32 console_alpha = g_settings->getS32("console_alpha");
	m_background_color.setAlpha(clamp_u8(console_alpha));

	// load the background texture depending on settings
	ITextureSource *tsrc = client->getTextureSource();
	if (tsrc->isKnownSourceImage("background_chat.jpg")) {
		m_background = tsrc->getTexture("background_chat.jpg");
		m_background_color.setRed(255);
		m_background_color.setGreen(255);
		m_background_color.setBlue(255);
	} else {
		v3f console_color = g_settings->getV3F("console_color");
		m_background_color.setRed(clamp_u8(myround(console_color.X)));
		m_background_color.setGreen(clamp_u8(myround(console_color.Y)));
		m_background_color.setBlue(clamp_u8(myround(console_color.Z)));
	}

	m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono);

	if (m_font == NULL)
	{
		errorstream << "GUIChatConsole: Unable to load mono font ";
	}
	else
	{
		core::dimension2d<u32> dim = m_font->getDimension(L"M");
		m_fontsize = v2u32(dim.Width, dim.Height);
		m_font->grab();
	}
	m_fontsize.X = MYMAX(m_fontsize.X, 1);
	m_fontsize.Y = MYMAX(m_fontsize.Y, 1);

	// set default cursor options
	setCursor(true, true, 2.0, 0.1);
}
Ejemplo n.º 3
0
void Game::updateInput( float dt )
{
    if (m_level)
        m_level->updateInput(dt);

    m_mouse->capture();
    m_keyboard->capture();

    if (isKeyDown(OIS::KC_ESCAPE))
        m_exit = true;

    if (isKeyDown(OIS::KC_S))
        movePlayer(-1.0f, 0.0f, dt);
    if (isKeyDown(OIS::KC_W))
        movePlayer(1.0f, 0.0f, dt);
    if (isKeyDown(OIS::KC_A))
        movePlayer(0.0f, -1.0f, dt);
    if (isKeyDown(OIS::KC_D))
        movePlayer(0.0f, 1.0f, dt);

    m_playerCam->update(dt, (float)m_mouse->getMouseState().X.rel, (float)m_mouse->getMouseState().Y.rel);

    if (isKeyDown(OIS::KC_F1))
    {
        FILE* file = fopen("player.txt", "wt");
        mkVec3 v = m_playerCam->getPosition();
        fprintf(file, "%.4ff, %.4ff, %.4ff", v.x, v.y, v.z);
        fclose(file);
    }

    if (isKeyDown(OIS::KC_F2) && !m_freelook)
    {
        mkVec3 pos = m_playerCam->getPosition();
        delete m_playerCam;
        m_playerCam = new CameraFPP(m_ogreCamera, getCurrentLevel()->getPlayer());
        m_playerCam->setTarget(getCurrentLevel()->getPlayer());
        m_playerCam->setTarget(NULL);

        m_freelook = true;
    }
    else if (isKeyDown(OIS::KC_F3) && m_freelook)
    {
        m_freelook = false;

        delete m_playerCam;
        m_playerCam = new CameraTPP(m_ogreCamera, getCurrentLevel()->getPlayer());
    }

    if (isKeyDown(OIS::KC_F5))
        s_EnableBulletDebugDraw = !isKeyDown(OIS::KC_LCONTROL);

    if (isKeyDown(OIS::KC_L))
    {
        if (s_ForceLowFramerate && isKeyDown(OIS::KC_LSHIFT))
            s_ForceLowFramerate = false;
        else if (!s_ForceLowFramerate && isKeyDown(OIS::KC_LCONTROL))
            s_ForceLowFramerate = true;
    }
    
    if (isKeyDown(OIS::KC_F9))
        m_pauseUpdates = true;
    else if (isKeyDown(OIS::KC_F10))
        m_pauseUpdates = false;

    if (isKeyDown(OIS::KC_F11))
        m_slomo = 10.f;
    else if (isKeyDown(OIS::KC_F12))
        m_slomo = 1.f;

    static float s_lastDbgAnimInput = -1.f;
    if (isKeyDown(OIS::KC_LCONTROL) && (getTimeMs() - s_lastDbgAnimInput) > 200.f && getCurrentLevel() && getCurrentLevel()->getPlayer())
    {
        if (isKeyDown(OIS::KC_Z))
        {
            getCurrentLevel()->getPlayer()->dbgPrevAnimPreview();
            getCurrentLevel()->getPlayer()->dbgPlayAnimPreview();

            s_lastDbgAnimInput = getTimeMs();
        }

        if (isKeyDown(OIS::KC_C))
        {
            getCurrentLevel()->getPlayer()->dbgNextAnimPreview();
            getCurrentLevel()->getPlayer()->dbgPlayAnimPreview();

            s_lastDbgAnimInput = getTimeMs();
        }

        if (isKeyDown(OIS::KC_X))
        {
            getCurrentLevel()->getPlayer()->dbgPlayAnimPreview();

            s_lastDbgAnimInput = getTimeMs();
        }
    }
}
Ejemplo n.º 4
0
void Client::afterContentReceived(IrrlichtDevice *device)
{
	infostream<<"Client::afterContentReceived() started"<<std::endl;
	assert(m_itemdef_received); // pre-condition
	assert(m_nodedef_received); // pre-condition
	assert(mediaReceived()); // pre-condition

	const wchar_t* text = wgettext("Loading textures...");

	// Clear cached pre-scaled 2D GUI images, as this cache
	// might have images with the same name but different
	// content from previous sessions.
	guiScalingCacheClear(device->getVideoDriver());

	// Rebuild inherited images and recreate textures
	infostream<<"- Rebuilding images and textures"<<std::endl;
	draw_load_screen(text,device, guienv, 0, 70);
	m_tsrc->rebuildImagesAndTextures();
	delete[] text;

	// Rebuild shaders
	infostream<<"- Rebuilding shaders"<<std::endl;
	text = wgettext("Rebuilding shaders...");
	draw_load_screen(text, device, guienv, 0, 71);
	m_shsrc->rebuildShaders();
	delete[] text;

	// Update node aliases
	infostream<<"- Updating node aliases"<<std::endl;
	text = wgettext("Initializing nodes...");
	draw_load_screen(text, device, guienv, 0, 72);
	m_nodedef->updateAliases(m_itemdef);
	std::string texture_path = g_settings->get("texture_path");
	if (texture_path != "" && fs::IsDir(texture_path))
		m_nodedef->applyTextureOverrides(texture_path + DIR_DELIM + "override.txt");
	m_nodedef->setNodeRegistrationStatus(true);
	m_nodedef->runNodeResolveCallbacks();
	delete[] text;

	// Update node textures and assign shaders to each tile
	infostream<<"- Updating node textures"<<std::endl;
	TextureUpdateArgs tu_args;
	tu_args.device = device;
	tu_args.guienv = guienv;
	tu_args.last_time_ms = getTimeMs();
	tu_args.last_percent = 0;
	tu_args.text_base =  wgettext("Initializing nodes");
	m_nodedef->updateTextures(this, texture_update_progress, &tu_args);
	delete[] tu_args.text_base;

	// Start mesh update thread after setting up content definitions
	infostream<<"- Starting mesh update thread"<<std::endl;
	m_mesh_update_thread.start();

	m_state = LC_Ready;
	sendReady();
	text = wgettext("Done!");
	draw_load_screen(text, device, guienv, 0, 100);
	infostream<<"Client::afterContentReceived() done"<<std::endl;
	delete[] text;
}
Ejemplo n.º 5
0
void OUTLOG(INTERFACE_LOG& outLog, uint32_t stat)
{
    outLog.setStat(stat);
    outputLog(Info, "%lu|%s|%lx|%u|%u|%s|%s|2|%u||||||%u", getTimeMs(), ip2str(outLog.ip), outLog.uid64, outLog.uid, outLog.requestId, outLog.module, outLog.interface, stat, outLog.towardId);
}
Ejemplo n.º 6
0
void INLOG(INTERFACE_LOG& inLog)
{
    outputLog(Info, "%lu|%s|%lx|%u|%u|%s|%s|1|0||||||%u", getTimeMs(), ip2str(inLog.ip), inLog.uid64,  inLog.uid, inLog.requestId, inLog.module, inLog.interface, inLog.towardId);
}
Ejemplo n.º 7
0
GUIChatConsole::GUIChatConsole(
		gui::IGUIEnvironment* env,
		gui::IGUIElement* parent,
		s32 id,
		ChatBackend* backend,
		Client* client
):
	IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
			core::rect<s32>(0,0,100,100)),
	m_chat_backend(backend),
	m_client(client),
	m_screensize(v2u32(0,0)),
	m_animate_time_old(0),
	m_open(false),
	m_height(0),
	m_desired_height(0),
	m_desired_height_fraction(0.0),
	m_height_speed(5.0),
	m_open_inhibited(0),
	m_cursor_blink(0.0),
	m_cursor_blink_speed(0.0),
	m_cursor_height(0.0),
	m_background(NULL),
	m_background_color(255, 0, 0, 0),
	m_font(NULL),
	m_fontsize(0, 0),
	m_freetype_font(NULL)
{
	m_animate_time_old = getTimeMs();

	// load background settings
	bool console_color_set = !g_settings->get("console_color").empty();
	s32 console_alpha = g_settings->getS32("console_alpha");

	// load the background texture depending on settings
	m_background_color.setAlpha(clamp_u8(console_alpha));
	if (console_color_set)
	{
		v3f console_color = g_settings->getV3F("console_color");
		m_background_color.setRed(clamp_u8(myround(console_color.X)));
		m_background_color.setGreen(clamp_u8(myround(console_color.Y)));
		m_background_color.setBlue(clamp_u8(myround(console_color.Z)));
	}
	else
	{
		m_background = env->getVideoDriver()->getTexture(getTexturePath("background_chat.jpg").c_str());
		m_background_color.setRed(255);
		m_background_color.setGreen(255);
		m_background_color.setBlue(255);
	}

	// load the font
	// FIXME should a custom texture_path be searched too?
	std::string font_name = g_settings->get("mono_font_path");
	#if USE_FREETYPE
	m_use_freetype = g_settings->getBool("freetype");
	if (m_use_freetype) {
		u16 font_size = g_settings->getU16("mono_font_size");
		m_freetype_font = gui::CGUITTFont::createTTFont(env, font_name.c_str(), font_size);
		m_font = m_freetype_font;
	} else {
		m_font = env->getFont(font_name.c_str());
	}
	#else
	m_font = env->getFont(font_name.c_str());
	#endif
	if (m_font == NULL)
	{
		dstream << "Unable to load font: " << font_name << std::endl;
	}
	else
	{
		core::dimension2d<u32> dim = m_font->getDimension(L"M");
		m_fontsize = v2u32(dim.Width, dim.Height);
		dstream << "Font size: " << m_fontsize.X << " " << m_fontsize.Y << std::endl;
	}
	m_fontsize.X = MYMAX(m_fontsize.X, 1);
	m_fontsize.Y = MYMAX(m_fontsize.Y, 1);

	// set default cursor options
	setCursor(true, true, 2.0, 0.1);
}
Ejemplo n.º 8
0
// --------------------------------------------
// --------------------------------------------
void onRadioRecv(void)
{
    static bool flRxProcessing=false;
    if(flRxProcessing){
#ifdef PRINT_PACKETS
        PRINTF("RX Locked\n");
#endif
        return;
    }
    flRxProcessing=true;    // There is a chance for a small race condition

#ifdef PRINT_PACKETS
    uint32_t rxTime = getTimeMs();
#endif
    int16_t rxLen;
    rssi_t rssi;
    lqi_t lqi;

    rxIdx++;
    if( rxIdx < 0 ) rxIdx=0;


    led1Toggle();

    // rxLen = radioRecv( &(DB_REC(db)), DB_REC_SIZE(db));
    // DB_REC(db).recLen = rxLen;
    rxLen = radioRecv(&radioBuffer, sizeof(radioBuffer));
    rssi = radioGetLastRSSI();
    lqi = radioGetLastLQI();

#ifdef PRINT_PACKETS
    PRINTF("%d\t%d\t%d\t%d\t%ld\t", (int)rxIdx, (int)rxLen, (int)rssi, (int)lqi, (long)rxTime);
#endif
#ifdef PRINT_PACKETS
    if (rxLen < 0) {
        PRINTF("RX failed\n");
    }
    else if (rxLen > 0 ) {
        debugHexdump((uint8_t *) &radioBuffer, rxLen);
        // debugHexdump((uint8_t *) &(DB_REC(db)), rxLen);
    }
#endif
    if (rxLen < 0) {
        led2Toggle();
        flRxProcessing=false;
        return;
    }

    if( ! MSG_SIGNATURE_OK(radioBuffer) ) { flRxProcessing = false; return; }

    // Anticipated payload types.
    MSG_NEW_PAYLOAD_PTR(radioBuffer, phaser_ping_t, test_data_p);
    MSG_NEW_PAYLOAD_PTR(radioBuffer, phaser_control_t, ctrl_data_p);
    MSG_NEW_PAYLOAD_PTR(radioBuffer, msg_text_data_t, msg_text_p);
    MSG_NEW_PAYLOAD_PTR(radioBuffer, test_config_t, test_config_p);

    int act = MSG_ACT_CLEAR;
    bool flOK=true;

    switch( radioBuffer.id ){
    case PH_MSG_Test:
        MSG_CHECK_FOR_PAYLOAD(radioBuffer, phaser_ping_t, flOK=false );
        if( !flOK ){
            PRINTF("BadChk\n");
            break;
        }
        // Check if new experiment iteration started.
        if(lastExpIdx != test_data_p->expIdx && curExp){
            sendTestResults();
        }
        processTestMsg(test_data_p, rssi, lqi);
        break;
    
    case PH_MSG_Angle:
        if(curExp) sendTestResults();
        if( flRestart ){        // Best time to resend the restart message after the angle change
            send_ctrl_msg(MSG_ACT_RESTART);
            flRestart = false;
        }
        break;

    case PH_MSG_Control:
        MSG_CHECK_FOR_PAYLOAD(radioBuffer, phaser_control_t, break);
        if(curExp) sendTestResults();

        act = ctrl_data_p->action;
        if(act == MSG_ACT_START ){
            flRestart = false;  // Clear restart command attempt
        }
        printAction(act);
        break;

    case PH_MSG_Text:
        MSG_CHECK_FOR_PAYLOAD(radioBuffer, msg_text_data_t, break );
        PRINTF(msg_text_p->text);
        PRINTF("\n");
        break;

    case PH_MSG_Config:
        MSG_CHECK_FOR_PAYLOAD(radioBuffer, test_config_t, break );
        PRINTF("Config received:\n");
        // TODO: parse the config and print
        print_test_config(test_config_p);
    }


    flRxProcessing=false;
}
Ejemplo n.º 9
0
bool GUITable::OnEvent(const SEvent &event)
{
	if (!isEnabled())
		return IGUIElement::OnEvent(event);

	if (event.EventType == EET_KEY_INPUT_EVENT) {
		if (event.KeyInput.PressedDown && (
				event.KeyInput.Key == KEY_DOWN ||
				event.KeyInput.Key == KEY_UP   ||
				event.KeyInput.Key == KEY_HOME ||
				event.KeyInput.Key == KEY_END  ||
				event.KeyInput.Key == KEY_NEXT ||
				event.KeyInput.Key == KEY_PRIOR)) {
			s32 offset = 0;
			switch (event.KeyInput.Key) {
				case KEY_DOWN:
					offset = 1;
					break;
				case KEY_UP:
					offset = -1;
					break;
				case KEY_HOME:
					offset = - (s32) m_visible_rows.size();
					break;
				case KEY_END:
					offset = m_visible_rows.size();
					break;
				case KEY_NEXT:
					offset = AbsoluteRect.getHeight() / m_rowheight;
					break;
				case KEY_PRIOR:
					offset = - (s32) (AbsoluteRect.getHeight() / m_rowheight);
					break;
				default:
					break;
			}
			s32 old_selected = m_selected;
			s32 rowcount = m_visible_rows.size();
			if (rowcount != 0) {
				m_selected = rangelim(m_selected + offset, 0, rowcount-1);
				autoScroll();
			}

			if (m_selected != old_selected)
				sendTableEvent(0, false);

			return true;
		}
		else if (event.KeyInput.PressedDown && (
				event.KeyInput.Key == KEY_LEFT ||
				event.KeyInput.Key == KEY_RIGHT)) {
			// Open/close subtree via keyboard
			if (m_selected >= 0) {
				int dir = event.KeyInput.Key == KEY_LEFT ? -1 : 1;
				toggleVisibleTree(m_selected, dir, true);
			}
			return true;
		}
		else if (!event.KeyInput.PressedDown && (
				event.KeyInput.Key == KEY_RETURN ||
				event.KeyInput.Key == KEY_SPACE)) {
			sendTableEvent(0, true);
			return true;
		}
		else if (event.KeyInput.Key == KEY_ESCAPE ||
				event.KeyInput.Key == KEY_SPACE) {
			// pass to parent
		}
		else if (event.KeyInput.PressedDown && event.KeyInput.Char) {
			// change selection based on text as it is typed
			s32 now = getTimeMs();
			if (now - m_keynav_time >= 500)
				m_keynav_buffer = L"";
			m_keynav_time = now;

			// add to key buffer if not a key repeat
			if (!(m_keynav_buffer.size() == 1 &&
					m_keynav_buffer[0] == event.KeyInput.Char)) {
				m_keynav_buffer.append(event.KeyInput.Char);
			}

			// find the selected item, starting at the current selection
			// don't change selection if the key buffer matches the current item
			s32 old_selected = m_selected;
			s32 start = MYMAX(m_selected, 0);
			s32 rowcount = m_visible_rows.size();
			for (s32 k = 1; k < rowcount; ++k) {
				s32 current = start + k;
				if (current >= rowcount)
					current -= rowcount;
				if (doesRowStartWith(getRow(current), m_keynav_buffer)) {
					m_selected = current;
					break;
				}
			}
			autoScroll();
			if (m_selected != old_selected)
				sendTableEvent(0, false);

			return true;
		}
	}
	if (event.EventType == EET_MOUSE_INPUT_EVENT) {
		core::position2d<s32> p(event.MouseInput.X, event.MouseInput.Y);

		if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) {
			m_scrollbar->setPos(m_scrollbar->getPos() +
					(event.MouseInput.Wheel < 0 ? -3 : 3) *
					- (s32) m_rowheight / 2);
			return true;
		}

		// Find hovered row and cell
		bool really_hovering = false;
		s32 row_i = getRowAt(p.Y, really_hovering);
		const Cell *cell = NULL;
		if (really_hovering) {
			s32 cell_j = getCellAt(p.X, row_i);
			if (cell_j >= 0)
				cell = &(getRow(row_i)->cells[cell_j]);
		}

		// Update tooltip
		setToolTipText(cell ? m_strings[cell->tooltip_index].c_str() : L"");

		if (event.MouseInput.isLeftPressed() &&
				(isPointInside(p) ||
				 event.MouseInput.Event == EMIE_MOUSE_MOVED)) {
			s32 sel_column = 0;
			bool sel_doubleclick = (event.MouseInput.Event
					== EMIE_LMOUSE_DOUBLE_CLICK);
			bool plusminus_clicked = false;

			// For certain events (left click), report column
			// Also open/close subtrees when the +/- is clicked
			if (cell && (
					event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN ||
					event.MouseInput.Event == EMIE_LMOUSE_DOUBLE_CLICK ||
					event.MouseInput.Event == EMIE_LMOUSE_TRIPLE_CLICK)) {
				sel_column = cell->reported_column;
				if (cell->content_type == COLUMN_TYPE_TREE)
					plusminus_clicked = true;
			}

			if (plusminus_clicked) {
				if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
					toggleVisibleTree(row_i, 0, false);
				}
			}
			else {
				// Normal selection
				s32 old_selected = m_selected;
				m_selected = row_i;
				autoScroll();

				if (m_selected != old_selected ||
						sel_column >= 1 ||
						sel_doubleclick) {
					sendTableEvent(sel_column, sel_doubleclick);
				}
			}
		}
		return true;
	}
	if (event.EventType == EET_GUI_EVENT &&
			event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED &&
			event.GUIEvent.Caller == m_scrollbar) {
		// Don't pass events from our scrollbar to the parent
		return true;
	}

	return IGUIElement::OnEvent(event);
}
Ejemplo n.º 10
0
 uint64_t getTime() override {
   return getTimeMs();
 }
Ejemplo n.º 11
0
int main(int argc, char** argv)
{
	int args = 1;
#ifdef USE_OPENCL
	if (argc < 10) {
#else
	if (argc < 7) {
#endif
		std::cout << "Not enough arguments" << std::endl;
		system("pause");
		return 1;
	}

	DIM = util::toInt(argv[args++]);
	N = util::toInt(argv[args++]);
	K = util::toInt(argv[args++]);
	ITERATIONS = util::toInt(argv[args++]);
	RUNS = util::toInt(argv[args++]);
#ifdef USE_OPENCL
	AM_LWS = util::toInt(argv[args++]);
	RP_LWS = util::toInt(argv[args++]);
	CT_LWS = util::toInt(argv[args++]);

	USE_ALL_DEVICES = util::toInt(argv[args++]);
#else
	device_count = util::toInt(argv[args++]);
#endif


	std::cout << "DIM = " << DIM << std::endl;
	std::cout << "N = " << N << std::endl;
	std::cout << "K = " << K << std::endl;
	std::cout << "ITERATIONS = " << ITERATIONS << std::endl;
	std::cout << "RUNS = " << RUNS << std::endl;
#ifdef USE_OPENCL
	std::cout << "AM_LWS = " << AM_LWS << std::endl;
	std::cout << "RP_LWS = " << RP_LWS << std::endl;
	std::cout << "CT_LWS = " << CT_LWS << std::endl;
	std::cout << "USE_ALL_DEVICES = " << USE_ALL_DEVICES << std::endl << std::endl;
#else
	std::cout << "device_count = " << device_count << std::endl << std::endl;
#endif


#ifdef _WIN32
	rng.seed();
	srand(GetTickCount());
#else
	rng.seed();
	srand(getTimeMs());
#endif

	u = boost::uniform_real<float>(0.0f, 1000000.0f);
	gen = new boost::variate_generator<boost::mt19937&, boost::uniform_real<float> >(rng, u);

#ifdef USE_OPENCL
	cl_int clError = CL_SUCCESS;
	initCL();

	for (int i = 0; i < clDevices.size(); ++i) {

		clInputBuf.push_back(cl::Buffer(clContext, CL_MEM_READ_ONLY, N * DIM * sizeof(float), NULL, &clError));
		if (clError != CL_SUCCESS) std::cout << "OpenCL Error: Could not create buffer" << std::endl;

		clCentroidBuf.push_back(cl::Buffer(clContext, CL_MEM_READ_WRITE, K * DIM * sizeof(float), NULL, &clError));
		if (clError != CL_SUCCESS) std::cout << "OpenCL Error: Could not create buffer" << std::endl;

		clMappingBuf.push_back(cl::Buffer(clContext, CL_MEM_READ_WRITE, N * sizeof(int), NULL, &clError));
		if (clError != CL_SUCCESS) std::cout << "OpenCL Error: Could not create buffer" << std::endl;

		clReductionBuf.push_back(cl::Buffer(clContext, CL_MEM_WRITE_ONLY, N * sizeof(float), NULL, &clError));
		if (clError != CL_SUCCESS) std::cout << "OpenCL Error: Could not create buffer" << std::endl;

		clClusterAssignment[i].setArgs(clInputBuf[i](), clCentroidBuf[i](), clMappingBuf[i]());
		clClusterReposition[i].setArgs(clInputBuf[i](), clMappingBuf[i](), clCentroidBuf[i]());
		clClusterReposition_k[i].setArgs(clInputBuf[i](), clMappingBuf[i](), clCentroidBuf[i]());
		//clClusterReposition_k_c[i].setArgs(clInputBuf[i](), clMappingBuf[i](), clCentroidBuf[i](), clConvergedBuf[i]());
		clComputeCost[i].setArgs(clInputBuf[i](), clCentroidBuf[i](), clMappingBuf[i](), clReductionBuf[i]());

	}

	device_count = clDevices.size();
#endif

	util::Clock clock;
	clock.reset();

	for (int i = 0; i < RUNS; ++i) {
		mapping_list.push_back(NULL);
		centroids_list.push_back(NULL);
		cost_list.push_back(0.0f);
	}

	float* source = new float[N*DIM];
	for (int i = 0; i < N*DIM; ++i)
		source[i] = gen_random_float();

	input_list.push_back(source);

	for (int i = 1; i < device_count; ++i) {
		float* copy = new float[N*DIM];
		memcpy(copy, source, N*DIM*sizeof(float));
		input_list.push_back(copy);
	}

	if (device_count > 1) {
		boost::thread_group threads;

		for (int i = 0; i < device_count; ++i) {
			threads.create_thread(boost::bind(exec, i, true));
		}

		threads.join_all();
	} else {
		exec(0, false);
	}

#ifdef USE_OPENCL
	reduction_group.join_all();
#endif

	int best_result = 0;
	float best_cost = std::numeric_limits<float>::max();
	for (int i = 0; i < RUNS; ++i) {
		if (cost_list[i] < best_cost) {
			best_cost = cost_list[i];
			best_result = i;
		}
	}

	FILE *out_fdesc = fopen("centroids.out", "wb");
	fwrite((void*)centroids_list[best_result], K * DIM * sizeof(float), 1, out_fdesc);
	fclose(out_fdesc);

	out_fdesc = fopen("mapping.out", "wb");
	fwrite((void*)mapping_list[best_result], N * sizeof(int), 1, out_fdesc);
	fclose(out_fdesc);

	std::cout << "Best result is " << best_result << std::endl;

	for (int i = 0; i < device_count; ++i) {
		delete[] input_list[i];
	}

	for (int i = 0; i < RUNS; ++i) {
		delete[] mapping_list[i];
		delete[] centroids_list[i];
	}

	float now = clock.get();
	std::cout << "Total: " << now << std::endl;

	system("pause");

	return 0;
}
Ejemplo n.º 12
0
u32 TimeTaker::getTime()
{
	u32 time2 = getTimeMs();
	u32 dtime = time2 - m_time1;
	return dtime;
}
Ejemplo n.º 13
0
long QQuizTimeCounter::elapsedTime() {
    return getTimeMs() - mStartTime;
}
Ejemplo n.º 14
0
void QQuizTimeCounter::stop() {
    mEndTime = getTimeMs();

    timer->stop();
}
Ejemplo n.º 15
0
void QQuizTimeCounter::start() {
    mStartTime = getTimeMs();

    timer->start();
}