Exemplo n.º 1
0
void World::readWaterIndex() {
	//filepath for the object file
	stringw path = WATER_INDEX;
	//the only tag in this file is the object tag to define a new object
	const stringw object("water");
	//initialize an XML reader
	io::IXMLReader* reader = Client::device->getFileSystem()->createXMLReader(path);

	//start the reading loop
	while (reader->read()) {
		  switch (reader->getNodeType()) {
			  //we found a new element
              case irr::io::EXN_ELEMENT:
				  //new <object> tag
				  if (object.equals_ignore_case(reader->getNodeName())) {
					  u16 id = reader->getAttributeValueAsInt(L"id");
					  u16 x = reader->getAttributeValueAsInt(L"x");
					  u16 y = reader->getAttributeValueAsInt(L"y");
					  u16 w = reader->getAttributeValueAsInt(L"w");
					  u16 l = reader->getAttributeValueAsInt(L"l");
					  float h = reader->getAttributeValueAsFloat(L"height");
					  water_index.push_back(WaterData(id, x, y,  w, l, h));
					  cout << "Water loaded " << id << " " << x << " " << y << " " << w << " " << l << " " << h << endl;
				  }
				  break;
		  }
	}

	//drop the xml reader
	reader->drop();
}
// Execute Console Event
void ConsoleState::executeConsoleEvent(stringw val)
{
	val.make_lower();

	if(val=="statelog")
	{	_coreApp->addLogItem(val); _coreApp->toggleStateLog();	}
	else if(val=="debugmode")
	{	_coreApp->addLogItem(val); _coreApp->toggleDebugMode(); }
	else if(val=="exit")
	{	_coreApp->exitApplication();	}
	else if(val.subString(0,4) == "exec")
	{	
		_coreApp->addLogItem(val);

		irr::core::stringc stateRef = val.subString(5,val.size()-5);

		if(stateRef == "mainmenu")
		{
			_coreApp->addLogItem("@Main Menu State - Added to Stack");
			_coreApp->getStateManager()->add(new MainMenuState(_coreApp));
		}
	}
	else
	{	_coreApp->addLogItem("[ERROR] Unknown Command");	}

	_coreApp->getInputManager()->resetString();
}
Exemplo n.º 3
0
void World::readWalkableObjectIndex() {

	//std::cout << "Loaidng objects that are walkable: " << endl;

	//filepath for the object file
	stringw path = WALK_OBJECT_INDEX;
	//the only tag in this file is the object tag to define a new object
	const stringw object("objectWalkable");
	//initialize an XML reader
	io::IXMLReader* reader = Client::device->getFileSystem()->createXMLReader(path);

	//start the reading loop
	while (reader->read()) {
		switch (reader->getNodeType()) {
			//we found a new element
		case irr::io::EXN_ELEMENT:
			//new <object> tag
			if (object.equals_ignore_case(reader->getNodeName())) {
				u16 id = reader->getAttributeValueAsInt(L"id");
				u16 x = reader->getAttributeValueAsInt(L"x");
				u16 y = reader->getAttributeValueAsInt(L"y");
				u16 f = reader->getAttributeValueAsInt(L"f");
				u16 h = reader->getAttributeValueAsInt(L"h");
				object_walkable_index.push_back(ObjectWalkableData(id, x, y, f, h));
				//cout << "object loaded: " << id << " " << x << " " << y << " " << f << endl;
			}
			break;
		}
	}

	//drop the xml reader
	reader->drop();
}
Exemplo n.º 4
0
// ----------------------------------------------------------------------------
void Editor::writeResAndExePathIntoConfig()
{
    stringc p;
    IFileSystem* file_system = m_device->getFileSystem();
    IXMLReader*  xml_reader = file_system->createXMLReader(m_config_loc + "/config.xml");
    if (xml_reader)
    {
        const stringw node_name(L"data_dir");
        while (xml_reader->read())
        {
            if (xml_reader->getNodeType() == EXN_ELEMENT
                && node_name.equals_ignore_case(xml_reader->getNodeName()))
            {
                p = xml_reader->getAttributeValueSafe(L"path");
            }
        }
        xml_reader->drop();
    }

    std::ofstream f;
    f.open((m_config_loc + "/config.xml").c_str());
    f << "<config>\n";
    f << "  <data_dir path=\"" << p.c_str() << "\" />\n";

    if (!m_exe_loc.empty())
        f << "  <exe path=\"" << m_exe_loc.c_str() << "\" />\n";

    f << "  <res x=\"" << m_screen_size.Width << "\" y=\"";
    f << m_screen_size.Height << "\" />\n";
    f << "</config>\n";
    f.close();

} // writeResAndExePathIntoConfig
Exemplo n.º 5
0
bool CGWIC_Cell::LoadObjectStates()
{
	path filenm = GWIC_CELLSTORE_DIR;
	filenm += GetCellFileSuffix();
	filenm += ".xml";
	IXMLReader* xml = graphics->getFileSystem()->createXMLReader(filenm);
	if (!xml) {
		std::cerr << "LoadObjectStates(): can't create xml reader for " << filenm.c_str() << std::endl;
		return false;
	}
	const stringw tg_obj(L"object");
	const stringw tg_pos(L"position");
	const stringw tg_opt(L"options");
	stringw cur_tag;
	path cfile;
	CIrrStrParser pos,rot,scl;
	CGWIC_GameObject* optr = NULL;
	while (xml->read()) {
		switch (xml->getNodeType()) {
		case EXN_ELEMENT:
			if ((cur_tag.empty()) && (tg_obj.equals_ignore_case(xml->getNodeName()))) {
				cur_tag = tg_obj;
				cfile = xml->getAttributeValueSafe(L"file");
				optr = new CGWIC_GameObject(cfile,GetCoord(),graphics,physics);
				if (!optr)
					std::cerr << "Failed to create object from " << cfile.c_str() << std::endl;
				else
					objects.push_back(optr);
			} else if ((cur_tag == tg_obj) && (optr)) {
				if (tg_pos.equals_ignore_case(xml->getNodeName())) {
					pos = xml->getAttributeValueSafe(L"pos");
					rot = xml->getAttributeValueSafe(L"rot");
					scl = xml->getAttributeValueSafe(L"scale");
					optr->SetPos(pos.ToVector3f());
					optr->SetScale(scl.ToVector3f());
					optr->SetRot(rot.ToVector3f());
				} else if (tg_pos.equals_ignore_case(xml->getNodeName())) {
					optr->SetPhysical(xml->getAttributeValueAsInt(L"physical"));
					optr->SetEnabled(xml->getAttributeValueAsInt(L"enabled"));
				}
			}
			break;
		case EXN_ELEMENT_END:
			cur_tag = L"";
			optr = NULL;
			break;
		default: break;
		}
	}
	xml->drop();
	return false;
}
Exemplo n.º 6
0
//Display a ingame question
bool GUIGame::showDialogQuestion(stringw text, std::string sound )
{

	IGUIStaticText* txt_dialog=(IGUIStaticText*)GUIManager::getInstance()->getGUIElement(GUIManager::TXT_ID_DIALOG);
	IGUIButton* guiBtDialogCancel=(IGUIButton*)GUIManager::getInstance()->getGUIElement(GUIManager::BT_ID_DIALOG_CANCEL);
	//Pause the player during the dialog opening
	DynamicObjectsManager::getInstance()->getPlayer()->setAnimation("idle");

	//stringw text2 = (stringw)text.c_str();
	txt_dialog->setText(text.c_str());
	if(!guiBtDialogCancel->isVisible())
		guiBtDialogCancel->setVisible(true);

	GUIManager::getInstance()->setWindowVisible(GUIManager::GCW_DIALOG,true);
	App::getInstance()->setAppState(App::APP_WAIT_DIALOG);

	//Play dialog sound (yes you can record voices!)
    dialogSound = NULL;

	if (sound.size()>0)
    //if((sound.c_str() != "") | (sound.c_str() != NULL))
    {
        stringc soundName = "../media/sound/";
        soundName += sound.c_str();
        dialogSound = SoundManager::getInstance()->playSound2D(soundName.c_str());
    }

	return true;
}
// -----------------------------------------------------------------------------
void IconButtonWidget::setLabel(const stringw& new_label)
{
    if (m_label == NULL) return;

    m_label->setText( new_label.c_str() );
    setLabelFont();
}
Exemplo n.º 8
0
	/*
		Add another icon which the user can click and select as cursor later on.
	*/
	void addIcon(const stringw& name, const SCursorSprite &sprite, bool addCursor=true)
	{
		// Sprites are just icons - not yet cursors. They can be displayed by Irrlicht sprite functions and be used to create cursors.
		SpriteBox->addItem(name.c_str(), sprite.SpriteId);
		Sprites.push_back(sprite);

		// create the cursor together with the icon?
		if ( addCursor )
		{
			/* Here we create a hardware cursor from a sprite */
			Device->getCursorControl()->addIcon(sprite);

			// ... and add it to the cursors selection listbox to the other system cursors.
			CursorBox->addItem(name.c_str());
		}
	}
