mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
new system for synchronizing game objects. fixes #74
This commit is contained in:
parent
3ef3a6abf9
commit
07dad646cf
19 changed files with 194 additions and 162 deletions
|
|
@ -83,8 +83,6 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
|
||||
var spawnTimeout = setTimeout(function() {
|
||||
player.spawn(spawnPoint.x, spawnPoint.y);
|
||||
// put it into
|
||||
self.gameObjects.animated.push(player);
|
||||
|
||||
var options = {
|
||||
id: player.id,
|
||||
|
|
@ -118,6 +116,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
|
||||
var update = {};
|
||||
|
||||
/*
|
||||
var body = this.physicsEngine.world.GetBodyList();
|
||||
do {
|
||||
if((getSleeping || body.IsAwake()) && body.GetType() === Box2D.Dynamics.b2Body.b2_dynamicBody) {
|
||||
|
|
@ -125,22 +124,33 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
|
||||
if (userData instanceof GameObject) {
|
||||
var gameObject = userData;
|
||||
|
||||
update[gameObject.uid] = {
|
||||
p: body.GetPosition(),
|
||||
a: body.GetAngle(),
|
||||
lv: body.GetLinearVelocity(),
|
||||
av: body.GetAngularVelocity()
|
||||
};
|
||||
|
||||
if(gameObject instanceof Doll) {
|
||||
update[gameObject.uid].as = gameObject.getActionState();
|
||||
update[gameObject.uid].laxy = gameObject.lookAtXY;
|
||||
var updateData = gameObject.getUpdateData();
|
||||
|
||||
if (updateData) {
|
||||
update[gameObject.uid] = updateData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} while (body = body.GetNext());
|
||||
*/
|
||||
|
||||
for (var uid in this.worldUpdateObjects) {
|
||||
|
||||
var gameObject = this.worldUpdateObjects[uid];
|
||||
|
||||
if (!(gameObject instanceof GameObject)) {
|
||||
console.warn('Cant find object ' + uid + ' in worldUpdateObjects pool (channel side), here is the object:');
|
||||
console.log(gameObject);
|
||||
continue;
|
||||
}
|
||||
|
||||
var updateData = gameObject.getUpdateData(getSleeping);
|
||||
|
||||
if (updateData) {
|
||||
update[gameObject.uid] = updateData;
|
||||
}
|
||||
}
|
||||
|
||||
return update;
|
||||
};
|
||||
|
|
@ -171,9 +181,11 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
GameController.prototype.getRuntimeItems = function() {
|
||||
var objects = [];
|
||||
|
||||
for (var i = 0; i < this.gameObjects.animated.length; i++) {
|
||||
if(this.gameObjects.animated[i] instanceof RubeDoll) {
|
||||
var object = this.gameObjects.animated[i];
|
||||
// This is using the level.createItem mechanism to
|
||||
// create the RubeDoll from its ItemSettings
|
||||
for (var uid in this.worldUpdateObjects) {
|
||||
if(this.worldUpdateObjects[uid] instanceof RubeDoll) {
|
||||
var object = this.worldUpdateObjects[uid];
|
||||
var options = object.options;
|
||||
options.x = object.getPosition().x;
|
||||
options.y = object.getPosition().y;
|
||||
|
|
|
|||
|
|
@ -98,6 +98,18 @@ function (Parent, Item, Box2D, Nc, Assert) {
|
|||
this.body.SetLinearVelocity(update.lv);
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.getUpdateData = function(getSleeping) {
|
||||
|
||||
var updateData = Parent.prototype.getUpdateData.call(this, getSleeping);
|
||||
|
||||
if(updateData) {
|
||||
updateData.as = this.getActionState();
|
||||
updateData.laxy = this.lookAtXY;
|
||||
}
|
||||
|
||||
return updateData;
|
||||
};
|
||||
|
||||
return Doll;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,39 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/GameObject"
|
||||
"Game/Core/GameObjects/GameObject",
|
||||
"Lib/Vendor/Box2D"
|
||||
],
|
||||
|
||||
function(Parent) {
|
||||
function (Parent, Box2D) {
|
||||
|
||||
return Parent;
|
||||
"use strict";
|
||||
|
||||
function GameObject(physicsEngine, uid) {
|
||||
Parent.call(this, physicsEngine, uid);
|
||||
}
|
||||
|
||||
GameObject.prototype = Object.create(Parent.prototype);
|
||||
|
||||
GameObject.prototype.getUpdateData = function(getSleeping) {
|
||||
|
||||
if (!this.body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.body.GetType() === Box2D.Dynamics.b2Body.b2_staticBody) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!getSleeping && !this.body.IsAwake()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
p: this.body.GetPosition(),
|
||||
a: this.body.GetAngle(),
|
||||
lv: this.body.GetLinearVelocity(),
|
||||
av: this.body.GetAngularVelocity()
|
||||
};
|
||||
}
|
||||
|
||||
return GameObject;
|
||||
});
|
||||
|
|
@ -8,8 +8,8 @@ function (Parent, Settings, FileSystem) {
|
|||
|
||||
"use strict";
|
||||
|
||||
function Level (uid, engine, gameObjects) {
|
||||
Parent.call(this, uid, engine, gameObjects);
|
||||
function Level (uid, engine) {
|
||||
Parent.call(this, uid, engine);
|
||||
}
|
||||
|
||||
Level.prototype = Object.create(Parent.prototype);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue