Crafty icon indicating copy to clipboard operation
Crafty copied to clipboard

CraftyJS & NodeJS

Open mucaho opened this issue 11 years ago • 11 comments

I have made a node module, which runs a slim version of the current crafty master version (0.5.3). It's still in development: npm_crafty

According to a Google Group Discussion about NodeJS & CraftyJS there is already some motivation to allow easy integration of crafty into a node server.

I was able to filter out the bulk of "unneeded" stuff for a server. As you can see here, some manual fine-tuning is required. If you allow a bit of refactoring, the whole process could be more automatized and clean:

  • the bold outlined components and Crafty features could be moved into seperate files

mucaho avatar Apr 01 '13 00:04 mucaho

Hi, I really want to see your project production ready so please let me know if I can help you develop it.

thanks!

eldad87 avatar May 18 '13 17:05 eldad87

Hi

The base goal is accomplished (logical communication between entities on server and clients). The pong example works fine on localhost. I hosted the pong example on a node server with xhr polling. Without handling the latency appropriately and introducing seperate game loops, the game is unplayable (see next paragraph).

The next level would be to further adjust input components, to introduce more game loops (network input/output loop, game state update loop) and to provide components for handling latency ( client-side: prediction & correction of client entities, interpolation of other entities; server-side: lag compensation).

I am not sure that providing these next level, high-level features would be such a good idea:

  • A lot of work. I do not have the time for it. Partial implementation is bad.
  • It would have to be implemented correctly: too much or too less abstraction -> user has to write his own networking code anyway
  • I am not sure if crafty is used for fully fledged networked games. Better to write an entire, specific "engine" combining crafty & networking? Networking for turn-based games is entirely different than for shooter games.

If you are still interested, let's continue the discussion on the github repository of npm_crafty.

mucaho avatar Jun 03 '13 10:06 mucaho

Just a quick update: BNG Article: Real Time Multiplayer in HTML 5

I have skimmed through the article, he has essentially using the above mentioned techniques for handling latency. It would just be a matter of translating his code into crafty components, right? :)

I still have to figure out if/how he has made the seperate update loops. Javascript is single-thread and when I hosted the pong example on the web server I got a wierd issue: Input from local client froze all entities except the local ones.

mucaho avatar Jun 16 '13 22:06 mucaho

Sorry, but I switched to isogenicengine.com

thanks anyway.

eldad87 avatar Jun 17 '13 08:06 eldad87

Any news on this yet? I really like crafty and would love to stick to it for multiplayer and node js!

pencilking2002 avatar Jun 19 '13 13:06 pencilking2002

Hey, are there any updates on this? What's the current state of crafty for use on nodeJS side?

sashman avatar Mar 02 '15 11:03 sashman

Crafty development has progressed with logic separation of components in mind (see #578). In its current state it is tremendously easier to build a server version than it was before. Coincidentally I am currently working on a new version of npm_crafty, so I will test out how to build Crafty for node and will report my findings here.

mucaho avatar Mar 02 '15 15:03 mucaho

Update: Majority of server-side stuff (except isometric) should run on nodejs now, you can also create multiple instances. (I just tested with an example game). You can test it for yourself if you copy the develop branch to the root folder of your node project and add "craftyjs": "./Crafty/" to your package.json dependencies. You can read more about local npm modules here. After that you do npm install and you should be able to create seperate instances by require('craftyjs')() (note the additional function call).

@starwed @kevinsimper Would it make sense to transfer npm_crafty over to the craftyjs organization (and possibly rename it to Crafty Net or something like that)? It has low-level client-server networking and automatic matchmaking is almost done. Roadmap includes implicit, high-level multiplayer support by extending features of current (input/control) components.

mucaho avatar Jul 16 '15 12:07 mucaho

By the way, @dekdevy and @Sythe2o0: I saw from your comments from another issues that you have used Crafty for networked games. Have you tried and/or had any issues require-ing and using Crafty on a node server?

mucaho avatar Mar 23 '16 23:03 mucaho

@mucaho
While we used a node server, we didn't have any crafty code server-side, only client-side, sorry. We didn't use require.

200sc avatar Mar 23 '16 23:03 200sc

@mucaho Same here, the client is crafty based, the server is not really using any game libraries since its only logic.

dekdevy avatar Mar 24 '16 18:03 dekdevy