Esempio n. 1
0
	void UnitDefinition::ParseTrainableUnits(XmlNode* trainableNode)
	{
		XmlNode* unitNode = trainableNode->first_node("Unit");
		while(unitNode != 0)
		{
			const char* defName = CopyChar(XmlUtility::XmlGetString(unitNode, "definition"));
			int num = XmlUtility::XmlGetInt(unitNode, "num");

			TrainableUnit* unit(xNew0(TrainableUnit));
			unit->DefinitionName = defName;
			unit->Number = num;

			XmlNode* allReqsNode = unitNode->first_node("Requirements");
			if( allReqsNode != 0 )
			{
				XmlNode* reqNode = allReqsNode->first_node("Requirement");
				while( reqNode != 0 )
				{
					unit->RequirementNames.push_back(CopyChar(
						XmlUtility::XmlGetString(reqNode, "name")));
				}
			}

			_trainableUnitsDefs.push_back(unit);

			unitNode = unitNode->next_sibling();
		}
	}
Esempio n. 2
0
	void CreateGameScreen::LoadNewGameSettings()
	{
		if(_newGameSettingsLoaded == false)
		{
			_newGameSettingsLoaded = true;

			// Get new game settings config file
			RefPtr<Configuration> mainConfig = ConfigurationManager::Instance()->GetConfiguration("Main");
			string filepath = mainConfig->FindOptionValue("NewGameConfig", "Files");
			RefPtr<XmlDocument> settingsDoc = XmlUtility::XmlDocFromFile(filepath.c_str());
			XmlNode* rootNode = settingsDoc->first_node("NewGameSettings");
			// Read values
			XmlNode* gameTypesListNode = rootNode->first_node("GameTypes");
			XmlNode* gameTypeNode = gameTypesListNode->first_node();
			while(gameTypeNode != 0)
			{
				GameTypeNames.push_back(XmlUtility::XmlGetString(gameTypeNode, "name"));
				gameTypeNode = gameTypeNode->next_sibling();
			}

			XmlNode* colorsListNode = rootNode->first_node("AvailableColors");
			XmlNode* colorNode = colorsListNode->first_node();
			while(colorNode != 0)
			{
				PlayersColorsList.push_back(XmlUtility::XmlGetRGB(colorNode));
				colorNode = colorNode->next_sibling();
			}
			NoColorIndex = PlayersColorsList.size() - 1;

			XmlNode* resourceModesListNode = rootNode->first_node("ResourceModes");
			XmlNode* resourceModeNode = resourceModesListNode->first_node();
			while(resourceModeNode != 0)
			{
				ResourceModeNames.push_back(XmlUtility::XmlGetString(resourceModeNode, "name"));
				resourceModeNode = resourceModeNode->next_sibling();
			}

			XmlNode* visibilityModesListNode = rootNode->first_node("VisibilityModes");
			XmlNode* visibilityModeNode = visibilityModesListNode->first_node();
			while(visibilityModeNode != 0)
			{
				VisibilityModeNames.push_back(XmlUtility::XmlGetString(visibilityModeNode, "name"));
				visibilityModeNode = visibilityModeNode->next_sibling();
			}

			XmlNode* startModesListNode = rootNode->first_node("StartLocModes");
			XmlNode* startModeNode = startModesListNode->first_node();
			while(startModeNode != 0)
			{
				StartLocModeNames.push_back(XmlUtility::XmlGetString(startModeNode, "name"));
				startModeNode = startModeNode->next_sibling();
			}
		}
	}
