SuperSpaceEye / Some-Peripherals

MIT License
4 stars 4 forks source link

Raycasts cost more time when raycaster is inside other ship's purple frame #20

Open kamitojaeger opened 7 months ago

kamitojaeger commented 7 months ago

`--local gpu = peripheral.wrap("tm_gpu_0") local rc = peripheral.wrap("front") --local ccRd = peripheral.wrap("createcomputing:computerized_redstone_link_1") local modem = peripheral.wrap("back")

local euler_mode = false local depth_map = false local cache = false

local width_roll_range = math.rad(37.24) local height_pitch_range = math.rad(10) local max_distance = 512 local vector_fov = 1

--gpu.setSize(64,64,4,4,16) --gpu.refreshSize() local width, height = 260,256

local radarOn_OFF_FileName = "isRadarOn.txt" local radarFilterName = "radarFilter.txt"

height_pitch_range = height_pitch_range * (height/width)

local table_insert = table.insert

local function linspace(start, end_, num) local linspaced = {} if num == 0 then return linspaced end if num == 1 then table_insert(linspaced, start) return linspaced end

local delta = (end_ - start) / (num - 1)

for i = 0, num-2 do
    table_insert(linspaced, start+delta*i)
end
table_insert(linspaced, end_)

return linspaced

end

local x_axis = linspace(-width_roll_range, width_roll_range, width) local y_axis = linspace(-height_pitch_range, height_pitch_range, height)

print(# x_axis) print(# y_axis)

print("height " .. height) print("width " .. width)

local start = os.epoch("utc") local function yield() if (os.epoch("utc") - start > 1000) then os.queueEvent("yield") os.pullEvent("yield") start = os.epoch("utc") end end

function radarResultManagement(item,xr,max_distance,targetTable,radarFilterType)

local floor = math.floor
local maxD = max_distance
local t = targetTable

if radarFilterType == "VS-E" then
    local entityHit = item.is_entity
    local VS_ShipHit = false

    if item.ship_id ~= nil then
        VS_ShipHit = true
    end

    if VS_ShipHit then
        local distance = floor(((maxD - item.distance) / 2) + 0.5)
        local x = floor((xr * 100) + 130 + 0.5)
        local type = "Ship"
        local temTable = {x,distance,type}
        table.insert(t,temTable)
    elseif entityHit then
        local distance = floor(((maxD - item.distance) / 2) + 0.5)
        local x = floor((xr * 100) + 130 + 0.5)
        local type = "entity"
        local temTable = {x,distance,type}
        table.insert(t,temTable)
    end

elseif radarFilterType == "Entity" then

    local entityHit = item.is_entity
    if entityHit then
        local distance = floor(((maxD - item.distance) / 2) + 0.5)
        local x = floor((xr * 100) + 130 + 0.5)
        local type = "entity"
        local temTable = {x,distance,type}
        table.insert(t,temTable)
    end

elseif radarFilterType == "VS" then
    local VS_ShipHit = false

    if item.ship_id ~= nil then
        VS_ShipHit = true
    end

    if VS_ShipHit then
        local distance = floor(((maxD - item.distance) / 2) + 0.5)
        local x = floor((xr * 100) + 130 + 0.5)
        local type = "Ship"
        local temTable = {x,distance,type}
        table.insert(t,temTable)

    end

end

return t

end

function readConfig(txt) local fileName = txt local file = fs.open(fileName,"r") local line = tostring(file.readLine()) file.close() return line end

function writeInfo(text,txt) local fileName = txt local file = fs.open(fileName,"w") file.write(text) file.close() end

writeInfo("VS-E",radarFilterName)

local isRadarOn = readConfig(radarOn_OFF_FileName) local radarFilterType = readConfig(radarFilterName)

while true do isRadarOn = readConfig(radarOn_OFF_FileName) if isRadarOn == "ON" then local startTime = os.clock() targetTable ={} for x=1, width do isRadarOn = readConfig(radarOn_OFF_FileName) radarFilterType = readConfig(radarFilterName) if isRadarOn == "ON" then for y=1, height do yield() local yr = y_axis[y] local xr = x_axis[x] --print("x = "..xr .. " y = " .. yr) local item = rc.raycast(max_distance, {yr, xr, vector_fov}, euler_mode, true, cache) targetTable = radarResultManagement(item,xr,max_distance,targetTable,radarFilterType) end --targetDisplay(targetTable)

            local num = #targetTable
            if num >= 5000 then
                print("Auto Shut Down due to Info OverStress")
                isRadarOn = "OFF"
                modem.transmit(11459,11459,isRadarOn)
                writeInfo(isRadarOn,radarOn_OFF_FileName)
                writeInfo("VS-E",radarFilterName)
                break
            end

            yield()
            modem.transmit(11459,11459,targetTable)
        elseif isRadarOn == "OFF" then
            sleep()
        end

    end
    targetTable = nil
    local endTime = os.clock()
    local runTime = endTime - startTime
    print("runTime  " .. runTime)

elseif isRadarOn == "OFF" then
    --print("Radar Is Off")
    yield()
end

end

`

kamitojaeger commented 7 months ago

image (3) image (2) image (1) image

kamitojaeger commented 7 months ago

image update