Jump to content

  • Log In with Google      Sign In   
  • Create Account

Perpetual Alpha

Evangelising till I drop

Posted by , 11 August 2009 - - - - - - · 318 views

Remember The Milk. Task list tool I've discovered relatively recently. Integrates beautifully with iGoogle and Gmail and a few other things that I don't use.

Also realizing how much I've missed C++, having spent so much time in C# in work and college.

Pretty short update this. I plan on going through the various abstraction layers I've had to make to be able to test the engine. Abstracting away the system dependencies from the exposed interfaces. Work is slower than it might otherwise be at this stage, but I'm expecting the clean interfaces to pay off.

Native code unit testing in VS

Posted by , 08 August 2009 - - - - - - · 228 views

Decided that since I was setting this up for my project anyway I'd grab a few screenshots and walk through the process of setting up testing of native code with Visual Studios testing framework.

The working name of the game is Project Baltar. So, the solution I created has that name, and I had no choice but to name the engine Gaius. No choice at all [smile]. The engine itself is a static library. And I inserted the following code to be tested:

So now that I have this native code that I want to test, I create a test project, which in the New Project dialog is under Visual C++ -> Test -> Test Project. I called it GaiusTest. The key thing to note is that you need to set the /clr flag, as opposed to /clr:safe to allow the native interop.

To the default test class that was created by the wizard, UnitTest1.cpp I added the include
#include "../Gaius/example.h"
and inserted the test code you see in the following shot. In order to make this compile I added Gaius as a dependency for GaiusTest by right clicking on GaiusTest in the Solution Browser pane and selecting Project Dependencies.

Finally to run the test, I selected Test->Windows->Test List Editor. There was only the one test on the list, so I ticked the box beside it, and hit the Run Checked Tests button at the top left of the test list editor window. And this is the final result:

Test Driven Development

Posted by , 06 August 2009 - - - - - - · 318 views

Long time since I've posted. The short version of things is I'm still in college, soon to be finished, and want to do something about getting a job in games when that happens.

To that end I'm starting making a game. The design is firming up, beating it out at the moment. Technology wise DX9,C++,Boost,FMOD are some of my choices so far, but that's not particularly interesting.

What's interesting, and what I want to write about here, is my decision to try do this via Test Driven Development. This summer I've been working in Microsoft, and I've been made develop using this TDD method, which I'd never heard of before. Initially I thought it was just unit testing, going under some new buzzword. But it's not at all. It's so much more than that.

A brief summary of the TDD process:

  1. Write a new test.

  2. Run tests and confirm that the new test fails.

  3. Write *ONLY JUST ENOUGH* code to make the test pass.

  4. Run tests and confirm that all tests pass.

  5. Refactor/clean code.

  6. Rerun tests and confirm that they all pass.

To give a bit of an example lets say I needed to develop an Object oriented encapsulation for integers. My first test might be:
void CanCreateNumberWithValue()
NumberClass n(1);

I run this test, and it fails, it doesn't compile, so first let's make it compile so we can ensure the test fails.

