Skip to content

Commit

Permalink
Improve convertToLocationInView memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
pandamicro committed Jul 30, 2018
1 parent 11c5390 commit c9a21d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
7 changes: 4 additions & 3 deletions cocos2d/core/platform/CCInputManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
THE SOFTWARE.
****************************************************************************/

const js = require('../platform/js');
const macro = require('./CCMacro');
const sys = require('./CCSys');
const eventManager = require('../event-manager');

const TOUCH_TIMEOUT = macro.TOUCH_TIMEOUT;

let _vec2 = cc.v2();

/**
* This class manages all events of input. include: touch, mouse, accelerometer, keyboard
*/
Expand Down Expand Up @@ -379,9 +380,9 @@ let inputManager = {
if (touch_event) {
let location;
if (sys.BROWSER_TYPE_FIREFOX === sys.browserType)
location = locView.convertToLocationInView(touch_event.pageX, touch_event.pageY, pos);
location = locView.convertToLocationInView(touch_event.pageX, touch_event.pageY, pos, _vec2);
else
location = locView.convertToLocationInView(touch_event.clientX, touch_event.clientY, pos);
location = locView.convertToLocationInView(touch_event.clientX, touch_event.clientY, pos, _vec2);
if (touch_event.identifier != null) {
touch = new cc.Touch(location.x, location.y, touch_event.identifier);
//use Touch Pool
Expand Down
20 changes: 13 additions & 7 deletions cocos2d/core/platform/CCView.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,11 +760,8 @@ cc.js.mixin(View.prototype, {
vb.y = -vp.y / this._scaleY;
vb.width = cc.game.canvas.width / this._scaleX;
vb.height = cc.game.canvas.height / this._scaleY;
cc.game._renderContext.setOffset && cc.game._renderContext.setOffset(vp.x, -vp.y);
}

// reset director's member variables to fit visible rect
var director = cc.director;
policy.postApply(this);
cc.winSize.width = this._visibleRect.width;
cc.winSize.height = this._visibleRect.height;
Expand Down Expand Up @@ -962,10 +959,19 @@ cc.js.mixin(View.prototype, {
* @param {Object} relatedPos - The related position object including "left", "top", "width", "height" informations
* @return {Vec2}
*/
convertToLocationInView: function (tx, ty, relatedPos) {
var x = this._devicePixelRatio * (tx - relatedPos.left);
var y = this._devicePixelRatio * (relatedPos.top + relatedPos.height - ty);
return this._isRotated ? {x: this._viewportRect.width - y, y: x} : {x: x, y: y};
convertToLocationInView: function (tx, ty, relatedPos, out) {
let result = out || cc.v2();
let x = this._devicePixelRatio * (tx - relatedPos.left);
let y = this._devicePixelRatio * (relatedPos.top + relatedPos.height - ty);
if (this._isRotated) {
result.x = this._viewportRect.width - y;
result.y = x;
}
else {
result.x = x;
result.y = y;
}
return result;
},

_convertMouseToLocationInView: function (in_out_point, relatedPos) {
Expand Down

0 comments on commit c9a21d7

Please sign in to comment.