Matt-D

Members
  • Content count

    200
  • Joined

  • Last visited

Community Reputation

1574 Excellent

About Matt-D

  • Rank
    Member
  1. Perhaps this will be of some use:   https://github.com/tylertreat/Comcast // lovely name https://jagt.github.io/clumsy/  
  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.) http://stackoverflow.com/questions/11496826/transferring-ownership-to-function-with-stdunique-ptr http://herbsutter.com/2013/06/05/gotw-91-solution-smart-pointer-parameters/ https://msdn.microsoft.com/en-us/library/hh279676.aspx   It's also available in Boost: http://www.boost.org/doc/libs/master/doc/html/move/reference.html#header.boost.move.unique_ptr_hpp http://www.boost.org/doc/libs/master/doc/html/boost/movelib/unique_ptr.html   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: http://herbsutter.com/2013/05/29/gotw-89-solution-smart-pointers/ http://herbsutter.com/2013/05/30/gotw-90-solution-factories/ http://herbsutter.com/2013/06/05/gotw-91-solution-smart-pointer-parameters/
  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 http://herbsutter.com/2013/02/11/atomic-weapons-the-c-memory-model-and-modern-hardware/ Then, watch his CppCon 2014 talks, "Lock-Free Programming (or, Juggling Razor Blades)": http://herbsutter.com/2014/10/18/my-cppcon-talks-2/ * 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: http://preshing.com/ For instance, check out his talk at CppCon 2014: "How Ubisoft Develops Games for Multicore - Before and After C++11" http://preshing.com/20141024/my-multicore-talk-at-cppcon-2014/   Getting familiar with Boost.Lockfree shouldn't hurt, either: http://boost.org/libs/lockfree   Good luck!
  4. There are also MinGW distributions which already include pre-built Boost binaries: - http://nuwen.net/mingw.html - https://msys2.github.io/ 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: http://think-async.com/
  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: http://blog.codinghorror.com/egoless-programming-you-are-not-your-job/ - You Are Not Your Code: http://www.hanselman.com/blog/YouAreNotYourCode.aspx
  6. 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: http://isocpp.org/get-started 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: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list   BTW, Scott Meyers is working on Effective Modern C++: http://scottmeyers.blogspot.com/2014/09/the-four-stages-of-doneness.html 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: http://cppreference.com/   For instance, sooner or later you'll need most of the algorithms listed here -- http://en.cppreference.com/w/cpp/algorithm -- 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: http://www.lua.org/pil/   Here's a comparison: http://lua-users.org/wiki/LuaVersusPython (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. SFML - Can't even compile tutorial code

    Try simply following the official tutorials: http://www.sfml-dev.org/tutorials/2.1/
  9. These are some pretty good starting points ("old-code-can-call-new-code" is a pretty succinct description): http://isocpp.org/wiki/faq/templates http://isocpp.org/wiki/faq/big-picture#generic-paradigm http://isocpp.org/wiki/faq/big-picture#multiparadigm-programming http://isocpp.org/wiki/faq/big-picture#old-code-can-call-new-code http://isocpp.org/wiki/faq/cpp11-language-templates One other thing -- they go hand in hand with "auto" and genericity: http://isocpp.org/wiki/faq/cpp11-language#auto 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: http://en.cppreference.com/w/cpp/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: https://en.wikipedia.org/wiki/Open/closed_principle // 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: http://accu.org/index.php/journals/538   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: http://channel9.msdn.com/Events/GoingNative/2013/Inheritance-Is-The-Base-Class-of-Evil
  11. gui/game librarys FOR C++

    I'd also recommend SFML: http://www.sfml-dev.org/ Don't forget the docs: http://www.sfml-dev.org/resources.php
  12. Because reproducibility is desirable, while non-reproducibility is undesirable. // See, for instance, http://openmd.org/?p=257 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: http://isocpp.org/files/papers/n3551.pdf
  13. Effective C++ (book)

    See also previous thread: http://www.gamedev.net/topic/645967-effective-and-more-effective-stl/#entry5082624
  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