Esempio n. 3
0
	void CreateGameScreen::AddGameModes(XmlNode* mapNode)
	{
		string defMode = XmlUtility::XmlGetString(mapNode->first_node("DefaultMode"), "name");
		_currentMode = 0;
		_availableModes.clear();
		_comboGameMode->removeAllItems();

		XmlNode* modesListNode = mapNode->first_node("Modes");
		int modeNum = 0;
		XmlNode* modeNode = modesListNode->first_node();
		while(modeNode != 0)
		{
			Mode mode;
			mode.Name = modeNode->name();
			mode.Display = XmlUtility::XmlGetStringIfExists(modeNode, "display", mode.Name.c_str());
			mode.IsCustomisable = XmlUtility::XmlGetBoolIfExists(modeNode, "customisable", true);
			_availableModes.push_back(mode);
			_comboGameMode->addItem(mode.Display, modeNum);

			// Additionaly find default mode index
			if(mode.Name.compare(defMode) == 0)
			{
				_currentMode = modeNum;
				_comboGameMode->setIndexSelected(modeNum);
			}

			++modeNum;
			modeNode = modeNode->next_sibling();
		}
	}
void XmlParser::readModel(Transform * transform, XmlNode * modelNode) {
    // Create model
    glm::mat4 model;

    if (modelNode) {
        // Get each transformation
        XmlNode * transformNode = modelNode->first_node();

        while (transformNode) {
            std::string type(transformNode->name());

            // Translate
            if (type == "translate") {
                XmlAttr * x, * y, * z;
                xmlAttribute(x, transformNode);
                xmlAttribute(y, transformNode);
                xmlAttribute(z, transformNode);

                // Apply transformation
                transform->translate(atof(x->value()), atof(y->value()), atof(z->value()));
            }
            // Rotate
            else if (type == "rotate") {
                // Read angle
                XmlAttr * angle;
                xmlAttribute(angle, transformNode);

                // Check normal
                glm::vec3 normal(0, 1, 0);
                XmlNode * normalNode = transformNode->first_node("normal");
                if (normalNode) {
                    XmlAttr * x, * y, * z;
                    xmlAttribute(x, normalNode);
                    xmlAttribute(y, normalNode);
                    xmlAttribute(z, normalNode);

                    // Set new normal
                    normal = glm::vec3(atof(x->value()), atof(y->value()), atof(z->value()));
                }

                // Apply transformation
                transform->rotate(atof(angle->value()), normal);
            }
            // Scale
            else if (type == "scale") {
                XmlAttr * x, * y, * z;
                xmlAttribute(x, transformNode);
                xmlAttribute(y, transformNode);
                xmlAttribute(z, transformNode);

                // Apply transformation
                transform->scale(atof(x->value()), atof(y->value()), atof(z->value()));
            }

            // Get next transformation
            transformNode = transformNode->next_sibling();
        }
    }
}
Esempio n. 5
0
	void CreateGameScreen::MapSelected(RefPtr<XmlDocument>& mapDoc)
	{
		_currentMapDoc = mapDoc;
		_currentMapDir = _mapList->GetCurrentDir();
		_buttonStart->setEnabled(false);
		try
		{
			// Read and set preview image and start locations
			XmlNode* mapNode = mapDoc->first_node("Map");
			Vector2 mapSize = XmlUtility::XmlGetXY(mapNode->first_node("Size"));
			string previewImage = XmlUtility::XmlGetString(mapNode->first_node("PreviewImage"), "value");
			XmlNode* startLocListNode = mapNode->first_node("AvailableStartLocations");
			XmlNode* startLocNode = startLocListNode->first_node();
			while( startLocNode != 0 )
			{
				_startLocPositions.push_back(XmlUtility::XmlGetXY(startLocNode));
				startLocNode = startLocNode->next_sibling();
			}

			_mapPreview->SetNewMap(mapSize, _mapList->GetCurrentDir() + previewImage, 
				previewImage, _startLocPositions.size());
			for(unsigned int i = 0; i < _startLocPositions.size(); ++i)
			{
				_mapPreview->MoveStartingPosition(i, _startLocPositions[i]);
				_mapPreview->SetStartingPositionColor(i, PlayersColorsList[NoColorIndex]);
			}

			AddGameModes(mapNode);
			int defMode = _currentMode;
			_currentMode = -1;
			SetGameMode(defMode);

			_comboGameMode->setEnabled(true);
			_comboResourcesMode->setEnabled(true);
			_comboStartLocMode->setEnabled(true);
			_comboVisibilityMode->setEnabled(true);
		}
		catch(...)
		{
			_ASSERT(false);
			// Map file is corrupted, maybe show some info on it
		}
	}
