๐Ÿ‚

Posts tagged with :fallen_leaf:

ced
@ced0
imagine you were making a multiplayer web game at regular intervals on the server, you want to tick your simulation. setInterval(() => { your players move forward, โžก๏ธ your enemies decide who to badger next, :threat: some of your projectiles are just barely dodged, :flug: and others smash satisfyingly into their targets :bonk: }, 1000 / 60); at each of these intervals, the server decides which of these occur, and which ... do not. the difference is quite literally life and death for the denizens of your online realm: if a player's input makes it to the server just after this update has occurred, they might just not move out of the way of the oncoming missile in time. after one of these updates when the server has just finished making these vital decisions, it blasts relevant portions of them out to everyone who's connected to your server. (there's no point in updating you about something if it's happening on the other side of the map!) meanwhile, in the player's web browser, these regular updates from the server are gradually applied, so the server's periodic contemplation is rendered as a seamless sequence of fluid movements... unless those updates aren't really so regular at all ... the contract that the server has with the client -- that the server will give the client evenly spaced out updates at regular-enough intervals so that the client can smoothly move between them -- isn't actually the same as the contract that setInterval provides. all setInterval(update, 1000) means is that there will be ABOUT one thousand milliseconds between each of your updates, usually more. so if the actual interval ends up being 1009ms one frame, the next update won't be about 991ms later so that updates happen at regular one second intervals, it will be more like 1007ms later, so that now you're a total of 16 ms away from the contract you had with the client. this is known as drift. at worst, this passes on all of the problems of using setInterval for animation onto your game. but what if you're doing something fancier than just moving between the updates you get from the server as you get them? there's always going to be a random delay between what the server sends and what you get, anyway. it might make more sense to push the updates you get from the server onto a stack, and exactly as often as the server updates, pop the next set of positions off of that stack. ... except that if you're popping using one setInterval on the client, and the server is pushing out those simulation ticks using a setInterval of its own ... and each has a different drift ... they're quickly going to fall out of sync. if the server is drifting a lot, your stack might gradually accumulate thousands of positions that you just can't keep up with ... and if the server is drifting less than you are, you might run out of positions to show the player! suffice it to say, it's super important to have a setInterval that updates without drift. I threw together an implementation of one this morning. I call it a `tick`, since it works well for those simulation ticks I was talking about before. To test it, I went ahead and also made a drift visualizer. Here's a screenshot of it! The grey lines are spaced out at 0.5s intervals, and the first row of blue marks is made by setInterval, while the other row of blue marks are made by my own tick function. as you can see, they stick to the "wall clock time" a lot better than Interval does, even when you leave it running for several minutes! here's a screenshot! I'll post the source in the thread :) fun fact: everything that moves is a CSS animation ๐Ÿ˜‚ I didn't want to pollute the JS event loop, although now that I think about it, it might've been better to so that I can see how well my ticker keeps itself together in the presence of some event loop pressure.
https://cloud-7qivvrkmx-hack-club-bot.vercel.app/0image.png
kayley
@kayley0
Fall 2021 with my favorite lab, section, professors, friends, and memories.
https://cloud-6yowj3x53-hack-club-bot.vercel.app/0image_from_ios.jpghttps://cloud-7rcbda0w8-hack-club-bot.vercel.app/0image_from_ios.jpghttps://cloud-6qb8x1r5z-hack-club-bot.vercel.app/0image_from_ios.jpghttps://cloud-emh3vpszc-hack-club-bot.vercel.app/0image_from_ios.jpghttps://cloud-7t0me74ln-hack-club-bot.vercel.app/0image_from_ios.jpghttps://cloud-3p1ywdhcj-hack-club-bot.vercel.app/0image_from_ios.jpghttps://cloud-34gbcxpp0-hack-club-bot.vercel.app/0image_from_ios.jpghttps://cloud-jw4m7lop2-hack-club-bot.vercel.app/0image_from_ios.jpghttps://cloud-bwdm5zxt1-hack-club-bot.vercel.app/0image_from_ios.jpghttps://cloud-pfrz5banp-hack-club-bot.vercel.app/0image_from_ios.jpg
sampoder
@sampoder0
https://cloud-i17szkncf-hack-club-bot.vercel.app/0screenshot_2021-12-14_at_2.52.34_pm.png
avi
@avi0
Nice fall vibes
https://cloud-d2d3e49j1-hack-club-bot.vercel.app/0pxl_20211102_192740229.jpghttps://cloud-mttb8iijx-hack-club-bot.vercel.app/0pxl_20211102_194604842.jpghttps://cloud-fqshebaad-hack-club-bot.vercel.app/0pxl_20211102_194550581.jpg
caleb
@caleb0
Leaf season is here
https://cloud-hyu6n17v8-hack-club-bot.vercel.app/0img_20211031_153638227_hdr.jpg
heyrajan
@heyrajan0
worked on my lab, tried out new safari and witnessed a bowl of rice fall asleep in class
https://cloud-53ab13mp1-hack-club-bot.vercel.app/0image.pnghttps://cloud-4zjwy5x6o-hack-club-bot.vercel.app/0image.png
JohnLins
@JohnLins0
https://cloud-d8dcm2sg3.vercel.app/0screenshot.png
blakedfreeman
@blakedfreeman0
Been learning โ€œhouse of the rising sunโ€ and my thumb feels like itโ€™s going to fall off
https://cloud-fbf1pvej5.vercel.app/0image_from_ios.jpg
christina695
@christina6950
Just enjoying the Fall in Vermont
https://cloud-haqxg6lo3.vercel.app/0img_1059.jpg