Thursday, December 15, 2005

Christmas, Santa is an anagram of Satan





I'm off to the UK. I won't be back in Japan till the New Year.
Everyone have a nice Christmas.

EDIT: Finally fixed the graphics bug in my main code. After christmas I'll have a chunk of free time and I want to get as far as possible into stage three.


Tags:
|

Tuesday, December 13, 2005

Working hard under the decimal point : What to do if when you move your camera the border pixels of your textures disappear or get stretched

It seems as thought I've solved the graphics problem, which goes to prove that if you keep bashing your head against it the wall will eventually break (provided you don't die from a brain heamorrage that is). After asking on every message board I could think of and even a IRC chat room or two I managed to stumble on to what seems to be the possible solution by myself. Finding a solution is one thing ... a reason is quite another. I can make guesses why my fix works but I don't think I'll ever go digging for the truth, though it would be nice if some body would tell me :D I have ideas, hypothesis' - yes - but nothing verifiable.

Anyway enough ranting here's the solution I worked on, thus titled: "What to do if when you move your camera the border pixels of your textures disappear or get stretched."

1. Read the mapping pixels to texels thing.
2. Don't translate your camera by a very small number. (I was doing 0.003)

I fixed this by scaling everything up so my view port is currently 800.0f by 600.0f and my textures are some equally large number (I may try and half this, or at least get some nice balance). I move by a full 1f instead of some dodgy fraction. And that's it, the mystery of the missing borders solved. It must be something to do with rounding error, something that's happening far far away in the arch-under-sewer in the sixhundred and sixty sixth level of the direct x API.

Anyway thank you to the following places:

GameDev Help Me Post
The Game Wiki Help Me Post
Usenet Help Me Post
MSDN Help Me Post
Mr Gamemaker Post

Saturday, December 10, 2005

Unit Testing IO

A little tricky no?

It's bad form in unit testing to write to files outside of the code ... but you still want to make sure you loaders and writers work. If, like me, you make use of serialization you can serialize to memory then unserailize and den-duhr nicely unit tested - check the object equals the original one.

This requires:

using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;


Here's an example of one my unit tests.


[Test]
public void SerializesDataOkay()
{
TurnManager tm = new TurnManager();
tm.TurnNumber = 2;

BinaryFormatter formatter = new BinaryFormatter();

MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, tm);
stream.Seek(0, 0); // return to start of stream

TurnManager newTm = (TurnManager)formatter.Deserialize(stream);

Assert.IsTrue(newTm.TurnNumber == 2);
}


Remember the stream.Seek(0,0) or you'll be at the end of the stream and when you try and load you'll get a crash with a exception that's something like: "end of stream encountered before serialization finished".

I fixed up a bug in the clock code that had problems with repeated pausing. I wrote a unit test first and then fixed, yay for me.

For now I've let my graphics problem rest.

Some kind soul on The Game Programming Wiki message boards suggested clamping. And this cleared up a little of my graphics bug but something still remains.



The bottom red line of the texture dissapears when I move the camera to a certain position. I have the feeling this bug isn't probably quite obvious to someone who knows what they're doing and is something to do with my wonky camera setup.

I ripped the graphics out and made a very simple form demo to demonstrate the bug. Here it is Problem.zip

EDIT: Places problem posted now numbering 3:

1. GameDev.net
(about a day ago)

2. The Game Development Wiki
(this morning, very fast helpful response but still no resolution)

3. USENET microsoft.public.win32.programmer.directx.managed
(Just now, fingers crossed)

EDIT 4: Microsfot MSDN help forums

I've finished my other todo and I've now deep in the heart of my map class hacking away dead things and redoing others. This time I'm adding unit-test plating as I go. In a round about way it's all to refactor one function that's comically bad and could probably be seen on The Daily WTF.

Friday, December 09, 2005

Under the water but in the boat

It seem I've finally dealt the killing blow to a bug that caused me extreme pain. I actually noted down a small fraction of my hunt for it here's the fraction.

Wait first let me explain the bug.

I'm making, like many others a simple tilebased game in Direct3D. I'm using Direct3D because we all know direct draw is the devil. Microsoft makes this rather hard. If I was doing it again I'd definetly go for allegro or some wonderful preexisting C# 2D engine.

Anyway in the 3D world there's the pesky extra z co-ordinate and there are cameras looking on to your 2D world. Also texturing isn't straight forward - it's not pixels anymore it's texels, the pixels evil cousin, he starts from the middle of all pixels and was designed by a crack team of scientists to make you cry. So you have to construct your tiles from vertices and rarara

I did this and at some point I got black lines, gaps, between my tiles. I hacked this away in what was now in retrospect a terrible bodge. My rendering code was like a dark jungle where one dared not venture. The black lines dissapeared and their was much dancing and rejoicing - I have no idea what I did but it was something hideous where the vertices spacing of the quad was changing depending on the size of the window. All I know is it wasn't a solution by pre-determined design, rather it was by pure bloody bruteforce.

Anyway the lines dissapeared but soon there where some overlaps and they appeared randomly every few tiles. Overlaps - why that's obviously something wrong with the tile plotter, one would think. Well it wasn't and after lots of confusion I decided it must be crazy 3D camera and floating point rounding errors creating gaps. Far too hard for me to bother win - I'll deal with it later.

Some months later on a monday was later. I decided I'd pull the graphics system out, simplify it and discover exactly where the problems came from. Now here's the log:


O Pulled out the graphics subsystem and madea simpler seperate program
-Revealed a drawing bug.
+Bug was fixed

O Fix is add to main code
-Problem remains

O A new game state was created in the main code to demonstrate the tile plot
+One tile plots fine, as the seperate program
-Using the RenderSubSection plots there's a bug
O Some pixels lines are stretched or clipped ~> a texture bug?
O It happens in the plotting funcion ~> a plotting bug?


Tests to run through
--------------------

Plot a number of tiles behind hand PREDICT: No Problem
RESULT: Fail.

A tile rendered next to the original seems to over lap it! By one pixel.
Even when rendered apart the second tile seems to be missing, it's left most pixel column!
(turn off all other tile rendering and do it again)x
This does nothing

Thoughts For Prediction 1
-------------------------

Are the same tile render functions being used?
Trace through render function
Rewrite the plotting function so that's it's more efficent.
Check a certain conversion function ... currently I'm thinking it's floating point error.

O Remove the +0.03f patch
+horizontal overlap dissapears from both test and example
+all top row squares are the same
-two rows down on the top subsection render a tile seems to overlap another

O Test this in full screen
-no top row or bottom row
-green pixels are twice as thick as blue lines
-top rows are missing from the first two rows.

Editing the textures results in uniform one pixel gapped tiles but with a single errant pixel.

This seems to shout texture problem.
Fiddle with UV textures?

O Fiddle with textures applying different corrections to different axis
+Seems to work on hand plot
-Not tested in full screen
+Hand plot works in full screen
-Doesn't work on long plot.
-Both vert and horizon problems.


-> See if automantic plot can be recreated by hand and if similar problems appear.

O Surrounded texture with pink
+A new pink line appers under tiles
+Obviously current settings require adjustment.

O Adjusted single tile plot seems fine
-Auto plot has same problems
-Not tested full screen

O Added tiles below and above
+Hand plot no problems
-Seems to be an autplot problem.
O A little hard to say but full screen also seems good.
-Full screen has double pixel of the leftmost side (;_;)
+On the sunny side seems like the problems becoming isolated and a fix is within reach.
+It's hacky but if it works it's wonderful.

O Write own render
+Have pink lines from over sampling texture
+Has to be some function in the render function that doesn't occur with hand placement.
O Do hand placement in the exact same place to ensure it's something in the rendering function.



O Moving the render function around proves it's LOCATION as well as a rendering error.
+If location matters than its something to do with the camera
+So I go into camera (;_;) I've been avoid this.
+I change the screen coordinates so that they're ratios of the actual window
+This *uniforms the problem*
+I also hard code the tile size. This wasn't hard coded as I was hoping bigger windows would have more tiles ... it seemed this never worked.
~> Potentially there's only one problem to solve

O First let's test full screen.
:o fullscreen actually seems to work now :o

My code is like an unexplored jungle; there are scary parts you just don't venture into.

O Let's check the actual game ... preparing self to cry.
+Same problems as before pretty much, just looks better now.
+I think now it must be texture problems.

(Solved earlier code mystery - characters where never scaled but tiles where, that's why characters didn't look awful)



Anyway so you see at the end of here things where starting to look hopefuly. But I was once again on the wrong track closer examinings proved there where still graphical glitches.

The seperate program that was suppose to locate the bugs was curiously bug free it worked a treat. So I pulled in some of the cleaner structures - bugs remained. So I pain stakingly ensure the camera and device where all set up exactly alike. The same.

Some lines where a little thicker than others in certain places. There seemed to be less and less places where there could be a problem.

Drumroll please: Eventually I looked to the form. The form itself is a bit of trickyness if you're using it as your device canvas. Let's say you want your game to have an 800x600 view - pretty standard for old school style.

Well you don't set the form to that no because the form includes the little lines of GUI niceness at the sizes and the size of the header bar. All this I knew and thought I had accounted for. Obviously I was somehat mistaken. The only difference between the two programs at this point seemed to be that I was running the main code directly upon the form while the test program be rendered on to a panel control. So I threw in a new control set it 800x600, perfectly fitting the form, and what do you know sharp crisp prefectly aligned graphics. Wonderful.

I found these two links helpful in solving parts of my graphics bug:

Directly Mapping Texels To Pixels (MSDN)


2D Tile Engine Problems, a post on the message board of The Game Programming Wiki.

I'm quite happy, but I'll be happier once the codes all locked down again and performed as expected.

EDIT: Increasing desperation prompts GameDev posting.

EDIT2: ...and now Game Dev Wiki too

Wednesday, December 07, 2005

Why monkeys fight

I found this an excellent and interesting read.

I have a whole spiel somewhere about whatsup with my progress but there's not much at the moment. I'm not willing to move on to the next stage until certain bugs are squashed. I could also do with bolstering my work ethic I think :D Unless I have at least a nice three hours or so of free time I'm reluctant to sink into my main code.

This next weekend is my last before I return to the UK. I'll be back in Japan in the newyear and will have some hacking time them. My new years resoultion will be to be well into stage three before I restart my job :D

When I go to school I often have snippets of free time - I read stuff that I've scrapbooked from various webpages. This morning I read something like 43 things where you write down your goals and see who shares them - sounded quite intereting perhaps it will motivate me more.

Monday, November 28, 2005

Japanese for the angry

It suddenly appears that I have been accepted for the Japanese proficency exam! I've not studyed! It's this weekend! There's lots to learn (;_;).

Expect no updates until after the weekend.

On a plus note I finshed nanowrimo but not my story. That too will have to wait until after this weekend.

Saturday, November 26, 2005

The devil has a mustache.


A screen shot of the first part of my conversation engine


It's the first part of my conversation engine! (click for full size) Isn't it nice. Currently it's working but I have managed to find a few bugs already. For some reason one person can happily carry on a two person conversation by themselves. I'm not quite sure how this is happening yet so I'll have to look into it.

Once again this weekend I don't have much time. Just this morning really. I managed to polish off another todo list item last night but I still have near a page left. Only two items on the page are for my goal of two weeks ago though ... the rest are fresh new bugs that I seem to have introduced or merely discovered more thouroughly. It may sound like I'm sinking in a helpless bog but I think things are actually getting better.

So yes the goals are finish up the Conversation Engine, so it doesn't have that bug. It also has crashed on the three person script but I think in that case it's a problem of not handling a malformed script gracefully.

