Advertisement
samuelask

Hologram New

Mar 9th, 2025 (edited)
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.77 KB | None | 0 0
  1. -- Base Station Script for Kino Drone (Holographic Rendering)
  2. local component = require("component")
  3. local event = require("event")
  4. local term = require("term")
  5. local modem = component.modem
  6. local hologram = component.hologram
  7.  
  8. hologram.clear()
  9.  
  10. local scan_data = {} -- Stores x, y, z, density values
  11. local scan_buffer = {} -- Buffer for batch processing
  12. local buffer_size = 10 -- ✅ Process in chunks of 50
  13. local max_scan_data = 2000 -- ✅ Limit memory usage
  14.  
  15. -- Configuration
  16. modem.open(123) -- Open communication port
  17.  
  18. local function debug(msg)
  19.     print("[DEBUG] " .. msg)
  20. end
  21.  
  22. -- ✅ Increase hologram scale (Fixes tiny display issue)
  23. hologram.setScale(1)
  24.  
  25. -- ✅ Function to apply buffered scan data to the hologram
  26. local function process_buffer()
  27.     for _, data in ipairs(scan_buffer) do
  28.         local key = string.format("%d,%d,%d", data.tx, data.ty, data.tz)
  29.         if not scan_data[key] then
  30.             scan_data[key] = {data.tx, data.ty, data.tz, data.density}
  31.             hologram.set(data.tx, data.ty, data.tz, 1)
  32.         --    debug("✅ Placed block at: HX=" .. data.tx .. " HY=" .. data.ty .. " HZ=" .. data.tz)
  33.         end
  34.     end
  35.     scan_buffer = {} -- ✅ Clear buffer
  36. end
  37.  
  38. -- Main loop
  39. print("Base Station active. Waiting for Kino data...")
  40. while true do  
  41.     local _, _, sender, _, _, command, data = event.pull("modem_message")
  42.  
  43.     if command == "debug" then
  44.         print("[Kino] " .. data)
  45.     elseif command == "scan_data" then
  46.         -- ✅ Convert received string back into a table
  47.         for x, y, z, d in string.gmatch(data, "([^,]+),([^,]+),([^,]+),([^,]+)") do
  48.             local tx = tonumber(x) + 24
  49.             local ty = tonumber(y) + 7
  50.             local tz = tonumber(z) + 24
  51.             local density = tonumber(d)
  52.  
  53.             if density and density > 0 then
  54.                 -- ✅ Store data for future use
  55.                 table.insert(scan_buffer, {tx = tx, ty = ty, tz = tz, density = density})
  56.                
  57.                 -- ✅ Process buffer when it reaches the limit
  58.                 if #scan_buffer >= buffer_size then
  59.                     process_buffer()
  60.                 end
  61.                
  62.                 -- ✅ Cap total scan data to prevent memory overflow
  63.                 if #scan_data > max_scan_data then
  64.                     scan_data = {} -- Clear memory
  65.                     debug("[⚠️] Memory limit reached! Clearing old scan data.")
  66.                 end
  67.             else
  68.                 debug("[⚠️] Invalid data format: " .. x .. "," .. y .. "," .. z .. "," .. d)
  69.             end
  70.         end
  71.     elseif command == "newscan" then
  72.             hologram.clear()
  73.             hologram.setScale(1)
  74.             scan_data = {} -- ✅ Clear stored scan data
  75.             scan_buffer = {} -- ✅ Reset buffer
  76.     elseif command == "base_sync" then
  77.             modem.send(sender, 123, "base_ack")
  78.     end
  79. end
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement