Exemple #1
0
int motor::Game::main(Window *wndw, Input *inp, Time *tt)
{
	window = wndw;
	input = inp;
	time = tt;

	cout << endl;

	float oldTime = time->get();
	world.load(8, 8, 8, 16, 16, 16); // 128
	world.generate();
	cout << "world generation took " << time->get() - oldTime << " seconds" << endl;
	cout << endl;

	glActiveTexture(GL_TEXTURE0);
	tileset = new Image("data/tileset.png");

	baseShader = new motor::Shader();
	baseShader->init();

	baseShader->attachVertexShader("data/base.vert");
	baseShader->attachFragmentShader("data/base.frag");
	baseShader->compile();

	int texUniform;
	texUniform = baseShader->getUniformLocation("texture");

	int positionAttrib;
	int texcoordAttrib;
	positionAttrib = baseShader->getAttributeLocation("position");
	texcoordAttrib = baseShader->getAttributeLocation("texcoord");

	baseShader->activate();

	camera = new Camera(input, baseShader);
	camera->setPerspective(45.0f, float(window->width) / float(window->height), window->near, window->far);
	camera->position = glm::vec3(0, 0, 0);

	cout << endl;

	glUniform1i(texUniform, 0);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, tileset->data);

	//	glPolygonMode(GL_FRONT, GL_LINE);

	pos = vel = acc = glm::vec3(0, 0, 0);

	pos = glm::vec3(0.5, 15, 0.5);
	camera->position = pos;
	vec3 rot = glm::vec3(0, 90, 0);
	camera->rotation = rot;
	settings.printPosition = false;

	plot.addNode("Velocity", false);

	while(loop)
	{
		time->update();
		input->update(time, window);//, time);


		if(input->quit())
			loop = false;
		if(input->windowResized())
		{
			cout << "handled!" << window->width << " " << window->height << endl;
			camera->setPerspective(45.0f, float(window->width) / float(window->height), 0.3f, window->far); 
		}

		if(input->isPressed(Key::H) && input->getKeyDelay(Key::H) > .5f)
		{
			input->resetKeyDelay(Key::H);
			settings.holdPosition = !settings.holdPosition;
		}
		if(!settings.holdPosition)
			handlePlayer();

		if(input->isPressed(Key::R) && input->getKeyDelay(Key::R) > .5f)
		{
			input->resetKeyDelay(Key::R);
			world.generate();
			camera->position = glm::vec3(0.5, 20, 0.5);
			cout << "regenerating" << endl;
		}

		camera->think();

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		world.draw(positionAttrib, texcoordAttrib);
		SDL_GL_SwapBuffers();
	}
	return 0;
}
void XMLProtocolParser::processElement(tinyxml2::XMLElement *curChild)
{
    const char *val = curChild->Value();
    std::string str(val);

    if (str.compare("Referee") == 0)
    {
        handleReferee(curChild);
    }
    else if (str.compare("StageChange") == 0)
    {
        handleStageChange(curChild);
    }
    else if (str.compare("GameStart") == 0)
    {
        handleGameStart(curChild);
    }
    else if (str.compare("GameStop") == 0)
    {
        handleGameStop(curChild);
    }
    else if (str.compare("KickOff") == 0)
    {
        handleKickOff(curChild);
    }
    else if (str.compare("DroppedBall") == 0)
    {
        handleDroppedBall(curChild);
    }
    else if (str.compare("FreeKick") == 0)
    {
        handleFreeKick(curChild);
    }
    else if (str.compare("GoalKick") == 0)
    {
        handleGoalKick(curChild);
    }
    else if (str.compare("ThrowIn") == 0)
    {
        handleThrowIn(curChild);
    }
    else if (str.compare("Corner") == 0)
    {
        handleCornerKick(curChild);
    }
    else if (str.compare("Penalty") == 0)
    {
        handlePenalty(curChild);
    }
    else if (str.compare("Parking") == 0)
    {
        handleParking(curChild);
    }
    else if (str.compare("RefboxEvent") == 0)
    {
        // DO NOTHING THIS CUZ OF --> <RefboxEvent xmlns="http://www.robocup.org/MSL/refbox/protocol2010">
    }
    else if (str.compare("GameInfo") == 0)
    {
        this->gameData->setGoals(GameData::Side::CYAN, 0);
        this->gameData->setGoals(GameData::Side::MAGENTA, 0);
        handleGameInfo(curChild);
    }
    else if (str.compare("TeamData") == 0)
    {
        handleTeamData(curChild);
    }
    else if (str.compare("Setup") == 0)
    {
        handleSetup(curChild);
    }
    else if (str.compare("Player") == 0)
    {
        handlePlayer(curChild);
    }
    else if (str.compare("PlayerOut") == 0)
    {
        handlePlayerOut(curChild);
    }
    else if (str.compare("PlayerIn") == 0)
    {
        handlePlayerIn(curChild);
    }
    else if (str.compare("GoalAwarded") == 0)
    {
        handleGoalAwarded(curChild);
    }
    else if (str.compare("CardAwarded") == 0)
    {
        handleCardAwarded(curChild);
    }
    else if (str.compare("Goals") == 0)
    {
        handleGoals(curChild);
    }
    else if (str.compare("Cards") == 0)
    {
        //                      Nothing to, comes with team data
    }
    else if (str.compare("PlayersOut") == 0)
    {
        //                      Currently ignored
    }
    else
    {
        std::cerr << "RQTREFBOX: CANNOT PARSE-> " << val << std::endl;
    }
}