View Single Post
Old April 13, 2015, 11:41   #8
Dean Anderson
Join Date: Nov 2009
Posts: 127
Dean Anderson is on a distinguished road
Originally Posted by AnonymousHero View Post
The difficulty here isn't so much that it's difficult per se. It's just that it's an enormous amount of sustained effort to convert, say, 200k-300k lines of old-school C to a modern language. Many of the idioms of C aren't even available in $LANGUAGE. (Java is particularly terrible here since it has signed bytes. SIGNED bytes! Wtf?)
Most of the code isn't a big problem when conmverting from C to C#, since the basic syntax is the same.

The main differences are that most of the stuff in Angband that throws around pointers to structs needs to be changed to throw around references to classes instead.

Unfortunately, the bits that require the most alteration are:

1) The terminal/display code (main-xxx.c/Z-term.c)
2) The code for reading/writing files (init1.c/init2.c/files/c)
3) The code for initialising the arrays of structs/objects (variable.c/tables.c)

The reason this is unfortunate is that these are the bits that needed converting first. Converting the LOS code or the code for when someone goes up a level can wait until we're at a point where we need those functions - in other words they can wait until we've got a skeleton program running and starting a game. But those basics need to be run as the program initialises and sets itself up.

My current progress is that I've fully converted the files listed above, and I'm now at the point where I can compile and run the program and it will do all its initialising and be ready to jump into character creation.

These things can be overcome with enough effort, but I think the temptation to start changing things as you're porting has claimed many victims...
I think the biggest issue there is that because some things have to be changed, it's tempting to change more "while I'm here".

For example, tables.c needed heavily re-writing because you don't initialise big arrays of objects in C# the same way that you do in C. So as well as simply converting the various structs to classes, I also had to write constructors for them so that I could use those constructors to create the big arrays.

It would be very tempting to start refactoring other bits of the program as I get to them by trying to convert static functions into class methods on those classes.

I sincerely wish you the best of luck, and AFAIK you'll be the first to succeed, if you do succeed.
That's a good incentive!
Dean Anderson is offline   Reply With Quote