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 ... 48 49 50 51 52 ... 150 >

# Technology for Data Processing

Mon
04
Oct 2010

When doing some engineering work on a computer, no matter if gamedev or any other field, there is sometimes a need to process or visualize some tabular data, especially numbers, e.g. statistics about performance or something gathered during program execution. What technology is best for this purpose? At the moment I know about following solutions:

Spreadsheet software, like Microsoft Excel or OpenOffice Calc. They can import CSV files and draw great variety of plots, but for more advanced data processing it would be useful to have something more like a programming language.

At the other end of the spectrum, we can write normal C++ or C# programs to do the work. It can be hard though as we have to code everything on our own, including data structures, loading files and drawing plots. It would be nice to use some higher-level, scripting language with rich standard library, built-in data structures and the like.

Any scripting language can do this. For example, PHP (which I know the best) can be used as a normal scripting language, not only in connection with a web server. All in all, its name means "PHP Hypertext Prerocessor", because it's suited for processing strings and text files.

A technology designed specially for the purpose of crunching numbers is Matlab and its free alternative - Scilab. It provides its own programming language with convenient built-in data types like matrix and is also able to draw plots.

Python is something in between - a normal scripting language with weird but nice syntax and a language-level support for operations like array slicing and complex numbers. It looks like many scientists and engineers use it for computation and data analysis, because there are Python libraries designed for this, like Numpy and Scipy.

There is also The R Project metioned at the Nick Darnells' Blog. It looks like another environment with its own, different programming language, designed especially for statistical computing. It can also load data from files and draw plots.

And finally, some tasks can be accomplished in environments that allow playing around with computer graphics, like EvalDraw (with its own, C-like simple programming language) or Processing (with a language based on Java).

So there are many possibilities in this subject. I've played a bit with all of them at some time, but obviously learning chosen one thoroughly would require much time and effort. So maybe you can help me decide? Which solution would you recommend? Personally I feel a little more convinced to Python, because it is a general purpose language that I can use in different fields too, like coding Blender plugins.

Comments | #math #languages #tools Share

# Sunday in Warsaw - a Time-Lapse Video

Sun
03
Oct 2010

I've made my first time-lapse video today. This is a technique in which you capture an image every several seconds, merge these images into a video and the result looks like the time is moving very fast. Here it is:

To make it, I used my webcam connected to my laptop (because USB cable was to short to connect it to my desktop PC :) Of course a special program had to be used to utilize webcam this way, taking snapshot to a JPEG file every several seconds. The program I used is booru WebCam 2.0. It does a good job and it's free, opposite to many others tools of its kind. The result of this program working for several hours was 805 MB of files named like "image-4887.jpg". I had to use another program to convert them to a video.

This can be done with powerful and free VirtualDub. It's not so obvious how to do it though, because there is no "Import images" command in the menu. Instead, one have to know that it's enough to issue a standard File / Open video file command and open first image with it. VirtualDub automatically recognizes subsequent images as video frames. Now the only thing that remained was to set Video / Frame Rate, Audio / Audio from other file, setup filters (resize in my case), video codec and encode final video with File / Export as AVI.

Comments | #video #tools Share

# Coding Windows Services in C++

Fri
01
Oct 2010

Services in Windows are like daemons in Linux - resident programs that work in background. I've recently learned how to code them in C++ using WinAPI. Here is a quick tutorial about this:

All the documentation you need to develop services can be found in MSDN Library. If you have it offline, go to: Win32 and COM Development / System Services / DLLs, Processes and Threads / SDK Documentation / DLLs, Processed, and Threads / Services. You can also read it online HERE. I talk only about native C and C++ code here, but services can also be written in .NET.

What are pros and cons of services, comparing to normal applications? Service can be automatically started with the system and work all the time, no matter if any user logs on and off. It can have extensive priviledges to access files on hard disk and the like, no matter what limitations do the logged-in user have. But service cannot interact directly with the user - it cannot show console or any window. So the only way for a service to do any input/output is to read some configuration files, write some log files or to communicate with some other client process ran by the user, e.g. via TCP socket connected to "localhost".

Service is written as a console application that uses special WinAPI functions to communicate with so called SCM - Service Control Manager. Example entry point routine looks like this:

// Standard console application entry point.
int main(int argc, char **argv)
{
    SERVICE_TABLE_ENTRY serviceTable[] = {
        { _T(""), &ServiceMain },
        { NULL, NULL }
    };
       
    if (StartServiceCtrlDispatcher(serviceTable))
        return 0;
    else if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
        return -1; // Program not started as a service.
    else
        return -2; // Other error.
}

StartServiceCtrlDispatcher is the first service-related function used here. It needs an array because a process can implement multiple different services, but I show only single-service process here. The function blocks for the entire execution time of working service and fails if program was run as normal application, not as a service. While service is working, a callback function is being executed, which I called ServiceMain here. It should initialize service and then execute all the code in loop until system wants to stop the service. You can also exit the function and thus stop the service at any time if you want (e.g. if some critical error occured).

// Main function to be executed as entire service code.
void WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
{
    // Must be called at start.
    g_ServiceStatusHandle = RegisterServiceCtrlHandlerEx(_T("SERVICE NAME"), &HandlerEx, NULL);
   
    // Startup code.
    ReportStatus(SERVICE_START_PENDING);
    g_StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    /* Here initialize service...
    Load configuration, acquire resources etc. */
    ReportStatus(SERVICE_RUNNING);

    /* Main service code
    Loop, do some work, block if nothing to do,
    wait or poll for g_StopEvent... */
    while (WaitForSingleObject(g_StopEvent, 3000) != WAIT_OBJECT_0)
    {
        // This sample service does "BEEP!" every 3 seconds.
        Beep(1000, 100);
    }

    ReportStatus(SERVICE_STOP_PENDING);
    /* Here finalize service...
    Save all unsaved data etc., but do it quickly.
    If g_SystemShutdown, you can skip freeing memory etc. */
    CloseHandle(g_StopEvent);
    ReportStatus(SERVICE_STOPPED);
}

RegisterServiceCtrlHandlerEx is a function that must be called first to register your application as a service, pass its name and a pointer to your control event handler function. Then you do some initialization, execute main service code in a loop and after it's time to stop it, do the cleanup and exit.

Service should report its state to the SCM with SetServiceStatus function. It can be called at any time and from any thread and informs the system about if your service is stopped, running, starting, stopping, paused etc. This function takes quite sophisticated SERVICE_STATUS structure, but I believe it can be simplified to three main cases which I enclosed in the following functions: ReportStatus reports basic status like SERVICE_STOPPED, SERVICE_RUNNING, SERVICE_START_PENDING or SERVICE_STOP_PENDING.

SERVICE_STATUS_HANDLE g_ServiceStatusHandle; 
HANDLE g_StopEvent;
DWORD g_CurrentState = 0;
bool g_SystemShutdown = false;

void ReportStatus(DWORD state)
{
    g_CurrentState = state;
    SERVICE_STATUS serviceStatus = {
        SERVICE_WIN32_OWN_PROCESS,
        g_CurrentState,
        state == SERVICE_START_PENDING ? 0 : SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN,
        NO_ERROR,
        0,
        0,
        0,
    };
    SetServiceStatus(g_ServiceStatusHandle, &serviceStatus);
}

Third member of the SERVICE_STATUS structure - dwControlsAccepted - indicates which events will be accepted by the service after this call. I want to accept events informing about system shutdown and allow user to stop the service. I could also pass SERVICE_ACCEPT_PAUSE_CONTINUE here, which means I supported pausing and resuming the service.

ReportProgressStatus function reports service status during initialization and finalization - SERVICE_START_PENDING, SERVICE_STOP_PENDING, SERVICE_CONTINUE_PENDING, SERVICE_PAUSE_PENDING. I don't actually use it, but if the startup or shutdown of your service takes a lot of time, you should periodically report progress with this function. CheckPoint is simply a counter that should be incremented with each call, telling that service is making some progress. WaitHint is an estimated time it will take to finish initialization, finalization or to perform its next step. By default, system waits about 30 seconds for your service to start or stop and you should not exceed that without a good reason.

void ReportProgressStatus(DWORD state, DWORD checkPoint, DWORD waitHint)
{
    g_CurrentState = state;
    SERVICE_STATUS serviceStatus = {
        SERVICE_WIN32_OWN_PROCESS,
        g_CurrentState,
        state == SERVICE_START_PENDING ? 0 : SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN,
        NO_ERROR,
        0,
        checkPoint,
        waitHint,
    };
    SetServiceStatus(g_ServiceStatusHandle, &serviceStatus);
}

Finally, there is a way for a service to shutdown and inform the system that some critical error occured. To do this, report SERVICE_STOPPED and pass error code. The code will be saved along with information about service failture to the system event log.

void ReportErrorStatus(DWORD errorCode)
{
    g_CurrentState = SERVICE_STOPPED;
    SERVICE_STATUS serviceStatus = {
        SERVICE_WIN32_OWN_PROCESS,
        g_CurrentState,
        0,
        ERROR_SERVICE_SPECIFIC_ERROR,
        errorCode,
        0,
        0,
    };
    SetServiceStatus(g_ServiceStatusHandle, &serviceStatus);
}

HandlerEx is a function to handle events sent by the system to control your service - stop it, pause, inform about the system shutdown or simply query for current status. You must always call SetServiceStatus in this function. It can be executed in different thread, so you must synchronize it with the code in ServiceMain. I do this with g_StopEvent - an event that will be set when the service should exit.

// Handler for service control events.
DWORD WINAPI HandlerEx(DWORD control, DWORD eventType, void *eventData, void *context)
{
    switch (control)
    {
    // Entrie system is shutting down.
    case SERVICE_CONTROL_SHUTDOWN:
        g_SystemShutdown = true;
        // continue...
    // Service is being stopped.
    case SERVICE_CONTROL_STOP:
        ReportStatus(SERVICE_STOP_PENDING);
        SetEvent(g_StopEvent);
        break;
    // Ignoring all other events, but we must always report service status.
    default:
        ReportStatus(g_CurrentState);
        break;
    }
    return NO_ERROR;
}

