Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 06 Feb 2013
Offline Last Active May 09 2013 09:11 PM

Posts I've Made

In Topic: Implementing a scene director

21 February 2013 - 08:57 PM

Well thank you very much. smile.png

Also of note, I've learned quite a bit more about smart pointers since I wrote this: http://agentultra.com/sdl-and-modern-c-plus-plus-images.html

One thing to be careful about when passing unique_ptr objects into function calls as I do in the examples above is: argument evaluation order. Some languages have a defined order in which to evaluate function arguments. C++ does not. Here it's probably not an issue but imagine a function that takes a unique_ptr and a couple of other values:


void myFunc(std::unique_ptr<MyType> x, int y)

// and then later on we call it like so...

myFunc(std::unique_ptr<MyType>(new MyType()), computeY());


What do you think will happen here if computeY throws an exception?

The answer: who knows? However depending on the order that the run-time chooses to evaluate the arguments in we could leave a dangling reference on the heap to that shiny, new MyType. Scott Meyers recommends (and I whole-heartedly agree) that you should declare your smart pointers in their own expression to avoid such awkward situations.


std::unique_ptr<MyType> my_ptr(new MyType());
myFunc(std::move(my_ptr), computeY());

Will work. Just look up Item 17 in Effective C++. You do already have three copies of that book, right? One for beside your bed, one for your desk, and one in the bathroom? If you want to program your games in C++ then you should have at least one copy. It's indispensable.

Anyway, my code is getting a little better. My 'engine' is coming along (if you can call it that). I'll post more tutorials as I come up with them.

In Topic: C++ Books

21 February 2013 - 08:24 PM

I'd suggest Expert C Programming


It's mainly about C, but it does overlap into C++. It's probably the only book on C/C++ that I'd read cover-to-cover. I have other books like Effective C++ (which is also really good) but I use them more as references. Expert C Programming teaches not only the "hows" but the "whys" as well with clever anecdotes and factoids. Well worth the read.

In Topic: Issues with animating for a durating, relative to game loops?

14 February 2013 - 04:05 PM



Is an excellent article on programming game loops I've found pretty useful.


The function you're going to want to google for is "tweening."


I'm not sure how to implement it but that definitely sounds like what you might be interested in.

In Topic: Implementing a scene director

14 February 2013 - 03:49 PM

Well success, I've cleaned out the bugs and added the cleanup calls in the right places. It runs under Valgrind and Clang's static analyzer with no warnings or errors. I leave it up to the reader if they're interested in using this code to figure out where those bugs are and how to fix them. It's pretty simple really.


The next step (probably after I get sprites and animations happening) is to abstract out the scene definitions into a sqlite file or something so that I can define new scenes on the fly without touching the engine code.


But one step at a time. Small victories.

In Topic: Implementing a scene director

14 February 2013 - 10:10 AM

Hah, there's a bug! See if you can spot it. :)