July 2011

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.

# Demoscene Night - Review

Jul 2011

Together with Tdc we have written a Review of Demoscene Night (in Polish) - party which took place on July 23rd. It is published on atarionline.pl website. You can also find there some photos from this event.

Noc z Demosceną Noc z Demosceną

Comments | #events #demoscene Share

# DevMeeting and Demoscene Night

Jul 2011

Yesterday I attended two events related to my interests. First was about collision detection in JavaScript games, organized by Marek Pawłowski from devmeetings.pl. During this almost 12-hour workshop we could learn about JavaScript, as well as some theory of 2D collision detection and space partitioning techniques. Nothing new for me, but I liked formula of this workshop. We could learn some theory from slides, but most of the time we had some tasks to code on our laptops - first to implement a simple library for aspects in JavaScript and then to code Asteroids game, including precise collision detection and QuadTree. Most of the code for this game was ready - we were given a framework, as well as libraries with math and a class for QuadTree. Our task was to just to connect it together. I think it's a good way of teaching programming in practice.

Web technologies are not my main interest, but I like JavaScript. I even think  it's the most beautiful scripting language in terms of syntax. Being able to freely draw 2D (using HTML Canvas) as well as 3D graphics (using WebGL) makes it a good technology for learning and prototyping geometry or gameplay algorithms. Marek also pointed on the DevMeeting an interesting conclusion that it's very easy to port algorithms from C/C++ to JavaScript. But on the other hand, Dab reminded me today that Lua is a scripting language with very similar features, but faster and more lightweight interpreter, so it's still better choice as a scripting language embedded in high-performance software like games.

More photos

Second event was Noc z Demosceną - Demoscene Night. It took place in Fabryka Kotłów club (former No Mercy). During that night we could see some olschool, as well as newschool demos presented on a a big screen and, what is most important, meet some nice people there. Thanks Voyager for organizing this event! It was great especially because the 3-day demoscene party RiverWash, which took place here in Warsaw in last 2 years, this year is in Łódź and I can't attend it. This night was very inspiring and now I feel like developing a technology to make a demo :)

Comments | #demoscene #webdev #javascript #math #events Share

# UDP Sockets: send Function Blocks

Jul 2011

Today I've met an interesting problem with programming UDP sockets in C++. Generally UDP protocol just sends packets (datagrams) and doesn't care whether they are successfully delivered or not. They may be dropped or arrive out of order. Destination machine can even not read them or not exist at all! So I was sure that when I have a socket created with socket(), socktype=SOCK_DGRAM and connect(), I can then send packets using send() and expect this call will always be fast.

I was sure about that until today, when I met a case where a call to send() blocked for above 3 seconds! Then I've made some experiments. It looks like sending UDP packets from my Windows XP behaves like this:

I've found a question about this problem: "when does a udp sendto() blocks ?" at StackOverflow. It looks like this behavior is caused by the system unsuccessfully trying to resolve IP address to physical MAC address with every send. But it's highly operating system dependent so we can't do much about it. We just have to keep in mind that using blocking sockets for sending UDP packets can freeze our application or thread for even several seconds with each packet sent.

13 Sep 2011 Update: I researched this issue further and it looks like it's even more specific. If the target machine was online and contacted before, but now it's offline, send() is very quick. Only if the ARP forgets the IP-MAC pair for that machine, send() blocks for such a long time with every call. It probably happens after several hours. You can also force ARP to clear the cache by issuing following console command in Windows, as Administrator: arp -d *.

Comments | #networking Share

# Too Low Level and Too High Level Abstraction

Jul 2011

Programmers fascinated by object-oriented methodology love the idea of abstraction and generalization, but others - especially those interested in data-oriented design - consider "premature generalization" as a big anti-pattern. I prefer the latter approach, so as I recently learn a little bit of Java, including Servlers and JSP, I feel terrified of how its API looks like. Let me explain...

Today an idea came to my mind that an API can be too abstract (general, universal) at low level or high level. The most abstract low-level API looks like this:

int write(void *buf, int bytes);
int read(void *buf, int bytes);

