craftyjs / Crafty

JavaScript Game Engine
http://craftyjs.com
MIT License
3.42k stars 558 forks source link

CraftyJS & NodeJS #440

Open mucaho opened 11 years ago

mucaho commented 11 years ago

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:

eldad87 commented 11 years ago

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

thanks!

mucaho commented 11 years ago

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:

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

mucaho commented 11 years ago

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.

eldad87 commented 11 years ago

Sorry, but I switched to isogenicengine.com

thanks anyway.

pencilking2002 commented 11 years ago

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

sashman commented 9 years ago

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

mucaho commented 9 years ago

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 commented 9 years ago

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 commented 8 years ago

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?

200sc commented 8 years ago

@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.

dekdevy commented 8 years ago

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