Passing variables in C++

Just a bit of condensed info that people will hopefully find helpful…

Variables that go ‘in’ but not ‘out’:

void foo(int x)

-x will not be modified outside the scope of foo
-x is copied (consider overhead for big things)


void foo(int const &x)
x=6; //will no compile

-x cannot be modified inside foo
-x is not copied, preventing some overhead


Variables that go in and out

void foo(int &x)

-x will be modified within foo and outside of foo
-x is not copied, preventing overhead, but modification of x outside of foo may be undesirable. see the use of const above.
-simpler than using pointer technique and avoids having to change calling code to pass a pointer


void foo(int *x)
*x = 6;

-the value at *x will be modified inside and outside foo
-x is not copied
-involves more effort to program



Recently, I’ve been playing Borderlands, a first person shooter crossed with an RPG, with excellent multiplayer support for co-op. (and PvP if you like that kind of thing)

The idea behind the game is a combination of levelling up, getting better weapons and items, and improving your own skill (using cover, working out where to shoot the enemies to get critical hits, and actually hitting those spots, etc)

The game is great fun on your own, and far more so with a teammate (or multiple teammates) – though some kind of communication between the team is important. The mic support for borderlands is very good, when you speak, the game transmits – I prefer this over push to talk, though prepare your ears for a teammate coughing or sneezing, and in the process deafening you completely. (woe woe woe)

The difficulty ramps up as you add more players, as does the loot – making multiplayer far more rewarding. It’s also more interesting, as you can chat, devise tactics, and decide who gets which guns. There really are a lot of guns, in lots of colours and flavours.

The game also looks and sounds excellent – the graphics are like a hardened up version of Okami’s style, with a more western look. Things can feel a bit dry and arid at times, but that’s the nature of the environment, and as much as possible there is good variety. The music is brilliant – it ends up getting stuck in your head, and the sound effects match the theme of the game.

The downsides – unskippable intro sponsors (can be fixed, but annoying), the claptraps (little robots) can be annoying if you’re trying to use a shop near them and they keep on ‘dancin dancin’. (but otherwise they’re quite cute), the stat compare takes a while to get used to, and some of the menus are still “consoley”, and don’t work well with a mouse. The story is also a bit weak – though I’ve not completed it yet, it probably won’t suddenly make amends – it’s a typical role playing ‘find treasure, kill baddies’ storyline. The story is missing, but it’s not a gaping hole in a game of this sort.

I was going to get some screenshots, but they’ll have to wait as they didn’t work. D: They’ll hopefully come in time. Nag me if you want to see and I forget.

The theory of good rice

This is the theory of good rice – having watched it in action and had it described step by step. The product was delicious! I am yet to successfully do it myself, but will try again soon.

  1. Rinse the rice in a pan until the water is clear. This takes about 15 rinses. (dry rice sinks, so you can pour off the water easily)
  2. Boil a bunch of water – enough to cover the rice by about 4cm
  3. Pour the boiling water over the rice, stir briefly with a fork and put a lid on the pan. Leave the pan to stand for 15 minutes.
  4. Drain off most of the water, leaving the water level a bit less than 1 cm above the rice, add a largish lump of margarine. (getting the water level just right here is key to getting good rice! Too little is better than too much, you can always add a bit more)
  5. Place on the hob, and set the heat hot enough to make the water steam, but not hot enough to boil. (don’t leave the pan here… rice can burn!)
  6. Cover the pan, stirring at regular intervals with a fork to prevent the rice sticking, for about 15 minutes. The aim is to let the rice absorb all the water.
  7. When the water is almost all gone, take the pan off the heat, and leave to stand with the lid on until the rest of the food is ready to be served. Don’t leave it on the heat at this point!

Then eat it. Nom nom nom.

Don’t email me my password!

You’d think, with all the recent hype about security scandals, missing briefcases and phishing attacks, people would be just a little bit more sensible about how they deal with usernames and passwords.

