lholliger / territory.cf

the stuff behind https://territory.cf
MIT License
3 stars 0 forks source link

choppy movement, freezes occasionally #2

Closed ghost closed 7 years ago

lholliger commented 7 years ago

yep. im looking at a way to make the backend send a more compressed map of claims, it could also be that stuff is done synchronously for http requests, i need help with fixing that :/

ghost commented 7 years ago

Only send part of the map

ghost commented 7 years ago

maybe 1.5x screen area and keep fetching on every move

lholliger commented 7 years ago

it fetches the screen every move you do, i need to look into sending certain portions of the screen, the current fetch system sends it like every block is claimed (it returns the unclaimed color)

ghost commented 7 years ago

Is this running on an ssd? You seem to be doing a lot of disk writes...

ghost commented 7 years ago

And canvas is probably faster than DOM? (or at least better for what you're doing)

lholliger commented 7 years ago

never thought of using canvas. The system is using an HDD, but i am planning to use a ramdisk that is constantly restoring to the HDD, because, if the system goes down, i dont think loosing like 5 blocks is a big issue

lholliger commented 7 years ago

i havent really learned canvas, soooo... ill attempt on a seperate page (probably territory.cf/canvas-beta.html)

lholliger commented 7 years ago

issue partially solved: the game now completely draws using canvas

the only issue is sync speed

ghost commented 7 years ago

maybe just sustain a socket and send the initial map ex:

xxxxxx   xxxx
 xx   xxxxx
xx   xx     xxxxxxx
                  x

then send messages of the form: [color, x-coordinate, y-coordinate]

and the client can do the computing

lholliger commented 7 years ago

how would i do sockets? i have only worked with synchronous get requests lol

ghost commented 7 years ago

Idk in php; Node makes it easier because you can handle requests in a more low-level way (and use socket.io)

lholliger commented 7 years ago

I think I'll use node for the map and movement system, but the initial game startup will use php to get the coordinates and other data values. I can't program at the moment so I'll do it sometime soon

ghost commented 7 years ago

I can PR

ghost commented 7 years ago

Ok I have the http server and stuff set up and I probably will need to rewrite most of territory.js lol

ghost commented 7 years ago

socket.io is cool

lholliger commented 7 years ago

Rewriting the engine would make it very hard for me to make modifications. Thanks for the help, but I don't know what I would do because I don't know much about node,

ghost commented 7 years ago

you'll see

lholliger commented 7 years ago

If you do a PR, I might use parts of the video but not all of it, I will definitely be switching to sockets, is it posible with python?

ghost commented 7 years ago

video?

ghost commented 7 years ago

Socket.io is cool because it is event-driven ex on server:

io.on('connection', function(socket) {
  // socket is individual connection
  // when client does io.emit('hi', [data is optional])
  socket.on('hi', function(data) {
    // io.emit sends message to all connected clients
    io.emit('hello', socket.id)
  })
})
lholliger commented 7 years ago

the code i would need most is it to tell the server "Hey! im playing the game!" and whenever it asks for the map/moves itll return the info. Dont worry about rewriting the map reciever, i might just leave that up to Python or some function ill rewrite

ghost commented 7 years ago

But thats still kinda slower

ghost commented 7 years ago

I would have the server do io.emit('+', {x: [x], y: [y]}) so the client can do it and its only a few bytes being sent on a move (but send the whole map when starting the game)

lholliger commented 7 years ago

wouldn't that send it to all the players?

ghost commented 7 years ago

The client can only send to the server (for security reasons and technical ones)

ghost commented 7 years ago

So the client would say "hey server I wanna move here" "ok mr. dr. sir" "everyone, in your records make [x, y] [color]" "Ok server" "Ok server"

lholliger commented 7 years ago

im going to mess with socket.io a little for myself to try some things :)

ghost commented 7 years ago

ok ;) but I already have some stuff done ok

lholliger commented 7 years ago

waaiiittt. wat port will i need to open on mai server

ghost commented 7 years ago

You can choose. if linux/mac, do export PORT=[port]

lholliger commented 7 years ago

im just wondering, why are you rewriting basiclly the entire game? it kinda seems like you are taking over almost all of it

ghost commented 7 years ago

If you used the express boilerplate, edit bin/www and change 3000 to whatever (put using the command thing will override)

ghost commented 7 years ago

Because it's fun and I need practice lol

lholliger commented 7 years ago

i just used npm install socket.io soooo

ghost commented 7 years ago

I never can come up with ideas and I was bored and this looked kinda sad (no offence)... So i decided... Why not rewrite something existing...

ghost commented 7 years ago

https://socket.io/get-started/chat/ look through this

lholliger commented 7 years ago

im kinda loosing control of the project it seems...

ghost commented 7 years ago

How? It's just a fork, and I can't modify this repo :P

lholliger commented 7 years ago

i know, ill probably use some but not all of the code, ill probably add some changes to it too when you publish it

lholliger commented 7 years ago

on another thing, i think im going to leave PHP up to the inital map and variable sending when you first join the game, and then let socket.io take over most of it after that

ghost commented 7 years ago

Kind of weird but ok...

lholliger commented 7 years ago

it doenst make it so we have to rewrite a bunch so it saves time

ghost commented 7 years ago

But wouldn't it make more sense to just hold everything in a multidimensional array anyways?

ghost commented 7 years ago

oh well

lholliger commented 7 years ago

So so far what do you have written

ghost commented 7 years ago

Well the web server, have socket.io up, and am working on a mechanism to send the map

lholliger commented 7 years ago

im getting a little better at it. looked at some of your code, took some code for returning resources (css), and currently it returns the coords of whatever i tell the server to when you start. now to have it restore sessions...

ghost commented 7 years ago

ok cool

lholliger commented 7 years ago

currently i have it to save sessions... now... for... the....impossible...part..... maps