MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / init

Method init

source/game/objects/StarPhysicsObject.cpp:48–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48void PhysicsObject::init(World* world, EntityId entityId, EntityMode mode) {
49 if (mode == EntityMode::Master) {
50 LuaCallbacks physicsCallbacks;
51 physicsCallbacks.registerCallback("setForceEnabled", [this](String const& force, bool enabled) {
52 m_physicsForces.get(force).enabled.set(enabled);
53 });
54 physicsCallbacks.registerCallback("setCollisionPosition", [this](String const& collision, Vec2F const& pos) {
55 auto& collisionConfig = m_physicsCollisions.get(collision);
56 collisionConfig.xPosition.set(pos[0]);
57 collisionConfig.yPosition.set(pos[1]);
58 });
59 physicsCallbacks.registerCallback("setCollisionEnabled", [this](String const& collision, bool const& enabled) {
60 auto& collisionConfig = m_physicsCollisions.get(collision);
61 collisionConfig.enabled.set(enabled);
62 });
63 m_scriptComponent.addCallbacks("physics", std::move(physicsCallbacks));
64 }
65 Object::init(world, entityId, mode);
66 m_metaBoundBox = Object::metaBoundBox();
67 for (auto const& p : m_physicsForces) {
68 PhysicsForceRegion forceRegion = p.second.forceRegion;
69 forceRegion.call([pos = position()](auto& fr) { fr.translate(pos); });
70 m_metaBoundBox.combine(forceRegion.call([](auto& fr) { return fr.boundBox(); }));
71 }
72}
73
74void PhysicsObject::uninit() {
75 m_scriptComponent.removeCallbacks("physics");

Callers

nothing calls this directly

Calls 9

initFunction · 0.85
callMethod · 0.80
registerCallbackMethod · 0.45
setMethod · 0.45
getMethod · 0.45
addCallbacksMethod · 0.45
translateMethod · 0.45
combineMethod · 0.45
boundBoxMethod · 0.45

Tested by

no test coverage detected