January 2011

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

18:04
Tue
18
Jan 2011

PolyJam - Global Game Jam 2011 in Warsaw

Global Game Jam is a worldwide initiative to organize a 48-hour game development competition in many different locations, at the same time. For more information, read the extensive GGJ Wiki. This year it takes place on January 28-30. In Poland there are even 3 registered places. KrakJam takes place at AGH University in Kraków. It is organized second time, by Koshmaar and the "Shader" scientific group.

For the first time the competition will also be held in Warsaw. It's called PolyJam and it's organized by "Polygon" scientific group at Warsaw University of Technology. Here is the list of PolyJam jammers. I invite everyone who is interested in game development (not only programming, but also graphics, sound, game design and other disciplines) to register.

I'm going to participate, yet I'm not quite sure how the atmosphere of such event looks like. What's the best approach to creating games at such competitions? Is it making a simple 2D game from scratch using some simple C++ framework, using some middleware like Unity, or maybe developing a web game in JavaScript of Flash?

Comments (0) | Tags: competitions events ggj | Author: Adam Sawicki | Share

20:12
Mon
17
Jan 2011

New jEdit Launcher - How to Install

Writing programs in some managed technologies like Java or .NET instead of native C/C++ has many disadvantages. First and the most obvious one is smaller efficiency and greater memory consumption. That's why, for example, I prefer uTorrent over Azureus as BitTorrent client. Second flaw is harder access to native system API. That's why my friend Przemek created libraries for accessing new Windows 7 taskbar features from Java, Python and Qt code and sells them as his startup Strix Code.

