auouymous wrote: ↑Sat Jun 12, 2021 02:40
sirrobzeroone wrote: ↑Sat Jun 12, 2021 01:09
I know Im basically talking to myself but helps me think and work through problems :)
If you were to give up, your public notes could be useful for someone else wanting to continue the project.
Good Point :)
This table removal bug was painful, the code is/was quiet difficult to follow and understand, and I got thrown off a couple of times:
Network.lua has essentially 3 scenarios:
[*]Deadend and placed
[*]Deadend and not placed
[*]Everything else
Now the code definition of a deadend is when a connection == 1, conduit or another machine count as a connection. the check radius is 1 node distance in each main axis
"Deadend and Placed" always works as the code always uses table.insert.
"Deadend and not placed" dosen't it uses a set nil event into the table of users
"Everything Else" I dont fully understand how this works but somehow this recalcs the whole network, the code leaves me scratching my head as it basically purges the whole network record,
but Im not sure how or when that gets rebuilt....anyway it works but my understanding on how very limited. edit: record is recaculated at next abm run and rebuilt and saved to "ele.graphcache".
So if you have two furnaces next to each other both connected, removing one will work okay as it drops through "Everything Else" as we have "2" connections and everything gets re-calc'd
G = Generator, F=Furnace, C=Conduit
If we have a single furnace we want to remove, this will drop through "Deadend and not placed"
problem is doing this it removed furnace by setting the table ref to nil so if it happened to be the highest number in the table everythign worked if its a mid number some will work some wont, if it was say no 1 no machine left on that network would work....
The code was a bit obscured but it was line 427:
Updating meant I had to adjust the "table" ref to "tables" so no local/inbuilt confusion as I need to use table.remove()
That then fixed the issue or seems to have....at least in my limited testing I no longer end up with a wonky network when removing furnaces...for a 1 line fix I had to add a ton of debug i removed nearly all of it....I added a note at the top of that section now indicating what it removes from where.
I see those 2 fix's although the second was small as fairly significant so I've uploaded the fixed network file to git. If someone feels like giving it a spin that would be great.
https://github.com/sirrobzeroone/elepower
Onto Powercells they are really brokwn now, dont work at all I think
EDIT-1 Power Cells just mostly broken, Connect generator directly to power cell and then have all machines come off of powercell. Cant have 2 batteries connected to a single Gen, they seem to bounce power back and forth and drain themselves...or I think thats whats happening. Use them at your own risk.....I think that was the case before.
EDIT-2 So I've been looking at the code and power cells already have a custom group of ele_storage at the moment that group gets dumped in with "ele_user" (crafting machines). I think if I add to the abm code such that if generators are generating enough power then power cells just get charged or if full ignored (same as crafting machines). However if generators are offline then the batteries kick in and provide power to the network. From an initial check through the code I cant see any major roadblocks, although bound to stumble on some headaches. Initally I'll make powercells and generators fully independent ie if any generator provides power (assuming not overloaded) then batteries do nothing. Once I get that working I'll see how hard it is to supplimenting from batteries, the problem with that is that the batteries will be causing some of the power drain on the generator so it could become a circular dependancy and require alot more checks....wouldnt want batteries bouncing power back and forth with each other for example.....
EDIT-3 I have 2 power cells on a single conduit with 1 solar panel and 1 furnace. During the day the solar panel charges the powercells and provides power to the furnace ie all charging. At night when the solar output drops to 0 the batteries kick in and supply power to the furnace. The only downside is at night the batteries provide the max they can so deplete really fast as they effectively rapid charge the furnace even if its not being used. Basically furnace drains them until its fully charged. Thats not particularly helpful behaviour as really just want batteries to provide a minimal on demand power if the machine is being used. So I want to look at that before committing any code, but at least my idea worked in principal and I was able to reuse a large proportaion of the existing code base ie minimal changes.
EDIT-4
Hmm my solution above although working in principal created a few bugs/issues:
[*] The way providers distribute power is done when the 1st provider is hit by the abm, however the abm still hits the others its just there storage is then 0 so powersupply is then 0 which was triggering my battery/powercell and depleting it unessecarly...fix I added a depeletion time and set the check as same as abm time ie 1 sec so if the dep time is <1 sec and pw_supply is 0 then dont run for batteries. If its dep time > 1 sec and pw_supply 0 then we run batteries - it seems to work although I havent done comprehensive testing.
[*] I've successfully lowered the power draw when on battery power however it still occurs even if machine is not active - So I need to improve this to check for machine active status as well, I could check node name for some machines as they have an "nodename_active" version but if a machine dosent have this it would still drain so I want to try and hook into the actual "power_used" just not sure were thats stored from second to second at the moment and I want to fix the issue below first.
[*]Somewhere along the way i've broken the powercell update code when they are being providers, probably as they dont recieve the provider template boilerplate code. behind the scenes the storage value is updating correctly just not updating with tooltip and when you click into formspec, they do all refresh as soon as the powercells start recieving power, but its very annoying and looks very broken.