Commit Graph
100 Commits
Author SHA1 Message Date
robert 18ab509554 Fix: automatic var to use *all* deps, not first
The tarball target depends on all the dependencies, but the automatic
variable `$<` means "the first dependency". It should be "all deps", or
`$^`.
2025-10-30 09:04:56 -05:00
robert 615bf79f30 First draft of page structure, basic styling
I'll revise the text at some point, and the styling is *extremely*
basic, but it's a start.
2025-10-29 16:33:11 -05:00
robert 71c095088c Fix: WASM target needs to depend on Cargo.* files
The binary output depends on the configuration input, so maybe tell
`make` about all of the inputs...
2025-10-29 11:35:55 -05:00
robert 7482130ac2 Don't have Bevy resize to full-screen
Now that I have a custom canvas, Bevy should adopt that as it's render
target rather than further modifying it.
2025-10-28 16:23:17 -05:00
robert e16c0e2e32 Add and use a custom canvas element on the page
Tell bevy to find the canvas with ID "#boids-canvas" instead of creating
it's own.
2025-10-28 16:12:09 -05:00
robert eca864ec8e Use vars to hold target & profile in makefile_web
I might sometimes build different profiles, so this gives me somewhere
to change them. It *does not work* for debug builds because of how cargo
works. So that sucks.

I can't think of a reason anyone would seriously want to change the
target, but I've made that a variable, too. WASM64 exists, but I can't
get a read on it's availability across browsers. The benefit seems to be
accessing >4GB of memory, which is not important for this project. Other
targets are for "desktop" platforms and so shouldn't be using the
makefile.
2025-10-28 16:10:28 -05:00
robert 0358935bf6 Group the WASM & JS targets so they're built once
https://www.gnu.org/software/make/manual/html_node/Multiple-Targets.html

The previous recipe told Make that each file could be produced by
running wasm-bindgen. The more correct expression is that *both* files
will be produced at the same time.

Now Make knows to only invoke the command one time to get both files if
either is out of date. Previously, multi-job builds (`-j2`) could build
the files twice -- one invocation for each out-of-date file.
2025-10-28 15:04:45 -05:00
robert 7408f056f6 Fix: use correct name suffix for the WASM file
Maybe I should have spent more time manually running each of the steps.
Eh, whatever. Bug found and fixed.
2025-10-28 15:00:28 -05:00
robert 370fe85d6c Make wasm binary target depend on source files
Now Make will know to rebuild the WASM binary if the source code
changes... because I forgot to do that, too. :v
2025-10-28 14:59:47 -05:00
robert 943483503c Turn output folder into an order-only prerequisite
This makes the output folder "required to exist" and not "required to be
more recent."

The folder's timestamp is updated when files are written into it. The
files inside depend on the folder existing. The result is that the WASM
and JS files are considered very slightly older than the folder that
contains them. The result is that the folder is up-to-date but it's
contents are not, thus re-building them and *again* updating the folder
timestamp. The makefile was stuck constantly rebuilding things that are
actually up-to-date.
2025-10-28 12:46:37 -05:00
robert 3c0cf85da5 Drop extra suffix in wasm-bindgen output name
Oops, it's not supposed to have a file suffix! It's a bit annoying that
it still produces both a WASM and JS file, just not the right ones (and
no _bg.wasm at all). Especially without any warning that it is doing
something different than normal. Oh well.
2025-10-28 12:42:44 -05:00
robert 39925b0c4e Rename WASM & JS output to match HTML
The index.html file calls for a "boids.js", so I need the Makefile to
produce one. I could change it, but that's off-topic for now so I won't.
2025-10-28 12:42:39 -05:00
robert 4eb4fefeb2 Add a Makefile to make web builds more ergonomic
Call with `make -f makefile_web` to produce a web root for serving. Use
target "boids_web_root.tar" to bundle the files into a tarball. For...
publishing... or something.

The `wasm-server-runner` program seems to supply it's own index.html and
is doing *something* regarding MIME types -- hosting a dev build of the
Boids program results in the browser complaining about "" (empty string)
being an invalid MIME type.

