MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / AttachPropagateMass

Function AttachPropagateMass

Descent3/attach.cpp:402–437  ·  view source on GitHub ↗

Adds and subtracts from mass from connections and disconnections

Source from the content-addressed store, hash-verified

400
401// Adds and subtracts from mass from connections and disconnections
402static void AttachPropagateMass(object *child, bool f_attach = true) {
403 object *new_parent;
404
405 if (!child)
406 return;
407
408 do {
409 new_parent = ObjGet(child->attach_parent_handle);
410 ASSERT(new_parent);
411 if (!new_parent) {
412 return;
413 }
414
415 float mass;
416
417 mass = Object_info[child->id].phys_info.mass;
418
419 if (mass < 0.0f)
420 mass = 0.0f;
421
422 ASSERT(new_parent->mtype.phys_info.mass >= 0.0f && mass >= 0.0f);
423
424 if (f_attach)
425 new_parent->mtype.phys_info.mass += mass;
426 else
427 new_parent->mtype.phys_info.mass -= mass;
428
429 if (new_parent->mtype.phys_info.mass < 0.0f) {
430 new_parent->mtype.phys_info.mass = 0.0f;
431 }
432
433 child = new_parent;
434
435 ASSERT(new_parent->mtype.phys_info.mass >= 0.0f);
436 } while (child->flags & OF_ATTACHED);
437}
438
439static inline void ComputeUltimateAttachParent(object *child) {
440 object *cur_obj = child;

Callers 2

AttachObjectFunction · 0.85
UnattachFromParentFunction · 0.85

Calls 1

ObjGetFunction · 0.85

Tested by

no test coverage detected