Design Problems in the Redstone Simulator
#1
I am a new developer. I have already fixes some bugs and while trying to fix some more of them today, I found out that there are
many issues with the redstone power cache "cIncrementalRedstoneSimulatorChunkData::m_CachedPowerLevels". This is actually the root cause for many problems. The concept of "powered blocks" is the wrong way to think about redstone. As an example take a look at this picture: (Vanilla)
   
There are actually two different power levels tranferred through the same block. This is possible because the game evaluates the redstone power level for the requested strength conceptually from the receiver to the source and not the other way around (like it is currently in Cuberite). This way different receivers can pick up different signals through the same block. That other concept makes everything complicated and some things like this do not currently work.

But there is more: The power cache uses a STL hash map and they wastes a lot of memory, does rather expensive lookups and trashes the CPU caches while the block data itself would most likely already be in the cache (the STL hash maps are especially bad because they are based on linked lists). Has anyone done measurements about this? Except if we change it to use something like a plain array for the cache, directly checking the power level should be faster. (It might be a good idea to do move some work in cChunk or cChunkMap to avoid extensive locking and access overhead)

While playing with Cuberite I often noticed that redstone got stuck. A clearly powered repeater would just not turn on. This was only fixable through reloading the world or rebuilding at another location. Some Plugins like WorldEdit caused that too. I am fairly certain that this issues were caused by the power cache that was probably not correctly updated in some circumstances.



Long story short:
The power cache has problems and I am not convinced that it even gives a speed up.
That is why I am thinking about removing it. That should simplify the code a lot and fix many subtle issues.

Any thoughts are welcome.Confusedhy:
Reply
Thanks given by:
#2
The design for each redstone handler tries to know as little about other things around it as possible, and just say when and what it needs updating. I added the power cache to know when there is a need to update, to prevent infinite loops, but do tell me how I can remove it, it is making the code quite unreadable and esoteric in places.

The image posted can't quite be reproduced because I haven't found a foolproof way of not letting wires link power other wires (if only vanilla didn't have this strange restriction!). The solid block in the middle, when asked by the bottom wire for the power that it can provide, only knows about the highest power previous delivered to it and stored in the cache, and that it was from another wire. The bottom wire therefore currently doesn't get any power (flawed implementation), despite a lower but valid, comparator source also powering the block.

I don't really know how to elegantly solve this problem. I suppose the idea of solid blocks acting as conduits (in terms of cSolidBlockHandler) needs refinement. Maybe the redstone controller could directly evaluate linked powering, and not through the limitations of a redstone handler. Any ideas?



For the stuck repeaters and this, you should submit bug reports. Smile
Reply
Thanks given by:
#3
Also, the above may make little sense if you haven't acquainted yourself with how the sim. currently works. Do ask for clarification if needed.
Reply
Thanks given by:




Users browsing this thread: 2 Guest(s)