Tag: libraries

Entries for tag "libraries", ordered from most recent. Entry count: 28.

Warning! Some information on this page is older than 5 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.

Pages: 1 2 3 4 >

# Vulkan Memory Allocator 2.0.0-alpha.3

Sep 2017

I just published new version of Vulkan Memory Allocator 2.0.0-alpha.3. I'm quite happy with the quality of this code. Documentation is also updated, so if nothing else, please just go see User guide. I still marked it as "alpha" because I would like to ask for feedback and I may still change everything.

I would like to discuss proposed terminology. Naming things in code is a hard problem in general, and especially as English is not my native language, so please fill free to contact me and propose more elegant names to what I called: allocator, allocation, pool, block, stats, free range, used/unused bytes, own memory, persistently mapped memory, pointer to mapped data, lost allocation (becoming lost, making other lost), defragmentation, and used internally: suballocation, block vector.

Comments | #vulkan #productions #libraries #graphics Share

# RegScript 2 - Parameters Framework

Apr 2016

On April 1st I've read a very interesting blog post that doesn't seem like April Fools' joke: Game Development Needs Data Pipeline Middleware. I fully agree with the author. There is a code very much needed in every game engine, game editor and other graphics/music/media applications, written over and over again - the one about storing, editing and serializing data structures of various kinds (basically all objects that make up the state/document/game level of a program), each having a set of parameters of various types (integers, floats, strings, vectors, arrays etc.) - so it makes sense to create a library for it.

I (as probably every game developer) already tried to create such framework many times. Now I decided to share the source of my last attempt: RegScript2 @ GitHub. It is not finished and some design decisions I've made may seem controversial, but at least we could start discussion about the solution. What do you think about it? Feel free to e-mail me at sawickiap__REMOVE__@poczta.onet.pl, comment this post or read and interact with my code on GitHub.

Comments | #libraries Share

# Using Google Test in Visual C++ 2012

Mar 2014

I was recently learning Google Test (Google C++ Testing Framework). It's a C++ library from Google (shared under new BSD license) to do unit testing, following xUnit convention.

As always with any library in C++, it's not that easy as just download the sources, compile and use it. Here are my experiences with making it work in Visual C++ 2012:

1. Visual Studio solution is already prepared in msvc/gtest.sln. You just need to confirm upgrading to new version and ignore report with warnings.

2. You only need "gtest" project. It compiles a static library. That's the way I decided to use it. Alternatively you could just include all library sources to your project.

3. The library uses tuple from new C++ that requires variadic templates. Visual C++ doesn't support this feature, so to make it compiling without errors, you need to globally define following macros (in project properties > C/C++ > Preprocessor > Preprocessor Definitions, in both Debug and Release configurations, in both library and your client project):


4. If your project uses different way of linking to the standard library than gtest, you will get linker errors like:

1>gtestd.lib(gtest-all.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in MyTestApp.obj
1>msvcprtd.lib(MSVCP110D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::_Container_base12(void)" (??0_Container_base12@std@@QAE@XZ) already defined in gtestd.lib(gtest-all.obj)
1>msvcprtd.lib(MSVCP110D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" (??1_Container_base12@std@@QAE@XZ) already defined in gtestd.lib(gtest-all.obj)

That's probable as default setting for new project is to link it dynamically, while gtest project links it statically. It should be same in both gtest and your project. To change it to linking dynamically, enter project properties > C/C++ > Code Generation > Runtime Library and choose Multi-threaded Debug DLL (for Debug) and Multi-threaded DLL (for Release).

After setting it up, usage of the library is very easy. You just need in your project:

1. Add "include" subdirectory to include directories.
2. #include <gtest/gtest.h>
3. Link with "msvc/gtest/Debug/gtestd.lib" (in Debug) and "msvc/gtest/Release/gtest.lib" (in Release).
4. Write your tests, like:

TEST(IntegerTest, Addition)
    EXPECT_EQ(4, 2 + 2);
    EXPECT_EQ(10, 3 + 7);

5. Write main function:

int main(int argc, char** argv)
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();

I like this library - it's easy to learn and use while quite powerful. It's also well documented - the main documentation is: Primer, Advanced Guide, FAQ.

There is also a GUI application available, called Guitar (Google Unit Test Application Runner) or gtest-gbar, which allows running your testing application and browsing results in a window instead of console.

Comments | #c++ #libraries #testing Share

# Building JSON Parser Library for C++

Sep 2010

C++ is a flawed language in many aspects, but one of its biggest problems is how difficult it is to start using some C or C++ library. Because of the lack of binary compatibility, separate version have to be prepared for each operating system, compiler and compiler version. Often a version for my compiler is not accessible (or no binary distributions are accessible at all) and I have to compile the library from source code, which always causes problems.

I recently wanted to start using JSON as a configuration file format. It's a nice description language that would make a good compromise between XML (which has lots of redundacy, is unreadable and I generally dislike it) and TokDoc (my custom description language). In search for a JSON parser library for C++, I've decided to use json-cpp. And here the story begins...

Json-cpp is distributed only as source code. README file says that I have to use Scons build system to compile it. WTF is this? How many f*** build systems like this are out there?! Well, I've downloaded it. It looks like it uses and requires Python. I have Python 2.6 installed - it should be OK. Scons Windows setup installed it in the Python directory - OK. What now?

Json-cpp readme says about Scons: "Unzip it in the directory where you found this README file. scons.py Should be at the same level as README.". Unzip?! OK, so maybe I should download the ZIP distribution of Scons instead of setup. I did it, enter the ZIP archive and... There is no scons.py file there! Only scons.1 and some other mysterious files. The only Python script in the main directory is setup.py. So desipte what json-cpp README says, scons cannot be just unzipped, it has to be setup somehow. ARGH!

Luckily this time the solution turned out to be easy. There is a Visual C++ solution file in build\vs71 subdirectory. I managed to successfully convert it to Visual C++ 2008 version and compile it to static LIB files. I only had to ensure that the Runtime Library in Project Options is set to same type as in all my projects, that is the DLL version.

Comments | #c++ #libraries Share

# Parallelizing Algorithms with Intel TBB and C++ Lambdas

Aug 2010

My demo for RiverWash is practically finished. I still could polish it or even make some big changes, because I know it's not great, but that's another story. What I want to write about today is how easily an algorithm can be changed to run in parallel on multicore processors when you use Intel Threading Building Blocks and C++ lambdas.

First, here is an algorithm. In one of my graphic effects I fill a 256x512 texture on CPU every frame. For each pixel I calculate a color based on some input data, which are constant during this operation. So the code looks like this:

void SaveToTexture(const D3DLOCKED_RECT &lockedRect)
  uint x, y;
  char *rowPtr = (char*)lockedRect.pBits;
  for (y = 0; y < TEXTURE_SIZEY; ++y)
    XMCOLOR *pixelPtr = (XMCOLOR*)rowPtr;
    for (x = 0; x < TEXTURE_SIZEX; ++x)
      *pixelPtr = CalcColorForPixel(x, y);
    rowPtr += lockedRect.Pitch;

How to parallelize such loop? First, some theoretical background. Intel TBB is a free C++ library for high-level parallel programming. It has nice interface that makes extensive use of C++ language features but is very clean and simple. It provides many useful classes, from different kinds of mutexes and atomic operations, through thread-safe, scalable containers and memory allocators, till sophisticated task scheduler. But for my problem it was sufficient to use simple parallel_for function that utilizes the task scheduler internally. To start using TBB, I've just had to download and unpack this library, add appropriate paths as Include and Library directories in my Visual C++ and add this code:

#include <tbb/tbb.h>

#ifdef _DEBUG
#pragma comment(lib, "tbb_debug.lib")
#pragma comment(lib, "tbb.lib")

Second topic I want to cover here are lambdas - new, great language feature from C++0x standard, available since Visual C++ 2010. Lambdas are simply unnamed functions defined inline inside some code. What's so great about them is they can capture the context of the caller. Selected variables can be passed by value or by reference, as well as this pointer or even "everything". It makes them ideal replacement for ugly functors that had to be used in C++ before.

Summing it all together, parallelized version of my algorithm is not much more complicated than the serial version:

void SaveToTexture(const D3DLOCKED_RECT &lockedRect)
    tbb::blocked_range<uint>(0, TEXTURE_SIZEY),
    [this, &lockedRect](const tbb::blocked_range<uint> &range)
    uint x, y;
    char *rowPtr = (char*)lockedRect.pBits + lockedRect.Pitch * range.begin();
    for (y = range.begin(); y != range.end(); ++y)
      XMCOLOR *pixelPtr = (XMCOLOR*)rowPtr;
      for (x = 0; x < TEXTURE_SIZEX; ++x)
        *pixelPtr = CalcColorForPixel(x, y);
      rowPtr += lockedRect.Pitch;
  } );

This simple change made all my 4 CPU cores busy for 90+% and gave almost 4x speedup in terms of frame time, which is good result. So as you can see, coding parallel applications is not necessarily difficult :)

