SquidDev-CC / CCTweaks

Random additions to ComputerCraft (somewhat deprecated, use CC-Tweaked if you're on Minecraft 1.12).
MIT License
12 stars 2 forks source link

Visitor visits every side #28

Closed SquidDev closed 9 years ago

SquidDev commented 9 years ago

The visitor currently visits every side that is connected on the node. This means that a packet can be received more than once on a network - as well as we scan peripherals multiple times on one node and we call networkInvalidated multiple times.

An alternative would be instead of testing for equality by checking the side we should test if this node isn't null and if it hasn't been visited already. This might require a rewrite of bits of the visitor though so should be fixed after feature/api-rewrites is merged.

ElvishJerricco commented 9 years ago

I must be missing something. Where does it add visited nodes to the visited set?

SquidDev commented 9 years ago

In the enqueue method. It is something like if(visited.add(location)). Visited returns false if it is already in the set.

ElvishJerricco commented 9 years ago

There we go, found it. Anyway, the issue now is that we're adding every location to the visited set, regardless of whether it can be visited or not. So if we try to visit a node through a cover, it gets added to visited, but doesn't get visited because of the cover. Then we don't try to visit it again from any other direction.

SquidDev commented 9 years ago

Yeah. You're right there. The thing is I want to ideally avoid fetching the node multiple times as the slowest bit will be running through the node providers. However storing the direction in the search location also doesn't work as otherwise we cannot find it.

ElvishJerricco commented 9 years ago

I think we just have to only add a node to visited when we actually visit it.