kingtide44

Untitled

Sep 9th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. // Simple function
  2.  
  3. int get_chunk_index(std::vector<Chunk> chunks, int x, int y) {
  4.     glm::vec3 target = glm::vec3(x * 40, 0, y * 40);
  5.     for (int i = 0; i < chunks.size(); i++) {
  6.         if (chunks[i].trans.GetPos() == target) {
  7.             return i;
  8.         }
  9.     }
  10.     return -1;
  11. }
  12.  
  13. // End simple function
  14.  
  15. // Relevant section
  16.         high_resolution_clock::time_point t1 = high_resolution_clock::now();
  17.         bool shouldMakeNew = (get_chunk_index(chunks, i, j) == -1); // nothing's at that place
  18.         high_resolution_clock::time_point t2 = high_resolution_clock::now();
  19.         float duration = duration_cast<microseconds>(t2 - t1).count();
  20.         std::cout << "Time in chunk checking: " << duration / 1000000 << "s \n";
  21.  
  22.         if (shouldMakeNew) {
  23.             float x = fbm2(glm::vec2(i * 0.1f + goffset, j * 0.2f + goffset)) * 1.5;
  24.             if (x > (1.0f / 4.0f) * 0.0f && x < (1.0f / 4.0f) * 1.0f)
  25.                 chunks.push_back(Chunk(Transform(glm::vec3(i, 0, j)), alltexts, offsets[0], 0.03f, 1.4f, &chunks)); // standard
  26.             if (x > (1.0f / 4.0f) * 1.0f && x < (1.0f / 4.0f) * 2.0f)
  27.                 chunks.push_back(Chunk(Transform(glm::vec3(i, 0, j)), alltexts, offsets[1], 0.02f, 1.2f, &chunks)); // plains
  28.             if (x > (1.0f / 4.0f) * 2.0f && x < (1.0f / 4.0f) * 3.0f)
  29.                 chunks.push_back(Chunk(Transform(glm::vec3(i, 0, j)), allsandtexts, offsets[2], 0.024f, 1.2f, &chunks)); // sand dunes
  30.             if (x > (1.0f / 4.0f) * 3.0f && x < (1.0f / 4.0f) * 4.0f)
  31.                 chunks.push_back(Chunk(Transform(glm::vec3(i, 0, j)), alltexts, offsets[3], 0.025f, 1.6f, &chunks)); // hilly
  32.             else
  33.                 chunks.push_back(Chunk(Transform(glm::vec3(i, 0, j)), alltexts, offsets[3], 0.025f, 1.6f, &chunks)); // hilly
  34.             std::cout << "biomeselec x : " << x << " \n";
  35.  
  36.             chunks[chunks.size() - 1].init();
  37.         }
  38.  
  39.         t1 = high_resolution_clock::now();
  40.         for (int i = 0; i < chunks.size(); i++) {
  41.             if (glm::distance(chunks[i].trans.GetPos(), cam.GetPosition()) < 400)
  42.                 chunks[i].draw_chunk(cam);
  43.         }
  44.         t2 = high_resolution_clock::now();
  45.         duration = duration_cast<microseconds>(t2 - t1).count();
  46.         std::cout << "Time in chunk drawing: " << duration / 1000000 << "s \n";
  47.  
  48. // End relevant section
  49.  
  50. // Complex function
  51. for (int i = 0; i < chunks.size(); i++) {
  52.     if (glm::distance(chunks[i].trans.GetPos(), cam.GetPosition()) < 400)
  53.         chunks[i].draw_chunk(cam);
  54. }
  55. // End complex function
Add Comment
Please, Sign In to add comment