That's all the code I wanted to show. Now, because service cannot be run as normal program, you must learn how to install and uninstall it. Fortunately there is a simple command line program for this distributed with Windows - sc. To install your service, enter following command (exactly like this, with "binPath=" SPACE "PATH"):

sc create SERVICE_NAME binPath= FULL_PATH_TO_EXE_FILE

To uninstall it:

sc delete SERVICE_NAME

To control your service - start it, stop it or query its status - use commands:

sc start SERVICE_NAME
sc stop SERVICE_NAME
sc query SERVICE_NAME

Or simply run Administrative Tools / Services (another way to access it is Start / Run / "services.msc").

Two kinds of command line arguments can be passed to a service. First are argc, argv parameters taken by main function. They come from a command line fixed during installation of the service. Second are argc, argv arguments taken by ServiceMain function. They are different - argv[0] is the service name and the rest are arguments that you passed as additional parameters when calling "sc start" command.

Of course there is more to be told on this subject. Service can depend on some other services, can be automatically started with the system or only on demand, can have priviledges of a selected user or one of standard ones, like "LocalSystem" (biggest priviledges on local system, the default), "LocalService" or "NetworkService". See MSDN Library for details.

Comments | #c++ #windows #winapi Share

# Building JSON Parser Library for C++

Wed
29
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

# Allegro Party

Tue
28
Sep 2010

Last weekend I've been in Poznań on Allegro Party -  party for users of Allegro.pl - online auctions website. But we went there with my friends from the demoscene not only because we trade stuff online, but as organizers, as one of the highlights of the event were classic computers like Amiga or Commodore, ready to play good old games. Here are my photos from the event.

NEW: Some more information about this party (in Polish) can be found here:

Now I try to catch up with news on my Twitter and on the blogs I follow. One of these news in GPU Technology Conference by NVIDIA, which took place Sep 20-24, 2010 in San Jose, USA. Much interesting new graphics and HPC-related hardware and software have been shown there. Many coverages can be found over the Internet, like this one. What attracted my attention the most is a plenoptic lens technology presented by Adobe (I recommend the video at the bottom of this page). Their camera is equipped with a matrix of many small lenses, giving kind of a 4D image. It can be then processed to a single photo with software-controlled depth of field. There are also more than a hundred posters presented on the conference, available for download here. Posters is a nice form for presenting research results because it's short and attractive.

Comments | #events #demoscene Share

# Game Event, Technology Event

Sun
19
Sep 2010

Another interesting events took place recently. IDF - Intel Developer Forum (Sep 13-15, 2010, San Francisco, USA) is organized by just one company, but they've shown some interesting stuff there. Intel manufactures CPU-s as well as GPU-s, so there was something about hardware, as well as high-performance and parallel programming. Some topics from IDF are covered in recent entries of SoftTalk blog.

After E3 in USA and GC in Europe, this time there was a game event in Japan - TGS - Tokyo Game Show (16-19 Sep, 2010). As always, there is much new information and multimedia data after such event, like trailers and news about games under development. Some of them are specific to the exotic Japanese culture, but most of them is about games that will be available on the West too. I like watching trailers :)

Comments | #events #games Share

# reg__ @ Delicious

Thu
09
Sep 2010

I've decided to start using Delicious - a social bookmarking website. I collect and browse many interesting links every day. Until now I've been keeping my bookmarks in a text file that I share here: Links - gamedev.txt. But if bookmarks are about the Internet, why not keep them online too? Delicious looks like a very nice service for that purpose. I only have to switch from organizing my links in hierarchical categories to tagging. Unfortunately I can't find any fully-featured desktop application for Windows to manage Delicious bookmarks, just like I use Thunderbird for e-mail, RSSOwl for RSS and TweetDeck for Twitter. I've already started entering some of the interesting links I've recently found so here is my account:

reg__ @ Delicious

NEW: I still learn how to make good use of tags, but I've already entered most of my bookmarks from different places into Delicious. So I think it's also the time to drop my Links page. It no longer appears in the menu at the top, while I placed all my "social" website links there. For the list of my favourite blogs I regularly visit, see my following tag.

Comments | #web Share

# Riverwash 2010 - After the Party

Sun
05
Sep 2010

Riverwash 2010 is over. I had really great time there. What's best about such party is the opportunity to meet so many interesting people. The most important and awaited part - competitions - was also very nice experience. I especially liked intros and demos. There was only one 4k intro - "Quantum Core" by KK from DMA - but it was so awesome it shouldn't have problems winning even if it would have some competitors. There were 5 newschool demos and mine scored the last place. The one designed for anaglyph 3D glasses was especially impressing - I haven't seen such 3D effect on these simple glasses before.

Here are my photos from the party: Riverwash 2010 by sawickiap @ Picasa

And here is the demo I've submitted for the Newschool Demo Compo:

Comments | #demoscene #productions Share

Pages: > 1 ... 48 49 50 51 52 ... 150 >

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