May 2014

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.

22:48
Wed
28
May 2014

Offensive Programming :)

Generally, defensive programming is a very good idea. But many times I've seen this following C++ code explained as an example of defensive programming:

if(pointer != NULL) {
   pointer->SomeMethod();
   // Some other things with pointer.
}

If the pointer here is expected to always point to a valid object and not NULL, otherwise it's a programmer's bug somewhere else in the code, then I believe such practice is very, very bad. I think there should be an assertion instead, like this:

assert(pointer != NULL);
pointer->SomeMethod();
// Some other things with pointer.

First of all, assertion is compiled only in debug configuration, while condition would be additional code executed in all builds, unnecessarily impacting performance. Second and more important argument is that when there is a bug and the pointer is NULL, we should know about it as soon as possible and be able to debug this particular place. That's easy when we put an assert. That's also easy when we dereference NULL pointer, because then the application would crash, which is also possible to catch in the debugger. On the other hand, when there is a condition around code using this pointer and the pointer is NULL, the code inside is just not executed, which may somehow corrupt or just propagate corrupted state of the program, hide the bug or defer its appearance for later time and to different place of the code, making it harder to find. Recommending to crash the app could sound radical, so let's call this "offensive programming" :)

Comments (2) | Tags: c++ | Author: Adam Sawicki | Share

23:40
Mon
19
May 2014

Simple 2-digit Method of Task Management

Managing some list of tasks to do (or "TODO list") is very important skill that helps in both work and everyday life. I usually use GTD (Getting Things Done) method. But sometimes, like on the recent Hack3city competition, a simpler method is more suitable.

A lot could be said about this subject (maybe some day I write an article or prepare a presentation about it). Generally, tasks to do can be organized based on different criteria, like:

Even after "filtering" only tasks that you can do and you should as soon as possible, they can be sorted in three different "dimensions":

  1. Difficulty: how difficult/big/time consuming the task is.
  2. Importance: How important is it to do this or consequences of not doing it.
  3. Urgency: How much this task should be done as soon as possible.

It's obvious that not all the tasks will be done. During a 2-day programmers' competition, just like in everyday life, writing down ideas for doing things is good, but there is never enough time to complete them all. That's why there is a need for some method of deciding what to do next. During Hack3city, I came up with a simple, ad hoc method, which I want to describe here. The goal of developing it was to make the bookkeeping of the list as quick and easy as possible.

During a hackathon like Hack3city, where we created most of our game in just 2 days, the 3rd dimension is not important. Sure sometimes something must be coded quickly because artist or level designer is waiting for it to be able to continue his work. Then I do this first. But otherwise all tasks are equally urgent - they should be done in the short amount of time, during the event. So what I did was I opened the system Notepad and started writing down tasks and all ideas that should be/could be added to our game, one line each. But instead of starting a line with "-" for just a bullet, I started it with two digits, meaning:

Normally I just delete lines with tasks I finished, but since some time during the event, I started to move them to "DONE" section instead to show them later in this post. So here is partial task list from our game:

23 smoke effect when player falls onto the ground
22 flashlight rotates when player dies
23 flashlight rotates following player walking animation
31 spear, shooting from a wall when player pushes a button
12 delay appearance of "game over" text
22 push button
12 door that can be opened
13 red eye of zombie should pulse and blink
13 graphics in the menu instead of text
31 sound effects
33 fix ladder climbing animation
31 fix double-jump bug
22 walking sound effects should be played randomly
12 parallax for moving background
21 bug: player death animation doesn't work
11 playsoft logo
12 music
12 zombie: add hysteresis to the decision weather approach the player
21 death from the spikes
12 turning flashlight on and off
22 there are some bugs/spiders walking on the floor
33 a spiked ball on a chain, hanging and swinging from the ceiling

Of course the list of tasks was constantly changing as artist, level designer and me came up with new ideas or decided that something is more or less important, found new bugs during testing etc. But I tried to concentrate on finishing one thing at time. When finished, I picked up next task to do according to following rule: I reviewed whole list to find a task with the smallest sum of its numbers. So the order in which I was doing the tasks was:

This way we managed to accomplish most of the tasks we planned so we were quite satisfied with our game as it looked and worked pretty much as we planned. That's why I believe this simple 2-digit method of managing task list is good for hectic, time-constraint and constantly changing work environment.

Comments (1) | Tags: events competitions productivity hack3city | Author: Adam Sawicki | Share

21:36
Wed
14
May 2014

Hack3city 2014 - Review

5-11 May 2014 there was first edition of Hack3city - a hackathon in Gdańsk, Poland. It was interesting and unusual in many ways. First of all, there were 4 different tracks, so each developer could choose what is interesting to him.

Teams could have up to 3 people. Of course I was in the Playsoft track. We made a game together with Arek Duchnowski and Marcin Szymczak, who work in aideMMedia.

On Monday evening there was an official beginning (and free beer :) That's when themes of each track were announced. During the week we could work on our projects from home. On Saturday and Sunday (including the night) we were invited to work all together in an open space in Starter.

Also on Saturday organizers announced additional "diversifiers" (like on Global Game Jam). Fulfilling them was additional plus. For games, they were like "graphics is black and white", "game is controlled with one button" or... "game includes Playsoft logo". You could imagine how such logo might be used in a game themed "fear of the dark" :)

On Saturday and Sunday we have 3 meals - all for free (and free beer at the end :) There were mentors representing the sponsoring companies available in place so we could ask them for help.

There were totally 19 teams participating in all tracks. Most of them were in the gamedev track. Projects were evaluated by a jury based on a 5-minute presentation and there were winners selected in each track. Some teams just presented their applications, while others focused on delivering a PowerPoint presentation. Finally we took 3rd place. See also more about Our game from Hack3city 2014.

Among teams that were creating a game, Unity was the most popular technology. That's also what we have used. But there were different technologies present too, like C++ with Marmalade (which was officially recommended and the prize for 1st place was a license for this library), JavaScript and... Lisp (or Scheme, to be more specific). During work, many interesting stuff could be learn and overheard, like what do artist say when they want to insult programmers: "lerpuj kwaterniona", which means: "go lerp quaternion" :)

But the event was not only about programming. Maybe because it was organized by and in the Starter, it had a "startup feeling". For me it looked like many people, while being programmers, were more focused on money and business than technology. Maybe the culmination of it was presentation of an application that helps with first aid - shows information about how to help injured person, helps measuring rate of artifical respiration etc. Someone from the audience asked a question: "Do you have business model?" Someone else from the audience answered jokingly: "If you want to save someone's life, please first watch this ad".

Overall I think the event was well organized. Rules and general feeling was somehow similar to Global Game Jam, still quite unique and different in many details. I don't know if it's a good idea to announce the theme on Monday and allow working during whole week. Developers with lots of free time have advantage over these who study, have family or a full-time job. I also didn't like the idea of presenting each project 3 times instead of only at the end. It took lots of precious time that we could spend on coding and also made the final presentation less of a suprise. Everything else was great (did I mention free beer?), so I recommend attending this event when it will be organized next time!

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

23:11
Sun
11
May 2014

Hack3city 2014 - Our Game

I just came back from Hack3city - a programming competition. Participants had to develop their applications over this week - Monday to Friday working from home, while Saturday and Sunday working in Starter, Gdańsk. There were 4 tracks. We participated in track organized by Playsoft, where we had to create a game. The theme of this competition was "fear of the dark". We took 3rd place.

As I promised to some of you, I publish playable version of our game today. The game is created in Unity and can be run in web browser if you have Unity Player installed.

PLAY ONLINE

Controls:

Our game is called "Jason McBrady Dark Adventure". It's a 2D platform game. It's about an adventure seeker exploring ancient tombs full of dangers like zombies, who want to kill you, but run away from from the light. It's quite difficult :)

We called our team NOQA. Credits are:

In the next post, I will write more about Hack3city. See: Hack3city 2014 - Review

Comments (1) | Tags: unity hack3city competitions productions | Author: Adam Sawicki | Share

18:31
Tue
06
May 2014

Boost Geometry LOL

