All Blog Entries

All blog entries, ordered from most recent. Entry count: 1198.

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

Pages: > 1 ... 40 41 42 43 44 ... 150 >

# Nowe życie w Gdańsku

Mon
14
Nov 2011

Myślę, że mogę teraz oficjalnie powiedzieć, czym zajmowałem się ostatnio: Po raz kolejny zacząłem nowe życie. Tym razem mieszkam w Gdańsku i pracuję dla Intel Technology Poland. Jako "Graphics Software Engineer" będę programował sterowniki do układów graficznych Intela.

Chciałbym przy tym podziękować wszystkim, którzy moje 3,5 roku spędzone w Warszawie uczynili tak wspaniałym doświadczeniem. Zawsze marzyłem aby mieszkać w dużym mieście. Dlatego żyjąc w Warszawie starałem się nie narzekać na korki, tłok czy hałas, za to wciąż odkrywać i doceniać ogromną ilość obecnych tam ciekawych miejsc, wydarzeń i przede wszystkim osób, z którymi warto się spotykać. Przechodząc w weekendowy wieczór pod tak nielubianym przez wielu Pałacem Kultury za każdym razem w jakiś tajemniczy sposób czułem się szczęśliwy, że teraz jestem właśnie tutaj - świadomy, że w ten sposób spełniło się moje marzenie.

Metropolis Software - moją pierwszą pełnoetatową pracę - wspominam bardzo dobrze, mimo że ostatecznie firma została zamknięta, a nasza gra They niedokończona. Szczególnie zapadła mi w pamięci atmosfera, jaka tam panowała. Równie ciekawym doświadczeniem była praca w Cyfrowym Polsacie. Poza pracą... to właśnie Warszawie zdobyłem cenne doświadczenie zawodowe, jak i życiowe. Zainteresowałem się nieco fotografią, jak również odkryłem muzykę Psychedelic Trance. Przede wszystkim jednak poznałem mnóstwo fantastycznych ludzi. Dlatego dziękuję za wspólnie spędzony czas i pozdrawiam: kolegów (i Iwonę) z Metropolis Software, Kubę (Willard) i wszystkich kolegów z Cyfrowego Polsatu, wszystkich ze światka polskiego gamedevu, których miałem okazję poznać przy piwkiu, Tomka (Dab) i wszystkich z Warsztatu, z którymi mogłem porozmawiać na żywo na warsztatowych spotkaniach, członków koła Polygon na PW, organizatorów i uczestników RiverWash oraz innych demoscenowców (w tym Tomka (tdc) i scenowców od 8-bitowego Atari), Andrzeja (L3v), Igę (Nell-Bluebell) i wszystkich pozytywnych ludzi słuchających transów, Michała i innych, których tu nie wymieniłem, chociaż powinienem.

To na pewno nie koniec naszej znajomości, ale przeprowadzka do innego miasta to ogromna zmiana i duże wyzwanie. Mam nadzieję, że życie tu okaże się jeszcze lepsze, nie tylko pod względem zawodowym :)

Comments | #life Share

# Copernicus Science Centre

Wed
02
Nov 2011

Some time ago this year I've been in Copernicus Science Centre in Warsaw. It's a huge interactive museum presenting numerous experiments from different fields of science. Of course for me most interesting was the stuff related to images, shapes and colors. There was a long queue near the entrance of the building and visiting all the exhibits - even briefly, took a lot of time, but still if you come to Warsaw and have a whole free day, I really recommend visiting Copernicus Science Centre. Here are my photos: Centrum Nauki Kopernik @ Picasa:

Comments | #events #gallery Share

# jEdit Doesn't Start

Sun
30
Oct 2011

jEdit is a free, multi-platform and my favorite text editor intended for programmers. Some time ago I encountered a problem with it, which repeated again today. So in case you also use this editor or found this post by searching Google, here is the solution:

Problem: jEdit (on Windows) doesn't start. Process is created and exists in memory, but it does nothing and shows no windows, so the only thing you can do is terminating it.

Solution: Terminate the jEdit process and the process of Java virtual machine, then browse to your user directory (like "C:\Users\Adam Sawicki" on my Windows 7) and delete the following small file in a sudirectory: ".jedit\server". After that you will be able to successfully start jEdit.

Comments | #java #tools #windows Share

# Circular Buffer of Raw Binary Data in C++

Fri
21
Oct 2011

Circular Buffer, Cyclic Buffer or Ring Buffer is a data structure that effectively manages a queue of some items. Items can be added at the back and removed from the front. It has limited capacity because it is based on preallocated array. Functionality is implemented using two pointers or indices - pointing to the first and past the last valid element. The Begin pointer is incremented whenever an item is popped from the front so that it "chases" the End pointer, which is incremented whenever a new item is pushed to the back. They can both wrap around the size of the array. Both operations are done very effectively - in constant time O(1) and no reallocations are needed. This makes circular buffers perfect solution for queues of some data streams, like video or audio.