Exemplo n.º 9
0
/**
 * Advanced constructor. Used for pickable items placed in container objects loaded from map files.
 */
CGameObject::CGameObject(stringw _root, s32 _id, IXMLReader* xml, IVideoDriver* driver)
{
	s32 position = _root.findLastChar(L"/",1);
	stringc _name = _root.subString(position+1,_root.size()-position);
	stringc _path = _root.subString(0,position+1);

	animations.clear();
	m_ListOfAbilities_Default.clear();
	m_ListOfSkills_Default.clear();
	m_ListOfTrajectoryPaths.clear();
	isAnimated = false;
	name = _name;
	path = _path;
	root = _name;
	id = _id;
	isContainer = false;
	isMonster = false;
	isAnchored = false;
	isNPC = false;
	isPickable = false;
	isArea = false;
	isTrigger = false;
	isInvisible = false;
	isIllusion = false;
	isStatic = false;
	isTerrain = false;
	isTile = false;
	isWall = false;
	hasTrajectoryPath = false;
	isTrajectoryNode = false;
	trajectoryParent = NULL;
	m_IconTexture = 0;
	description = L"No description specified";
	script = _name + ".script"; //default, but can be different
	icon = _name + ".png"; //default, but can be different
	m_Driver = driver;
	nameID = 0;
	trajectoryPathFile = "";

	if(xml)
	{
		LoadPropertiesFromXMLFile(xml);
		xml->drop();
	}
}
void OptionsScreenPlayers::onNewPlayerWithName(const stringw& newName)
{
    ListWidget* players = this->getWidget<ListWidget>("players");
    if (players != NULL)
    {
        core::stringc newNameC(newName.c_str());
        players->addItem( newNameC.c_str(), translations->fribidize(newName) );
    }
}
Exemplo n.º 11
0
//! Loads a config file
bool CConfigReader::Load( const stringw& filename ) 
{
    std::wifstream stream ( filename.c_str(), std::ios::in );
    
    bool success = Load( stream );
    
    stream.close();
    
    return success;
}
// -----------------------------------------------------------------------------
void IconButtonWidget::setLabel(stringw new_label)
{
    if (m_label == NULL) return;
    
    m_label->setText( new_label.c_str() );
    
    const bool word_wrap = (m_properties[PROP_WORD_WRAP] == "true");
    const int max_w = m_label->getAbsolutePosition().getWidth();
    
    if (!word_wrap &&
        (int)GUIEngine::getFont()->getDimension(new_label.c_str()).Width > max_w + 4) // arbitrarily allow for 4 pixels
    {
        m_label->setOverrideFont( GUIEngine::getSmallFont() );
    }
    else
    {
        m_label->setOverrideFont( NULL );
    }
}
Exemplo n.º 13
0
void Game::updateProgressBar(int newValue, stringw msg) {
    progBar->setVisible(false);
    progBar = env->addImage(rect<int>(0, (cfg_settings.WindowSize.Height-68), (cfg_settings.WindowSize.Width*newValue)/100, (cfg_settings.WindowSize.Height-20)));
    progBar->setImage(driver->getTexture("textures/bars/progressbar_bar_720.png"));
        progBar->setUseAlphaChannel(true);
    progText->setText(msg.c_str());
    driver->beginScene(true, true, SColor(0, 0, 0, 0));
    env->drawAll();
    driver->endScene();

    }
