Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Base Station Script for Kino Drone (Holographic Rendering)
- local component = require("component")
- local event = require("event")
- local term = require("term")
- local modem = component.modem
- local hologram = component.hologram
- hologram.clear()
- local scan_data = {} -- Stores x, y, z, density values
- local scan_buffer = {} -- Buffer for batch processing
- local buffer_size = 10 -- ✅ Process in chunks of 50
- local max_scan_data = 2000 -- ✅ Limit memory usage
- -- Configuration
- modem.open(123) -- Open communication port
- local function debug(msg)
- print("[DEBUG] " .. msg)
- end
- -- ✅ Increase hologram scale (Fixes tiny display issue)
- hologram.setScale(1)
- -- ✅ Function to apply buffered scan data to the hologram
- local function process_buffer()
- for _, data in ipairs(scan_buffer) do
- local key = string.format("%d,%d,%d", data.tx, data.ty, data.tz)
- if not scan_data[key] then
- scan_data[key] = {data.tx, data.ty, data.tz, data.density}
- hologram.set(data.tx, data.ty, data.tz, 1)
- -- debug("✅ Placed block at: HX=" .. data.tx .. " HY=" .. data.ty .. " HZ=" .. data.tz)
- end
- end
- scan_buffer = {} -- ✅ Clear buffer
- end
- -- Main loop
- print("Base Station active. Waiting for Kino data...")
- while true do
- local _, _, sender, _, _, command, data = event.pull("modem_message")
- if command == "debug" then
- print("[Kino] " .. data)
- elseif command == "scan_data" then
- -- ✅ Convert received string back into a table
- for x, y, z, d in string.gmatch(data, "([^,]+),([^,]+),([^,]+),([^,]+)") do
- local tx = tonumber(x) + 24
- local ty = tonumber(y) + 7
- local tz = tonumber(z) + 24
- local density = tonumber(d)
- if density and density > 0 then
- -- ✅ Store data for future use
- table.insert(scan_buffer, {tx = tx, ty = ty, tz = tz, density = density})
- -- ✅ Process buffer when it reaches the limit
- if #scan_buffer >= buffer_size then
- process_buffer()
- end
- -- ✅ Cap total scan data to prevent memory overflow
- if #scan_data > max_scan_data then
- scan_data = {} -- Clear memory
- debug("[⚠️] Memory limit reached! Clearing old scan data.")
- end
- else
- debug("[⚠️] Invalid data format: " .. x .. "," .. y .. "," .. z .. "," .. d)
- end
- end
- elseif command == "newscan" then
- hologram.clear()
- hologram.setScale(1)
- scan_data = {} -- ✅ Clear stored scan data
- scan_buffer = {} -- ✅ Reset buffer
- elseif command == "base_sync" then
- modem.send(sender, 123, "base_ack")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement