Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/client/engine/controls/InputHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,23 @@ InputHandler.prototype = {
}
}
},

_pointerMoveHandler: function(pointer) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at src/client/objects/sector/Movement.js - an old version of how to detect mouse movement without events is commented out...

You probably don't need to edit InputHandler.js

// Abort. We've been destroyed.
if(this.sprite === null) { return; }

var sendEvent, data = this._pointerData[pointer.id];
if(data.isOver || pointer.dirty) {
sendEvent = data.isOver;

data.x = pointer.x - this.sprite.x;
data.y = pointer.y - this.sprite.y;

if(sendEvent && this.sprite) {
this.sprite.emit('inputMove', this.sprite, pointer);
}
}
},

_pointerOutHandler: function(pointer) {
// Abort. We've been destroyed.
Expand Down
2 changes: 2 additions & 0 deletions src/client/engine/controls/Pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ Pointer.prototype = {
while(i--) {
input.moveCallbacks[i].callback.call(input.moveCallbacks[i].context, this, this.x, this.y, fromClick);
}

input.interactiveItems.callAll('_pointerMoveHandler', this);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't actually need to call move on all the interactive objects, that's more for click down and up events (like draggin)


// Easy out if we're dragging something and it still exists
if(this.targetObject !== null && this.targetObject.isDragged === true) {
Expand Down
33 changes: 24 additions & 9 deletions src/client/objects/sector/InputManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,47 @@ function Selection(game) {
return true;
};

this.world.on('inputUp', this._onInput, this);
this.world.on('inputDown', this._onInput, this);
};
this.world.on('inputDown', this._onInputDown, this);
this.world.on('inputUp', this._onInputUp, this);
this.world.on('inputMove', this._onInputMove, this);
}

Selection.prototype.constructor = Selection;

Selection.prototype._onInput = function(world, pointer) {
Selection.prototype._emitInputAction = function(dataType, pointer, emitPrimary, emitSecondary) {
var data = {
type: pointer.isDown ? 'start' : 'stop',
type: dataType,
target: {
x: pointer.x,
y: pointer.y
}
};
if(pointer.button === engine.Mouse.LEFT_BUTTON) {
if (emitPrimary) {
this.game.emit('ship/primary', data);
} else if(pointer.button === engine.Mouse.RIGHT_BUTTON) {
}
if (emitSecondary) {
this.game.emit('ship/secondary', data);
}
};

Selection.prototype._onInputDown = function(world, pointer) {
this._emitInputAction('start', pointer, pointer.button === engine.Mouse.LEFT_BUTTON, pointer.button === engine.Mouse.RIGHT_BUTTON);
};

Selection.prototype._onInputUp = function(world, pointer) {
this._emitInputAction('stop', pointer, pointer.button === engine.Mouse.LEFT_BUTTON, pointer.button === engine.Mouse.RIGHT_BUTTON);
};

Selection.prototype._onInputMove = function(world, pointer) {
this._emitInputAction('move', pointer, pointer.leftButton.isDown, pointer.rightButton.isDown);
};

Selection.prototype.destroy = function() {
this.input.destroy();

this.world.removeListener('onDown', this._onInput);
this.world.removeListener('onUp', this._onInput);
this.world.removeListener('inputDown', this._onInputDown);
this.world.removeListener('inputUp', this._onInputUp);
this.world.removeListener('inputMove', this._onInputMove);

this.game =
this.input = undefined;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See:

Movement.prototype.move = function() {
...

You could probably do something similar here, in fact, that is what that function use to do, but it needs to be fixed and updated.

Expand Down
14 changes: 13 additions & 1 deletion src/client/objects/sector/ShipManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function ShipManager(game) {
this.glowEmitter = new GlowEmitter(this.game);
this.shockwaveEmitter = new ShockwaveEmitter(this.game);
this.fireEmitter = new FireEmitter(this.game);

// throttled function to plot ship course
this._throttledPlot = null;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can throttle using
this.game.clock.throttle(this.move, 100, this);


this.game.particles.add(this.explosionEmitter);
this.game.particles.add(this.flashEmitter);
Expand Down Expand Up @@ -217,14 +220,15 @@ ShipManager.prototype._primary = function(data) {
y: input.mousePointer.y
});
});
} else {
} else if (data.type === 'stop') {
this.autofire && clock.events.remove(this.autofire);
}
}
};

ShipManager.prototype._secondary = function(data) {
var game = this.game,
clock = this.clock,
ship = this.player,
socket = this.socket,
indicator = this.indicator,
Expand All @@ -239,6 +243,14 @@ ShipManager.prototype._secondary = function(data) {
uuid: ship.uuid,
destination: destination
});
} else if (data.type === 'move') {
this._throttledPlot = this._throttledPlot || clock.throttle(function (data) {
socket.emit('ship/plot', data);
}, 250); // throttle threshold
this._throttledPlot({
uuid: ship.uuid,
destination: destination
});
}
}
};
Expand Down