Exemplo n.º 14
0
// -----------------------------------------------------------------------------
void ChangePasswordDialog::submit()
{
    const stringw current_password = m_current_password_widget->getText().trim();
    const stringw new_password1 = m_new_password1_widget->getText().trim();
    const stringw new_password2 = m_new_password2_widget->getText().trim();
    if (current_password.size() < 8 || current_password.size() > 30)
    {
        sfx_manager->quickSound("anvil");
        m_info_widget->setErrorColor();
        m_info_widget->setText(_("Current password invalid."), false);
    }
    else if (new_password1.size() < 8 || new_password1.size() > 30)
    {
        sfx_manager->quickSound("anvil");
        m_info_widget->setErrorColor();
        m_info_widget->setText(_("Password has to be between 8 and 30 characters long!"), false);
    }
    else if (new_password1 != new_password2)
    {
        sfx_manager->quickSound("anvil");
        m_info_widget->setErrorColor();
        m_info_widget->setText(_("Passwords don't match!"), false);
    }
    else
    {
        m_options_widget->setDeactivated();
        m_info_widget->setDefaultColor();
        Online::CurrentUser::get()->requestPasswordChange(current_password, new_password1, new_password2);
    }
}
Exemplo n.º 15
0
// ----------------------------------------------------------------------------
void ChangePasswordDialog::submit()
{
    const stringw current_password = m_current_password_widget->getText().trim();
    const stringw new_password1 = m_new_password1_widget->getText().trim();
    const stringw new_password2 = m_new_password2_widget->getText().trim();

    if (current_password.size() < 8 || current_password.size() > 30)
    {
        sfx_manager->quickSound("anvil");
        m_info_widget->setErrorColor();
        m_info_widget->setText(_("Current password invalid."), false);
    }
    else if (new_password1.size() < 8 || new_password1.size() > 30)
    {
        sfx_manager->quickSound("anvil");
        m_info_widget->setErrorColor();
        m_info_widget->setText(_("Password has to be between 8 and 30 "
                                 "characters long!"),                   false);
    }
    else if (new_password1 != new_password2)
    {
        sfx_manager->quickSound("anvil");
        m_info_widget->setErrorColor();
        m_info_widget->setText(_("Passwords don't match!"), false);
    }
    else
    {
        m_options_widget->setDeactivated();
        m_info_widget->setDefaultColor();

        // We don't need to use password 2 anymore, it was already confirmed
        // that both passwords are identical.
        changePassword(current_password, new_password1);
    }
}   // submit
Exemplo n.º 16
0
void ZoneSoundLoader::readZonesFromFile(){

	m_firstRun = true; // dont remove this :) in here for good execution flow

	// clear the zone_index vector
	m_zone_index.clear();

	// read from .dat file which contains zone boundaries
	stringw reader_path = SOUND_INDEX;
	io::IXMLReader* reader = Client::device->getFileSystem()->createXMLReader(reader_path);

	const stringw zone("zone");

	// read through the zones
	while (reader->read()){

		switch (reader->getNodeType()) {
			// if new zone is found..
		case irr::io::EXN_ELEMENT:
			//new <object> tag
			if (zone.equals_ignore_case(reader->getNodeName())) {
				u16 id = reader->getAttributeValueAsInt(L"id");
				u16 x = reader->getAttributeValueAsInt(L"x");
				u16 z = reader->getAttributeValueAsInt(L"z");
				u16 tox = reader->getAttributeValueAsInt(L"tox");
				u16 toz = reader->getAttributeValueAsInt(L"toz");
				//stringw name = reader->getAttributeValue(L"name");
				const wchar_t* songName = reader->getAttributeValue(L"songName");
				const wchar_t* name = reader->getAttributeValue(L"name");
				wstring sN(songName);
				//std::cout << "Song name:" << endl;
				//std::wcout << sN.c_str() << endl;
				// push the object to a vector
				m_zone_index.push_back(ZoneData(id, x, z, tox, toz, name, songName));
			}
			break;
		}

	}
}
Exemplo n.º 17
0
/** Collects the data entered into the gui and submits a login request.
 *  The login request is processes asynchronously b the ReqeustManager.
 */
