May 23, 2012

Using P4SandBox for 3 Weeks or So

I have been using P4SandBox for 3 weeks or so, and I'm pretty happy with it. The private repo is great: creating new streams(read it as branches) and switching between them are fast. (It internally uses shelving, of course)  So streams almost work as branches + automatic shelving.

One bug I found:

  • If you MANUALLY shelve in a stream, you won't be able to unshelve it!  So currently I'm not doing any manual shelving in a stream: Instead, I keep creating a new stream if I need to shelve what I've been working on and start to work on something else. By the way, it works fine in the traditional central-controlled scheme with no P4SandBox involved.
One annoyance I found:
  • When you copy/merge, (it's basically push/pull in Git) it doesn't propagate change histories. Perforce said the next version will have this feature implemented


May 21, 2012

COM Smart Pointer in DX9/11 Renderer?

Main Article
Recently I've been developing a real-time application outside the gaming industry, and I happened to implement a very thin, stateless DX9 renderer, and then ported it to DX11. This piece of software runs on Windows PC, so it was kind of nice to deal with more powerful hardware than current-gen consoles, which I've been married to for the last 6+ years.

In the gaming industry, I don't think I saw anyone using COM smart pointers in a rendering engine while Direct3D is built on COM. Probably it's because of performance concerns.  But I'm not sure if it is still a valid concern. For the last few years, I saw more non-rendering game codes using smart pointers extensively, and most of the time the performance was fine. So I'm thinking now that it might be okay to use COM smart pointers for D3D objects.  Does anyone have any experience with this on a commercial game? If so, how did it behave?

Maybe I Should Add Something Useful Here
I feel guilty to finish this post without giving out any useful info. So let me just say how to use COM smart pointers for DX9 and 11.

For DX9:
To define smart pointers in DX9, just include comdef.h before including d3d9.h.

#incldue <comdef.h> 
#include <d3d9.h>

Then you will get a smart pointer for every single D3D type with ~Ptr prefix.  With this, your D3D device's smart pointer will be declared like this:

IDirect3DDevice9Ptr mDevice;

And using it is very straight-forward.  There's really no gotchas using this pointer.. (unlike dx11's)

For DX11:
d3d11.h doesn't contain any special preprocessor macros that automatically generate COM smart pointer types for D3D interfaces. So what I had to do was using atlbase's COM smart pointer.

First, include atlbase.h

#include <atlbase.h>

Now you can manually make smart pointers for any D3D declaration like this:

CComPtr<ID3D11Device> mDevice;

It works mostly same as DX9's COM smart pointer except one gotcha.  If you try to pass in the address of an atlbase COM smart pointer, while it's not empty, it'll assert on you.  And you know how often you have to pass in type** to a D3D calls. (e.g, to create a render target texture)  So if you do this, you should clear the smart pointer before you use & operator. This should be done by assigning nullptr to the smart pointer like this:

mRenderTarget = nullptr;

One gotcha here, I once assumed CComPtr's detach() function does the same thing as assigning nullptr, which was not true. gaaaahhh!! So don't do this, if you do that you will have unreleased resources hanging around.


K, I'm not feeling guilty anymore.. so ciao :)





May 1, 2012

Personal Choice of Version Control System in 2012


Sometime ago, I wrote a blog post about my personal choice of VCS and the winner was  Subversion.  But now there has been two changes from Perforce that made me want to re-evaluate. Those two changes are:
  • New feature called P4SandBox
  • More generous free version limitations: 20 users and 20 workspaces


What is P4SandBox?
This new feature available in Perforce 2012.1 enables us to use a local private depot similar to Git.  But this is not a completely distributed system: it is more like you make a mirror in your HDD and work offline.  Then when you are ready to commit to the central server, you push all your local changes to the central server. Also P4SandBox has the concept of streams which almost work similar to the powerful Git branching.

This video will explain these new features better than me :)


Background
Being in the gaming industry about 10 years and playing with some open-source projects means I have dealt with different version control systems, or VCSs, from complete free, brute-force manual file copy method to very expensive commercial-grade Perforce.

So which program have I been using at home? Subversion.... I know! A lot of people will argue that other programs are better, and I am not gonna say they are wrong. The reason why I have been using Subversion is because it did what I want with the least amount of annoyance.  But now I'm gonna switch back to Perforce because I became to believe Perforce will serve me better now.  Below is the list of what I need/want from my personal VCS and how the most popular VCSs do the job:

Windows Support
Yes, I'm a MS whore.  I use Windows all the time, and I, as a game programmer, personally don't see huge need for Linux for myself.  Also if I can maintain only one OS at home, that's less drama for me. (Yay?).
  • Git(-2): I like Git a lot, especially how it handles branches, so I really wanted to use it on Windows.  But, as far as I know, the only way to use Git server on Windows is through Cygwin or msysgit.  Cygwin is basically doing Linux emulation in a sense, and I personally don't enjoy installing Cygwin. msysgit is a bit easier to install on Windows, but still I had to set up SSH or what not, so there's no one-button solution for Git on Windows.  So big no-no to a MS whore like me.
  • Perforce(+1): Perforce supports Windows pretty well.  It comes with easy-to-install server program/service for windows.
  • Subversion(+2): This was actually a big surprise to me.  There is a program called VisualSVN Server, which is one-click solution for Subversion server on Windows.  It just works and comes with https access and access control all in one nice and simple GUI.  This was even easier than installing Perforce.
Occasional Multi-User Support
Although my VCS is mostly there to keep a history and backups of my own codes, sometimes I open it up to my friends so that I can get useful feedback from them.  So having multi-user support is very useful for me.

  • Git(+1): Git can easily support multiple users.  But setting access control for each users can be a bit of PITA on Windows.  When I tried it last time, I had to make fake Windows user accounts and hook'em up with SSH.
  • Perforce(+1): Perforce used to be free for either i) 2 users and 5 client workspaces, or ii) unlimited users and up to 1000 files.  But now it's free for 20 users and 20 client workspaces with unlimited # of files.  I believe each user need 2 workspaces to get P4SandBox working(one for main and the other for the mirror) per computer.  So if we say each user uses 2 computers, one user will take up 4 workspaces.  So 5 full-time users...  I think it's very reasonable for my personal projects. So I changed this score from -1 to 1
  • Subversion(+2): As I said earlier in Windows Support section, VisualSVN Server comes with a nice GUI where you can simply setup users and access control.  So another big thumbs up from me.

Cost
I'm cheap. I love free stuff.

  • Git(+1): free
  • Perforce(0): free for limited use. and this time the limitation is not severe.. So I changed the score from -1 to 0.
  • Subversion(+1): free

GUI Client
I'm in love with Perforce's nice GUI clients. Not so much with P4V; more with P4Win. But P4Win is discontinued.... Oh well, P4V is still good enough.  Sure, I still use command-line a lot for certain things GUI clients don't support, but I found 90% of time, using GUI clients are much faster and easier.

  • Git(-1): it doesn't have any nice free GUI client as far as I know.  There are some being developed at this moment, but they don't seem to be mature or free enough to use them.  TortoiseGit is good enough most of the time.  But I still prefer P4Win style, real GUI clients. 
  • Perforce(+2): P4Win is awesome. P4V is great, too.
  • Subversion(+1): I found a program called SmartSVN.  It has limited functionalities unless you buy the pro version, but I found the basic free version is good enough for day-to-day operations.  Anything that cannot be done through the free SmartSVN version, I use TortoiseSVN.  Then anything that cannot be done by TortoiseSVN, I use command-line.  
Branching
Who doesn't love branching?  It's such a neat tool to fuck around(read it as experiment) your code without ruining your projects.
  • Git(+2): I love the powerful branching feature of Git. You don't need to make a copy in different directories, so it helps a lot with path referencing in the code.  Say you have a program that links with library Awesome, and now you wanna branch library Awesome.  With Git, you simply need to switch to different branch and build.  But with other source control systems like Perforce, you will have to branch the library into a different directory and change the library path in your program code.
  • Perforce(+2): As I just explained in Git section above, branching into a different folder sucks.  Also the speed of branching a large number of files is slow because Perforce server controls everything.  Network speed is slower than your HDD's spin rate. However, if you use streams in P4SandBox the branching almost became Git's branching. Everything works inside your sandbox without connecting to the central server, so it's super fast.  So I changed the score from -2 to 2 here.
  • Subversion(-1): The speed is fast enough.  But still you have to branch into different directory.. uggh.. that bothers me.

Final Score
So final score for me is like this.
Don't forget.  This is the score for my personal need. Not for the big giant game studios.  So if you ever comeback and say "but Perforce is better because it can supports 200 users easily", I'm gonna make you watch this video for 2 hours before you go to bed.


Apr 9, 2012

Fixing My Stupid Canadian Keyboard

If you buy a laptop in Canada, most of the time it comes with a fucked up multilingual keyboard, which looks like this:

Image source: wikipedia
Look at the left shift key.  It's half the size of the shift key on tje "standard" US keyboard layout.  Sure there are other small difference here and there, but nothing really pisses me off as much as this small tiny left shift key. The key next to the left shift key has really no meaning for non-French users like me, and it doesn't even register any character if you are using EN keyboard on Windows.  But still I'm very used to press in the middle of the longer shift key, so sometimes my left pinky presses the "dead" key... :(

Sure, it's stupid to have this type of keyboards to begin with since there is virtually noone who is still using French in Canada unless you are in Quebec... But whatever, I already have a stupid laptop, so I had to fix it: as long as the weird key next to left shift can be remapped to the left shift key. I should be fine eh?

I googled a bit, Sure there are some manual tricks, including registry tweaks, I could use, but I managed to find a nice small program called SharpKeys, which allows me to remap any keys on the keyboard.  The best feature of this program is that I can just press a key on the keyboard and say "remap what I pressed to the key I'm gonna press now".

YAY~

Mar 29, 2012

Canstruction 2012


While walking around Vancouver downtown, I spotted an eagle inside of the HSBC building.  That got me curious enough to get into that building... and guess what..? Canstruction 2012 is happening... So I took some pictures :D




I'm pretty sure it's humping




By the way, this is apparently an international contest... (that I didn't know)





Mar 28, 2012

Fixing Trigger Finger?


Since I got my pinkie injury while playing basketball 15 years ago, I have had a trigger finger, a symptom that prevents you finger to bend smoothly: Your finger will be locked somewhere in the middle, and you have to put more force to make it to snap-bend. Yuck....

This was the excuse, I have been making for my poor guitar play... also it's been bugging me recently, especially when I play the piano... So today.. I talked to my doctor... yeah why not.. we Canadians don't pay a dime for seeing a doctor or getting this type of things fixed.

He suggested me to take 3~4 pills of Magnesium Citrate right before the bedtime for a month.  According to him, this might fix the problem, or make it better. If it does, I'll have to take this forever.  If not, that's when we can discuss about the surgical way... (which I was expecting to begin with, I guess....)




Okay, here we go... Let's see if it works. If it does, I'll become the best guitarist in history :P

p.s. Oh, by the way, one side effect of this pills:  DIARRHEA!


Feb 22, 2012

Double the Budget for Free T-shirts

I read something like this from a game business book, which I don't remember the title anymore (sorry it's been a while.  If anyone let me know, I'll update this post):


"If you don't have a budget for free T-shirts for employees, make one.  If you do, double it up"

I totally agree.  From company's point of view, this is a really cheap way to show it cares about people and keep morale high.  Don't forget that people become happy or pissed off by mostly small things. So if you are in a position to make a decision on free swags, please get each of your employees at least one free T-shirt an year.

It's also very interesting to see how high morale can affect the quality of games.  Throughout my career, I have seen plenty of game developers who did more than what they were asked for when they were given free T-shirts, thus excited.  Of course, I also saw the opposite: the sweat-shop game developers who did never more than what they were required just because they were treated like factory workers.  Actually, seeing the latter more often nowadays, I'm a bit worried.

To me, game making is a form of art + technology collaboration.  So more excited your developers are, more inspiration they offer to their colleagues, which means more iterations = better games.  If you don't trust me, maybe you can ask how many free T-shirts each employees get at your favorite game studios... :)

Feb 19, 2012

Do Your Part for the Environment, Shaw

Shaw communications is a load of bullcrap.  I'm pretty sure any Shaw subscribers, whether it is cable TV, internet or digital phone, would remember that you were asked to switch to paper-free billing to save the environment.  You even probably remember the following picture, which was mailed to you at least once or twice.

image source: shaw.ca, of course an environment-friendly-fraudly company.

This is great.  Don't you think?  I switched to paperless instantly(or maybe even before I was asked) not because I cared too much about the environment.  It was just more convenient for me to receive the bill via email.  See? I'm being honest at least.  Unfortunately, Shaw is not.

So did Shaw really care about the environment?  My answer is no.  Since a lot of customers switched to paperless billing, Shaw increased the number of promotional materials PRINTED ON PAPER AND MAILED to you.  Yup, so now I'm getting more mails from Shaw.  For example, last week I received two.  One is asking me to sign up for their digital phone service(AGAIN!), and the other was some new internet or TV service, called EXO. And this EXO mail was printed on higher-quality glossier paper than your normal paper bills.

So Shaw saved some money, not the environment, by not printing your bills on paper and used that saving to print their promotional materials more aggressively.

Way to go, Shaw.  Do your part for the Environment, if you really meant, or just don't BS.  I'll accept you. I have great a fondness toward a business which's trying to make money without lies.

Feb 12, 2012

Crazy Eye Pain & Headache = MSG Side Effects?

This morning, I woke up with some crazy eye pain, headache and nausea and I had no clue what caused it.  This is my 2nd time having these symptoms.  The first one was sometime last year when I had to call in sick.  I usually don't have headaches.  Just this one is too strong for me to do any normal works: the only thing I can do is just to lie down and do nothing.

Once I got better around 11 PM, I did some web search and now I think it might be related to the high intake of MSG.  According to this site, my symptoms are MSG side effects, and guess what? I went to a Chinese restaurant last night and ate a lot!  Too bad, I don't remember what I ate last time I had this problem.  If I remembered, I would be more certain. :)

Oh well, MSG can be unhealthy anyways, so I guess it's time to cut, or reduce, MSG out of my diet?

Feb 10, 2012

[WIP] Music: Out of Reach Intro

This is something I wrote last night.. It's still intro to a song I, for now, call Out of Reach.  I quite like it, so I might finish it one day.. yes one day...




For comments, use my Facebook (one-man) band page I guess?