@@ -192,48 +192,21 @@ local safe_serialize = function(value)
192
192
return minetest .serialize (deep_copy (value ))
193
193
end
194
194
195
- local interrupt = function (params )
196
- lc_update (params .pos , {type = " interrupt" , iid = params .iid })
197
- end
195
+ mesecon .queue :add_function (" lc_interrupt" , function (pos , iid , luac_id )
196
+ -- There is no luacontroller anymore / it has been reprogrammed / replaced
197
+ if (minetest .get_meta (pos ):get_int (" luac_id" ) ~= luac_id ) then return end
198
+ lc_update (pos , {type = " interrupt" , iid = iid })
199
+ end )
198
200
199
201
local getinterrupt = function (pos )
200
202
local interrupt = function (time , iid ) -- iid = interrupt id
201
203
if type (time ) ~= " number" then return end
202
- local iid = iid or math.random ()
203
- local meta = minetest .get_meta (pos )
204
- local interrupts = minetest .deserialize (meta :get_string (" lc_interrupts" )) or {}
205
- local found = false
206
- local search = safe_serialize (iid )
207
- for _ , i in ipairs (interrupts ) do
208
- if safe_serialize (i ) == search then
209
- found = true
210
- break
211
- end
212
- end
213
- if not found then
214
- table.insert (interrupts , iid )
215
- meta :set_string (" lc_interrupts" , safe_serialize (interrupts ))
216
- end
217
- minetest .after (time , interrupt , {pos = pos , iid = iid })
204
+ luac_id = minetest .get_meta (pos ):get_int (" luac_id" )
205
+ mesecon .queue :add_action (pos , " lc_interrupt" , {iid , luac_id }, time , iid , 1 )
218
206
end
219
207
return interrupt
220
208
end
221
209
222
- local handle_timer = function (pos , elapsed )
223
- local err = lc_update (pos , {type = " timer" })
224
- if err then print (err ) end
225
- return false
226
- end
227
-
228
- local gettimer = function (pos )
229
- local timer = function (time )
230
- if type (time ) ~= " number" then return end
231
- local nodetimer = minetest .get_node_timer (pos )
232
- nodetimer :start (time )
233
- end
234
- return timer
235
- end
236
-
237
210
local getdigiline_send = function (pos )
238
211
if not digiline then return end
239
212
-- Send messages on next serverstep
@@ -255,7 +228,6 @@ local create_environment = function(pos, mem, event)
255
228
pin = merge_portstates (vports , rports ),
256
229
port = vports ,
257
230
interrupt = getinterrupt (pos ),
258
- timer = gettimer (pos ),
259
231
digiline_send = getdigiline_send (pos ),
260
232
mem = mem ,
261
233
tostring = tostring ,
@@ -334,7 +306,6 @@ local do_overheat = function (pos, meta)
334
306
if overheat (meta ) then
335
307
local node = minetest .get_node (pos )
336
308
minetest .swap_node (pos , {name = BASENAME .. " _burnt" , param2 = node .param2 })
337
- minetest .get_meta (pos ):set_string (" lc_interrupts" , " " )
338
309
minetest .after (0.2 , overheat_off , pos ) -- wait for pending operations
339
310
return true
340
311
end
@@ -348,20 +319,6 @@ local save_memory = function(meta, mem)
348
319
meta :set_string (" lc_memory" , safe_serialize (mem ))
349
320
end
350
321
351
- local interrupt_allow = function (meta , event )
352
- if event .type ~= " interrupt" then return true end
353
-
354
- local interrupts = minetest .deserialize (meta :get_string (" lc_interrupts" )) or {}
355
- local search = safe_serialize (event .iid )
356
- for _ , i in ipairs (interrupts ) do
357
- if safe_serialize (i ) == search then
358
- return true
359
- end
360
- end
361
-
362
- return false
363
- end
364
-
365
322
local ports_invalid = function (var )
366
323
if type (var ) == " table" then
367
324
return false
375
332
376
333
lc_update = function (pos , event )
377
334
local meta = minetest .get_meta (pos )
378
- if not interrupt_allow (meta , event ) then return end
379
335
if do_overheat (pos , meta ) then return end
380
336
381
337
-- load code & mem from memory
@@ -412,10 +368,10 @@ local reset_meta = function(pos, code, errmsg)
412
368
" image_button_exit[9.72,-0.25;0.425,0.4;jeija_close_window.png;exit;]" ..
413
369
" label[0.1,5;" .. errmsg .. " ]" )
414
370
meta :set_int (" heat" , 0 )
371
+ meta :set_int (" luac_id" , math.random (1 , 1000000 ))
415
372
end
416
373
417
374
local reset = function (pos )
418
- minetest .get_meta (pos ):set_string (" lc_interrupts" , " " )
419
375
action (pos , {a = false , b = false , c = false , d = false })
420
376
end
421
377
@@ -541,21 +497,23 @@ minetest.register_node(nodename, {
541
497
reset (pos )
542
498
reset_meta (pos , fields .code )
543
499
local err = lc_update (pos , {type = " program" })
544
- if err then print (err ) end
545
- reset_meta (pos , fields .code , err )
500
+ if err then
501
+ print (err )
502
+ reset_meta (pos , fields .code , err )
503
+ end
546
504
end ,
547
505
on_timer = handle_timer ,
548
506
sounds = default .node_sound_stone_defaults (),
549
507
mesecons = mesecons ,
550
508
digiline = digiline ,
551
- is_luacontroller = true ,
552
509
virtual_portstates = { a = a == 1 , -- virtual portstates are
553
510
b = b == 1 , -- the ports the the
554
511
c = c == 1 , -- controller powers itself
555
512
d = d == 1 },-- so those that light up
556
513
after_dig_node = function (pos , node )
557
514
mesecon :receptor_off (pos , output_rules )
558
515
end ,
516
+ is_luacontroller = true ,
559
517
})
560
518
end
561
519
end
@@ -588,11 +546,12 @@ minetest.register_node(BASENAME .. "_burnt", {
588
546
reset (pos )
589
547
reset_meta (pos , fields .code )
590
548
local err = lc_update (pos , {type = " program" })
591
- if err then print (err ) end
592
- reset_meta (pos , fields .code , err )
549
+ if err then
550
+ print (err )
551
+ reset_meta (pos , fields .code , err )
552
+ end
593
553
end ,
594
554
sounds = default .node_sound_stone_defaults (),
595
- is_luacontroller = true ,
596
555
virtual_portstates = {a = false , b = false , c = false , d = false },
597
556
})
598
557
0 commit comments