void LoginScreen::login()
{
    // Reset any potential error message shown.
    LabelWidget *info_widget = getWidget<LabelWidget>("info");
    info_widget->setDefaultColor();
    info_widget->setText("", false);

    const stringw username = getWidget<TextBoxWidget>("username")
                            ->getText().trim();
    const stringw password = getWidget<TextBoxWidget>("password")
                            ->getText().trim();

    if (username.size() < 4 || username.size() > 30 || 
        password.size() < 8 || password.size() > 30    )
    {
        sfx_manager->quickSound("anvil");
        info_widget->setErrorColor();
        info_widget->setText(_("Username and/or password too short or too long."),
                             false);
    }
    else
    {
        m_options_widget->setDeactivated();
        info_widget->setDefaultColor();
        bool remember = getWidget<CheckBoxWidget>("remember")->getState();
        Online::CurrentUser::get()->requestSignIn(username,password, 
                                                  remember           );
    }
}   // login
Exemplo n.º 18
0
void World::readClickableObjectIndex() {
	ObjectClickable oc;
	//filepath for the objects that are clickable file
	stringw path = CLICK_OBJECT_INDEX;
	//the only tag in this file is the object tag to define a new object
	const stringw object("object");
	//initialize an XML reader
	io::IXMLReader* reader = Client::device->getFileSystem()->createXMLReader(path);

	//start the reading loop
	while (reader->read()) {
		switch (reader->getNodeType()) {
			//we found a new element
		case irr::io::EXN_ELEMENT:
			//new <object> tag
			if (object.equals_ignore_case(reader->getNodeName())) {
				u16 id = reader->getAttributeValueAsInt(L"id");
				u16 x = reader->getAttributeValueAsInt(L"x");
				u16 y = reader->getAttributeValueAsInt(L"y");
				u16 f = reader->getAttributeValueAsInt(L"f");
				stringw m = oc.getMenuItemsList(id);

				//oc.addTriangleSelector();

				object_clickable_index.push_back(ObjectClickableData(id, x, y, f, m));
				cout << "CLICKABLE object loaded: " << id << " " << x << " " << y << " " << f << endl;
				//u16 height = reader->getAttributeValueAsInt(L"h");
				//object_walkable_index.push_back(ObjectWalkableData(id, x, y, f, height));
			}
			break;
		}
	}

	//drop the xml reader
	reader->drop();
}
Exemplo n.º 19
0
// ----------------------------------------------------------------------------
std::list<stringc> Editor::readRecentlyOpenedList()
{
    std::list<stringc> list;

    IFileSystem* file_system = m_device->getFileSystem();
    IXMLReader*  xml_reader = file_system->createXMLReader(m_config_loc + "/recent.xml");

    stringc s;
    if (xml_reader)
    {
        const stringw file(L"file");
        while (xml_reader->read())
        {
            if (xml_reader->getNodeType() == EXN_ELEMENT
                && file.equals_ignore_case(xml_reader->getNodeName()))
            {
                s  = xml_reader->getAttributeValueSafe(L"name");
                list.push_back(s);
            }
        }
        xml_reader->drop();
    }
    return list;
} // readRecentlyOpenedList
Exemplo n.º 20
0
// ----------------------------------------------------------------------------
void Editor::readConfigFile(IFileSystem* file_system)
{
    IXMLReader* xml_reader = file_system->createXMLReader(path(PHYSFS_getBaseDir())
                                                                    + "config.xml");

    if (!xml_reader)
    {
        path dir = PHYSFS_getUserDir();
        m_config_loc = dir + "/.stk-te";
        xml_reader = file_system->createXMLReader(m_config_loc + "/config.xml");
        if (!xml_reader)
        {
            PHYSFS_setWriteDir(dir.c_str());
            PHYSFS_mkdir(".stk-te");
            return;
        }
    }
    else m_config_loc = PHYSFS_getBaseDir();

    const stringw node_name(L"data_dir");
    const stringw res(L"res");
    const stringw exe(L"exe");
    while (xml_reader->read())
    {
        if (xml_reader->getNodeType() == EXN_ELEMENT)
        {
            if (res.equals_ignore_case(xml_reader->getNodeName()))
            {
                m_screen_size = dimension2du(
                    atol(((stringc)xml_reader->getAttributeValueSafe(L"x")).c_str()),
                    atol(((stringc)xml_reader->getAttributeValueSafe(L"y")).c_str()));
            }
            else  if (node_name.equals_ignore_case(xml_reader->getNodeName()))
            {
                m_data_loc = xml_reader->getAttributeValueSafe(L"path");
                m_icons_loc = m_data_loc + "editor/icons/";
            }
            else if (exe.equals_ignore_case(xml_reader->getNodeName()))
            {
                m_exe_loc = xml_reader->getAttributeValueSafe(L"path");
            }
        }
    }
    xml_reader->drop();
} // readConfigFile
void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& newName)
{
    bool slot_found = false;
    
    PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players;
    for (int n=0; n<players.size(); n++)
    {
        if (players[n].getName() == newName)
        {
            unlock_manager->setCurrentSlot(players[n].getUniqueID());
            unlock_manager->updateActiveChallengeList();
            slot_found = true;
            break;
        }
    }
    
    if (!slot_found)
    {
        fprintf(stderr, "[StoryModeLobbyScreen] ERROR: cannot find player corresponding to slot '%s'\n",
                core::stringc(newName.c_str()).c_str());
    }
    
    StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
}
Exemplo n.º 22
0
	/*
	Load xml from disk, overwrite default settings
	The xml we are trying to load has the following structure
	settings nested in sections nested in the root node, like so
	<pre>
		<?xml version="1.0"?>
		<mygame>
			<video>
				<setting name="driver" value="Direct3D9" />
				<setting name="fullscreen" value="0" />
				<setting name="resolution" value="1024x768" />
			</video>
		</mygame>
	</pre>
	*/
	bool load()
	{
		//if not able to create device don't attempt to load
		if (!NullDevice)
			return false;

		irr::io::IXMLReader* xml = NullDevice->getFileSystem()->createXMLReader(SettingsFile);	//create xml reader
		if (!xml)
			return false;

		const stringw settingTag(L"setting"); //we'll be looking for this tag in the xml
		stringw currentSection; //keep track of our current section
		const stringw videoTag(L"video"); //constant for videotag

		//while there is more to read
		while (xml->read())
		{
			//check the node type
			switch (xml->getNodeType())
			{
				//we found a new element
				case irr::io::EXN_ELEMENT:
				{
					//we currently are in the empty or mygame section and find the video tag so we set our current section to video
					if (currentSection.empty() && videoTag.equals_ignore_case(xml->getNodeName()))
					{
						currentSection = videoTag;
					}
					//we are in the video section and we find a setting to parse
					else if (currentSection.equals_ignore_case(videoTag) && settingTag.equals_ignore_case(xml->getNodeName() ))
					{
						//read in the key
						stringw key = xml->getAttributeValueSafe(L"name");
						//if there actually is a key to set
						if (!key.empty())
						{
							//set the setting in the map to the value,
							//the [] operator overrides values if they already exist or inserts a new key value
							//pair into the settings map if it was not defined yet
							SettingMap[key] = xml->getAttributeValueSafe(L"value");
						}
					}

					//..
					// You can add your own sections and tags to read in here
					//..
				}
				break;

				//we found the end of an element
				case irr::io::EXN_ELEMENT_END:
					//we were at the end of the video section so we reset our tag
					currentSection=L"";
				break;
			}
		}

		// don't forget to delete the xml reader
		xml->drop();

		return true;
	}
