How to weld large objects together?

studio crashed, there was probably a bug in there

1 Like

Fixed the code, but a possible problem

For large amount of cells like here, it can take upto 200 ms just to proccess if a cell can be deleted

Output shows the delay in ms. It prints every time a new cell is added

It practically runs through every cell and loops through all of its connections until it hits core.

Edit: I theorized a solution, where parts already proccessed to connect to the core are saved into a dictionary, and if a cell borders one of those, it is certain that its connected

>90% FASTER

After implementing cached paths, where cells that have already been calculated to have an indirect connection to Core, which if a cell is bordering one of these cells known to be indirectly connected to the core, then it knows that that cell is also indirectly connected.

This alongside stopping to check cells if a false is detected, is a very good optimization to the system

Could you show your code? I can try to optimize it further.

local function CheckIndirectConnection(checkCell, excludeCell, extraCache:{}?)
	local startos = os.clock()
	local alreadyListed = {excludeCell, leditorFol.cnct, leditorFol.temp}
	local connected = false
	
	local deteCache = extraCache or {}

	local function proccess(cell, notaddlist)
		if deteCache[cell] then connected = true return end
		table.insert(alreadyListed, cell)
		
		local size : Vector3 = cell.PrimaryPart.Size
		local radius = math.max(size.X, size.Y, size.Z) / 2
		
		local olp = OverlapParams.new()
		olp.FilterType = Enum.RaycastFilterType.Exclude
		olp.FilterDescendantsInstances = alreadyListed
		
		local inArea = workspace:GetPartBoundsInRadius(cell:GetPivot().Position, radius + .1, olp)
		local listedModels = {}
		for _, part in pairs(inArea) do
			local cellModel = FindModelParentOfCell(part)
			if cellModel.Name == "Core" then connected = true break end
			if not listedModels[cellModel] then
				listedModels[cellModel] = true
				if deteCache[cellModel] then connected = true break end
				proccess(cellModel)
			end
		end 
	end
	proccess(checkCell)
	return connected
end

local function CIC_all(list, excludeCell)
	local cancel = true
	local cachedSaved = {}
	for _, cell in pairs(list) do
		if cell.Name == "Core" then 
		else

			local bool = CheckIndirectConnection(cell, excludeCell, cachedSaved)
			if bool then
				cachedSaved[cell] = true
			else
				cancel = false
				break
			end
		end
	end
	return cancel
end

CIC_all (CheckIndirecConnection all) is the function called to check if removing a cell would effect any cell’s connection

oh yeah btw the benchmarks from the previous two screenshots are in ms, never mentioned that as I assumed it was self-explanatory

You can reuse overlapParams and also instead of doing:

if value == "alright" then

else
	-- Main code

You can do:

if value ~= "alright" then
	-- Main code

Code:

local function CheckIndirectConnection(checkCell, excludeCell, extraCache:{}?)
	local startos = os.clock()
	local alreadyListed = {excludeCell, leditorFol.cnct, leditorFol.temp}
	local connected = false

	local deteCache = extraCache or {}
	
	local olp = OverlapParams.new()
	olp.FilterType = Enum.RaycastFilterType.Exclude

	local function proccess(cell, notaddlist)
		if deteCache[cell] then connected = true return end
		table.insert(alreadyListed, cell)

		local size : Vector3 = cell.PrimaryPart.Size
		local radius = math.max(size.X, size.Y, size.Z) / 2

		olp.FilterDescendantsInstances = alreadyListed

		local inArea = workspace:GetPartBoundsInRadius(cell:GetPivot().Position, radius + .1, olp)
		local listedModels = {}
		for _, part in pairs(inArea) do
			local cellModel = FindModelParentOfCell(part)
			if cellModel.Name == "Core" then connected = true break end
			if not listedModels[cellModel] then
				listedModels[cellModel] = true
				if deteCache[cellModel] then connected = true break end
				proccess(cellModel)
			end
		end 
	end
	proccess(checkCell)
	return connected
end

local function CIC_all(list, excludeCell)
	local cancel = true
	local cachedSaved = {}
	for _, cell in pairs(list) do
		if cell.Name ~= "Core" then 
			local bool = CheckIndirectConnection(cell, excludeCell, cachedSaved)
			if bool then
				cachedSaved[cell] = true
			else
				cancel = false
				break
			end
		end
	end
	return cancel
end

You could also try using native code generation.

1 Like

Parallel Luau may also be useful.

The editor script was over 500 lines long but I decided to rewrite the entire script anew for readiability, performance and reliability issues.

Will update soon on the new algorithmn I will put inplace!