Page 1 of 2

game speed - how to maximize it

Posted: 14 July 2021, 23:45
by developgame
Hello Everyone:
just another newbie question,
I am trying to create a realtime game. I hope to have the game speed or user actions processed by the game quick enough so it is possible for players to beat the game.

BGA server can often be very busy ,
I thought it would be fastest to do much processing on the client side and limit server side processing to moving through states and database access.

I have most of the necessary database game information stored in arrays in javascript
I am realizing that many javascripts array methods are very slow. for example findIndex

How would you maximize the game speed and minimize the amount of time spent on each user action .



thanks for any suggestions!

Re: game speed - how to maximize it

Posted: 15 July 2021, 07:40
by tsaunat
Is it multiplayer? Do players interact? If so find a way to use websocket I would assume, but BGA might not be your best choice for that style game.

If it's limited interaction and you don't need to use the server to keep them (perfectly) synced so you are doing client processing. I'm certainly not an expert in optimization, but you should be able to get the data structure to a speed that should work great. Current clients are ridiculously speedy.

Re: game speed - how to maximize it

Posted: 15 July 2021, 07:47
by tchobello
BGA server in the Studio is not optimized...
you'll get better results in Production.

Re: game speed - how to maximize it

Posted: 15 July 2021, 10:10
by robinzig
developgame wrote: 14 July 2021, 23:45 I am realizing that many javascripts array methods are very slow. for example findIndex
I'm not easily able to say whether you're better off doing things on the client-side or not in this situation (although in general I'm a fan of not involving the server where it's not necessary) - but this sentence seems off to me. Modern JS implementations are pretty fast, and array methods like this shouldn't take any noticeable time until you get to arrays with tens of thousands of elements (maybe more). If you're experiencing noticeable delays in client-side code there's likely some performance issues with your code (eg doing something expensive in the function you're passing to findIndex), rather than it being the fault of the language itself!

Re: game speed - how to maximize it

Posted: 15 July 2021, 10:13
by robinzig
tsaunat wrote: 15 July 2021, 07:40 Is it multiplayer? Do players interact? If so find a way to use websocket I would assume, but BGA might not be your best choice for that style game.
You certainly need websockets to do any kind of real-time interaction over the web - but BGA handles that already in the framework. I may be missing something but I don't see why developers on BGA would want to reinvent this themselves, and I certainly wouldn't be advising this!

Re: game speed - how to maximize it

Posted: 15 July 2021, 14:32
by Victoria_La
I agree with previous posts, here is my summary:
* BGA is not a real time framework, there would be never gurantee that players action will reach the server in certain time, in certain order or anything like this, so you cannot rely on this at all
* If game relies on "who acts first" like rcochet robots - it will always favor people with faster internet, unless you do some kind of complecated alanysis on imestamps from client (which is not reliable either)
* if you CAN do processing on client side - do it, it will save everybody time, unload the server, etc. But you cannot rely on that entirily - server have to validate all data assuming everything you get from the client can be manually entered
* if you see perfomance issues on client side - it not js, its your algorithms, unless you doing sophistcated AI mini-max optimizations problems - there is no way it can be noticible slow if its done right. Browser comes now days with lots of profiling tool - use it.

Re: game speed - how to maximize it

Posted: 15 July 2021, 23:05
by Idsky
I was just thinking about this. When doing this.ajaxcall(…), set lock:false, so that the client is not paused while the full round-trip server response takes place. This means the client can run at full speed with no delays. The client needs to check that all actions sent are valid so that hopefully they will all be accepted by the server.

It will get ahead of the server (which must still check all actions in case of cheaters or conflicts with other player actions). On the client, knowledge of what other players are doing will always be delayed, so it can get a bit complicated.

Re: game speed - how to maximize it

Posted: 16 July 2021, 05:03
by tsaunat
robinzig wrote: 15 July 2021, 10:13
tsaunat wrote: 15 July 2021, 07:40 Is it multiplayer? Do players interact? If so find a way to use websocket I would assume, but BGA might not be your best choice for that style game.
You certainly need websockets to do any kind of real-time interaction over the web - but BGA handles that already in the framework. I may be missing something but I don't see why developers on BGA would want to reinvent this themselves, and I certainly wouldn't be advising this!
my point I was suggesting was finding a way to tap into BGA's websocket as far as I know we don't necessarily have direct access to it, also BGA uses it to pass notification traffic to the client, but this is not the way moves are summited to the server which would not result in realtime network layer . I was not suggesting the developer should try to implement their own web socket on BGA. If realtime traffic is actually needed (due to player direct interaction) I was suggesting BGA might not be the place for that. Websockets are not particularly difficult, but don't try to implement your own websocket on BGA --it's not going to work.

Re: game speed - how to maximize it

Posted: 16 July 2021, 10:28
by robinzig
tsaunat wrote: 16 July 2021, 05:03
robinzig wrote: 15 July 2021, 10:13
tsaunat wrote: 15 July 2021, 07:40 Is it multiplayer? Do players interact? If so find a way to use websocket I would assume, but BGA might not be your best choice for that style game.
You certainly need websockets to do any kind of real-time interaction over the web - but BGA handles that already in the framework. I may be missing something but I don't see why developers on BGA would want to reinvent this themselves, and I certainly wouldn't be advising this!
my point I was suggesting was finding a way to tap into BGA's websocket as far as I know we don't necessarily have direct access to it, also BGA uses it to pass notification traffic to the client, but this is not the way moves are summited to the server which would not result in realtime network layer . I was not suggesting the developer should try to implement their own web socket on BGA. If realtime traffic is actually needed (due to player direct interaction) I was suggesting BGA might not be the place for that. Websockets are not particularly difficult, but don't try to implement your own websocket on BGA --it's not going to work.
Thanks for clarifying. I did say "I may be missing something" and it seems indeed I was (about your intended meaning) - but I probably wasn't the only one so it's all good that you've come back and explained what you actually meant. Which sounds sensible :)

(It's interesting what you say - which I've noticed too but not thought too much about before - that BGA only appears to use websockets for transmitting notifications from the server to players/spectators, and not for the actual game moves on the client, which use standard HTTP/Ajax. I'm not sure why this is, but also completely ignorant of what the effects on performance might be. I'm sure it's something the BGA developers must have thought about however!)

Re: game speed - how to maximize it

Posted: 19 July 2021, 18:04
by developgame
tsaunat wrote: 15 July 2021, 07:40 Is it multiplayer? Do players interact? If so find a way to use websocket I would assume, but BGA might not be your best choice for that style game.

If it's limited interaction and you don't need to use the server to keep them (perfectly) synced so you are doing client processing. I'm certainly not an expert in optimization, but you should be able to get the data structure to a speed that should work great. Current clients are ridiculously speedy.
Thanks robinzig for your advices. I do not know about websockets, but I will learn more.
The games is cooperative dice chucking game where I do not need the servr to keep them perfectly syn. It is a game where all the players must accomplish some feats in 10 minutes to beat the game