lance-gg / lance

Multiplayer game server based on Node.JS
https://lance-gg.github.io/
Apache License 2.0
1.57k stars 166 forks source link

Custom renderers #75

Open trusktr opened 6 years ago

trusktr commented 6 years ago

https://github.com/lance-gg/lance/blob/78e91bc6a8ed62e44e1a0d95ea00480de72039fa/src/render/ThreeRenderer.js#L6-L12

I saw your comment there.

I have my own tool that I use for rendering: https://infamous.io

But I suppose that I need to somehow hook it up with Lance in order to take advantage of the client-side prediction of player position, to mitigate network lag, etc. (if I understand correctly, this is what Lance does)

What are requirements for making a renderer? I mean, I see the Renderer source, but some actual guides would be better. Maybe this discussion can be a starting point for that.

trusktr commented 6 years ago

Let me also follow the tutorial, that might help...

OpherV commented 6 years ago

That's a very good question, and I really appreciate your help in starting a meaningful discussion :) You have good timing, as I'm actually in the process of refactoring the Pixi renderer for the upcoming Lance v2.

There are two "levels" of renderers - let's call those "Infrastructure renderers" and "game-title renderers".

Infrastructure renderers included renderers like the Pixi.js renderer and the Three.js renderer. They're the connecting glue between Lance (networking) and display (drawing pixels on the screen). They don't actually implement the drawing put themselves, but they're used to hook up Lance to a an actual drawing API and take care the basic needs of multiplayer game rendering. These include things like object creation, object destruction and object updating. Lance itself takes care of "easing" the pain caused by communication latency and syncing (prediction, like you mentioned).

The "game-title renderers" are those implemented by game developers using Lance - they use the APIs provided by Lance to implement their own game title. So any game-specific rendering required for their game will go there.

So requirements for a "renderer" in the Lance case would be to make sure the corresponding display-objects for each game object are created, updated, and destroyed. "Updated" could mean gameplay-specific property updating (like position, which powerup is active) or cosmetic updates (a character's shadow, or idle animation - the arguably that would probably be implemented in the game-title renderer). This gets further complicated by the fact that a game object could consists of sub-render objects. Imagine a tank game object. It's rendering objects and sub-objects could consist of the tank body, wheels, independently rotating turret, smoke particle emitter, and fire particle emitter as it fires.

Does that make sense?

btw infamous.io looks really neat!