Complete Box2D to Planck.js migration

- Replace Box2D.js with Planck.js physics engine
- Update all require paths from 'Lib/Vendor/Box2D' to 'Lib/Vendor/Planck'
- Convert Box2D contact listeners to Planck.js event system
- Fix all method name capitalization (Get* -> get*, Set* -> set*)
- Update collision detection system for Planck.js compatibility
- Server now starts successfully and basic physics working
- Character can land on platforms - core physics functional

Major milestone: Game now running on modern, maintained physics engine
This commit is contained in:
Karl Pannek 2025-07-16 15:01:59 +02:00
parent 875abd60d9
commit dc779def9c
43 changed files with 701 additions and 14524 deletions

View file

@ -53,8 +53,8 @@ function(Parent, nc, Parser, Settings) {
}
var difference = {
x: Math.abs(update.p.x - this.player.doll.body.GetPosition().x),
y: Math.abs(update.p.y - this.player.doll.body.GetPosition().y)
x: Math.abs(update.p.x - this.player.doll.body.getPosition().x),
y: Math.abs(update.p.y - this.player.doll.body.getPosition().y)
};
if(difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS &&
@ -67,8 +67,8 @@ function(Parent, nc, Parser, Settings) {
var body = this.player.doll.body;
var options = {
p: body.GetPosition(),
lv: body.GetLinearVelocity()
p: body.getPosition(),
lv: body.getLinearVelocity()
};
nc.trigger(nc.ns.channel.to.client.user.gameCommand.send + this.player.id, "positionStateReset", options);

View file

@ -4,7 +4,7 @@ define([
"Game/Config/Settings",
"Lib/Utilities/RequestAnimFrame",
"Lib/Utilities/NotificationCenter",
"Lib/Vendor/Box2D",
"Lib/Vendor/Planck",
"Game/Channel/Player",
"Game/Channel/GameObjects/GameObject",
"Game/Channel/GameObjects/Doll",
@ -131,8 +131,8 @@ function (Parent, PhysicsEngine, Settings, requestAnimFrame, nc, Box2D, Player,
/*
var body = this.physicsEngine.world.GetBodyList();
do {
if((getSleeping || body.IsAwake()) && body.GetType() === Box2D.Dynamics.b2Body.b2_dynamicBody) {
var userData = body.GetUserData();
if((getSleeping || body.isAwake()) && body.getType() === 'dynamic') {
var userData = body.getUserData();
if (userData instanceof GameObject) {
var gameObject = userData;

View file

@ -1,7 +1,7 @@
define([
"Game/Core/GameObjects/Doll",
"Game/Channel/GameObjects/Item",
"Lib/Vendor/Box2D",
"Lib/Vendor/Planck",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Assert"
],
@ -42,14 +42,14 @@ function (Parent, Item, Box2D, nc, Assert) {
Parent.prototype.onImpact.call(this, isColliding, fixture);
if(isColliding) {
var otherBody = fixture.GetBody();
var otherBody = fixture.getBody();
if(otherBody) {
var item = otherBody.GetUserData();
var item = otherBody.getUserData();
if(item instanceof Item) {
var itemVelocity = item.body.GetLinearVelocity();
//var itemMass = item.body.GetMass();
var itemVelocity = item.body.getLinearVelocity();
//var itemMass = item.body.getMass();
var ownVelocity = this.body.GetLinearVelocity();
var ownVelocity = this.body.getLinearVelocity();
var b2Math = Box2D.Common.Math.b2Math;
var absItemVelocity = b2Math.AbsV(itemVelocity);
@ -97,9 +97,9 @@ function (Parent, Item, Box2D, nc, Assert) {
if(!this.isAnotherPlayerNearby()) {
Assert.number(update.p.x, update.p.y);
Assert.number(update.lv.x, update.lv.y);
this.body.SetAwake(true);
this.body.SetPosition(update.p);
this.body.SetLinearVelocity(update.lv);
this.body.setAwake(true);
this.body.setPosition(update.p);
this.body.setLinearVelocity(update.lv);
}
};

View file

@ -1,6 +1,6 @@
define([
"Game/Core/GameObjects/GameObject",
"Lib/Vendor/Box2D"
"Lib/Vendor/Planck"
],
function (Parent, Box2D) {
@ -19,19 +19,19 @@ function (Parent, Box2D) {
return null;
}
if (this.body.GetType() === Box2D.Dynamics.b2Body.b2_staticBody) {
if (this.body.getType() === 'static') {
return null;
}
if (!getSleeping && !this.body.IsAwake()) {
if (!getSleeping && !this.body.isAwake()) {
return null;
}
return {
p: this.body.GetPosition(),
a: this.body.GetAngle(),
lv: this.body.GetLinearVelocity(),
av: this.body.GetAngularVelocity()
p: this.body.getPosition(),
a: this.body.getAngle(),
lv: this.body.getLinearVelocity(),
av: this.body.getAngularVelocity()
};
}

View file

@ -74,9 +74,9 @@ function (Parent, nc) {
Item.prototype.onCollisionChange = function(isColliding, fixture) {
if(isColliding) {
var otherBody = fixture.GetBody();
var otherBody = fixture.getBody();
if(otherBody) {
var otherItem = otherBody.GetUserData();
var otherItem = otherBody.getUserData();
if(otherItem instanceof Item) {
if(!this.lastMoved && !otherItem.lastMoved) return;

View file

@ -56,10 +56,10 @@ function (Parent, Settings, nc) {
for(var name in this.limbs) {
limbUpdateData[name] = {
p: this.limbs[name].GetPosition(),
a: this.limbs[name].GetAngle(),
lv: this.limbs[name].GetLinearVelocity(),
av: this.limbs[name].GetAngularVelocity()
p: this.limbs[name].getPosition(),
a: this.limbs[name].getAngle(),
lv: this.limbs[name].getLinearVelocity(),
av: this.limbs[name].getAngularVelocity()
};
}
updateData['limbs'] = limbUpdateData;