-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbatch_destroy_fuzz.lua
More file actions
121 lines (97 loc) · 2.98 KB
/
batch_destroy_fuzz.lua
File metadata and controls
121 lines (97 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
local evo = require 'evolved'
evo.debug_mode(true)
---
---
---
---
---
local __table_unpack = (function()
---@diagnostic disable-next-line: deprecated
return table.unpack or unpack
end)()
---
---
---
---
---
local all_entity_list = {} ---@type evolved.entity[]
for i = 1, math.random(1, 10) do
local entity = evo.id()
all_entity_list[i] = entity
end
for _, entity in ipairs(all_entity_list) do
for _ = 0, math.random(0, #all_entity_list) do
local fragment = all_entity_list[math.random(1, #all_entity_list)]
evo.set(entity, fragment)
end
if math.random(1, 5) == 1 then
evo.set(entity, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)
end
if math.random(1, 5) == 1 then
evo.set(entity, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT)
end
end
---
---
---
---
---
local should_be_destroyed_entity_set = {} ---@type table<evolved.entity, integer>
local should_be_destroyed_entity_list = {} ---@type evolved.entity[]
local should_be_destroyed_entity_count = 0 ---@type integer
local function collect_destroyed_entities_with(entity)
local entity_destroy_policy = evo.get(entity, evo.DESTROY_POLICY)
or evo.DESTROY_POLICY_REMOVE_FRAGMENT
if entity_destroy_policy == evo.DESTROY_POLICY_DESTROY_ENTITY then
for _, other_entity in ipairs(all_entity_list) do
if evo.has(other_entity, entity) and not should_be_destroyed_entity_set[other_entity] then
should_be_destroyed_entity_count = should_be_destroyed_entity_count + 1
should_be_destroyed_entity_list[should_be_destroyed_entity_count] = other_entity
should_be_destroyed_entity_set[other_entity] = should_be_destroyed_entity_count
end
end
end
end
local destroying_include_list = {} ---@type evolved.entity[]
for i = 1, math.random(1, #all_entity_list) do
local destroying_include = all_entity_list[math.random(1, #all_entity_list)]
destroying_include_list[i] = destroying_include
end
for _, entity in ipairs(all_entity_list) do
if evo.has_all(entity, __table_unpack(destroying_include_list)) then
collect_destroyed_entities_with(entity)
end
end
do
local r = math.random(1, 2)
local q = evo.builder():include(__table_unpack(destroying_include_list)):spawn()
if r == 1 then
evo.batch_destroy(q)
elseif r == 2 then
assert(evo.defer())
evo.batch_destroy(q)
assert(evo.commit())
end
end
---
---
---
---
---
local all_chunk_query = evo.spawn()
for chunk in evo.execute(all_chunk_query) do
assert(not chunk:has_any(__table_unpack(should_be_destroyed_entity_list)))
for _, fragment in ipairs(chunk:fragments()) do
assert(not evo.has_all(fragment, __table_unpack(destroying_include_list)))
end
end
for _, destroyed_entity in ipairs(should_be_destroyed_entity_list) do
assert(not evo.alive(destroyed_entity))
end
---
---
---
---
---
evo.destroy(__table_unpack(all_entity_list))
evo.collect_garbage()