Esempio n. 6
0
	void UnitDefinition::ParseCommands(XmlNode* commandsNode)
	{
		// Get command list
		XmlNode* commandNode = commandsNode->first_node("Command",7);
		while(commandNode != 0)
		{
			Command* customCommand = 0;
			// Read command type and if its default one
			int key = OrderTypes::ParseOrderType(commandNode->first_attribute("type",4,false)->value());
			if( XmlUtility::XmlGetBool(commandNode, "custom", 6) )
			{
				// Custom command ( ability or non-default non-ability )
			}

			// Get command button its name, position, hotkey
			XmlNode* buttonNode = commandNode->first_node("Button",6);

			string buttonName = XmlUtility::XmlGetString(buttonNode,"definition", 10);
			int hotkey = SystemSettings::GetKeyBindings().KeyCodeNamesMap[
				XmlUtility::XmlGetString(buttonNode, "key", 3)];
				int posx = XmlUtility::XmlGetInt(buttonNode, "x", 1);
				int posy = XmlUtility::XmlGetInt(buttonNode, "y", 1);

				// Lambda funtion for creating button -> button needs definition which can
				// be not loaded at this point ( as CommandSet is created in UnitDefinition ),
				// so we'll create it later, when all Definitions are loaded
				auto createButton = [this, key, buttonName, hotkey, posx, posy, customCommand]() 
				{
					CommandButton* button = xNew1(CommandButton, 
						MainGameObjectPool::GlobalPool->GetObjectDefinitionByNameCast
						<CommandButtonDefinition>(buttonName, "CommandButton"));
					button->SetHotkey(hotkey);
					button->SetPosX(posx);
					button->SetPosY(posy);
					if( customCommand == 0 )
						_defaultCommandButtons.push_back(std::make_pair(key, button));
					else
						_customCommands.push_back(std::make_pair(customCommand, button));
				};
				MainGameObjectPool::GlobalPool->OnAllDefinitionsLoaded() +=
					xNew1(DelegateEventHandler<decltype(createButton)>,createButton);

				commandNode = commandNode->next_sibling();
		}
	}
Esempio n. 7
0
	void MainEventPool::ParseAllTriggers(XmlNode* rootNode)
	{
		// trigsNode is root node in map's triggers file
		// First save all variables - find node Variables
		XmlNode* varsNode = rootNode->first_node("Variables", 9);
		// Save all variables 
		// Create triggers - find Triggers node
		XmlNode* trigsNode = rootNode->first_node("Triggers", 8);
		XmlNode* trigNode = trigsNode->first_node("Trigger");
		while(trigNode != 0)
		{
			Trigger* trigger = CreateTrigger(trigNode);
			_triggers.insert(std::make_pair(trigger->GetName(), trigger));

			bool enabled = XmlUtility::XmlGetBoolIfExists(trigNode, "is_enabled", true);
			if(enabled)
				trigger->Enable();

			trigNode = trigNode->next_sibling();
		}
	}
Esempio n. 8
0
	Trigger* MainEventPool::CreateTrigger(XmlNode* trigNode)
	{
		const char* trigName = XmlUtility::XmlGetString(trigNode, "name");

		Trigger* trigger = xNew1(Trigger, trigName);

		XmlNode* evtNode = trigNode->first_node("Event");
		if(evtNode != 0) // Trigger may not have and event
		{
			trigger->SetEvent(FindEvent(evtNode));
		}

		XmlNode* actsNode = trigNode->first_node("Actions", 7);
		MultiAction* actions = xNew0(MultiAction);
		XmlNode* actNode = actsNode->first_node("Action", 6);
		while (actNode != 0)
		{
			actions->AddAction(CreateAction(actNode));
			actNode = actNode->next_sibling();
		}
		trigger->SetActions(actions);
		return trigger;
	}
