Skip to content

Commit da418cd

Browse files
committed
made LuaCollisionSystem only use handlers instead of global table
1 parent de28585 commit da418cd

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

common/systems/LuaCollisionSystem.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace kengine {
1616
LuaCollisionSystem(kengine::EntityManager & em)
1717
: putils::BaseModule(&em),
1818
_lua(*query<kengine::packets::LuaState::Response>(kengine::packets::LuaState::Query{}).state) {
19-
_lua["collisions"] = sol::new_table();
2019
_lua["collisionHandlers"] = sol::new_table();
2120
}
2221

@@ -25,9 +24,6 @@ namespace kengine {
2524
const auto & firstName = p.first.getName();
2625
const auto & secondName = p.second.getName();
2726

28-
_lua["collisions"][firstName] = secondName;
29-
_lua["collisions"][secondName] = firstName;
30-
3127
sol::table handlers = _lua["collisionHandlers"];
3228
handlers.for_each([&firstName, &secondName](auto && pair) {
3329
sol::function f = pair.second;

common/systems/LuaCollisionSystem.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44

55
### Behavior
66

7-
##### *"collisions"* table
8-
9-
Whenever a `Collision` packet is received, the `LuaCollisionSystem` adds an entry to the ***"collisions"*** table in the `LuaSystem`'s state.
10-
11-
After receiving a `Collision` between two entities *"A"* and *"B"*, the following will be true:
7+
Upon construction, a global `collisionHandlers` table is definde in the `LuaSystem`'s state. This table can be populated by scripts by adding functions with the following prototype:
128

139
```lua
14-
collisions["A"] == "B"
15-
collisions["B"] == "A"
10+
function (name, otherName) end
1611
```
1712

18-
The table is never purged or reset. Once a collision is processed, scripts should remove it from the table.
19-
20-
##### Collision handlers
13+
`name` and `otherName` are the names of the [GameObjects](../../GameObject.md) involved in the collision.
2114

22-
Whenever a `Collision` packet is received, the `LuaCollisionSystem` also looks for a `collis
15+
Whenever a `Collision` packet is received, the `LuaCollisionSystem` iterates over the `collisionHandlers` table and calls each handler it contains with the name of the two `GameObjects` involved.

0 commit comments

Comments
 (0)