Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old April 9, 2015, 13:56   #1
Dean Anderson
Adept
 
Join Date: Nov 2009
Posts: 111
Dean Anderson is on a distinguished road
C#, Angband and Unity

I've been looking around and Googling, and I'm surprised at the lack of Angband ports to C# or Java or other languages. There's a half-finished C# port on Google Code, and I've found a few discussions about Java ports but nothing substantial.

So I'm currently working on an experimental C# port of the Cthangband code myself.

What I'm basically doing is this:

1) Take a snapshot of the Cthangband 5.0.0 code (I've done this - it's a simple copy/paste operation!).

2) Strip out all the horrible hacks that make it work on multiple platforms - all the #ifdef business - so we have a simpler codebase which contains only the code that's actually compiled into the Windows Console version. (I've done that, and it compiles and works as normal.)

3) Port the code from C to C#, as-is. (I'm in the process of doing this. Obviously I can't keep it completely as-is, since the file handling, memory management and console code are rather different in C# to C, but I've completed those "tricky" bits now.)

4) Once I have a working C# port, refactor the code to make it properly object oriented. (I'm trying to avoid any of this until I've got the basic port in #3 working, but I'm having to do little bits in order to get the terminal stuff to work - for example instead of using a load of function hooks, the 'term' functions are now in an abstract class which is inherited by the specific 'ConsoleTerm' class containing the Console implementation of a term.)

5) Once I have a fully object oriented C# version of Cthangband running, I want to swap out the Console display for something flashier. I was thinking that Unity would be good because it's nicely portable and handles C# code natively.
Dean Anderson is offline   Reply With Quote
Old April 9, 2015, 14:25   #2
Carnivean
Swordsman
 
Join Date: Sep 2013
Posts: 485
Carnivean is on a distinguished road
Have you checked out the work that the Vanilla maintainers and the NPPAngband crew have been doing? They've taken different approaches to splitting the UI from the engine and refactoring the codebase to simplify thing, and in the case of NPP have a working GUI. You might find you only need to reinvent 1/2 the wheel.
Carnivean is offline   Reply With Quote
Old April 9, 2015, 14:49   #3
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 8,374
Derakon is on a distinguished road
"Rewrite Angband in a nicer language" is basically what you're talking about here. In addition to the 4.0 efforts, I also recommend you look at Pyrel, which is a Python-based rewrite with a radically different design aiming for high extensibility and flexibility. Unfortunately Pyrel's on indefinite hiatus since I'm busy with half a billion other things. Sorry, Magnate and d_m and everyone else who contributed to it.
Derakon is offline   Reply With Quote
Old April 9, 2015, 14:53   #4
Dean Anderson
Adept
 
Join Date: Nov 2009
Posts: 111
Dean Anderson is on a distinguished road
I haven't actually seen their Qt port in action, but I'm aware of it.

In my case, the thought process wasn't:

I want a new UI
=> Unity looks good
=> Unity needs C#
=> Therefore I need to port it to C# in order for it to work

The thought process was actually:

I've been a professional C# developer since the language came out and the company I work for switched to .NET
=> So why the **** am I messing around doing this in plain old C
=> I should totally convert Cthangband to C# for my own enjoyment/ease of use
=> Cool
=> ...
=> ...
=> Hmmm... I could probably do a graphical front end at some point. I wonder what 2D graphics engines are available for C#?
=> Unity looks good. And it's portable too!

So while the Qt front end sounds interesting, for me it's the C# port that's the important bit, not the addition of a front end. Also, the 3.x based code that the current dev team are working on is very different from the Zangband 2.1.1-based code that Cthangband is built on - so they're starting from a very different place. Just converting Cthangband to use the new Angband code would be a major task in itself, without doing any porting.
Dean Anderson is offline   Reply With Quote
Old April 9, 2015, 14:59   #5
Dean Anderson
Adept
 
Join Date: Nov 2009
Posts: 111
Dean Anderson is on a distinguished road
Quote:
Originally Posted by Derakon View Post
"Rewrite Angband in a nicer language" is basically what you're talking about here. In addition to the 4.0 efforts, I also recommend you look at Pyrel, which is a Python-based rewrite with a radically different design aiming for high extensibility and flexibility. Unfortunately Pyrel's on indefinite hiatus since I'm busy with half a billion other things. Sorry, Magnate and d_m and everyone else who contributed to it.
Interesting - although I don't know Python from a hole in the ground!
Dean Anderson is offline   Reply With Quote
Old April 9, 2015, 17:00   #6
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 8,374
Derakon is on a distinguished road
Quote:
Originally Posted by Dean Anderson View Post
Interesting - although I don't know Python from a hole in the ground!
It has a fairly straightforward syntax, so it's not hard to learn once you wrap your head around the fact that whitespace is significant to the parser. Even if you don't want to work in Python, though, I think its design approach is worth imitating. I put a lot of thought into how to set up a system that could easily be extended without needing to know a lot about the code.
Derakon is offline   Reply With Quote
Old April 11, 2015, 23:02   #7
AnonymousHero
Veteran
 
AnonymousHero's Avatar
 
Join Date: Jun 2007
Posts: 1,346
AnonymousHero is on a distinguished road
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?)

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 sincerely wish you the best of luck, and AFAIK you'll be the first to succeed, if you do succeed.

EDIT: FWIW, I do think your general approach is sensible: Strip down to the bare minimums before starting to port, resist at all cost the temptation to redesign while porting, refactor post-porting -- hopefully in a friendlier language!
AnonymousHero is offline   Reply With Quote
Old April 13, 2015, 10:41   #8
Dean Anderson
Adept
 
Join Date: Nov 2009
Posts: 111
Dean Anderson is on a distinguished road
Quote:
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.

Quote:
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.

Quote:
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
Old April 13, 2015, 13:18   #9
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 53
Posts: 7,110
Donated: $60
Nick is on a distinguished road
I'm reading this thread with the way we've updated the Vanilla codebase in mind. I don't think there is really anywhere we can really help each other - Angband and Cthangband are really too far apart now - but it's very interesting to see the changes you're making and your reasons for them.

The V changes I'm hoping will be useful for future variants...
__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
Nick is offline   Reply With Quote
Old April 14, 2015, 11:27   #10
the Invisible Stalker
Adept
 
Join Date: Jul 2009
Posts: 160
the Invisible Stalker is on a distinguished road
Quote:
Originally Posted by AnonymousHero View Post
(Java is particularly terrible here since it has signed bytes. SIGNED bytes! Wtf?)
Just be glad it doesn't have signed bits.
the Invisible Stalker is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reviving Iso-Angband, an isometric view addon for Angband Hajo Development 111 August 3, 2014 19:44


All times are GMT +1. The time now is 12:42.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.