Thursday, July 26, 2012

XNA4.0 – 01 – Intro

Hey, working on my time management, last day before of packing and stuff, tomorrow I am leaving on holiday, not done packing, so obviously I must find time to push out an XNA intro post. Obviously!

From now on I'll be coding in C# and will be relying on XNA (and hopefully a lot of GPU hardware based processing to compensate for the relative slowness of C# whenever possible). Of course I won't be able to just pick up the project where I left of and cut out some of the dwarf related stuff, I need to port over tons of code from C++ with Irrlicht to C# with XNA. Now while Irrlicht has quite a few problems and I have developed a personal grudge against it, that won't stop me from giving praise where praise is due: Irrlicht really does not shit around making you write glue code, lengthy resource and window setup procedures or anything. After a short setup sequence (that you may wish to rewrite and encapsulate in a more reusable component that you can use from project to project), you are free to get down and dirty immediately. And as far as I can tell, XNA maintains this "sit down and code" "no hassle" setup. DirectX, even with DXUT needs a lot of glue code to reduce the hassle. This was the primary reason I couldn't hammer out a to the point base from where to present the real shaders and code I wanted. 

So while I am porting my code, I need to find time and present XNA a little for the initiated. You will need a few tools before you get started, but luckily these tools are free. First you will need Visual C# 2010 Express | Microsoft Visual Studio. The free version is not quite as feature rich as the commercial one, but unless you are a pro familiar with the full experience, you won't miss these features. Then you need Microsoft XNA Game Studio 4.0. This will install the required XNA support in Visual C# Express. There is also a Game Studio 4.0 Refresh. I don't know what this one is about and I think that it is meant to bring XNA to Windows phones. I won't be using that one for now so don't grab it. I have nothing against Windows phones and making your games more portable is always a plus, but Windows phone has like a 2% market share. Until they don't reach at least 15% I will pretentiously disregard their effort as "cute".

