-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various Typing Fixes & Client-Side Render Event (Multiple Client Compatible) #428
base: master
Are you sure you want to change the base?
Conversation
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
|
A demonstration of this technique is shown here. 2024-02-26.00-01-49.mp4 |
There appears to be an 1.8.8 error. However, that doesn't appear to be my fault; the error says the test did not find the server (404 error). I will attempt to re-run. |
.vscode/settings.json
Outdated
@@ -0,0 +1,3 @@ | |||
{ | |||
"print.colourScheme": "GitHub" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove
examples/bot.js
Outdated
}) | ||
|
||
bot.once('spawn', () => { | ||
bot.once('spawn', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't do anything, please undo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
const fps = Math.ceil((frameCount / ((currentTime - lastTime) / fpsCheck))) | ||
lastTime = currentTime | ||
frameCount = 0 | ||
if (fps != null) socket.emit('renderFPS', { id: socket.id, fps }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add to doc + use it in an example to explain what it's good for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know where I would put this server-sided event (renderFPS) firing into docs as there is no mention of server-sided code in the READMEs.
I included documentation on the bot.viewer event firing, however.
io.on('connection', (socket) => { | ||
const getRenderInterval = (fps) => setInterval(() => bot.viewer.emit('onRender', fps), 1000 / fps) | ||
|
||
const updateListener = ({ id, fps }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a comment explaining the intent of this; it's far from obvious
I fixed some typings for Mineflayer, specifically the bot.viewer object.
I also implemented a system that keeps track of the highest FPS of clients currently connected to the viewer. This is used to provide a "render" event that guarantees at least one firing per frame of the fastest client connected.
I chose to poll the FPS of each client every second. That can be tweaked if performance is an issue.
There is unnoticeable impact to performance, both computationally and memory-wise. (It only stores a mapping of socket ids to a number).
In the event that no clients are connected, the event will not fire and the interval that would be firing said event is cleared.