Tuesday, March 17, 2009

More C# woes....

The more I look into C# the more I wonder how it manages to run as fast as it does. Even the simplest things it appears to double up on code, put in random meaningless opcodes etc. For example a simpel series of load/store operators like below resolves itself into a reasonable ugly mess of asm...

   Vector.X = InVec.X;
Vector.Y = InVec.Y;
Vector.Z = InVec.Z;


The problem is that it simply can't track registers properly and that means it has to continually reload the base address of the object which ends up making the code twice the size.

It also insists on loading then storing floats even though its just transfering bits. You can obviously just use integer registers to transfer data and this could pipline much better than series of FPU load/stores. It's frustrating as if this was C++ I could just drop to ASM and do it myself, but in managed code your at the mercy of the JIT.

Now the JIT gets better each itteration but it doesn't appear to get better where it counts sometimes. For normal code, this simply doesn't matter, you lose around 5-10% speed max. But for code that needs to be highly optimal, this can be a real issue.

Sunday, March 15, 2009

C# and Ants

Since it's been a little while I thought I'd tell you what I've been up to lately at home and work. I've been playing with ANT4.0 which is a profiling tool for C# (and .NET in general). The last one was pretty good but had some issues, while the new one is excellent. Profilers can always get better but the leap from the last version is pretty huge. For a start profiling is almost realtime which is very impressive, normally apps crawl when they're being profiled. You can also play with results while the application is running, which is damn impressive!

I bought ANTS3.0 last year and its pretty expensive but I thought that since I do lots of C# at home I would get the use out of it... trouble is, the stuff I do at home simply doesn't need profiled! Not that V4.0 is here I dont really want to spend huge sums of cash on it again, bnut its such a nice app I'm a little torn... Oh well.

Anyway, I've been profiling some of my work and doing some optimisation at home. It's actually been years since I've done any serious optimising and I'm having a bit of fun with it. C# is pretty cool in that you can do real managed code, or unsafe C++ style code if you really want to. When you're optimising you tend to fall back to unmanaged code as its still quicker.

We've also been getting some little shocks at work as some of the C# collections just aren't as quick or optimal as we were expecting, this has meant we've been starting to write our own set just to make sure its doing what we think it should be doing. Games programmers are funny like that, we hate slow code and will happily sacrifce readability for speed (within reason of course). Anyhooo.. I'm having a blast playing with peep-hole optimising, although its hard to say how this will affect the app overall just now, but I'm pretty happy with the main loop now as its very tight.

It reminds me that optimising is great fun, and thats why I got into games in the first place!!

Monday, February 09, 2009

SubVersion.

I've been trying to set this up again, but this time using Apache (since I have that installed anyway!). I've almost got it going, but for some reason apache can't see the repository. Its there, and the DOS commands can access it, but apache can't - must be something simple. Anyway, the reason behind this is because Russ has set it up on his machine and we reckon we can get it to share repositories so that I have a full copy of the history etc. Anyways, once I have it running Russ can start to help with the editor and the debugger and add features for the spectrum as he needs to. Once its running that is....

I've also finally gotten C# to give me the cursor keys! It's a bit of a hack to do it, but I finally managed to get a key up/down for them. This means I should be able to do cursor key movement in RetroEdit so you don't have to use the mouse. I didn't think this was important until I tried to use it on my laptop which only has those stupid PADs, it then became obvious that cursor key movement would be great! So I've spent a couple of hours trying to get C# to actually deliver cursor key inputs, and man was it yucky.... Still all done now, so I can now do the work to move around with them tonight.

Edit: Test....

Saturday, February 07, 2009

Tick tock....

Been a little bit since I did an update, so here goes. I've been busy playing games (of all things) so haven't done as much as I should have, but I am still making slow progress on RetroEdit. I picked an older game called The Witchers, a very pretty RPG. Now I'm not a huge RPG fan, but I do love games like Diablo which have small amounts of RPG goodness in them, and this is in a similar vain, so I've been having great fun with it. Theres a little too much running around, but it's pretty good fun all the same.

Anyway... I've added inserting, deleting and cloning of frames which means we are almost at a usable state, but before I get to use it I still need to add colour picking and project loading and saving. I've decided to use the good old IFF to store all my data as it means I can add new features without losing too much data if I ever need to upgrade. So I'm writing (another) IFF file processor that lets me load/save IFF files easily, and putting it in the RetroBitmap control which allows others access to it if they like.

