improvement(world): separate bodies from actor management

This commit is contained in:
Kazhnuz 2019-06-22 17:19:54 +02:00
parent 241baad935
commit 2b1bdd0be5
2 changed files with 13 additions and 16 deletions

View file

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased ## Unreleased
### Changed
- **world2D:** Use a list for bodies (hitboxes, etc) and one other for actors
### Fixed ### Fixed
- **world:** Remove a forgotten camera debug function - **world:** Remove a forgotten camera debug function

View file

@ -39,37 +39,30 @@ end
function World2D:initActors() function World2D:initActors()
self.currentCreationID = 0 self.currentCreationID = 0
self.actors = Bump.newWorld(50) self.actors = {}
self.bodies = Bump.newWorld(50)
end end
function World2D:registerActor(actor) function World2D:registerActor(actor)
actor.creationID = self.currentCreationID World2D.super.registerActor(self, actor)
self.currentCreationID = self.currentCreationID + 1 return self.bodies:add(actor, actor.x, actor.y, actor.w, actor.h)
return self.actors:add(actor, actor.x, actor.y, actor.w, actor.h)
end end
function World2D:removeActor(actor) function World2D:removeActor(actor)
return self.actors:remove(actor) World2D.super.removeActor(self, actor)
return self.bodies:remove(actor)
end end
function World2D:moveActor(actor, x, y, filter) function World2D:moveActor(actor, x, y, filter)
return self.actors:move(actor, x, y, filter) return self.bodies:move(actor, x, y, filter)
end end
function World2D:checkCollision(actor, x, y, filter) function World2D:checkCollision(actor, x, y, filter)
return self.actors:check(actor, x, y, filter) return self.bodies:check(actor, x, y, filter)
end end
function World2D:queryRect(x, y, w, h) function World2D:queryRect(x, y, w, h)
return self.actors:queryRect(x, y, w, h) return self.bodies:queryRect(x, y, w, h)
end
function World2D:countActors()
return self.actors:countItems()
end
function World2D:getActors()
return self.actors:getItems()
end end
return World2D return World2D