Author Topic: How does Arcen code its games? (Architecture wise)  (Read 7521 times)

Offline Reactorcore

  • Newbie Mark II
  • *
  • Posts: 14
How does Arcen code its games? (Architecture wise)
« on: May 20, 2012, 02:38:27 pm »
Hi

I've been following how Arcen keeps updating AVWW at a rapid rate, sometimes incorporating big changes incredibly fast, got me wondering on what programming paradigm(s) is Arcen using to create its games?

By programming paradigms, I mean what kind of style of programming do you use to base the game's architecture upon? How do you organize it? Is it Component-based or Automata-based or something else?

I'm asking this because I'm currently trying to build a computer game too, but how to organize it all (menu system, game manager, save system, ingame actors and objects, gameplay logic, metagame) is something I have not yet understood on how to do it. I was hoping someone could help explain how they do it and what is their thought process while building the architecture of a full game?
« Last Edit: May 20, 2012, 02:48:53 pm by Reactorcore »

Offline keith.lamothe

  • Arcen Games Staff
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 19,505
Re: How does Arcen code its games? (Architecture wise)
« Reply #1 on: May 20, 2012, 03:09:20 pm »
We don't use any formal method, really.  But there are certain patterns Chris and I have learned in previous jobs and evolved on Arcen's projects, etc.

Writing in C# helps dev-speed because it permits a fairly high level of static analysis and thus potential bugs (type-mismatch, etc) prevented before it's ever run.  Also, it's generally easy to find all references to a particular symbol due to the early-binding of variables (we don't use the more late-binding-oriented features of the language), which helps a lot in bug hunts.  And not using any explicit memory management (leaving it to the garbage collector) is incredibly important for cutting time spent on debugging (due to accessing memory that's not yours, double-deletes, etc).

Being a very small group (only 2 of us are coders) with a high average level of experience also helps dev-speed because we can get away with limited defensive programming and code-review because we can reasonably rely on programmer discipline to prevent things like desync-causing code (in AIW, mainly; though similar principles apply in AVWW).  That's not to say we don't make some pretty funny and devestating mistakes sometimes, but it's not like larger teams where whole positions have to be devoted to controlling the quality of code produced by other members.
Have ideas or bug reports for one of our games? Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Reactorcore

  • Newbie Mark II
  • *
  • Posts: 14
Re: How does Arcen code its games? (Architecture wise)
« Reply #2 on: May 20, 2012, 05:45:34 pm »
We don't use any formal method, really.  But there are certain patterns Chris and I have learned in previous jobs and evolved on Arcen's projects, etc.

What patterns are they? I'm coincidentally currently reading about programming design patterns (Singleton, State, Factory and more), so it would be great to know what are relevant patterns one should learn for video game development.

Also C# ftw, I really like how that language is structured and how it guides the developer to type better code. I'll be using it with the Unity3D engine.

Offline keith.lamothe

  • Arcen Games Staff
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 19,505
Re: How does Arcen code its games? (Architecture wise)
« Reply #3 on: May 20, 2012, 07:46:35 pm »
We use singleton a lot, though that's not really anything special. 

One that may not be as obvious: we don't use inheritance for most objects that are part of the gamestate (we do use it for less performance-critical stuff), but rather for things like GameEntity or ForegroundObject (the "character/monster/tree/etc" class from AVWW and the "ship/building/etc" class from AIW, respectively) we have something like:

enum GameEntityType
- has one value for each distinct type of entity in the game, so "Darrell" is one of the npc/player-entity types, "SkelebotSniper" is the Skelebot Sniper, and "Cedar" is one of the cedar tree types.

class GameEntityTypeData
- has exactly one instance per GameEntityType value, and each instance has all the fields about that particular type of entity that never change during the game
- this has a static Initialize() method that is called when the application is first run, that calls the ctor once per GameEntityType value and stores them in a "static GameEntityTypeData[] Lookup", which can be retrieved from like "GameEntityTypeData.Lookup[(int)GameEntityType.SkelebotSniper]".

class GameEntity
- corresponds to an actual in-game entity, so if there are 4 skelebot sniper on your screen there are actually (bopping around in RAM somewhere) 4 instances of GameEntity whose this.TypeData.Type value is GameEntityType.SkelebotSniper


We use the Type/TypeData/Instance pattern all over the place.  Sometimes we just do Type/TypeData for, say, PurchaseType/PurchaseTypeData; each PurchaseType enum corresponds to a specific transaction that is possible in the opal guardian store.  But there's no "Purchase" Instance class because we had no need to have an object representing the transaction: the TypeData provides all the necessary information to handle it from start to finish, and the resulting change in your inventory is all that needs to happen, no additional intermediate or residual state.
Have ideas or bug reports for one of our games? Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Mánagarmr

  • Core Member Mark V
  • *****
  • Posts: 4,272
  • if (isInRange(target)) { kill(target); }