Comments | #libraries #rendering #c++ Share

# Music Analysis - Spectrogram

Jul 2010

I've started learning about sound analysis. I have some deficiencies in education when it comes to digital signal processing (greetings for the professor who taught this subject at our university ;) but Wikipedia comes to the rescue. As a starting point, here is a spectrogram I've made from one of my recent favourite songs: Sarge Devant feat. Emma Hewitt - Take Me With You.

Now I'm going to exaplain in details how I've done this by showing some C++ code. First I had to figure out how to decode an MP3, OGG or other compressed sound format. FMOD is my favourite sound library and I knew it can play many file formats. It took me some time though to find functions for fast decoding uncompressed PCM data from a song without actually playing it for all 3 minutes. I've found on the FMOD forum that Sound::seekData and Sound::readData can do the job. Finally I've finished with this code (all code shown here is stripped from error checking which I actually do everywhere):

Read full entry > | Comments | #math #libraries #music #rendering #dsp #algorithms Share

# Smarty Cheatsheet

Jun 2010

I knew about this before, but today I've found some time to deeply study Smarty - a free template engine for PHP. Templates in webdev (not to confuse with templates in C++) look like an interesting concept, because they separate PHP code from HTML code. I wish I used them from the start during coding my homepage and the www.gamedev.pl website instead of print()-ing HTML tags directly...

Anyway, I've written a small Smarty Cheatseet. Of course it makes sense only after studying the original library documentation, it cannot replace it.

By the way, I was also looking for some PHP library for creating RSS or ATOM feeds and I've found Feedcreator. Now I'm going to make something useful with it...

NEW: This "something" is an RSS feed for newest screenshots uploaded into www.gamedev.pl website: Feed Warsztat - Screeny, as well as for projects: Feed Warsztat - Projekty.

Comments | #webdev #php #libraries Share

# Some Thoughts about Library Design

May 2010

Much has been said about designing good user interface, whether for desktop applications, websites or games. There are whole books available about GUI design and even this year's IGK-7'2010 conference featured two lectures about the interface in games. But what about interfaces for programmers?

I can't find much about the rules of good library API design and I believe there is much to say in this subject. I only know The Little Manual of API Design written by Jasmin Blanchette from Trolltech/Nokia, one of the creators of Qt library (thanks for the link Przemek!). There is also a blog entry about Math Library, which is quite interesting. Inspired by it, I've came up with a general thought that you cannot have all the following features when designing a library and its API, you have to choose 2 or 3 of them and make some compromise:

I think some patterns and best practices as well as some anti-patterns could be found when you look at interfaces of many libraries. Maybe I'll post some more of my thoughts on this subject in the future. In the meantime, do you know any other resources about API design?

Comments | #philosophy #software engineering #libraries Share

Pages: 1 2 3 4 >

[Stat] [STAT NO AD] [Download] [Dropbox] [pub] [Mirror]
Copyright © 2004-2017