The correct way to do things…

You sign up for a site, your password is transmitted securely and encrypted in a store. There is no way to ‘retrieve’ a forgotten password, that is it, it will enver come out of the database in a readable format. To reset your password in this scenario, you receive a new, randomly generated password, after providing some details – something of that sort.

The wrong way to do things…

You sign up for a site, check your inbox, and find an email: ‘Dear user, thank you for signing up with us. Your username is JoeBloggs and your password is paSSword25. We hope you have a secure inbox, because we don’t have a secure system!’ (I added the last bit)

Your email, sent unencrypted in most cases, could easily be intercepted. Intercepted, and assuming you’re human like the rest of us, the hacker has access to a great many, if not all of, the sites you’ve ever signed up to, along with whatever details you have submitted to them.

What’s more, the database itself has a reversible encryption method (or just stored in a plain-text file, maybe? Why make it difficult after all…) – so a dedicated hacker canĀ  take all of those lovely passwords.

The message to developers – if you’re setting up a username and password system, there is no excuse not to research security. If you email me my password, then I will put you in my blacklist, which is available here.

Bubbel – Starting to look like a game

My first (woo) game, Bubbel, has started to look like a game. It’s a very simple 2D bubble clone. The aim is to make a really addictive playable game to begin with. Then maybe I’ll add some funky ideas – or maybe not.

The motivation for this game is threefold. Firstly, most importantly, is for myself. I want to make it, I want to do it. The second is to get a demo, which I can show off to prospective employers – a demo I couldn’t develop very well within the scope of my degree. The third is for Illusia, a bubble fan of supreme proportions.

So here it is – the beginning!

An early version of bubbel - not playable yet, but geting there.
An early version of bubbel - not playable yet, but geting there.

A menu for an(y) XNA game

So, my current project is to make a game, as you might have guessed. Ideally I want it to be so darn good I can sell it through some distribution service for a very reasonable price.

My first sub project (I’m easily bugged by not having certain ‘features’ of programs during development) was to build a menu that extended GameComponent, and was a pluggable, easy to implement menu. It has no flashy features (currently) and is not quite ready to release (it’s clean running, but I want to make the code a bit more flexible for possible future features). When it’s ready I’ll make it available on

Using only a few lines of code, the menu looks like this:transparentsilvermenu

And by picking that irresistible button…

transparentbunnymenuA semi transparent bunny fill the image. Obviously (or not?) a bunny would not be the image of choice in a real game, but it allow you a few important choices:

  • The menu background is an image showing some beautiful prerend of a scene in your game
  • The menu is a transparent grey, using the real game (paused, potentially) in the background as an image
  • A plain colour
  • A slightly transparent image of something (maybe stars, clouds?) over the background. Although I haven’t tested it, pngs with transparency data should work too.

In case you’re wondering, the blue tint in these images is the ‘game’ showing through – a default otherwise unedited XNA project.

The features, then:

Choice of menu title position and menu items position (auto aligning to look best). Choices are top and bottom lefts and rights, and centred. Menu items can be automatically stacked under the menu title.

Menu item active and inactive colours can be set (the title is inactive colour, but I’m planning to make that so you can set it differently)

Menu items are added in the form of text-delegate pairs – so you have complete control over what they do. The menu listens for Escape key presses, and can hide and show itself. When hidden by escape it calls a user set ‘pause’ and ‘resume’ delegate to give you control over your game when the menu shows itself. You don’t actually have to set these… the menu will then just show and hide itself.

All in all, to get a menu with 2 options (resume/quit, maybe?), you need only 6 lines of code, and a simple but functional menu will work alongside your existing game. (not counting the methods that respond to resume/exit – I’m assuming you already have them. It makes the required lines of code look better! If you must be picky, the methods take another 6-7 lines depending on what you put in them)

Next time – I’ll either have added some game to the menu (woo), flashed up the menu some, or quite possibly done something totally different… You will have to wait and see!