Skip to content
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

Speed Fix #5

Open
GrumpyOet opened this issue Jun 18, 2016 · 57 comments
Open

Speed Fix #5

GrumpyOet opened this issue Jun 18, 2016 · 57 comments

Comments

@GrumpyOet
Copy link

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
Copy link
Author

you have need to change the 9 to 4.8

@RowanHarley
Copy link
Owner

RowanHarley commented Jun 18, 2016

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

@RowanHarley
Copy link
Owner

RowanHarley commented Jun 19, 2016

@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

@GrumpyOet
Copy link
Author

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

@RowanHarley
Copy link
Owner

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

@GrumpyOet
Copy link
Author

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

@RowanHarley
Copy link
Owner

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

@GrumpyOet
Copy link
Author

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

@GrumpyOet
Copy link
Author

il gonna try that when i am home

@Mat2095
Copy link
Contributor

Mat2095 commented Jun 27, 2016

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

@RowanHarley
Copy link
Owner

RowanHarley commented Jun 27, 2016

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

@GrumpyOet
Copy link
Author

how they are both Int8

@GrumpyOet
Copy link
Author

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

@RowanHarley
Copy link
Owner

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

@GrumpyOet
Copy link
Author

GrumpyOet commented Jun 27, 2016

i think the is something wrong in L126

@RowanHarley
Copy link
Owner

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

@GrumpyOet
Copy link
Author

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
Copy link
Author

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

@GrumpyOet
Copy link
Author

GrumpyOet commented Jun 27, 2016

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
Copy link
Author

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

@RowanHarley
Copy link
Owner

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

@RowanHarley
Copy link
Owner

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

@Mat2095
Copy link
Contributor

Mat2095 commented Jun 27, 2016

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.

@RowanHarley
Copy link
Owner

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

@RowanHarley
Copy link
Owner

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

@GrumpyOet
Copy link
Author

Rowan what did you change?

@RowanHarley
Copy link
Owner

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)));

@Mat2095
Copy link
Contributor

Mat2095 commented Jun 27, 2016

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

@RowanHarley
Copy link
Owner

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

@GrumpyOet
Copy link
Author

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

@Mat2095
Copy link
Contributor

Mat2095 commented Jun 27, 2016

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.

@GrumpyOet
Copy link
Author

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
Copy link
Author

GrumpyOet commented Jun 27, 2016

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
Copy link
Author

GrumpyOet commented Jun 27, 2016

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)));

@RowanHarley
Copy link
Owner

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

@Mat2095
Copy link
Contributor

Mat2095 commented Jun 27, 2016

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?

@GrumpyOet
Copy link
Author

Mat can you make a code for that?

@GrumpyOet
Copy link
Author

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

@GrumpyOet
Copy link
Author

Maybe you can take a look at this:

https://github.com/whxaxes/slither

@GrumpyOet
Copy link
Author

For the rotation

@Mat2095
Copy link
Contributor

Mat2095 commented Jun 27, 2016

@GrumpyOet make a code for what?

@GrumpyOet
Copy link
Author

for rotation of the snake

@Mat2095
Copy link
Contributor

Mat2095 commented Jun 27, 2016

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

@RowanHarley
Copy link
Owner

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

@GrumpyOet
Copy link
Author

GrumpyOet commented Jun 27, 2016

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

@Mat2095
Copy link
Contributor

Mat2095 commented Jun 27, 2016

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)

@GrumpyOet
Copy link
Author

/\ Hè use that code /\

@RowanHarley
Copy link
Owner

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

@Mat2095
Copy link
Contributor

Mat2095 commented Jun 28, 2016

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)

@RowanHarley
Copy link
Owner

Just updated the code. Still getting the jerk bug

@GrumpyOet
Copy link
Author

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)));

@RowanHarley
Copy link
Owner

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

@GrumpyOet
Copy link
Author

O ok

@GrumpyOet
Copy link
Author

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

@Mat2095
Copy link
Contributor

Mat2095 commented Jun 29, 2016

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 ?

@RowanHarley
Copy link
Owner

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants