Closed ghost closed 4 years ago
~Another possibly simpler option.. just precompute a bunch of paths as a set of arrays, large enough that it's unlikely anyone would remember all the patterns, and use (pos.x^pos.y^id)%length
as an index into it~
~This might make the loop much cleaner. Still need to figure a way to represent the path changes that can be applied fractionally.. because the calculation loop can run for partial frames~
Can use Xorshift for it, it's tiny:
function xorshift32(x)
{
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
return x;
}
Just need to cache this.rand = (this.id * this.pos.x * this.pos.y) & 0xffffffff
in the mob instance constructor and this.rand = xorshift32(this.rand)
every time a new word is needed
This is vaguely a design discussion / idea basically for Wight server, but overlaps with frontend. It's more implementation discussion than anything else..
I hacked the client Mob.js update() basically with this:
Which produced the video on /r/airmash.
So for each frame it perturbs the path somehow. Rather than using
Math.random()
, could use a PRNG or even just a hash function to generate bits the server also knows.. maybe something like:Then for each frame,
Or similar. Then right-shift bits off the integer to get 'random' state.
Since server and client both have the same id/pos/speed, this means their wonkiness decisions are in sync.
Is there a simpler way to do this? I thought maybe server could send MOB_UPDATE on each change, but that is a ton of network traffic