summaryrefslogtreecommitdiff
path: root/honey/ecs-systems.lua
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-04-15 01:56:14 -0500
committersanine <sanine.not@pm.me>2023-04-15 01:56:14 -0500
commite603997055259039cefcdceaece5604e3856e36d (patch)
treef09e2c8984b0e61438ac9f407fe9f8ab0b91fd9c /honey/ecs-systems.lua
parentf41a96c6669354ae49b6b5e42830d010571f8a36 (diff)
fix circular reference bug for physics objects
Diffstat (limited to 'honey/ecs-systems.lua')
-rw-r--r--honey/ecs-systems.lua24
1 files changed, 17 insertions, 7 deletions
diff --git a/honey/ecs-systems.lua b/honey/ecs-systems.lua
index 54bac89..47c0f6d 100644
--- a/honey/ecs-systems.lua
+++ b/honey/ecs-systems.lua
@@ -157,9 +157,11 @@ end
--===== physics =====--
+
physics = function(params)
local interval = params.interval or 0.016
local groupSize = params.groupSize or 20
+ local refs = {}
return {
db=params.db,
space=params.space,
@@ -169,14 +171,21 @@ physics = function(params)
priority=0,
update=function(self, dt)
+ for i, ref in ipairs(refs) do
+ print(i, ref.tbl, ref.physics)
+ end
local query = self.db:queryComponent("physics")
+
for id, physics in pairs(query) do
if not physics._body then
- physics._body = ode.BodyCreate(self.world)
+ print("add physics body for "..id)
+ local body = ode.BodyCreate(self.world)
physics._gc = honey.util.gc_canary(function()
print("releasing physics body for " .. id)
- ode.BodyDestroy(physics._body)
+ ode.BodyDestroy(body)
+ body = nil
end)
+
local mass = ode.MassCreate()
local class = physics.mass.class
if not class then
@@ -188,30 +197,31 @@ physics = function(params)
physics.mass.radius
)
end
- ode.BodySetMass(physics._body, mass)
+ ode.BodySetMass(body, mass)
local m = self.db:getComponent(id, "transform").matrix
ode.BodySetPosition(
- physics._body,
+ body,
m[1][4], m[2][4], m[3][4]
)
ode.BodySetRotation(
- physics._body,
+ body,
m[1][1], m[1][2], m[1][3],
m[2][1], m[2][2], m[2][3],
m[3][1], m[3][2], m[3][3]
)
ode.BodySetLinearVel(
- physics._body,
+ body,
physics.velocity[1],
physics.velocity[2],
physics.velocity[3]
)
ode.BodySetAngularVel(
- physics._body,
+ body,
physics.angularVelocity[1],
physics.angularVelocity[2],
physics.angularVelocity[3]
)
+ physics._body = body
end
end