void Game::setup() { //Define a cor de limpeza da tela glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); /*glEnable(GL_CULL_FACE); glCullFace(GL_BACK);*/ glEnable(GL_SMOOTH); glEnable (GL_LINE_SMOOTH); glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); //glEnable(GL_BLEND); gameState = 2; rotate = 0.0f; glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); //GLfloat light_ambient[] = {0, 0, 0, 1.0}; //glLightfv(GL_LIGHT0, GL_AND_INVERTED, light_ambient); // glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45); // GLfloat spot_direction[] = { 0, 0, -1 }; // glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); //Valor para os componentes ambiente e difuso /* float ambient[] = {0.2f, 0.2f, 0.2f, 1.0f}; float diffuse[] = {0.8f, 0.8f, 0.8f, 1.0f}; float specular[] = {1.0f, 1.0f, 1.0f, 1.0f}; // Tipo de material - reflexão glMaterialfv(GL_LIGHT0, GL_AMBIENT, ambient); glMaterialfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glMaterialfv(GL_LIGHT0, GL_SPECULAR, specular); */ //Posição da Luz //glLightfv(GL_LIGHT0, GL_POSITION, posicao); glMatrixMode(GL_PROJECTION); gluPerspective(45, GAMEWINDOW.getRatio(), 0.1, 10); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); objCamera.Position_Camera(0, -0.5f, 2, 0, 0, 0, 0, 0, 0.5); srand(time(0)); generateMap(); printf("Aguardando cliente conectar...\n"); tcp->createServer(8280); sendMap(buffer); // Send buffer map sendMap(color); // Send buffer color gameState = 1; }
void Game::sendNetwork() { timeToUpdateMap++; if (timeToUpdateMap > 10){ sendMap(buffer); // Send buffer map sendMap(color); // Send buffer color timeToUpdateMap = 0; } sendRotation(); // Send a float rotation }
void Game::start() { GameTime t; t.reset(); _gameTime = t.getElapsedTime(); _map.init(); _map.setDelegate(this); _numberOfPlayerAlive = _playerList.size(); Message msg; while (stillPlaying()) { while (t.getElapsedTime() - _gameTime < TIME_UNIT) { getPlayerActions(msg); } _gameTime = t.getElapsedTime(); addSpawn(); updateMap(); sendMap(msg); } _gameEnd = _gameTime; while (msg.time - _gameTime < 100) { msg.messageType = (_gameState == GAME_WON) ? MSG_WON : MSG_LOST; msg.time = t.getElapsedTime(); sendAll(msg); getPlayerActions(msg); } while (msg.time - _gameTime < 100) { for (std::list<Player *>::iterator it = _playerList.begin(); it != _playerList.end(); ++it) { (*it)->recvMsg(msg); } } release(); }
/* Parse the files specified by the files vector then send them to the Reducer*/ void parseAndSend(vector<string> *files) { string pagename, word; CombinerMap combinerMap; WordCountMap wordCountMap; double start_time, total_time=0; int i = 0, num_files = (int)files->size(); /* Loop over the directory and process each file */ MPI_Send(&num_files,1,MPI_INT,0,TAG_INIT1,MPI_COMM_WORLD); while(i < num_files) { start_time = MPI_Wtime(); // start of time evaluation string filename="./files/"; filename.append(files->at(i)); ifstream in(&filename[0] , ifstream::in ); if(!in) { fprintf(stderr,"ERROR:Cannot open input file:%s",filename.c_str()); } else { //Parse a single file into the map while (!in.eof()) { in>>word; if(word.substr(0,3).compare("###")==0){ pagename = word.substr(3); in>>word; wordCountMap.insert(pair<string, int>(word, 1)); combinerMap.insert(pair<string, map<string,int> >(pagename, wordCountMap)); wordCountMap.clear(); } else{ WordCountMap::iterator combinerMapIter = combinerMap[pagename].begin(); combinerMapIter = combinerMap[pagename].find(word); if (combinerMapIter == combinerMap[pagename].end()) { combinerMap[pagename].insert(pair<string, int >(word, 1)); } else { combinerMap[pagename][word]++; } } } in.close(); total_time += MPI_Wtime()-start_time; fprintf(stderr,"Map Time for Rank %d = %lf\n",rank,total_time); sendMap(&combinerMap); combinerMap.clear(); }
void Room::changeAndSendMap(const void* data, size_t data_length) { printf("chageandsendmap\n"); assert(hostPlayerNumber < 4); assert(players[hostPlayerNumber]); // Some basic package validation if (data_length <= sizeof(NetPkgs::MessageHeader) + 4 /* un-/compressed size 2*2B */ || data_length > MAPPKG_SIZE_LIMIT) { printf("[error] Corrupt map arrived from host in room %u\n", roomID); return; } delete mapPackage.data; mapPackage.data = new uint8_t[data_length]; memcpy(mapPackage.data, data, data_length); mapPackage.size = data_length; sendMap(); }
void worldSpace::updateSlice() { //Check the rockmap against the current terrain to see if there are any //Rocks over a water tile. If there are, destroy the rock and the water //Tile. for(int c = 0; c < COL; c++) { for(int r = 0; r < ROW; r++) { if(clvl[c][r] == 'w' && rockmap[c][r] == 'r') { if(onlvl == 1) { lvl1[c][r] = 'g'; clvl = lvl1; } else if(onlvl == 2) { lvl2[c][r] = 'g'; clvl = lvl2; } else if(onlvl == 3) { lvl3[c][r] = 'g'; clvl = lvl3; } rockmap[c][r] = 'n'; } } } //Update Slice with the current terrain. int c2 = 0; for(int c = cXpos-12; c < cXpos+13; c++) { int r2 = 0; for(int r = cYpos-12; r < cYpos+13; r++) { //If r is less than 0 or more than ROW/COL, it's off the map. //Update Slice with a 'n' or null tile. Otherwise, update it //with what's currently there. if((r >= 0 && r < ROW) && (c >= 0 && c < COL)) slice[c2][r2] = clvl[c][r]; else slice[c2][r2] = 'n'; r2 = r2 + 1; } c2 = c2 + 1; } //Update slice with the rockmap. c2 = 0; for(int c = cXpos-12; c < cXpos+13; c++) { int r2 = 0; for(int r = cYpos-12; r < cYpos+13; r++) { if((r >= 0 && r < ROW) && (c >= 0 && c < COL) && (rockmap[c][r] == 'r')) slice[c2][r2] = rockmap[c][r]; r2 = r2 + 1; } c2 = c2 + 1; } emit sendMap(prepMap()); }
// Slots void QArClient::mapChanged(ArMap *map) { sendMap(map); }
//Constructor for the gamespace class gameSpace::gameSpace(QWidget *parent) : QWidget(parent) { QPushButton *button1 = new QPushButton(tr("Orders")); button1->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button2 = new QPushButton(tr("End Turn")); button2->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button3 = new QPushButton(tr("Quests")); button3->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button4 = new QPushButton(tr("Log")); button4->setFont(QFont("Times", 18, QFont::Bold)); wspace = new worldSpace; wtree = new worldTree; lmap = new localMap; (void) new QShortcut(Qt::Key_Up, wspace, SLOT(moveUP())); (void) new QShortcut(Qt::Key_Right, wspace, SLOT(moveRIGHT())); (void) new QShortcut(Qt::Key_Down, wspace, SLOT(moveDOWN())); (void) new QShortcut(Qt::Key_Left, wspace, SLOT(moveLEFT())); (void) new QShortcut(Qt::CTRL + Qt::Key_Q, this, SLOT(close())); connect(button1, SIGNAL(clicked()), this, SLOT(showOrderWindow())); connect(button2, SIGNAL(clicked()), wspace, SLOT(endYourTurn())); connect(this, SIGNAL(pickedUnitm(unit)), wspace, SLOT(movementOverlay(unit))); connect(this, SIGNAL(pickedUnita(unit)), wspace, SLOT(attackOverlay(unit))); connect(wspace, SIGNAL(deselectall()), wspace, SLOT(wipeOverlay())); connect(wspace, SIGNAL(moved()), wspace, SLOT(updateSlice())); connect(wspace, SIGNAL(sendMap(std::vector<std::vector<tile> >)), lmap, SLOT(updateMap(std::vector<std::vector<tile> >))); connect(wspace, SIGNAL(updateTree(unit)), wtree, SLOT(updateTree(unit))); QGridLayout *gridLayout = new QGridLayout; gridLayout->addWidget(wspace, 0, 0, 2, 2); gridLayout->addWidget(wtree, 0, 2, 1, 2); gridLayout->addWidget(lmap, 1, 2, 1, 2); gridLayout->addWidget(button1, 2, 0); gridLayout->addWidget(button2, 2, 1); gridLayout->addWidget(button3, 2, 2); gridLayout->addWidget(button4, 2, 3); gridLayout->setColumnStretch(0, 8); gridLayout->setColumnStretch(1, 8); setLayout(gridLayout); }