Finally it's sometimes harder to integrate such programs with system shell. With .NET it's not the case because it creates EXE files so they can work as normal programs and even system services (I'm not sure about shell extensions and device drivers). With Java it's more difficult because there program is a JAR file. As jEdit is still my favourite text editor (second after Visual C++ of course), I was looking for a way to integrate it with Windows so it was my default editor for TXT and other text files. Recently I've found New jEdit Launcher - a package that serves this purpose very well, but unfortunately it's quite hard to setup. So in case you also use jEdit and look for a way to do it, here are the steps, checked under Windows XP as well as 7:

  1. Unpack New jEdit Launcher to some directory. Windows 7 causes lots of problems with Program Files so I prefer some other places, let's say "h:\Program_Files\New jEdit Launcher".
  2. Run command prompt ("cmd.exe"). On Windows 7 you must do it as Administrator, so open Start menu, type "cmd", right-click on the black "cmd.exe" icon and select "Run as administrator".
  3. From the command prompt, enter the "bin" subdirectory of New jEdit Launcher like this:
    > h:
    > cd "\Program_Files\New jEdit Launcher\bin"
  4. Call the magic command to register DLL file:
    > regsvr32 jeditext.dll
  5. Now launch registery editor through Start > Run > "regedit" and create entries as decribed in "New jEdit Launcher\README.html" documentation in "Installing" section.
  6. Second bunch of required registry entries (described in "Configuration" section) can be entered more conveniently, through "New jEdit Launcher\config\launcher.reg" file. Open this file in some text editor (Notepad or... jEdit :) and fix the paths to your Java JRE and jEdit directories. Enter path to "javaw.exe" not "java.exe" as the "Java Executable", because you don't want system console to be shown along with jEdit window. Values "jEdit Target" and "jEdit Working Directory" must point to the place where you have jEdit installed. Don't forget that all backslashes in these paths must be doubled, like "h:\\Program_Files\\jEdit 4.3.2\jedit.jar"!!!
  7. Now run this "launcher.reg" file through double-clicking on it. After confirming the warning/question, the registry entries should be created.
  8. Check if it works by running "New jEdit Launcher\bin\jedit.exe" file. jEdit should be started if it wasn't already running.
  9. You can create a shortcut to this "jedit.exe" file in your Start menu. This way you have a shortcut to jEdit with pretty icon instead of default Java one, as when linking directly to the "jedit.jar" file.
  10. Associate TXT and possibly other file types (extensions) with this "jedit.exe" program. It's done differently in Windows XP and 7 but generally you can find the appropriate configuration window it in the Control Panel. This way all text files will be opened by jEdit and they also (unfortunately) get jEdit icon.

Comments (1) | Tags: windows | Author: Adam Sawicki | Share

11:35
Sat
08
Jan 2011

Origami - Super Spike Ball

As the Spike Ball Heaven website shows, an origami module with four tabs and four pockets invented by Rona Gurkewitz and Bennett Arnstein can be assembled into three sizes of spike balls - Spike Ball (from 12 pieces), Super Spike Ball (from 24 pieces) and Super Duper Spike Ball (from 54 pieces). Recently I've made the Super Spike Ball - it's the one on left left. I don't plan to try the third size anytime soon :)

Comments (0) | Tags: origami | Author: Adam Sawicki | Share

19:22
Fri
07
Jan 2011

Process Class Deadlocks on Long Lines when Redirecting Output

To run a console process programatically from your program and capture its output is very difficult to do right. There are so many possible problems! Not only you have to pass correct command line parameters and escape them if they contain special characters like space, care about working directory and maybe even environmental variables. You must also handle different possible behavior of the program. For example, it can freeze indefinitely, so you better do some timeout when waiting for it to exit. It may ask for additional console input and wait for it. It may print some information on both of its outputs - "standard output" and "standard error". They are all asynchronous and you better capture these data because if a buffer fills up, the program will hang waiting until you consume this output to allow it to post more. You also have to read these buffers to the end after program exited because there may still be some bytes remaining.

I do it in C# and I was hoping I already did it all right... Until today. I wanted to run "mysqldump" and capture its output to store a MySQL database table in memory and then import it on another machine. But when exporting a table with large binary data in its BLOB fields, my program hung. My code was like this:

using System.Text;
using System.Diagnostics;
using System.Threading;

class ConsoleCommand
{
  public void Execute(string fileName, string arguments, int timeout, string standardInputData)
  {
    using (Process process = new Process())
    {
      process.StartInfo.FileName = fileName;
      process.StartInfo.Arguments = arguments;
      process.StartInfo.RedirectStandardInput = true;
      process.StartInfo.RedirectStandardOutput = true;
      process.StartInfo.RedirectStandardError = true;
      process.StartInfo.UseShellExecute = false;
      process.StartInfo.CreateNoWindow = true;
      process.OutputDataReceived += new DataReceivedEventHandler(StandardOutputHandler);
      process.ErrorDataReceived += new DataReceivedEventHandler(StandardErrorHandler);
      process.Start();
 
      process.BeginOutputReadLine();
      process.BeginErrorReadLine();
 
      if (standardInputData != null)
      {
        process.StandardInput.Write(standardInputData);
        process.StandardInput.Close();
      }
 
      if (!process.WaitForExit(timeout))
        throw new Exception("Process execution timeout.");
      m_StandardOutputEvent.WaitOne();
      m_StandardErrorEvent.WaitOne();
 
      m_ExitCode = process.ExitCode;
    }
  }

  public int ExitCode { get { return m_ExitCode; } }
  public string StandardOutputData { get { return m_StandardOutputData.ToString(); } }
  public string StandardErrorData { get { return m_StandardErrorData.ToString(); } }

  private void StandardOutputHandler(object process, DataReceivedEventArgs e)
  {
    if (e.Data == null)
      m_StandardOutputEvent.Set();
    else
      m_StandardOutputData.AppendLine(e.Data);
  }

  private void StandardErrorHandler(object process, DataReceivedEventArgs e)
  {
    if (e.Data == null)
      m_StandardErrorEvent.Set();
    else
      m_StandardErrorData.AppendLine(e.Data);
  }

  private int m_ExitCode;
  private StringBuilder m_StandardOutputData = new StringBuilder();
  private StringBuilder m_StandardErrorData = new StringBuilder();
  private ManualResetEvent m_StandardOutputEvent = new ManualResetEvent(false);
  private ManualResetEvent m_StandardErrorEvent = new ManualResetEvent(false);
}

I couldn't find any solution on the Internet. That's why I write about it here - maybe some day someone (you?) who has same problem finds this article on Google. I know it must have something in common with binary data on the output, so I coded a small program that printed all possible ASCII characters. It worked. So there was not the problem with characters codes, but with the length of the data. The delegate associated with OutputDataReceived and ErrorDataReceived is designed to handle text lines. I suppose there is an internal buffer somewhere inside .NET that splits the text into lines. If there is a lot of data (more than 1 MB) in a single line (binary data without end-of-line character), the buffer fills up, neither OutputDataReceived delegate is called, nor the console program is able to print more output and everything just deadlocks :(

The only solution I know at the moment is not to use these OutputDataReceived and ErrorDataReceived events, but to poll for output data synchronously like this:

class ConsoleCommand
{
  public void Execute(string fileName, string arguments, int timeout, string standardInputData)
  {
    using (Process process = new Process())
    {
      process.StartInfo.FileName = fileName;
      process.StartInfo.Arguments = arguments;
      process.StartInfo.RedirectStandardInput = true;
      process.StartInfo.RedirectStandardOutput = true;
      process.StartInfo.RedirectStandardError = true;
      process.StartInfo.UseShellExecute = false;
      process.StartInfo.CreateNoWindow = true;
      process.Start();

      if (standardInputData != null)
      {
        process.StandardInput.Write(standardInputData);
        process.StandardInput.Close();
      }

      DateTime end_time = DateTime.Now + TimeSpan.FromMilliseconds((double)timeout);
      bool process_exit = false, output_end = false, error_end = false;
      for (;;)
      {
        if (!output_end)
        {
          if (process.StandardOutput.EndOfStream)
            output_end = true;
          else
            m_StandardOutputData.Append(process.StandardOutput.ReadToEnd());
        }

        if (!error_end)
        {
          if (process.StandardError.EndOfStream)
            error_end = true;
          else
            m_StandardErrorData.Append(process.StandardError.ReadToEnd());
        }

        if (!process_exit)
          process_exit = process.WaitForExit(0);

        if (DateTime.Now > end_time)
        {
          process.Close();
          throw new Exception("Process execution timeout.");
        }

        if (process_exit && output_end && error_end)
          break;

        System.Threading.Thread.Yield();
      }

      m_ExitCode = process.ExitCode;
    }
  }

  public int ExitCode { get { return m_ExitCode; } }
  public string StandardOutputData { get { return m_StandardOutputData.ToString(); } }
  public string StandardErrorData { get { return m_StandardErrorData.ToString(); } }

  private int m_ExitCode;
  private StringBuilder m_StandardOutputData = new StringBuilder();
  private StringBuilder m_StandardErrorData = new StringBuilder();
}

Comments (1) | Tags: .net | Author: Adam Sawicki | Share

11:20
Thu
06
Jan 2011

Data-Oriented Design - Links and Thoughts

In April 2008 I've written an essay "Fanatyzm obiektowy" (in Polish, it means "Object-Oriented Fanaticism"). I've always believed there is something wrong with object-oriented programming, that it simply doesn't meet its own objectives and so following it blindly as an ideology not only a programming language mechanics has many pitfalls. Now I'm glad that recently a concept of "Data-Oriented Design" (DOD) emerged and gained popularity among game developers. Here is my try to aggregate all important information on this subject that can be found on the Internet:

Slides:

Blog entries:

Other:

If you know any other good readings on this subject, please leave a comment. I'll update my list.

As far as I can see, focusing more on data instead of objects gives a number of benefits for the code:

Of course DOD doesn't exist in the void. It's related to many other concepts and you can find many good sources of knowledge about each one. Some of them are:

Comments (26) | Tags: software engineering c++ | Author: Adam Sawicki | Share

00:40
Thu
06
Jan 2011

My Talk about OOP on Polygon Group - Slides

Here are slides from my today presentation - "Pu³apki programowania obiektowego" (in Polish): PDF, PPTX.

Comments (0) | Tags: teaching events | Author: Adam Sawicki | Share

22:09
Tue
04
Jan 2011

Generating LIB File for DLL Library

I've been recently trying to use libVLC - functionality of great, codec-less VLC media player enclosed in form of DLL library. By the way I've came across a great article: GenerateLibFromDll and now I know how to generate LIB file for any DLL library! Here is detailed description of the problem:

When you have a DLL library you want to use in your C++ code, you may do it dynamically by using LoadLibrary and GetProcAddress functions from WinAPI, but it's more convenient to do it statically. But it's not enough to just #include signatures of library functions and use them in your project. You also need to link with some LIB file, event if the file is not a real static library with compiled code, but only a few-kilobyte-long list of imported functions. I believe that's just another flaw of C++ language, because other languages like for example C# don't need this even when importing functions from native DLL libraries.

If you have some SDK prepared for Visual C++ or compile the library by yourself, you also get the LIB file next to DLL. But if you have only the library, that article shows following steps to generate matching LIB:

1. From Start menu run "Visual Studio Command Prompt".

2. Execute command:

dumpbin /exports DLL_FILE.dll > DEF_FILE.def

This command prints some information about given DLL library in textual form to its standard output. We redirect it to a text file with DEF extension. But to make it real DEF file, we need to edit it.

3. Open DEF_FILE.def in some text editor and edit it to contain only the names of exported functions in form of:

EXPORTS
function_1_name
function_2_name
function_3_name
...

4. From the Visual Studio Command Prompt, execute another command:

lib /def:DEF_FILE.def /out:LIB_FILE.lib /machine:x86

And there you have it! The so much required LIB file generated from DLL library. You only need signatures of these functions with proper parameters and return values declared in some H header file and you can successfully use your DLL by linking with LIB file created by yourself :)

Comments (2) | Tags: winapi windows c++ visual studio | Author: Adam Sawicki | Share

18:25
Mon
03
Jan 2011

My Talk about OOP on Polygon Group

This Wednesday on the Polygon scientific group I'll give a talk titled "Pu³apki programowania obiektowego" ("Pitfalls of Object-Oriented Programming" - but that's just a translation, not to be confused with great English article with same title). It will be a polemics with the recent Veldrin's presentation on design patterns and also another expression of my interest in the topic of DOD (Data-Oriented Design). I'll post more on this subject soon, including slides from my presentation.

Comments (1) | Tags: teaching events | Author: Adam Sawicki | Share

13:34
Sun
02
Jan 2011

Origami: Platonic Solids?

Here are all solids I managed to assemble from origami Sonobe module that look like regular polyhedra. I know 4 of them and I wonder if there are some more possible? Are there somehow related to the concept of platonic solid?

Comments (1) | Tags: origami | Author: Adam Sawicki | Share

STAT NO AD [Stat] [Admin] [STAT NO AD] [pub] [Mirror] Copyright © 2004-2013 Adam Sawicki
Copyright © 2004-2013 Adam Sawicki