Verdigris torch
This commit is contained in:
+37
-10
@@ -1,13 +1,15 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// how long verdigris wire takes on a stone floor, see "Performance" in REDSTONE.md, and how many set_block messages a
|
||||
// how long verdigris takes on a stone floor, see "Performance" in REDSTONE.md, and how many set_block messages a
|
||||
// player watching would get: placing a 1000 wire zigzag one wire at a time, a lever switching it, a block placed and
|
||||
// taken away beside it while it's powered, a wire broken out of its middle and put back, and a lever switching a 64×64
|
||||
// grid. with the net index a wire took 0.5 ms to place however big its net, a block beside the powered zigzag 0.1 ms
|
||||
// and no wire messages, and switching took 15 to 20 ms for the zigzag and 50 to 60 ms for the grid, about 15 µs a
|
||||
// wire. walking the net on every change, a wire took 30 ms to place in the zigzag and 400 ms in the grid, a block
|
||||
// beside 20 ms, and switching 35 to 45 ms and 135 ms. repeater clocks and torch towers come with repeaters and torches
|
||||
// taken away beside it while it's powered, a wire broken out of its middle and put back, a lever switching a 64×64
|
||||
// grid, and a lever switching a tower of 50 torches. with the net index a wire took 0.5 ms to place however big its
|
||||
// net, a block beside the powered zigzag 0.1 ms and no wire messages, and switching took 15 to 20 ms for the zigzag and
|
||||
// 50 to 60 ms for the grid, about 15 µs a wire. walking the net on every change, a wire took 30 ms to place in the
|
||||
// zigzag and 400 ms in the grid, a block beside 20 ms, and switching 35 to 45 ms and 135 ms. the tower's 50 torches
|
||||
// changing over 102 ticks took about 3 ms more than the ticks did with nothing switched. repeater clocks come with
|
||||
// repeaters
|
||||
// deno run -A tools/verdigris_bench.ts
|
||||
import type { Face } from "../common/mod_api/shared.ts";
|
||||
import { AIR_ID } from "../common/protocol.ts";
|
||||
@@ -84,9 +86,9 @@ async function floor() {
|
||||
}
|
||||
return `${(ms / count).toFixed(2)} ms, ${sent / count} set_block (${wires / count} wire)`;
|
||||
};
|
||||
const power = (x: number, y: number, z: number) =>
|
||||
block_states(t.game.world.get_block_value(x, y, z), t.game.world.get_block_info(x, y, z)!).power;
|
||||
return { t, use, lay, lever, measure, power };
|
||||
const states = (x: number, y: number, z: number) =>
|
||||
block_states(t.game.world.get_block_value(x, y, z), t.game.world.get_block_info(x, y, z)!);
|
||||
return { t, hold, use, lay, lever, measure, states };
|
||||
}
|
||||
|
||||
// 1000 cells in rows of 40 along x, every other z, each row joined to the next at alternating ends
|
||||
@@ -111,7 +113,7 @@ function zigzag(): Pos[] {
|
||||
console.log(` lever switching them: ${f.measure(20, () => f.use(...lever, "top"))}`);
|
||||
f.use(...lever, "top");
|
||||
f.t.take(1);
|
||||
if (f.power(...cells.at(-1)!) !== 15) throw new Error("the zigzag isn't powered");
|
||||
if (f.states(...cells.at(-1)!).power !== 15) throw new Error("the zigzag isn't powered");
|
||||
// beside a wire on two rows
|
||||
console.log(
|
||||
` a block beside them placed and taken away: ${
|
||||
@@ -137,4 +139,29 @@ function zigzag(): Pos[] {
|
||||
);
|
||||
console.log(` lever switching it: ${f.measure(10, () => f.use(...lever, "top"))}`);
|
||||
}
|
||||
|
||||
{
|
||||
const f = await floor();
|
||||
// 50 torches, each on top of a block on top of the one below, and a lever on the side of the bottom block
|
||||
const height = 50;
|
||||
f.hold("bworld:verdigris_torch");
|
||||
for (let i = 0; i < height; i++) {
|
||||
f.t.game.set_block(0, 100 + i * 2, 0, "bworld:stone");
|
||||
f.use(0, 100 + i * 2, 0, "top");
|
||||
}
|
||||
f.hold("bworld:lever");
|
||||
f.use(0, 100, 0, "east");
|
||||
// each torch changes 2 ticks after the one under it
|
||||
const ticks = height * 2 + 2;
|
||||
const run = () => {
|
||||
for (let i = 0; i < ticks; i++) f.t.game.tick();
|
||||
};
|
||||
run();
|
||||
const top = () => f.states(0, 101 + (height - 1) * 2, 0).lit;
|
||||
const was = top();
|
||||
const idle = f.measure(4, run);
|
||||
console.log(`a ${height} torch tower switched by a lever, over the ${ticks} ticks it takes:`);
|
||||
console.log(` ${f.measure(10, () => (f.use(1, 100, 0, "top"), run()))}, against ${idle} with nothing switched`);
|
||||
if (top() !== was) throw new Error("the top torch didn't change back");
|
||||
}
|
||||
Deno.exit(0);
|
||||
|
||||
Reference in New Issue
Block a user