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
57 changes: 17 additions & 40 deletions shared/src/SimuloPhysicsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2182,57 +2182,34 @@ class SimuloPhysicsServer {
var springs: { p1: number[], p2: number[], image: string | null, line: { color: string, scale_with_zoom: boolean } | null, width: number }[] = []; // distance joints are considered springs
var mouseSprings: { p1: number[], p2: number[], image: string | null, line: { color: string, scale_with_zoom: boolean } | null, width: number }[] = [];
while (box2D.getPointer(joint)) {
var j = joint;
const j = joint;
joint = joint.GetNext();
if (j.GetType() == box2D.e_distanceJoint) {
var d = box2D.castObject(j, box2D.b2DistanceJoint);
var dData = d.GetUserData() as SimuloJointData;
const joint_type = j.GetType();
if (joint_type == box2D.e_distanceJoint || joint_type == box2D.e_mouseJoint) {
const d = box2D.castObject(j, box2D.b2DistanceJoint);
const dData = d.GetUserData() as SimuloJointData;
var image: string | null;
if (dData.image != null) {
image = dData.image;
}
else {
image = null;
}
var line: { color: string, scale_with_zoom: boolean } | null;
if (dData.line != null) {
line = dData.line;
}
else {
line = null;
}
springs.push({
p1: [d.GetAnchorA().get_x(), d.GetAnchorA().get_y()],
p2: [d.GetAnchorB().get_x(), d.GetAnchorB().get_y()],
image: image,
line: line,
width: dData.width,
});
}
else if (j.GetType() == box2D.e_mouseJoint) {
var m = box2D.castObject(j, box2D.b2MouseJoint);
var mData = m.GetUserData() as SimuloJointData;
var image: string | null;
if (mData.image != null) {
image = mData.image;
}
else {
image = null;
}
var line: { color: string, scale_with_zoom: boolean } | null;
if (mData.line != null) {
line = mData.line;
var line: { color: string, scale_with_zoom: boolean } | null = dData.line;

const spring = {
p1: [d.GetAnchorA().get_x(), d.GetAnchorA().get_y()],
p2: [d.GetAnchorB().get_x(), d.GetAnchorB().get_y()],
image: image,
line: line,
width: dData.width,
};
if (joint_type == box2D.e_distanceJoint) {
springs.push(spring);
}
else {
line = null;
mouseSprings.push(spring);
}
mouseSprings.push({
p1: [m.GetAnchorA().get_x(), m.GetAnchorA().get_y()],
p2: [m.GetAnchorB().get_x(), m.GetAnchorB().get_y()],
image: image,
line: line,
width: mData.width,
});
}
}
return { springs: springs, mouseSprings: mouseSprings };
Expand Down
5 changes: 4 additions & 1 deletion shared/src/SimuloServerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class SimuloServerController {
theme: SimuloTheme;
localClients: SimuloLocalClient[] = [];
selectedObjects: { [key: string]: (SimuloJoint | SimuloObject)[] } = {};
// counts the number of iterations done in nonpaused mode
itCount: number = 0;

sendAll(type: string, data: any) {
if (this.networkServer) {
Expand Down Expand Up @@ -125,9 +127,10 @@ class SimuloServerController {
this.physicsServer.loadWorld(this.savedWorld);
console.log("reverted to last step");
}
else {
else if (this.itCount % 40 == 0) {
this.savedWorld = this.physicsServer.saveWorld();
}
this.itCount++;
}
var render = this.physicsServer.render() as SimuloStep;

Expand Down