It's not very sophisticated data structure, but there is one problem. Sample codes of circular buffers you can find on the Internet, just like for many other data structures, operate usually on a single object of some user-defined type. What if we need a buffer for raw binary data, stored as array of bytes? We can treat single bytes as data items, but enqueueing and dequeueing single bytes with separate function calls would not be efficient. We can, on the other hand, define some block of data (like 4096 bytes) as the type of item, but this limits us to operating on on such block at a time.

Best solution would be to write an implementation that operates on binary data in form of (const char *bytes, size_t byte_count) and allows writing and reading arbitrary amount of data in a single call, just like functions for writing and reading files do. The only problem that arises in such code is that sometimes the block of data you want to write to or read from the buffer is not in a continuous region of memory, but wraps around to the beginning of the array so we have to process it on two parts - first at the end of the array and the second at the beginning.

Here is my C++ implementation of a circular buffer for raw binary data:

#include <algorithm> // for std::min

class CircularBuffer
{
public:
  CircularBuffer(size_t capacity);
  ~CircularBuffer();

  size_t size() const { return size_; }
  size_t capacity() const { return capacity_; }
  // Return number of bytes written.
  size_t write(const char *data, size_t bytes);
  // Return number of bytes read.
  size_t read(char *data, size_t bytes);

private:
  size_t beg_index_, end_index_, size_, capacity_;
  char *data_;
};

CircularBuffer::CircularBuffer(size_t capacity)
  : beg_index_(0)
  , end_index_(0)
  , size_(0)
  , capacity_(capacity)
{
  data_ = new char[capacity];
}

CircularBuffer::~CircularBuffer()
{
  delete [] data_;
}

size_t CircularBuffer::write(const char *data, size_t bytes)
{
  if (bytes == 0) return 0;

  size_t capacity = capacity_;
  size_t bytes_to_write = std::min(bytes, capacity - size_);

  // Write in a single step
  if (bytes_to_write <= capacity - end_index_)
  {
    memcpy(data_ + end_index_, data, bytes_to_write);
    end_index_ += bytes_to_write;
    if (end_index_ == capacity) end_index_ = 0;
  }
  // Write in two steps
  else
  {
    size_t size_1 = capacity - end_index_;
    memcpy(data_ + end_index_, data, size_1);
    size_t size_2 = bytes_to_write - size_1;
    memcpy(data_, data + size_1, size_2);
    end_index_ = size_2;
  }

  size_ += bytes_to_write;
  return bytes_to_write;
}

size_t CircularBuffer::read(char *data, size_t bytes)
{
  if (bytes == 0) return 0;

  size_t capacity = capacity_;
  size_t bytes_to_read = std::min(bytes, size_);

  // Read in a single step
  if (bytes_to_read <= capacity - beg_index_)
  {
    memcpy(data, data_ + beg_index_, bytes_to_read);
    beg_index_ += bytes_to_read;
    if (beg_index_ == capacity) beg_index_ = 0;
  }
  // Read in two steps
  else
  {
    size_t size_1 = capacity - beg_index_;
    memcpy(data, data_ + beg_index_, size_1);
    size_t size_2 = bytes_to_read - size_1;
    memcpy(data + size_1, data_, size_2);
    beg_index_ = size_2;
  }

  size_ -= bytes_to_read;
  return bytes_to_read;
}

Similar phenomenon can be observed in API of the FMOD sound library. Just like graphical textures in DirectX, sound samples in FMOD can also be "locked" to get pointer to a raw memory we can read or fill. But DirectX textures lie in the continuous memory region, so we get a single pointer. The only difficult thing in understanding locking textures is the concept of "stride", which can be greater than the width of a single row. Here in FMOD the Sound::lock() method returns two pointers and two lengths, probably because the locked region can wrap over end of internally used circular buffer like the one shown above.

Comments | #c++ #algorithms Share

# Easiest Way to Generate a Bitmap

Wed
19
Oct 2011

I wanted to visualize results of some mathematical computations so I wondered what is the easiest way to generate and then show or save a bitmap? I considered Scilab, PHP with GD library, C++ with WinAPI GDI, C++ with some library that have image file formats support like FreeImage... Finally I've came up with the following solution, using only C++ and WinAPI to fill appropriate data structures and save the image as 24-bit BMP file.

// Width and height of the bitmap
unsigned size_x = 1280, size_y = 720;
// Rows top-down,
// for each row pixels from left to right,
// for each pixel components B, G, R = 0..255.
unsigned data_size = size_x * size_y * 3;
unsigned char *data = new unsigned char[data_size];

// Here fill the data, for example:
for (unsigned y = 0, i = 0; y < size_y; ++y) {
  for (unsigned x = 0; x < size_x; ++x) {
    data[i++] = 255; // G
    data[i++] = 255; // B
    data[i++] = 255; // R
  }
}

