refactor: move world concepts into engine

This commit is contained in:
Toad 2026-08-24 15:17:53 +02:00
parent eeedcb8e48
commit 2d15c7ab8d
52 changed files with 3298 additions and 1558 deletions

View file

@ -1,15 +1,28 @@
import { Terrain } from "../../Terrain"
import type { Mesh } from "../../../engine/scene/Mesh"
import type { Mob } from "../Mob"
import type { Entity } from "../../../engine/scene/Actor"
import { Terrain, type Terrain as Ground } from "../../../engine/world/Terrain"
import { Mesh, type Mesh as Geometry } from "../../../engine/scene/Mesh"
import type { Material } from "../../../engine/render/Material"
import type { ActorDefinition } from "../../../engine/scene/Actor"
import { Mob, type MobState } from "../Mob"
import { ellipsoid, nextRand, ovoidZ, wanderHeading, wing } from "./mobkit"
export const bee: Entity<Mob, Terrain> = {
name: "bee",
build,
update,
boundingRadius: 0.5,
bodyHeight: 0.5,
export type Bee = ActorDefinition<MobState, Ground>
export namespace Bee {
export function create(material: Material): Bee {
const mesh = Mesh.create()
build(mesh)
return {
prototype: {
groups: [{ mesh, material }],
radius: 0.6,
minY: -0.5,
maxY: 1,
},
update,
transform: Mob.transform,
collider: (state) => Mob.collider(state, 0.5, 0.5, false),
}
}
}
const LEASH = 6
@ -20,7 +33,7 @@ const HOVER = 1.1
const BOB_AMP = 0.18
const BOB_FREQ = 3
function build(mesh: Mesh): void {
function build(mesh: Geometry): void {
// Fore-aft ovoid body striped along its length, a dark head at the front, two
// pale wings. UVs: bee texture is stripe bands (left), head-dark (mid), wing-pale
// (right); the body maps v along z so the stripes band across it.
@ -30,7 +43,7 @@ function build(mesh: Mesh): void {
wing(mesh, -1, 0.83, 0.99, 0, 1)
}
function update(mob: Mob, dt: number, terrain: Terrain): void {
function update(mob: MobState, dt: number, terrain: Ground): void {
mob.phase += dt
mob.timer -= dt
if (mob.timer <= 0) {