I've been toying with MC and perl for quite a bit and noticed a few strange things. A few notes first: my C knowledge is very rusty and I didn't look at the source yet. I think I'd figure out what exactly goes on, but it'd take me way too much time, so I'd prefer to ask here. Other than that, as I said, I'm using perl. Seeing that MC starts a new perl interpreter thread for each plugin script, I assume it will be the same for all other languages, with the only probable exception being LUA (not sure how exactly LUA scripts are parsed). This allows a bit of 'multitasking' or 'parallel processing', if you get the idea. This much said, here are my questions..
1. I've noticed that BroadcastPlugin() triggers the according function in all Plugins "simultaneously". This was confirmed by running 2 plugins and letting one of them sleep for 2 and the other for 3 seconds. Total processing time was 3 seconds. Quite logical so far, as I metioned before. But there is an interesting issue: MC seems to wait until all plugins return from the function (I see the reason for that), but if you let both send something to the output (with Note() for example), you will see that something arrives, but not what. The previous lines get "duplicated", and the output is redrawn -after- all plugins finish the job. To clarify, if you take those two plugins that sleep on BroadcastPlugin() and send back something like 'done sleeping {newline} slept X seconds' when finished, you will see something like this:
As I said, I see the reason for waiting for all plugins to finish the job before you continue (sleep() effectively freezes MC for the time), but since MC does realize that it gets something back, why is it not rendered as soon as its received?
2. When playing with OnPluginPacketReceived(), I kind of expected all plugins to get the original packet. But instead, MC seems to 'walk' through all plugins in the order they were loaded, passing the return of the previous to the next one. This is kind of 'unreliable', because while the plugins seem to be always loaded in the order you installed them, you can mess it up by reloading a plugin (this pushes it to the end of the list). This might be screaming for a new feature like definable order in which the plugins are loaded. And I've noticed something I don't quite understand yet.. If I let both plugins report back the time when they received the packet and the time when they were done with it and were about to return it, sometimes the second plugin reports a 'received' time that is -before- the 'returned' time of the first plugin, and yet works with the modified data of the first plugin (the difference being up to 1.5 milliseconds). I can only imagine that some MC functions, like Note(), work once again in another thread and allow the language interpreter to continue before that function actually finished the work. That would be very very strange though. Any explanation to that? I can supply the testing code if any of you wish to see it.
I hope this makes any sense to you all. Thanks for your patience!
1. I've noticed that BroadcastPlugin() triggers the according function in all Plugins "simultaneously". This was confirmed by running 2 plugins and letting one of them sleep for 2 and the other for 3 seconds. Total processing time was 3 seconds. Quite logical so far, as I metioned before. But there is an interesting issue: MC seems to wait until all plugins return from the function (I see the reason for that), but if you let both send something to the output (with Note() for example), you will see that something arrives, but not what. The previous lines get "duplicated", and the output is redrawn -after- all plugins finish the job. To clarify, if you take those two plugins that sleep on BroadcastPlugin() and send back something like 'done sleeping {newline} slept X seconds' when finished, you will see something like this:
...
Old line.
-> GO <- some command that sends the Broadcast
...
Old line.
Old line.
Old line. <- First plugin finished and sent back something, but its not displayed yet. Instead, the last lines get duped.
...
Old line.
PI_1 - done sleeping.
PI_1 - slept 2 seconds.
PI_2 - done sleeping.
PI_2 - slept 3 seconds. <- all plugins done, output is rendered here.
As I said, I see the reason for waiting for all plugins to finish the job before you continue (sleep() effectively freezes MC for the time), but since MC does realize that it gets something back, why is it not rendered as soon as its received?
2. When playing with OnPluginPacketReceived(), I kind of expected all plugins to get the original packet. But instead, MC seems to 'walk' through all plugins in the order they were loaded, passing the return of the previous to the next one. This is kind of 'unreliable', because while the plugins seem to be always loaded in the order you installed them, you can mess it up by reloading a plugin (this pushes it to the end of the list). This might be screaming for a new feature like definable order in which the plugins are loaded. And I've noticed something I don't quite understand yet.. If I let both plugins report back the time when they received the packet and the time when they were done with it and were about to return it, sometimes the second plugin reports a 'received' time that is -before- the 'returned' time of the first plugin, and yet works with the modified data of the first plugin (the difference being up to 1.5 milliseconds). I can only imagine that some MC functions, like Note(), work once again in another thread and allow the language interpreter to continue before that function actually finished the work. That would be very very strange though. Any explanation to that? I can supply the testing code if any of you wish to see it.
I hope this makes any sense to you all. Thanks for your patience!