Esempio n. 9
0
	UnitDefinition::UnitDefinition(XmlNode* soDefNode) :
		PhysicalObjectDefinition(soDefNode),
		_baseStats(xNew0(UnitStats)),
		_canTrainUnits(false),
		_selectionMarkerDef(0)
	{
		SetFinalType(GetTypeId<Unit>());
		SetFinalTypeName("Unit");
		_selectionFlags |= SelectionFlags::Unit;

		// Get node specific to Unit
		XmlNode* unitNode = soDefNode->first_node("PhysicalObject")->
			first_node("Unit");

		XmlNode* propsNode = unitNode->first_node("Properties");
		if(propsNode != 0)
			ParseUnitProperties(propsNode);

		XmlNode* soundsNode = unitNode->first_node("SoundSet");
		ParseUnitSounds(soundsNode);

		_baseStats->Parse(unitNode->first_node("Stats",5));

		_iconName = XmlUtility::XmlGetString(unitNode->first_node("Icon",4), "name", 4);
		_guiName = XmlUtility::XmlGetLocaleString(unitNode->first_node("GuiName",7));
		/*
		Ogre::Image icon;
		icon.load(_iconName, "Icons");
		Ogre::TexturePtr iconTexture = Ogre::TextureManager::getSingleton().createManual(
		_iconName, "Icons", Ogre::TEX_TYPE_2D, (int)icon.getWidth(), (int)icon.getHeight(), 1, icon.getFormat());
		iconTexture->loadImage(icon);
		*/
		ParseWeapons(unitNode->first_node("Weapons",7));
		ParseCommands(unitNode->first_node("Commands"));

		XmlNode* trainableNode = unitNode->first_node("TrainableUnits");
		if( trainableNode != 0 )
			ParseTrainableUnits(unitNode->first_node("TrainableUnits"));

		XmlNode* selectionNode = unitNode->first_node("SelectionMarker");
		if( selectionNode != 0 )
		{
			ParseSelectionMarker(selectionNode);
		}

		ParseMoveStrategy(unitNode->first_node("MoveStrategy"));
	}