(Of course I'm fixing these bugs by first writing failing unit tests.)

After that the current goals are:

1. Have loading and saving turns (I'm sure I knew what I meant when I wrote this ... I need to check out the code though)
2. Reproduce a texturing bug in a simplified bug so I can ask for help killing it.

Should be doable.

If you're interested in programming languages you should check out Subtext. It has an excellent flash video (how often do read that phrase, I usually loathe flash, but it's helpful here.) I think the ideas presented are pretty sound. A lot seems so obvious when it's explain that's it's a wonder such ideas haven't become popular before. Anyway check it out.

Aen's blog continues his incredibly rapidly developing tile editor. I can't believe he progresses so fast! The editor looks really cool. I really hope it revitalizes the Verge community a bit - I want more Inide RPGS! I want the days of Megazeux and ZZT to return for the Indie RPG scene!


Over on distractionware I was pointed to a very interesting "game" Rameses ( executable link ). It isn't all that interactive but it will give you a strange sensation. It's extremely well written and worth playing, to try something new. It's also small and short, I finished it at work :D

That's it really. I'm nearing the end of nanowrimo but didn't write anything yesterday or today. I'd quite to finish so I'll probably go into crunch mode monday. I'm going to leave it then and maybe revise it in a month or so.

Friday, November 25, 2005

RAD

I was messing about in windows forms creating a GUI front end for my conversation class (so I can test it visually in real time to make it is really working) - everything's a little bit cooler in VS2005. The form creation has auto align bars - even better than that there seems to be support for .... AUTO-COMPELETION how cool is that? My grammar language could do with a nice bit of that.

There are also various other grovy things and the buttons look a bit different too - who can argue.

Tuesday, November 22, 2005

Dll problems

I wanted to do something really simple tonight - just update a .dll file.

It's really given me the run around though, it kept using the old dll that it magic'ed up from somewhere. Eventually I was forced to include the dll parent project as a sub project of my main programs solution. This suddenly allowed everything to work. I don't know where I was going wrong but gah. At least it's better now.

Tomorrow is a bank holiday but I'm still going to be teaching (>_<) also I have social commitments so I don't know how much time I'll have to work on my program.

The conversation engine is complete but needs a little stress testing to make sure it can handle everything. My unit testing ablitity failed me on the final larger structures :o. So I'm not as confident as with the lower structures.

Monday, November 21, 2005

Recently

I've been building up my conversation engine that required a non-recursive permutation function ... I really didn't want to think how to make this work, luckily it's well documented on the net so I grabbed an algorithm written in C. It could work better but I think works well enough for the time being. I got another class unit tested and pretty much finished and started work on a controller class to tie all my classes together.

The only problem I have is that the Controller class requires classes from my game and I want to keep it modular and seperate from my game. I came up with the following crappy solution.

It uses a interface called ITalker implement get and sets for AreYouInAConversation? and that's about it (all that my conversation controller really needs to know). Which would be fine. . .


... but I want to be able to check things like "Are you near a lamp post?"

So this involves a messy cast that happens outside of my class. I pass the ask talker to Lua, Lua asks some other class to try and cast it to a GameObject for GameX. Then lua can use it's various loaded query functions.

Apart from that messy part of the architecture things are okay.

Today I'm playing with my scroll bar once more, it's one of the things I want complete before I move to state two. Currently it displays fine and can be resized. If you hold down the arrow the thumb zooms as fast as it can to the arrow ... far far too fast. I need a timer ... if I was thinking I'd probably have used windows timer but instead I actually have my own in it's own dll.

I don't want my GUI system to require any other dlls, so I broke it into two parts, the GUI pieces that require a clock function and those that don't. This too seems to be a messy decision :(

(The "mouse-feel" is now so much better)

I need to get break as I've managed to sort out plenty of real life stuff today.

*Scroll bar is totally finished - functionality wise any way. It needs prettying up as I use a tutorial with rather unfriendly names (caps differences in variable names *shudder*). It could also do with a few events to make it useful. I'm thinking OnMouseOverScrollButton, OnMouseOverTrack, OnMouseOverThumb, OnValueChanged. This way I can add fancy graphics and the like - a little pointy hand over the button for instance.

I'm actually a little behind where I wanted to be code wise but at least I've knocked one thing off the to-do list.

Saturday, November 19, 2005

More Unit Testing Fun.

I'm really impressed with unit testing. If you think of your program like a building, the unit tests are the scaffolding. I'd used similar stuff before but then I'd throw the small tests away. Bite size pieces of code to make sure everything was working. With unit tests each test confirms that you're code's working and going the way you want to it to.

Anyway I was so impressed I decided to sign up to the nunit mailing list and see what useful tit-bits I could glean.

I'm working on quite a tricky library at the moment and trying to make it modular - at least for now (if it's too hard, or there are too many casts later - I'll merge it).

I'm working tomorrow :( So no game programming. I'm hoping on monday I finally be able to finish off stage two. It's a lot of code but I'm optimistic. I'm also tempted to start making some of my code unit tested but I think I'll resist such a urge for now.

Wednesday, November 16, 2005

Behold the template


using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;

namespace $rootnamespace$
{
[TestFixture]
public class $safeitemname$
{
[TestFixtureSetUp]
public void DoTestSetup()
{
Console.WriteLine("Set up test");
}

[TestFixtureTearDown]
public void DoTestTearDown()
{
Console.WriteLine("Test Tear Down");
}

[SetUp]
public void TestSetup()
{
Console.WriteLine("Do test setup");
}
}


}


Now each time I want to create a class to do a load of tests I select my unit test class and denden immediate test. So yes today I have been continuing my test driven development of Converse. My faith in unit testing as something useful and non-faddish grows as I use it. It really does pick kill bugs. You still need an architecture before you start imo.

Tuesday, November 15, 2005

Unit testing fun

Getting nunit to work with visual studio 2005 is a bit of problem. It's spits out sometype of invalid file error.

You have to go into the config.exe and in the startup tag there are a number of different .net version - every single one was older than my latest version. So I deleted them all and put in the latest number - which required some searching around.

nunit-gui.exe.config



Looks like so:

<?xml version="1.0" encoding="Windows-1252"?>
<configuration>

<startup>
<supportedruntime version="v2.0.50727">


</startup>


</configuration>




Then it all worked rather nicely and test-first I built up a nice new class to go into my Conversation engine. The scroll bar also now displays properly. Anything where you have to hold the mouse button down currently doesn't work but its getting there.

My super tip for nunit is have your main project in one class library (a dll) then create a new class library called tests (or something equally inspired). Go to references add a reference, then click on the project tab and add your first dll where your main project is. Thereby allowing your test library to have access to your main programs classes! Now all your tests are in a totally seperate piece of code. For the coup de la resistance. Go to the test solution properties and add a post build command that loads nunit.

On Succesful build "nunit /run" should do it. I made the nunit bin directory a system variable. (I did this with lua and python to so I can call them anywhere from the command line. I remember in dos this was rather in easy, the path command or something in autoexec.bat? Anywhoo in window go to control panel. Double click system. Click on the advanced tab. Then click on the environmental varaibles button at the bottom. There's a box called System Variables, in the box is a list box, double click on the one labelled PATH. Then append the following to the string ;C:\Program Files\NUnit 2.2.2\bin. All path's are colon seperated. If you fire up a dos box and type nunit-gui or nunit-console it will run the program.)

Read more about unit testing!

Test-Driven C#: Improve the Design and Flexibility of Your Project with Extreme Programming Techniques -- MSDN Magazine, April 2004


Games From Within Tutorials - excellent resource for nunit test advice - what tests to write and why
Test-Driven Game Development (Part 1)
Test-Driven Game Development (Part 2)
Test-Driven Game Development (Part 3)

Monday, November 14, 2005

VS.net 2005

Currently all my old projects are building :D The object inspector looks really cool too. Everythings ready for me to resume development.

Sunday, November 13, 2005

Visual Studio 2005 and Migrating my DirectX C# programs.

Well I've had one locking bug but with time and magic that dissapeared. Then I had a load of problems with dlls and non-matching version numbers.

How did you solve this Dan? Well, of course I messed about for a long time. Finally reading this thread. Where it told me to remove all the references and re-add them. That worked a treat ... at least for my GUI library.

I didn't finish this weeks goal but I did finish last weeks goal :D So at least I got some stuff done. I'm hoping to polish off some more of this weeks goal tomorrow night. I'm busy tuesday through to Friday night :(

When I finally work up the will to clean up my tutorials or write more this tool will be invaluble Copy Source As Html. I found it from the Ten Essential Tools list on MSDN. The list from last year is still extremely valid and worth checking out.

Have fun.

Sunday

Well yesterday I didn't make my goals for nanowrimo. But I did do pretty well on the programming size. Programming wise I could probably finish up the stage-two tasks. But it seems I've somehow been pulled into entertaining children - can't children entertain themselves grahhhh.

I'm currently installing VS.net 2005, it's bit of chore to force it onto my remaining space. Suprise suprise my projects don't compile.

Saturday, November 12, 2005

This week.

Last week I wanted to decouple map references from my map object ... I'm still working on this.

During the week I started building a new library in dll format. It's going to be involved in conversations. It's mainly pulling together lots of little pieces of code that I've been working on. I may work on it today somemore. I also did some very minor city generation stuff nothing exciting yet, though I have a good idea for an algorithm.

Last week I did some refactoring and suddenly lost collisions! I managed to get tile collisions back in and just now and I've added in collisions between actors.

There are now new problems ... (;_;) I get flickering when my character moves from one map to another and if he starts moving from map to map to quickly he and all the other actors dissapear. I'll deal with this after all my current problems are finished. I'm not going to move to stage 3 until it's dealt with though.

I now think I've removed everything that was causing the abstract class map object to be coupled with a map, so I can safetly remove it. This is another step to maing my code less tangled and more modular.

My weekend goals are to tidy up stage 2 ready for stage 3.

+decouple map object
* Done! Game has also become magically faster too. The best kind of optimization is the magic, unexpected kind.

+prevent crashing when actors move on to unbuffered maps
* Also potential done but I need to check. checked it, it didn't work immediately but does now. Yay!

+develop a scroll bar in my GUI (it's been half finished for ever)
* Working much more than it used to be.
If you ever thinking of buying Wordware's DirectX 9.0 User Interfaces Design and Implementation, don't. Being very favourable it could be called a code listing. But the code is incomplete, the naming of the variables and methods seem almost purposefully misleading and the actually logic in some of the code is just off.

That said my scroll bar class is somewhat working. Unfortuanely the scroll bar thumb can scroll right off the bar. Not a big problem though. Far better than the previous scrollbar that didn't even show it's thumb. It's now working apart from if you stretch the bar :( The scaling code just isn't doing it's thing. Sooooo I think I can hack it. I'll make a scroll bar that won't work in every case but will work everywhere I want it to in my game. Afterall I'm not developing an operating system here.


+remove debug users (my menu support a number of users - for people who share a pc or one to have several different games on the go)
+default world image
+in the menu order the worlds by last played
+try to reduce class heaviness especially actor (this is a bad goal as it's vague. I think Actor is much lighter now anyway)
+slow down turns / pause turns
+save / load turn state

The last two sound rather daunting and while they'll probably be hard they're not as bad as they sound.

I will be supremely happy if I manage to get all the above done :D

Currently attempting to install VS.net 2005 but it seems to mean I'll finally have to install Service Pack 2 :D

Wednesday, November 09, 2005

Hear my mighty roar

Mid week programming isn't going to great.
I've been playing with a very simple city generating algorithm that currently produces output. I've been cleaning up the code and just today fixed another bug I managed to cause with my unfinished refactoring (vs .net 2005 looks so sweet - but I have no room on this portable to swing an upgrade. Maybe I can sort something out when I go home)

Unsually enough for me I've been mainly playing with the core code. The goal this weekend is to conclusively finish last weeks goal (decoupling object dependance - I want my mapobject class not to need a map reference) and then tidy up all the remaining stage two tasks.

... at some point I really hope to have a game :D

Sunday, November 06, 2005

Progress

I didn't realized before but I pretty much have a good chunk of full RPG system up and running. I can have NPCs that are controlled by lua scripts then the only big game pieces missing are combat and inventory.

Still refactoring and hunting down bugs.
Nanowrimo isn't really helping me.

Anywho refactoring continues. Currently I've altered bits of code all over the place and I'm trying to get to all work correctly again.

*Every works as it should now. The code in the process of being moved to a more zen-state, though I like compilable stepping stones to guide my way.

(also it's become quite apparent that I really knew nothing about OOD before I started out programming this. Such questions as Intersection where should such a function go in my myraid classes - were answered incorrecty. Each entity is my game had an intersection function. But really is that any object? Is that what this object should have to think about. It would have to know it's position and other creatures position too - its far more appropiate for it to be in the world or map object. At time of typing intersection remains with the entities ... but I'm getting there.)

*Map object still have a reference to a map. Tiles and Actors are map objects. They each have one function that make use of the map varaible. These are all the stand in the way of my goal. If there's time I deal with them tomorrow night.

This mini-wave of refactoring is really helping to clean up my interfaces once again. Errr what else ... oh it would also have been rather hard to plan the perfect architecture from the start. As soon as I finish the house work on stage 2 I'll get to some of the more exciting functional content in stage 3. A lot of it will be stuffed patched in that I've worked out in the snippet complier but there's other stuff that requires writing from scratch.

Continuing Refactorization

... the code will be better after this.

It will be a long way from perfect, it will most likely still be a long way from nice but it will be catching up to workable. That's the target.

Then I'll be doing some game niceities. Basically place holder graphics for various bit's that aren't in. I'll have another crack a texture tiling bug - somethings the last line of a texture is cut off for no appararent reason.

Once city generation is in - it will start to look quite nice and explorable. I'll probably need to work very hard on making it always stable.

How not to code:

Trawling through my code base seems to be like breaking open a rotten orange. I found this gem of an interface:


namespace EINFALL.Game.World
{
///
/// Summary description for ILocalMap.
///

public interface ILocalMap : IAbsoluteBounds
{
void RefreshTilePositions(); //If map DX pos changes
//Check if one MapObject's potential boundary collides with another map
//object
bool ObstructedByMapObject(BlockBounds boundary, MapObject focus);
bool ObstructedByMapObject(PointF point, MapObject focus);

bool IsPointBlocked(PointF p);
bool IsPointBlocked(float x, float y);
int GetTileIndex(Tile t);
int GetTileIndex(float posX, float posY);
int GetTileIndex(int x, int y);

void RemoveMapObject(MapObject m);
void AddMapObject(MapObject m);
//Remove a map object after it finished being used
void KillMapObject(MapObject mo);

//Is some map object potetially going to break the map boundary?
void TransferCheck(IAbsoluteBounds aBounds, MapObject mo, Breaks breaks);

void RenderDetail(float x, float y, Device device);
void RenderBase(float x, float y, Device device);
void RenderSubSection(Point startPoint, Point endPoint,
Device device);
void RenderSubSection(Tile startTile, Tile endTile,
Device device);
void Render(float x, float y, Device device);
Tile GetTile(int x, int y);

void SetMetaMap(BufferedMap m);

//Could probably be turned into getters
Tile[] GetTileArray();
void SetTopLeftDXPosition(float x, float y);
void SetTopLeftDXPosition(PointF Position);
Point GetShellPosition();
int GetTileDimension();

}
}


It seems to have nearly every function as the map class but with near everyone of it's function abstract.

It did make sense, in the beginning, to have a ILocalMap class. . . well at least I think it did. Well I made sense to have an abstract Map class - I was definetly going to have more than one type of map class - that would probably share functionality.

Some how that reasonable intention turned into the above monstrosity - nearly all the functions are only relevant to one type of map! This morning I've been cutting away dead code - that randomly threw up a few errors - miles away in the code! Suddenly there seems to be a endless loop happening now and again in my map functions. I think I've squashed it. I know I've at least fixed one oversight but who knows what else may be lurking.

Anyway I'm slowing hacking away at the code and we'll see how it goes. I'd love some good recommendations for OOD, OOP books actually. Maybe I should grab the a patterns book too?

* Turns out I needed this interface beast so I could have a skeleton map too. One that did nothing but existed while a real map was being loaded from the disk. I'm almost certain that this is the most messy solution I could have come up but it does work.


Saturday, November 05, 2005

Rules Object

We all want our code to modular. Even in an advanced project it would be nice to be able to:


Orc orc = new Orc();
Man man = new Man();
Write(man.Health);
Write(orc.Health);

RenderSystem.Render(man, x,y);


Something as simple as the above using only very light code. We don't have to locate graphics files each time we load a man, or pass in a sound system pointer, or a input object, or rendering system, or skill tree object - As much as possible we strive to make our classes as independant and modular as possible.

Among other things that what I'm striving for today.

How?



Well one of the ways to do this, especially with Actors and the like is by using a mediator class. For actors, sprites, beings, gameobjects ... this mediator class is often called: Rules or GameMaster. That's where you put your interaction rules - how things will interact with each other and the world.

So instead of each actor have something like:

actor.Attack(IAttackable a)


You have:

Rules.Attack(Actor actor, Actor target);


This way your game pieces are more modular and your game logic is kept tight and together.


*Renamed extremely unhelpfully named class (that's been here since near the start).
*Fixed a GUI object so it works as you'd expect
*Pulled loads of stuff out of my Globe class and pushed it back in utility classes of pre-existing objects

[This month i decided my never ending game project wasn't enough and decided to see if I could write a novel in a month with the happy crew of nanowrimo. It's fun, if you think you can catch up you should give it a go.]

Refactoring ...

I'm using a lot of the Replace command today. I've made a lot of classes that have been required for quite some time. The codes becomng more organized but it still feels a little messy. I've not even started on this weekends goal yet :D

Friday, November 04, 2005

Refactoring

I've finished my second stage.
The code needs cleaning though. A lot of stuff is messy and far far too interlinked so I'm going to try and reduce the amount of code and make it clearer. The goal for the weekend is to remove the map dependancy from the map object class. Map objects should be owned by the map class, there shouldn't be a need for a back link! ... at least I'm pretty sure there shouldn't be.

This is tomorrows job any way. Tonight I'm going to relax.

Monday, October 31, 2005

Rolling rolling rolling ...

Gah I think I'm going to have to roll my own XML parser - this is cheifly because I don't really want to use XML. I want to use bits of it. I want to embed pieces of code - code use < and > signs and that's exactly what I want to type. I don't want to do : lb or whatever special mark-up voodoo it is.

Also I find lots of tags tend to bulk up the files and make them unreadable. I'm going to be hand writing these files so they need to be clean. So that will give me something to do at work tomorrow.


Tags:
| | |

Sunday, October 30, 2005

AI!

Yes now the warlord just starts running - clunky animation and all. It's quite cool.

The only problem is when he's out of the players view he continues to run. Maps are buffered around the player. When he manages to run off a map, well then the game crashes. He's checking if there's anything blocking him - as he moves from one map to another. The next map not being buffered means null pointer and CRASH!

Not an entirely unexpected bug. At this point the NPC should be promoted to metamap status, or depending on importantance - just turn around. Maybe as default I should always have the blocking state be returned as true.

There's also the problem that CPU cycles shouldn't be spent on what the player can't see and the distance he travels should just be estimates. All this is for another day.

I've succesful reached my goal yay! Not too hard it you keep them modest!

Tea drunk. Warlord added.

A quite poorly drawn warlord has graced the world with his prescene. I'm going to put in some extremely stupid AI and then I'll be done and happy.

So how are the goals going ...?

Well I keep looking at my code and thinking - what is this? What does it all do? Why is all so messy?

It needs refactoring. Programming something so big - has really allowed me to see design flaws that much more sharply. So I'm noting down changes that are required. After every stage I refactor - and I'm oh so very near the end of this (stage 2).


I've written out a full plan on how I'd like my conversation tool set to progress. Then I did some programmer art for a warlord. Current he can walk forward - or run forward. It's not incredibly dire (artist ablility wise) but it's far far away from good or usable even. I really think I should start colouring the sprites in black and white and the colourize afterwards.

So I polished off some of the frames of the sprite. Great. Then I knitted together some code that was seperate in my project but required knitting. Then I checked and it seems to work rather nicely - just as it did in the test program.

Next up I need to write a very simple warlord brain, I need to hook a physical representation up to the warlord. Then I need everything to work. But first - a big mug of tea and then to work!


Tags:
| | | | |

Saturday, October 29, 2005

Goals rawr

Saturday, (time of writing), I generally don't work on my projects - as I need my socializing time away from work. The same is true of this saturday. Tomorrows goal is fixing up the warlord code but that's tommorrow.

I have an hour or two free this morning so I'm continuing to work on smaller programs that have caught my interest. These programs are generally written using SnippetCompiler or Lua.

Also I've been catching up on my mail list reading. It's quite useful to subscribe to a few technical mail lists as it keeps your knowledge fresh and up to date. This is the theory anyway. Generally I recieve the mail but never read it . . . I'm catching up on maybe a months worth now. I wish there was a simple extremely lightweight program that would download my unread gmails - without deleting them - and allow me to read them offline.

Anyhoo some clever chap got Lua up and running on the Nintendo DS! There's a screen shot of the console here.

This morning I'm working a little on my conversation modules - I'd say Engine but there's no architecture yet! It's all bottom level functions -> that have yet to be pulled into anything useful.

I also got around to downloading the version 2.0 of net or whatever it's called. Whatever gives me the new CSharp stuff. I want to start playing with generics - they sound groovy. I try not to worry about speed but all the boxing and unboxing with arraylists - always worried me in my program. I don't know if I'll convert my current code base though - it's a rather lot of work. I'll wait until I finish of need to optimize.

(offtopic:I also watched "The Corporation" which I quite enjoyed in a disturbing way. A bit like the No Logo book. Check it out, try a different perspective out, it's all about different experiences.)


Tags:
| | | | |

Thursday, October 27, 2005

Beep beep boop beep

This week at work I managed to write my Context Free Grammar code entirely in C#. It now creates a C# datastructure rather than taking the easy way out and producing a Lua program (I didn't stick with this - 1. I wasn't sure about cleaning up the memory. 2. There where conflicts with Lua keywords in some cases 3. It would not be as fast. 4. It was pretty tricky to extend.)

So I did that. Checked it then wrote a nice dll to wrap it. I want to write code and forget about how it works - for me, the way Visual Studio works - doesn't let me do this easily. I want to write code that's done and then I never ever want to see that code again unless theirs a problem. The way I've been using Visual Studio - it's all their as clutter. DLLs are one way around this - but I don't want a billion dll files. I think perhaps the best way to do a large project is to write nearly everything as a dll then you can add a load of other projects to your solution that reference that dll. You can have a unit test project for instance. Lots of small projects that poke around with your main code. Surely the way to go. Currently I have three dlls - clock, GUI, grammatron. These are mine. I don't use the clock dll as the code's part of my project.

I've been playing a little bit with combat and I've been playing a little more with conversations - and the format for writing them. This weekend I try to reach last weekends goal :D

Sunday, October 23, 2005

El Weekend

Argh nothing done this weekend at all due to various social commitments. During the week I wrote a game development tool but that's all!


Here's a cool site called distractionware which is chroncling the progress of an interesting looking RPG, there's video and screens shots and stuff.


Here's a a handy thesis on computer game architecture
. I've not read it yet but it does look rather promising. It hosted a gamasutra - so you may need a free login - or use bugmenot.

Here's a podcast, that covers video games and ludology. I've not listened to it - and I'm a tiny bit suspscious of ludology as whole. There seems to be some real mindless rubbish written in it's name.

Nothing much else to add. Hopefully I'll get a chance this week to develop some bits and pieces more thoroughly.

Sunday, October 16, 2005

On Namespaces

I'm patching in the code today. In the past I've never got namespaces correct.

They tend to be:


  • Poorly Named

  • Deepy Nested



I think I'm getting better lately though.

A general rule to try and follow is don't nest deeper than 3 steps.

For me it goes the first part is always the company name. Then the general division goes as follows:


EINFALL.GUI
EINFALL.Clock
EINFALL.Game
EINFALL.Engine
EINFALL.IO
EINFALL.Tests
EINFALL.Menu


These are all created to be as modular as possible - with the exception of IO. Though I did write the classes in there so as little as possible needs to be swapped around.

Game is the current namespace where I'm thowing plenty of stuff in.

Saturday, October 15, 2005

Code Finished

That's the code finished in snippet compiler, all that's left is to push it into the main trunk of my code in VS.net. That's not going to happen today though. I've been leisurely prodding at the code the last few hours and I'm out of ompff.

Working on.

It's working quite well now. About one more line to change then it's ready to throw into the main code brew.

Amazing what gets done while trying to avoid coding.

I've messed around with the template for the blog a bit. It's still not perfect but I think it's better.

The goal this weekend is getting the concept of a turn (as turn based game, type of turn) into a real system. Also having AI decide what to do and execute what to do over a number of terms. It's one of the complicated parts of my project - that really should get a lot more planning than I've given it.

I'm not messing around in my main code at least. I've just fired up Snippet Compiler and wrapped my clock code up to a .dll file. That way I'm free to mess around. This was on done while at work - which was busier than usual.

I've got a basic idea what to do but it's not straight forward and I'm making use of some design pattern stuff. To document the code I wanted something visual so I searched around a decent free UML package. AgroUml was the answer. Hosted on tigris - the same as Subversion content management. I think Tigris an open source intiative that has a goal - of fully completed projects - not just stuff that's hanging around hardly touched. Anyway it does everything I wanted - simple UML diagrams. I downloaded the c# plugin too - even though in the end I couldn't find how to make it work (I don't wanna spend too much time messing around). Also high level C# and Java aren't radically different so it suited my needs.

There's currently a nearly complete prototype sitting in the snippet compiler program now written in a pleasant manner. So I'll finish up that today and if I have time I'll pull it into the my main code.

There's a nice little blog / journal over on Gamedev.net it's all about creating a Final Fantasy Tactics style RPG in Java. The posts are quite informative! Worth checking out.

I also need sort out the comments on the blog as the new templates messed them up a bit.

Oh look at that I seem to have got tags working again as well

Friday, October 14, 2005

Read This!

How origin fell! (personally I've always blamed EA it will be nice to finally know the truth.

http://www.escapistmagazine.com/issue/14/4

Origin was the best game company ever ever ever

Ultima Underworld's, Ultima Seven part one and two, Ultima Online (near the begining before it was decided that it should try and clone everquest as much as possible)

Also I really really want the offical book of ultima. So very badly.

Goals for this weekend include mixing turn based and real time time. Also some AI. My goals are little bit more detailed than that but my eyes hurt so I don't wanna type any more.

Saturday, October 08, 2005

Pretty much done!

I'm calling it a day now. Every is oh so nearly complete. Users can be selected - but I haven't hooked up the new game launching code yet. That's all that's left to tackle for me to reach my goal of getting it done this weekend. Oh that and arrows and testing. I'd put up a screen shot if it didn't look so poor :D Maybe at the end of the next stage!

I think my work ethic today, left a little to be desired. Still I ploughing on - and that what's counts. It's starting to get a unique feel too instead of being a YAWAD (Yet Another Walk Around Demo) - I made that up all by myself :D.

There's another blogger over here, blogging about developing a 3D engine - hopefully it will make good reading!

I also changed my blog name from Game Dev to game development. I think it looks nicer - it always felt like seeing half a word before. Though Dev's easier to say / think.

Progression

I've spent an hour or two messing with the GUI code. Luckily it's now cleaner rather than messier. I've managed to kill off two classes that were just replicating code - infact I suspect I'd intended to kill them earlier but forgot.

Some of the GUI artwork is up and running but it needs to be dynamically positioned by the computer - that's still to be done! Still it's nice to see progress!

Goals for the weekend

I'm finishing off my menus - the codes done. I just need graphics then I need to hook everything up. Shouldn't be too hard ... graphics just take time.

Wednesday, October 05, 2005

Cultures

Today I cleaned up my XML io code. It's pretty simple - each object has information about it store about as XML. One function finds the XML files and then the information is loaded. It can save to - all pretty standard.

After that I moved on to my culture data sets. I'm really using Lua and C# here at the same time to represent "culture". (This is a word I've chosen don't read too much into - it's mainly gimmicks :D ) Anyway the cool thing is that a lot of the data is store in Lua tables that can be modified on the fly - I'd like cultures to be able to change. I'm being intentionally vague - as I don't want whippersnappers stealing my glorious ideas :D The C# code can also write out the state of the culture as Lua code - which is quite cool. It's a long way from being but into the game though.

That's pretty much it for today. I'm looking forward to fiddling with the main trunk of my code this weekend and possibly coming to the end of stage 2 of my development plan!

Tuesday, October 04, 2005

The worse XML parser ever

Today I wrote a very crappy XML parser (built on an XML library). It reads in some setup stuff but I'm pretty sure it will crash out on malformed XML.

All the XML will be computer generated though - so I'm leaving it, as it is. It's pretty much the final link in my menu system. Everything basic can now work. So I've managed to catch up on the coding I missed this weekend.

I also put word verification on the comments - because I started get lots of spam there. If you're logged into blogger though - I really don't think it should be required! I'm sure there's a better way; like making sure ips can submit many comments to many blogs impossibly fast. Or, heh, blogger's partnered up with google can't they use the same spam killing stuff that works on gmail? The current way is quite user unfriendly. (why do you have to type in 6 distorted letters - wouldn't 3 or even 1 have been just as effective?)

The Games Developers Refuge (GDR) seems to have been ressurected - a forum for indie game developers to chat. FrozenEmu and Tsugumo don't seem to have a had a hand in it though :( Still there seem to be a few interesting threads for it to be enough of a diversion.

Monday, October 03, 2005

Weekend woes

I got nothing done and managed to lose more sleep than I gained. Still today I managed to get some IO stuff done and tune my grammar front end a little bit.

Depending on what works is like I'll be able to polish up my io ready to slot it in on the weekend and add some pretty graphics.

Friday, September 30, 2005

The Code Empire

I've been programming some Empire code for my game but it's very skeletal. I've also rejigged some of the IO so the diretories have sensible names. This weekend I'm going to have my "world select" code finished.

Nothing too excited - if I keep up the pace I'll be stage three of my program plan by next weekend. That will be nice :D

Wednesday, September 28, 2005

Making the computer sing!

Creating a grammar to produce a random song is hard. I'm guessing AI research PhD hard. But I just want extremely simple ditties to liven up my game. And if I can make insulting ditties about the player - all the better!

A grammar can only produce extremely simple songs - as it's very hard to keep the song about the same thing. You might have a production.


[songs_about] -> love | angels | sausages | wilderbeast


Looks pretty promising right? - WRONG!

The song will change half way through - at one point the singers talking about love then sausages - entertaining - yes but not widely applicable.

Therefore the grammar output needs to have some post processing / don't use a grammar at all - or use a Context Sensitive Grammar (harder to right, not as fast) instead of a Context Free Grammar.

For now I'm going the post-process route. Anyway with these grammars bards could make up songs on the spot - enough songs to draw from and it might even sound okay. The bard could also draw from things he can see - which could be interesting.

I'm very interested in making songs about the players deeds if they're cool enough but the current way I'm making songs won't cut it. Anyway let's see a pre-post-processed song grammar output.

Oh I knew a man and he loved a [lovedthing],
Finer than the big wide sky thought he, it to be,
[lovedthing] oh [lovedthing] was all his eye did see,

[lovedthing] oh [lovedthing] was all his eye did see,
hey hey oh heyyyy,
[lovedthing] oh [lovedthing] was all his eye did see,

Oh I knew a man and he loved a [lovedthing],
Finer than life itself thought he, it to be,
[lovedthing] oh [lovedthing] was all his eye did see


Surely heartfelt and the new global number one. Let's assume I've written some post process code (which I haven't) and let's say it makes the following song:

Oh I knew a man and he loved a cat,
Finer than the big wide sky thought he, it to be,
cat oh cat was all his eye did see,

cat oh cat was all his eye did see,
hey hey oh heyyyy,
cat oh cat was all his eye did see,

Oh I knew a man and he loved a cat,
Finer than life itself thought he, it to be,
cat oh cat was all his eye did see


Currently I have a conversation mark-up code thing - I may produce that rather than plain text. That may make things a little more interesting - it can handle producing stuff like a woman, anorange.

Here's the pretty crude grammar. I actually wrote three of four song grammars but this was the first:


[start] -> [songs]

[more] -> "life itself" | "the big wide sky" | "the deep blue sea" | "gold and silver" |
"his sweet family"

[songs] -> [song1]

[song1] -> [stanza1] "\r\n" [chorus1] "\r\n" [stanza1] |
[stanza2] "\r\n" [chorus1] "\r\n" [stanza2]

[stanza1] -> [line1][line2][line3]
[stanza2] -> [line1][a1line2][line3]

[line1] -> "Oh I knew a man and he loved a [lovedthing],\r\n"
[line2] -> "He loved it more than " [more] ",\r\n"
[a1line2] -> "Finer than " [more] " thought he, it to be,\r\n"
[line3] -> "[lovedthing] oh [lovedthing] was all his eye did see,\r\n"

[chorus1] -> [line3] "hey hey oh heyyyy,\r\n" [line3]


Here I could also have [emotion] -> hate | love ... which would give the song more scope for being random. These are all post process procedures - which I haven't touched. I'd like them to be quite modular.

Of course I also want books, item description, personal histories ... etc

... maybe I should be looking in more fractal stuff. (the linguistics stuff in this article is dodgey in my opinion. You and I understand the sentenced - Bryan bryan-ed his was down to the shops. We can make up words and be very creative in sentences - it's not a strict grammar - have these people ever heard anyone speak?)

Also this link about games for education caught my attention. One of the things in the back of my head is a FF / DQ rpg to teach English. A little like Slime Forest (which is for learning Japanese) but with more puzzles.

Tuesday, September 27, 2005

Jeeves and Wooster, policemen like foxes enjoy being hunted.

Currently I'm doing boring IO stuff. Also the people at my job actually seem to want me to do some work this week so I have less time to tinker. I downloaded the latest version of the Snippet Compiler (the beta one).

Last night, by the magical wonders of the internet, I was watching some Jeeves and Wooster (featuring Hugh Laurie and Stephen Fry). I always thought the books played with words quite well and the series, though rather old now, is excellent.

The names where also good too, as recent posts have shown I'm a bit fixated with names at the moment. The names bandied about in this program - along with the language is obviously upper class. These names belong to certain strata of society. I wondered if I could get a grammar going ... :D I only watched one episode but I managed to note down a few of the names that came up mainly last names. Today at school I came up with the following rough grammar:


[start] -> [S1][mid][e2] | [S1][V][e1] | [S2][V][e1]


[S1] -> "gl" | "br" | "f"
[S2] -> "wo"
[V] -> "a" | "e" | "i" | "o" | "u"
[mid] -> "ith" | "ains" | "ipps" | "iggs"
[e1] -> "ssup" | "ster" | "gget" | "n" | [e2]
[e2] -> "ley" | "wauld" | "worth" | "wick" | "bottom"


Which gave some reasonably good outputs even though it's obviously rather limited at the moment.


Fithley
Woan
Glogget
Woester
Woen
Briggsley
Brester
Glithbottom
Woussup
Woin
Bregget
Figgswauld
...


These are pretty good names but I'd like a little more variety. I'm thinking of creating possibly fifty or so grammars like the above for upper and lower classes. On top of that I may add a random grammar generator that will probably create truely unusual but not impossible name-sets.

Of course at this point you may be thinking Why why why all these names? Well I find it entertaining and interesting. Also the scope of my game is rather large and name thirsty. I'm not the only one[2, 3] of course people writing MMORPG will want name generators perhaps as leveled as mine (or even more complicated)

Nothing else interesting to report at the moment though.

Sunday, September 25, 2005

A Grammar Bender

I'm on a bit of a grammar bender [2, 3] at the moment.

Today I converted my old pirate crew and captain generator, written in C# to two nice grammars.


Cut throat Robinson
Cutlass Thirsty Thomas
Yellow Joyce
Sea Cow Rapin' Bill
Whore Bitin' Bob
Fingean the criminal
Muttering Todd
Silver Swimming Henry
Nail Carryin' Guybrush


I'm tempted to post the grammars here but they're pretty lengthy so I'm going to skip it!

Here's some random french too! (see the grammar at the bottom of this post)


Entretarfitie ciep nunson sousolec
Chanic quuntou entrejimspemee gaumir
Ranceau conessom maliman rancam
Senoir quoeunir chontent sileur
Conamep blonpie fentegne goitain
Sousassugne vanseau voic ranpec
Stance entredagnejonou ninsusse domeur


Words seem a bit long but still pretty cool.

I've added a help commmand to my console - so I don't forget the commands I add!

Also this is an excellent article on promoting your game!

Saturday, September 24, 2005

Grammary Front End Goodnes'

I have a very nice C# form front end to my grammar parser, builder, excuter-majig.
(probably about 15 minutes work - C# is a wonder! Once again I'd love to show pictures - I'm holding out that one day bloggers picture option will work for me, too)


[start] -> [C][V][C][End]
[C] -> "b" | "c" | "d" | "f" | "g" | "h" | "j" | "k" | "l" |
"m" | "n" | "p" | "q" |"r" | "s" | "t" | "w" | "x" | "y" | "z"
[V] -> "a" | "e" | "i" | "o" | "u"
[End] -> "dur" | "mir"


Grammars such as the above go in one box - names come out the other! Splendid.

Minor problem is that, for different grammars, I never reset the parse tree so the grammar just grows and grows. The end functions probably aren't too clean in lua either. (as in tricky to remove memory-wise)

Here's some example output:


Bifmir
Mesdur
Lizdur
Giymir
Rojdur
Jirdur
Foldur


Not bad names - ends could do with a little variety though.

This and my world generation algorithm in my main code has made today quite successful!

I've registered a source forge account and might upload this project once I've polished it. Probably under the MIT license or some quite unrestrictive license.

The High Seas

My world generation is working. I can now walk my character around the world through (overly vast) oceans and come across land! It's pretty cool. Just like a mighty pirate.

I'd put up a screen shot but the image tool for blogger does not work me :(

I'll now remove the world generation code from the user selection screen (I hacked it into test.) Then I'll work on whatever next on my todo list. Or I might add a front end to my grammar thing - then I can convert some complicated C# code and Lua code into clean simple grammars.

I'm approaching the fun coding again! yay!


Still the world selection screen will probably hurt me :D

Friday, September 23, 2005

The F in Friday is for Freedom

Today it's a bank holiday in Japan. I don't care why - I'm just happy it's here.

This morning I spent ages rewriting the last post - so it was far clearer. At the end I added more examples. There where useful links all over the place. But posting to blogger failed! And going back revealled the original post. I wanted to cry. I'm sure there's some plugin for firefox that might save me future horrors like this ... I'll look for it later.

This morning I've fixed up my code. The globes genarator seems to be working reasonably nicely. It's writing files out. Soon I'll push it into my main code base shortly. Hopefully painless.

Thursday, September 22, 2005

Grammars

I had a couple of goes at creating a grammar programming language before. I posted some my results in this venture here and here. I never finished my implementation because I ran up against something tricky problems and got bored. Well, recently I started playing with this again but this time I finished!

If you're not familiar with grammars (I talked about using them for generating random names) they are collections of rules. As an example, let's make one production rule for all the vowels. We'll call the rule V.


[V] -> a | i | e | u | o


Pretty simple. Any [V], a non-terminal, can be reduced to anyone one of the vowels, a terminal. Now imagine we had the constants, too and something called "ends".


[C] -> b | c | d | ... | z //assume I've written them all out here
[ends] -> dar | ug | hir


We can line up these non-terminals ([C][V][ends]) to create names.


[name] -> [C][V][C][ends]


Then if we reduce [name] by randomly picking elements we'll be given a variety of randomly generated names. Of the form a constant, a vowel, a constant.


pick1: Nogdar
pick2: Hilug
pick3: Yahdar
etc


Pretty cool! Not just for names either - we can build random descriptions. Also grammars don't have to be reduced to strings they could be reduced to a list of functions or instructions.

At first I tried to create a nice parser written entirely in Lua. My last attempt had also been in Lua ... and it's painfully obvious it's just not the right language, for me, to do this stuff. So I did it in C#, the traditional way -- I parsed it and built a symbol tree.

There a lot of things that can be done witha symbol tree - it can be used to generate a C# data structure, that can the make use of the grammar. This would probably be the expected thing to do. If you want to go the program language route then you might change the tree to an ASM program or program for virtual machine (like the one .net uses). I didn't do either.

The program outputs the tree as a Lua program. (Previously I'd had written a Lua program that would write a lua program according to a grammar, that worked but had a restrictive syntax). Then the program generated works just like the grammar and can be run in Lua. The reductions are randomly picked (there's no options for probabilities like from the vowels be more likely to select 'e'. This is something that can be added later) Grammars can also be written that call Lua functions too! So that's quite a lot of power right there!

I had intended this program for world generation but currently I'll be using it for names and title generation. I may add a few extra steps like randomly generating the grammar itself (possibly with a grammar :D).


[metaEnds] -> "ends ->[" [C] [V] [C] "]"


If I polish it I may upload it as a sourceforge project as its potentially quite useful to others as well.

That's it! Following are grammar examples!

(These are taken (an converted) from http://www.ruf.rice.edu/~pound/ but it seems to be dead at the momement. The names are left undescriptive)

Psuedo French



Why did I choose this one it's massive! Oh well. Imagine in your game you could, on the fly create random foreign books - or have people randomly speak (say before you've learnt the language).


[words] -> [C][D][F] | [C][V]"n"[A][X] | [C][V]"n"[A][U] |
[C][V]"n"[A][T] | [C][V][M][T] | [C][D][M][U] |
[C][V][M][U] | [I][V][M][T] | [E][C][T] [C][V][Z][X]

[I] -> "in" | "ad" | "con" | "des" | "mal" | "pour" | "sous"

[E] -> "entre" | "re"

[T] -> [V][F]

[M] -> "l" | "ll" | "t" | "ss" | "n" | "m"

[U] -> "eur" | "ien" | "ant" | "esse" | "ent" | "able" | "oir" |
"eau" | "aire" | "erie" | "e" | "er" | "ir" | "ain" | "age" |
"ule" | "on" | "ade"

[C] -> "b" | "c" | "ch" | "d" | "f" | "g" | "j" | "l" | "m" | "n" |
"p" | "qu" | "r" | "s" | "t" | "v" | "s"[P] | [R]"r" | [L]"l"

[F] -> "c" | "f" | "gne" | "m" | "n" | "nt" | "p" | "r" | "sse" |
"t" | "s" | "l"

[Z] -> "c" | "f" | "gn" | "m" | "n" | "nt" | "p" | "r" | "t" | "s" | "l"

[A] -> "c" | "p" | "s" | "t"

[P] -> "p" | "t"

[Q] -> "b" | "d" | "g"

[L] -> "b" | "f" | "p" | "c"

[R] -> [P] | [Q] | "f"

[V] -> "a" | "e" | "i" | "o" | "u"

[D] -> "au" | "ai" | "oi" | "ou" | "ie" | "eau" | "oeu"

[X] -> "ee" | "e" | "ou" | "ie" | "eau" | "oi"

Thursday, September 15, 2005

Name Generators for NPCs to populate your RPG (or any other game)

This post will go over some name generation algorithms. As humans beings we can easily make up names - watch:

Bob, Orthur, Sonstig, Rachon

How can we make the computer do something similar?

1. A Really Big List


Open notepad, start typing names. At the very least we'll want two lists one for female names and one for male. (You may also be able to grab lists off the web. Baby naming sites seem to be abundant and full of oddness that would go well in most games York Hawkright)

When you create a NPC you check gender, choose the correct list then randomly choose an entry.

Advantages


  • Names will always be sensible (no "wwprojh" or offensive words)

  • No CPU cycles are spent on generation algorithms.


Disadvantages


  • Takes a lot of time and effort.
    • The more stratification* you want the more effort is required

  • The list is finite - as some point there will be repitition

  • Altering name distribution is tricky. (some names are slightly more common in region X for instance)



*stratification: Perhaps you'd like names associated by birth place. Indian people tend to have different names than Chinese people. You might also want to swap names by social standing, beggars have different names than lords. Occupational names may also want to seperated -pirates and ninjas. Knights and monks. Bad guys and good guys. Demons and Angels.

The big list approach has enough drawbacks for us to want something better. Not to say big list is redundant. It made be used with any other name generation technique.

2. Markov Chains


By using a markov chaining algorithm we recieve a data structure that can produce many different names. A markov chain is a record of patterns in a sequence of information. Here our sequence of information will be letters but it could be any sequence - dungeon tiles, musical notes etc.

A markov algorithm has two important parameters, the first is the data sequence. The second is it's "pattern memory" or "step size". This is best explained with an example.

Example 1. Stepsize = 1


The data sequence will be the following three words.

bag
bat
ate

Each word we'll feed into the algorithm ... and this is what will happen:

First Rule: b -> a b|ag

Letter b's can be followed by letter a's. Is what this says. This rule is recorded.

Second Rule: a -> g ba|g

Letter a's can be followed by letter g's. The final rule that doesn't need recording is letter g's are followed by nothing. This is default behaviour for all letters without rules. That leaves us with two production rules.

b -> a
a -> g

From these rules we can make new words. This is done by randomly choosing a starting rule. For instance we might choose rule two. We put down "a".

a

According to the production rule we know after a we can put a "g". This is our only choice so we put down g.

ag

G has no production rule so we should stop. This leaves us with the rather unsatisfactory word "ag".

What to do when we've finished but the words to short? Well we can pick another rule at random - the warning here is this greatly increases your chances or getting some rubbish words. So we have ag, let's say we but down "a" or "b" then follow the production rule. We might get

agag or agbag

So even at this early stage we have things that look like words!

Now to feed in the last two words. This leaves us with the following rules.

b -> a
b -> a
a -> g
a-> t
a -> t
t -> e

So some of the rules are duplicate, that means their more likely to get picked. (Programming this you'd probably give each rule a pick count rather than have multiple duplicate rules in your array. This also allows you to toggle whether or not you want probablities to effect picking.)

Using these rules we can produce things like: batag, bate, bagbat ...

Example 3. Stepsize = 2


So what's step size 2? Well the production rules produced will now look like the following:

ba -> g_
ba -> t_
at -> e_.

As you can see setsize two really suits words greater than three letters. How about "rope", "road" and "peon". The following rules would be produced.

ro -> ad
ro -> pe
pe -> on

From this we can get: ropeon. The more words fed in the greater the possible outputs. Let's add "adventure".

ro -> ad
ro -> pe
pe -> on
ad -> ve
ve -> tu
tu -> re

In this fasion a large database of rules can be built. You are best feeding in name-words rather than gardening terms, for instance.

Advantages


  • Easy to churn out new words from a name list.

  • The intensive phase of building the data structure is done once and need only be done once.


Disadvantages


  • It will tend to produce some obviously non-name words
    • Especially if it's comes to a end (g-> nothing) and then you force it to pick a random production and carry on.

  • It has to carefully set up by feeding in a "good" data set.

  • It's not easy to demand words of a certain size



Markov chains are a step in the right direction. Names will often be good enough. But can we do better?

Extension to the Markov Chain Algorithm


We force words to meet certain moulds. This ensures we always have words of a set size and logical composition. Each word we enter into the database we save the order of it's constant vowels. e.g.


nathiel -> CVCCVVC
derkor -> CVCCVC


Then we lock all generated names into the above patterns. This reduces the amount of non-name words.

3. Handbuilt Grammars


A grammar is a lot like a collection of the production rules we generated above but this time we type them out by hand! Seems a bit like a step-backwards but we'll get much higher quality names this way. First here's the bat, bag, ate grammar version of a the markov chain.


[a] -> a[t] | a[g]
[b] -> b[a]
[g] -> g
[t] -> t


The square brackets mean that this an element that needs to be reduced. The | (pipe) means "or". Seems to be pretty similar but we no longer have the probabilty stuff (this of course can be programmed in). Well hand writing the grammar give us a much finer degree of control. Let's imagine a grammar for last names.

[name] -> [C][V][C][ending]
[C] -> b | c | d | f | ... // A selection of the constants
[V] -> a | e | i | o | u
[ending] -> ith | on | ton | field | man

So we reduce [name] and from this are given some more symbols to reduce. Once we reduce everything we're left with a name. If we're given two or more "or" options in a production we pick one a random. This name genator will produce names such as:


Darman, Homon, Turith ...


These aren't bad names! So we'd probably want to create at the least a male and female grammar. We'd get a standard somewhat related set of names.

The fun doesn't stop with names for players of course - we can name stars, swords, monsters, cities, boats, ports, districts, houses, steeds, gods ...

If we write a grammar interpretter that will take in any type of grammar - then we can generate the actually grammar content randomly! :o

Advantages


  • Great degree of control and random generation combined

  • Names sounds natural and relatedness between names can be encouraged


Disadvantages


  • Handbuilt grammars are ... Yes! Created by hand. Therefore there's sometime investment

  • You may end building quite a few if you want names for different places, and monsters names... blah blah blah


And here is some extremely cheap lua code


--[[
Cheap Grammar
A attempt to make a grammar with out the hard parsing programming.
--]]
require("lualib.txt");
math.randomseed(os.time());

function C()
return Pick({"b","c","d","f","g","h","j","k","l","m","n","p","r","s","t","v","w","x","y","z"})
end

function V()
return Pick({"a","i","e","o","u"});
end

function Ending()
return Pick({"ith", "ton", "on", "field", "man"})
end

math.randomseed(os.time());
print(C() .. V() .. C() .. Ending());


Rogfield, Ravon ... Geton, Xanith, Kolman.

(Why does my random pick function alway pick R first? Something to look into)
lualib.txt is my library of useful lua functions. One of these functions is Pick. I'm considering writing something on this library but for now Pick is left as an excerise for the reader.


4. The End


There are three ways to add a variety of names to your game. You can chose to use one or use them all in concert. Have fun.

Some resources


I seem to have removed a load of my links - I'll come back to this and try and fill it up with a few useful bits

Wednesday, September 14, 2005

Busy

Tonight eikaiwa, tommorrow japanese lesson, friday enkai, saturday morning osaka, monday morning return.

It's going to be a while before I'm going to be able to work on EINFALL. I have handwritten some stuff on name generation. So I might get time to type that up thursday and post it. It's a general overview rather than code but still worth checking out I think. Useful for RPG games with randomly generated content or procedural content.

Tuesday, September 13, 2005

On going ...

This weekend I sat down and got quite a bit done. I didn't finish though - there's still a few bits and pieces that needed tidying up. My world generation stuff seems to work well and there's a little bit of threading in there two.

All thats left to do is write the generated maps to disk (this is dropping in a function call). That's it for this stage. It will need to be expanded on later - I'll want to give the worlds I create a name and cities, empires, caves, dungeons that kind of thing.


Also there's a really really cool image manipulation reseach site here. The techniques they show have loads of applications for game developments. I also wonder in the algorimth could be easily extend to 3D dimensions. Definitely check out the video it's excellent.

I could imagine using this to pick things up in old style ultima style 2D game. It would make the objects act more naturally and be pretty surreal.

Sunday, September 11, 2005

Generating Maps for AdventureRole Playing Game Fun

Today I want to finish patching my world generation code into my main "trunk" of my RPG's code. The word trunk is in quotes, as the only source management I use is copying and pasting.

This post (on the RPG Rogue-like development group)for interactions between game world objects - like opening doors, attacking characters and all that - seems to be an excellent idea.

Instead of having


NPC1.Attack(Monster2)


Which means that at some level NPC code must know about Monster code and this leads to a lack of clean seperation. Well instead you do the following:


Rules.Attack(NPC, Monster2)


This way only rules need know about all the game objects and the game objects themselves can be written in an extremely clear manner. It would probably mean that the objects would have to be a little more public as rules will need to request quite a bit of information.

(I always kinda of wish that you could have an oop language where privacy could be altered for each class like public{class1, ..., class n}: for instance.
C++ kind of has a crude version of this with the friend keyword. There's probably some reason it's not been done - maybe it's gets you into coding trouble ... still I'd like to play with it.)

I also now found myself wondering about generating the Rules internal code randomly using a preset-rule bag and lots of Lua :D but I think my RPG is quite ambitious enough.

The thread this post was plucked from is here but I didn't find the rest of it all the useful.

Another thread that caught eye was a list of special attacks for monsters. Though I think this type of thing could be better compiled from walkthroughs taken from places like gamefaqs.

Wednesday, September 07, 2005

The loveliness of houses.

Today has been a pretty bad development wise and in most other respects but hey it's finally coming to close. I made some very small nudges towards pushing my world generator in my main code. I'm at the bit where data files are being created and they need to be put in certain directories - which may need to be made - and what do we do if there's that looks like we have to overwrite
and ...
and ...
and ...

so it needs a lot of testing and stuff. It has lots potential breaking areas grahh. Aim is to have it all done by end of the weekend. This could be hard as I'm working Saturday.

Also I'm trying to decide what to do next year 2006 around July. If you're a very nice Game company and want me to work for you - please let me know :D I'm also looking at maybe taking a year in Bangalore on a tourist visa and working on my game. Even though I doubt it would ever generate a years worth of cash it's something that's important to me and something I want to make.

Tuesday, September 06, 2005

Today's RPG update: I'll beat you with my shoe.

What got accomplished today? Well I was polished off my Culture class - that's right a class for culture you ingrate.

There's also a class called theIdeasOfMan. I'm quite sure the contents of such classes are mysterious and that's the way it should be. OOP 101: Objects should be like a black box, black and mysterious - you want to open it but it's locked with a mysterious key in a mysterious hole.

The main things these interesting classes do - is ... allow the NPCs to be much more inventive with their insults to the characters. And that's all any one wants from a game. Currently it's a bit of nightmare but there's a definite plan to tie it down.

There's lots of Lua and lua code generated on the fly. It's all quite exciting but I'm not going to go into any detail until there's something to show. i.e. a screen of a man or woman, I'm nor sexist this 2005, insulting another character.

Onwards and upwards.