mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fooled around with joints for hiding lag
This commit is contained in:
parent
f5eacb6335
commit
8f245f33d6
4 changed files with 68 additions and 12 deletions
|
|
@ -1,4 +1,4 @@
|
|||
define(function () {
|
||||
define(function () {
|
||||
|
||||
function Key () {
|
||||
this._active = false;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
define([
|
||||
"Lib/Vendor/Box2D",
|
||||
"Game/Core/GameController",
|
||||
"Game/Client/Physics/Engine",
|
||||
"Game/Client/View/ViewController",
|
||||
"Game/Client/Control/PlayerController",
|
||||
"Game/Core/NotificationCenter",
|
||||
"Lib/Utilities/RequestAnimFrame"
|
||||
"Lib/Utilities/RequestAnimFrame",
|
||||
"Game/Config/Settings"
|
||||
],
|
||||
|
||||
function (Parent, PhysicsEngine, ViewController, PlayerController, NotificationCenter, requestAnimFrame) {
|
||||
function (Box2D, Parent, PhysicsEngine, ViewController, PlayerController, NotificationCenter, requestAnimFrame, Settings) {
|
||||
|
||||
function GameController () {
|
||||
this.viewController = new ViewController();
|
||||
|
|
@ -23,6 +25,25 @@ function (Parent, PhysicsEngine, ViewController, PlayerController, NotificationC
|
|||
|
||||
GameController.prototype = Object.create(Parent.prototype);
|
||||
|
||||
GameController.prototype.makeMouseJoint = function(p) {
|
||||
var ground = this.physicsEngine.getGround();
|
||||
var body = this.me.getBody();
|
||||
|
||||
var def = new Box2D.Dynamics.Joints.b2MouseJointDef();
|
||||
|
||||
def.bodyA = ground;
|
||||
def.bodyB = body;
|
||||
def.target = p;
|
||||
|
||||
def.collideConnected = false;
|
||||
def.maxForce = 100;
|
||||
def.dampingRatio = 0.99;
|
||||
|
||||
this.mouse_joint = this.physicsEngine.world.CreateJoint(def);
|
||||
|
||||
body.SetAwake(true);
|
||||
}
|
||||
|
||||
GameController.prototype.destruct = function() {
|
||||
//destroy box2d world etc.
|
||||
};
|
||||
|
|
@ -51,10 +72,38 @@ function (Parent, PhysicsEngine, ViewController, PlayerController, NotificationC
|
|||
if(bodyName && updateData[bodyName]) {
|
||||
var update = updateData[bodyName];
|
||||
body.SetAwake(true);
|
||||
body.SetPosition(update.p);
|
||||
body.SetAngle(update.a);
|
||||
body.SetLinearVelocity(update.lv);
|
||||
body.SetAngularVelocity(update.av);
|
||||
|
||||
if(false && this.me && this.me.getBody() == body) {
|
||||
|
||||
var p = body.GetPosition();
|
||||
var x = update.p.x - p.x;
|
||||
var y = update.p.y - p.y;
|
||||
|
||||
var max = 0.5;
|
||||
var factor = 0.2;
|
||||
|
||||
//if(x > max || x < -max || y > max || y < -max) {
|
||||
if(!this.mouse_joint) this.makeMouseJoint(update.p);
|
||||
else this.mouse_joint.SetTarget(update.p);
|
||||
var self = this;
|
||||
/*setTimeout(function() {
|
||||
self.physicsEngine.world.DestroyJoint(self.mouse_joint);
|
||||
self.mouse_joint = null;
|
||||
}, Settings.WORLD_UPDATE_BROADCAST_INTERVAL / 2)*/
|
||||
//} else {
|
||||
//this.physicsEngine.world.DestroyJoint(this.mouse_joint);
|
||||
//this.mouse_joint = null;
|
||||
//}
|
||||
|
||||
// NEXT TIME, try to create a simple body, that gets position and velocities from server doll
|
||||
// and connect the joint to that.
|
||||
|
||||
} else {
|
||||
body.SetPosition(update.p);
|
||||
body.SetAngle(update.a);
|
||||
body.SetLinearVelocity(update.lv);
|
||||
body.SetAngularVelocity(update.av);
|
||||
}
|
||||
}
|
||||
} while (body = body.GetNext());
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ define({
|
|||
WALK_SPEED: 2.5,
|
||||
RUN_SPEED: 4.0,
|
||||
FLY_SPEED: 3.2,
|
||||
JUMP_SPEED: 3.0,
|
||||
JUMP_SPEED: 4.0,
|
||||
JUMP_UPLIFT: 0.05,
|
||||
|
||||
// restitution: bouncyness, friction: rubbing, density: mass
|
||||
|
|
@ -46,5 +46,5 @@ define({
|
|||
DEBUG_MODE: true,
|
||||
|
||||
// NETWORKING
|
||||
WORLD_UPDATE_BROADCAST_INTERVAL: 100
|
||||
WORLD_UPDATE_BROADCAST_INTERVAL: 70
|
||||
})
|
||||
|
|
@ -11,12 +11,17 @@ function (Settings, Box2D, CollisionDetector) {
|
|||
new Box2D.Common.Math.b2Vec2(0, Settings.BOX2D_GRAVITY),
|
||||
Settings.BOX2D_ALLOW_SLEEP
|
||||
);
|
||||
this.ground = null;
|
||||
}
|
||||
|
||||
Engine.prototype.getWorld = function () {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
Engine.prototype.getGround = function () {
|
||||
return this.ground;
|
||||
}
|
||||
|
||||
Engine.prototype.setCollisionDetector = function (player) {
|
||||
|
||||
var detector = new CollisionDetector(player);
|
||||
|
|
@ -24,7 +29,9 @@ function (Settings, Box2D, CollisionDetector) {
|
|||
}
|
||||
|
||||
Engine.prototype.createBody = function (bodyDef) {
|
||||
return this.world.CreateBody(bodyDef);
|
||||
var body = this.world.CreateBody(bodyDef);
|
||||
if(!this.ground) this.ground = body;
|
||||
return body;
|
||||
}
|
||||
|
||||
Engine.prototype.update = function () {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue