Added a memory node, stores 16 values and takes into account an offset.

It's accessed using a channel in the form of sending a digiline message:
Channel: <prefix><address + offset>
Message:
 - For read: "get"
 - For write: a number (it doesn't really mind beyond that)
This commit is contained in:
Izaya 2016-10-06 14:47:51 +11:00
parent 43a8e5bbec
commit 0e489bcec4
3 changed files with 82 additions and 0 deletions

2
test3d_t416/depends.txt Normal file
View File

@ -0,0 +1,2 @@
default
digilines

80
test3d_t416/init.lua Normal file
View File

@ -0,0 +1,80 @@
local MEMSIZE=16
if not digiline then
print("Digilines not found.")
return
end
local oldprint=print
local function print(...)
for k,v in ipairs({...}) do
oldprint("[Test3D:T416] "..tostring(v))
end
end
print("Loading.")
local function t416_digiline_receive(pos, node, channel, msg)
print("Digiline: "..tostring(pos.x)..","..tostring(pos.y)..","..tostring(pos.z).."; Channel: "..tostring(channel).."; Message: "..tostring(msg))
local meta = minetest.get_meta(pos)
local mem = string.split(meta:get_string("mem"),"\n")
local ms = ""
local chan = meta:get_string("channel")
local memoffset = meta:get_int("startaddr")
if channel:sub(1,#chan) == chan and tonumber(channel:sub(#chan+1),16)+1-memoffset <= MEMSIZE and tonumber(channel:sub(#chan+1),16)+1-memoffset > 0 then
local memaddr = tonumber(channel:sub(#chan+1),16)+1-memoffset
print(memaddr)
if tostring(msg):lower() == "get" then
digiline:receptor_send(pos, digiline.rules.default, channel, tonumber(mem[memaddr] or 0))
print("Reading address "..tostring(memaddr)..": "..tostring(mem[memaddr]))
else
mem[memaddr] = tonumber(msg) or 0
for k,v in ipairs(mem) do
ms = ms .. tostring(v) .. "\n"
end
meta:set_string("mem",ms)
print("Set address "..tostring(memaddr).." to "..tostring(tonumber(msg)))
end
end
end
print("Created T416 digiline function")
local function t416_set_meta(pos)
local meta = minetest.get_meta(pos)
local ms = ""
for i = 1, 16 do
ms = ms .. "0\n"
end
meta:set_string("mem",ms)
meta:set_string("channel","Default")
meta:set_int("startaddr",0)
meta:set_string("formspec","size[5,12]\nlabel[0.4,0.5;T416 Memory Node (16 words)]\nfield[0.5,2;4,1;channel;Channel prefix;${channel}]\nfield[0.5,3;4,1;startaddr;Starting address;${startaddr}]\ntextarea[0.5,4;4,8;mem;Memory contents;${mem}]")
end
minetest.register_node("test3d_t416:t416", {
description = "T416 Memory Node",
tiles = {
{
image="t416.png",
animation={
type = "vertical_frames",
aspect_w=16,
aspect_h=16,
length=18,
length=1.8,
},
},
},
on_construct = t416_set_meta,
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
digiline = {
receptor = {},
effector = {
action = t416_digiline_receive
}
},
on_receive_fields = function(pos,_,fields,sender)
if fields.channel == nil then return end
local meta = minetest.get_meta(pos)
fields.channel = fields.channel or ""
meta:set_string("channel",fields.channel)
meta:set_int("startaddr",tonumber(fields.startaddr))
end
})
print("T416 node registered")

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B