class NumberClass {
NumberClass(int n) { }
int GetInt() { return 0; }

Running the tests, it is clear that this will fail. To only just get the test to pass, let's do the following:

class NumberClass {
NumberClass(int n) { }
int GetInt() { return 1; }

And now running the tests this passes. Only enough code has been added to pass the test. This is a very important thing. There is no code that there hasn't been a test written for. Because the tests are a complete description of the features of the program, the tests will ensure that any and all implicit contracts are preserved. While this is a trivial example, I have found that rigorously doing this has caught bugs before they happen.

So now we add a second test, for another value.

void CanCreateNumberWithValue2()
NumberClass n(2);

Obviously, running the tests will result in a pass for test 1, and a fail for test 2. So now we want to make the code pass test 1 and test 2. So now we change the class to this:

class NumberClass {
int value;
NumberClass(int n) { value = n; }
int GetInt() { return value; }

And now test 2 passes as well, and test 1 will still be passing. It's worth noting that before we added test 2, the class was fully compliant with the specifications for what the class should do, with that set of tests.

You might think you'll end up wasting a lot of time with this. But what I found was that I ended up spending so little time agonising over class design decisions. Bugs became incredibly rare. I was much happier with the rate at which final code was being produced.

TDD is an amazing design methodology, with testing built right into it. The thing I had to realise, and it came out of my thinking about whether I should be testing private methods, is that in step 1 of the process you aren't writing a unit test. You're instead specifying a new feature for the program/library. Whether you need to implement that in terms of other existing functions which can lead to refactoring common functionality to private members, or whether it's all new functionality that requires new classes it doesn't matter.

One side-effect of this is, for me anyway, is that my encapsulation is much better. My classes are better designed. Clean interfaces are defined.

And it is this last point that is concerning me at the moment. There are things that can't be tested properly, like creating a window and setting a resolution and a pixel format. Or rendering a model to the screen. These sort of things you can't test like this. Instead you need to abstract away from them. For an example of this I might have a GraphicsKernel class that I'm testing these functionalities with. But to be able to test them, GraphicsKernel has to take an interface to a low level implementation. And the testing methods need to be able to instantiate the GraphicsKernel using a replacement test object, which implements the interface, without the system dependancies.

I think the effort of creating these abstractions should be worth the reward of having a comprehensive

Feeback Request: If this is any interest to people I can write up the process of getting native C++ code tested using the Visual Studio testing framework. Getting it working with managed code is pretty trivial.

(Accidentally posted this in General Programming and not my journal :P)

Then again...

Posted by , 08 July 2008 - - - - - - · 228 views

... I'm not sure if this whole marching cubes thing is the best way to go about things. I want a situation where the players avatar is standing on a 'platform', and can pull a piece of ground in front up them up to form a protective shield. Or raise the ground they are standing on to be able to jump to a higher ledge, or lower the ground etc... And while marching squares can easily generate the outline of these regions, considering the fact that I want to add sides to these regions, sides that aren't of uniform depth, there might be nicer ways to do this. Especially considering how much geometry would have to be sent to the card.

At the moment I'm thinking of a traditional height map stored in a texture, using the vertex shader to displace the mesh vertices and calculate normals. Combine this with some clever texturing and it might result in rather nice looking stuff. No idea how expensive it is to send a new texture to the card every frame though. Experiments will show how good an idea this is.

The thing about this is how I represent it logically. Probably in much the same way. How I manipulate it should be interesting...

As an aside, writing all this stuff down really helps you find the holes in things. At the beginning of writing this post I had planned on writing about a VERY different idea, but it turned out to be just silly.

I would really hope to have more screens soon. And a name. It's not a game if it doesn't have a name. [smile]

It's hip to be square

Posted by , 06 July 2008 - - - - - - · 201 views

So, I have had this idea bumming about for a while. Mostly involving using some of the really nice fluid simulation stuff here, especially the super-viscous fluids stuff to make some nice deformable terrain. And the game as of now should be some kind of platformer, so I think for the sake of making things easy I'm going to tie everything down to a 2d plane.

Before I start messing with navier-stokes and other brain melters, I want to get the rendering out of the way. Enter marching cubes, but since this is going to be tied to a plane, reduce it down to marching squares.

This is the first time I've done anything involving dynamic vertex buffers. So I'm not really sure how I should be courting them. Right now I'm generating the vertex data in an array in RAM and then memcpying it to the locked vertex buffer. Its working grand atm, but I want to look into if it's better to keep the buffer locked for a longer period of time and not have that memcpy. Or hell, if I'm doing dynamic vertex buffers just plain wrong as well.

Well this is what I have so far:

That's from a hardcoded grid of values that is marching-squared, and new geometry generated, every frame. I'll be adding sides to the regions defined by the algorithm, which is trivial enough. It'll be a while before I get things looking the way I want, and after that I can get down to making it fast [smile]

GA fun

Posted by , 11 April 2008 - - - - - - · 208 views

Very long time without a post. In college now, doing computer science. Coming to the end of the second year of the course. Fun, fun, fun. But what I really want to talk about is my end of year project that me and a few guys got permission to do and are currently working away on. I'm really excited about this, it's working out much better than I'd hoped.

The project abstract is "To determine the applicabilty of genetic algorithms to the solving of real world phyisical problems". We reduced the problem by choosing to create support latices for structures under complex sets of forces, and then further reduced it for demonstration purposes by creating support latices for bridges, to show some real world application.

So, I think this is really cool. We're currently working away on the systems required to allow us to experiment with the genetic algorithms themselves. Myself I've been developing a distributed network system for processing a scenario. Others have been working on the GUI / Editor and the physics simulator.

We're using XNA in WinForms for presentation, mostly because of the handiness of the content pipeline. The physics is being handled by the Farseer library, though that's requiring some tertiary research into materials to solve problems relating to correct coefficients for materials' properties. And my section, the evolver, is just stright C#. It takes an initial scenario, a specified genetic algorithm script and sorts out all the processing, returning the most successful structure back to the GUI to be presented.

There are a few things I've discovered in the .NET framework that have made everything so much more pleasurable. The XmlSerializer has made developing and implementing a network protocol trivial. The reflection capabilities make deserializing polymorphically a non-issue. I can later swap this out with binary serialization to reduce network traffic, or implement my own formatting without having to change anything in the code that uses the protocol.

The GAs themselves are written as C# script files. Again, I was very pleasantly surprised by how easy it is to compile code stored in memory and load the resulting assemblies, with full error reporting.

I'm not sure how successful we are going to be in creating a GA to solve this problem. The fitness function for how a structure performs is going to be extremely tricky. But no matter I can't wait to dive into that section of the project.

The GUI is coming along nicely, hopefully I'll have screenshots soon, and I very much hope updates on how developing fitness functions are coming. Yes, definitely screenshots soon.

I couldn't possibly take anymore. I'm too full.

Posted by , 09 April 2006 - - - - - - · 225 views

I have the tris being filled. I had a big problem with the edge calculation code that took me a while to figure out. I was using the bresenham line algo that I was using before to work out the edges of the tri. But it would locate more than one edge on each side of the tri on each scanline for lines of certain slopes. It took me a while to figure out what was going on there. Once I figured out that was the problem I wrote up a similar algo to the bresenham that would only ever have one pixel on each scanline and the system worked propperly.

I'm only rendering 2 of the faces of the cube there because, despite how it looks there isn't actually any sorting being done yet and if all 6 faces were being rendered it would just look like a crazy jumble of 4 sided polygons stacked on top of each other.

So my next job should be fairly simple, though from experience those words are the prelude to pain. Sorting the tris. Then I'll have a filled sorted box. After that I'm going to get color gradients working, so I can have per-vertex lighting.

Triangles are my favourite.

Posted by , 08 April 2006 - - - - - - · 250 views

And now I have triangles. Yay! This was very simply added, just an extension of the line drawing I had before, with a bit of processing stuff thrown on top. The real job now is filling the tris. I simply have never come across the algorithms for it, so I get to do some research now. I could probably work it out, but I want to do it somewhat correctly.

You can see from the picture that the tris aren't even being sorted yet. That is going to be the most important job to get done when I have them being filled. Actually, it might be an even higher priority than filling them, but I'll get the filing done first. It sounds like more fun [smile]

Recent Entries

Recent Comments