View Single Post
Old October 17, 2017, 13:06   #22
Dean Anderson
Adept
 
Join Date: Nov 2009
Posts: 127
Dean Anderson is on a distinguished road
So, it's two (and a bit) years later. What's the current situation?

Well, as you might have guessed from the fact that I stopped posting on the thread, I gave up. I'd been approaching the project in the wrong way and it wasn't really progressing.

However, a couple of months ago - in the Summer - I decided to revisit Cthangband again. I started by making some changes to the program - I've got a Cthangband 5.1.0 sitting on my hard drive now with various fixes and enhancements. But then I decided to have another go at porting it to C#.

I approached it from a different angle this time. This time my method was:
  1. Remove all the redundant code and code for other systems (I'd already done this in Cthangband 5.1.0).
  2. Wrap all the code so that it is all in one big stonking class spanning 51 files (using C#'s ability to declare "partial" classes that span files).
  3. Comment out all the C code.
  4. Go through the code a function at a time replacing each commented out C function with a C# equivalent.
  5. Only after getting everything converted and working would I then start refactoring things to make it object oriented.

This might look similar to the prior attempt, but the significant difference is in #2. Previously I'd made each .c file into a static class while doing the conversion (so object1.c would be a class called Object1 and cmd4.c would be a class called Cmd4, and so forth). This meant that everything was static and I needed to reference between the classes constantly.

This time, by making it all one single class, I could just create an instance of the class and all the functions and variables could see each other just like in the C version of the code.

Similarly, in #4, I haven't been going through it file by file. Instead I've been going though it commenting out calls to functions that haven't yet been re-written and then slowly putting them back in in the right order to always have a runnable program.

So I started out with a program that would compile and run. Then one that would show the splash screen. Then one that would show the splash screen and let you start a new game. Then one that would also take you through character generation. Then one that would create a town. Then one that would have monsters. Then one that had objects. Then one in which the monsters also moved. And so forth.

And that made all the difference in the world. I now have a fully working and fully featured C# version of Cthangband 5.1.0 as well as a C version. There's no remaining un-ported code left.

So I've finished #4 and I'm currently most of the way through step #5 - refactoring everything to make it object oriented. Of the 51 original source files that I converted, I've moved all the code out of 38 of them and partially out of the remaining 13; moving the code into a proper object model and doing further re-writes as I go.

I haven't gone with Unity or anything as a front end for the moment. It's effectively just a Console app (I say "effectively", because technically it doesn't actually use the console window - they're horribly slow to update, so it uses a custom window that looks like a console but is actually just user-drawn graphics).
Dean Anderson is offline   Reply With Quote