www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Can you port a 45+kloc commercial C++ game to D?

reply Kai Backman <kai shorthike.com> writes:
 Hello everyone and nice to be around,

 My day job is developing a commercial space station game called ShortHike.
It's a constantly evolving project and has been in production since 2002=
 and
selling online since Feb 2003. The current unstable version contains about
45,000+ lines of custom C/C++ code. The code is pretty streamlined,
I've had plenty of time to keep things clean and refactored. I use only=
 basic
C++ functionality and a extremely limited set of external C libraries.  An
important part of my development strategy is flexibility and gradual
improvement of the game. There is also a separate (custom) scripting layer.
I'm the only developer working on the code. The base code has been
through 6 larger rewrites/refactorings since the project started (60-80% of=
 code
reworked), and is partially based previous work dating back a few years or=
 so.

 Part of a larger rewrite I'm reconsidering my strategy to use C++ for the=
 base
layer. After evaluating the usual suspects (C++/C#/Java) D looks like the=
 most
viable candidate. All the external dependencies already have D headers or=
 they
would be easy to produce.

So here are my specific questions:
- Is it currently feasible to port a commercial 45kloc C++ program to D?
- For those with actual experience doing this, what problems do you foresee=
 I will
encounter in the process?
- Alternatively, what are the experiences in writing 50k loc applications in=
 D?
- Can you point me to shipping application in the 30k-60k range?

 I would appreciate all input I can get to help me make the decision. This
project provides bread on the table so you can understand I want to do my=
 due
diligence.. :-)

 You can find out more about the game at: http://www.shorthike.com

 Thanks in advance for the replies and insight!

  Take care,

 Kai
 
--
Kai Backman, programmer, kai shorthike.com
http://www.ShortHike.com - space station game
Oct 03 2005
next sibling parent reply "Walter Bright" <newshound digitalmars.com> writes:
"Kai Backman" <kai shorthike.com> wrote in message
news:2005103113238.284032 birch...

- Is it currently feasible to port a commercial 45kloc C++ program to D?

Yes.

- For those with actual experience doing this, what problems do you foresee
I will
encounter in the process?

You may need to rethink the memory allocation strategies you'er using.

- Alternatively, what are the experiences in writing 50k loc applications in
D?

DMDScript was converted from C++ to D, and it took about 2 weeks.

- Can you point me to shipping application in the 30k-60k range?

DMDScript.

Good luck! -Walter
Oct 03 2005
parent reply Kai Backman <kai shorthike.com> writes:
 On Mon, 3 Oct 2005 11:49:45 +0300, Walter Bright wrote:
=A0- Can you point me to shipping application in the 30k-60k range?

=A0DMDScript.

Thank for the quick reply Walter. The D version is roughly 22kloc. How many kloc was the C++ version? (To get a rough C++->D ratio) Kai -- Kai Backman, programmer, kai shorthike.com http://www.ShortHike.com - space station game
Oct 03 2005
parent "Walter Bright" <newshound digitalmars.com> writes:
"Kai Backman" <kai shorthike.com> wrote in message
news:200510312219.080693 birch...
On Mon, 3 Oct 2005 11:49:45 +0300, Walter Bright wrote:
 - Can you point me to shipping application in the 30k-60k range?

 DMDScript.

many kloc was the C++ version? (To get a rough C++->D ratio)

C++ version: dscript source: 736,957 bytes support code: ~300,000 total: 1,036,957 D version: dscript source: 505, 806 support code: 0 total: 505,806 By "support code" I mean things like the gc, symbol tables, string handling, UTF support, array handling, regular expressions, etc. In D, those are handled either in the core language or in the standard library. (I broke them out separately because many would argue that in C++ one could use STL or Boost.) The D version is a line by line conversion of the C++ code, and the comments in the code are the same. The D version runs faster, too <g>.
Oct 03 2005
prev sibling next sibling parent Tom S <Tom_member pathlink.com> writes:
Hi there !

