Client side chunk sections
This commit is contained in:
@@ -4,10 +4,10 @@
|
||||
// the server sends the world in whole chunks, like minecraft java: nearest first, in batches the client paces, and
|
||||
// only to players who can see them
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { CHUNK_AREA, CHUNK_SIZE } from "@/common/constants.ts";
|
||||
import { CHUNK_AREA } from "@/common/constants.ts";
|
||||
import { decode_level_chunk, encode_level_chunk, is_within_view } from "@/common/chunk_streaming.ts";
|
||||
import { PROTOCOL_VERSION } from "@/common/protocol.ts";
|
||||
import { ChunkColumn } from "@/common/section.ts";
|
||||
import { ChunkColumn, section_index, to_flat } from "@/common/section.ts";
|
||||
import { WorldShape } from "@/common/world_shape.ts";
|
||||
import { sent_block, test_game } from "./helpers.ts";
|
||||
|
||||
@@ -28,7 +28,8 @@ Deno.test("a chunk comes back as it was encoded, whatever its sections hold", ()
|
||||
const decoded = decode_level_chunk(encode_level_chunk(ChunkColumn.from_flat(-3, 70000, shape, blocks, biomes)));
|
||||
assertEquals(decoded.x, -3);
|
||||
assertEquals(decoded.z, 70000);
|
||||
assertEquals(decoded.blocks, blocks);
|
||||
assertEquals(to_flat(decoded.sections), blocks);
|
||||
assertEquals(decoded.sections.map((section) => section.blocks === null).indexOf(false), 1, "uniform ones stay so");
|
||||
assertEquals(decoded.biomes, biomes);
|
||||
|
||||
// one biome, and the receiver's numbering
|
||||
@@ -37,8 +38,8 @@ Deno.test("a chunk comes back as it was encoded, whatever its sections hold", ()
|
||||
(value) => value === 7 ? 70 : value,
|
||||
);
|
||||
assertEquals(one.biomes, biomes.map(() => "bworld:plains"));
|
||||
assertEquals(one.blocks[0], 70);
|
||||
assertEquals(one.blocks[section], 1);
|
||||
assertEquals(one.sections[0].value, 70);
|
||||
assertEquals(one.sections[1].get(0), 1);
|
||||
});
|
||||
|
||||
Deno.test("the view is round, with a ring of chunks past it for meshing its edge", () => {
|
||||
@@ -136,7 +137,7 @@ Deno.test("block changes only go to players who have the chunk, the others get t
|
||||
assertEquals(alice.blocks[game.world.block_ids["bworld:stone"]], "bworld:stone");
|
||||
const chunk = decode_level_chunk(game.world.level_chunk(0, 0));
|
||||
const y = 120 - game.world.shape.min_y;
|
||||
assertEquals(chunk.blocks[y * CHUNK_AREA + 5 * CHUNK_SIZE + 3], game.world.get_block_value(3, 120, 5));
|
||||
assertEquals(chunk.sections[y >> 4].get(section_index(3, y, 5)), game.world.get_block_value(3, 120, 5));
|
||||
});
|
||||
|
||||
Deno.test("/viewdistance caps every player's view distance, and raising it gives them what they asked for", async () => {
|
||||
|
||||
Reference in New Issue
Block a user