Saturday, September 30, 2006

The reasons behind guinea pigs

Still going through the little schemer, one of my programs called for the "to the power of" operator. I couldn't find scheme's definition, so I wrote my own! Yay me.


(define ^
(lambda (x y)
(cond
((zero? y) 1)
(else
(* x (^ x (sub1 y)))))))


Today I'm going to polish off another chapter in the scheme book and hopefully two in the C++ book. Last night I added the FPS counter to the second version of tilemap. I have one or two small todo's today on it too.

On Friday I had an intro lecture to the Computer Game Programming course. There where some interesting figures for where the worlds best selling games are made (this was on slides no source was given)


15% UK
36% Japan
44% USA
therest% other places


I was suprised the UK was so high, and that all the grand theft autos where british made (same for laura croft, broken sword and a host of others I embarrasingly didn't know :) though some I suspected :D ) Interestingly Serious Sam was made in Croatia.

Then we saw the final year projects. They were impressive, one demonstrated fluids in real time, another was soft body modelling.

Soft body modelling is making your normal "hard" polygon model a bit softer and more natural. We can press our skin and it gives a litte, same for clothes, this isn't the case in games where if two models meet they cannot press on each other. Rather we might see some rather ugly polygon clipping problems, or they'd just rebound like they're made from an euclidian solid. The demo showed a 3D worm (from the Worms 3D game by Team 17) and when items interacted with him, his skin would wobble, a cool cartoony effect. The project allowed this kind of soft bodyness to be applied to any model it could load. I think the guy who made it was given a little help from Team 17 but still it was very impressive.

There was another one that animated cloth and another project that added fur dynamically and then rendered it in real time in DirectX. That was good too. The were a host of options for altering the fur parameters, colour, shell number, length etc.

The course is focused extremely hard on the graphics side of game development. I don't believe we'll even briefly cover a definition of a game or what might make one game fun and another crap. That's ok with me though :)

We closed having a look at the Wii and PS3 marketing strategies (I guess) where the PS3 is saying "look we have all this super raw power" - there was a demo of a guy holding two coloured beakers. The Ps3 was hooked up to a camera and it rendered two glasses where the beakers where. He was then able to interact with a bath tub - including pouring water from one beaker to another. The wii was more emphasizing - "our console is going to be fun", it's going to be something you'll play with your friends and many people will enjoy. Then we saw some adverts for the wii.

There's was also a chart showing which companies graduates went to places like Rare, Team17, Lionhead and others.

Looks like it's going to be a lot of hardwork.

EDIT: Did a nice chunk of work on Einfall tonight. Simplified a function or two that was doing too much stuff like:


MasterFunction()
{
MethodB();
}

MethodB()
{
// A load of stuff
MethodA();
// More stuff
}


Converted to


MasterFunction()
{
MethodB();
MethodA();
}

Removed MethodA from MethodB


Something I probably should have seen before. Also extracting some if-boolean statements to seperate functions for clarity. It means it's much easier to read now.

EDIT2: Added the tile part of the map so now I can add some tiles and see if it works - which it pretty much does yay! I set the world origin to the top corner of the window but it seems to be ignoring this for some reason. Otherwise, everything is looking pretty good. Next up is preparing the classes so I can slot them into Einfall without a massive headache :D

Thursday, September 28, 2006

atm confidential dances

Working my way through Accelerated C++. This book is great! It teaches C++ not C in a C++ compiler with some classes thrown in, like so many other books seem to do.

Started a new subversion repository where I'm creating a final version of my tight map, which will be fast (like the old version) and handle such things as users logging out and in without crashing (unlike the old version).

EDIT: More accelerated C++, seems tightmap version 1 is quite modular so I won't have to redo any of the code just the windows wrappers stuff (I'll probably tinker anyway :>), I had some confusion resolved.

Tuesday, September 26, 2006

Dank Cat Paw

We're expected to make a game by Christmas and to be extremely proficent in C++ by Christmas. It sounds fun.

My C++ is rusty to the point of collapse. So I'm going to work through one or two of the C books I brought along. Then I'll find what are a few good reference books for C++ and order them.

As for my simple tile rendering stuff - it now persists even if you log out and then log back in. And through screen savers and everything else. I want to talk about how to accomplish this but not quite yet :D

I want any articles I write to be in some kind of document source code and then the ones uploaded here are "compiled" to html. So I'm looking into docbook, but it looks very hard to set up. So maybe I'll see what I can do with a few latex plugins.

Sunday, September 24, 2006

In Hull

And tomorrow lectures start. A year of game programming goodness.

Today I've added some small bits of code to reset the vertexbuffers when the device is reset in the RenderPrimitives dll. Also polished off another chapter of the little schemer.

Thursday, September 21, 2006

Living in a refurbished slaughter house

Back to poking at my .Net code this morning. Seeing as I'm on a new computer I'm also going to see if blogger will allow me to upload photos, in the past it's always been quite fussy. I think that it's because I had firefox force any pop-up to load in a background tab. Well looks like it's working now!

Anyway I thought I'd talk a little about DirectX devices and forms. This relates to creating directx fullscreen apps as well.

When you create your device you create a PresentParameters object and this takes in two important variables; the height and width of your display area. If you have a form you might think - oh this is just form1.Width and form1.Height but you'd be wrong! That's the entire height of the form, including the blue bar with the maximize, minimize and close buttons, and the little grey border. If you use these values it will most likely throw some of your calculations off.

One way round this is to put a panel in the form and then use panel1.Height, panel1.Width and this will work fine because the panel has no border stuff. Unfortunately it will fail horribly if you try to do fullscreen. To do fullscreen the component you use must be a form.

So what's the best way to get the width and height? Well it's not to hard-code them, like I seem to have done on my project :D Rather it's to get them from form1.DisplayRectangle. This gives the area you can draw in and doesn't include any of the form fluff, like grey outlines and drop menu strips!

So there you go.