void CRaycastTankExample::createTank(const stringw file, const stringw collFile, const vector3df &pos, const f32 mass)
{
    IAnimatedMeshSceneNode *Node = device->getSceneManager()->addAnimatedMeshSceneNode(
        device->getSceneManager()->getMesh(file.c_str()));
	Node->setPosition(pos);
	//Node->setRotation(vector3df(-40,90,0));
	Node->setMaterialFlag(video::EMF_LIGHTING, true);
	//Node->setScale(vector3df(2,2,4));



	IGImpactMeshShape *shape = new IGImpactMeshShape(Node, device->getSceneManager()->getMesh(collFile.c_str()), mass);


	tank = world->addRigidBody(shape);

    // When using a raycast vehicle, we don't want this rigid body to deactivate.
	tank->setActivationState(EAS_DISABLE_DEACTIVATION);

    // Set some damping on the rigid body because the raycast vehicles tend to bounce a lot without a lot of tweaking.
    // (cheap fix for the example only)
	tank->setDamping(0.4, 0.4);

    // We create our vehicle, passing our newly created rigid body as a parameter.
	vehicle = world->addRaycastVehicle(tank);


    // Set up our wheel construction info. These values can be changed for each wheel,
    // and the values that you want to keep will stay the same, that way
    // all parameters for each wheel can stay the same for what needs to remain equal,
    // such as directions and suspension rest length.
    SWheelInfoConstructionInfo wheel;
    wheel.chassisConnectionPointCS = vector3df(0.0,-0.88,4.0);
    wheel.wheelDirectionCS = vector3df(0.0,-0.1,0.0);
    wheel.wheelAxleCS = vector3df(-0.5,0.0,0.0);
    wheel.suspensionRestLength = 0.6;
    wheel.wheelRadius = 8.0;
    wheel.isFrontWheel = true;

    // The bones are in the center of the mesh on the X axis, so we just set the width ourselves.
    // Do the left row of wheels.
    for(u32 i=0; i < Node->getJointCount(); i++)
    {
        // The bones that we need in this mesh are all named "RoadWheels" with a numerical suffix.
        // So we do a quick check to make sure that no unwanted bones get through as wheels.
        if(Node->getJointNode(i)->getName()[0] == 'R')
        {
            wheel.chassisConnectionPointCS = vector3df(-4, Node->getJointNode(i)->getPosition().Y,Node->getJointNode(i)->getPosition().Z);
            vehicle->addWheel(wheel);
        }
    }

    wheel.wheelAxleCS = vector3df(0.5,0.0,0.0);

    // Do the right row of wheels.
    for(u32 i=0; i < Node->getJointCount(); i++)
    {
        if(Node->getJointNode(i)->getName()[0] == 'R')
        {
            wheel.chassisConnectionPointCS = vector3df(4, Node->getJointNode(i)->getPosition().Y,Node->getJointNode(i)->getPosition().Z);
            vehicle->addWheel(wheel);
        }
    }


	for (u32 i=0;i<vehicle->getNumWheels();i++)
    {
        SWheelInfo &info = vehicle->getWheelInfo(i);

        info.suspensionStiffness = 0.08f;
        info.wheelDampingRelaxation = 20.0f;
        info.wheelDampingCompression = 20.0f;
        info.frictionSlip = 1000;
        info.rollInfluence = 0.1f;


        // We call updateWheel, which takes SWheelInfo as the first parameter,
        // and the ID of the wheel to apply that info to. This must
        // be called after any changes in order for the changes to actually take effect.
        vehicle->updateWheelInfo(i);
    }
}
Exemplo n.º 24
0
			// TODO: Make private?  (Game needs to reach it, currently, in addAgent().)
			void logWindowMessage( const stringw text )
			{	logWindow->addItem( text.c_str() ); }// logMessage()
Exemplo n.º 25
0
void PhysicsSim::setWindowTitle(stringw windowTitle)
{
	dvc->setWindowCaption(windowTitle.c_str());
}
Exemplo n.º 26
0
bool CGWIC_BodyPart::LoadModelFile(irr::io::path fname)
{
	IXMLReader* mio = irDevice->getFileSystem()->createXMLReader(fname);
	if (!mio) return false;
	std::cout << "Reading model XML: " << fname.c_str() << std::endl;
	const stringw mt_model(L"Model");
	const stringw mt_inslot(L"InSlot");
	const stringw mt_outslot(L"OutSlot");
	const stringw mt_collision(L"Collision");
	const stringw mt_colbox(L"StandardBox");
	const stringw mt_colsph(L"StandardSphere");
	const stringw mt_coltri(L"TriMeshShape");
	const stringw mt_colcvx(L"ConvexHull");
	const stringw mt_colgim(L"GImpact");
	GWIC_BPSlot cslot;
	CIrrStrParser strparse;
	nocollision = true; //in case we can't load or found collision shape model
	while (mio->read()) {
		if (mt_model.equals_ignore_case(mio->getNodeName())) {
			mesh = scManager->getMesh(GWIC_BPARTS_DIR+mio->getAttributeValueSafe(L"file"));
			if (mesh) root = scManager->addAnimatedMeshSceneNode(
					mesh,parent,GWIC_PICKABLE_MASK | GWIC_ACTOR_MASK);
			if (root) {
				root->updateAbsolutePosition();
				root->setMaterialFlag(EMF_NORMALIZE_NORMALS,true);
				ITriangleSelector* sel = scManager->createTriangleSelector(mesh,root);
				root->setTriangleSelector(sel);
				sel->drop();
			}
			//TODO: texturing
		} else if (mt_inslot.equals_ignore_case(mio->getNodeName())) {
			strparse = mio->getAttributeValueSafe(L"position");
			slot_in.posit = strparse.ToVector3f();
			strparse = mio->getAttributeValueSafe(L"rotation");
			slot_in.rotat = strparse.ToVector3f();
			strparse = mio->getAttributeValueSafe(L"axis");
			slot_in.axis = strparse.ToVector3f();
		} else if (mt_outslot.equals_ignore_case(mio->getNodeName())) {
			cslot.ID = mio->getAttributeValueAsInt(L"ID");
			strparse = mio->getAttributeValueSafe(L"position");
			cslot.posit = strparse.ToVector3f();
			strparse = mio->getAttributeValueSafe(L"rotation");
			cslot.rotat = strparse.ToVector3f();
			strparse = mio->getAttributeValueSafe(L"axis");
			cslot.axis = strparse.ToVector3f();
			slot_outs.push_back(cslot);
		} else if (mt_collision.equals_substring_ignore_case(mio->getNodeName())) {
			mass = mio->getAttributeValueAsFloat(L"mass");
			stringw data = mio->getAttributeValueSafe(L"type");
			nocollision = false;
			if (data.equals_substring_ignore_case(mt_colbox))
				coltype = ECST_BOX;
			else if (data.equals_substring_ignore_case(mt_colsph))
				coltype = ECST_SPHERE;
			else if (data.equals_substring_ignore_case(mt_coltri))
				coltype = ECST_BVHTRIMESH;
			else if (data.equals_substring_ignore_case(mt_colcvx))
				coltype = ECST_CONVEXHULL;
			else if (data.equals_substring_ignore_case(mt_colgim))
				coltype = ECST_GIMPACT;
			else {
				std::cerr << "Collision model unknown: " << data.c_str() << std::endl;
				nocollision = true;
			}
			//colmesh = scManager->getMesh(mio->getAttributeValueSafe(L"file"));
		}
	}
	mio->drop();
	return true;
}
Exemplo n.º 27
0
 const wchar_t* c_str() const { return m_value.c_str(); }
