Mindustry icon indicating copy to clipboard operation
Mindustry copied to clipboard

Better power nodes yet again

Open buthed010203 opened this issue 2 years ago • 10 comments

It works

  • [x] I have read the contribution guidelines.
  • [x] I have ensured that my code compiles, if applicable.
  • [x] I have ensured that any new features in this PR function correctly in-game, if applicable.

buthed010203 avatar Mar 28 '22 18:03 buthed010203

@Anuken why do all the placed methods even have a if(net.client()) return;? They are never even be run on the client (at least in vanilla) anyways...

buthed010203 avatar Mar 30 '22 13:03 buthed010203

What are your thoughts on something like this? It would allow the node auto linking when placing powered blocks to work with surge towers and modded nodes while not sacrificing too much speed (if you use an IntFloatMap at least), I also suspect that indexer.eachBlock would be significantly faster than iterating every tile in a circle with a high maxRange hence why that is what is used now.

EDIT: There isn't an ordered IntFloatMap, pain EDIT2: I dont even need an IntFloatMap, I need a FloatIntMap lmao, I guess I can just use a standard ObjectIntMap since the boxing shouldnt really matter here image image

buthed010203 avatar Mar 30 '22 14:03 buthed010203

Is the maxRange optimization worth it? Even with surge towers, there shouldn't be that many buildings in range. My guess is that it's unnecessary.

eachBlock was added after this class was made and is generally superior to circle iteration, so yes, it should be used here.

Anuken avatar Mar 30 '22 14:03 Anuken

Is the maxRange optimization worth it? Even with surge towers, there shouldn't be that many buildings in range. My guess is that it's unnecessary.

So I guess I would just set maxRange to max(maxRange, laserRange) on every placement

buthed010203 avatar Mar 30 '22 14:03 buthed010203

Its pretty bad even with a map image

buthed010203 avatar Mar 30 '22 15:03 buthed010203

        tempTileEnts.sort((a, b) -> {
            int type = -Boolean.compare(a.block instanceof PowerNode, b.block instanceof PowerNode);
            if(type != 0) return type;
            return Float.compare(a.dst2(tile), b.dst2(tile));
        });
image

I guess when this was pasted into the getNodeLinks method, this sort wasn't changed... All of the blocks in the list are power nodes. Also wtf is up with the newline placement here

buthed010203 avatar Mar 30 '22 15:03 buthed010203

...this is getting pretty confusing and might even cause conflicts, so I'm just going to wait until the private branch merge until I can take a closer look.

Anuken avatar Mar 30 '22 15:03 Anuken

why do all the placed methods even have a if(net.client()) return;? They are never even be run on the client (at least in vanilla) anyways...

It's definitely redundant now, but I believe it was called at one point (before I refactored placement calls).

Anuken avatar Mar 30 '22 15:03 Anuken

~~The only issue now is that maxRange isnt set on world load... Should I add an Events.on(WorldLoadEvent) or just move the code to onproximityupdate?~~

I opted to just move it to onProximityAdded instead

buthed010203 avatar Mar 30 '22 15:03 buthed010203

ok this is ready to merge now

buthed010203 avatar Mar 30 '22 15:03 buthed010203