I want my own index.html during testing, and I can't figure out why the
MIME type info is wrong. I've decided to automate the web-root build
process and serve it up with whatever webserver I have on hand.
2025-10-28 12:22:26 -05:00
robert 57a4d0924d Fix: Missing destination in Docker copy instr.
check / stable / fmt (push) Successful in 45s
check / beta / clippy (push) Failing after 51s
check / stable / clippy (push) Failing after 47s
check / semver (push) Failing after 5m38s
check / nightly / doc (push) Successful in 2m12s
check / ubuntu / stable / features (push) Successful in 2m21s
check / ubuntu / 1.79.0 (push) Failing after 27s
I don't really know how I did that, or how I got a build up on Fly.io
without committing the fix. Well, anyway... it's done now.
2025-10-03 13:01:47 -05:00
robert 0c8d39d483 Fix casing in Dockerfile
check / stable / fmt (push) Successful in 22s
check / beta / clippy (push) Failing after 56s
check / stable / clippy (push) Failing after 48s
check / semver (push) Failing after 5m45s
check / nightly / doc (push) Successful in 2m18s
check / ubuntu / stable / features (push) Successful in 2m25s
check / ubuntu / 1.79.0 (push) Failing after 27s
2025-09-27 10:27:27 -05:00
robert 6009dae6d8 Mark crate version 0.3.0, upadate lockfile 2025-09-27 10:26:02 -05:00
robert 085b855ef7 Disable the minimal-version pins 2025-09-27 10:25:47 -05:00
robert d808bda765 Use busybox:musl to save a couple more MB
Yay for tiny Linux userspaces.
2025-09-04 09:29:07 -05:00
robert 6b7692cf78 Build using the locked dependency versions
I want to at least have the smell of reproducible builds, so I'll make
the image build using the lockfile. Otherwise the build-time dependency
information gets lost.
2025-09-04 09:29:03 -05:00
robert 0ad31b30df Check-in the fly.toml config file 2025-09-04 09:17:21 -05:00
robert 5e4b7f04b7 Dockerfile for WASM build's webserver 2025-09-04 09:07:31 -05:00
robert 01c50e4bb6 Add an index.html file, taken from Bevy Cheatbook
https://bevy-cheatbook.github.io/platforms/wasm/webpage.html

I need a page to give the user, which loads some JS, which loads the
WASM file. The JS and WASM are both generated by the wasm-bindgen tool.
2025-09-03 17:04:43 -05:00
robert 60417d6956 Make the WASM build profile even smaller 2025-09-03 16:15:48 -05:00
robert 2d568455d8 Use whole browser window
Taken from
https://johanhelsing.studio/posts/extreme-bevy
2025-09-03 16:14:38 -05:00
robert df86f05876 Mark v0.2.0, update lockfile 2025-09-03 14:46:25 -05:00
robert 68d6de9a83 Add a WASM build configuration
The config.toml lets me run `cargo run --target wasm32-unknown-unknown`
and host a dev server.

