Skip to content

Commit cea9b9f

Browse files
committed
Merge branch 'feature/cached_hooks' into dev
2 parents 39c0b98 + b6cc943 commit cea9b9f

5 files changed

Lines changed: 386 additions & 91 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
- [Chunk](#chunk)
6666
- [Builder](#builder)
6767
- [Changelog](#changelog)
68+
- [vX.Y.Z](#vxyz)
6869
- [v1.10.0](#v1100)
6970
- [v1.9.0](#v190)
7071
- [v1.8.0](#v180)
@@ -1668,6 +1669,11 @@ builder_mt:destruction_policy :: id -> builder
16681669

16691670
## Changelog
16701671

1672+
### vX.Y.Z
1673+
1674+
- Slightly improved performance of modifying operations for fragments with [`ON_INSERT`](#evolvedon_insert) and [`ON_REMOVE`](#evolvedon_remove) hooks
1675+
- Slightly improved performance of queries with [`EXPLICIT`](#evolvedexplicit) fragments
1676+
16711677
### v1.10.0
16721678

16731679
- Added the new [`evolved.lookup`](#evolvedlookup) and [`evolved.multi_lookup`](#evolvedmulti_lookup) functions that allow finding ids by their names

develop/all.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'develop.testing.build_tests'
2+
require 'develop.testing.cached_hooks_tests'
23
require 'develop.testing.cancel_tests'
34
require 'develop.testing.clone_tests'
45
require 'develop.testing.depth_tests'
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
local evo = require 'evolved'
2+
3+
evo.debug_mode(true)
4+
5+
do
6+
local f1, f2 = evo.id(2)
7+
8+
local insert_hook_calls = 0
9+
10+
if f1 < f2 then
11+
evo.set(f1, evo.ON_INSERT, function()
12+
insert_hook_calls = insert_hook_calls + 1
13+
end)
14+
else
15+
evo.set(f2, evo.ON_INSERT, function()
16+
insert_hook_calls = insert_hook_calls + 1
17+
end)
18+
end
19+
20+
do
21+
insert_hook_calls = 0
22+
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
23+
assert(insert_hook_calls == 1)
24+
evo.destroy(e)
25+
end
26+
27+
evo.remove(f1, evo.ON_INSERT)
28+
evo.remove(f2, evo.ON_INSERT)
29+
30+
do
31+
insert_hook_calls = 0
32+
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
33+
assert(insert_hook_calls == 0)
34+
evo.destroy(e)
35+
end
36+
37+
if f1 < f2 then
38+
evo.set(f1, evo.ON_INSERT, function()
39+
insert_hook_calls = insert_hook_calls + 2
40+
end)
41+
else
42+
evo.set(f2, evo.ON_INSERT, function()
43+
insert_hook_calls = insert_hook_calls + 2
44+
end)
45+
end
46+
47+
do
48+
insert_hook_calls = 0
49+
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
50+
assert(insert_hook_calls == 2)
51+
evo.destroy(e)
52+
end
53+
end
54+
55+
do
56+
local f1, f2 = evo.id(2)
57+
58+
local insert_hook_calls = 0
59+
60+
if f1 > f2 then
61+
evo.set(f1, evo.ON_INSERT, function()
62+
insert_hook_calls = insert_hook_calls + 1
63+
end)
64+
else
65+
evo.set(f2, evo.ON_INSERT, function()
66+
insert_hook_calls = insert_hook_calls + 1
67+
end)
68+
end
69+
70+
do
71+
insert_hook_calls = 0
72+
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
73+
assert(insert_hook_calls == 1)
74+
evo.destroy(e)
75+
end
76+
77+
evo.remove(f1, evo.ON_INSERT)
78+
evo.remove(f2, evo.ON_INSERT)
79+
80+
do
81+
insert_hook_calls = 0
82+
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
83+
assert(insert_hook_calls == 0)
84+
evo.destroy(e)
85+
end
86+
87+
if f1 > f2 then
88+
evo.set(f1, evo.ON_INSERT, function()
89+
insert_hook_calls = insert_hook_calls + 2
90+
end)
91+
else
92+
evo.set(f2, evo.ON_INSERT, function()
93+
insert_hook_calls = insert_hook_calls + 2
94+
end)
95+
end
96+
97+
do
98+
insert_hook_calls = 0
99+
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
100+
assert(insert_hook_calls == 2)
101+
evo.destroy(e)
102+
end
103+
end
104+
105+
do
106+
local f1, f2 = evo.id(2)
107+
108+
local remove_hook_calls = 0
109+
110+
if f1 < f2 then
111+
evo.set(f1, evo.ON_REMOVE, function()
112+
remove_hook_calls = remove_hook_calls + 1
113+
end)
114+
else
115+
evo.set(f2, evo.ON_REMOVE, function()
116+
remove_hook_calls = remove_hook_calls + 1
117+
end)
118+
end
119+
120+
do
121+
remove_hook_calls = 0
122+
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
123+
evo.destroy(e)
124+
assert(remove_hook_calls == 1)
125+
end
126+
127+
evo.remove(f1, evo.ON_REMOVE)
128+
evo.remove(f2, evo.ON_REMOVE)
129+
130+
do
131+
remove_hook_calls = 0
132+
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
133+
evo.destroy(e)
134+
assert(remove_hook_calls == 0)
135+
end
136+
137+
if f1 < f2 then
138+
evo.set(f1, evo.ON_REMOVE, function()
139+
remove_hook_calls = remove_hook_calls + 2
140+
end)
141+
else
142+
evo.set(f2, evo.ON_REMOVE, function()
143+
remove_hook_calls = remove_hook_calls + 2
144+
end)
145+
end
146+
147+
do
148+
remove_hook_calls = 0
149+
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
150+
evo.destroy(e)
151+
assert(remove_hook_calls == 2)
152+
end
153+
end
154+
155+
do
156+
local f1, f2 = evo.id(2)
157+
158+
local remove_hook_calls = 0
159+
160+
if f1 > f2 then
161+
evo.set(f1, evo.ON_REMOVE, function()
162+
remove_hook_calls = remove_hook_calls + 1
163+
end)
164+
else
165+
evo.set(f2, evo.ON_REMOVE, function()
166+
remove_hook_calls = remove_hook_calls + 1
167+
end)
168+
end
169+
170+
do
171+
remove_hook_calls = 0
172+
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
173+
evo.destroy(e)
174+
assert(remove_hook_calls == 1)
175+
end
176+
177+
evo.remove(f1, evo.ON_REMOVE)
178+
evo.remove(f2, evo.ON_REMOVE)
179+
180+
do
181+
remove_hook_calls = 0
182+
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
183+
evo.destroy(e)
184+
assert(remove_hook_calls == 0)
185+
end
186+
187+
if f1 > f2 then
188+
evo.set(f1, evo.ON_REMOVE, function()
189+
remove_hook_calls = remove_hook_calls + 2
190+
end)
191+
else
192+
evo.set(f2, evo.ON_REMOVE, function()
193+
remove_hook_calls = remove_hook_calls + 2
194+
end)
195+
end
196+
197+
do
198+
remove_hook_calls = 0
199+
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
200+
evo.destroy(e)
201+
assert(remove_hook_calls == 2)
202+
end
203+
end

develop/testing/main_tests.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,8 +2928,8 @@ do
29282928
last_insert_entity, last_insert_component = 0, 0
29292929
local e = evo.spawn({ [f2] = 21, [f1] = true })
29302930
assert(set_count == 2 and insert_count == 2)
2931-
assert(last_set_entity == e and last_set_component == 21)
2932-
assert(last_insert_entity == e and last_insert_component == 21)
2931+
assert(last_set_entity == e and (last_set_component == 21 or last_set_component == true))
2932+
assert(last_insert_entity == e and (last_insert_component == 21 or last_insert_component == true))
29332933
end
29342934

29352935
do
@@ -2948,8 +2948,8 @@ do
29482948
last_insert_entity, last_insert_component = 0, 0
29492949
local e = evo.spawn({ [f3] = 33, [f2] = 22 })
29502950
assert(set_count == 2 and insert_count == 2)
2951-
assert(last_set_entity == e and last_set_component == nil)
2952-
assert(last_insert_entity == e and last_insert_component == nil)
2951+
assert(last_set_entity == e and (last_set_component == nil or last_set_component == 22))
2952+
assert(last_insert_entity == e and (last_insert_component == nil or last_insert_component == 22))
29532953
end
29542954
end
29552955

0 commit comments

Comments
 (0)