Slither-Server icon indicating copy to clipboard operation
Slither-Server copied to clipboard

Speed Fix

Open GrumpyOet opened this issue 9 years ago • 57 comments

you have need to change this in the movement.js:

var message = require('../utils/message');

var type = 'G'.charCodeAt(0);

exports.build = function(id, x, y) {
    var arr = new Uint8Array(4.8);
    var b = 0;
    b += message.writeInt8(b, arr, 0);
    b += message.writeInt8(b, arr, 0);
    b += message.writeInt8(b, arr, type);
    b += message.writeInt16(b, arr, id);
    b += message.writeInt8(b, arr, x);
    b += message.writeInt8(b, arr, y);
    return arr;
};

instead of this:

var message = require('../utils/message');

var type = 'G'.charCodeAt(0);

exports.build = function(id, x, y) {
    var arr = new Uint8Array(9);
    var b = 0;
    b += message.writeInt8(b, arr, 0);
    b += message.writeInt8(b, arr, 0);
    b += message.writeInt8(b, arr, type);
    b += message.writeInt16(b, arr, id);
    b += message.writeInt8(b, arr, x);
    b += message.writeInt8(b, arr, y);
    return arr;
};

GrumpyOet avatar Jun 18 '16 07:06 GrumpyOet

you have need to change the 9 to 4.8

GrumpyOet avatar Jun 18 '16 07:06 GrumpyOet

I'm away now but I'll fix it as soon as I get home. Thanks!

RowanHarley avatar Jun 18 '16 08:06 RowanHarley

@GrumpyOet When changing 9 to 4.8, the snake is removed from the game. Not sure if this is an error on my side but I'll have a look

RowanHarley avatar Jun 19 '16 06:06 RowanHarley

Do hou know why the shake get removed from the map?

GrumpyOet avatar Jun 25 '16 06:06 GrumpyOet

I'm not too sure. The Slither.io Protocol says that there are 6 bytes in the array

RowanHarley avatar Jun 25 '16 07:06 RowanHarley

but how do we fix it because you only can do 9 not less or more

GrumpyOet avatar Jun 26 '16 19:06 GrumpyOet

