Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simple function
- int get_chunk_index(std::vector<Chunk> chunks, int x, int y) {
- glm::vec3 target = glm::vec3(x * 40, 0, y * 40);
- for (int i = 0; i < chunks.size(); i++) {
- if (chunks[i].trans.GetPos() == target) {
- return i;
- }
- }
- return -1;
- }
- // End simple function
- // Relevant section
- high_resolution_clock::time_point t1 = high_resolution_clock::now();
- bool shouldMakeNew = (get_chunk_index(chunks, i, j) == -1); // nothing's at that place
- high_resolution_clock::time_point t2 = high_resolution_clock::now();
- float duration = duration_cast<microseconds>(t2 - t1).count();
- std::cout << "Time in chunk checking: " << duration / 1000000 << "s \n";
- if (shouldMakeNew) {
- float x = fbm2(glm::vec2(i * 0.1f + goffset, j * 0.2f + goffset)) * 1.5;
- if (x > (1.0f / 4.0f) * 0.0f && x < (1.0f / 4.0f) * 1.0f)
- chunks.push_back(Chunk(Transform(glm::vec3(i, 0, j)), alltexts, offsets[0], 0.03f, 1.4f, &chunks)); // standard
- if (x > (1.0f / 4.0f) * 1.0f && x < (1.0f / 4.0f) * 2.0f)
- chunks.push_back(Chunk(Transform(glm::vec3(i, 0, j)), alltexts, offsets[1], 0.02f, 1.2f, &chunks)); // plains
- if (x > (1.0f / 4.0f) * 2.0f && x < (1.0f / 4.0f) * 3.0f)
- chunks.push_back(Chunk(Transform(glm::vec3(i, 0, j)), allsandtexts, offsets[2], 0.024f, 1.2f, &chunks)); // sand dunes
- if (x > (1.0f / 4.0f) * 3.0f && x < (1.0f / 4.0f) * 4.0f)
- chunks.push_back(Chunk(Transform(glm::vec3(i, 0, j)), alltexts, offsets[3], 0.025f, 1.6f, &chunks)); // hilly
- else
- chunks.push_back(Chunk(Transform(glm::vec3(i, 0, j)), alltexts, offsets[3], 0.025f, 1.6f, &chunks)); // hilly
- std::cout << "biomeselec x : " << x << " \n";
- chunks[chunks.size() - 1].init();
- }
- t1 = high_resolution_clock::now();
- for (int i = 0; i < chunks.size(); i++) {
- if (glm::distance(chunks[i].trans.GetPos(), cam.GetPosition()) < 400)
- chunks[i].draw_chunk(cam);
- }
- t2 = high_resolution_clock::now();
- duration = duration_cast<microseconds>(t2 - t1).count();
- std::cout << "Time in chunk drawing: " << duration / 1000000 << "s \n";
- // End relevant section
- // Complex function
- for (int i = 0; i < chunks.size(); i++) {
- if (glm::distance(chunks[i].trans.GetPos(), cam.GetPosition()) < 400)
- chunks[i].draw_chunk(cam);
- }
- // End complex function
Add Comment
Please, Sign In to add comment