Page 1 of 1
Documentation on how the game was ported to C/C++
Posted: 31 Oct 2011 01:40
by blug_julien
Dear All,
I am planning to make a presentation about openTTD at our local LUG (Beijing) this month and I would like to talk a little about how the game has been created.
Do you have any documentation available on how (using which tools and what process) the game has been ported to C/C++?
Cheers,
Julien
Re: Documentation on how the game was ported to C/C++
Posted: 31 Oct 2011 07:09
by Lord Aro
well, here is the c++ branch merge commit:
http://vcs.openttd.org/svn/changeset/8038
Re: Documentation on how the game was ported to C/C++
Posted: 31 Oct 2011 07:18
by planetmaker
blug_julien wrote:Dear All,
I am planning to make a presentation about openTTD at our local LUG (Beijing) this month and I would like to talk a little about how the game has been created.
Do you have any documentation available on how (using which tools and what process) the game has been ported to C/C++?
Cheers,
Julien
This game is a re-implementation of TTD and is already
originally written in C (thus no porting needed) and slowly more and more elements were and are moved to C++.
Thus all you need is an editor of your choice and a C/C++ compiler (and the required libraries). Of course other tools like Valgrind etc have been of great use as well.
Re: Documentation on how the game was ported to C/C++
Posted: 31 Oct 2011 07:54
by blug_julien
Thanks for your replies, I think I got confused somewhere so I did a little more reading and I am back with some more questions
My understanding is it goes like this:
(1) Transport Tycoon Deluxe was originally coded in Assembly and released in 94 as an MS DOS game
(2) The game was then ported to C to run on Windows 95 in the late 90s
(3) Then OpenTTD was started 2003.
What confuses me is the wikipedia page says the following:
In 2003 Ludvig Strigeus announced he was intending to reverse engineer Transport Tycoon Deluxe and convert the game to C. In 2004 this re-engineered Transport Tycoon Deluxe was released and christened "OpenTTD".[10][11]
I would like to know if this re-engineering was done from the original assembly code or from the C Windows 95 port. And most importantly, if there is any information on how it was done and (as a bonus) if it is similar to the work done with openDune.
I hope I am making more sense, and that the wikipedia page is accurate
Julien
Edit: found some good info in the first release forum thread:
http://www.tt-forums.net/viewtopic.php?f=29&t=6559
Re: Documentation on how the game was ported to C/C++
Posted: 31 Oct 2011 09:21
by michael blunck
blug_julien wrote:
I would like to know [...] if there is any information on how it was done
Much information has been drawn from Marcin“s
documentation of the Transport Tycoon Deluxe savegame internals which had been originally prepared for the development of TTDPatch.
regards
Michael
Re: Documentation on how the game was ported to C/C++
Posted: 31 Oct 2011 10:16
by FooBar
blug_julien wrote:(2) The game was then ported to C to run on Windows 95 in the late 90s
That AFAIK is not correct. Yes, the game was made to run on Win95, but not ported to C. The graphics palette was changed to allow for the Windows system colours and a loader was added. But the game itself is still ASM.
Re: Documentation on how the game was ported to C/C++
Posted: 31 Oct 2011 13:58
by TrueBrain
blug_julien wrote:(..)
In 2003 Ludvig Strigeus announced he was intending to reverse engineer Transport Tycoon Deluxe and convert the game to C. In 2004 this re-engineered Transport Tycoon Deluxe was released and christened "OpenTTD".[10][11]
I would like to know if this re-engineering was done from the original assembly code or from the C Windows 95 port. And most importantly, if there is any information on how it was done and (as a bonus) if it is similar to the work done with openDune.
(..)
How OpenTTD was exactly reconstructed from Transport Tycoon Deluxe only Ludde most likely knows. At a certain point it just was. By the looks of pre-releases, he build it from the ground up, looking closely to how TTD did things. But this process has never been written down (or shared) to my knowledge, and all information you read on the web about it are most likely guessed by people who weren't involved

