TEST(DefaultGridTest, Test) { int remainder = 0; ui::grid<3, 3, griditem> testGrid; testGrid.Add(0,0, griditem('a'), 10, 8, 1, remainder); EXPECT_EQ(remainder, 2); testGrid.Remove(0,0,8); EXPECT_TRUE(testGrid.IsEmpty(0,0)); testGrid.Add(1,0, griditem('b'), 2, 99, 0, remainder); testGrid.Add(2,0, griditem('c'), 3, 99, 0, remainder); testGrid.Add(2,0, griditem('c'), 7, 99, 0, remainder); testGrid.Add(0,1, griditem('d'), 4, 99, 0, remainder); testGrid.Add(1,1, griditem('e'), 5, 99, 0, remainder); testGrid.Add(2,1, griditem('f'), 6, 99, 0, remainder); testGrid.Remove(2, 1, 5); EXPECT_TRUE(testGrid(1, 0).Item().test == 'b'); EXPECT_TRUE(testGrid(1, 0).Count() == 2); testGrid.Remove(1, 0, 2); EXPECT_TRUE(testGrid(1, 0).Count() == 0); testGrid.Swap(2, 0, 2, 1); EXPECT_EQ(testGrid(2, 0).Item().test, 'f'); EXPECT_EQ(testGrid(2, 1).Item().test, 'c'); }
int main() { Grid<int> testGrid(5, 3, 7); for (Grid<int>::dimension_type x = 0; x < testGrid.GetColumnCount(); x++) { for (Grid<int>::dimension_type y = 0; y < testGrid.GetRowCount(); y++) { testGrid.GetCell(x, y) = std::rand() % 80 + 1; } } PrintIndices(testGrid); for (Grid<int>::dimension_type i = 0; i < testGrid.columnCount * testGrid.rowCount; i++) { std::cout << testGrid.grid_data[i] << std::endl; } std::cout << "Check Value: " << testGrid[2][1] << std::endl; std::cout << "Check Value Method: " << testGrid.GetCell(2, 1) << std::endl; testGrid.ResizeGridPreserveData(8, 5, 9); printf("\n"); std::cout << testGrid << std::endl; getchar(); return 0; }
int main(int argc, char** argv) { MPI_Init(&argc,&argv); int rank,size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); // Create a 8×8 Testgrid std::array<int32_t, 3> globalSize{20,20,1}; std::array<bool, 3> isPeriodic{false,false,true}; { FsGrid<int,1> testGrid(globalSize, MPI_COMM_WORLD, isPeriodic); /* if(rank == 0) { std::cerr << " --- Test task mapping functions ---" << std::endl; } if(rank == 0) { for(int i=0; i<8; i++) { auto taskLid = testGrid.getTaskForGlobalID(8*1*0+8*0+i); std::cerr << "Cell ( " << i << ", 0, 0) is located on task " << taskLid.first << std::endl; std::cerr << " and it has LocalID " << taskLid.second << std::endl; } for(int i=0; i<8; i++) { auto taskLid = testGrid.getTaskForGlobalID(8*1*0+8*i+0); std::cerr << "Cell ( " << 0 << ", " << i << ", 0) is located on task " << taskLid.first << std::endl; std::cerr << " and it has LocalID " << taskLid.second << std::endl; } for(int i=0; i<8; i++) { auto taskLid = testGrid.getTaskForGlobalID(8*1*0+8*i+i); std::cerr << "Cell ( " << i << ", " << i << ", 0) is located on task " << taskLid.first << std::endl; } } */ std::array<int, 3> localSize=testGrid.getLocalSize(); int z = 0; for(int y = -1; y < localSize[1] + 1; y++){ for(int x = -1; x < localSize[0] + 1; x++){ *(testGrid.get(x, y, z)) = rank; } } if(rank==1) { printf("local size %d %d %d\n", localSize[0], localSize[1], localSize[2]); printf("----------------------------------\n"); int z = 0; printf("z=%d\n", z); for(int y = -1; y < localSize[1] + 1; y++){ printf("y=%d :", y); for(int x = -1; x < localSize[0] +1; x++){ printf("%d ", *(testGrid.get(x, y, z))); } printf("\n"); } printf("----------------------------------\n"); } testGrid.updateGhostCells(); if(rank==1) { printf("local size %d %d %d\n", localSize[0], localSize[1], localSize[2]); printf("----------------------------------\n"); int z = 0; printf("z=%d\n", z); for(int y = -1; y < localSize[1] + 1; y++){ printf("y=%d :", y); for(int x = -1; x < localSize[0] +1; x++){ printf("%d ", *(testGrid.get(x, y, z))); } printf("\n"); } printf("----------------------------------\n"); } if(rank == 0) { std::cerr << " --- Test data transfer into the grid ---" << std::endl; } // First, setup grid coupling to do everything from task 0 if(rank == 0) { testGrid.setupForGridCoupling(globalSize[0]*globalSize[1]); for(int y=0; y<globalSize[1]; y++) { for(int x=0; x<globalSize[0]; x++) { testGrid.setGridCoupling(y*globalSize[0]+x,0); // All cells are coupled to 0 } } } else { testGrid.setupForGridCoupling(0); } testGrid.finishGridCoupling(); // Fill in some junk data from task 0 std::vector<int> fillData; if(rank == 0) { fillData.resize(globalSize[0]*globalSize[1]); // We are going to send data for all 8×8 Cells testGrid.setupForTransferIn(globalSize[0]*globalSize[1]); for(int y=0; y<globalSize[1]; y++) { for(int x=0; x<globalSize[0]; x++) { fillData[y*globalSize[0] + x] = x*y; testGrid.transferDataIn(y*globalSize[0]+x,&fillData[y*globalSize[0]+x]); } } } else { // The others simply recieve testGrid.setupForTransferIn(0); } testGrid.finishTransfersIn(); // Now have each task output their data for(int i=0; i<size; i++) { if(i == rank) { std::cerr << "Contents of Task #" << rank << ": " << std::endl; std::array<int32_t,3> localSize = testGrid.getLocalSize(); for(int y=0; y<localSize[1]; y++) { for(int x=0; x<localSize[0]; x++) { std::cerr << *testGrid.get(x,y,0) << ", "; } std::cerr << std::endl; } } MPI_Barrier(MPI_COMM_WORLD); } // Transfer it back std::vector<int> returnedData; if(rank ==0) { returnedData.resize(globalSize[0]*globalSize[1]); testGrid.setupForTransferOut(globalSize[0]*globalSize[1]); for(int y=0; y<globalSize[1]; y++) { for(int x=0; x<globalSize[0]; x++) { testGrid.transferDataOut(y*globalSize[0]+x,&returnedData[y*globalSize[0]+x]); } } } else { testGrid.setupForTransferOut(0); } testGrid.finishTransfersOut(); // Validate the result if(rank == 0) { std::cerr << " --------- " << std::endl; std::cerr << "Returned array contents:" << std::endl; for(int y=0; y<globalSize[1]; y++) { for(int x=0; x<globalSize[0]; x++) { std::cerr << returnedData[y*globalSize[0]+x] << ", "; } std::cerr << std::endl; } } } MPI_Finalize(); return 0; }
int main() { std::vector<sf::Texture*> gridObjectTextures; sf::Texture defaultTexture; if ( !defaultTexture.loadFromFile( "res/OpenPlain.png" ) ) { std::cout << "Texture did not load properly!" << std::endl; return -1; } gridObjectTextures.push_back(&defaultTexture); sf::Texture trainTexture; if ( !trainTexture.loadFromFile( "res/Train.png" ) ) { std::cout << "Texture did not load properly!" << std::endl; return -1; } sf::Texture trackTexture; if(!trackTexture.loadFromFile("res/Track.png")){ std::cout << "Texture did not load properly!" << std::endl; return -1; } sf::Texture trackLayerTexture; if(!trackLayerTexture.loadFromFile("res/TrackLayer.png")){ std::cout << "Texture did not load properly!" << std::endl; return -1; } sf::Texture trackLayerDirectionalArrow; if(!trackLayerDirectionalArrow.loadFromFile("res/TrackLayerArrow.png")){ std::cout << "Texture did not load properly!" << std::endl; return -1; } TextureManager man("res/texture_list"); gridObjectTextures.push_back(&trackTexture); FOTHgrid testGrid(GRID_LENGTH, gridObjectTextures); Train painTrain( &trainTexture, sf::Vector2f( 2, 18 ), FOTH::North, (Grid*) &testGrid ); TrackLayer layer(&trackLayerTexture, &trackLayerDirectionalArrow, 2, 14, &testGrid ); //Creating window and setting frame rate sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "FOTH"); window.setFramerateLimit(60); Camera screen(0, (GRID_LENGTH - 10) * testGrid.getGridSpaceDimPxl().y, SCREEN_WIDTH, SCREEN_HEIGHT, &window); sf::Clock timeDiff; //Used to properly advance the game each tick sf::Time tickTime; //The infamous "game loop" while ( window.isOpen() ) { sf::Event event; //Checking window events while( window.pollEvent( event ) ) { if( event.type == sf::Event::Closed ) { window.close(); } else if( event.type == sf::Event::KeyPressed ) { switch( event.key.code ) { case sf::Keyboard::Left: layer.moveAndPlace(FOTH::West); break; case sf::Keyboard::Right: layer.moveAndPlace(FOTH::East); break; case sf::Keyboard::Up: layer.moveAndPlace(FOTH::North); break; case sf::Keyboard::Down: layer.moveAndPlace(FOTH::South); break; default: break; } } else if( event.type == sf::Event::Resized ) { //Maintains correct aspect ratio sf::Vector2u newSize = window.getSize(); newSize.x = int (newSize.y / 10) * 7; window.setSize( newSize ); } } //Takes current value in timeDiff and restarts it //Used to "freeze" a single time value to ensure all tick functions receive the same time tickTime = timeDiff.restart(); painTrain.tick(tickTime); screen.move(0, -1); //Drawing operations window.clear(); testGrid.draw( window, sf::RenderStates::Default ); layer.draw(window, sf::RenderStates::Default); painTrain.draw( window, sf::RenderStates::Default ); window.display(); } return 0; }