Stress for create networks
This commit is contained in:
@@ -2,10 +2,18 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// how create's moving blocks are drawn: kinetic blocks turn by the speed the server puts in their "speed" client data,
|
||||
// as rotating instances, so a block turning steadily costs nothing per frame
|
||||
// as rotating instances, so a block turning steadily costs nothing per frame. they're still while their network is
|
||||
// overstressed
|
||||
import type { ClientContext, Instances, ModelRef, Visual, VisualBlock } from "bworld/client";
|
||||
import type { Face } from "bworld/shared";
|
||||
import { type Axis, FACINGS, kinetic_shape, type KineticParams, type KineticShape } from "./kinetics/connections.ts";
|
||||
import {
|
||||
actual_speed,
|
||||
type Axis,
|
||||
FACINGS,
|
||||
kinetic_shape,
|
||||
type KineticParams,
|
||||
type KineticShape,
|
||||
} from "./kinetics/connections.ts";
|
||||
import { head_offset, type PressShown } from "./processing/press.ts";
|
||||
|
||||
// the crank's handle model has its hub on its south side and its grip reaching north, so it's turned to put north
|
||||
@@ -104,7 +112,7 @@ export function setup(ctx: ClientContext) {
|
||||
const ticks = last === undefined ? 0 : time - last;
|
||||
last = time;
|
||||
// a quarter of the way to the shaft's speed each tick
|
||||
velocity += (speed_of(block) * 0.3 - velocity) * Math.min(1, ticks / 4);
|
||||
velocity += (actual_speed(block) * 0.3 - velocity) * Math.min(1, ticks / 4);
|
||||
angle = (angle + velocity * ticks) % 360;
|
||||
handle.set_rotation(shape.axis, 0, angle);
|
||||
},
|
||||
@@ -112,15 +120,13 @@ export function setup(ctx: ClientContext) {
|
||||
}, { replaces_model: true });
|
||||
}
|
||||
|
||||
const speed_of = (block: VisualBlock) => block.get_client_data<number>("speed") ?? 0;
|
||||
|
||||
// a model turning around the block's axis at its speed, the block's own when not given. returns what turns it again
|
||||
// when the speed changes. on every other block it's offset by half a small cog's tooth, so cogs mesh with the ones
|
||||
// beside them, and on the rest by offset, like KineticBlockEntityVisual.rotationOffset
|
||||
function turning(block: VisualBlock, instances: Instances, shape: KineticShape, model?: ModelRef, offset = 0) {
|
||||
const instance = instances.rotating(model);
|
||||
const angle = should_offset(shape.axis, block) ? 22.5 : offset;
|
||||
const turn = () => instance.set_rotation(shape.axis, speed_of(block), angle);
|
||||
const turn = () => instance.set_rotation(shape.axis, actual_speed(block), angle);
|
||||
turn();
|
||||
return turn;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user