Gossip travels fast on the Internet
Also, what FooBar already said: as far as I am aware, there was never created any C port for Windows 95. It just was made compatible enough to run on those systems.
In relation to OpenDUNE, nothing is comparable. The process of OpenDUNE is highly unique (if I say so myself) and has not been attempted on any other project of such scale (in the Open Source world). OpenDUNE could only be done like this, because Dune2 was compiled by a real compiler (Borland C compiler), where TTD was written in assembly. The same process would be impossible to apply on TTD. (it highly depends on the existence and consistency of function-frames).
Hope this helps you a bit. Make sure to share your presentation with us, I am sure a few people would be interested in it. Good luck.
Re: Documentation on how the game was ported to C/C++
Posted: 31 Oct 2011 18:58
by Zuu
If you read Swedish, there was a quite long (8 pages) article about Ludvig in a Swedish magazine this summer. The article is in the "jun/jul 2011" issue and the magazine is called "Filter". The article is about Ludvig and his programming projects.
It doesn't provide any fundamental new information but it is still a good article that is not too shallow.
Edit: According to the magazine website it appears that the article is in
issue #20 (you still need to obtain a copy via eg. a library or contacting them)
Re: Documentation on how the game was ported to C/C++
Posted: 01 Nov 2011 02:46
by blug_julien
Thanks again for all the answers, I unfortunately do not read any Swedish so I will keep the mystery around the port
It is a pity that the process has not been more documented as the output is quite remarkable and I am curious to know if it could be done for other old games / applications
And also, as this is the development board, thanks for the great work

Re: Documentation on how the game was ported to C/C++
Posted: 01 Nov 2011 11:37
by Alberth
blug_julien wrote:... I am curious to know if it could be done for other old games / applications
I am not sure whether switching to another programming language would still be 'porting', it sounds a bit at the edge the definition.
Aside from that technicality, I am quite sure you *could* do it for other programs too. There may be legal problems though, many programs explicitly forbid reverse engineering in their license.
On the other hand, there are several other possibilities too, like: de-compile, get the actual source code, or write from scratch with or without use of the original game data. Each of these (and no doubt more options exist) has its advantages and disadvantages. I'd say it all depends on what the person(s) doing the actual work prefer, together with legal implications and technical expertise.
Re: Documentation on how the game was ported to C/C++
Posted: 01 Nov 2011 12:39
by Eddi
Alberth wrote:There may be legal problems though, many programs explicitly forbid reverse engineering in their license.
however, german copyright states, that for any license stating that, this part is void.
in general, there are two kinds of reverse engineering, the first, more legally lenient, way is to "watch" the operations of the program, then you can freely write your own program that does something similar. the second is to decompile/disassemble/other automatically and modify the program directly this way, this method may only be used for "compatibility with another program" (e.g. porting to a different OS) and "bug fixes", but this may only be distributed to people which have a licensed copy of the original.
Re: Documentation on how the game was ported to C/C++
Posted: 01 Nov 2011 12:44
by blug_julien
I also believe that for some of these old games/app from the 80s or early 90s, nobody actually as any clue of who owns the game

Re: Documentation on how the game was ported to C/C++
Posted: 02 Nov 2011 15:35
by Darkvater
Given that Transport Tycoon was written in assembly, the decompiled code was largely human readable (or at least more so than if a compiler would've had its way with it). The original "porter", Ludde, then basically retranslated all the assembly code back to C, made it logical in the parts he could figure out what was going on.
I remember for quite a long time how the AI was just a black big box. unk0 - unkXXX variables everywhere, unfollowable code, etc. Ludde had no idea - nor the desire - what was going on in there

. We spent most of the time in the beginning figuring out what the code was doing, rewriting it and documenting functionality.
After this a gradual C++ translation was started. I believe one of the first structures was Vehicle.