From 0e489bcec421eff362cb27bcef617803f99f86d7 Mon Sep 17 00:00:00 2001 From: Izaya Orihara Date: Thu, 6 Oct 2016 14:47:51 +1100 Subject: [PATCH] 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:
Message: - For read: "get" - For write: a number (it doesn't really mind beyond that) --- test3d_t416/depends.txt | 2 + test3d_t416/init.lua | 80 ++++++++++++++++++++++++++++++++++ test3d_t416/textures/t416.png | Bin 0 -> 778 bytes 3 files changed, 82 insertions(+) create mode 100644 test3d_t416/depends.txt create mode 100644 test3d_t416/init.lua create mode 100644 test3d_t416/textures/t416.png diff --git a/test3d_t416/depends.txt b/test3d_t416/depends.txt new file mode 100644 index 0000000..2cec86e --- /dev/null +++ b/test3d_t416/depends.txt @@ -0,0 +1,2 @@ +default +digilines diff --git a/test3d_t416/init.lua b/test3d_t416/init.lua new file mode 100644 index 0000000..a8a88b3 --- /dev/null +++ b/test3d_t416/init.lua @@ -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") diff --git a/test3d_t416/textures/t416.png b/test3d_t416/textures/t416.png new file mode 100644 index 0000000000000000000000000000000000000000..e5bfed3840363a715966e6332eb1bec92a3d06c7 GIT binary patch literal 778 zcmV+l1NHogP)+v8?yE3yLO72OU8Q|lz<#VJq zAoSR2e^5#x#HcL!cn|pKE3M^Ua`mUYmeVeN+4jvp*TUfUmHy`;9i)0NdZ-!r^@u}{ zP(8xXBUX=e0f7fMkH#TWJ-CBZ4@HkS^hnhs3_U{iNJEc^9$Gy*2T%3T4pKer#eVM* zh90SUq@hO`d6*ScJsO8j^@ts0PJ7Ob9*iEQ5SZ$5l|A4gm>-ND`gJ{~=)ssDf*z(& zoa@m*Fh4SS2-Y8r9$GyVJs9f`L6402(K+UNgbsopg7rs652+sdvVv@ltJOo$BV+v` z=+QZ5=V=4M`h(F!uz$(bgI{LY9*C<)#{NangR%bT9CJNl2SE?T{-xyy5CVsr}2fETO+` z9)k5p#{ETx`60N!WUM~~J-GLC{YIYJ-(Il=&p%rKlF>u3{@~&M!dQO@dSvWh+Vc++ z^i!XIT-(|?Bcq34|H9~@!}>$fgRy@R^vL~rP%i}j