Also looks as if blogger's actually going to show one of my images. This test image just shows how I use firefox and rss. If in firefox you add a bookmark and put it in the "Bookmarks Toolbar Folder", it will appear as a button on a strip just above the window your currently browsing. Then you can press it and it'll take you to the relevant page. Great. If you add a bookmark to an RSS feed in the folder, a button will once again appear on the strip. But this time when you press it, it will form a drop down menu listing all the newest items in that feed (you can do that with this webapge by the way :D You'd get a list of all my latest posts with their rather cryptic titles :) . Even greater. Of course, if you keep doing this, that strip's going to get quite full! So you might want to add a folder within the "Bookmarks Toolbar Folder", this folder will also be represented as a button on the strip.

Click the folder and it will create a drop down of all the links you've put in there. I like to have folder just of RSS feeds. Then I can run my mouse down them and see if there's anything new on the webpages I'm interested in.

If you've read this and you're thinking, "I don't know what RSS feeds are :(", well, well done for reading it all :D RSS feeds are some XML files hosted on the webpage you're interested in and each time the page is updated, the xml's updated too. Then your computer periodically (every few minutes or so) queries this xml file and updates it's local listing of that particular pages updates. So rather than you manually checking for updates the updates are brought to you.

(Well the image seems to work quite nicely. The webpage shown is an online stockmarket electronic broker thing, because recently I've become a little interested in the stockmarket, after reading the, to be honest, rather crappy book, Rich Dad Poor Dad. Expect more images from now on!)


EDIT: I think I've the found artifact problem, it seems to be due to the ratio between directx space and pixel size of the display area and textures.

EDIT: I can't believe I was back again today battling with artifacts when rendering tiles GAH!! Anyway for what's it's worth it's fixed now. I made a new library with fixed spelling called Einfall.RenderPrimitives. Where I made one small change. But I think one of the main sources of artifacts occurs if your form.DisplayRectangle doesn't equal your othographic projection width and length. Currently I'm scrolling smoothly with batched unartifact tiles. So that's nice. I guess the worse thing was this worked fine before on my laptop :O I'm somewhat confident now it will work nicely on all systems. So now all I need do is rewrite my tight map project (which is basically a small tiled engine that uses batching, animation and layers.) and the artifacts should dissapear.

Then once that's working nicely I'll have to merge it into Einfall which I guess will be a never ending serious of headaches. And then, then, I'll have einfall create buildings that actually have walls! Currently the buildings are merely flat outlines.

Final Edit: Quick bit of tinkering and tight map is now compiling as expected.

Wednesday, September 20, 2006

Additional Scheming

Up to chapter 4 in the little schemer now. It's interesting to see that most loops are actually done by using recursion ... and it reminds me of another programming language I was taught in University, probably prolog.

I'm not finding the book too hard going and can work out most of the answers to the questions. But I never seem to get the brackets right (as Jani pointed out this is the intially scary thing about lisps) I'm always doing (cons (atom) (atoms)) where it should be (cons atom (atoms)). (>_<) I don't know any of the debugging stuff yet either.



(define spanner
(lambda (lst)
(cond
((null? lst) (quote()))
(else
(cons 'spanner
(spanner (cdr lst)))))))



Here is my amazing second entirely homemade function that takes a list and replaces every atom in it with the word (unitialized variable) "spanner". Yay me.

On an unrelated note
This article on stackless python
is quite interesting, the comments are good too.

I've also spent way too much time messing about on a Linux box - it's Ubuntu, easily the most friendly distribution, but I've never ever had an install where I didn't need to compile some C code to get some critical piece of hardware working, if I do ever get it working, that is. It seems unlikely even with the advent of DRM-happy-Vista that Linux is going to widely used on peoples desktops in the near future. I guess if you do happen to have the perfect mix of hardware though Ubuntu is an extremely attractive desktop alternative. Of course there are no games :(

Tuesday, September 19, 2006

Scheme scheme scheme

Here's my first scheme (that I've written off my own back rather than copying from the text book) function it's very very simple. If you pass in a true value it returns hello, if you pass in a false value is return goodbye. Goodbye and hello aren't strings they're more like unitialized variables.

Anyway behold:


(define test?
(lambda (a)
(cond
((eq? a #t) 'hello)
(else 'goodbye))))


Yesterday I played with the map editor program a bit more. I'm having trouble transforming the device for my various swap chains so that's something I need to play with. (this looks like a reasonable place to start) I also added a moving camera to my tile renderer to make sure there are no artifacts. It works fine. So I documented my simple rendering stuff - the RenderPrimitives library that handles batching. Time to find another suspect for the artifacts.

Monday, September 18, 2006

Removing the close box from a c# form

I have a child of a MDI container and I don't want the user to be able to close it, or maximize, or minimize it. But I do want the user to be able to resize it and drag it around and will. So I want to get rid of the close, minimize and maximize buttons but retain the blue strip.

If you write some code like so:


this.ControlBox = false;
this.MaximizeBox = false;
this.MinimizeBox = false;


Where "this" is some form, you may find yourself with a control lacking a blue strip to move the form around! The solution to this problem is to enter some text in the text field.


this.Text = "My useful form";
this.ControlBox = false;
this.MaximizeBox = false;
this.MinimizeBox = false;


And that seems to be how it's done. Of course there are other ways override the message handler or using PInvoke (yes I tried Google before working this out for myself) but you really don't need to.

Sunday, September 17, 2006

Chasing down bugs.

I'm still having issues with some of my program that display maps missing a pixel or two on each tile - this only happened since I've switched the programs to my desktop machine rather than my portable. Also it doesn't happen with all my programs - suggesting, the somewhere, in certain programs, I'm doing something stupid. So I'm hunting that down.

I just built a very simple program that demonstrates the batcher and I don't lose any tile edges in this case ... so it must be somewhere else. The search continues.

I'm also rather slowly teaching myself Scheme in Emacs because I must have a deep repressed masochism. I'm using the Little Schemer book. So far so good. I'm just running an interpretter through Emacs at the moment. It does syntax highlighting, indentation and bracket matching - everytime I press one bracket, the matching one appears. After reading The Pragmatic Coder, I really felt like I should put in the effort to try and master Emacs. (I still can't imagine it ever matching VS.net productivity but I like the core structure of customisation and extensibility.)

Also I have somewhere to live in Hull, which will be useful as I'm starting University there next week. It use to be a slaughter house, and there are still hooks in a large wooden beam in the downstairs front room! Cosy.

Tuesday, September 12, 2006

Scheme, Petite, Emacs and the error message; spawning child process invalid argument

This errors been giving me a headache for a while but I've now found the solution!

So I've Gnu Emacs 21.3.1 running on windows and I'm interested in learning scheme. I went into the Control Panel > System > Environmental Variables and edited the PATH variable to include petite. So if I typed petite in a command prompt - up would come the interpretter - great! Or so I thought.

Next I wanted to have it runnable from Emacs, running as a child process so I can compile my code as I type it.


(custom-set-variables '(scheme-program-name "petite"))


Emacs is already preset up for such tinkery so all I need do, is tell it what my scheme program is called. This is where it all went wrong. I could tell emacs to run a shell command, type petite, and it would run it, but tell it to M-x run-scheme, and it failed with the error "spawning child process invalid argument" or a "could not find petite message" depending on if I located gave the full path to petite or just the file name and hoping the windows "path" variable would sort it out.

So various head bangings later and it turns out that emacs doesn't like the quotation marks that I put around the path in the Windows PATH variable. So remember don't to this:


PATH="path1";"path2"


do this

PATH=path1;path2

Monday, September 11, 2006

Ebichu

So I'm still hacking away at the old map editor, DirectX is now playing nicely with windows forms. In fact this is such a useful thing to do that I may as well explain how (briefly).

Using DirectX, C#, Windows Forms, to create a non-flickering interactive form application that also has a render loop for DirectX.



Now there's a smooth, smooth title.



using System;


using System.Collections.Generic;


using System.Text;


using System.Windows.Forms;


using System.Runtime.InteropServices;


 


namespace MapEditor


{


    [StructLayout(LayoutKind.Sequential)]


    public struct Message


    {


        public IntPtr hWnd;


        public Int32 msg;


        public IntPtr wParam;


        public IntPtr lParam;


        public uint time;


        public System.Drawing.Point p;


    }


 


    delegate void LoopHandler();


 


    /// <summary>


    /// Sets up a render loop so DirectX bits are updated as often as possible.


    /// </summary>


    class RenderLoop


    {


        [System.Security.SuppressUnmanagedCodeSecurity]


        [DllImport("User32.dll", CharSet = CharSet.Auto)]


        public static extern bool PeekMessage(


            out Message msg,


            IntPtr hWnd,


            uint messageFilterMin,


            uint messageFilterMax,


            uint flags);


 


        public event LoopHandler Loop;


 


        private bool AppStillIdle


        {


            get


            {


                Message msg;


                return !PeekMessage(out msg,


                                    IntPtr.Zero,


                                    0, 0, 0);


            }


        }


 


        public RenderLoop(LoopHandler loopHandler)


        {


            Loop += loopHandler;


            Application.Idle += new EventHandler(OnApplicationIdle);


        }


 


        private void OnApplicationIdle(object sender, EventArgs e)


        {


            while (AppStillIdle)


            {


                Loop();


            }


        }


    }


 


 


}





Ok, so this is a slightly modified version of my render loop. The thing to notice is there's an event called Loop, this is where you want to attach a function that'll handle your DirectX rendering. Loop's called as often as possible, while the application's free. Yes, I know for a map editor I really should try and save cycles because it should play friendly with other programs but it's far easier doing this way. ( I haven't tested it after making modifications but I'm pretty sure it should work :D)

Anyway, we've got this wonderful looping class let's see how we'd use it in an application.



/// <summary>


/// The main entry point for the application.


/// </summary>


[STAThread]


static void Main()


{


    Application.EnableVisualStyles();


    Application.SetCompatibleTextRenderingDefault(false);


 


 


    Form form1 = new Form();


 


 


    RenderLoop renderLoop = new RenderLoop(delegate()


    {


        form1.Render();


    });


    Application.Run(form1);


}




So we create a new form and that form has a render method. This is where DirectX does it's stuff. DirectX might be updating a panel or something, or maybe you want rotating 3D cubes on your buttons - whatever, this is where that code goes.

We hook the form's Render method up the RenderLoop's Loop event. So the game loop now will call form1.Render each iteration. This is often called loose coupling, it's cool because I can use the class RenderLoop again and again in different projects, in different ways.

I hooked the loop to the Render method using an anonymous delegate. If you program C# and don't know what this is - learn it! Right now! Go! Here I use one so I can make use of the form1 variable, instead of having to make it static. I'll finish with an example render loop. *warning this is far more complicated than it has to be because it's ripped straight from my code and it's using swap chains)



internal void Render()


{


    if (swapChain.Device == null)


    {


        return;


    }


 


    Device device = swapChain.Device;


 


    device.SetRenderTarget(0, renderTarget);


    device.Clear(ClearFlags.Target, Color.Aquamarine, 0.0f, 1);


    device.BeginScene();


    device.EndScene();


    swapChain.Present(this);


}




Wow an actual post with some substance, it's been a while. Using the above code you could have a windows form which is partly directX. For instance a panel might show a £D model and by the panel are a number of buttons that make the model play various animations. This stuff is very useful for writing test programs and editors, or borrowing the Windows GUI if you don't fancy rolling your own.

Happy hacking.

Sunday, September 10, 2006

Harvard concludes - you suck.

Currently I have a copious free time, which I spend playing Dwarf fortress and reading books in the garden. Yesterday or the day before I helped out a friend at his work by doing a little flash programming for a very well known multinational company, so that was fun (and made me feel very big and important :) ) though I've never used flash before, and generally hate it on webpages. (Flashblock it was one of the main reasons I use Firefox :D )

But today I've been fooling around with a map editor. (I'm currently not playing with Einfall so much because I need to install a paint program that can handle png alpha channels, this would take all of two minutes, but reading and gardens often seem to get in the way) Yes map editor, a long time ago, some one commented that they were anxiously waiting for another tutorial that would cover map editors. I confess at this point I have no intention of writing a tutorial. My program is very basic at the moment, a MDI parent window. MDI stands for multi-document interface, I think, basically what you'd be using if you used Photoshop - a window for a each picture you opened.

The clever thing is my child windows are Direct X enabled. Using swap chains. I'm thinking about a tile palette but haven't quite decided anything yet, apart from it will be resizable and always arrange the tiles nicely :D

Wednesday, September 06, 2006

maybe you have to be English to know how wounding those eyebrows and coughs can be

Some my graphics stuff that worked on my portable didn't work when transferred over to the desktop. After having a bit of look it seems the problem was that I wasn't storing some of my textures in powers of 2.

Friday, September 01, 2006

The Norske Mustachclub

I've been puttering around in my resource code. It's quite nice to come back to after a break, as it's much easier to see dubious design decisions. My resource manager works around a very shallow inheritence tree, basically there are few types of bank, that manage the resources loaded into the game. All the banks are generic so they can hold any type of resource.

The situation arises where you might ask the bank for a resource and it doesn't have it . For some reason only one of the banks deals with this situation in a decent manner. It calls an event, where the user of the bank would write a call handling the event and probably loading the missing resource from disk. There's no reason why all the banks shouldn't have this event so I'm in the process of moving it now and fixing things according to the unit tests.

I'm trying to make my more mature code more solid, documented and polished.