// Prepare data structures
DWORD data_offset = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
DWORD file_size = data_offset + data_size;
BITMAPFILEHEADER file_header = {
  0x4D42, // bfType = "BM"
  file_size, // bfSize
  0, 0, // bfReserved1, bfReserved2
  data_offset, // bfOffBits
};
BITMAPINFOHEADER info_header = {
  sizeof(BITMAPINFOHEADER), // biSize
  (LONG)size_x, -(LONG)size_y, // biWidth, biHeight
  1, // biPlanes
  24, // biBitCount
  BI_RGB, // biCompression
  0, // biSizeImage
  72, 72, // biXPelsPerMeter, biYPelsPerMeter
  0, 0, // biClrUsed, biClrImportant
};

// Save file
FILE *file = fopen("file_name.bmp", "wb");
fwrite(&file_header, sizeof(file_header), 1, file);
fwrite(&info_header, sizeof(info_header), 1, file);
fwrite(&data[0], 1, data_size, file);
fclose(file);

// Finalize
delete [] data;

Comments | #rendering #winapi #c++ Share

# Vector Register Size - Diagram

Thu
29
Sep 2011

It may be hard to imagine and remember what is the exact number of bits, bytes, words or floats in some piece of data, like a SIMD register. So today I've made following diagram/cheatsheet:

Vector Register Size Diagram - SIMD, MMX, SSE, AVX registers

Here you can find its "source" in OpenOffice Draw format: Vector_register_size.odg.

Comments | #hardware #math Share

# Handling Ctrl+C in Windows Console Application

Wed
28
Sep 2011

Just a small code snippet: Let's say you write a console application in native C++ for Windows. Closing the console by pressing Ctrl+C, Ctrl+Break or clicking on close window button [X] kills the process. Is there any way to handle such event and close the program gracefully? The answer is calling SetConsoleCtrlHandler() WinAPI function and implementing your own HandlerRoutine callback function. The template looks like this:

// Handler function will be called on separate thread!
static BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType)
{
  switch (dwCtrlType)
  {
  case CTRL_C_EVENT: // Ctrl+C
    break;
  case CTRL_BREAK_EVENT: // Ctrl+Break
    break;
  case CTRL_CLOSE_EVENT: // Closing the console window
    break;
  case CTRL_LOGOFF_EVENT: // User logs off. Passed only to services!
    break;
  case CTRL_SHUTDOWN_EVENT: // System is shutting down. Passed only to services!
    break;
  }

  // Return TRUE if handled this message, further handler functions won't be called.
  // Return FALSE to pass this message to further handlers until default handler calls ExitProcess().
  return FALSE;
}

int main(int argc, char **argv)
{
  SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
  ...
}

If your program performs some loop and you want the user to be able to break it by closing the console or pressing Ctrl+C, you can solve it this way:

static volatile bool g_exit = false;

static BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType)
{
  g_exit = true;
  return TRUE;
}

int main(int argc, char **argv)
{
  SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
  initialize();
  while (!g_exit)
    do_a_piece_of_work();
  finalize();
}

Comments | #windows #winapi #c++ Share

# Windows 8 Developer Preview

Thu
15
Sep 2011

News about upcoming Windows 8 appear for some time. Information about the new Windows version directly from Microsoft, including technical details for developers, can be found in this PDF: Windows Developer Preview - Windows 8 guide. Recently Microsoft shared a full, development version of this system to download, install and test on your computer for free. It's a developer preview - it contains the new operating system along with new Visual Studio 11. You can download it as ISO image from Windows Developer Preview downloads. The system works in VirtualBox virtual machine. You can see my first gallery of screenshots here:

My first impressions after testing Windows 8 are... quite weird. Apparently they try to make desktop OS looking like a cellphone, with big fonts and all apps working in fullscreen. But that's only a half-truth. I feel that in Microsoft they always do it this way: a boss comes and tells that "we do it again from scratch only better, redefine everything, but we have to preserve backward compatibility", then a developer thinks how to implement it the simplest possible way and it ends in a new flashy UI containing several shortcuts to the most important commands with the old, good windows hiding somewhere under "Advanced" button. It was the same with Control Panel, with formatting functions in MS Office and now it's the same with the whole Desktop. You are presented a new screen full of colourful rectangles, but as soon as you move your cursor to the bottom-left corner of the screen and click "Start", you are teleported to the normal desktop with a wallpaper, taskbar and the Recycle Bin :)

Other things that attracted my attention: You now login to Windows using your Windows Live ID account. System is integrated with Facebook by providing some application to browse it. Explorer now uses the new Ribbon toolbar, just like new versions of MS Office, Paint or WordPad do for some time. There are lots of new games. New Task Manager is great because it now shows four columns with all most important statistics of every running program: the usage of CPU time, RAM memory, disk transfer and network transfer. Finally the new UI style: flat, colourful, minimalistic, full of solid filled rectangles.

Comments | #windows #visual studio #gui Share

Pages: > 1 ... 40 41 42 43 44 ... 150 >

[Download] [Dropbox] [pub] [Mirror] [Privacy policy]
Copyright © 2004-2026