26 January 2013

Interesting Links in January


This time:
  • Unity Builds
  • Curriculum Part 10: User Defined Types
  • Inline Shaders in C++ Code
  • The Rise and Fall of Languages in 2012
  • The Exceptional Beauty of Doom 3’s Source Code

Unity Builds link_1 and link_2

The good side
Unity Build is an interesting way of reducing build times for a c++ project. Currently I have occasion to work with large code base and that is why this topic caught my attention. In general one has to include all "cpp" files into one single "cpp" file and click/enter build command. Quite simple... but how does it work? And why it improves build times? The whole magic happens because of reducing number of file openings and creation. Preprocessor makes one huge file (one huge compilation unit) and then it is compiled and linked. After this process you can reduce build time from for instance 55 minutes to 6 minutes only.

The bad side
Unfortunately Unity Builds have nasty flaws. The second link that is provided describes this issue. Here is a short list of problems related to this style of build.
  • good for rebuild all, but most of time we do not have to build all, but only parts that are changed.
  • including cpp file causes problems with unnamed namespaces, static variables, using namespaces.
  • when you change some private implementation in one cpp file the a full rebuild is needed (because it is included in main unity build file).
To sum up I will try not to use this method. Although it could help when doing full rebuild it introduces to many problems afterwards. It is better to look for something else.

Curriculum Part 10: User Defined Types

At #AltDevBlogADay you can find a lot of interesting posts related to game development and software development in general  Among many topics there is a "C/C++ Low Level Curriculum" series created by Alex Darby. I hight recommend reading Darby's posts.

In part 10 there is a description of User defined types in C++. One thing that I found interesting is that the author mentions a secret Visual Studio compiler option. Those, actually, two switches enables us to get a detailed description of all or selected class.
/d1reportAllClassLayout - prints layout of all classes
/d1reportSingleClassLayoutXXX - prints layout of class with name XXX

example layout:
1> class MySuperClass size(12):
1>   +---
1> 0 | myInteger1
1> 4 | myInteger2
1> 8 | myInteger3
1>   +---
This option could be nice for teaching purposes, for debugging and performance optimizations as well.
So simple and small macro that enables one to quickly move your shader source from separate file to source code.
#define GLSL(version, shader)  "#version " #version "\n" #shader
 
static const char* SHADER = GLSL(120, 
                                 uniform mat4 myUniform;
                                 varying vec3 myVarying;
 
                                 void main() {
                                     gl_Position = ...
                                 }
                                 );

Although using this form makes shader debugging harder, because there will be no line numbers.

The Rise and Fall of Languages in 2012

Short article about current trends in programming language popularity. One sentence worth mentioning is that: 
"The emergence of a new language, however, is almost always tied to needs in a specific sector."
We could see that "need" when IPhone came out (and created niche for Objective-C). Now we are in need for better languages for multi and many core platforms. That way we hear more and more about functional languages like Scala or Haskell. But to be brief:
  • functional languages gains its popularity, but quite slowly
  • c++ "renaissance" does not work well, steady drop unfortunately
  • D, Go can become mainstream
Another interesting opinion about C++ was that it needs to become main solution for some platform, like big data, mobile, cloud (gamedev is not enough unfortunately). Hope in report for 2013 C++ will behave much better.

The Exceptional Beauty of Doom 3’s Source Code

Being a software developer is like being an architect (but our cathedrals fall more often :)). Unfortunately there is little or even no subjects (at studies) about software style or code history (like there is history of architecture and a guide through different styles). As developers, I think, we should read a lot of code to gain new perspective and simply: to learn.

The above article contains a nice guide through Doom 3's code style. I've read this with pleasure. You can find some other articles about entire design of this game, but in this particular examples there is only about code style. Most discussion about style are very subjective, some of ideas from id's engine might be strange or controversial... but still it is worth gaining some new perspective.
Please read it :)

Interested in new blog posts and bonus content? Sign up for my newsletter.

© 2017, Bartlomiej Filipek, Blogger platform
Any opinions expressed herein are in no way representative of those of my employers.
This site contains ads or referral links, which provide me with a commission. Thank you for your understanding.