RNull Posted October 4, 2017 Share Posted October 4, 2017 Hello guys, So I am something like 3 weeks after the beginning of my game. It has been quite some fun and I believe I have made some good progress. Now since I got most of the mechanics going, AI, Battle system, Player control, HUD, terrains, npc's and characters , I started adding the server. The game is a multiplayer online RPG. My first try was to add Babylon.js to Node and I thought that would make it run, it didn't. Babylon.js seems to be requesting for a window object ( and thats fair to be honest ). Searching the forum I didn't see any solution so I thought to develop the server using electron. Also since electron can be run as headless that really is a viable option for now. I am not really convinced though so I thought to ask here about other ideas. Just to clarify, I need Babylon.js in the server side code because the server is authorative. I am not using any physics, just the navmash library of Babylon which need to be both sides in order for prediction to work. Client side and server side simulations need to be mostly identical to avoid as much server reconciliation as I can. So I would love to hear your thoughts about it. Thank you and best regards, RelativeNull/ Quote Link to comment Share on other sites More sharing options...
Sebavan Posted October 5, 2017 Share Posted October 5, 2017 We are planing to add support for this as the request is more and more frequent after 3.1. But you should check with @FunFetched how they did :-) He developed some server side tech for http://shellshock.io but not sure they are built in BJS. Quote Link to comment Share on other sites More sharing options...
FunFetched Posted October 5, 2017 Share Posted October 5, 2017 I wanted to re-use some math functions on the server-side so I could use the same code to simulate player movement on both ends. I copied the relevant portions from BJS to my server. It was easy enough, as those portions don't expect a .window object. What you need sounds to be a lot more complicated, so I'm not sure how you would proceed. My maps are just simple grids, so I coded the collision detection portions myself. Quote Link to comment Share on other sites More sharing options...
HeadClot Posted October 5, 2017 Share Posted October 5, 2017 I would look into this http://lance.gg/ Quote Link to comment Share on other sites More sharing options...
RNull Posted October 5, 2017 Author Share Posted October 5, 2017 6 hours ago, Sebavan said: We are planing to add support for this as the request is more and more frequent after 3.1. But you should check with @FunFetched how they did :-) He developed some server side tech for http://shellshock.io but not sure they are built in BJS. Great to hear there are plans for this. Yeah actually I was curious to know how @FunFetched did it. Don't get me wrong, with electron it works, I am able to put together server side and client side code I just think it is not a clean solution. 6 hours ago, FunFetched said: I wanted to re-use some math functions on the server-side so I could use the same code to simulate player movement on both ends. I copied the relevant portions from BJS to my server. It was easy enough, as those portions don't expect a .window object. What you need sounds to be a lot more complicated, so I'm not sure how you would proceed. My maps are just simple grids, so I coded the collision detection portions myself. Well I could take the parts I need as well and use those but I don't know if its really worth it. Since I got it running anyway with electron at least. 5 hours ago, HeadClot said: I would look into this http://lance.gg/ Uhmm, that is very cool but I am not sure if that can help. I will check it though. Quote Link to comment Share on other sites More sharing options...
RNull Posted October 5, 2017 Author Share Posted October 5, 2017 Just a follow up for everyone who might be interested. I just managed to run Babylon in Node.js using Nodes window and navigator objects. It gives no error and printing the object works. I will do some more tests and post my final decision here. I am very optimistic and hope that in a couple of months you will be able to play my game . Quote Link to comment Share on other sites More sharing options...
Arte Posted October 5, 2017 Share Posted October 5, 2017 Hi @RelativeNull, Can you explain to me how you manage to run Babylon in Nodes? Quote Link to comment Share on other sites More sharing options...
inteja Posted October 5, 2017 Share Posted October 5, 2017 @RelativeNull take a look at Colyseus as well http://gamestd.io/colyseus/ developed by @endel Quote Link to comment Share on other sites More sharing options...
Raggar Posted October 5, 2017 Share Posted October 5, 2017 Lance.GG is something I've been wanting to test out for some time now. The Sprocket League demo is using CannonJS. I have taken a look at it, but I need something a bit simpler to study I'm mostly interested in how it rewinds and redoes the simulations. Right now I'm cheating when I do that. You could theoretically use either ThreeJS or CannonJS, as both can be run on NodeJS. I use CannonJS on the backend, but for less physics-aware games, I would absolutely prefer getting BabylonJS to run instead, so the tools and functions can remain the same. The bare minimum must be something like creating a scene with a "world", primitive shapes and the vector functions, like .set, .translate, .multiply etc. Let us know if you are able to run the basics in NodeJS. Quote Link to comment Share on other sites More sharing options...
RNull Posted October 5, 2017 Author Share Posted October 5, 2017 5 hours ago, Arte said: Hi @RelativeNull, Can you explain to me how you manage to run Babylon in Nodes? Hey, well I just installed a window and navigation dependency for nodejs and it didn't give problems. However creating an engine gave a webgl context problem ( understandable ). I didn't go much further as I noticed that the headless webgl dependencies of Nodejs were all outdated, probably there might be a hack to it however I think I will just go with electron. I managed to run it headlessly and I read somewhere that it used the nodejs engine rather that of chromium. If that is the case I don't see any reason why I shouldn't go with it. 5 hours ago, inteja said: @RelativeNull take a look at Colyseus as well http://gamestd.io/colyseus/ developed by @endel Thanks will give it a look as well!!! 49 minutes ago, Raggar said: Lance.GG is something I've been wanting to test out for some time now. The Sprocket League demo is using CannonJS. I have taken a look at it, but I need something a bit simpler to study I'm mostly interested in how it rewinds and redoes the simulations. Right now I'm cheating when I do that. You could theoretically use either ThreeJS or CannonJS, as both can be run on NodeJS. I use CannonJS on the backend, but for less physics-aware games, I would absolutely prefer getting BabylonJS to run instead, so the tools and functions can remain the same. The bare minimum must be something like creating a scene with a "world", primitive shapes and the vector functions, like .set, .translate, .multiply etc. Let us know if you are able to run the basics in NodeJS. Well yeah, reconcilitation is quite hard, I have also used another method than the classic one which I believe is even more performant and logical. About nodejs, I don't think it is worth the hassle, if electron runs it and I already saw that it was very fast, that should do. In any case, my code won't be related to the platform so should be portable very easily. If I decide change to pure nodejs someday and find a way I will definitely let you guys know! Also if there are other solutions available please let me know. Best Regards, RelativeNull. Arte 1 Quote Link to comment Share on other sites More sharing options...
Raggar Posted October 5, 2017 Share Posted October 5, 2017 I have an old-ish project I haven't touched in some months. I chose to start out by doing something simpler, to try and release a game. It didn't end up any simpler, like, at all. But in that project I used the classic prediction, reconciliation and interpolation strategies. It worked very good at that time. Although, testing it today it was.. well.. not good at all. I'll have to figure out why that is. But I might as well rewrite the project, as a lot of my code has changed since then. Quote Link to comment Share on other sites More sharing options...
FunFetched Posted October 5, 2017 Share Posted October 5, 2017 2 hours ago, RelativeNull said: Hey, well I just installed a window and navigation dependency for nodejs and it didn't give problems. However creating an engine gave a webgl context problem ( understandable ). I didn't go much further as I noticed that the headless webgl dependencies of Nodejs were all outdated, probably there might be a hack to it however I think I will just go with electron. I managed to run it headlessly and I read somewhere that it used the nodejs engine rather that of chromium. If that is the case I don't see any reason why I shouldn't go with it. Oh, interesting. I had no idea that there was a window package for NodeJS. Makes sense, I suppose. The only thing I'd be concerned with there is that it might be using a lot of CPU to do things that you don't need done on the server side. On the other hand, if you never start engine.renderLoop, then maybe you're okay. Quote Link to comment Share on other sites More sharing options...
RNull Posted October 5, 2017 Author Share Posted October 5, 2017 1 hour ago, FunFetched said: Oh, interesting. I had no idea that there was a window package for NodeJS. Makes sense, I suppose. The only thing I'd be concerned with there is that it might be using a lot of CPU to do things that you don't need done on the server side. On the other hand, if you never start engine.renderLoop, then maybe you're okay. Yeah me neither. Seems like there is also a complete DOM package as well. Yeah I think I will check things on my way, if optimizations will be needed I will work it out thanx for the tips ! Btw, is your server fully authoritative or something in-between? Quote Link to comment Share on other sites More sharing options...
FunFetched Posted October 8, 2017 Share Posted October 8, 2017 On 10/5/2017 at 1:13 PM, RelativeNull said: Yeah me neither. Seems like there is also a complete DOM package as well. Yeah I think I will check things on my way, if optimizations will be needed I will work it out thanx for the tips ! Btw, is your server fully authoritative or something in-between? Fully-authoritative (it's the only way to go). Well, the only thing that isn't is the player's rotation, which doesn't matter, as "hacking" it is pointless. There's simulation on the client side, which uses the same code that I have on the server, but that's just to allow instant-feedback for movement inputs. The player's position is then nudged (or warped occasionally, if your connection is poor) if it gets out of sync with the server. Quote Link to comment Share on other sites More sharing options...
RNull Posted October 8, 2017 Author Share Posted October 8, 2017 3 hours ago, FunFetched said: Fully-authoritative (it's the only way to go). Well, the only thing that isn't is the player's rotation, which doesn't matter, as "hacking" it is pointless. There's simulation on the client side, which uses the same code that I have on the server, but that's just to allow instant-feedback for movement inputs. The player's position is then nudged (or warped occasionally, if your connection is poor) if it gets out of sync with the server. I couldn't agree more, I was just wondering since you took a part of babylon code for the server. Well I have l played your game and really enjoyed it, kudos to you! I am not a FPS player but hey, your game made it cool for me . I almost finished the multiplayer code, well most of it, I am still to code the lag compensation for the battles but shouldn't take too much time . Btw I found your game unplayable in some old pcs, being so simple probably it could be more optimized? Quote Link to comment Share on other sites More sharing options...
RNull Posted October 12, 2017 Author Share Posted October 12, 2017 For anyone interested ( pinging @Arte ), I have managed to run Babylon on node using just the requirements of window object, headless-gl and a xmlhttprequest. Other than that seems like Babylon loads up fine. I am using xmlhttprequest because I am loading the models ( I use animation end to define damage ), probably you might not need it at all if all you want to do is computations. Below you can find a snippet of code which works for me. I'll be happy to answer any questions . var express = require('express'); const Window = require('window'); global.window = new Window(); global.HTMLElement = window.HTMLElement; global.HTMLImageElement = window.HTMLImageElement; global.Image = window.Image; global.document = window.document; global.navigator = global.window.navigator; global.XMLHttpRequest = require('w3c-xmlhttprequest').XMLHttpRequest; var BABYLON = require('babylonjs'); var canvas = global.window.document.createElement('canvas'); var width = 64; var height = 64; var gl = require('gl')(width, height, { preserveDrawingBuffer: true }) canvas.getContext = function(thecontext,options){ return gl; } canvas.addEventListener = function (event,options){ return 1; } var engine = new BABYLON.Engine(canvas, true); BitOfGold and Arte 1 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 12, 2017 Share Posted October 12, 2017 I plan to soon work on headless engine for babylon.js where window and gl won't be required Arte 1 Quote Link to comment Share on other sites More sharing options...
RNull Posted October 12, 2017 Author Share Posted October 12, 2017 20 minutes ago, Deltakosh said: I plan to soon work on headless engine for babylon.js where window and gl won't be required @Deltakosh Yeah I have seen the issue in Github and also the various posts. However, in the mean time, we could use this as a solution. I don't think changing to the headless version when it is out will affect the code much, right ? Also if I am not wrong, work on headless version will start after 3.1 so it might take awhile. Performance-wise, if we never call scene.render there won't be any differences or not ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 13, 2017 Share Posted October 13, 2017 Actually most of the code is done Here is a node.js sample:https://github.com/BabylonJS/Babylon.js/tree/master/tests/nullEngine Raggar, BitOfGold, Arte and 1 other 4 Quote Link to comment Share on other sites More sharing options...
Raggar Posted October 13, 2017 Share Posted October 13, 2017 1 hour ago, Deltakosh said: Actually most of the code is done Here is a node.js sample:https://github.com/BabylonJS/Babylon.js/tree/master/tests/nullEngine Very nice. I did a quick test, and so far it seems to work. I tested some shapes and positions as well as the camera with collisions(Only gravity for now, as I can't really use the arrow keys out of the box). Quote Link to comment Share on other sites More sharing options...
RNull Posted October 15, 2017 Author Share Posted October 15, 2017 On 10/13/2017 at 8:34 PM, Deltakosh said: Actually most of the code is done Here is a node.js sample:https://github.com/BabylonJS/Babylon.js/tree/master/tests/nullEngine @Deltakosh That is quite amazing! Any idea when it may be complete ? Just wondering whether it will be ready before I publish my game or after, I plan to spend another couple of months before my first alpha. Do you think I will be able to run the server directly with it? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 16, 2017 Share Posted October 16, 2017 I hope to have a beta version by end of week Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 16, 2017 Share Posted October 16, 2017 Here we are: http://doc.babylonjs.com/generals/nullengine RNull, TomaszFurca, jerome and 2 others 5 Quote Link to comment Share on other sites More sharing options...
Aerion Posted October 17, 2017 Share Posted October 17, 2017 @DeltaKosh Please add the most simple ( meaning without using "this" or "prototype" but basic functions ) of a Babylon.js MMO example! Thank you! <3 ~M Quote Link to comment Share on other sites More sharing options...
RNull Posted October 17, 2017 Author Share Posted October 17, 2017 10 hours ago, Deltakosh said: Here we are: http://doc.babylonjs.com/generals/nullengine @Deltakosh Amazing, I am very excited to try it out. One note , probably in a second version the xmlhttprequest dependency can be replaced with a nodejs native system file reader ? I understand that you are trying to keep consistency between versions but it still looks a little bit ugly. Still better than with the window and gl dependencies though . 1 hour ago, Mythros said: @DeltaKosh Please add the most simple ( meaning without using "this" or "prototype" but basic functions ) of a Babylon.js MMO example! Thank you! <3 ~M @Mythros The problem with "a Babylon.js MMO example" is that it is not a Babylon.js example. A game to become multiplayer needs networking which is not in the scope of babylon.js. Here you have a phaser.io example using node.js and socket.io. The basics and concept apply to any render engine be it 3D or 2D.http://www.dynetisgames.com/2017/03/06/how-to-make-a-multiplayer-online-game-with-phaser-socket-io-and-node-js/ . For a more in-depth understanding of an authoritative server you can have a read or two here :https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking and http://www.gabrielgambetta.com/client-server-game-architecture.html Hope you find this information helpful. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.