Once I have these 4 things added (and it all going well it shouldn't take too long), I'll try and get Luca to test it - although he's been in hiding reciently, but if he resurfaces he can take it for a spin and we can get on with some real features instead of the core editing stuff.

I did start looking at Onion Skining, and its a little more complex than I wanted as the retro bitmap control would need multiple sets of data to render it itself. This means I need to add a fairly large command that can render any format the control can and then return the image for Onion Skining. It's a little bit of a fudge, but oh well...

Wednesday, January 28, 2009

RetroEdit small steps.

I've had a little bit of a problem with a virus I think, but have managed to revert things by rolling back a few days. This however has screwed with my source files - even though it said it wouldn't. Oh well...

I've finally managed to get the colour palette into retro edit so I'll need to do colour selection next. It's a little flickery though but I'll deal with that later, as long as it's working just now I don't really care. It's feeling a little sluggish on my machine so I may be doing something wrong, but I'll need to try it on someone elses PC first. I have the feeling its drawing WAY too often. I'm happy to say though that its finally making some headway and I hope to deposit the first version into Luca's lap soon. I'll need to get loading/saving into it first so I'll do that after colour picking/selection has been added.

You'll also notice its missing sprite sizes, I'll add this later as well - it shouldn't be too hard - although I'll need to save differently for each platform. Currently these are Plus4 (MCM/Hires) C64 (MCM/Hires) and Spectrum. I'll probably add CPC down the line - along with anyother computer/console I play with.

Small Basic.

For those who don't know, Microsoft development labs has released a new language called Small Basic. This is aimed squarely at the beginner. Do you remember how you started to program? Well, if your an old git like me it would have been on and old 8bit machine like the zx81, spectrum, Vic20 or Commodore 64 (or some other old 8-bit thing). The reason these machines were so cool to program with is that they were just so simple. Switch on and start. Basic was built right in and anyone could start and learn it.

Well, a chap at Microsoft called Vijaye Raji has started a personal little project that one day he hopes will be included with windows - like QBasic was with DOS. This is an amazingly good idea, and one I had quite a while back as well (see here), but typically never got very far with. He however is getting on pretty well and has now released a really nice little development environment that while a little buggy, is looking very cool indeed.

Theres an interviewwith him on Microsofts channel 9 which is well worth watching. This is something I'll be keeping an eye on and might even write a little something for in the future. Its very cool.

Sunday, January 25, 2009

Home again....

After my trip down to Warrington where I was able to take a side trip to Birmingham and get to the Commodore Computer Club meet it's good to be back home. I've decided an hour and a half is about as much as Im prepared to drive for a meet, and more and its a bit of a killer. This kinda rules out any others unless I happen to be in the area (like this time), or its particually large and I'm willing to stay for a couple of days; I'm getting too old for this shit... It was nice to be able to meet folk I'd been speaking to though, and gettting some faces to go with the names is great.

It's also the first time I've used my new iPhone for mobile web, and the map applications are fab. Asking for directions, or distances from where you are is a great thing to have on you. Safari was a little slow under 3G, but it worked and help pass the time at motorway service stations. However the battery life isn't wonderful so I kept feeling like I needed to switch it off. I'll need to see if I can find the PSU for it as being able to plug it into a wall to charge would have helped - if I'd but thought that far ahead....

I hope to do a little retro edit tonight, but I'm pretty pooped after the drive up, so lets wait and see....

Sunday, January 18, 2009

RetroEdit to-do list

So, heres my current to-do list. I'll update THIS blog entry as I change things, so you can always check back here to see where I am. I'll add a link on the right for easy access.

  • Paint with colour 1 (left mouse)
  • Paint with colour 2 (right mouse)
  • +/- to change frames
  • rotate frame (up,down,left,right)
  • rotate line
  • rotate column
  • Colour selection
  • Colour Changing
  • Cursor rendering
  • Cursor key movement or cursor
  • Copy frame
  • Insert frame
  • Delete frame
  • Colour Swap
  • Area selection
  • Copy
  • Paste
  • Brush paste (like a sprite, drops out the background colour)
  • Mirror
  • Flip
  • Save project
  • Save data (native format)
  • Load Project
  • Load data (native format)
  • Onion skinning
  • undo/redo

    Remember to check back here to see how I'm getting on.
  • Saturday, January 17, 2009

    RetroEdit.

    I've not been doing much past few days/weeks. With the flu over Christmas and now a cold I've not really been in the mood. However, I've decided to make an effort and have started back on RetroEdit.

    I've finished the refactoring of it an am now happy with its layout and internal code construction. Basically, the old control I was writing delt with retro graphics in an abstracted way, and so you had to do some work to use it, now however the control deals directly with the raw format which means all you need to do is copy actual retro graphics data into the control and your all set.

    So with this done, I've started to plow ahead with some features. Actual editing is obviously first, and I can now draw pixels with the mouse in both hires and multi colour modes. This is also true for C64 and spectrum editing. I've also put in sprite rotate left and right, and am about to do up/down.

    Once I've done this I'll add colour picking. Currently I have 2 default colours and you can't change them - this obviously has to change to be of any use, and as its a biggie, I'll do that next.

    I'm sure I listed these before, but it must have been ages ago so here it is again; the feature list I want in for version 1.


  • Paint with colour 1 (left mouse)
  • Paint with colour 2 (right mouse)
  • +/- to change frames
  • rotate frame (up,down,left,right)
  • rotate line
  • rotate column
  • Colour selection,
  • Colour Changing,
  • Copy frame
  • Insert frame
  • delete frame
  • Colour Swap
  • Copy
  • Paste (+background)
  • Brush paste (like a sprite)
  • Mirror (+around selection only)
  • Flip (+around selection only)
  • Save project
  • Save data (native format)
  • Load Project
  • Load data (native format)

    If theres anything else that you think is a must have, then let me know. I've no idea how long this will take me, but the sooner the better. Currently it lets you edit Plus4, C64 and Spectrum sprites although I still have to put real support for the C64 sprites.
  • Wednesday, January 14, 2009

    Powering up.....

    Because I was ill over Christmas, it's actually been a while since I did any real work at home. So I thought I'd make an effort to get over this and actually DO something!

    To this end I've resumed the refactoring of RetroEdit and decided to get editing actually working and usable. So now that I think I've actually finished the refactor I was wanting, I've started to write the editing features. I've currently got hires sprites being editing, so I'm about to try MultiColour Mode ones. I'll then do some basic features like scrolling the whole thing around the window, flip etc. then move onto colour editing.

    I need to get the selected machine's palette drawn so I can pick colours and then I need to tackle saving. I'll need a PROJECT save, and a binary save. I'll also need to allow plugins so that folk like Russell can save formats he wants to deal with; although he may well end up doing his own editor, but others might need it so...

    With a bit of luck, most of these shouldn't take very long, and I can take the core of the sprite editing and move it to the character editing tab. The core concept of this is a special RetroBitmap control. This allows you to deal with retro graphics directly without having to write huge chunks of code over and over - its also a standard control so others could use it in their own projects if they wanted to.