I've been developing a 3d game engine in D for about a year now. I'm using
OpenGL with SDL, SDLttf, OpenIL, Cg and more. The LOC count for the moment being
is about 35k (not counting the above libs or their bindings of course). I don't
have recent demo, but I'll be releasing one soon, with complete source code.
I'm actively working on the rendering subsystem, trying to make it compatible
with cards from RivaTNT to Geforce6 and a similar range of ATI cards, though
still use the best features available on a given GPU (I'm implementing the
shader/vertex cache system that YannL proposed on gamedev.net's forums). I'm
also in the middle of some debugging work, since completely redesigning my
rendering pipeline has produced a few bugs.
Having experience with C++ programming, I think it would take about 30% more
lines of code to produce the same result in that language. Furthermore, the
debugging effort would have to be much greater.
Making a complex D application isn't a dream though. You'll have to fight your
way through compiler bugs and somehow different memory management strategies.
For instance, I'm currently using dmd.132 because dmd.133 introduced an obscure
bug in nested functions that I hasn't been able to isolate yet. I'm also using
lots of malloc/free because the default new/delete are connected to the GC,
causing any memory-intensive application to hang occasionally. E.g. while doing
photon mapping on a 1M polygon model, memory use in my engine can get as high as
400 - 500MB and a fullCollect of the GC takes about 10seconds on my Athlon 2k+
512RAM.
Nevertheless, I think that switching to D was a great choice... I have
considered switching back to C++ at a few points (extreme frustration at the
GC), but just thinking how much cleaner, easier to write and debug D code is,
I've had the motivation to stick to D. In the long run, I've never regretted it
:)

My project is being developed on dsource: http://dsource.org/projects/fragbots/
 The forum's got a few links to old and ugly demos of the engine ( you can
crash the GUI demo by clicking on a listbox with two mousebuttons :D - bug
removed in the current version ).

Good luck with your project !

--
Tomasz Stachowiak a.k.a. h3r3tic
Oct 03 2005
prev sibling next sibling parent clayasaurus <clayasaurus gmail.com> writes:
You'll see a huge improvement in compile time with D as well.

Kai Backman wrote:
  Hello everyone and nice to be around,
 
  My day job is developing a commercial space station game called ShortHike.
 It's a constantly evolving project and has been in production since 2002 and
 selling online since Feb 2003. The current unstable version contains about
 45,000+ lines of custom C/C++ code. The code is pretty streamlined,
 I've had plenty of time to keep things clean and refactored. I use only basic
 C++ functionality and a extremely limited set of external C libraries.  An
 important part of my development strategy is flexibility and gradual
 improvement of the game. There is also a separate (custom) scripting layer.
 I'm the only developer working on the code. The base code has been
 through 6 larger rewrites/refactorings since the project started (60-80% of
code
 reworked), and is partially based previous work dating back a few years or so.
 
  Part of a larger rewrite I'm reconsidering my strategy to use C++ for the base
 layer. After evaluating the usual suspects (C++/C#/Java) D looks like the most
 viable candidate. All the external dependencies already have D headers or they
 would be easy to produce.
 
 So here are my specific questions:
 - Is it currently feasible to port a commercial 45kloc C++ program to D?
 - For those with actual experience doing this, what problems do you foresee I
will
 encounter in the process?
 - Alternatively, what are the experiences in writing 50k loc applications in D?
 - Can you point me to shipping application in the 30k-60k range?
 
  I would appreciate all input I can get to help me make the decision. This
 project provides bread on the table so you can understand I want to do my due
 diligence.. :-)
 
  You can find out more about the game at: http://www.shorthike.com
 
  Thanks in advance for the replies and insight!
 
   Take care,
 
  Kai
  
 --
 Kai Backman, programmer, kai shorthike.com
 http://www.ShortHike.com - space station game
 

Oct 03 2005
prev sibling parent reply Bruno Medeiros <daiphoenixNO SPAMlycos.com> writes:
Btw, how is any of you measuring LoC ? (with what tool I mean)