Exemplo n.º 28
0
/*
Ok, now for the more interesting part. First, create the Irrlicht device. As in
some examples before, we ask the user which driver he wants to use for this
example:
*/
int main(int argc,char* argv[])
{

	IrrlichtDevice * device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(640, 500));

	PORT = atoi(argv[2]);
	IP = argv[1];

	if (device == 0)
		return 1; // could not create selected driver.

	/* The creation was successful, now we set the event receiver and
		store pointers to the driver and to the gui environment. */

	device->setWindowCaption(L"InSchool Robot - Simulation");
	device->setResizable(true);


	driver = device->getVideoDriver();
	

	/*
	To make the font a little bit nicer, we load an external font
	and set it as the new default font in the skin.
	To keep the standard font for tool tip text, we set it to
	the built-in font.
	*/


	smgr = device->getSceneManager();

	scene::ITriangleSelector* selector = 0 ;

	isikEkle();
	
	// Creates the mesh
	mesh = device->getSceneManager()->getMesh( "kat.obj" );

	for (unsigned int i=0; i<mesh->getMeshBufferCount(); i++) {
        mesh->getMeshBuffer(i)->setHardwareMappingHint(scene::EHM_STATIC);
    }

	// Create animated scene node.
	bina = smgr->addMeshSceneNode(mesh);