I've adjusted the Cargo.toml to use the kdtree_rayon feature by default,
but disable the Rayon feature for WASM builds (because it doesn't work).
2025-09-03 14:41:53 -05:00
robert ccd8a12b79 Autoformat 2025-09-03 14:27:28 -05:00
robert f2a71e712a Put the boid separation range back to 1/4 not 1/8
With the 1.0 radius boids (instead of whatever `Circle::default()`
uses), a separation activation of 1/4 the range looks more visually
appealing (imo).
2025-09-03 14:25:16 -05:00
robert dca8bcdaa7 Add speed_controller to maintain system energy
The starting velocities going outwards in a circle means that the sum of
energy in the system is 0. As the boids come back together, they will
slow down to fall into a lattice. This is interesting, but not the
flocking behavior Boids are supposed to have.

I've replaced the `space_brakes` function with this new speed controller
to keep boids moving between two speeds. Anything too slow will speed up
along it's current vector, and anything too fast will slow down.
2025-09-03 14:20:17 -05:00
robert e6e56506f8 Fix: alignment should align to vel, not impulse
I need to apply an impulse to match the velocities, but the previous
version was trying to match the forces.
2025-09-03 14:11:18 -05:00
robert bc0630b4ae Fix: off-by-one error in alignment averaging
The "length" is actually the `enumerate()` index, which is one less than
the item count. The previous version was not using the average, and may
have been deviding by 0 for boids with exactly one neighbor.
2025-09-03 14:09:40 -05:00
robert 76a6b4f999 New cohesion rule function 2025-09-03 14:07:50 -05:00
robert 451311126d New separation rule function 2025-09-03 14:07:34 -05:00
robert 7b380196a5 Filter-map the entities to avoid self-alignment
The boids shouldn't try to align with themselves. That doesn't really
make any sense.
2025-09-03 12:23:53 -05:00
robert 8b61d38636 Make keyboard control forces, not velocities
The keyboard input should apply a force, not modify the velocity. Right
now, there is no Mass component, but in the future there might be. I've
just fixed a broken physics integrator made by bad assumptions, too, so
I'm goig to do this for consistency if nothing else.
2025-09-03 12:23:53 -05:00
robert b3cf47e684 Remove BoidBundle, use required-components instead 2025-09-03 12:23:53 -05:00
robert 69403bc6ca Fix the physics integrator
The velocity component never got updated. Instead, the system was only
calculating the current frame's deltaV. That instantaneous dV and any
velocity that *did* get assigned (bundle insertion, keyboard control)
would be added to the position.

Now forces are integrated into velocity, and velocity is integrated into
position. You know... like a real integration function.
2025-09-03 12:23:53 -05:00
robert a6240c844a Make another new alignment system 2025-09-03 12:23:53 -05:00
robert 3eb23fb4bf Move physics parts to a physics module 2025-09-03 12:23:53 -05:00
robert 532025b42f Bump Rust edition to 2024 2025-08-30 15:45:20 -05:00
robert 4150f85ccc Rename & restructure birdoids module
The module isn't the plugin, so it's going to be called simply
"birdoids" going forward.

I've turned it into a folder and a `mod.rs` so I can slap down a small,
custom physics system.
2025-08-30 15:39:41 -05:00
robert 214da65db5 Switch off deprecated functions, fix clippy lints 2025-08-30 15:39:41 -05:00
robert 325e515a7b Autoformat 2025-08-30 15:39:41 -05:00
robert e85114c4c8 Adjust code for Bevy 0.14 -> 0.16 upgrade
Now the program builds again.
2025-08-30 15:39:41 -05:00
robert feeeb15d22 Begin v0.2.0-dev and upgrade Bevy version
Resuming work on this project. New crate version, new Bevy version.
2025-08-30 15:39:41 -05:00
robert a0292eb789 Add a "mini" build profile
It's like release, but with LTO and LLVM's `-Oz` size optimization.
2025-05-16 18:37:34 -05:00
robert 076fcd3c3f Full fat LTO for the very best size reduction 2024-12-29 15:59:32 -06:00
robert d181a690f8 Bump MSRV for named profiles to work
Yay for cargo-msrv
2024-09-12 22:53:53 -05:00
robert 41b487e70e Pin grand-dependencies for -Zminimal-versions
This pins the dependencies of our dependencies so that the
`-Zminimal-versions` flag of cargo nightly will result in a working
build. Ideally the package authors would have their versions set
correctly. The flag is on nightly for a reason, though. Oh well.
2024-09-12 22:22:55 -05:00
robert b75c05940d Run cargo fmt before merging branch 2024-07-16 09:31:15 -05:00
robert e09399cc23 Update force functions to use Option<Force> 2024-07-16 09:02:09 -05:00
robert abd107d04a Update tests: Force return needs an Option<>
The force functions are discontinuous at (0,0), and as such need to
return an optional. Without this, I'll be feeding NaNs back into the
program, which will propogate and cause a total simulation collapse.
2024-07-16 08:50:26 -05:00
robert 519482aaf3 Rename separation_force parameters 2024-07-15 14:42:39 -05:00
robert a75704fb49 Placeholder for separation on div-0 error
This calculation should produce an infinity, or NaN. Either way, it's an
error that definitely still exists. I'll make a test for it, and then
fix it at some point. This is so that I don't forget.
2024-07-15 14:41:46 -05:00
robert 60a0357b0d Tests were missing the BOID_VIEW_RANGE
I love it when I need to test my tests. It's just so easy to do.
2024-07-15 14:40:18 -05:00
robert 82dabcfabe Fix: Cohesion function was accepting bad input
The cohesion function would accept inputs over the range (-1, 1) when it
has been designed to work over (0, 1). This changes the math to
calculate the magnitude separately and re-apply it to the pointing
vector.
2024-07-15 13:48:13 -05:00
robert c48fe1ed2e Add unit tests for force functions
Finally time to just use the unit testing tools Cargo gives me. These
are all a bunch of simple tests to verify that the functions work as
expected.

... They don't. I made the assertion that the input ranges are (0, 1)
when, in fact, they are not. The boid's view distance is scaled into
a unit vector space. The trouble with this is that a valid coordinate
is (-1, 0). The force functions don't have the correct shape at this
range.

The fix is to get the absolute value -- the vector's magnitude -- and
feed that through the force calculation function. This way it *is* in
the range (0, 1). The magnitude can then be multiplied back over the
deviation vector to get a proper force application.

This unit vector can then optionally be multiplied back up to have more
exaggerated effects. The {COHESION,SEPARATION,ALIGNMENT}_FACTOR's can
pick up that role again.
2024-07-15 11:38:39 -05:00
robert 651ed774c3 Move separation_force down with cohesive_force 2024-07-15 10:14:13 -05:00
robert 283a0bdde3 Add separation_force function 2024-07-15 10:10:56 -05:00
robert 6c38083e6d Fix: Return Force instead of Vec2 2024-07-15 10:04:41 -05:00
robert 930aa2e75d Add cohesive_force function 2024-07-15 10:01:43 -05:00
robert 18885d9b94 Rename Acceleration to Force
Closes #2

Acceleration is mass * force.
This doesn't materially change anything, but it will make it easier to
give the boids a mass component. The change will not require updates to
most of the systems, only the physics integrator and the boids bundle.
2024-07-12 16:47:27 -05:00
robert 092f0a25dd Give space_brakes a const coefficient 2024-07-12 14:49:17 -05:00
robert 27cf0f390b Drop unneeded use line 2024-07-12 10:10:33 -05:00
robert f9ce96bbce cargo fmt again 2024-07-12 10:00:27 -05:00
robert a161aacaca Crank up the forces to see the boids move!
The Boids algorithm functions need a lot of work, but the cohesion and
separation functions appear to nominally perform their stated goal.

Both are constant forces across their whole range, so there is a jerking
motion as things cross in and out of the activation boundaries.

I think the alignment function breaks the laws of thermodynamics, as
well. Oh well, that's what the spacebrakes system is for.
2024-07-11 17:00:12 -05:00
robert 32991d3e37 Fix: Acceleration needs to be reset to 0
The physics integrator is real scuffed. Nothing has mass, and no forces
are applied. Instead, objects affect each other's acceleration. It acts
functionally like a force accumulator where everything has a mass of 1.

Under this model, it must be cleared each frame so that it can be
re-accumulated during the next physics calculation cycle.

This bug was spotted because of anomolous behavior of the velocity
pointer. Nearly stationary boids would have a rather large (especially
after the coefficient reduction earlier) velocity. I noticed this
earlier when building the debug tool and thought it was an error in
the calculations. There might still be bugs, I still need to test, but
that particular one seems to have been a position integrator error.
2024-07-11 16:56:47 -05:00
robert bb33fda018 Fix: spatial tree update frequency is too low
The reubild frequency of the spatial tree was causing calculations to
operate on old information. This is not the intended behavior. The
default schedule seems to be to run every frame.

I also lowered the debug pointer coefficient. Boids moving at a normal
velocity are actually fast enough to draw a meaningful line. Maybe I'll
switch it into some kind of exponential space so small changes are
visible, and big changes don't draw a line all the way across the
screen.
2024-07-11 16:53:38 -05:00
robert 8001bbceb9 Refactor alignment() to use velocity_of_boids 2024-07-11 16:23:53 -05:00
robert d2a9d1214a Refactor cohesion() to use center_of_boids()
I made the center_of_boids() and velocity_of_boids() functions so that
they can be reused in the debug overlay operations. I should probably
use them in the main system, too.
2024-07-11 16:13:34 -05:00
robert e38df137a8 Move util functions below systems functions
I'm trying to group the kinds of parts together so that they're easier
to locate.
2024-07-11 15:24:57 -05:00
robert 336992573e Completed velocity pointer gizmo
Right-clicking toggles velocity sensing mode and the cursor gets a line
that indicates the average velocity of the targeted points.

There is a coefficient of 50.0 on the pointer magnitude. The boids move
so slowly that the line is very short without this magnification.

There is also something wrong with the math. The boids expand and slow
down, but the velocity vector does not reflect this. It *grows* slightly
and then stays at that size as the boids slowly approach a stop.

When writing the average velocity function, I realized that it is
**exactly** the same as the center of mass function. They're both just
averaging a bunch of points. Both functions are implemented as pass-
through calls to a general purpose Vec2 averaging function.

The `impl Iterator<...>...` *is* actually necessary because of the use
of `map()`s to filter out the boids parts from the spatial tree.
2024-07-11 14:46:36 -05:00
robert ac25a41f77 Fix: off-by-one in the boid count enumeration
`enumerate()` begins counting at 0, so I was dividing the sum by one
less than the count of boids. Thus the over-expanded result.

I should do unit testing.

I should rewrite this function to take the vector directly. I *know*
that the input is a vector at all times. Mmh.
2024-07-11 14:13:07 -05:00
robert a0d2e2b467 Debug draw CoM is working!... CoM has error
The debug tool can draw a center-of-mass dot, but it doesn't look like
a sensible location. Time to check on the math, I guess.
2024-07-11 14:02:55 -05:00
robert c75374a566 Cursor gizmo mode changing inputs are working 2024-07-11 11:14:56 -05:00
robert 3b03be7dbf Scaffolding for selection & scanning modes
The gizmo currently draws as an annulus with the intention that it is an
area selection tool. These new components will serve as mode selectors
so that different selection modes can be used.
2024-07-11 09:32:37 -05:00
robert 2cbe15e72b New DebugUI plugin
This plugin is meant to have some add-ons to interact with the
simulation to provide insight.

This first change adds a cursor under the mouse with the intention that
it's circle can be used as a reticule for targeting boids. Hovering over
a cluster and getting their CoM or velocities, for example.
2024-07-11 09:16:42 -05:00
robert 9f37addb5f This is only a Boids project, now. Drop others.
The examples and learning plugins have outlived their usefulness, and
this repo already has substantial history in being a boids plugin. I'm
renaming the crate (and repo, but that isn't visible to git) to treat
this simply as a boids repo.
2024-07-11 08:33:33 -05:00
robert d99326d849 Braking function to slow all boids
This will help during debugging to prevent things from screaming around
the play area. Especially when the acceleration routines are unbounded
and can infinitely add energy to the system.
2024-07-10 16:27:21 -05:00
robert 7eb65df7cf Alignment function complete, seems off... 2024-07-10 16:26:56 -05:00
robert 1fc79ae7bb Spawn boids in larger ring so they don't pop apart
The separation function causes the boids to rush away from each other
when the simulation starts because they're all stacked at the origin.

Spawn them out in a ringso that this doesn't happen nearly as
aggressively.
2024-07-10 15:03:49 -05:00
robert 806c23c620 Use 1.0 for steering, and small init velocity 2024-07-10 14:53:10 -05:00
robert 8fb11fe800 Make cohesion() affect the acceleration 2024-07-10 14:38:41 -05:00
robert eb6d4b2e32 Further rewrite of cohesion to match separation 2024-07-10 14:35:46 -05:00
robert 95cdd90485 Fix over-application of cohesion forces
The cohesion function was erroneously applying forces to boids that
shouldn't be experiencing them. It shouldn't be iterating over all
boids-with-velocity and adding speed. It should be applying that force
only to the one boid that the loop is examining at that iteration.

I also cleaned up the signature to have just one query struct. I had it
split as two because I was getting issues with mutability. The fix was
to make the query mutable, and then keep the Transforms as immutable
references. This way I can reach through and update the Velocity alone.
2024-07-10 14:03:38 -05:00
robert a0323af081 Fix: Put the cohesion function back in 2024-07-10 10:59:18 -05:00
robert 13cacb558e Fix: force direction & magnitude for separation
The clumping was because the function was moving the boids together,
not apart. The chaotic movement was the result of the large coefficient
on the force.
2024-07-10 10:53:12 -05:00
robert 368d6c9201 Boids clumping (try for separation function)
I've updated the position integration function to account for
acceleration. I need to change it once more to represent force, instead.
The idea is that the steering functions can all do their thing and apply
a force to the boid. Then, all mobs have their acceleration (forces)
integrated up through velocity and into their new position.

This version produces clumps of fast moving boids. Boids out on their
own will slowly come to a stop. I'm not sure why either of these is the
case.
2024-07-10 10:34:16 -05:00
robert 38c1d779c1 Just use a for loop in the cohesion function
I was trying to work out a way to run the loop using iterators, but
that doesn't really matter. I had an empty loop to consume the results,
which means I just have a for loop anyway.
2024-07-10 08:47:30 -05:00
robert 3293706328 Iterate over all boids instead of only the player
I understand what Daniel was talking about when they referred to the
movement being very rigid.

https://github.com/danieldidiobalsamo/boids/blob/master/src/boids_plugin.rs#L289

Their implementation has a different main loop than mine so that the
acceleration can be delayed by one frame. This way things can choose
their movements without being able to observe the ones that have already
completed theirs for the current frame. I haven't done that, and things
are weird.

I'm going to try to resolve this by moving down into an acceleration
value. Apply a force, integrate at the beginning or end of the frame.
2024-07-09 17:02:14 -05:00
robert 5d41cd57d3 Fix cohesion force vector
Found it! The force was going the wrong way.
2024-07-09 16:42:19 -05:00
robert 4cf591f937 Cohesion function... sorta. Cohesion *no* function
I got the cohesion function to act on the Boids, but there's something
wrong with the math. I already had to dance around the accidental
introduction of NaN's into the system.
2024-07-09 16:37:46 -05:00
robert 3a680a4ea2 Added bevy_spatial for boid interactions
I'm finally starting on the actual Boids flocking algorithm parts.
I don't want to iterate over all the things, and Bevy doesn't seem to
have fast collision testing yet, so I've reached for bevy_spatial to
track my Boids.
2024-07-09 11:56:52 -05:00
robert ecbfea04be Apply cargo check fixes 2024-07-09 10:43:20 -05:00
robert 84fa15bd77 cargo-fmt 2024-07-08 16:53:02 -05:00
robert ed33b8e615 New Cargo.toml config & updated lock file
It's just the (Windows portion of the) recommendations the Bevy getting-
started guide contains.
2024-07-08 16:46:37 -05:00
robert 8f52ad3954 Border avoidance system 2024-07-08 16:10:31 -05:00
robert 7224199a94 Delete unused entity spawn, add player color const 2024-07-08 15:18:18 -05:00
robert 20d12bb056 Slightly better signature for keyboard handler 2024-07-08 14:20:54 -05:00
robert 2e5c34da3d Basic player character steering
This is basically useless as an actual feature, but it was helpful to
demonstrate that I'm beginning to understand how to do this stuff.
2024-07-08 14:18:50 -05:00