Posts: 160
Threads: 31
Joined: Oct 2011
Thanks: 0
Given 0 thank(s) in 0 post(s)
Any ideas?
My guess is on every server tick the server checks every power giving redstone device for redstone wires up to X distance and follows them giving power to any device it's attached to within that distance?
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
My guess is the same as you, but instead of every tick only when the circuit changes
Posts: 160
Threads: 31
Joined: Oct 2011
Thanks: 0
Given 0 thank(s) in 0 post(s)
11-02-2011, 01:15 PM
(This post was last modified: 11-02-2011, 01:17 PM by rs2k.)
so, an on_circuit_change() class called whenever someone places a redstone torch, uses a lever or button/pressure plate, a block is changed within 1 square of a redstone device then?
Something like:
the class will check all blocks within 1 square doing something different for vertical blocks based on the device in the center square.
If a redstone device in that square is changed it calls the class again on the new square with a direction or position put into the class.
Something like a repeater will have to call the class after X server ticks based on what its setting is.
The class will change the redstone meta device meta data and move on if needed.
Posts: 160
Threads: 31
Joined: Oct 2011
Thanks: 0
Given 0 thank(s) in 0 post(s)
What functions might there already be in place for a block to look at the contents of the blocks around it?
Posts: 160
Threads: 31
Joined: Oct 2011
Thanks: 0
Given 0 thank(s) in 0 post(s)
11-04-2011, 05:26 AM
(This post was last modified: 11-04-2011, 05:36 AM by rs2k.)
Recursive, or something else? It won't be too difficult to make redstone work recursively, just really annoying. I've already figured out how to make a new redstone torch update all redstone wires around it. Have to think of a way to avoid infinite loops though.
What about something else though?
All wires belong to a virtual circuit.
Example:
2 redstone wire blocks at 0, 0, 120 and 1, 0, 120 belongs to virtual wire 1211 that connects to device piston 120 and power device redstone torch 219
if power device 219 turns off and no other virtual power devices are attached to virtual wire 1211, then all redstone wire in virtual wire 1211 are set to meta value 0 (off state). and all devices attached to virtual wire 1211 are checked for other power sources, if none are found then the device is turned off.
I can find a way to make this work with MySQL and PHP, and I'm positive there's a way to make it work with c++, I'm, just not sure how yet. I read something about has tables that might do the trick.
Each "state change event" should only happen once per tick or the server will do nothing but update redstone wires. I'm pretty sure this is how the notch server works which is what causes the lag when using repeaters. The problem with the notch server is the 16 wire length because of the recursive nature of his redstone design. The virtual circuit would eliminate that problem since the circuit won't care if the blocks are 16 or 16,000 blocks away. It will only calculate changes based on the devices attached to the wire being changed, not every 32 blocks per redstone device.
I'm not sure how you would import a redstone circuit yet. I guess when an unattached redstone device was found the redstone class would need to recursively recalculate the entire circuit all at once and load it as a new virtual circuit.
Virtual redstone circuits would either need to be saved in a file, or recalculated and put into memory every time the server was started. I think the later would be the safest way to do it, but would cause lag on VERY large circuits.
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
Are you sure you want the redstone to behave differently in MCServer? AFAIK redstone is just a floodfill with special behaviour calculated for special blocks at the beginning/end of each tick
Posts: 160
Threads: 31
Joined: Oct 2011
Thanks: 0
Given 0 thank(s) in 0 post(s)
11-06-2011, 04:46 AM
(This post was last modified: 11-06-2011, 04:56 AM by rs2k.)
I forgot to make that change to cRedstone.cpp and included the same problem in cPiston.cpp. Oops
I think the redstone class should be changed to not update blocks, but to build a queue of blocks that need to be changed and send all the blocks that need to be changed to the world tick queue.
Anyone else have any ideas on this?
Also, now that I have a working fill algorithm, I should probably change it to a more efficient one. I used the easiest one to program in as a proof of concept. Currently, a 10x10x1 block of redstone requires 344 block replacements instead of just 100, and I don't know how many times it checks each block. Probably more than 344 times
Posts: 160
Threads: 31
Joined: Oct 2011
Thanks: 0
Given 0 thank(s) in 0 post(s)
Success!
Redstone torches can now be used as a NOT gate and you can create redstone clocks. Redstone torches that are to be updated join a queue that the world tick goes through. The queue is pretty inefficient right now as a torch can be placed in it several times. The whole recursive nature of this style of redstone is really inefficient, but it works.
Still need to update several redstone device to work correctly when found and placed into a circuit. (Torches aren't completely done)