soledad penadés
repeat 4[fd 100 rt 90]

Escena.org invtro v2

20080516 by sole

This demo was released at Inspire, a new demoscene gathering held in a small town north of Spain, with the aim of promoting escena.org, the spanish demoscene website. There was already another promotional demo done by elerium core in 2001, but I thought it would be interesting to have a newer one to kick things off.

Scene 1

It is very, very calmed. I had thought at the beginning about doing something very demoscene-ish, just as the previous promo demo was, but then I found myself not wanting to redo yet again the same old school effects, and headed towards something a bit more abstract. Then I remembered about eb7m's 3400 miles below and suddenly lots of ideas came to mind!

The tech stuff

The biggest change compared to previous demos which I've coded is that I used a scripting engine instead of writing everything in C++, and recompiling every time I wanted to change a parameter. For this I've finally used Lua, after considering Ruby and Python. The nicest thing about Lua is that it is really easy to embed. If you want to embed Ruby or Python, it's a completely different (and long) story, but with Lua you just build the library (with a nice makefile which they provide already and just works™) and link to that library in your project, and that's it. You can then create as many instances of Luas as you want, and they won't interfere with each other. In my case I just use one, which loads and executes the demo script (demo.lua).

The second nicest thing with Lua is the way in which you pass parameters between C and Lua. It is very simple, with functions such as lua_tonumber, or lua_tostring; if you compare with Python for example, it is way more verbose.

In the demo script you can access several functions which I created in C and exposed (registered) to Lua. So for example, there's a function for loading a song in C and once I say to Lua: hey, there's this function in C that you can use!, you can write loadSong("filename") in the script and it will end up calling fmod through the C function.

The syntax and function naming is highly inspired by Processing's syntax, although I still want to change a few details and remove some functions which end up doing the same, so that there's only one way of doing things and it's minimalist, as Lua is.

This was also a bit of a benchmark for Lua, so instead of using the typical Vector3D, Face and Mesh C++ classes I decided to implement a reduced subset using Lua's metatables. Even normals are calculated using Lua's math library! Considering the insane amount of stuff which is going on there (I basically increased the number of things such as particles, terrain segments, etc, until the frame rate began to be a little bit jerky), I think it performs very decently. Next step would be to optimise what is sent to opengl, since currently not only everything is drawn in immediate mode but also nothing is culled at all.

Scene 2

Why does it look like that?

Some weeks ago, trace was joking about the lack of texturing of any kind in my demos. I said I would try to use some texturing next time, but as it happens, I thought it would be more funny to play with lights. Yes, I think it's the first time I use lights in a demo. Well, a light. Since the song's title is 3400 miles below, I thought of building something like an underwater world. A very deep one indeed, since sun rays do not even reach that depth, and so any ship which wanted to explore that area would need to use their own light - hence the light is needed for illuminating where we are looking at ;-)

I first built the ground. Initially I thought about calculating an evenly distributed matrix of points and then randomize the heights so that they formed something such as a terrain, but it looked too usual - so I broke some things here and there and that's why it looks as if the tiles are misplaced.

Then I wanted some kind of life in there. But life in very deep waters doesn't resemble the usually depicted fishes. It's more about strange entities, and so I thought of those strange spiders which are in the scene. They are simply there, waiting for something while their legs oscillate.

But it was still too plain. I went too creative and added some plankton, which actually is quite wrong (plankton isn't present at that depth). The plankton is abstracted with those little triangles which go up. In fact they shouldn't go up but down, since they are created and fall from above, but in this case they contribute towards the how odd, things are moving upwards feeling.

In the quest for making it a bit more sinister and mysterious I also added fog. I think it's the first time I use fog too! It was a black fog so that colours got even darker with the distance.

And then I began with the particles-text effect. I didn't want to load and analyze a bitmap to find out where the points were, so I remembered about those naive drawings we did with PRINT in Basic, and did this:

escena = {
        "XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX    XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX",
        "XX      XX XX         XX         XX      XX XX      XX         XX    XX      XX XX         XX        ",
        "XXXXXXXXXX XXXXXXXXXX XX         XXXXXXXXXX XX      XX XXXXXXXXXX    XX      XX XX         XX     XXX",
        "XX                 XX XX         XX         XX      XX XX      XX    XX      XX XX         XX      XX",
        "XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XX      XX XXXXXXXXXX XX XXXXXXXXXX XX         XXXXXXXXXX",
        "                                                                                                     "
        }

which is a table with strings. When loading the demo and preparing the effects, I go through each string and if there's an 'X' I store a new point in the list of particles to draw. Actually, I created several particles for each point so that the fountain of particles was a tad denser. Then in each frame they move a little bit towards their final destination. To make it more subtle too, I made the alpha dependent of the height, so that transparency decreased with height.

The problem was that everything was still too evident. Something else was needed in order to hide stuff and avoid showing everything from the beginning. So that's why I added several randomly sized but circularly distributed meshes around the center of the scene. They even look sort of kryptonitic to me!

And why is everything green? Because our ship has only got a very old green phosphorus monitor, so it can only display things in green shades. Apparently ;-)

Scene 3

Source release and other builds

I intend on releasing the source code soon, once I decide which functions go away and which ones do stay. It is only a few source files and it's built with C and some bits of STL so it hopefully should be quite easy to understand and follow, even if you just want to see how to connect Lua and C.

