1
0
mirror of https://github.com/p2r3/bareiron.git synced 2025-10-02 07:35:08 +02:00

use VIEW_DISTANCE to determine sent chunk volume

This commit is contained in:
p2r3
2025-08-21 01:36:17 +03:00
parent 2d2c92d1ee
commit ea8be085e8

View File

@@ -120,8 +120,8 @@ void handlePacket (int client_fd, int length, int packet_id) {
// Send spawn chunk first // Send spawn chunk first
sc_chunkDataAndUpdateLight(client_fd, _x, _z); sc_chunkDataAndUpdateLight(client_fd, _x, _z);
for (int i = -2; i <= 2; i ++) { for (int i = -VIEW_DISTANCE; i <= VIEW_DISTANCE; i ++) {
for (int j = -2; j <= 2; j ++) { for (int j = -VIEW_DISTANCE; j <= VIEW_DISTANCE; j ++) {
if (i == 0 && j == 0) continue; if (i == 0 && j == 0) continue;
sc_chunkDataAndUpdateLight(client_fd, _x + i, _z + j); sc_chunkDataAndUpdateLight(client_fd, _x + i, _z + j);
} }
@@ -267,28 +267,34 @@ void handlePacket (int client_fd, int length, int packet_id) {
printf("sending new chunks (%d, %d)\n", _x, _z); printf("sending new chunks (%d, %d)\n", _x, _z);
sc_setCenterChunk(client_fd, _x, _z); sc_setCenterChunk(client_fd, _x, _z);
int count = 0;
clock_t start, end; clock_t start, end;
start = clock(); start = clock();
if (dx != 0 && dz != 0) { while (dx != 0) {
sc_chunkDataAndUpdateLight(client_fd, _x + dx * 2, _z - dx); sc_chunkDataAndUpdateLight(client_fd, _x + dx * VIEW_DISTANCE, _z);
sc_chunkDataAndUpdateLight(client_fd, _x + dx * 2, _z); count ++;
sc_chunkDataAndUpdateLight(client_fd, _x + dx * 2, _z + dz); for (int i = 1; i <= VIEW_DISTANCE; i ++) {
sc_chunkDataAndUpdateLight(client_fd, _x + dx * 2, _z + dz * 2); sc_chunkDataAndUpdateLight(client_fd, _x + dx * VIEW_DISTANCE, _z - i);
sc_chunkDataAndUpdateLight(client_fd, _x + dx, _z + dz * 2); sc_chunkDataAndUpdateLight(client_fd, _x + dx * VIEW_DISTANCE, _z + i);
sc_chunkDataAndUpdateLight(client_fd, _x, _z + dz * 2); count += 2;
sc_chunkDataAndUpdateLight(client_fd, _x - dz, _z + dz * 2); }
} else { dx += dx > 0 ? -1 : 1;
sc_chunkDataAndUpdateLight(client_fd, _x + dx * 2, _z + dz * 2); }
sc_chunkDataAndUpdateLight(client_fd, _x + dx * 2 + dz, _z + dz * 2 + dx); while (dz != 0) {
sc_chunkDataAndUpdateLight(client_fd, _x + dx * 2 - dz, _z + dz * 2 - dx); sc_chunkDataAndUpdateLight(client_fd, _x, _z + dz * VIEW_DISTANCE);
sc_chunkDataAndUpdateLight(client_fd, _x + dx * 2 + dz * 2, _z + dz * 2 + dx * 2); count ++;
sc_chunkDataAndUpdateLight(client_fd, _x + dx * 2 - dz * 2, _z + dz * 2 - dx * 2); for (int i = 1; i <= VIEW_DISTANCE; i ++) {
sc_chunkDataAndUpdateLight(client_fd, _x - i, _z + dz * VIEW_DISTANCE);
sc_chunkDataAndUpdateLight(client_fd, _x + i, _z + dz * VIEW_DISTANCE);
count += 2;
}
dz += dz > 0 ? -1 : 1;
} }
end = clock(); end = clock();
double total_ms = (double)(end - start) / CLOCKS_PER_SEC * 1000; double total_ms = (double)(end - start) / CLOCKS_PER_SEC * 1000;
printf("generated 5 chunks in %.0f ms (%.2f ms per chunk)\n", total_ms, total_ms / 5.0f); printf("generated %d chunks in %.0f ms (%.2f ms per chunk)\n", count, total_ms, total_ms / (double)count);
return; return;
} }