@@ -180,24 +180,115 @@ end
180
180
-- Signals
181
181
182
182
function mesecon :activate (pos , node , rulename )
183
- local effector = mesecon :get_effector (node .name )
184
- if effector and effector .action_on then
185
- effector .action_on (pos , node , rulename )
183
+ if MESECONS_GLOBALSTEP then
184
+ if rulename == nil then
185
+ for _ ,rule in ipairs (mesecon :effector_get_rules (node )) do
186
+ mesecon :activate (pos , node , rule )
187
+ end
188
+ return
189
+ end
190
+ add_action (pos , " on" , rulename )
191
+ else
192
+ local effector = mesecon :get_effector (node .name )
193
+ if effector and effector .action_on then
194
+ effector .action_on (pos , node , rulename )
195
+ end
186
196
end
187
197
end
188
198
189
199
function mesecon :deactivate (pos , node , rulename )
190
- local effector = mesecon :get_effector (node .name )
191
- if effector and effector .action_off then
192
- effector .action_off (pos , node , rulename )
200
+ if MESECONS_GLOBALSTEP then
201
+ if rulename == nil then
202
+ for _ ,rule in ipairs (mesecon :effector_get_rules (node )) do
203
+ mesecon :deactivate (pos , node , rule )
204
+ end
205
+ return
206
+ end
207
+ add_action (pos , " off" , rulename )
208
+ else
209
+ local effector = mesecon :get_effector (node .name )
210
+ if effector and effector .action_off then
211
+ effector .action_off (pos , node , rulename )
212
+ end
193
213
end
194
214
end
195
215
196
216
function mesecon :changesignal (pos , node , rulename , newstate )
197
- local effector = mesecon :get_effector (node .name )
198
- if effector and effector .action_change then
199
- effector .action_change (pos , node , rulename , newstate )
217
+
218
+ newstate = newstate or " on"
219
+ -- rulename = rulename or mesecon.rules.default
220
+ if MESECONS_GLOBALSTEP then
221
+ if rulename == nil then
222
+ for _ ,rule in ipairs (mesecon :effector_get_rules (node )) do
223
+ mesecon :changesignal (pos , node , rule , newstate )
224
+ end
225
+ return
226
+ end
227
+ add_action (pos , " c" .. newstate , rulename )
228
+ else
229
+ local effector = mesecon :get_effector (node .name )
230
+ if effector and effector .action_change then
231
+ effector .action_change (pos , node , rulename , newstate )
232
+ end
233
+ end
234
+ end
235
+
236
+ function execute_actions (dtime )
237
+ local nactions = mesecon .to_update
238
+ mesecon .to_update = {}
239
+ for _ ,i in ipairs (nactions ) do
240
+ node = minetest .env :get_node (i .pos )
241
+ if node .name == " ignore" then
242
+ add_action (i .pos , i .action , i .rname )
243
+ else
244
+ effector = mesecon :get_effector (node .name )
245
+ if i .action == " on" then
246
+ if effector and effector .action_on then
247
+ effector .action_on (i .pos , node , i .rname )
248
+ end
249
+ elseif i .action == " off" then
250
+ if effector and effector .action_off then
251
+ effector .action_off (i .pos , node , i .rname )
252
+ end
253
+ elseif i .action == " con" then
254
+ if effector and effector .action_change then
255
+ effector .action_change (i .pos , node , i .rname , " on" )
256
+ end
257
+ elseif i .action == " coff" then
258
+ if effector and effector .action_change then
259
+ effector .action_change (i .pos , node , i .rname , " off" )
260
+ end
261
+ end
262
+ end
263
+ end
264
+ local nactions = mesecon .r_to_update
265
+ mesecon .r_to_update = {}
266
+ for _ ,i in ipairs (nactions ) do
267
+ if i .action == " on" then
268
+ mesecon :receptor_on_i (i .pos , i .rules )
269
+ else
270
+ mesecon :receptor_off_i (i .pos ,i .rules )
271
+ end
272
+ end
273
+ end
274
+
275
+ minetest .register_globalstep (execute_actions )
276
+
277
+ function add_action (pos , action , rname )
278
+ for _ ,i in ipairs (mesecon .to_update ) do
279
+ if i .pos .x == pos .x and i .pos .y == pos .y and i .pos .z == pos .z and i .rname .x == rname .x and i .rname .y == rname .y and i .rname .z == rname .z then
280
+ if (i .action == " on" and action == " on" ) or (i .action == " off" and action == " off" ) then
281
+ -- nothing
282
+ elseif i .action == " coff" and action == " on" then i .action = " on"
283
+ elseif i .action == " con" and action == " off" then i .action = " off"
284
+ else
285
+ if action == " on" or action == " con" then i .action = " con" end
286
+ if action == " off" or action == " coff" then i .action = " coff" end
287
+ end
288
+ break
289
+ end
200
290
end
291
+ mesecon .to_update [# mesecon .to_update + 1 ] = {pos = pos , action = action , rname = rname }
201
292
end
202
293
203
294
-- Rules
0 commit comments