-- 
Bruno Medeiros - CS/E student
"Certain aspects of D are a pathway to many abilities some consider to 
be... unnatural."
Oct 05 2005
next sibling parent reply =?ISO-8859-1?Q?Thomas_K=FChne?= <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bruno Medeiros schrieb:
 Btw, how is any of you measuring LoC ? (with what tool I mean)
 

http://thomas.kuehne.cn/tools/locd.html Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDRG423w+/yD4P9tIRAkEkAJ9oI0/YG2OJVkM3yTqYThCsDmewGgCeKC9m 9G+vqoYnORdGrsSrKowPfJQ= =ioQ0 -----END PGP SIGNATURE-----
Oct 05 2005
next sibling parent reply zwang <nehzgnaw gmail.com> writes:
Thomas Kühne wrote:
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 Bruno Medeiros schrieb:
 
Btw, how is any of you measuring LoC ? (with what tool I mean)

http://thomas.kuehne.cn/tools/locd.html Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDRG423w+/yD4P9tIRAkEkAJ9oI0/YG2OJVkM3yTqYThCsDmewGgCeKC9m 9G+vqoYnORdGrsSrKowPfJQ= =ioQ0 -----END PGP SIGNATURE-----

Call me paranoid, but the first thing I throw to LoCd is a zero-byte file. And Bang! Access violation. :)
Oct 05 2005
parent reply JT <jtd514 ameritech.net> writes:
Man: "Doctor, when I do this it hurts"

Doctor: "Then - dont do that. That will be $75."

:D

zwang wrote:
 Call me paranoid, but the first thing I throw to LoCd is a zero-byte 
 file. And Bang! Access violation. :)

Oct 05 2005
parent =?ISO-8859-1?Q?Thomas_K=FChne?= <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

JT schrieb:

 Man: "Doctor, when I do this it hurts"
 
 Doctor: "Then - dont do that. That will be $75."
 
 :D
 
 zwang wrote:
 
 Call me paranoid, but the first thing I throw to LoCd is a zero-byte
 file. And Bang! Access violation. :)


;) Fixed -----BEGIN PGP SIGNATURE----- iD8DBQFDRRY43w+/yD4P9tIRAk1HAJwMnkgzxJqKE1UN+64JtvLlfl7dLwCcCtAA 8bGxuDdxoMjq+G9kreJOZGo= =9FjI -----END PGP SIGNATURE-----
Oct 06 2005
prev sibling parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
 Btw, how is any of you measuring LoC ? (with what tool I mean)

http://thomas.kuehne.cn/tools/locd.html Thomas

I think it's pretty common to not count lines containing only { or } as a LOC. From a few samples it looks like locd counts such lines.
Oct 05 2005
parent "Walter Bright" <newshound digitalmars.com> writes:
"Ben Hinkle" <ben.hinkle gmail.com> wrote in message
news:di20ka$20ef$1 digitaldaemon.com...
 I think it's pretty common to not count lines containing only { or } as a
 LOC. From a few samples it looks like locd counts such lines.

If one wants to go down that path, I'd count # of statements + # of expression nodes + number of declarations.
Oct 05 2005
prev sibling next sibling parent Markus Dangl <danglm in.tum.de> writes:
Bruno Medeiros wrote:
 Btw, how is any of you measuring LoC ? (with what tool I mean)

I use sloccount ( http://www.dwheeler.com/sloccount/ ). The output is a bit weird but it works :) Looks like there is no Windows binary :(
Oct 05 2005
prev sibling parent Kai Backman <kai shorthike.com> writes:
 On Wed, 5 Oct 2005 13:46:22 +0300, Bruno Medeiros wrote:
=A0Btw, how is any of you measuring LoC ? (with what tool I mean)

I just found another simple and quick measure. Zip the source up and look at the compressed size. Anything < 750kB is small, < 1500kB medium and beyond that large. The compression ratio is also directly related to your COBOL constant, which= defines how fast the bones in your fingertips will start showing due to excessive typing. -K -- Kai Backman, programmer, kai shorthike.com http://www.ShortHike.com - space station game
Oct 06 2005