Re: How does Arcen code its games? (Architecture wise)
« Reply #4 on: July 07, 2012, 06:57:32 am »
Spontaneously though, concerning memory management, would writing the game in say C++ give you greater control over memory management and make the code more efficient and stable (provided you don't code any bugs :P) compared to C#, or is the garbage collector in C# so awesome it makes manual memory management superflous?
Click here to get started with Mantis for Suggestions and Bug Reports.

Thank you for contributing to making the game better!

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: How does Arcen code its games? (Architecture wise)
« Reply #5 on: July 07, 2012, 08:23:08 am »
C++ is generally a source of bugs, not a solution to them. The .net garbage collector is incredibly awesome. The current mono one that the game uses is unfortunately less awesome in performance by a factor of 20 or somesuch, but it's still more than acceptable. And mono is beta-ing a new GC that is slightly better in performance compared to .net.

I really, really see no upsides to C++ on modern home computer programs, to be honest. Crysis aside, perhaps; but even that has more to do with the GPU and HLSL language, I'd bet.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Mánagarmr

  • Core Member Mark V
  • *****
  • Posts: 4,272
  • if (isInRange(target)) { kill(target); }
Re: How does Arcen code its games? (Architecture wise)
« Reply #6 on: July 07, 2012, 08:52:16 am »
It's funny you should say that, because as far as my limited understanding goes, C++ is vastly dominant in the gaming world, as far as game engines go. Is that simply a matter of "We haven't adapted to a new language yet", or?
Click here to get started with Mantis for Suggestions and Bug Reports.

Thank you for contributing to making the game better!

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: How does Arcen code its games? (Architecture wise)
« Reply #7 on: July 07, 2012, 08:55:43 am »
Is that simply a matter of "We haven't adapted to a new language yet", or?

Bingo.  In my opinion.  It's the same thing that happened in the early 90s with the move to C++ away from C/ASM.  I still remember when the common wisdom was to code anything performance-critical in ASM, but now of course that's ludicrous.  We're fast approaching that point with C++, and in my opinion for anything that isn't a graphical powerhouse we're already there.

C++ is a lot more time consuming to code in due to verbosity, it only has 11% better performance than C# on average, and it is vastly more prone to bugs (thus raising dev costs).  At the rate at which processors keep improving, that 11% is trivial compared to what it was a decade ago when I was first into C#.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Mánagarmr

  • Core Member Mark V
  • *****
  • Posts: 4,272
  • if (isInRange(target)) { kill(target); }
Re: How does Arcen code its games? (Architecture wise)
« Reply #8 on: July 07, 2012, 08:58:16 am »
Yeah, as far as my understanding has been, C++, while efficient, is an absolutely nightmare to both code and debug, leading to huge maintenance costs in the long run. I've been interested in learning C++, but all the memory management is, easy to say, daunting.
Click here to get started with Mantis for Suggestions and Bug Reports.

Thank you for contributing to making the game better!

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: How does Arcen code its games? (Architecture wise)
« Reply #9 on: July 07, 2012, 09:00:22 am »
Even just structurally, it's really annoying -- header files and such make everything take twice as long because now you have two files to deal with instead of one.  You have to define your methods and such in two places rather than one.  WTF?

That sort of thing really grates on me.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Mánagarmr

  • Core Member Mark V
  • *****
  • Posts: 4,272
  • if (isInRange(target)) { kill(target); }
Re: How does Arcen code its games? (Architecture wise)
« Reply #10 on: July 07, 2012, 09:05:40 am »
Yeah, let's just say that I'm a Java coder atm. That's probably as close to baby steps as it gets in code. Java vs C++ to me looks like the comparison between a 60 meter stroll and the marathon.

The only thing I really have against C# is its close connection to .NET and Microsoft. Microsoft aren't exactly well known to support portability and freedom :/
Click here to get started with Mantis for Suggestions and Bug Reports.

Thank you for contributing to making the game better!

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: How does Arcen code its games? (Architecture wise)
« Reply #11 on: July 07, 2012, 11:22:03 am »
C# wasn't Microsoft's idea, they just had the first mainstream implementation.  The version of C# we use is actually Mono, which is open source and as portable and free as you can possibly get.

Java isn't as baby steps as you can get, either: there's always Ruby or Javascript or Python. ;)  Not that those languages can't be incredibly useful and powerful, but they are generally simpler and less verbose than Java.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: How does Arcen code its games? (Architecture wise)
« Reply #12 on: July 07, 2012, 12:06:48 pm »
still remember when the common wisdom was to code anything performance-critical in ASM, but now of course that's ludicrous.

That's not quite dead. Ultra, ultra commonly used functions that are used in commonly used in inner loops and inner, inner loops sometimes still get written in ASM.
For example, modern versions of Sun's (well, now Oracle's) JVM uses hand tuned assembly for System.arraycopy (I wouldn't be surprised if some C# implementations use a similar technique for Array.copy)

But yea, unless you got something that is used that frequently, hand tuned ASM isn't worth the trouble. ;)

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: How does Arcen code its games? (Architecture wise)
« Reply #13 on: July 07, 2012, 12:18:32 pm »
You're discussing writing a virtual machine, though.  For a VM or compiler or even an OS or a library that interacts very directly with hardware (drivers, code that runs on ARM co-processors for specialized robotics, etc) ASM is a wonderful tool and makes a lot of sense.

But when it comes to general application development, and game development in particular, that's what I was referring to.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: How does Arcen code its games? (Architecture wise)
« Reply #14 on: July 07, 2012, 12:23:41 pm »
You're discussing writing a virtual machine, though.  For a VM or compiler or even an OS or a library that interacts very directly with hardware (drivers, code that runs on ARM co-processors for specialized robotics, etc) ASM is a wonderful tool and makes a lot of sense.

But when it comes to general application development, and game development in particular, that's what I was referring to.

Exactly. In everyday development of user applications, pretty much nothing gets performance critical enough to deserve fancy stuff like ASM. Most compilers and/or runtime optimizers do a fine job. In fact, on modern machines, rarely does stuff become CPU bound (though still happens sometimes, like large battles in AI War. ;)). It's typically IO bound, sometimes memory bound, but most often, "user interaction bound".
« Last Edit: July 07, 2012, 11:09:13 pm by TechSY730 »