It's so general and universal that it would fit anywhere, but on the other hand it doesn't provide anything specific. It's just a very narrow pipe we have to pass all our data through. Of course this method is sometimes useful. For example that's the way we transfer data over network. But we do it using some specific protocol so it's reasonable to define a higher-level API with some objects that encapsulate concepts specific to that protocol, just like cURL implements HTTP, FTP and other network protocols on top of network sockets.

Let's compare some details from two APIs. A socket can have additional options that can be set. There are different options for different kinds of sockets and they have different types - some of them are bools, others are ints. But there is only one function to set such options - setsockopt:

int setsockopt(SOCKET s, int level, int optname, const char *optval, int optlen);

Objects in POSIX Threads API also can have additional attributes, but there are specific functions to set them, like in the example below. Which way do you prefer?

int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
int pthread_attr_setstacksize(pthread_attr_t *attr , size_t stacksize);

But excessive abstraction can also go too far the other way. That's what I see in Java API. I mean, these who code a lot in this language certainly can "feel" the sense in this approach, but for me it's almost ridiculous. Not only every part of the Java API has dozens of small classes with not much more than simple getName/setName methods and there is an interface for everything just like people were afraid of using real classes, but lots os stuff is refered by strings. I'd say Java is so high level that it's not only a strongly-typed language, it's stringly-typed language. Lots of classes implementing some interface can be registered in some global registry under its name so an instance can be constructed without ever refering to the real class, like: new SomeSpecificClass().

Probably the most grotesque example I saw today is java.naming package. Including its subpackages, it contains about hunred of classes and interfaces. But there is more than this. It's the whole great body of knowledge called JNDI (Java Naming and Directory Interface) with long tutorials and lots of concepts to understand, like Context, InitialContext, Directory, Service Provider, Lookup, Names, Composite Names, Compound Names, Naming System, Federations and so on... All this just to provide an abstract interface for a tree of any objects referred by name, so that disk files and directories can be accessed same way as data received with LDAP or some global variables defined in an XML file. Do anyone really needs that? The javax.naming.Context interface is not far from what would be the ultimate high level abstraction:

interface SuperAbstractEverything {
  public Object getObject(String namePathIdOrWhatever);

Comments | #java #software engineering Share

# Social Graph - Application on Facebook

Jul 2011

If you are active Facebook user and you like data visualisation just like me, then I strongly recommend you look at Social Graph application. When you run in, a Flash applet draws circles representing all your friends and connections between them. You are not there because, well, these are your friends so you are connected to all of them. You can only see how are they connected to each other. What's most interesting though is that they form some groups, which are clearly depicted thanks to graph visualisation algorithm used in this app. For example, my graph looks like this:

Facebook Social Graph

Several persons are not connected to anyone other I know. They are drawn somewhere outside the graph in a far distance. These are people who I know from some unusual place or who do not participate actively in Facebook and do not collect friends.

Rest of them forms clearly distinctive groups. The group on the right are people from my home town - mostly my friends from high school or university. The biggest group in the middle are passionate game developers from warsztat.gd community. Small group at the bottom consisting of four circles are contacts from my current job. On the left of Warsztat there is a group of professional game developers from Polish game industry. And finally the smaller group on the left consists of people I know from psytrance parties :)

What's also interesting is that there are some people who play role of a "center" of some group - are connected with almost everyone else in that group. Others are "connectors" that join two groups.

Comments | #rendering #web Share

# Nyan Cat + Angry Birds = Angry Nyan Cat

Jul 2011

If Angry Birds was joined with Nyan Cat, how would it look like? I think it would be something like this:

Angry Birds + Nyan Cat = Angry Nyan Cat

Note: This is only an image I created just "for the lulz". There is no actual game like that.

Comments | #humor #games #web Share

# Google+ - Social Network from Google

Jul 2011

Google announced they are working on a social networking website called Google+ which is going to compete with Facebook. It looks very promising so I look forward to test it when they release the website to the public. I especially like the idea of creating "Circles" of people to share things with only some groups of friends, not everyone. I don't want to express my political and other views to everyone or, on the other hand, bother all my friends with information about programming that are understandable and interesting to only those who share my passion.

Facebook is already popular, but we all know that Google develops good products (like search engine, Gmail, Chrome, Translate and numerous other stuff) so all in all I hope Google+ will become the successor of Facecbook, not a big failure like Google Wave. I already publish my photos on Picasa not on Facebook.

Comments | #web Share

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