Tag Archives: C++

C++11: Variadic templates. Part I

UPDATE: Adding a new concept

The new C++ standard, namely C++11, is here at last; offering many additions to the language’s core as well as in the companion library, the STL. Without doubt it will change the way we think and work but nobody can predict if it is for better or worst. The experimentation period is nearly over, only a handful of features missing from GCC and clang and the C++ engineers will have to learn and master the new tricks in both fronts (core and STL). For those familiar with boost library the second front should be an easy transaction to the new STL, for the first though we need tutorials and lots of them. This little article is one tutorial that extends the already published ones.

One of the new cool features is the variadic templates, simply put, templates with variable number of template parameters. To put it into context this is a variadic template:

template<typename... Types>
struct Foo{};

Continue reading “C++11: Variadic templates. Part I” »

C++ Class: Accessing contents but not the container

When constructing a C++ class a good practice is to never have any member variables in public scope and this includes containers. In this little article we will discuss how to have a C++ container as a private member and be able to expose its contents without exposing the container itself.

Continue reading “C++ Class: Accessing contents but not the container” »

Multithreading: Parallel uniform jobs

Multithreading is a concept that exist for many decades in computer science, nevertheless, only in recent years it become a trend in game development with the arrival of multi-core CPUs in our home PCs. In this small article we will discuss how AnKi utilizes the power of multiple processors. Also the source code of an example can be found at the end of the article.

The concept of multiple threads offers many advantages in applications that execute many uniform jobs at the same time, for example a webserver needs to serve multiple hosts at the same time and without a host waiting for a previous request to finish. A game application though used to have a very standard and linear flow. For example, we first update the AI, then the physics, then we update the world, we do visibility determination and lastly we render, then we repeat the same again. Sometimes its difficult to execute some of these distinctive steps in parallel because the data of the previous step will be used by the next. I bet high class development studios have found ways to blend these steps but in AnKi we use a more simple approach. We use multiple threads to run uniform jobs in parallel.

One good example to illustrate how AnKi uses the power of multiple threads is the visibility determination algorithm. One step of visibility determination is the test for every renderable scene node against the camera’s view frustum. If we have N nodes to test and M threads we can roughly assign for testing the first N/M nodes to the first thread, the next N/M nodes to the next thread etc.

Continue reading “Multithreading: Parallel uniform jobs” »

STL auto_ptr: A bad idea

C++ Standard Template Library (STL) offers a smart pointer called auto_ptr. auto_ptr is a template class that acts as a wrapper for a single dynamically allocated class instance. Its purpose and its usefulness is to deallocate the memory when this smart pointer gets out of scope. Its a way to do automatic garbage collection in C++ by saving us from the extra code writing. One extra reason to use auto_ptr is that it makes the code less error prone simply because it doesn’t rely on the programmer to do the memory dealocation.

In this short article we will discuss a case where auto_ptr fails to do what its supposed to do….

Continue reading “STL auto_ptr: A bad idea” »

The perfect logging system for C++ apps

Ok, the title sounds a little bit pompous and promises allot, many fellow programmers will disagree with the described methodology and others may find it useful. After many changes and rewrites of the AnKi logging system we’ve gained some experience of how a proper logger should be designed and work. The purpose of this article is to pass this knowledge to anyone who is interested.

Continue reading “The perfect logging system for C++ apps” »

The nessesarity of binary files

Until now AnKi used to read all the assets from text files. The mesh (containing the geometry), the skeleton, the skeleton animation, the light properties, the materials etc etc were all text files. Text files are pretty nice for debugging and importing but they contain lots of unnecessary information and they take lots of time to load, not to mention the size. If we take into account that some of the AnKi assets are automatically generated we see that text files are simple inadequate for some cases.

Continue reading “The nessesarity of binary files” »

C++ exceptions and overhead

There are numerous ways for error handling in C++. From day one AnKi used an almost C-like way to handle errors and the standard error to report them. The truth is that we never cared to recover from errors, the only concern was and still is to report the errors and be able to identify the cause of the problem without the use of a debugger. What about exceptions then? Are they a nice way for error handling? Lets see…

Continue reading “C++ exceptions and overhead” »