refactor(packages): 0.R5 - the shop's week is rolled by its tick and asking reads it; needs start filled and vehicles start with their list; character, physics, vehicles and nativeecho's lazy starts are defaults; --tighten over all four
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
67d8079c47
commit
87259f989d
31 changed files with 104 additions and 111 deletions
|
|
@ -46,7 +46,7 @@ export function phys_remove(physics_st: mut PhysicsState, id: int) -> void {
|
|||
# where a body is, how it is turned and how fast it goes; null when there is no such body
|
||||
export function phys_pose(physics_st: mut PhysicsState, id: int) -> PhysPose {
|
||||
if physics_st.ph_world == null { return null }
|
||||
ph_buffers(physics_st)
|
||||
ph_buffers()
|
||||
if jph_body_read(physics_st.ph_world, id, physics_st.ph_vals) != 0 { return null }
|
||||
let v = physics_st.ph_vals
|
||||
let p = new PhysPose
|
||||
|
|
@ -77,7 +77,7 @@ export function phys_angular_impulse(physics_st: mut PhysicsState, id: int, x: f
|
|||
# how fast it turns about y, radians a second
|
||||
export function phys_spin_y(physics_st: mut PhysicsState, id: int) -> float {
|
||||
if physics_st.ph_world == null { return 0.0 }
|
||||
ph_buffers(physics_st)
|
||||
ph_buffers()
|
||||
jph_body_spin(physics_st.ph_world, id, physics_st.ph_vals)
|
||||
return physics_st.ph_vals[1]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ export property PhysHit {
|
|||
export function phys_ray(physics_st: mut PhysicsState, ox: float, oy: float, oz: float, dx: float, dy: float, dz: float, mask: int) -> PhysHit {
|
||||
let h = new PhysHit
|
||||
if physics_st.ph_world == null { return h }
|
||||
ph_buffers(physics_st)
|
||||
ph_buffers()
|
||||
h.body = jph_ray(physics_st.ph_world, ox, oy, oz, dx, dy, dz, mask, physics_st.ph_vals)
|
||||
if h.body == -1 { return h }
|
||||
let v = physics_st.ph_vals
|
||||
|
|
@ -49,7 +49,7 @@ export function phys_step_top(physics_st: PhysicsState, x: float, z: float, r: f
|
|||
export function phys_overlap(physics_st: mut PhysicsState, x: float, y: float, z: float, r: float, mask: int) -> []int {
|
||||
let out = new []int
|
||||
if physics_st.ph_world == null { return out }
|
||||
ph_buffers(physics_st)
|
||||
ph_buffers()
|
||||
let n = jph_overlap(physics_st.ph_world, x, y, z, r, mask, physics_st.ph_ids, PH_CAP)
|
||||
for i in 0 .. n { push(out, physics_st.ph_ids[i]) }
|
||||
return out
|
||||
|
|
@ -66,7 +66,7 @@ export property PhysPush {
|
|||
export function phys_push(physics_st: mut PhysicsState, x: float, z: float, r: float, y0: float, y1: float, mask: int) -> PhysPush {
|
||||
let p = new PhysPush
|
||||
if physics_st.ph_world == null { return p }
|
||||
ph_buffers(physics_st)
|
||||
ph_buffers()
|
||||
p.n = jph_push(physics_st.ph_world, x, z, r, y0, y1, mask, physics_st.ph_vals)
|
||||
p.x = physics_st.ph_vals[0]
|
||||
p.z = physics_st.ph_vals[1]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
# a world for up to max_bodies (threads 0: the cores less one, at most four); false if C refused
|
||||
export function phys_open(physics_st: mut PhysicsState, max_bodies: int, threads: int) -> bool {
|
||||
phys_close(physics_st)
|
||||
ph_buffers(physics_st)
|
||||
ph_buffers()
|
||||
physics_st.ph_world = jph_world_new(max_bodies, threads)
|
||||
physics_st.ph_gen += 1
|
||||
physics_st.ph_acc = 0.0
|
||||
|
|
@ -39,7 +39,7 @@ export function phys_close(physics_st: mut PhysicsState) -> void {
|
|||
|
||||
function ph_keep(physics_st: mut PhysicsState, s: pointer) -> int {
|
||||
if s == null { return -1 }
|
||||
ph_buffers(physics_st)
|
||||
ph_buffers()
|
||||
push(physics_st.ph_shapes, s)
|
||||
return len(physics_st.ph_shapes) - 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ export const PH_CAP: int = 512 # contacts drained a step, queries' buffer
|
|||
|
||||
export state PhysicsState {
|
||||
ph_world: pointer = null
|
||||
ph_shapes: []pointer = null # a shape id is its place here; null once freed
|
||||
ph_shapes: []pointer = new []pointer # a shape id is its place here; null once freed
|
||||
ph_step: float = 0.016666668 # seconds a step
|
||||
ph_sub: int = 1 # collision steps in each
|
||||
ph_max_steps: int = 4 # a slow frame catches up this far and no further
|
||||
|
|
@ -44,29 +44,22 @@ export state PhysicsState {
|
|||
ph_steps: int = 0
|
||||
ph_gen: int = 0 # how many worlds have been opened: an id from an older one is stale
|
||||
ph_hard: float = 2.0 # metres a second: a contact under this is not a fact
|
||||
ph_floats: []int = null # buoyant bodies' ids
|
||||
ph_float_k: []float = null # and theirs: buoyancy, linear drag, angular drag, wet
|
||||
ph_floats: []int = new []int # buoyant bodies' ids
|
||||
ph_float_k: []float = new []float # and theirs: buoyancy, linear drag, angular drag, wet
|
||||
ph_rx: float = 0.0 # where the last phys_resolve put a body
|
||||
ph_rz: float = 0.0
|
||||
ph_walkers: []pointer = null # a walker id is its place here; null once removed
|
||||
ph_ids: []int = null
|
||||
ph_vals: []float = null
|
||||
ph_facts: Queue<PhysFact> = null
|
||||
ph_walkers: []pointer = new []pointer # a walker id is its place here; null once removed
|
||||
ph_ids: []int = words(PH_CAP * 2)
|
||||
ph_vals: []float = floats(PH_CAP * 4)
|
||||
ph_facts: Queue<PhysFact> = ph_facts__new()
|
||||
}
|
||||
|
||||
# the facts, oldest first
|
||||
export function phys_facts(physics_st: mut PhysicsState) -> Queue<PhysFact> {
|
||||
if physics_st.ph_facts == null { physics_st.ph_facts = queue_new("physics.facts") }
|
||||
export function phys_facts(physics_st: PhysicsState) -> Queue<PhysFact> {
|
||||
return physics_st.ph_facts
|
||||
}
|
||||
|
||||
function ph_buffers(physics_st: mut PhysicsState) -> void {
|
||||
if physics_st.ph_ids == null { physics_st.ph_ids = words(PH_CAP * 2) }
|
||||
if physics_st.ph_vals == null { physics_st.ph_vals = floats(PH_CAP * 4) }
|
||||
if physics_st.ph_shapes == null { physics_st.ph_shapes = new []pointer }
|
||||
if physics_st.ph_floats == null { physics_st.ph_floats = new []int }
|
||||
if physics_st.ph_float_k == null { physics_st.ph_float_k = new []float }
|
||||
if physics_st.ph_walkers == null { physics_st.ph_walkers = new []pointer }
|
||||
function ph_buffers() -> void {
|
||||
}
|
||||
|
||||
# a step's length, its collision steps, and how hard a contact must be to be a fact
|
||||
|
|
@ -75,3 +68,4 @@ export function phys_config(physics_st: mut PhysicsState, step: float, sub: int,
|
|||
physics_st.ph_sub = sub
|
||||
physics_st.ph_hard = hard
|
||||
}
|
||||
function ph_facts__new() -> Queue<PhysFact> { return queue_new("physics.facts") }
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export function phys_advance(physics_st: mut PhysicsState, dt: float) -> int {
|
|||
# exactly one step: the water, Jolt, then the contacts that matter as facts
|
||||
export function phys_step(physics_st: mut PhysicsState) -> void {
|
||||
if physics_st.ph_world == null { return }
|
||||
ph_buffers(physics_st)
|
||||
ph_buffers()
|
||||
ph_buoy_all(physics_st)
|
||||
jph_world_step(physics_st.ph_world, physics_st.ph_step, physics_st.ph_sub)
|
||||
physics_st.ph_steps += 1
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ function ph_walker(physics_st: PhysicsState, id: int) -> pointer {
|
|||
# r wide and h tall, feet at (x, y, z), mass in kg; -1 with no world
|
||||
export function phys_walker_add(physics_st: mut PhysicsState, r: float, h: float, x: float, y: float, z: float, max_slope: float, mass: float) -> int {
|
||||
if physics_st.ph_world == null { return -1 }
|
||||
ph_buffers(physics_st)
|
||||
ph_buffers()
|
||||
push(physics_st.ph_walkers, jph_char_new(physics_st.ph_world, r, h, x, y, z, max_slope, mass))
|
||||
return len(physics_st.ph_walkers) - 1
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ export function phys_walker_step(physics_st: mut PhysicsState, id: int, dt: floa
|
|||
export function phys_walker_pose(physics_st: mut PhysicsState, id: int) -> PhysWalk {
|
||||
let k = ph_walker(physics_st, id)
|
||||
if k == null { return null }
|
||||
ph_buffers(physics_st)
|
||||
ph_buffers()
|
||||
jph_char_read(k, physics_st.ph_vals)
|
||||
let v = physics_st.ph_vals
|
||||
let p = new PhysWalk
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const PH_K: int = 4
|
|||
|
||||
# buoyancy 1 floats level with the surface, more rides higher; drags in 1/s
|
||||
export function phys_float(physics_st: mut PhysicsState, id: int, buoyancy: float, linear_drag: float, angular_drag: float) -> void {
|
||||
ph_buffers(physics_st)
|
||||
ph_buffers()
|
||||
phys_sink(physics_st, id)
|
||||
push(physics_st.ph_floats, id)
|
||||
push(physics_st.ph_float_k, buoyancy)
|
||||
|
|
@ -56,7 +56,7 @@ function ph_buoy_one(physics_st: mut PhysicsState, i: int, id: int, x: float, z:
|
|||
physics_st.ph_float_k[k + 3] = float(wet)
|
||||
}
|
||||
|
||||
function ph_splash(physics_st: mut PhysicsState, id: int, x: float, y: float, z: float) -> void {
|
||||
function ph_splash(physics_st: PhysicsState, id: int, x: float, y: float, z: float) -> void {
|
||||
let f = new PhysFact
|
||||
f.what = PHYS_SPLASH
|
||||
f.a = id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue