GC, the simple solution

Chad J gamerChad at _spamIsBad_gmail.com
Mon Jun 12 02:21:22 PDT 2006


David Gileadi wrote:
> 
> It seems that a fairly common desire is to use D for writing games. 
> Games don't typically have hard real-time requirements, but it also 
> doesn't look good if your screen freezes for a second or two in the 
> middle of play.
> 
> This is an area where an incremental collector or some kind of reference 
> counting solution would be handy, since (especially in large programs) 
> it would be difficult to avoid using garbage collected code.  I realize 
> that the programmer has the responsibility to manage memory 
> intelligently, but it would be nice to not avoid using GC code entirely. 
>  As others have stated, it would even be worth giving up some overall 
> performance to gain a smooth playing experience.

This is what I'm screaming.

It is becoming popular nowadays to allow people to modify games in 
various ways, one of which is modding the game's code.  I don't think 
you will see much of this happening inside a 3d engine, but the game 
logic that sits next to the 3d engine and dictates gameplay may be open. 
  This allows people to change things like how the AI behaves, how much 
damage you take when hit with a certain weapon, how that certain weapon 
behaves, how an economy behaves, etc.

Modders may or may not be experienced programmers, so it's probably best 
to assume they don't have significant experience.  This has caused 
plenty of games to use scripting languages for modding, since C plus 
plus is tough to learn and not good for this stuff.  I think D could do 
it though.  It would kick butt if D could do this, because it would make 
the mods run much faster than the interpreted code that is probably 
going to be used nowadays, even if you have like 50% reference counting 
overhead.

Automatic memory management is a huge boon to that sort of ease of code 
writing that is expected for inexperienced coders to get in on the 
action and do constructive stuff.  Even without the modding argument, 
being able to use automatic memory management in some parts of the game 
would be very advantageous in development time.  It seems to me though, 
that if you want to do non-pausing games in D, you just use C style 
memory management.  Bummer.

As David Gileadi said, games don't have strict latency requirements. 
For games, garbage collection doesn't need to be deterministic, and it 
doesn't need to finish in under 100 microseconds, it just needs to not 
be noticable.  For a few years I've messed with RunUO which is, afaik, 
written entirely in C#, and I never noticed the pauses (though the 
worldsaves were annoying!).  This is doable.

Also, think of all the new D programmers there would be if someone were 
to release a popular game that exposed D as a scripting language :)



More information about the Digitalmars-d mailing list