Many programmers I follow on Twitter made fun recently of this page: Boost Geometry - Design Rationale. I agree with them - it's ridiculous how sophisticated a simple geometric distance function can become if you want to make it generic using C++ metaprogramming. There are many developers who like such tricks, but I'm not one of them.

Of course I know and appreciate that C++ is so powerful you can write such generic code and that all the complexity is solved in compile time so run-time performance is good and not affected by this. But on the other hand, generic programming in C++ has its flaws: it's hard to learn, the code is long and complex, hard to write, debug, read and understand. When you make a mistake, error messages are cryptic, which is inevitable with so many levels of indirection.

So here is what I thought about this: If all these traits and other helper, boilerplate code was not needed and if compile-time metaprogramming was imperative and iteration-based like the main language itself, not functional and recursion-based, then a dimension-agnostic distance function could look like as simple as this:

struct vec2 { float x, y; }
struct vec3 { float x, y, z };

declare components of vec2 as { x, y };
declare components of vec3 as { x, y, z };

float distance(a, b)
{
    float dist = 0;
    foreach(c in a.components)
        dist += (b.c - a.c) * (b.c - a.c);
    return sqrt(dist);
}

But because it doesn't, I will stick with 2D, 3D and 4D vectors of floats :)

Comments (2) | Tags: boost c++ | Author: Adam Sawicki | Share

22:47
Mon
05
May 2014

Fluorescence

The main and general formula in computer graphics is Rendering Equation. It can be simplified to say that perceived color on an opaque surface is: LightColor * MaterialColor. The variables are are (R, G, B) vectors and (*) is per-component multiplication. According to this formula:

There are many phenomena that go beyond this model. One of them is subsurface scattering (SSS), where light penetrates object and goes out from different place on the surface. Another one is fluorescence - a property of a material which absorbs some light wavelength and emits different wavelength in return. One particularly interesting kind of it is UV-activity - when material absorbs UV light (also called blacklight, which is invisible to people) and emits some visible color. This way an object, when lit with UV light, looks like it's glowing in the dark, despite it has no LED-s or power source.

I've never seen a need to simulate fluorescence in computer graphics, but in real life it is used e.g. in decorations for psytrance parties, like this installation on main stage on Tree of Life 2012 festival in Turkey:

So what types of materials are fluorescent? It's not so simple that you can take any vividly colored object and it will glow in the  UV. Some of them do, some don't. You can take a very colourful T-shirt and it may be not visible under UV at all. On the other hand, some substances glow while they would better not (like dandruff :) But there are some materials that are specially designed and sold to be fluorescent, like the Fluor series of Montana MNT 94 paints I used to paint my origami decorations.

 

Comments (1) | Tags: rendering psytrance art | Author: Adam Sawicki | Share

13:23
Sun
04
May 2014

Four primary colors

I've already posted about my origami decoration. My choice of colors is not random. Of course I could make it more colorful, but evey paint costs some money, so I decided to buy just four: red, green, yellow and blue. Why?

That's because I still keep in my mind the great article Color Wheels are wrong? How color vision actually works. It tells that although our eyes can see three colors: red, green and blue (RGB), our perception is not that simple and direct. Our vision first does the difference between R and G, so each color is even more red or more green. Next and more importantly, it does the difference between RG and B, so each color is either more yellow (or red, or green) also known as warm colors, or more blue, aka cool colors.

That's also how photo manipulation software works (e.g. Adobe Lightroom). Instead of scrollbars for RGB, you can find there two scrollbars: to choose between more red and more green (called tint) and between more yellow and more blue (called temperature).

That's why it could be said that for our vision, there are four primary colors: red, green, yellow and blue.

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

22:04
Sat
03
May 2014

Origami Psytrance Decoration

I've posted before about modular origami. This time I made some bigger spike balls, painted them with fluorescent colors and used as decoration on yesterday's psychedelic trance party - Nirvana Open Air. It's 24-module Super Spike Ball (it's a link to Wayback Machine / Web Archive, because the great website spikeballheaven.net is no longer online), painted with Montana MNT 94 flourescent paints. Now I'm too tired after the party, but in the next two posts I will try to explain some theory behind it. And yes, it will be related to computer graphics :)

  1. Four primary colors
  2. Fluorescence

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

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