//218
	bina->setPosition(core::vector3df(0, 0, 0));
	bina->setScale(core::vector3df(1,1,1));

	selector = smgr->createOctreeTriangleSelector(bina->getMesh(),bina,1024);
	bina->setTriangleSelector(selector);


	// Creates the mesh
	meshPlayer = device->getSceneManager()->getMesh( "araba.obj" );

	for (unsigned int i=0; i<meshPlayer->getMeshBufferCount(); i++) {
        meshPlayer->getMeshBuffer(i)->setHardwareMappingHint(scene::EHM_STATIC);
    }

	// Create animated scene node.
	player = smgr->addMeshSceneNode(meshPlayer);

	player->setPosition(core::vector3df(200, KAT_Y[1], 1475));
	player->setScale(core::vector3df(3,3,3));
	player->setRotation(core::vector3df(0, -90, 0));


	/*
	To be able to look at and move around in this scene, we create a first
	person shooter style camera and make the mouse cursor invisible.
	*/
	cam = smgr->addCameraSceneNode();
	device->getCursorControl()->setVisible(true);

	camPosition = player->getPosition();
	camPosition.Y += 60;
	camPosition.X -= 150;
	cam->setPosition(camPosition);


	cam->bindTargetAndRotation(true);
	cam->setRotation(core::vector3df(0, -90, 0));
	cam->setTarget(player->getPosition());

	int status = 0;

	env = device->getGUIEnvironment();

	GUIAdd();
     
	// Store the appropriate data in a context structure.
	SAppContext context;
	context.device = device;
	context.counter = 0;
	MyEventReceiver receiver(context);
	device->setEventReceiver(&receiver);

	pthread_create( &portThread, NULL, dataControlAndProccess, NULL);
	pthread_create( &BPlaniThread, NULL, sendString, NULL);

	str = L"BILGI EKRANI"; 


	while(device->run() && driver){


		driver->beginScene(true, true, video::SColor(255,113,113,113));

        smgr->drawAll();
        env->drawAll();

        driver->endScene();

		if(receiver.IsKeyDown(irr::KEY_KEY_X)){
			device->drop();
			exit(0);
		}

		playerPosition = player->getPosition();
		camPosition = cam->getPosition();

			//printf("%f %f %f\n",playerPosition.X,playerPosition.Y,playerPosition.Z);

		if(XPos_Positive > 0.05 ){
			if(BPlaniPanik == 0 && durButton == 0){
				runControl = 1;
				if(status == 0){
					camPosition = player->getPosition();
					camPosition.Y += 60;
					camPosition.X -= 150;
					rotation(robotFront, XPOS, camPosition);
					
					cam->setPosition(camPosition);
					
					cam->setTarget(player->getAbsolutePosition());
					cam->setRotation(core::vector3df(0, 90, 0));
					status = 1;
				}
					
				
				playerPosition.X += HIZ;
				player->setPosition(playerPosition);
				cam->setTarget(player->getAbsolutePosition());
				camPosition.X += HIZ;
				cam->setPosition(camPosition);
					
				
				XPos_Positive-- ;

				if(XPos_Positive < 0.05){
					runControl = 0;
					status = 0 ;
				}
			}
		}

		if(XPos_Negative > 0.05 ){
			if(BPlaniPanik == 0 && durButton == 0 ){
				runControl = 1;
				if(status == 0){
					camPosition = player->getPosition();
					camPosition.Y += 60;
					camPosition.X += 150;

					rotation(robotFront, XNEG,camPosition);
					
					cam->setPosition(camPosition);
					
					cam->setTarget(player->getAbsolutePosition());
				    cam->setRotation(core::vector3df(0, -90, 0));
					status = 1;
				}

				driver->beginScene(true, true, video::SColor(255,113,113,133));
				playerPosition.X -= HIZ;
				player->setPosition(playerPosition);
				cam->setTarget(player->getAbsolutePosition());
				camPosition.X -= HIZ;
				cam->setPosition(camPosition);
				
				
				XPos_Negative-- ;

				if(XPos_Negative < 0.05){
					runControl = 0;
					status = 0 ;
				}
			}
		}

		if(ZPos_Positive > 0.05){
			if(BPlaniPanik == 0 && durButton == 0){
				runControl = 1;
				if(status == 0){
					camPosition = player->getPosition();
					camPosition.Y += 60;
					camPosition.Z -= 150;

					rotation(robotFront, ZPOS, camPosition);
					
					cam->setPosition(camPosition);
					
					cam->setTarget(player->getAbsolutePosition());
					cam->setRotation(core::vector3df(0, 360, 0));
					status = 1;
				}

				driver->beginScene(true, true, video::SColor(255,113,113,133));
				playerPosition.Z += HIZ;
				player->setPosition(playerPosition);
				cam->setTarget(player->getAbsolutePosition());	
				camPosition.Z += HIZ;
				cam->setPosition(camPosition);
				
				ZPos_Positive-- ;

				if(ZPos_Positive < 0.05){
					runControl = 0;
					status = 0 ;
				}
			}
		}

		if(ZPos_Negative > 0.05){
			if(BPlaniPanik == 0 && durButton == 0 ){
				runControl = 1;

				if(status == 0){
					camPosition = player->getPosition();
					camPosition.Y += 60;
					camPosition.Z += 150;

					rotation(robotFront, ZNEG, camPosition);
					
					cam->setPosition(camPosition);
					
					cam->setTarget(player->getPosition());
					cam->setRotation(core::vector3df(0, 180, 0));

					status = 1;
				}
					

				driver->beginScene(true, true, video::SColor(255,113,113,133));
				playerPosition.Z -= HIZ;
				player->setPosition(playerPosition);
				cam->setTarget(player->getPosition());
				camPosition.Z -= HIZ;
				cam->setPosition(camPosition);
				
				ZPos_Negative-- ;
				if(ZPos_Negative < 0.05){
					runControl = 0;
					status = 0 ;
				}
			}
		}

		if(BPlaniPanik == 1){
			runControl = 1;
			if(DEGISIM<0){
				if(playerPosition.Y > KAT_Y[HEDEFKAT]){
					playerPosition.Y += DEGISIM/100;
					camPosition.Y += DEGISIM/100;
					player->setPosition(playerPosition);
					cam->setPosition(camPosition);
					cam->setTarget(player->getPosition());
				
				}
				else{
					BPlaniPanik = 0;
					runControl = 0;
					playerPosition.Y = KAT_Y[HEDEFKAT];
					player->setPosition(playerPosition);
					BULUNDUGUM_KAT = HEDEFKAT;
					str = L"DEVAM'A BASIN";
				}
			}

			if(DEGISIM>0){
				if(playerPosition.Y < KAT_Y[HEDEFKAT]){
					playerPosition.Y += DEGISIM/100;
					camPosition.Y += DEGISIM/100;
					player->setPosition(playerPosition);
					cam->setPosition(camPosition);
					cam->setTarget(player->getPosition());
				
				}
				else{
					BPlaniPanik = 0;
					runControl = 0;
					playerPosition.Y = KAT_Y[HEDEFKAT];
					player->setPosition(playerPosition);
					BULUNDUGUM_KAT = HEDEFKAT;
					str = L"DEVAM'A BASIN";
					
				}
			}
			if(HEDEFKAT == 0)
				Current	= BASLANGIC0;
			if(HEDEFKAT == 1)
				Current	= BASLANGIC1;
			if(HEDEFKAT == 2)
				Current	= BASLANGIC2;

		}

		if(playerPosition.Z > 1350){
			str = L"KAT:";
			str += BULUNDUGUM_KAT; 
			str += L" > DOGU KORIDORU";

			char a[2];
			sprintf(a,"%d",BULUNDUGUM_KAT);
			StringDATA[0]= '\0';
			strcat(StringDATA,"KAT:");
			strcat(StringDATA,a);
			strcat(StringDATA," > DOGU KORIDORU");
		}
		if(playerPosition.Z < -860){
			str = L"KAT:";
			str += BULUNDUGUM_KAT; 
			str += L" > BATI KORIDORU"; 

			char a[2];
			sprintf(a,"%d",BULUNDUGUM_KAT);
			StringDATA[0]= '\0';
			strcat(StringDATA,"KAT:");
			strcat(StringDATA,a);
			strcat(StringDATA," > BATI KORIDORU");

		}
		if(playerPosition.Z > -860 && playerPosition.Z < 1350 && playerPosition.X < -480){
			str = L"KAT:";
			str += BULUNDUGUM_KAT; 
			str += L" > KUZEY KORIDORU"; 

			char a[2];
			sprintf(a,"%d",BULUNDUGUM_KAT);
			StringDATA[0]= '\0';
			strcat(StringDATA,"KAT:");
			strcat(StringDATA,a);
			strcat(StringDATA," > KUZEY KORIDORU");
		}
		if(playerPosition.Z > -860 && playerPosition.Z < 1350 && playerPosition.X > 780){
			str = L"KAT:";
			str += BULUNDUGUM_KAT; 
			str += L" > GUNEY KORIDORU"; 

			char a[2];
			sprintf(a,"%d",BULUNDUGUM_KAT);
			StringDATA[0]= '\0';
			strcat(StringDATA,"KAT:");
			strcat(StringDATA,a);
			strcat(StringDATA," > GUNEY KORIDORU");
		}
		
		myTextBox->setText(str.c_str());


		if(receiver.IsKeyDown(irr::KEY_KEY_W)){
				XPos_Positive = (1 * MetreBUYUTME);
		}

		if(receiver.IsKeyDown(irr::KEY_KEY_S)){
				XPos_Negative = (1 * MetreBUYUTME);
		}

		if(receiver.IsKeyDown(irr::KEY_KEY_A)){
				ZPos_Positive = (1 * MetreBUYUTME);
		}

		if(receiver.IsKeyDown(irr::KEY_KEY_D)){
				ZPos_Negative = (1 * MetreBUYUTME);
		}

		if(receiver.IsKeyDown(irr::KEY_KEY_K)){
				BPlaniPanik = 1;
		}

		if(receiver.IsKeyDown(irr::KEY_KEY_L)){
				BPlaniPanik = 0;
		}
		

	}

	device->drop();

	return 0;
}
Exemplo n.º 29
0
//Need to be reworked: BAD. Render loop is done here!
stringc GUIGame::showInputQuestion(stringw text)
{
    std::string newtxt = "";

    bool mouseExit = false;

	
    while(!App::getInstance()->isKeyPressed(KEY_RETURN) && mouseExit==false && App::getInstance()->getDevice()->run())
    {
		u32 timercheck = App::getInstance()->getDevice()->getTimer()->getRealTime();
        App::getInstance()->getDevice()->getVideoDriver()->beginScene(true, true, SColor(0,200,200,200));
        App::getInstance()->getDevice()->getSceneManager()->drawAll();
        //guienv->drawAll();

        App::getInstance()->getDevice()->getVideoDriver()->draw2DRectangle(SColor(150,0,0,0), rect<s32>(10,
                                                                                                        App::getInstance()->getDevice()->getVideoDriver()->getScreenSize().Height - 200,
                                                                                                        App::getInstance()->getDevice()->getVideoDriver()->getScreenSize().Width - 10,
                                                                                                        App::getInstance()->getDevice()->getVideoDriver()->getScreenSize().Height - 10));

        rect<s32> textRect = rect<s32>(10,  App::getInstance()->getDevice()->getVideoDriver()->getScreenSize().Height - 180,
                                            App::getInstance()->getDevice()->getVideoDriver()->getScreenSize().Width - 10,
                                            App::getInstance()->getDevice()->getVideoDriver()->getScreenSize().Height - 10);

        stringw realTxt = stringw(text.c_str());
        realTxt += stringw(newtxt.c_str());
		// Flashing cursor, flash at 1/4 second interval (based on realtime)
	    if((timercheck-timer2>250))
		{
			realTxt += L'_';
			if (timercheck-timer2>500)
				timer2=timercheck;
		}

		GUIManager::getInstance()->guiFontDialog->draw(realTxt.c_str(),textRect,SColor(255,255,255,255),false,false,&textRect);


        //draw YES GREEN button
        position2di buttonYesPosition = position2di(App::getInstance()->getDevice()->getVideoDriver()->getScreenSize().Width - 58,
                    App::getInstance()->getDevice()->getVideoDriver()->getScreenSize().Height - 58);

        App::getInstance()->getDevice()->getVideoDriver()->draw2DImage(guiDialogImgYes,buttonYesPosition,
                                                                   rect<s32>(0,0,48,48),0,SColor(255,255,255,255),true);

        //check mouse click on OK button
        position2di mousePos = App::getInstance()->getDevice()->getCursorControl()->getPosition();
		if(mousePos.getDistanceFrom(buttonYesPosition+position2di(16,16)) < 16 && App::getInstance()->isMousePressed(0)) mouseExit = true;


        //verify pressed chars and add it to the string

        if(timercheck-timer > 160)
        {
            //process all keycodes [0-9] and [A-Z]
            for(int i=0x30;i<0x5B;i++)
            {
				if(App::getInstance()->isKeyPressed(i))
                {
                    newtxt += i;
                    timer = timercheck;
                }
            }

            //process delete and backspace (same behavior for both of them -> remove the last char)
            if(App::getInstance()->isKeyPressed(KEY_BACK) || App::getInstance()->isKeyPressed(KEY_DELETE))
            {
                newtxt = newtxt.substr(0,newtxt.size()-1);
				timer = timercheck;
            }
        }
        App::getInstance()->getDevice()->getVideoDriver()->endScene();
    }

    //EventReceiver::getInstance()->flushKeys();
    //EventReceiver::getInstance()->flushMouse();
	GUIManager::getInstance()->flush();

    return stringc(newtxt.c_str());
}
Exemplo n.º 30
0
PhysicsSim::PhysicsSim(stringw windowTitle, uint width, uint height, bool render)
{
    broadphase = new btDbvtBroadphase();

    collisionConfiguration = new btDefaultCollisionConfiguration();
    dispatcher = new btCollisionDispatcher(collisionConfiguration);

	btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);

    solver = new btSequentialImpulseConstraintSolver;

    dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);

    setGravity(9.8);

	SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
	params.EventReceiver = this;
	#ifndef NO_GRAPHICS
	if(render)
	{
	    params.Vsync = true;
		params.DriverType = video::EDT_OPENGL;
		params.WindowSize = core::dimension2d<u32>(width, height);
		params.Fullscreen = true;
		params.AntiAlias = 4;
		params.Stencilbuffer = false;
	}
	else
		params.DriverType = video::EDT_NULL;
	#else
	params.DriverType = video::EDT_NULL;
	#endif

	dvc = createDeviceEx(params);

	dvc->getLogger()->setLogLevel(ELL_INFORMATION);

	dvc->setWindowCaption(windowTitle.c_str());
	dvc->getCursorControl()->setVisible(false);

    driver = dvc->getVideoDriver();

	smgr = dvc->getSceneManager();

	env = dvc->getGUIEnvironment();
	pipImage = env->addImage(recti(10,10,200,200));
	pipImage->setScaleImage(true);
	pipImage->setUseAlphaChannel(false);
	pipImage->setVisible(false);

	for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
		KeyIsDown[i] = false;

	lasttick = 0;

	paused = false;

	testSphere = NULL;
	terrain = NULL;

	mediaDirectory = L"./";

	srand(time(NULL));
}