I also need to fix a couple of details, such as the universal libraries issue that I found at last minute, and changing to the data directory in non mac builds (in mac, it automatically changes to the data dir inside the Resources folder), etc. At that point new builds should be available for something else than Leopard.

I was also thinking of replacing fmod with a free alternative, but I have several problems: it seems there isn't a decent, open and easy to integrate module player library (other than fmod and bass, which doesn't work in linux), and libvorbis is quite heavy for what I want. Suggestions welcome :-)

Thanks

Of course big thanks to Pplux for his awesome explanation about how the stack in Lua works. That was all I needed to take off!

I'd also like to thank Corsario for offering his computer as compo machine, and trace for the hard work in his inspire demo - it encouraged me to finish this one on time :-)

And finally thanks to Inspire organizers for all the enthusiasm they have put into this new event. Let's hope we can release lots more of demos in subsequent Inspire editions!

Common GUI design mistake, fixed in Ubuntu

20080514 by sole

Common GUI design mistake, fixed in Ubuntu

He ought to be happy now!

Split files into folders by letter

20080513 by sole

I had a lot of files in one folder. It is not very practical to browse the folder that way, so I decided to create a little script which would split the files into different folders, using the first letter of the file for naming the folder, as in a, b, c, d… but using Python this time!

import os
import shutil
import sys

if len(sys.argv) > 1:
        folder = sys.argv[1]
else:
        folder = '.'

for item in os.listdir(folder):

        full_path = os.path.join(folder, item)
       
        if os.path.isdir(full_path):
                continue
       
        dst_folder = os.path.join(folder, item[0].lower())
       
        if not os.path.exists(dst_folder):
                os.mkdir(dst_folder)
               
        shutil.move(full_path, os.path.join(dst_folder, item))

Download from svn (this should always be the most up to date version)

To use simply go to your favourite terminal window and type

python split_files_into_folders_by_letter.py /path/to/messy/folder

It will pick the first letter of each file, create a folder with the lowercased letter (if it doesn't exist yet) and move the file to the folder. It won't move folders! (because of the os.path.isdir check).

If there's any pythonista in the audience with ideas for improving this, feel free to leave your suggestions in the comments, thanks! :-)

Note

There wasn't any special reason for not doing it with Ruby; I simply wanted to know what the differences would be. And while the semantics aren't very different (e.g. where it says os.path.join we would use File.join in Ruby), there is a huge difference between them and it's called documentation. Python documentation is hosted in Python's website, it is reviewed (and mostly written too) by Guido van Rossum (Python's author) and it's up to date and very easy to browse and read. Whereas Ruby docs were hosted elsewhere until very recently, are a pain to browse and pretty much a dump of automatically generated docs from source, which I find very uncomfortable to use. It still feels a little bit weird to use python's indenting style but I'm really liking it. A pity there isn't a Hpricot in python :-)

Bye bye, Burnaby! Hello, Laurel!

20080504 by sole

\o/

If you're reading this, it means my new server is working properly

It's been a long process, there were several websites to migrate and there were several issues too. First, the old data is in utf8 but the database is latin-1, which I solved with some smart scripting to update text and char columns. Second, and a bit more tedious, the database for this website was in a quite disastrous state. I suspect from a risky move from myself: I dared to use a trunk version of wordpress past year and it messed a bit with the categories, but I didn't notice until it was a tad late.

With the latest split from categories into terms, taxonomies and relationships WP2.5, it just went even worse. There were several empty terms, some taxonomies weren't related to any object at all, but their count was not zero and so they were shown in the list and when you accessed them, you got a nice 404 error, etc etc. That was relatively easy to fix with a bit of scripting again. And to top it all, some posts had lost their categories! So, lots of fun adding them again!

I had also been toying with a new theme which would use all the latest css goodness bits from newer browsers such as Safari and … er … Konqueror? Box shadows aren't implemented in Firefox yet so that basically ruins my theme idea. I also wanted to have gravatars, but plain gravatars aren't very surprising per se. I finally decided that if I couldn't have shadows and nice effects, then I would have a lo-res theme: only two colours, gravatars included. So if you leave comments here and you have a gravatar associated with your e-mail address, it will be abducted and reduced to a black and white dithered image which nicely fits with this spartan theme. Isn't it great?

I thought I would miss the old server (Burnaby), but I changed my mind as soon as I played with the new one. The admin interface is better and more intuitive, the response times are shorter and the technology is also newer (a shared accelerator versus the old shared hosting scheme). Hopefully there won't be any downtimes or they will be also shorter.

Hope that explains the lack of updates and activity in my online presence of late. And now I want to see your dithered faces in the comments ;-)

Building a universal library in Mac OS X

20080421 by sole

If you need to use a library in a universal binary you'll need to use a universal library too.

Let's use FMOD as an example; libfmod.a is the PPC compiled version, libfmodx86.a is the intel version.

For combining both into a universal library:

lipo -create libfmodx86.a libfmod.a -output libfmod-universal.a
ranlib libfmod-universal.a

In the case of FMOD they provide you the with precompiled static libraries (the .a files). But if you build libraries from source code, there's a magic compiler option called -arch which will help you in this. Unfortunately I don't have an example handy right now. I'll put it whenever I find it again, but it roughly goes on the lines of -arch i386 -arch ppc :-)

I'm not sure that naming a library with something as *-universal.a is a good idea, specially if you have code which uses -Llibraryname for linking libraries — I guess you might need to change that parameter. I am explicitly adding the libraries to the project in XCode so it's working fine for me.

Suggestions and better practices are welcome!