Darwinbots 3

From WikiManual
Revision as of 17:17, 4 July 2008 by Numsgil (talk | contribs) (Adding paths: Made a major mistake last time)
Jump to: navigation, search

Darwinbots 3 is a long term project to recode Darwinbots in C# as a brand new program. Every feature and aspect is going to be examined and refined as its added, in a framework that will ensure robustness and agility in handling bugs and new features.

The repository

Introduction

Darwinbots3 is stored in an SVN location on Numsgil's SVN account with www.hosted-projects.com (which I highly recommend. Excellent customer service). You can browse it in an explorer, but to download it to work on, you'll need an SVN manager. Numsgil uses SmartSVN, which again I highly recommend.

For those unfamiliar with version control, it's basically a way to ensure that multiple people can work on the same source code. You "check out" a copy of the current source code from the repository and store it locally on your computer. You then change the source code in places and "commit" it back to the repository. If there have been changes in the mean time that conflict with your changes (should be a pretty rare occurrence), SVN will notify you and ask you to resolve te problem before the commit is applied to the central code repository. Another advantage of working this way is that the entire evolution of the code is tracked. If some bug is found that was introduced months ago, you can browse through the repository at different versions of the program to find what changes caused it.

Etiquette

  • Prefer to post lots of small, atomic changes over large, far-reaching changes. It's easier to integrate for other people, and minimizes the possibility of commit conflicts.
  • Keep the repository's code running. Don't commit a change that would break the program, or worse, prevent it from compiling. If you do anyway, fix the problem immediately.

Accessing the repository

https://svn2.hosted-projects.com/Numsgil/DarwinbotsCS/ This is the link for the repository. It has anonymous access, so anyone can download and browse it. To commit changes, you need a username and password. Post a request for one here. If you haven't registered in the forum yet, please do so. It's important that progress is talked about so others can see what's going on.

Compiling the code

Getting the compiler

You'll need a version of Microsoft Studio 2005 C# (this all might run under Mono in Linux, but I don't have either so no promises). You can download C# express here for free. Follow every instruction on the page. This will probably take several hours to do. The good news is that even if you never start programming Darwinbots, you just found a free high quality compiler :D

Downloading the dependancies

So far, the following are the list of program dependancies for Darwinbots3:

  • .Net 2.0 (this comes with the C# express install)
  • NUnit unit testing framework.
  • Tao bindings for OpenGL and other things

The following are not required yet, but probably will be soon:

  • Some 3D math package. Currently leaning towards Sharp3D.

I might end up creating an "install" for DB3 that includes all these dependancies, and have people add a source directory to the install.

Adding paths

In order for the UnitTest project(s) to correctly run after they're built, you need to add your NUnit bin directory to the environment paths for your computer. For Windows XP, hit the windows key button + page break to open up a hardware dialog. Go to the advanced tab, and hit the environment variables button. In either the user or system box, find the PATH entry, and click on it. Then hit the "edit" button and the following text to the end of the PATH variable value field:

  • Variable Value: ;C:\Program Files\NUnit 2.4.7\bin

replace the above directory with whatever other folder you installed NUnit to.

Visual Studio will now run the unit tests as a post build event whenever it builds any Unit Test projects. This way, the unit testing is encorporated into your build process, and you're far less likely to botch something without knowing it.

Coding standards

One of the nice things about C# is that it intelligently keeps everyone using the same coding style, so I won't belabor this point. I will, however, talk about some important ideas not everyone may be aware of.

Unit testing

Unit testing is a way to ensure that a function or section of code works like you think it should. It is immeasurably important for keeping the code robust and bug free. It also makes refactoring much easier. this site is an excellent introduction to Unit Testing for games.

Ideally, you would write the tests first and then "fix" the program to pass those tests. This requires some disciple that I personally don't always have, so I'm not going to strongly enforce this. Aim for this standard anyway. Definitely unit test as many aspects of the code you're working on as possible, even if it's after the fact.

Design patterns

I'm not too concerned about strictly following design patterns, but you should at the least be aware of them. This article shows the more common design patterns and examples for them. Personally I've found various factory patterns useful for things like the DNA language parsing and unparsing.

Architecture

I'm designing the program around the idea of "data-centered". You can read a paper about it here (just browse through it, it's pretty big. Focus on the part near the beginning where he explores different architecture models).

Basically, each module interacts only indirectly with other modules through a central data repository. Instead of a something like monster[456].Draw(), you'd have Draw(Monster[456]). The benefit of a design like this is that it allows you to swap different modules (change your graphics from OpenGL to Ogre, for instance) easily, lowers the allowed interdependency between modules, and lets the modules themselves be reused in different projects.

In general, all the game data, such a bots, shots, ties, etc., go into a central repository. A method goes into class of a data object only if it's strictly involved with manipulating the data and not doing something to it. For instance, a function that takes an amount a bot is supposed to be charged in nrg and gives it waste too should go with the bot's class. A function that handles collisions between bots and shots should probably go in a module. It's not strictly black and white, but generally ask yourself if adding a function ties the data directly together with a module. If we wanted to swap out one of the modules, would we find it difficult to disentangle the data repository from it? If so, it belongs in a module (in the case of the bot shot collision, it would probably belong in the game logic module).

The following is a rough draft of the different modules I'm planning:

  • DNAModule AKA Sunweaver - A fairly self contained module that handles most of its own functions, parsing, etc. Very little interfacing is needed with it beyond a few "black box" controls.
  • Graphics Module - Consists strictly of calls to OpenGL, assuming I use OpenGL.
  • GUI Module - Contains the dialog boxes and windows the user will probably use and see, all written with Forms.
  • Game Logic Module - Handles the core simulation, minus physics and DNA.
  • Physics Module AKA Lodestone Physics Engine - The physics engine for Darwinbots, coded for a great deal of feedback as far as collision forces, etc.
  • Networking - Handles interfacing with the internet. Users could download bots from an online database right from the program, for instance. Also internet sharing, program updates, etc.
  • Disk IO - Handles serializing the data. Data will probably be saved as zipped XML files, to allow for outside manipulation through scripting languages.
  • MainExe - Basically nothing more than calls to the different modules to initialize them and start the game loop, calling each module in the proper order.
  • Central Data Repository - Stores references to bots, shots, ties, DNA, etc. Very little algorithmic work going on.

These modules ideally would end up as seperate DLLs to help enforce modularity, but this might cause cyclic dependancies, so I'm not holding my breath.

Design

Visit the wish list to see the major features under consideration from the point of view of the end result. Discuss them in the forum.