Esempio n. 10
0
void XmlParser::readLights(Scene * scene, XmlNode * lights) {
    if (lights) {
        // Read all lights from scene
        XmlNode * light = lights->first_node("light");
        while (light) {
            // Create light
            Light * l = new Light();

            // Get position from xml
            XmlNode * position;
            xmlElement(position, light);
            // Get coordinates
            XmlAttr * x, * y, * z;
            xmlAttribute(x, position);
            xmlAttribute(y, position);
            xmlAttribute(z, position);
            // Set position
            l->setPosition(atof(x->value()), atof(y->value()), atof(z->value()));

            // Get direction from xml
			XmlNode * direction;
			xmlElement(direction, light);
			// Get coordinates
			xmlAttribute(x, direction);
			xmlAttribute(y, direction);
			xmlAttribute(z, direction);
			// Set position
			l->setDirection(atof(x->value()), atof(y->value()), atof(z->value()));

			// Check angle
			XmlNode * angle = light->first_node("angle");
			if (angle) {
				XmlAttr * value;
				xmlAttribute(value, angle);
				l->setLightAngle(atof(value->value()));
			}

            // Try to get diffuse
            XmlNode * diffuse = light->first_node("diffuse");
            if (diffuse) {
                // Get coordinates
                XmlAttr * r, * g, * b;
                xmlAttribute(r, diffuse);
                xmlAttribute(g, diffuse);
                xmlAttribute(b, diffuse);
                // Set diffuse
                l->setDiffuse(atof(r->value()), atof(g->value()), atof(b->value()));
            }

            // Try to get specular
            XmlNode * specular = light->first_node("specular");
            if (specular) {
                // Get coordinates
                XmlAttr * r, * g, * b;
                xmlAttribute(r, specular);
                xmlAttribute(g, specular);
                xmlAttribute(b, specular);
                // Set specular
                l->setSpecular(atof(r->value()), atof(g->value()), atof(b->value()));
            }

            // Read scripts
            XmlNode * scripts = light->first_node("scripts");
            readScripts(scene, l, scripts);

            // Add to scene
            scene->addLight(l);

            // Get next light
            light = light->next_sibling("light");
        }
    } else {
        printf("No lights\n");
    }
}
Esempio n. 11
0
void XmlParser::readMeshs(Renderer * renderer ,Scene * scene, XmlNode * meshNode) {
    // Read mesh
    while(meshNode) {
        // Create cube
        glm::mat4 id;
        MeshObject * mesh = new MeshObject(id);
        // Read shaders and init it
        int basicShader = renderer->getDefaultBasicShader();
        int lightShader = renderer->getDefaultLightShader();
        XmlNode * basicShaderNode = meshNode->first_node("basic-shader");
        XmlNode * lightShaderNode = meshNode->first_node("light-shader");
        
        // If there is a basic shader node
        if (basicShaderNode) {
            XmlAttr * vert, * frag;
            xmlAttribute(vert, basicShaderNode);
            xmlAttribute(frag, basicShaderNode);
            // Create new shader
            basicShader = renderer->createShaderProg(vert->value(), frag->value());
        }

        // If there is a light shader node
        if (lightShaderNode) {
            XmlAttr * vert, * frag;
            xmlAttribute(vert, lightShaderNode);
            xmlAttribute(frag, lightShaderNode);
            // Create new shader
            lightShader = renderer->createShaderProg(vert->value(), frag->value());
        }

        // Init mesh
        mesh->init(basicShader, lightShader);

        // Load file (it must exist)
        XmlAttr * file;
        xmlAttribute(file, meshNode);
        mesh->loadFromFile(file->value());
        
        // Try to read model
        readModel(mesh, meshNode->first_node("model"));

        // Add c to scene
        scene->addGameObject(mesh);

        // Set texture
        XmlNode * textureNode = meshNode->first_node("texture");
        if (textureNode) {
            // Get file name
            XmlAttr * file;
            xmlAttribute(file, textureNode);

            // Create texture
            Texture texture(GL_TEXTURE0, std::string(file->value()));

            // Set texture
            mesh->setTexture(texture);
        }

        // Set normal map
        XmlNode * normalMapNode = meshNode->first_node("normal-map");
        if (normalMapNode) {
            // Get file name
            XmlAttr * file;
            xmlAttribute(file, normalMapNode);

            // Create texture
            Texture normalMap(GL_TEXTURE2, std::string(file->value()));

            // Set texture
            mesh->setNormalMap(normalMap);
        }

        // Set material
		XmlNode * material = meshNode->first_node("material");
		if (material) {
			// Create material
			Material * m = new Material();

			// Set emissive
			XmlNode * emissive = material->first_node("emissive");
			if (emissive) {
				XmlAttr * r, *g, *b;
				xmlAttribute(r, emissive);
				xmlAttribute(g, emissive);
				xmlAttribute(b, emissive);
				// Set diffuse
				m->setEmissive(atof(r->value()), atof(g->value()),
						atof(b->value()));
			}

			// Read ambient
			XmlNode * ambient = material->first_node("ambient");
			if (ambient) {
				XmlAttr * r, *g, *b;
				xmlAttribute(r, ambient);
				xmlAttribute(g, ambient);
				xmlAttribute(b, ambient);
				// Set diffuse
				m->setAmbient(atof(r->value()), atof(g->value()),
						atof(b->value()));
			}

			// Read diffuse
			XmlNode * diffuse = material->first_node("diffuse");
			if (diffuse) {
				XmlAttr * r, *g, *b;
				xmlAttribute(r, diffuse);
				xmlAttribute(g, diffuse);
				xmlAttribute(b, diffuse);
				// Set diffuse
				m->setDiffuse(atof(r->value()), atof(g->value()),
						atof(b->value()));
			}

			// Read specular
			XmlNode * specular = material->first_node("specular");
			if (specular) {
				XmlAttr * r, *g, *b;
				xmlAttribute(r, specular);
				xmlAttribute(g, specular);
				xmlAttribute(b, specular);
				// Set diffuse
				m->setSpecular(atof(r->value()), atof(g->value()),
						atof(b->value()));
			}

			// Read specular
			XmlNode * shininess = material->first_node("shininess");
			if (shininess) {
				XmlAttr * value;
				xmlAttribute(value, shininess);
				// Set diffuse
				m->setShininess(atof(value->value()));
			}

			// Set material
			mesh->setMaterial(m);
		}

        // Read Scripts
        XmlNode * scripts = meshNode->first_node("scripts");
        readScripts(scene, mesh, scripts);

        // Get next cube
        meshNode = meshNode->next_sibling("mesh");
    }
}
Esempio n. 12
0
void XmlParser::loadFromXml(const char * fileName, int * argc, char ** argv) {
    XmlFile xmlFile(fileName);
    XmlDocument doc;
    doc.parse<0>(xmlFile.data());
    int W, H;

    XmlNode * rtNode = doc.first_node("ge");

    /*** Read window information ***/
    XmlNode * windowNode = rtNode->first_node("window");
    if (windowNode) {
        // Try to read window name
        XmlNode * name;
        xmlElement(name, windowNode);

        // Read width and height
        XmlNode * width, *height;
        xmlElement(width, windowNode);
        xmlElement(height, windowNode);

        W = atoi(width->value());
        H = atoi(height->value());

        // Set window parameters
        GameWindow::setWindow((name) ? name->value() : "GE", W, H);
    } else {
        W = 512;
        H = 512;

        GameWindow::setWindow("GE", W, H);
    }
    // Init gamewindow and light
    GameWindow::init(argc, argv);
    Light::init();
    Material::init();
    Input::init();
    GBuffer::init(W,H);
    // Load noise texture
    glActiveTexture(GL_TEXTURE11);
    LoadTexBMP("textures/noise.bmp");
    /*** Read Scene ***/
    // Reference to scene node
    XmlNode * sceneNode = rtNode->first_node("scene");
    // Instantiate scene    
    Scene * scene = new Scene();
    // Instantiate renderer
    Renderer * renderer = new Renderer();
    // Set renderer
    GameWindow::setRenderer(renderer);
    renderer->setScene(scene);

	// Create camera
	Camera * camera = new Camera();
	// Set camera
	renderer->setCamera(camera);
	camera->setAspectRatio(W/H);

	// Read Camera
	XmlNode * cameraNode = rtNode->first_node("camera");
	if (cameraNode) {
		readModel(camera, cameraNode->first_node("model"));
//		// Set position
//		XmlNode * position = cameraNode->first_node("position");
//		if (position) {
//			// Get coordinates
//			XmlAttr * x, *y, *z;
//			xmlAttribute(x, position);
//			xmlAttribute(y, position);
//			xmlAttribute(z, position);
//			camera->setPosition(atof(x->value()), atof(y->value()), atof(z->value()));
//		}
//
//		// Set direction
//		XmlNode * direction= cameraNode->first_node("direction");
//		if (direction) {
//			// Get coordinates
//			XmlAttr * x, *y, *z;
//			xmlAttribute(x, direction);
//			xmlAttribute(y, direction);
//			xmlAttribute(z, direction);
//			camera->setDirection(atof(x->value()), atof(y->value()),
//					atof(z->value()));
//		}
//
//
//		// Set direction
//		XmlNode * up = cameraNode->first_node("up");
//		if (up) {
//			// Get coordinates
//			XmlAttr * x, *y, *z;
//			xmlAttribute(x, up);
//			xmlAttribute(y, up);
//			xmlAttribute(z, up);
//			camera->setUp(atof(x->value()), atof(y->value()),
//					atof(z->value()));
//		}

		// Read scripts
		XmlNode * scriptsNode = cameraNode->first_node("scripts");
		readScripts(scene, camera, scriptsNode);
	}

    // Light shadow map must be initialized after renderer has a camera
    Light::initShadowMap(renderer->createShaderProg("shaders/shadow.vert", "shaders/shadow.frag"));

    // Read objects
    XmlNode * objectsNode = sceneNode->first_node("objects");
    if (objectsNode) {
        // Read all cubes
        XmlNode * cubeNode = objectsNode->first_node("cube");
        readCubes(renderer, scene, cubeNode);

        // Read all mesh from scene
        XmlNode * meshNode = objectsNode->first_node("mesh");
        readMeshs(renderer, scene, meshNode);
        
    } else {
        printf("No objects\n");
    }

    // Read Lights
    XmlNode * lights = sceneNode->first_node("lights");
    readLights(scene, lights);
}
Esempio n. 13
0
void XmlParser::readCubes(Renderer * renderer ,Scene * scene, XmlNode * cubeNode) {
    // Read all cubes from scene
    while(cubeNode) {
        // Create cube
        Cube * c = new Cube();
        // Read shaders and init it
        int basicShader = renderer->getDefaultBasicShader();
        int lightShader = renderer->getDefaultLightShader();
        XmlNode * basicShaderNode = cubeNode->first_node("basic-shader");
        XmlNode * lightShaderNode = cubeNode->first_node("light-shader");
        
        // If there is a basic shader node
        if (basicShaderNode) {
            XmlAttr * vert, * frag;
            xmlAttribute(vert, basicShaderNode);
            xmlAttribute(frag, basicShaderNode);
            // Create new shader
            basicShader = renderer->createShaderProg(vert->value(), frag->value());
        }

        // If there is a light shader node
        if (lightShaderNode) {
            XmlAttr * vert, * frag;
            xmlAttribute(vert, lightShaderNode);
            xmlAttribute(frag, lightShaderNode);
            // Create new shader
            lightShader = renderer->createShaderProg(vert->value(), frag->value());
        }

        // Init cube
        c->init(basicShader, lightShader);
        
        // Try to read model
        readModel(c, cubeNode->first_node("model"));


        // Add c to scene
        scene->addGameObject(c);

        // Set texture
        XmlNode * texture = cubeNode->first_node("texture");
        if (texture) {
            // Get file name
            XmlAttr * file;
            xmlAttribute(file, texture);

            // Create texture
            Texture texture(GL_TEXTURE0, std::string(file->value()));

            // Set texture
            c->setTexture(texture);
        }

        // Set material
        XmlNode * material = cubeNode->first_node("material");
        if (material) {
        	// Create material
        	Material * m = new Material();

        	// Set emissive
        	XmlNode * emissive = material->first_node("emissive");
			if (emissive) {
				XmlAttr * r, *g, *b;
				xmlAttribute(r, emissive);
				xmlAttribute(g, emissive);
				xmlAttribute(b, emissive);
				// Set diffuse
				m->setEmissive(atof(r->value()), atof(g->value()),
						atof(b->value()));
			}

			// Read ambient
			XmlNode * ambient = material->first_node("ambient");
			if (ambient) {
				XmlAttr * r, *g, *b;
				xmlAttribute(r, ambient);
				xmlAttribute(g, ambient);
				xmlAttribute(b, ambient);
				// Set diffuse
				m->setAmbient(atof(r->value()), atof(g->value()),
						atof(b->value()));
			}

			// Read diffuse
			XmlNode * diffuse = material->first_node("diffuse");
			if (diffuse) {
				XmlAttr * r, *g, *b;
				xmlAttribute(r, diffuse);
				xmlAttribute(g, diffuse);
				xmlAttribute(b, diffuse);
				// Set diffuse
				m->setDiffuse(atof(r->value()), atof(g->value()),
						atof(b->value()));
			}

			// Read specular
			XmlNode * specular = material->first_node("specular");
			if (specular) {
				XmlAttr * r, *g, *b;
				xmlAttribute(r, specular);
				xmlAttribute(g, specular);
				xmlAttribute(b, specular);
				// Set diffuse
				m->setSpecular(atof(r->value()), atof(g->value()),
						atof(b->value()));
			}

			// Read specular
			XmlNode * shininess = material->first_node("shininess");
			if (shininess) {
				XmlAttr * value;
				xmlAttribute(value, shininess);
				// Set diffuse
				m->setShininess(atof(value->value()));
			}

			// Set material
			c->setMaterial(m);
        }

        // Read Scripts
        XmlNode * scripts = cubeNode->first_node("scripts");
        readScripts(scene, c, scripts);

        // Get next cube
        cubeNode = cubeNode->next_sibling("cube");
    }
}