Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

1574 Excellent

About Matt-D

  • Rank

Personal Information

  • Interests
  1. Perhaps this will be of some use: // lovely name  
  2. If you still have a single, unique owner at a time (which you should verify), then std::unique_ptr would be the way to go -- you can move it around, thus transferring ownership. (In contrast, boost::scoped_ptr cannot be moved, let alone copied.)   It's also available in Boost:   TL;DR: you have to analyze and understand the exact ownership semantics that apply to your case at hand, everything else should follow from that. In particular, you may want to familiarize yourself (thoroughly) with GotW #89 to #91:
  3. I think this topic is interesting and worth knowing for game development (see Ubisoft examples later).   The good news is that -- if you'd like to learn -- there's now plenty of really good materials available.   I'd start with Herb Sutter's talks: atomic Weapons: The C++ Memory Model and Modern Hardware Then, watch his CppCon 2014 talks, "Lock-Free Programming (or, Juggling Razor Blades)": * Part 1: Lazy initialization with DCL vs. call_once vs. function local statics, and lock-free mailbox algorithms * Part 2: Lock-free linked lists, the ABA problem, and atomic smart pointers (Note: "Example-driven talk on how to design and write lock-free algorithms and data structures using C++ atomic -- something that can look deceptively simple, but contains very deep topics. (Important note: This is not the same as my "atomic Weapons" talk; that talk was about the "what they are and why" of the C++ memory model and atomics, and did not cover how to actually use atomics to implement highly concurrent algorithms and data structures.)") Last but definitely not least, I highly recommend following Jeff Preshing's (a Technical Architect at Ubisoft Montreal) blog: For instance, check out his talk at CppCon 2014: "How Ubisoft Develops Games for Multicore - Before and After C++11"   Getting familiar with Boost.Lockfree shouldn't hurt, either:   Good luck!
  4. There are also MinGW distributions which already include pre-built Boost binaries: - - Perhaps it would be easier to use one of these?   Alternatively, in case you only want ASIO, there's also a standalone (non-Boost) version only requiring a C++11 compiler:
  5. TL;DR - unless you've been telling everyone that you're the greatest software engineer who's ever lived, you should never feel like that.   . . .   +1!   To add to that: - Egoless Programming: - You Are Not Your Code:
  6. Matt-D

    A Starting Point

    Go with something recent -- i.e., targeting C++11/C++14; anything older is a waste of time, especially when learning. Even if you end up unlucky enough to be confined to maintaining legacy code, it's always easier to pick up older C++ coding style along the way if you already are familiar with the foundations of the language. And getting familiar with the foundations of the language is definitely easier starting with C++11.   Here's the official getting-started list: I think the recommendations there are 100% spot on, so I won't repeat them here. I can just say that personally I think "C++ Primer" may be the choice for you (and that's what I usually recommend to C++-is-not-my-first-programming-language programmers).   For more, see The Definitive C++ Book Guide and List:   BTW, Scott Meyers is working on Effective Modern C++: From the previews so far it definitely looks a great second/third C++ book to have.   Now, that's as far as the learning is concerned (worth emphasizing: you definitely need a book, IMHO you can't really learn much from the on-line references that won't be covered in a first chapter or two of a good book). Regarding the reference, worth bookmarking and revisiting as you learn along the way:   For instance, sooner or later you'll need most of the algorithms listed here -- -- it may save you quite some time to at least get familiarized with their existence, in order to avoid unnecessarily reimplementing the wheel :-)   Good luck!
  7. I'd also add Lua -- it's more minimalistic than Python and is often useful for embedding as a scripting language for your game (so that the players can extend it: modify the AI behavior, add custom scenarios, etc.). In fact, Lua would be my first choice for an embedded scripting language (not just) in a gamedev context.   It's also very easy to get started:   Here's a comparison: (even though it's hosted on lua-users it points both the upsides and the downsides of both).   OTOH, if you already know Python, picking up Perl wouldn't necessarily have the highest priority (the use-cases of these substantially overlap).
  8. Try simply following the official tutorials:
  9. These are some pretty good starting points ("old-code-can-call-new-code" is a pretty succinct description): One other thing -- they go hand in hand with "auto" and genericity: For instance, instead of writing: int add(int a, int b) { return a + b; } float add(float a, float b) { return a + b; } double add(double a, double b) { return a + b; } int x = add(1, 2); float y = add(1.f, 2.f); double z = add(1., 2.); You can simply write: template <typename T> T add(T a, T b) { return a + b; } auto x = add(1, 2); auto y = add(1.f, 2.f); auto z = add(1., 2.); So they help you achieve generic, reusable code that doesn't just work for a particular type, but for a bunch of types that happen to satisfy a concept: // This concept is implicit here -- operator "+" has to exist. You can make it explicit with type-traits, static_assert, and enable_if.   This is useful -- say, instead of "add" taking two numbers, think of "will_first_monster_win" taking two monsters: template <typename FirstMonsterType, typename SecondMonsterType> bool will_first_monster_win(const FirstMonsterType & first_monster, const SecondMonsterType & second_monster) {   return strength(first_monster) >= strength(second_monster); // super-fancy combat algorithm! } Now, if you add new monster types to your game, your "will_first_monster_win" function will keep working unmodified -- as long as the relevant (new) "strength" function exists (let's call this particular existence requirement a "has-strength" concept -- in other words, FirstMonsterType & SecondMonsterType in the "will_first_monster_win" function will successfully match any types that satisfy the "has-strength" concept). In other words, you can extend your code (and add new code) without modifying the already written ("old") code: // Note: the linked article happens to use inheritance/inclusion-run-time-polymorphism (typical OOP technique) to illustrate this; in many ways, however, templates/compile-time-polymorphism (typical Generic Programming) as in the "will_first_monster_win" example will work just as well if not better.   Without templates, you'd have to know the types of your monsters in advance / right at the moment when you're implementing "will_first_monster_win" -- and then rewrite it / provide overloads / etc. each time you add new monster type. Or just settle for a boring game with fixed monster types :-(   With templates you can save quite some time, speed up your experiments, and keep adding increasingly cruel monsters, so you can provide more fun for the players :-)
  10. To start with, C++ offers several distinct forms of polymorphism, each one with different use cases in mind (and different trade-offs). To be able to make an informed choice, it's a good idea to become familiar with them all:   You'll learn some of the trade-offs the hard way, after discovering that working on your game (or other program) becomes harder over time, when adding more features forces you to go back to the old code that wasn't written with them in mind, etc. And that's OK, this is how you learn and improve -- as long as you Refactor Mercilessly!   It's especially worth noting that run-time polymorphism is very much possible (and arguably cleaner!) without inheritance -- I strongly recommend watching this:
  11. Matt-D

    gui/game librarys FOR C++

    I'd also recommend SFML: Don't forget the docs:
  12. Because reproducibility is desirable, while non-reproducibility is undesirable. // See, for instance, Think how hard debugging would be if you couldn't guarantee the same execution path of your program.   Besides, even if you were fine with non-reproducibility, seeding with time functions is often a bad idea -- at least, you'd need a high resolution timer. As an alternative, you can do the following: std::random_device rdev{}; // ASSUMPTION: your implementation / target platform actually guarantees this is random std::default_random_engine e{rdev()}; // seed with the aforementioned source of randomness   For more, read this:
  13. Matt-D

    Effective C++ (book)

    See also previous thread:
  14.   I would still consider using std::vector, see: Bjarne Stroustrup: Why you should avoid Linked Lists. The cache benefits of std::vector using contiguous memory are so massive that they may in practice outweigh the benefits provided by the lists, EVEN when inserting/removing elements in the middle. It's a trade-off; what's your relative access-to-modification ratio? It's worth checking the performance with profiler (ideally, avoid synthetic benchmarks, and test with your actual gameplay, e.g., using automated replay feature (assuming you have that in your engine)).   See “Software Development for Infrastructure” for more details and the graph mentioned in the video.        
  15.   Only if you store & call it via a pointer (or its variants, like std::unique_ptr) or a reference (or its variants, like std::reference_wrapper). Otherwise, object slicing occurs.   Just like here, where you store by value: std::list< EventHandler<E> > m_handlerList; // oops   and here, where you call your stored-by-value (and sliced) handler for (typename std::list< EventHandler >::iterator it = m_handlerList.begin(); m_handlerList.end() != it ; ++it) // oops { EventHandler handler = *it; // oops *pMessage << "Informing handler nr. " << i << ": " << handler.getName().c_str(); m_pLogger->log(pMessage, Logger::LOGLEVEL_DEBUG); handler.handleEvent(pEvent); // this is sliced
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!