Handling Input on the Server

Post your help queries and engine programming questions here

Handling Input on the Server

Postby paulstraw » Sun May 18, 2014 10:37 am

Hey all,

I've been working with Isogenic a lot after picking it up earlier this week. Things are great so far, but I'm still trying to wrap my head around the best way to handle inputs on the server side of things. For example, I'm syncing animations as described in this thread: http://www.isogenicengine.com/forum/viewtopic.php?f=5&t=46, but I can't figure out a "nice" way to do things on the server when an input "begins", but not continuously as it's held (e.g., I need to make some changes to the Box2D body when certain buttons are pressed, and need "momentary contact" for some types of jumps).

Right now, all my input handling is happening in a `ServerNetworkEvents` file, based on the 24.2-multiplayer example. So, basically stuff like this:

Code: Select all
  _onPlayerLeftDown: (data, clientId) ->
    ige.server.players[clientId].controls.left = true

  _onPlayerLeftUp: (data, clientId) ->
    ige.server.players[clientId].controls.left = false


That obviously leaves a lot to be desired, and doesn't give me any way to determine that the input state has changed in my class. Are there any examples or conventions I could go off of, or anyone who's solved this in an elegant/more extensible way?
User avatar
paulstraw
 
Posts: 3
Joined: Tue May 13, 2014 10:34 am
Location: Santa Cruz, CA

Re: Handling Input on the Server

Postby robaldred » Sun May 18, 2014 2:49 pm

Hi,
I don't know exactly what you want to do but if you refer to the 24.4-multiplayer-isometric-keyboard
The input control event messages are only sent once per state change from client->server (this is how it should be done) you don't keep sending playerControlLeftDown events for example, if the player keeps the key pressed, that's a huge waste of bandwidth, since key presses are absolute, either pressed or not.

If you look in PlayerComponent.js from that example you'll see what happens...
When a control is pressed on the client, it checks the current state of the control using a local cache of the control state in the player (on the client)
If the state of the control has changed since the last tick, the network event is triggered to the server.

The server side event listener, then deals with the request, in the examples this often doesn't do a lot, usually you just want to update the state of the player controls on the server but you can do what ever you want when an event is received on the server.

If you need an action that only happens once ever, you need to control that as well, but not by just updating the server's state of the controls...
Say something like jump, it only jumps once when pressed you don't jump continuously when the key is held.

I have a small platformer game which when I press space my character jumps... It really really simple.
I have a method jump on my player which I call when the playerJump event is received, the jump method then applies an impulse to the player entity.
Code: Select all
//client
if (ige.input.actionState('space')) {
    if (!this.playerControl.controls.space) {
        // record that space is pressed
        this.playerControl.controls.space = true;

        // tell the server about the space now being pressed
        ige.network.send('playerJump');
    }
} else {
    //record that space isn't pressed
    this.playerControl.controls.space = false;
}

//server
_onPlayerJump: function (data, clientId) {
    // handle the space pressed by calling jump() on our player
    ige.server.players[clientId].jump();
},
I don't work for Irrelon. All comments are my own.
I would strongly encourage anyone building production projects with Isogenic to buy a premium licence, it costs very little and will help towards continued development of the engine. Irrelon have spent thousands of hours developing this wonderful platform with many features found in AAA game engine.
User avatar
robaldred
 
Posts: 243
Joined: Wed Oct 23, 2013 8:09 pm
Location: Manchester, England


Return to Help & Questions

Who is online

Users browsing this forum: No registered users and 1 guest
cron