<div class="gmail_quote">On Fri, Oct 26, 2012 at 1:27 PM, Giovanni Bajo <span dir="ltr"><<a href="mailto:giovannibajo@gmail.com" target="_blank">giovannibajo@gmail.com</a>></span> wrote:<br><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><div>Il giorno 26/ott/2012, alle ore 02:17, Dreammaster <<a href="mailto:dreammaster@scummvm.org" target="_blank">dreammaster@scummvm.org</a>> ha scritto:</div><div>Yup, in fact I wouldn't have thought it to be possible to refactor existing code from threads to coroutines :) How long did it take you?</div>
</div></div></blockquote><div><br>Several months of work in my off hours. Luckily, we already had a proven coroutine module that was created for the Tinsel engine, another of our game engines that runs the Discworld games. In their case, they used coroutines rather than threads, but the way they did it was horribly unportable, using the 'setjmp' and 'longjmp' functions to save the entire state of execution stacks and later restore them. One of the other developers, who I can't remember off the top of my head, adapted some C code from the Internet to simulate them, and then did further work to C++-ify the code, to make it easier to encapsulate local variables and have everything saved.<br>
<br>As a result, I just need to add a few more methods to support Windows-style Events (semaphores) that the game used, and it was already ready to use. Of course, since using the coroutine framework does require each method to be individually converted to use the macros, as you will have seen it code, it still took a lot of work to convert everything.<br>
<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div class="im"></div><div>I went though the pull review code and of course lots of memories sprang to mind, so I'm happy to post a few things.</div>
</div></div></blockquote><div><br>Thanks for the recollections in your previous post. I enjoyed reading it. Given the amount of time I spent working on the code to convert it, it was nice to learn a bit of the history behind it.<br>
<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br><div>Given my ignorance of "advanced" programming techniques, I think I simply couldn't think of how one could execute a linear (blocking) piece of script code without recurring to multi-threading. So I think I didn't even explore alternatives to multithreading. Obviously multithreading programming isn't easy, so custom C++ functions, called from MPAL, were full of locking issues wrt to the main thread that redraws the screen. The game was developed under Windows 95 and in fact was released before Windows 2000 was out; on the NT kernel, the game didn't work too well and crashed often because of race conditions. I see that you debugged and fixed at least few those bugs, well done! Those simply weren't triggering on a 9x kernel. </div>
</div></div></blockquote><div><br>Yes, some of them were doozies, and was part of the reason it took a while for us to get the game running. Not only the race conditions, but also code in places launching actions, and then having the caller presuming that the launched action/method had reached a certain point in a certain amount of time. I ended up having to have a bunch of explicit calls in places, for example, to properly ensure launched 'threads' had already gotten to a certain point. There were also several that came up during testing that others were eventually able to track down and fix after a lot of examination of the code in detail.<br>
 </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div><div>Another issue with MPAL is that there's no way to skip cutscenes; I don't remember whether I couldn't think of a good way of doing it, or whether all methods I devised would require too much workload on scripters that were already quite full. I think it's my #1 technical regret when I see the game, and in fact I would quite love if you found a way to implement it now.</div>
</div></div></blockquote><div><br>Agreed, that would be nice. One of the things we pride ourselves on is not just fixing original game bugs, but also offering improvements, such as the Global Save/Load dialog allowing for extra saves, with thumbnails. Support for skipping cutscenes would be nice. Maybe we can do something that would suppress screen updates and all waits so the game essentially runs as fast as it can go until it returns to idle, or things like a screen change or conversation starts.<br>
 </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div><div>I think this ends my braindump of today. Feel free to ask questions of course.</div>
<div><br></div><div>Thanks again for your work!</div></div></div></blockquote><div><br>No worries. Thanks for putting so much work into creating the game in the first place. I've got to say that, honestly, some of the puzzles were weird.. I still think the whole thing you have to do with the worm is bizarre, but overall, it was a fun game, both to work on the code, and to actually play. :)<br>
 <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div class="im"><div>
<span style="border-collapse:separate;border-spacing:0px"><span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><div style="word-wrap:break-word">
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><div style="word-wrap:break-word">
<div>-- </div><div>Giovanni Bajo</div><div><br></div><div>My Blog: <a href="http://giovanni.bajo.it/" target="_blank">http://giovanni.bajo.it</a></div></div></span></div></span></span></div></div></div></blockquote><div><br>
Paul Gilbert. <br></div></div><br>