I think we need to fix position.js. The buggy movement (and I'd say speed) are because of sending exact co-ordinates. We need to send both (or a mixture of both) to fix the bugs

RowanHarley avatar Jun 26 '16 19:06 RowanHarley

I think we have neem to change THE position.js to 7 and THE movement.js to 7 or 6

GrumpyOet avatar Jun 27 '16 05:06 GrumpyOet

il gonna try that when i am home

GrumpyOet avatar Jun 27 '16 05:06 GrumpyOet

The G packet is 7 bytes long (last index is 6, but index starts at 0), the g packet is 9 bytes long.

Mat2095 avatar Jun 27 '16 09:06 Mat2095

@Mat2095 The g packet gives me the error: Int16 out of bound. This error comes from here

RowanHarley avatar Jun 27 '16 10:06 RowanHarley

how they are both Int8

GrumpyOet avatar Jun 27 '16 10:06 GrumpyOet

and i don't get a error when i change that but the snake goes a little bit slower

GrumpyOet avatar Jun 27 '16 10:06 GrumpyOet

I'm talking about position.js not movement.js. I've just updated the code. Uncomment L126 to use position.js.

RowanHarley avatar Jun 27 '16 10:06 RowanHarley

i think the is something wrong in L126

GrumpyOet avatar Jun 27 '16 10:06 GrumpyOet

Don't think there is. Have you uncommented it?

RowanHarley avatar Jun 27 '16 10:06 RowanHarley

yes en there is no other option to change in the position.js because i tried to change the Uint8Array to every thing from 1 to 20 and nothing of that work

GrumpyOet avatar Jun 27 '16 10:06 GrumpyOet

and the error says that's the error is in L126

GrumpyOet avatar Jun 27 '16 10:06 GrumpyOet

the question is why that:

    throw new Error('Int16 out of bound.');
      ^

Error: Int16 out of bound.
    at Object.module.exports.writeInt16 (/Users/Luke/Desktop/Slither-Server/src/utils/message.js:20:13)

and why that:

at Object.exports.build (/Users/Luke/Desktop/Slither-Server/src/messages/position.js:12:15)

right?

GrumpyOet avatar Jun 27 '16 11:06 GrumpyOet

no wait i think that the error is in the message.js file (maybe?)

GrumpyOet avatar Jun 27 '16 11:06 GrumpyOet

It's in position.js, you're right. The number being sent is 144685. Not sure why this number is being sent though

RowanHarley avatar Jun 27 '16 11:06 RowanHarley

Ok, so I think I found the problem. Initially, the body's x and y are sent as Int24's. This means they're gonna be big numbers. position.js is looking for Int8's though. I'm still not sure how I'm gonna fix it but I'll look into it

RowanHarley avatar Jun 27 '16 13:06 RowanHarley

Be careful! In the 's' packet the position is an int24, but multiplied by 5. So if the position in the 's' packet is 144685, the snake actually has the coordinates 28937, which fits into an int16. For the 'G' and 'g' packets the coordinates are not multiplied/divided by 5.

Mat2095 avatar Jun 27 '16 13:06 Mat2095

ok, thanks! I'll check if that fixes it!

RowanHarley avatar Jun 27 '16 13:06 RowanHarley

Ok, after fixing that, the snake barely moves and when it does, it moves in sudden jerks

RowanHarley avatar Jun 27 '16 13:06 RowanHarley

Rowan what did you change?

GrumpyOet avatar Jun 27 '16 14:06 GrumpyOet

I changed broadcast(messages.position.build(conn.id, conn.snake.body.x, conn.snake.body.y)); to broadcast(messages.position.build(conn.id, (conn.snake.body.x / 5), (conn.snake.body.y / 5)));

RowanHarley avatar Jun 27 '16 14:06 RowanHarley

What client are you using for testing? Does the sudden-movement happen on client side only or also on server side?

Mat2095 avatar Jun 27 '16 14:06 Mat2095

I'm using the original slither.io client. I only see the jerking client-side only although I have no debug statements that would come up server-side

RowanHarley avatar Jun 27 '16 14:06 RowanHarley

i tried it to now the snake looks like a retard now

GrumpyOet avatar Jun 27 '16 14:06 GrumpyOet

I don't understand this line: conn.snake.body.x += Math.round(Math.cos(conn.snake.direction.angle * 1.44 * Math.PI / 180) * 170);

  • You probably don't have to round here
  • What is the measurement of direction.angle? radians? degrees? The formula kindof looks like it should be degrees, but why is it * 1.44?
  • You definitely need to add the snake-speed to the formula!

If the snake moves too slow on the client side, maybe you didn't send the speed correctly. Typically, the speed is between 5 and 6, lets say 5. The speed is sent in int16, but the client is dividing it by 1000, therefore you need to send 5000.

If you can read/write Java, you can try the server with my client, it should work well for most basic stuff while it only has 1500 to 2000 lines of code.

Mat2095 avatar Jun 27 '16 14:06 Mat2095

I think with the broadcast(messages.position.build(conn.id, (conn.snake.body.x / 5), (conn.snake.body.y / 5))); code

the speed is fine but now we have need to fix the rotation of the snake

GrumpyOet avatar Jun 27 '16 15:06 GrumpyOet

for what is this code conn.snake.body.x += Math.round(Math.cos(conn.snake.direction.angle * 1.44 * Math.PI / 180) * 170);

rotation or something

GrumpyOet avatar Jun 27 '16 15:06 GrumpyOet

Rowan i think you must use this code for the next version 0.0.5b2 and fix the retard snake for 0.0.5b2 to ......................,.,.,.,.,.,.,.,.,.,..,.,.,.,.,., / broadcast(messages.position.build(conn.id, (conn.snake.body.x / 5), (conn.snake.body.y / 5)));

GrumpyOet avatar Jun 27 '16 15:06 GrumpyOet

The angle is 0 @Mat2095 (sorry for late reply)

RowanHarley avatar Jun 27 '16 15:06 RowanHarley

That's boring :( so the snake can only go to the right? I meant the measurement, so does it go from 0 to 360 or to 2*PI or something else?

Mat2095 avatar Jun 27 '16 15:06 Mat2095

Mat can you make a code for that?

GrumpyOet avatar Jun 27 '16 17:06 GrumpyOet

If we can work from here then we only have need to fix rotation of the snake becaus the speed is good

GrumpyOet avatar Jun 27 '16 18:06 GrumpyOet

Maybe you can take a look at this:

https://github.com/whxaxes/slither

GrumpyOet avatar Jun 27 '16 18:06 GrumpyOet

For the rotation

GrumpyOet avatar Jun 27 '16 18:06 GrumpyOet

@GrumpyOet make a code for what?

Mat2095 avatar Jun 27 '16 18:06 Mat2095

for rotation of the snake

GrumpyOet avatar Jun 27 '16 19:06 GrumpyOet

I don't speak JS, but this is the general idea: deltaAngle = mamu * deltaTime * snake.scang * snake.spang (deltaTime is the time in ms since the last iteration / 8) Depending on the snake.dir: 0: set the ang to wang 1: subtract deltaAngle from ang 2: add deltaAngle to ang If wang is between the old and the new ang, set ang to wang and dir to 0

Mat2095 avatar Jun 27 '16 19:06 Mat2095

There is no snake.scang or snake.spang in my code. Is there a default value for them?

RowanHarley avatar Jun 27 '16 19:06 RowanHarley

dont ask me I can read JS script but not code it

GrumpyOet avatar Jun 27 '16 19:06 GrumpyOet

snake.scang = 0.13 + 0.87 * Math.pow((7-snake.sc)/6 , 2) snake.spang = Math.min(snake.speed/spangdv, 1) snake.sc = Math.min(6, 1 + (parts.size-2)/106.0)

Mat2095 avatar Jun 27 '16 21:06 Mat2095

/\ Hè use that code /\

GrumpyOet avatar Jun 28 '16 06:06 GrumpyOet

@Mat2095 Is that the server-side code or do I need to use the opposites of that?

RowanHarley avatar Jun 28 '16 07:06 RowanHarley

You only need opposite code when you modify before/after sending, like you have x in your code, but you send data=10*x, then you have to read it with x=data/10. So no, this code is the same for server and client (I mean I can't say for sure, the server-code is not public)

Mat2095 avatar Jun 28 '16 11:06 Mat2095

Just updated the code. Still getting the jerk bug

RowanHarley avatar Jun 28 '16 17:06 RowanHarley

Can iT be this

broadcast(messages.movement.build(conn.id, conn.snake.direction.x, conn.snake.direction.y));

To

broadcast(messages.movement.build(conn.id, (conn.snake.direction.x / 5), (conn.snake.direction.y / 5)));

GrumpyOet avatar Jun 28 '16 19:06 GrumpyOet

no. It's position.js that's the problem

RowanHarley avatar Jun 28 '16 21:06 RowanHarley

O ok

GrumpyOet avatar Jun 29 '16 05:06 GrumpyOet

Maybe because you did / 5 you need to do that on a other conn.snake.body.something /5

GrumpyOet avatar Jun 29 '16 05:06 GrumpyOet

Okay, take a look at the direction-packet ('e'):

You make an Uint8Array sized 7 and write 8 bytes in it. That doesn't work.

You set the first two bytes to 0. This is very wrong! The documentation says "Time since last message from client". I don't know how to calculate the data you need to send here, but you HAVE to find it out (from the client-code) for the server to work. (Take an official server and client, just set these bytes to 0, and the game is broken)

Then you you send the packet-type and id, which is ok.

Next you send the current angle. I doubt it is in the right format, but you still haven't answered my question about that, so I don't know.

Next you send 104 and 1 (You can't, the array is too short). Is this the wanted-angle and speed? So the snake always goes down-left and its speed is always less than 0.06 ?

Mat2095 avatar Jun 29 '16 17:06 Mat2095

Ok, so about the body x and y, the formula used there is this. The Center_X and Center_Y aren't added as there is no point in adding 0

RowanHarley avatar Jun 30 '16 08:06 RowanHarley

Sorry for the late reply. Ive been busy lately. To answer your question in full.

  • Q1: I removed the last byte. Must've missed something there
  • Q2: I set the 1st 2 bytes to 0 because I didn't think it would make a difference. If you have any idea where I should be looking, please tell me.
  • Q3: ^^
  • Q4: The Snake can go any direction. To be honest I don't know why the angle is 104. I changed the last byte to 5.79 although I dont know if that's correct

RowanHarley avatar Jul 08 '16 10:07 RowanHarley