So after both tools (and a lot of prerequired packages which hopefully these setups have taken care of for you), you can launch Visual Studio (that's what I'll be calling C# Express from now on, VS for short) and create a new project. You should be greeted by the following dialog (with more options available if you installed more languages than C#):

You can click on the "XNA Game Studio 4.0" sub category so you can find what you are looking for more easily:

Here you will select "Windows Game" as a project type (don't worry, I'm sure the Mono guys are hard at work porting Mono over to Linux so you can run your game there once Linux gets proper and rock-solid hardware support for your GPU (and resurrected female clone Hitler saves us from the flying shark attack apocalypse using a fire hose, duck tape an a a few million hamsters interested in philosophy) lisp).

I renamed the "Game1" class to "Game" (VS will prompt you if you want to replace all references, click "yes") and after you can run the project and almost instantly the game window should appear. Alternatively, if you are running on a very old or budget integrated GPU, you might be greeted by this window:

XNA has two profiles to tackle the challenge of a very diverse landscape of PCs out there and let me tell you: two is not enough! It is very easy to wind up in between the two. If this is the case, you need to go to project options:

The two profiles are HiDef and Reach. HiDef is default and if your machine can't handle that, you can switch to Reach:

In case you are curious, here is the breakdown of the differences between the two profiles, using a link that will surely never go away. Translating that into things you might care about, using Reach you are stuck with pixel shader 2.0, which means no pretty shadow mapping (basic one should work fine), just a few lights, no multiple lights normal/parallax mapping (you may be able to cheat this with leeloo multipass) and a few more main limitations, like 16 bit index buffers and no multiple render targets. And combining multiple techniques that work fine on their own with PS2.0 becomes a lot harder.

And finally, here we see the game window:

Glorious, just glorious!

Tuesday, July 24, 2012

Status update

Well, it's that time of the year when I do my status update! (a pun upon how often I post these days). I did not post in a while because I did not know what I really wanted to do and wanted to avoid giving inaccurate information yet again.

But anyway, long story short: my life has changed a lot and the activities I take part in, the free time I have and the way I spend it are quite different from how things were a little over half a year ago. Things have gotten to the point where I am no longer even a hobby programmer, which I find quite shameful. There are things I love about my new lifestyle and things I hate. It is quite unrealistic to expect to love everything and be perfectly happy of course, but the positives outweigh the negatives by a large margin.

Except for the programming part. I want to program again crazy and stupid stuff. And I want to write about it! This weekend I am leaving on holiday (to Greece!) and I am spending over a week there, but once I get back I want and need to get back to programming. It will take quite a while to get used to doing it again because I need to find space for it in my new lifestyle, so I'll start slow, doing some small things in weekends and try to post once a week. Hopefully I can get back to my usual 8-12 posts a month in no time! Fingers crossed!

So what will I be doing after I return? Well, the first step is going to be to return all donations over €10. I don't know exactly how one can do that, so I'll try and use the e-mail address that Paypal reports as the source of the donation and hopefully it will work. Smaller donations generally I won't be returning, especially not the ones under €2 because conversion taxes, transaction taxes and Paypal taxes make this a very inefficient process, with a lot of money wasted in the system. Notice I used bold on "generally", meaning that if you donated a small sum and want it back, hit me up with a mail and I will naturally return it. I just don't want to do that for every €1-€3 donation. So I apologize if you lost a few Euros here. As said, if you are offended, e-mail me and I'll prioritize your transaction, otherwise they will be returned in decreasing order of their sum.

So why am I returning the donations? While I do want to get back to full time hobby programming, that's it! Just a fun hobby. I don't want deadlines, pressure or to have to do anything I am not excited about. Or creating a product! So Dwarves & Holes is officially dead. A lot of the ideas, design and code will survive, but the project as a Dwarf Fortress inspired 2D/3D game with squad based city building is dead. What I will be doing will be more similar to the last videos I made, but not the ones where I am only showing a stool.

So let me give a few reasons while Dwarves & Holes is dead, even if I will be spending the same amount of time or hopefully even more on other things:
  • It is too much work. I was prepared for 2-3 years of development before I get something half-decent feature wise. My final ambitions, especially on the 3D side inflated all projections to 7-10 years for one single man. This wouldn't be a problem if I really really really wanted to create a new Dwarf Fortress, but to be honest I am more excited about other ideas. Especially since:
  • I never wanted to make a Dwarf Fortress like game. I wanted to make Dwarf Fortress. I realize that now. I couldn't care less about cloning or whatever. I just wanted a more pleasant and visually engaging Dwarf Fortress. Because of the public outcry over this I switched over to designing my own game and my productivity dropped like a rock. And it opened Pandora's box. With me no longer focusing on a clear design, I started experimenting and found things that interest me more.
  • By the time I would have finished anything meaningful A Game of Dwarves 3 would have been released (if the formula proved to be successful). There is no way I can keep up with even 1/10th of the pace a full company with talent and a budget can have.
  • Writing a modern 3D engine is near impossible. Modern techniques are hard to implement and you barely find any information on them because they are trade secrets. And on older techniques you barely find any information because this is how the Internet works and old links die. I am pretty sure that given a team of 5 people and infinite budget, It would take us over two years of mostly experimenting and optimizing to create a modern engine and it would still be behind. Engines are extremely long living and iterative beasts. You iterate and iterate upon it, year by year, adding features, stability and performance. You can't just spit out an engine, even with all the talent and money in the world. So I need to cut down on my ambition to a very reasonable and realistic level, something that can be truly be made by one man.
  • And probably number one: I worked so much on it and still I don't have anything to show. I feel the need to distance myself from this personal failure and start anew with a new set of principles.

With this out of the way, let me go over a few principles for whatever I will be doing in the future:
  • Working without obtaining anything of value (except for knowledge and experience) is hardly desirable. Having the old 2D engine dead and buried on my disk and the 3D one in perfect hiatus does not help anyone. So what I will be coding will be open-source. I just need to decide on the license and find an appropriate free repository, like GitHub or Gitorius, and upload things there. I need to make sure that the license is not restrictive for other people, but at the same time it allows me to fork the project in the future if I ever do something monetizable, so in the end it does not cut others off but also gives me full rights to my fork. Something that permits dual licensing probably. Don't know yet.
  • It need to be easy to understand and somewhat didactic, because if I never make something out of that code base it has at least potential use as a learning tool. This was the purpose of the DXUT series, but not long after I bragged how long posts about DXUT don't take a lot of time to write, the next one took so much time that I'm still not done with it. DXUT is too low level. So the shaders will be coming, but I'll switch over to C# and a higher level 3D engine. Something with very little glue code. Like Irrlicht, only not being so bad.
  • I'll keep updates short and things need to move swiftly. I want something where I can hack around and hour or two when I have free time and come up with something interesting. I'll freely commit to the public repository, but won't post about it every time I do, only when I have something interesting to say. A post might be about a single big commit or 10 small ones.
  • I won't optimize. I spent huge amounts of time in the past optimizing and with my new approach this won't work. Things need to be functional and work acceptably. This won't be a real product, rather more of a fun project I can geek out on. C# is slow anyway, so trolololololo.
  • Code will be short and sweet, with a lot of short but powerful components. This goes hand-in-hand with the "not optimizing" bit. My short implementation will probably get 5 times as long if I optimize it and 20 times if this was made so scalable that it would be appropriate for a real and ambitious product.
  • I won't optimize for old hardware. Pixel shader 3, probably 4 will be the minimum. It is incredibly hard to implement a PS2 variant of a PS3/4 algorithm, even if you don't care about how the PS2 one will perform.
  • 3D technology wise my ambitions will be scaled to reasonable output levels of a single person.

So in August, after I return from Greece I'll set up the repository and start returning donations. I will probably be able to do some brainstorming until then so that I have a good plan about what to do. I have a few ideas. A few key points are first person viewpoint, very heavy procedural content with most assets produced by code randomly and an emphasis on creation and building elements.

Maybe I can even prototype something in Unity first to see how it goes and then either continue using Unity or go with something between XNA and something more heavy and feature rich based on XNA. Luckily I write clean C++ and generally I can easily copy and paste over large chunks with only minor editing and it will compile at least under C#.