TMarc wrote: ↑28 Nov 2019, 00:00
The question is: why do you have to call http requests during a race?
Each separate request is always accompanied by lot of protocol (overhead) which results in this behavior.
If you want to get rid of the delay, then you need to either:
- setup a socket connection at the begin, keep it open and use it for requests
- use multithreading (not featured in maniascript as far as I assume)
- don't use in-between http requests at all
There is a lot that can be requested during a race.
In Challenge, I made a thing I call playsessions which very basically creates a short-time HTTP communication service on a map you launch in solo. To send your gameplay information to the server, you have to request quite often, even during the race.
Additionally, and the major thing that requires during-race requesting, is the "status requesting" that I made which checks every 10 seconds about the title pack status, and for example, kick everyone from the title pack if a critical bug is found (I didn't implement title pack kicking yet due to lack of time), but this status requesting also checks how many people are playing your exact map and if new messages arrived in map chat, or if new notification has been received.
I also had the idea that when you pass a checkpoint, the race and checkpoint information would be sent to my web/database and I would be able to measure first-lap time and best-lap time records, which may be good to send in real-time? (or well, this could be actually sent after race I guess).
I unfortunately didn't know about long-polling when I was making these features and so it's a bit inefficient, but some of these things can't be done with long-polling anyway and you have to consistently send requests over and over again.
ManiaScript doesn't support sockets, only OpenPlanet does, which is what I want to avoid using in my "playful nontechnical" projects. We have only HTTP available, or we have to work around it through server controllers, tho that isn't really solo. xd
Multithreading in ManiaScript is kinda dream, but I mean, HTTP requests there work asynchronously, they
don't block the game until the
request has received response. They block the game for the actual split second and the game wakes up even if the request wasn't yet finished.
The requests are processed in the background after calling Http.CreateGet() and the only way they are controllable is that you can Destroy them meanwhile they process. I'm not good at explaining this but this should make sense when you know about CHttpManager.